Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm a new in C# and creating Mdiparent form in that form toolstrip menu items are Login,Invoice,Transaction like...when I login form open it opened and other menu items are Enabled(previously disabled)..

This is login form code:
C#
private void login_Click(object sender, EventArgs e)
        {
            bool flag = false;

            try
            {
                System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection();
                conn.ConnectionString = BillingApplication.Properties.Settings.Default.DB_BillingConnectionString;
                conn.Open();

                string selectString = "SELECT * FROM login WHERE (Username = '" + textBox1.Text + "' AND Password = '" + textBox2.Text + "')";
                OleDbCommand cmd = new OleDbCommand(selectString, conn);
                OleDbDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        flag = true;

                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Error with Database Connection");
            }
            if (flag == true)
            {
                frmLogin login = new frmLogin();
                login.Hide();

                foreach (Form form in Application.OpenForms)
                {
                    if (form.GetType() == typeof(MDIParent1))
                    {
                        form.Activate();
                        return;
                    }
                }
                
              
            }
        }
Posted
Updated 23-Nov-12 20:39pm
v2

1 solution

Main Form Code
C#
private void frmMain_Load(object sender, EventArgs e)
   {
       this.Hide();

       DialogResult dr;
       frmLogin lStudent = new frmLogin();
       dr = lStudent.ShowDialog(this);
       lStudent.Dispose();

       if (dr != System.Windows.Forms.DialogResult.OK)
           this.Dispose();
       else
          this.Show();
   }

Login Form Code
C#
string u = "tochal",p="1357";
               if (txtUserName.Text == u && p == txtPassword.Text)
               {
                   this.DialogResult = System.Windows.Forms.DialogResult.OK;
                   this.Dispose();
               }
 
Share this answer
 
v2
Comments
Ali91Asadi 24-Nov-12 3:17am    
ShowDialog(this)=>Locking Main Form

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