[C#][Visual2k17] How to retrieve data from a previous form? : I really need your help right now. I want to **disable** a button in a form when the user **is log as** "operator" and enable it when he is an "admin". I have 3 form : first one => **login page** where i have the **"User" and "password"** parameters, second one => **menu** where i have a **label on the top** saying who is currently connect (operator or admin), third one => the **repair** **page**. The problem is that when i click on the button "Back" on my third form, and **i get back** on the second form, the button **is enable**. So even "Operator" can access it through this glitch / bug.

Code for my login page:



    public partial class Login : Form
    {
        
        public Login()
        {
            InitializeComponent();
            
           
        }

        public void button2_Click(object sender, EventArgs e)
        {
            Main form2 = new Main(this);
            try
            {
                SqlConnection con = new SqlConnection("Server=(local); Database= Seica_Takaya;Integrated Security = SSPI; ");
                SqlDataAdapter sda = new SqlDataAdapter("SELECT count(*) FROM Loginmdp WHERE util='" + textBox1.Text + "' AND mdp='" + textBox2.Text + "'", con);
                DataTable dt = new DataTable();
                sda.Fill(dt);
                


                if (dt.Rows[0][0].ToString() == "1")
                {
                    MessageBox.Show("Connexion réussie ! ");
                    this.Hide();
                    form2.Show();

                    con.Close();


                }
                else
                {
                    MessageBox.Show("Identifiant / Mot de passe faux. Veuillez resaisir votre identifiant et mot de passe.");

                    con.Close();
                }
                
            }
            catch(SqlException ex)
            {
                MessageBox.Show("SQL EXCEPTION : " + ex.Message);
            }

         
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

     


    }



Here is my code for the menu : 

    

    public partial class Main : Form
    {
        private Login login;
       

        public Main()
        {
            

            InitializeComponent();
          

        }



        public Main(Login login)
        {
            InitializeComponent();
            label3.Text = login.textBox1.Text;

            this.login = login;

            if (login.textBox1.Text == "admin" && login.textBox2.Text == "root")
            {
                button2.Enabled = true;

            }
            else
            {
                button2.Enabled = false;
            }

        }

     
        private void button1_Click(object sender, EventArgs e)
        {
            Repair form3 = new Repair();
            this.Hide();

            form3.Show();

        }

      

        private void button2_Click(object sender, EventArgs e)
        {
            Admin form4 = new Admin();
            this.Hide();
            form4.Show();
        }



        private void button3_Click(object sender, EventArgs e)
        {
            new Login().Show();
            this.Hide();
            MessageBox.Show("Vous êtes déconnecté");


        }


      

       
    }


Code for the repair page : 


    public partial class Repair : Form
    {
        

        public Repair()
        {
            InitializeComponent();
            
            
            
        }

       

        private void button1_Click(object sender, EventArgs e)
        {

            SqlConnection maConnexion = new SqlConnection("Server= localhost; Database= Seica_Takaya;Integrated Security = SSPI; ");
           
            maConnexion.Open();

             string Var1 = textBox1.Text;
             SqlCommand command = maConnexion.CreateCommand();
             command.Parameters.AddWithValue("@BoardName", Var1);
             command.Parameters.AddWithValue("@Machine", Var1);
             command.Parameters.AddWithValue("@SerialNum", Var1);
             command.Parameters.AddWithValue("@FComponent", Var1);
            command.CommandText = "SELECT * FROM FailOnly WHERE BoardName=@BoardName OR Machine=@Machine OR SerialNum=@SerialNum OR FComponent=@FComponent AND ReportingOperator != NULL";
             SqlDataAdapter sda = new SqlDataAdapter(command);
             DataSet ds = new DataSet();
             sda.Fill(ds);
             dataGridView1.DataSource = ds.Tables[0];



        }



        private void button2_Click(object sender, EventArgs e)
        {

            
            this.Hide();
            Main ff = new Main();
            ff.Show();
            
            

       
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           /**
            BindingSource bs = new BindingSource();
            bs.DataSource = dataGridView1.DataSource;
            bs.Filter = string.Format("BoardName LIKE '%{0}%'",textBox1.Text.Replace("'","''"));
            dataGridView1.DataSource = bs;**/
            
            


            
        }
    }

Step by step pictures now :

[First][1]
[Second][2]


  [1]: https://i.stack.imgur.com/cB5Oe.png
  [2]: https://i.stack.imgur.com/4h1TI.jpg
