private void btnThem_Click(object sender, EventArgs e) { if (KiemTra()) { try { KhachHang kh = new KhachHang(); kh.MaKH = KhachHangBUS.XuLyMa(); kh.TenKH = txtTenKH.Text; if (cbxGioiTinh.Text == "Nam") { kh.GioiTinh = 1; } else kh.GioiTinh = 0; kh.NgaySinh = dateNgaySinh.DateTime; kh.CMND = txtCMND.Text; kh.Email = txtEmail.Text; kh.QuocTich = txtQuocTich.Text; kh.DiaChi = txtDiaChi.Text; kh.SDT = txtSDT.Text; KhachHangBUS.Insert(kh); LoadData(); MessageBox.Show("Thêm khách hàng thành công!", "Thông Báo"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
private void btnLuu_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { if (KiemTra()) { try { KhachHang kh = new KhachHang(); kh.MaKH = (string)gridView1.GetFocusedRowCellValue(colMaKH); kh.TenKH = gridView1.GetFocusedRowCellDisplayText(colTenKH); kh.GioiTinh = (int)gridView1.GetFocusedRowCellValue(colGioiTinh); kh.NgaySinh = Convert.ToDateTime(gridView1.GetFocusedRowCellDisplayText(colNgaySinh)); kh.CMND = gridView1.GetFocusedRowCellDisplayText(colCMND); kh.Email = gridView1.GetFocusedRowCellDisplayText(colEmail); kh.QuocTich = gridView1.GetFocusedRowCellDisplayText(colQuocTich); kh.DiaChi = gridView1.GetFocusedRowCellDisplayText(colDiaChi); kh.SDT = gridView1.GetFocusedRowCellDisplayText(colSDT); KhachHangBUS.Update(kh); LoadData(); MessageBox.Show("Sửa Nhân viên thành công!", "Thông Báo"); } catch (Exception ex) { MessageBox.Show(ex.Message); } } }
public void KhachHang_Update(KhachHang kh) { using (var cmd = new SqlCommand("SP_KhachHang_Update", GetConnection())) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@MaKH", kh.MaKH)); cmd.Parameters.Add(new SqlParameter("@TenKH", kh.TenKH)); cmd.Parameters.Add(new SqlParameter("@GioiTinh", kh.GioiTinh)); cmd.Parameters.Add(new SqlParameter("@NgaySinh", kh.NgaySinh)); cmd.Parameters.Add(new SqlParameter("@QuocTich", kh.QuocTich)); cmd.Parameters.Add(new SqlParameter("@CMND", kh.CMND)); cmd.Parameters.Add(new SqlParameter("@DiaChi", kh.DiaChi)); cmd.Parameters.Add(new SqlParameter("@Email", kh.Email)); cmd.Parameters.Add(new SqlParameter("@SDT", kh.SDT)); cmd.ExecuteNonQuery(); } }
public static void Update(KhachHang kh) { db.KhachHang_Update(kh); }
public static void Insert(KhachHang kh) { db.KhachHang_Insert(kh); }