//Nút sửa private void btnSua_Click(object sender, RoutedEventArgs e) { #region 1. Lấy thông tin DataRowView _drv = (DataRowView)dgKhachHang.SelectedItem; KhachHangPublic _kh = new KhachHangPublic(); _kh.MaKH_KH = _drv["MaKH_KH"].ToString(); _kh.HoTen_KH = _drv["HoTen_KH"].ToString(); _kh.GioiTinh_KH = _drv["GioiTinh_KH"].ToString(); _kh.NgaySinh_KH = Convert.ToDateTime(_drv["NgaySinh_KH"].ToString()); _kh.Email_KH = _drv["Email_KH"].ToString(); _kh.NHK_KH.MaNKH_NKH = _drv["Ma_NHK_KH"].ToString(); _kh.DiemTichLuy_KH = Convert.ToInt32(_drv["DiemTichLuy_KH"].ToString()); _kh.SoLanMuaHang_KH = Convert.ToInt32(_drv["SoLanMuaHang_KH"].ToString()); _kh.SDT_KH = _drv["SDT_KH"].ToString(); _kh.GhiChu = _drv["GhiChu_KH"].ToString(); _kh.TuDongLenNhom_KH = (bool)_drv["TuDongLenNhom_KH"]; _kh.DangDung_KH = (bool)_drv["DangDung_KH"]; #endregion #region 2. Hiển thị wpf sửa KhachHangSuaPresentation wpf = new KhachHangSuaPresentation(); wpf._kh = _kh; wpf._SuaKhachhang += new EventHandler(SuaKhachHang); wpf.ShowDialog(); #endregion }
//Phương thức sửa khách hàng void SuaKhachHang(object sender, EventArgs e) { #region 1. Lấy thông tin KhachHangSuaPresentation wpf = (KhachHangSuaPresentation)sender; KhachHangPublic _kh = wpf._kh; #endregion #region 2. Lưu vào csdl if (KhachHangBusiness.SuaKhachHang(_kh)) { LoadDataToDataGrid(); } else { MessageBox.Show("Sửa thông tin khách hàng thất bại"); } #endregion }