예제 #1
0
        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            //Kiểm tra null or empty
            if (string.IsNullOrEmpty(txtTenTaiKhoan.Text))
            {
                MetroFramework.MetroMessageBox.Show(this, "Vui lòng điền tên đăng nhập", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                txtTenTaiKhoan.Focus();
                return;
            }
            try
            {
                using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
                {
                    if (db.State == ConnectionState.Closed)
                    {
                        db.Open();
                    }
                    //Excute sql query, then map data return from sql to User class
                    UserThiSinh obj       = db.Query <UserThiSinh>($"select * from TTHocVien where SoCMND ='{txtTenTaiKhoan.Text}'", commandType: CommandType.Text).SingleOrDefault();
                    string      mahocvien = obj.MaHV;
                    Properties.Settings.Default.mahocvien = mahocvien;
                    Properties.Settings.Default.KMaHV     = mahocvien;
                    Properties.Settings.Default.KTenHV    = obj.TenHV;
                    Properties.Settings.Default.KHoHV     = obj.HoHV;
                    Properties.Settings.Default.KSoCMND   = obj.SoCMND;
                    Properties.Settings.Default.KKyThi    = obj.KyThi;
                    if (obj != null)
                    {
                        if (obj.MaHV == txtMatKhau.Text)//True
                        {
                            Console.WriteLine("\n\n Gia tri cua mahocvien la:  " + Properties.Settings.Default.KHoHV);

                            using (NavigateForm frm = new NavigateForm())//Open main form and hide login form
                            {
                                this.Hide();
                                frm.ShowDialog();
                            }
                        }
                        else
                        {
                            MetroFramework.MetroMessageBox.Show(this, "Sai Tài Khoản Hoặc Mật Khẩu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                        MetroFramework.MetroMessageBox.Show(this, "Sai Tài Khoản Hoặc Mật Khẩu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
            catch (Exception ex)
            {
                MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #2
0
 private void btnDangNhap_Click(object sender, EventArgs e)
 {
     //Kiểm tra null or empty
     if (string.IsNullOrEmpty(txtTenTaiKhoan.Text))
     {
         MetroFramework.MetroMessageBox.Show(this, "Vui lòng điền tên đăng nhập", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         txtTenTaiKhoan.Focus();
         return;
     }
     try
     {
         using (IDbConnection db = new SqlConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
         {
             if (db.State == ConnectionState.Closed)
             {
                 db.Open();
             }
             //Excute sql query, then map data return from sql to User class
             UserThiSinh obj = db.Query <UserThiSinh>($"select * from TTHocVien where SoCMND ='{txtTenTaiKhoan.Text}'", commandType: CommandType.Text).SingleOrDefault();
             if (obj != null)
             {
                 if (obj.MaHV == txtMatKhau.Text)                  //True
                 {
                     using (NavigateForm frm = new NavigateForm()) //Open main form and hide login form
                     {
                         this.Hide();
                         frm.metroTile2.Visible          = true;
                         frm.metroTile4.Visible          = true;
                         frm.metroTile6.Visible          = true;
                         frm.metroTile14.Visible         = true;
                         frm.btnMetroInfoAccount.Visible = true;
                         frm.ShowDialog();
                     }
                 }
                 else
                 {
                     MetroFramework.MetroMessageBox.Show(this, "Sai Tài Khoản Hoặc Mật Khẩu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 }
             }
             else
             {
                 MetroFramework.MetroMessageBox.Show(this, "Sai Tài Khoản Hoặc Mật Khẩu", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception ex)
     {
         MetroFramework.MetroMessageBox.Show(this, ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }