Example #1
0
 private void Dangnhap()
 {
     try
     {
         var tb = LoadData.KiemTraTaiKhoan(txtTaiKhoan.Text, MaHoaMd5.Md5(txtMatKhau.Text));
         if (tb.Rows.Count > 0)
         {
             var taikhoan = new Taikhoan
             {
                 ID       = int.Parse(tb.Rows[0]["ID"].ToString()),
                 TaiKhoan = tb.Rows[0]["TaiKhoan"].ToString(),
                 MatKhau  = tb.Rows[0]["MatKhau"].ToString(),
                 HoTen    = tb.Rows[0]["HoTen"].ToString(),
                 Quyen    = tb.Rows[0]["Quyen"].ToString()
             };
             CheckDangNhap(this, true, taikhoan);
         }
         else
         {
             MessageBox.Show(FormResource.FrmDangNhap_Dangnhap_, @"Thông báo");
             txtMatKhau.Clear();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.Contains(FormResource.msgLostConnect) ? FormResource.txtLoiDB : ex.Message);
         Log2File.LogExceptionToFile(ex);
     }
 }
 private void uG_DanhSach_AfterExitEditMode(object sender, EventArgs e)
 {
     try
     {
         if (DeleteAndUpdate)
         {
             DeleteAndUpdate = false;
             return;
         }
         var indexcell = dgv_DanhSach.ActiveCell.Column.Index;
         var id        = dgv_DanhSach.ActiveRow.Cells["ID"].Text;
         var ht        = dgv_DanhSach.ActiveRow.Cells["HoTen"].Text;
         var qu        = dgv_DanhSach.ActiveRow.Cells["Quyen"].Text;
         if (indexcell == 3)
         {
             var mk = dgv_DanhSach.ActiveRow.Cells["MatKhau"].Text;
             if (!string.IsNullOrEmpty(id) &&
                 !string.IsNullOrEmpty(mk))
             {
                 foreach (var item in _listUpdatepass.Where(item => item.ID == int.Parse(id)))
                 {
                     item.MatKhau = MaHoaMd5.Md5(mk);
                     return;
                 }
                 var hs = new Taikhoan
                 {
                     ID      = int.Parse(id),
                     MatKhau = MaHoaMd5.Md5(mk)
                 };
                 _listUpdatepass.Add(hs);
             }
         }
         else if (!string.IsNullOrEmpty(id))
         {
             foreach (var item in _listUpdate.Where(item => item.ID == int.Parse(id)))
             {
                 item.HoTen = ht;
                 item.Quyen = qu;
                 return;
             }
             var hs = new Taikhoan
             {
                 ID    = int.Parse(id),
                 HoTen = ht,
                 Quyen = qu
             };
             _listUpdate.Add(hs);
         }
     }
     catch (Exception ex)
     {
         Log2File.LogExceptionToFile(ex);
     }
 }
        protected override void SaveDetail()
        {
            try
            {
                if (ValidateData())
                {
                    MessageBox.Show(@"Vui lòng nhập đầy đủ thông tin", @"Lỗi");
                }
                else
                {
                    foreach (var row in dgv_DanhSach.Rows.Where(row => string.IsNullOrEmpty(row.Cells["ID"].Text)))
                    {
                        var hs = new Taikhoan
                        {
                            TaiKhoan = row.Cells["TaiKhoan"].Value.ToString(),
                            HoTen    = row.Cells["HoTen"].Value.ToString(),
                            Quyen    = row.Cells["Quyen"].Value.ToString(),
                            MatKhau  = MaHoaMd5.Md5(row.Cells["MatKhau"].Value.ToString())
                        };
                        _listAdd.Add(hs);
                    }
                    if (_listAdd.Count <= 0 && _listUpdate.Count <= 0 && _listUpdatepass.Count <= 0)
                    {
                        return;
                    }
                    if (_listUpdate.Count > 0)
                    {
                        UpdateData.UpdateTaiKhoan(_listUpdate);
                    }
                    if (_listUpdatepass.Count > 0)
                    {
                        UpdateData.UpdateMatKhau(_listUpdatepass);
                    }
                    if (_listAdd.Count > 0)
                    {
                        InsertData.ThemTaiKhoan(_listAdd);
                    }

                    MessageBox.Show(FormResource.MsgThongbaothanhcong, FormResource.MsgCaption, MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    LoadFormDetail();
                }
            }
            catch (Exception ex)
            {
                Log2File.LogExceptionToFile(ex);
            }
        }
 private void button1_Click(object sender, System.EventArgs e)
 {
     if (string.IsNullOrEmpty(txtMK1.Text))
     {
         txtMK1.Focus();
         errorcu.SetError(txtMK1, @"Chưa nhập mật khẩu cũ");
     }
     else if (string.IsNullOrEmpty(txtMK2.Text))
     {
         txtMK2.Focus();
         errorcu.Dispose();
         errormoi.SetError(txtMK2, @"Chưa nhập mật khẩu mới");
     }
     else if (string.IsNullOrEmpty(txtMK3.Text))
     {
         txtMK3.Focus();
         errormoi.Dispose();
         errornhaplai.SetError(txtMK3, @"Nhập lại mật khẩu mới");
     }
     else if (txtMK2.Text != txtMK3.Text)
     {
         txtMK3.Focus();
         errornhaplai.Dispose();
         MessageBox.Show(@"Mật khẩu nhập lại không khớp", @"Thông báo", MessageBoxButtons.OK,
                         MessageBoxIcon.Warning);
     }
     else if (_matkhau != MaHoaMd5.Md5(txtMK1.Text))
     {
         txtMK1.Focus();
         MessageBox.Show(@"Sai Mật khẩu cũ", @"Thông báo", MessageBoxButtons.OK,
                         MessageBoxIcon.Warning);
     }
     else
     {
         UpdateData.UpdateMatKhau(_taikhoan, MaHoaMd5.Md5(txtMK3.Text));
         CheckUpdate = true;
         MessageBox.Show(@"Mật khẩu đã được thay đổi", @"Thông báo", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
         Close();
     }
 }