private void lblClickDeThemBaoHiem_Click(object sender, EventArgs e) { BAOHIEM bh = new BAOHIEM(); frmThongTinBaoHiem frm = new frmThongTinBaoHiem(); frm.btnBaoHiem_Sua.Enabled = false; frm.btnBaoHiem_Xoa.Enabled = false; if (frm.ShowDialog() == DialogResult.Yes) { bh.SoBH = frm.SoBaoHiem; bh.NgayCap = frm.NgayCap; bh.NoiCap = frm.NoiCap; bh.NoiKhamBenh = frm.NoiKhamBenh; bh.NgayHetHan = frm.NgayHetHan; bh.MaNV = Convert.ToInt32(dgvNhanVien.SelectedRows[0].Cells["MaNV"].Value); lstBaoHiem.Add(bh); lblClickDeThemBaoHiem.Visible = false; dgvBaoHiem.DataSource = typeof(List <BAOHIEM>); dgvBaoHiem.DataSource = lstBaoHiem; CustomDataGridViewBaoHiem(); BaoHiemBUL.Them(bh); } frm.btnBaoHiem_Sua.Enabled = true; frm.btnBaoHiem_Xoa.Enabled = true; }
private void dgvBaoHiem_Click(object sender, EventArgs e) { if (dgvBaoHiem.SelectedRows.Count > 0) { BAOHIEM bh = new BAOHIEM(); DataGridViewRow dgvRow = dgvBaoHiem.SelectedRows[0]; bh.SoBH = dgvRow.Cells["SoBH"].Value.ToString(); bh.NgayCap = Convert.ToDateTime(dgvRow.Cells["NgayCap"].Value); bh.NoiCap = dgvRow.Cells["NoiCap"].Value.ToString(); bh.NoiKhamBenh = dgvRow.Cells["NoiKhamBenh"].Value.ToString(); bh.NgayHetHan = Convert.ToDateTime(dgvRow.Cells["NgayHetHan"].Value); bh.MaNV = Convert.ToInt32(dgvRow.Cells["MaNV"].Value); frmThongTinBaoHiem frm = new frmThongTinBaoHiem(); frm.SoBaoHiem = bh.SoBH; frm.NgayCap = bh.NgayCap; frm.NoiCap = bh.NoiCap; frm.NoiKhamBenh = bh.NoiKhamBenh; frm.NgayHetHan = bh.NgayHetHan; DialogResult res = frm.ShowDialog(); if (res == DialogResult.Yes) { bh.SoBH = frm.SoBaoHiem; bh.NgayCap = frm.NgayCap; bh.NoiCap = frm.NoiCap; bh.NoiKhamBenh = frm.NoiKhamBenh; bh.NgayHetHan = frm.NgayHetHan; bh.MaNV = Convert.ToInt32(dgvRow.Cells["MaNV"].Value); lstBaoHiem.Add(bh); dgvBaoHiem.DataSource = typeof(List <BAOHIEM>); dgvBaoHiem.DataSource = lstBaoHiem; CustomDataGridViewBaoHiem(); BaoHiemBUL.Them(bh); } else if (res == DialogResult.OK) { bh.SoBH = dgvRow.Cells[0].Value.ToString(); bh = lstBaoHiem.SingleOrDefault(i => i.SoBH == bh.SoBH); bh.NgayCap = frm.NgayCap; bh.NoiCap = frm.NoiCap; bh.NoiKhamBenh = frm.NoiKhamBenh; bh.NgayHetHan = frm.NgayHetHan; dgvBaoHiem.DataSource = typeof(List <BAOHIEM>); dgvBaoHiem.DataSource = lstBaoHiem; CustomDataGridViewBaoHiem(); BaoHiemBUL.CapNhat(bh); } else if (res == DialogResult.No) { bh.SoBH = dgvRow.Cells[0].Value.ToString(); bh = lstBaoHiem.SingleOrDefault(i => i.SoBH == bh.SoBH); lstBaoHiem.Remove(bh); dgvBaoHiem.DataSource = typeof(List <BAOHIEM>); dgvBaoHiem.DataSource = lstBaoHiem; CustomDataGridViewBaoHiem(); BaoHiemBUL.Xoa(bh.SoBH); } } }