Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

Instead of copy and past the same code for all form.
I have the idea to make a DLL file or class to set property for all controls in form by just use a few lines of code.

I can use this code for each form I need to set property for controls
C#
SqlDataAdapter adapt;
      SqlConnection conn = new SqlConnection(Properties.Settings.Default.ConnectionString); ;
      DataSet permiss = new DataSet();
      adapt = new SqlDataAdapter("SELECT * from dbo.controltorole WHERE dbo.ControltoRole.FormName='" + this.Name.ToString() + "'", conn);
      adapt.Fill(permiss, "Permiss");
      conn.Close();
      DataTable pm = permiss.Tables["Permiss"];

      if (pm.Rows.Count > 0)
      {
          for (int i = 0; i < pm.Rows.Count; i++)
          {
              try
              {
                  this.Controls[pm.Rows[i]["ControlName"].ToString()].Enabled = Convert.ToBoolean(pm.Rows[i]["Enabled"].ToString());
                  this.Controls[pm.Rows[i]["ControlName"].ToString()].Visible = Convert.ToBoolean(pm.Rows[i]["Visible"].ToString());
              }
              catch
              {
                  //rbMain.Items[pm.Rows[i]["ControlName"].ToString()].Visibility = BarItemVisibility.Never;
              }

              //MessageBox.Show(pm.Rows[i]["ControlName"].ToString());
              //MessageBox.Show(pm.Rows[i]["Enabled"].ToString());

          }
          pm.Clear();
      }
      else
      {
         // MessageBox.Show("Null");
      }


Now I want to make a DLL file or Class that I can use some code like

C#
AZMan.SetPermiss(this.Name.ToString())


Please help me do it.
Posted
Updated 31-Jan-12 17:55pm
v3

1 solution

Dll just for this method? Why not create an internal (or public as you want it to be available through a dll) method and your application will be able to access it from anywhere?

Or did I get your question wrong?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900