Ejemplo n.º 1
0
 private void buttonDN_Click(object sender, EventArgs e)
 {
     try
     {
         if (String.IsNullOrEmpty(textBoxTK.Text))
         {
             MessageBox.Show("Ban chua nhap ten tai khoan!!");
             this.ActiveControl = textBoxTK;
         }
         else if (String.IsNullOrEmpty(textBoxMK.Text))
         {
             MessageBox.Show("Ban chua nhap mat khau!!");
             this.ActiveControl = textBoxMK;
         }
         else
         {
             NguoiDung ndCheck = db.NguoiDungs.SingleOrDefault(x => x.TenUser == textBoxTK.Text && x.MatKhau == textBoxMK.Text);
             if (ndCheck != null)
             {
                 FormMainMenu formMain = new FormMainMenu();
                 formMain.ShowDialog();
             }
             else
             {
                 MessageBox.Show("Tai khoan hoac mat khau sai!!");
                 textBoxTK.Clear();
                 textBoxMK.Clear();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 2
0
        private void buttonDangNhap_Click(object sender, EventArgs e)
        {
            FormMainMenu fm = new FormMainMenu();

            try
            {
                if (String.IsNullOrEmpty(textBoxTK.Text))
                {
                    MessageBox.Show("Ban chua nhap ten tai khoan!!");
                    this.ActiveControl = textBoxTK;
                }
                else if (String.IsNullOrEmpty(textBoxMK.Text))
                {
                    MessageBox.Show("Ban chua nhap mat khau!!");
                    this.ActiveControl = textBoxMK;
                }
                else
                {
                    UserTaiKhoan user = db.UserTaiKhoans.SingleOrDefault(x => x.TaiKhoan == textBoxTK.Text &&
                                                                         x.MatKhau == textBoxTK.Text);
                    if (user != null)
                    {
                        this.Hide();
                        fm.ShowDialog();
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Tai khoan hoac mat khau khong dung!!!");
                        textBoxTK.Clear();
                        textBoxMK.Clear();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 3
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txtPassword.Text) || String.IsNullOrWhiteSpace(txtUsername.Text))
            {
                MessageBox.Show("Please fill in required fields!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            con.Open();
            cmd.Connection  = con;
            cmd.CommandText = "SELECT UserName, Position, isActive FROM tblUserAccounts WHERE UserName = '******' AND Password = '******'";
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                if (Convert.ToInt32(dr["Position"]) == 1 && Convert.ToInt32(dr["isActive"]) == 1)
                {
                    this.Hide();
                    frmAdminMainMenu.ShowDialog();
                    this.Close();
                }
                else if (Convert.ToInt32(dr["Position"]) == 2 && Convert.ToInt32(dr["isActive"]) == 1)
                {
                    this.Hide();
                    frmStaffMainMenu.ShowDialog();
                    this.Close();
                }
                else
                {
                    MessageBox.Show("User Account is has been blocked!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            else
            {
                MessageBox.Show("User Account is not existing!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            con.Close();
        }