Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox2.Text.Trim() == "" || textBox3.Text.Trim() == "")
            {
                if (textBox2.Text.Trim() == "" && textBox3.Text.Trim() == "")
                {
                    MessageBox.Show("Please provide username.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBox2.Focus();
                }
                else if (textBox2.Text.Trim() == "" && textBox3.Text.Trim() != "")
                {
                    MessageBox.Show("Please provide username.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBox2.Focus();
                }
                else if (textBox2.Text.Trim() != "" && textBox3.Text.Trim() == "")
                {
                    MessageBox.Show("Please provide password.", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    textBox3.Focus();
                }
            }
            else
            {
                wmsdb obj = new wmsdb();
                var   cc  = (from c in obj.WMS_USRS_VIEW
                             where c.usr_username == textBox2.Text.Trim()
                             select c.usr_username).FirstOrDefault();
                if (cc != null)
                {
                    var dd = (from c in obj.WMS_USRS_VIEW
                              where c.usr_username == textBox2.Text.Trim()
                              select new
                    {
                        c.usr_id,
                        c.usr_username,
                        c.usr_password,
                        c.usr_fname,
                        c.usr_lname,
                        c.usr_type_id,
                        c.usr_type_name
                    }).FirstOrDefault();

                    if (textBox3.Text.Trim() == dd.usr_password)
                    {
                        loggedin_user.userId       = dd.usr_id;
                        loggedin_user.userName     = dd.usr_username;
                        loggedin_user.fistName     = dd.usr_fname;
                        loggedin_user.lastName     = dd.usr_lname;
                        loggedin_user.userTypeId   = dd.usr_type_id;
                        loggedin_user.userTypeName = dd.usr_type_name;

                        label1.Focus();
                        Thread.Sleep(1);
                        this.Hide();
                        textBox2.Text = "";
                        textBox3.Text = "";
                        Form xmf = Application.OpenForms["Main_Form"];
                        if (xmf != null)
                        {
                            Main_Form.GetInstance().Show();
                        }
                        else
                        {
                            Main_Form.GetInstance().Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("You have entered invalid password.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("You are not registered, Please contact administrator.", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
 static void MainFormInstance_FormClosed(object sender, FormClosedEventArgs e)
 {
     Main_Form.MainFormInstance = null;
 }