private void btnThemTK_Click(object sender, EventArgs e) { if (txtTenTK.Text.Equals("") || txtMKMoi.Text.Equals("") || txtMKMoi2.Text.Equals("")) { MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } QLNS.Services.LogIn logInSer = new QLNS.Services.LogIn(); TaiKhoanInfo taikhoan = new TaiKhoanInfo(); taikhoan.ID = txtTenTK.Text; if (logInSer.CheckAcc(taikhoan)) { MessageBox.Show("Trùng tên tài khoản", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!txtMKMoi.Text.Equals(txtMKMoi2.Text)) { MessageBox.Show("Mật khẩu nhập lại không trùng khớp", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } taikhoan.LoaiTK = 2; taikhoan.Pass = txtMKMoi.Text; TaiKhoanDAO taikhoanDao = new TaiKhoanDAO(); taikhoanDao.InsertAccount(taikhoan); }
private void btnLuu_Click(object sender, EventArgs e) { if (cboNhanVien.Text == "") { MessageBox.Show("Chưa chọn nhân viên!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (cboQuyenHan.Text == "") { MessageBox.Show("Chưa chọn quyền hạn!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (txtMatKhau.Text == "") { MessageBox.Show("Mật khẩu không được bỏ trống!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { TaiKhoanInfo tk = new TaiKhoanInfo(); tk.NhanVien.MaNV = cboNhanVien.SelectedValue.ToString(); tk.MatKhau = txtMatKhau.Text; tk.Quyen = cboQuyenHan.SelectedIndex; if (isThem) { tkCtrl.Them(tk); } else { tk.Id = Convert.ToInt32(dataGridViewTK.CurrentRow.Cells[0].Value.ToString()); tkCtrl.Sua(tk); } frmTaiKhoan_Load(sender, e); } }
public int dangKy(TaiKhoanInfo tk) { conn.Open(); SqlCommand cmd = new SqlCommand("dangKy", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] par = new SqlParameter[] { new SqlParameter("@username", SqlDbType.NVarChar), new SqlParameter("@pass", SqlDbType.NVarChar), new SqlParameter("@hoten", SqlDbType.NVarChar), new SqlParameter("@email", SqlDbType.NVarChar), new SqlParameter("@sdt", SqlDbType.NVarChar), //new SqlParameter("@province",SqlDbType.NVarChar), //new SqlParameter("@district",SqlDbType.NVarChar), //new SqlParameter("@ward",SqlDbType.NVarChar), new SqlParameter("@diachi", SqlDbType.NVarChar), new SqlParameter("@maquyen", SqlDbType.Int) }; par[0].Value = tk.Username; par[1].Value = tk.Password; par[2].Value = tk.HoTen; par[3].Value = tk.Email; par[4].Value = tk.SDT; //par[5].Value = tk.Province; //par[6].Value = tk.District; //par[7].Value = tk.Ward; par[5].Value = tk.DiaChi; par[6].Value = tk.MaQuyen; cmd.Parameters.AddRange(par); int i = cmd.ExecuteNonQuery(); conn.Close(); return(i); }
private void btnDoiMK_Click(object sender, EventArgs e) { if (txtMKCu.Text.Equals("") || txtMKMoi.Text.Equals("") || txtMKMoi2.Text.Equals("")) { MessageBox.Show("Vui lòng nhập đủ thông tin", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (!txtMKMoi.Text.Equals(txtMKMoi2.Text)) { MessageBox.Show("Mật khẩu nhập lại sai", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } TaiKhoanInfo tk = new TaiKhoanInfo(); tk.Pass = txtMKCu.Text; if (!tk.Pass.Equals(taikhoan.Pass)) { MessageBox.Show("Sai mật khẩu hiện tại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } taikhoan.Pass = txtMKMoi.Text; TaiKhoanDAO taikhoanDao = new TaiKhoanDAO(); taikhoanDao.UpdatePassWord(taikhoan.ID, taikhoan.Pass); MessageBox.Show("Thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); }
public bool dangNhap(TaiKhoanInfo tk) { bool ketqua = false; string conn = ConfigurationManager.ConnectionStrings["STR_CONN"].ToString(); SqlConnection objConn = null; SqlDataReader dr = null; try { objConn = new SqlConnection(conn); objConn.Open(); SqlCommand objComm = new SqlCommand("dangnhap", objConn); objComm.CommandType = CommandType.StoredProcedure; SqlParameter[] parms = new SqlParameter[] { new SqlParameter("@username", SqlDbType.NVarChar), new SqlParameter("@password", SqlDbType.NVarChar) }; parms[0].Value = tk.tendangnhap; parms[1].Value = tk.matkhau; objComm.Parameters.AddRange(parms); dr = objComm.ExecuteReader(); if (dr.Read()) { ketqua = true; } } finally { objConn.Close(); } return(ketqua); }
//create proc sp_ThongTinTaiKhoan @Ten nvarchar(20),@MatKhau nvarchar(20) public TaiKhoanInfo ThongTinTaiKhoan(string Ten, string MatKhau) { dataService.Conect(); dataService.Cmd = new SqlCommand("sp_ThongTinTK", dataService.Cnn); dataService.Cmd.CommandType = CommandType.StoredProcedure; dataService.Cmd.Parameters.Add("@Ten", SqlDbType.NVarChar); dataService.Cmd.Parameters["@Ten"].Value = Ten; dataService.Cmd.Parameters.Add("@MatKhau", SqlDbType.NVarChar); dataService.Cmd.Parameters["@MatKhau"].Value = MatKhau; SqlDataReader r; TaiKhoanInfo tk = new TaiKhoanInfo(); r = dataService.Cmd.ExecuteReader(); while (r.Read()) { tk.Ma = int.Parse(r.GetValue(0).ToString()); tk.Ten = r.GetValue(1).ToString(); tk.MatKhau = r.GetValue(2).ToString(); tk.Loai = r.GetValue(3).ToString(); break; } dataService.DisConect(); return(tk); }
protected void btnCapNhat_Click(object sender, EventArgs e) { //cập nhật theo thông tin TaiKhoanInfo ti = new TaiKhoanInfo(); ti.HoTen = txtHoTen.Text; //ti.Province = ddlProvince.SelectedValue; //ti.District = ddlDistrict.SelectedValue; //ti.Ward = ddlWard.SelectedValue; ti.DiaChi = txtDiaChi.Text; ti.SDT = txtSDT.Text; ti.Email = txtEmail.Text; ti.Username = Session["Username"].ToString(); TaiKhoanBLL tb = new TaiKhoanBLL(); if (tb.updateUser(ti)) { lblThongBao2.Visible = true; lblThongBao2.Text = "Cập nhật thông tin thành công."; // giá trị trả về đúng thì update thành công loadInfo(); } else { lblThongBao2.Visible = true; lblThongBao2.Text = "Lỗi.";//ngược lại thì lỗi } }
public IList showUserinfo() { conn.Open(); string sql = "select * from TaiKhoan"; SqlCommand cmd = new SqlCommand(sql, conn); ArrayList lst = new ArrayList(); TaiKhoanInfo hh; SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { hh = new TaiKhoanInfo(); if (!dr.IsDBNull(0)) { hh.MaUser = dr.GetInt32(0); } if (!dr.IsDBNull(1)) { hh.Username = dr.GetString(1); } if (!dr.IsDBNull(2)) { hh.Password = dr.GetString(2); } if (!dr.IsDBNull(3)) { hh.HoTen = dr.GetString(3); } if (!dr.IsDBNull(4)) { hh.Email = dr.GetString(4); } if (!dr.IsDBNull(5)) { hh.SDT = dr.GetString(5); } //if (!dr.IsDBNull(6)) hh.Province = dr.GetString(6); //if (!dr.IsDBNull(7)) hh.District = dr.GetString(7); //if (!dr.IsDBNull(8)) hh.Ward = dr.GetString(8); if (!dr.IsDBNull(6)) { hh.DiaChi = dr.GetString(6); } if (!dr.IsDBNull(7)) { hh.MaQuyen = dr.GetInt32(7); } lst.Add(hh); } dr.Close(); conn.Close(); return(lst); }
private void btnXoa_Click(object sender, EventArgs e) { if (MessageBox.Show("Bạn có muốn xóa tài khoản " + txtTenDangNhap.Text + "?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { TaiKhoanInfo info = new TaiKhoanInfo(); info.ID = Convert.ToInt32(dGV.CurrentRow.Cells[0].Value.ToString()); tkBus.Xoa(info); } // Tải lại lưới frmTaiKhoan_Load(sender, e); }
public bool CheckAcc(TaiKhoanInfo AccInfo) { DataTable dt = AccDAO.GetSingle(AccInfo.ID); if (dt != null && dt.Rows[0] != null) { if (dt.Rows[0].Field <string>("ID") == AccInfo.ID) { return(true); } } return(false); }
public bool DeleteAccount(TaiKhoanInfo AccInfo) { try { SqlCommand cmd = new SqlCommand(); cmd.CommandText = @"Delete From TAIKHOAN Where ID = @ID"; cmd.Parameters.Add("@ID", SqlDbType.Char, 20); cmd.Parameters["@ID"].Value = AccInfo.ID; return(Delete(cmd)); } catch (SqlException e) { MessageBox.Show(e.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } }
private void btnDangNhap_ItemClick(object sender, ItemClickEventArgs e) { //DangNhap dangnhap = new DangNhap(); //AddTabControl(dangnhap, "Đăng Nhập"); DangNhapFrm frm = new DangNhapFrm(); frm.ShowDialog(); if (frm.DialogResult == DialogResult.Cancel) { ChangeTypeMenu(frm.LoaiTK); if (frm.LoaiTK > 0) { taikhoan = frm.taikhoan; ribTaiKhoan.Text = taikhoan.ID; } } }
private void btnDangNhap_Click(object sender, EventArgs e) { TaiKhoanInfo AccInfo = new TaiKhoanInfo(); QLNS.Services.LogIn logInSer = new QLNS.Services.LogIn(); AccInfo.ID = txtTaiKhoan.Text; AccInfo.Pass = txtMatKhau.Text; LoaiTK = logInSer.CheckPass(AccInfo); if (LoaiTK > 0) { MessageBox.Show(IDS_SUCCESS_LOGIN, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(IDS_FAIL_LOGIN, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
//create proc sp_ThemTaiKhoan @ten nvarchar(20), @matkhau nvarchar(20), @loai nvarchar(20) public void sp_ThemTaiKhoan(TaiKhoanInfo info) { dataService.Conect(); dataService.Cmd = new SqlCommand("sp_ThemTaiKhoan", dataService.Cnn); dataService.Cmd.CommandType = CommandType.StoredProcedure; dataService.Cmd.Parameters.Add("@ten", SqlDbType.NVarChar); dataService.Cmd.Parameters["@ten"].Value = info.Ten; dataService.Cmd.Parameters.Add("@matkhau", SqlDbType.NVarChar); dataService.Cmd.Parameters["@matkhau"].Value = info.MatKhau; dataService.Cmd.Parameters.Add("@loai", SqlDbType.NVarChar); dataService.Cmd.Parameters["@loai"].Value = info.Loai; dataService.Cmd.ExecuteNonQuery(); dataService.DisConect(); }
public bool InsertAccount(TaiKhoanInfo AccInfo) { try { SqlCommand cmd = new SqlCommand(); cmd.CommandText = @"Insert Into TAIKHOAN values(@ID, @PassWord, @Loai)"; cmd.Parameters.Add("@ID", SqlDbType.Char, 20); cmd.Parameters.Add("@PassWord", SqlDbType.Char, 32); cmd.Parameters.Add("@Loai", SqlDbType.Int); cmd.Parameters["@ID"].Value = AccInfo.ID; cmd.Parameters["@PassWord"].Value = AccInfo.Pass; cmd.Parameters["@Loai"].Value = AccInfo.LoaiTK; return(Insert(cmd)); } catch (SqlException e) { MessageBox.Show(e.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } }
//---lay Ma Tai Khoan //sp_LayThongTinTKMoiThem public TaiKhoanInfo sp_LayThongTinTKMoiThem() { dataService.Conect(); dataService.Cmd = new SqlCommand("sp_LayThongTinTKMoiThem", dataService.Cnn); dataService.Cmd.CommandType = CommandType.StoredProcedure; SqlDataReader r; TaiKhoanInfo tk = new TaiKhoanInfo(); r = dataService.Cmd.ExecuteReader(); while (r.Read()) { tk.Ma = int.Parse(r.GetValue(0).ToString()); tk.Ten = r.GetValue(1).ToString(); tk.MatKhau = r.GetValue(2).ToString(); tk.Loai = r.GetValue(3).ToString(); break; } dataService.DisConect(); return(tk); }
public bool updateUser(TaiKhoanInfo ti) { bool rs = true; conn.Open(); SqlCommand cmd = new SqlCommand("update_user", conn); cmd.CommandType = CommandType.StoredProcedure; SqlParameter[] par = new SqlParameter[] { new SqlParameter("@hoten", SqlDbType.NVarChar), //new SqlParameter("@province",SqlDbType.NVarChar), //new SqlParameter("@district",SqlDbType.NVarChar), //new SqlParameter("@ward",SqlDbType.NVarChar), new SqlParameter("@diachi", SqlDbType.NVarChar), new SqlParameter("@sdt", SqlDbType.NVarChar), new SqlParameter("@email", SqlDbType.NVarChar), new SqlParameter("@username", SqlDbType.NVarChar) }; par[0].Value = ti.HoTen; //par[1].Value = ti.Province; //par[2].Value = ti.District; //par[3].Value = ti.Ward; par[1].Value = ti.DiaChi; par[2].Value = ti.SDT; par[3].Value = ti.Email; par[4].Value = ti.Username; cmd.Parameters.AddRange(par); int i = cmd.ExecuteNonQuery(); if (i > 0) { rs = true; } else { rs = false; } conn.Close(); return(rs); }
private void btnLuu_Click(object sender, EventArgs e) { if (txtTenDangNhap.Text.Trim() == "") { MessageBox.Show("Chưa chọn nhân viên!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (txtTenNV.Text.Trim() == "") { MessageBox.Show("Tên nhân viên không được bỏ trống!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (cboQuyenHan.Text == "") { MessageBox.Show("Chưa chọn quyền hạn!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else if (txtMatKhau.Text == "") { MessageBox.Show("Mật khẩu không được bỏ trống!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { TaiKhoanInfo tk = new TaiKhoanInfo(); tk.TenDangNhap = txtTenDangNhap.Text.Trim(); tk.TenNV = txtTenNV.Text.Trim(); tk.MatKhau = txtMatKhau.Text; tk.Quyen = cboQuyenHan.SelectedIndex; if (isThem) { tkBus.Them(tk); } else { tk.ID = Convert.ToInt32(dGV.CurrentRow.Cells[0].Value.ToString()); tkBus.Sua(tk); } // Tải lại lưới frmTaiKhoan_Load(sender, e); } }
public int CheckPass(TaiKhoanInfo AccInfo) { DataTable dt = AccDAO.GetSingle(AccInfo.ID); MD5 md5Hash = MD5.Create(); //string PassMd5 = GetMd5Hash(md5Hash, AccInfo.Pass); if (dt != null && dt.Rows.Count > 0) { string SourcePass = dt.Rows[0].Field <string>("Pass"); int LoaiTK = dt.Rows[0].Field <int>("LoaiTK"); StringComparer comparer = StringComparer.OrdinalIgnoreCase; if (0 == comparer.Compare(AccInfo.Pass, SourcePass)) { return(LoaiTK); } else { return(0); } } return(0); }
public DoiMK(TaiKhoanInfo tk) { InitializeComponent(); taikhoan = tk; }
public void ThemTaiKhoan(TaiKhoanInfo info) { accTaikhoan.sp_ThemTaiKhoan(info); }
public void Xoa(TaiKhoanInfo info) { string sql = "DELETE FROM TAIKHOAN WHERE ID = " + info.ID; data.ExecuteSQL(sql); }
public void Sua(TaiKhoanInfo info) { string sql = "UPDATE TAIKHOAN SET TENDANGNHAP = '" + info.TenDangNhap + "', TENNV = N'" + info.TenNV + "', MATKHAU = '" + info.MatKhau + "', QUYEN = " + info.Quyen + " WHERE ID = " + info.ID; data.ExecuteSQL(sql); }
public void Them(TaiKhoanInfo info) { string sql = "INSERT INTO TAIKHOAN(TENDANGNHAP, TENNV, MATKHAU, QUYEN) VALUES('" + info.TenDangNhap + "', N'" + info.TenNV + "', '" + info.MatKhau + "', " + info.Quyen + ")"; data.ExecuteSQL(sql); }
public void Sua(TaiKhoanInfo tk) { data.Sua(tk); }
public void Them(TaiKhoanInfo tk) { data.Them(tk); }
public void Xoa(TaiKhoanInfo info) { data.Xoa(info); }
public void Them(TaiKhoanInfo tk) { DB2Command cmd = new DB2Command("INSERT INTO QLLK5.TAIKHOAN(MANV, MATKHAU, QUYEN) VALUES('" + tk.NhanVien.MaNV + "', '" + tk.MatKhau + "', " + tk.Quyen + ")"); data.Load(cmd); }
public void Sua(TaiKhoanInfo tk) { DB2Command cmd = new DB2Command("UPDATE QLLK5.TAIKHOAN SET MANV = '" + tk.NhanVien.MaNV + "', MATKHAU = '" + tk.MatKhau + "', QUYEN = " + tk.Quyen + " WHERE ID = " + tk.Id); data.Load(cmd); }
public void Sua(TaiKhoanInfo info) { data.Sua(info); }