public static bool TaoKhachHang(KhachHang khachHangMoi) { using (var context = new VeTauEntities(false)) { context.KhachHangs.Add(khachHangMoi); return context.SaveChanges() > 0; } }
public static int CapNhat(KhachHang khachHang) { using (var context = new VeTauEntities(false)) { var doiTuong = context.KhachHangs.SingleOrDefault(i => i.Id == khachHang.Id); if (doiTuong != null) { doiTuong.Id = khachHang.Id; doiTuong.TenKhachHang = khachHang.TenKhachHang; doiTuong.CMND = khachHang.CMND; doiTuong.SoDienThoai = khachHang.SoDienThoai; doiTuong.LoaiKhachHangId = khachHang.LoaiKhachHangId; doiTuong.MatKhau = khachHang.MatKhau; doiTuong.RuleDangNhap = khachHang.RuleDangNhap; } return context.SaveChanges(); } }
private void btnDangKy_Click(object sender, EventArgs e) { if (KiemTraHopLeVaThongBao()) { var khachHangMoi = new KhachHang { Id = tbId.Text.ToUpper(), TenKhachHang = tbTenKhachHang.Text, CMND = tbCMND.Text, SoDienThoai = tbDienThoai.Text, }; if (KhachHangDal.TaoKhachHang(khachHangMoi)) { MessageBox.Show(Resources.TaoDoiTuong + Resources.thanhCong + Resources.MThanhCong); Close(); } else { MessageBox.Show(Resources.TaoDoiTuong + Resources.thatBai + Resources.MThatBai); } } }
private void btnThem_Click(object sender, EventArgs e) { if (KiemTraHopLeVaThongBao()) { var khachHangMoi = new KhachHang { Id = tbId.Text.ToUpper(), TenKhachHang = tbTenKhachHang.Text, CMND = tbCMND.Text, SoDienThoai = tbDienThoai.Text, LoaiKhachHangId = cbLoaiKhachHang.SelectedValue is int ? (int) cbLoaiKhachHang.SelectedValue : 0, MatKhau = MyUtil.MaHoaMatKhau(tbMatKhau.Text), RuleDangNhap = twRuleDangNhap.IsOn }; if (KhachHangDal.TaoKhachHang(khachHangMoi)) { MessageBox.Show(Resources.TaoDoiTuong + Resources.thanhCong + Resources.MThanhCong); btnLamMoi_Click(null, null); } else { MessageBox.Show(Resources.TaoDoiTuong + Resources.thatBai + Resources.MThatBai); } } }