Пример #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);
     }
 }
Пример #2
0
        private void CheckDangNhap(object sender, bool checkState, Taikhoan hs)
        {
            LoadDefaul(hs.Quyen);
            _dangnhap = true;
            lbusername.Text = hs.HoTen;
            _taikhoan = hs.TaiKhoan;
            _matkhau = hs.MatKhau;
            _quyen = hs.Quyen;
            _frmDangNhap.Close();

            cboChonkythi.DataSource = LoadData.Load(18);
            Tabquanlykythi.Tab.Visible = false;
        }
 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);
            }
        }
Пример #5
0
 /// <summary>
 /// Update thông tin 1 tài khoản
 /// </summary>
 /// <returns>true</returns>
 private static void UpdateTaiKhoan(Taikhoan item)
 {
     try
     {
         Conn.ExcuteQuerySql("Update TAIKHOAN set HoTen = N'" + item.HoTen + "', Quyen = N'" + item.Quyen +
                             "' where ID = " + item.ID + "");
     }
     catch (Exception ex)
     {
         Log2File.LogExceptionToFile(ex);
     }
 }
Пример #6
0
 private static void UpdateMatKhau(Taikhoan item)
 {
     try
     {
         Conn.ExcuteQuerySql("Update TAIKHOAN set MatKhau = N'" + item.MatKhau + "' where ID = " + item.ID + "");
     }
     catch (Exception ex)
     {
         Log2File.LogExceptionToFile(ex);
     }
 }
Пример #7
0
 /// <summary>
 /// Thêm 1 người dùng mới
 /// </summary>
 /// <returns></returns>
 public static bool ThemTaiKhoan(Taikhoan item)
 {
     try
     {
         Conn.ExcuteQuerySql("INSERT INTO TAIKHOAN(TaiKhoan,MatKhau,HoTen,Quyen) values(N'" +
                             item.TaiKhoan + "',N'" + item.MatKhau + "',N'" + item.HoTen + "',N'" +
                             item.Quyen + "')");
         return true;
     }
     catch (Exception ex)
     {
         Log2File.LogExceptionToFile(ex);
         return false;
     }
 }