//sự kiện cho Quản lý Chi Tiết Dịch Vụ private void chiTiếtDịchVụToolStripMenuItem_Click(object sender, EventArgs e) { //gọi form var frmCTDV = new frmChiTietDichVu(); frmCTDV.ShowDialog(); CapNhapDuLieu(); }
//sự kiện Click cho nút btnUpdate private void btnUpdate_Click(object sender, EventArgs e) { try { //thao tac su kien dvg.Enabled = true; txtMa.Enabled = false; btnDelete.Enabled = true; //lay du lieu int ma = Int32.Parse(txtMa.Text.ToString()); int maHD = Int32.Parse(cbMaHD.Text.ToString()); int maPT = Int32.Parse(cbPhongTro.Text.ToString()); if (insert == 0) //nếu update { try { var chiTietHD = context.ChiTietHopDongs .Where(s => s.MaChiTietHD == ma).First();//lấy chiTietHD tương ứng //gán lại dữ liệu chiTietHD.MaHD = maHD; chiTietHD.MaPhong = maPT; }//end try catch (Exception)//lỗi { MessageBox.Show("Loi! Vui long kiem tra lai thong tin", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); LoadData(); return;//thoát }//end catch }//end if else//nếu insert { try { ChiTietHopDong chiTietHD = new ChiTietHopDong();//tạo //thêm dữ liệu cho ChiTietHopDong vừa tạo chiTietHD.MaChiTietHD = ma; chiTietHD.MaHD = maHD; chiTietHD.MaPhong = maPT; context.ChiTietHopDongs.Add(chiTietHD); //thêm vào bảng ChiTietHopDong context.SaveChanges(); //lưu //thêm chi tiết hợp đồng không DialogResult traLoi = MessageBox.Show("Ban co muon them Chi Tiet Dich Vu khong?", "Hoi", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (traLoi == DialogResult.Yes) { /*thêm chi tiết hợp đồng kết hợp thêm chi tiết dịch vụ*/ var chitietDV = new frmChiTietDichVu(); //tạo chitietDV.ShowDialog(); //hiện formChiTietDichVu } }//end if catch (Exception)//lỗi { MessageBox.Show("Loi! Vui long kiem tra lai thong tin", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); LoadData(); return;//thoát }//end catch insert = 0;//tắt cờ insert }//end else context.SaveChanges();//lưu MessageBox.Show("Thanh cong!", "Thong bao", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception)//lỗi { MessageBox.Show("Loi! Vui long kiem tra lai thong tin", "Loi", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(); }