Ejemplo n.º 1
0
        private void btn_login(object sender, EventArgs e)
        {
            //connection_check1();
            try
            {
                // connection_check1();
                string uPass = "";
                string dPass = "";
                try
                {
                    connection_check1();
                    MySqlCommand fins = new MySqlCommand("select password ,branch_n,user_name from fsm_signup where user_name ='" + tex_user.Text + "'", conn);
                    fins.ExecuteNonQuery();
                    MySqlDataReader bcc = fins.ExecuteReader();
                    if (bcc.Read())
                    {
                        dPass           = bcc[0].ToString();
                        branch_nnn.Text = bcc[1].ToString();
                        role_text.Text  = bcc[2].ToString();
                    }

                    bcc.Dispose();
                    branch = branch_nnn.Text;
                    user_n = role_text.Text;
                    uPass  = texpwd.Text;
                }
                catch (Exception ex)
                {
                }

                if (dPass == "")
                {
                    MessageBox.Show("Invalid User-Name, Please verify again", "Invalid UserName", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (uPass == dPass)
                {
                    //MessageBox.Show("You are Successfully Login", "Login Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    try
                    {
                        connection_check1();
                        MySqlCommand itd = new MySqlCommand("insert into fsm_login(user_name,domain,pc_name,date,time,branch_n,role) Values('" + tex_user.Text + "','" + myIP + "','" + hostName + "','" + DateTime.Today.ToString("dd-MM-yyyy") + "','" + DateTime.Now.ToString("hh:mm:ss") + "' ,'" + branch_nnn.Text + "' ,'" + role_text.Text + "')", conn);
                        itd.ExecuteNonQuery();
                        itd.Dispose();


                        tex_user.Text = "";
                        texpwd.Text   = "";
                        mainfrm fs = new mainfrm();
                        Hide();
                        fs.Show();
                        // Close();
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
                else if (uPass != dPass)
                {
                    MessageBox.Show("Invaild Password,Please try again", "Login error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    texpwd.Focus();
                    return;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invaild Username and Password,Please try again", "Login error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }

            loadingCurrentAccount();
        }
Ejemplo n.º 2
0
        private void texpwd_KeyDown(object sender, KeyEventArgs e)
        {
            // try
            {
                if (e.KeyCode == Keys.Enter)
                {
                    connection_check1();
                    string uPass = "";
                    string dPass = "";
                    try
                    {
                        MySqlCommand fins = new MySqlCommand("select password ,branch_n,user_name from fsm_signup where user_name ='" + tex_user.Text + "'", conn);
                        fins.ExecuteNonQuery();
                        MySqlDataReader bcc = fins.ExecuteReader();
                        if (bcc.Read())
                        {
                            dPass           = bcc[0].ToString();
                            branch_nnn.Text = bcc[1].ToString();
                            role_text.Text  = bcc[2].ToString();
                        }

                        bcc.Dispose();
                        branch = branch_nnn.Text;
                        uPass  = texpwd.Text;
                        user_n = role_text.Text;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    if (dPass == "")
                    {
                        MessageBox.Show("Invalid User-Name, Please verify again", "Invalid UserName", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else if (uPass == dPass)
                    {
                        try
                        {
                            connection_check1();
                            MySqlCommand itd = new MySqlCommand("insert into fsm_login(user_name,domain,pc_name,date,time,branch_n,role) Values('" + tex_user.Text + "','" + myIP + "','" + hostName + "','" + DateTime.Today.ToString("dd-MM-yyyy") + "','" + DateTime.Now.ToString("hh:mm:ss") + "' ,'" + branch_nnn.Text + "' ,'" + role_text.Text + "')", conn);
                            itd.ExecuteNonQuery();
                            itd.Dispose();
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message);
                        }
                        mainfrm fs = new mainfrm();
                        //this.Close();
                        fs.ShowDialog();
                        // this.Show();
                        //welcome fs1 = new welcome();
                        //fs1.Close();
                    }
                    else if (uPass != dPass)
                    {
                        MessageBox.Show("Invaild Password,Please try again", "Login error", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
                    }
                }
            }
            // catch (Exception ex)
            {
                //  MessageBox.Show(ex.Message);
            }
        }