//sự kiện cho Quản lý Hợp Đồng private void hợpĐồngToolStripMenuItem1_Click(object sender, EventArgs e) { var frmHD = new frmHopDongThue(); frmHD.ShowDialog(); CapNhapDuLieu(); }
//sự kiện Click cho nút Update private void btnUpdate_Click(object sender, EventArgs e) { try { //thao tac su kien dvg.Enabled = true; txtMaKH.Enabled = false; btnDelete.Enabled = true; //lay du lieu int maKH = Int32.Parse(txtMaKH.Text.ToString()); string tenKH = txtTenKH.Text.ToString(); int soCMND = Int32.Parse(txtCMND.Text.ToString()); string gioiTinh = txtGioiTinh.Text.ToString().ToUpper(); string diaChi = txtDiaChi.Text.ToString(); string ngheNghiep = txtNgheNghiep.Text.ToString(); decimal sdt = Decimal.Parse(txtSDT.Text.ToString()); if (insert == 0)//insert { try { var kh = context.KhachHangs .Where(s => s.MaKhach == maKH).First(); //tìm khách hàng tương ứng //gán lại giá trị kh.TenKhach = tenKH; kh.CMND = soCMND; kh.GioiTinh = gioiTinh; kh.DiaChiKhach = diaChi; kh.NgheNghiep = ngheNghiep; kh.SdtKhach = sdt; kh.HinhAnhKH = img; }//end try catch (Exception)//lỗi { MessageBox.Show("Loi! Vui long kiem tra lai thong tin", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); LoadData(); return; } //end catch } //end if else //update { try { KhachHang kh = new KhachHang(); //tạo //gán giá trị kh.MaKhach = maKH; kh.TenKhach = tenKH; kh.GioiTinh = gioiTinh; kh.HinhAnhKH = img; kh.NgheNghiep = ngheNghiep; kh.SdtKhach = sdt; kh.CMND = soCMND; kh.DiaChiKhach = diaChi; context.KhachHangs.Add(kh); //thêm khách hàng vừa tạo context.SaveChanges(); //lưu //thêm hợp đồng không DialogResult traLoi = MessageBox.Show("Ban co muon them Hop dong thue khong?", "Hoi", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (traLoi == DialogResult.Yes) { var hd = new frmHopDongThue(); hd.ShowDialog(); } }//end try catch (Exception) { MessageBox.Show("Loi! Vui long kiem tra lai thong tin", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); LoadData(); return; } //end catch insert = 0;//tắt cờ } //end else context.SaveChanges();//lưu //thông báo thành công MessageBox.Show("Thanh cong!", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information); }//end if catch (Exception)//lỗi { MessageBox.Show("Loi! Vui long kiem tra lai thong tin", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); }