public bool xoaCTPT(CT_PHIEUTRA ct) { CT_PHIEUTRA _ct = qltv.CT_PHIEUTRAs.Where(c => c.MaChiTietPhieuTra == ct.MaChiTietPhieuTra).FirstOrDefault(); if (_ct != null) { PHIEUTRA _pt = qltv.PHIEUTRAs.Where(t => t.MaPhieuTra == _ct.MaPhieuTra).FirstOrDefault(); try { _pt.SoLuongSachTra = _pt.SoLuongSachTra - 1; qltv.CT_PHIEUTRAs.DeleteOnSubmit(_ct); qltv.SubmitChanges(); PHIEUMUON _pm = qltv.PHIEUMUONs.Where(m => m.MaPhieuMuon == _ct.MaPhieuMuon).FirstOrDefault(); if (_pm != null) { CT_PHIEUMUON _ctpm = qltv.CT_PHIEUMUONs.Where(t => t.MaVach == _ct.MaVach && t.MaPhieuMuon == _pm.MaPhieuMuon).FirstOrDefault(); _ctpm.TinhTrangTraCT = false; _pm.TinhTrangTra = false; qltv.SubmitChanges(); } return(true); } catch (Exception ex) { return(false); } } return(false); }
public bool luuPhieuTra(int mapm, int manv, DateTime ngaytra, int sltra, bool tiencoc, string tiencocdg, List <CT_PHIEUTRA> lstCTPT) { PHIEUTRA pt = new PHIEUTRA(); try { //pt.MaPhieuMuon = mapm; pt.MaNhanVien = manv; pt.NgayLap = ngaytra; pt.SoLuongSachTra = sltra; pt.TinhTrangXoa = false; qltv.PHIEUTRAs.InsertOnSubmit(pt); qltv.SubmitChanges(); PHIEUTRA mapt = qltv.PHIEUTRAs.Where(n => n.TinhTrangXoa == false).OrderByDescending(x => x.MaPhieuTra).First(); foreach (CT_PHIEUTRA ctpt in lstCTPT) { CT_PHIEUTRA _ctpt = new CT_PHIEUTRA(); _ctpt.MaPhieuTra = mapt.MaPhieuTra; _ctpt.MaPhieuMuon = ctpt.MaPhieuMuon; _ctpt.MaVach = ctpt.MaVach; _ctpt.TinhTrangXoa = false; CT_PHIEUMUON _ctpm = qltv.CT_PHIEUMUONs.Where(m => m.MaPhieuMuon == ctpt.MaPhieuMuon && m.MaVach == ctpt.MaVach).FirstOrDefault(); if (_ctpm.TinhTrangTraCT == false) { _ctpm.TinhTrangTraCT = true; } if (updateTinhTrangPM(ctpt.MaPhieuMuon.ToString())) { if (tiencoc == true) { PHIEUMUON _pm = qltv.PHIEUMUONs.Where(m => m.MaPhieuMuon == ctpt.MaPhieuMuon).FirstOrDefault(); _pm.PhiCoc = 0; tiencocdg = _pm.PhiCoc.ToString(); } } qltv.CT_PHIEUTRAs.InsertOnSubmit(_ctpt); qltv.SubmitChanges(); } return(true); } catch (Exception ex) { return(false); } }
private void QLP_T_btnXoa_CT_Click(object sender, EventArgs e) { CT_PHIEUTRA ct = new CT_PHIEUTRA(); ct.MaChiTietPhieuTra = int.Parse(QLP_T_dgvDSCT.CurrentRow.Cells[0].Value.ToString()); ct.MaPhieuTra = int.Parse(QLP_T_dgvDSCT.CurrentRow.Cells[1].Value.ToString()); DialogResult rs = MessageBox.Show("Bạn có chắc muốn xóa mã phiếu trả " + ct.MaPhieuTra, "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (rs == DialogResult.Yes) { if (qlpt.xoaCTPT(ct)) { MessageBox.Show("Xóa thành công !"); loadCTPTTheoPT(int.Parse(ct.MaPhieuTra.ToString())); load_dgvDSPT(); } else { MessageBox.Show("Xóa thất bại !"); } } }
private void QLMT_TDG_btnXacNhanTra_Click(object sender, EventArgs e) { //luu phieu tra //cap nha phieu muon ( neu tra du thi tinh trang = true, tinh trang chi tiet = true List <CT_PHIEUTRA> lstCTPT = new List <CT_PHIEUTRA>(); List <LOAIVIPHAM> lstLoaivp = new List <LOAIVIPHAM>(); List <CT_XULYVIPHAM> lstCTXL = new List <CT_XULYVIPHAM>(); string[] tienbt = QLMT_TDG_lblTongtien.Text.Split(' '); manv = Frm_Main.username; int sltra = QLMT_TDG_dgvCT_TLTra.Rows.Count - 1; DateTime ngaytra = DateTime.Now; int mapm = int.Parse(QLMT_TDG_dgvDSTLTra.CurrentRow.Cells[1].Value.ToString()); //lvp.MaLoaiViPham = QLMT_T_cboLoaiVP.SelectedIndex; if (QLMT_TDG_dgvCT_TLTra.Rows.Count - 1 > 0) { for (int i = 0; i < QLMT_TDG_dgvCT_TLTra.Rows.Count - 1; i++) { CT_PHIEUTRA _ct = new CT_PHIEUTRA(); _ct.MaVach = QLMT_TDG_dgvCT_TLTra.Rows[i].Cells[0].Value.ToString(); _ct.MaPhieuMuon = int.Parse(QLMT_TDG_dgvCT_TLTra.Rows[i].Cells[1].Value.ToString()); lstCTPT.Add(_ct); } } if (QLMT_TDG_dgvCT_Vipham.Rows.Count - 1 > 0) { for (int i = 0; i < QLMT_TDG_dgvCT_Vipham.Rows.Count - 1; i++) { CT_XULYVIPHAM ctxl = new CT_XULYVIPHAM(); ctxl.MaVach = QLMT_TDG_dgvCT_Vipham.Rows[i].Cells[1].Value.ToString(); ctxl.MaLoaiViPham = int.Parse(QLMT_TDG_dgvCT_Vipham.Rows[i].Cells[4].Value.ToString()); ctxl.TienBoiThuong = float.Parse(QLMT_TDG_dgvCT_Vipham.Rows[i].Cells[3].Value.ToString()); lstCTXL.Add(ctxl); } } // lấy ds loại vi phạm và ds tiền bồi thường bool phicoc; if (QLMT_TDG_chkTraTienCoc.Checked) { phicoc = true; } else { phicoc = false; } if (QLMT_TDG_dgvCT_TLTra.RowCount - 1 > 0) { if (qlt.luuPhieuTra(mapm, int.Parse(manv.ToString()), ngaytra, sltra, phicoc, QLMT_TDG_lblTienCoc.Text, lstCTPT)) { // luu phieu xu ly neu co if (QLMT_TDG_dgvCT_Vipham.Rows.Count - 1 > 0) { qlt.luuPhieuXLVP(ngaytra, float.Parse(QLMT_TDG_lblTongTienBT.Text), lstCTXL, int.Parse(manv)); mathetv = ""; } MessageBox.Show("Quá trình trả thành công ! "); } } else { MessageBox.Show("Quá trình trả thất bại !"); } //luu chi tiet phieu nhap //reset dgv QLMT_TDG_dgvDSTLTra.DataSource = null; QLMT_TDG_dgvDSTLTra.Refresh(); QLMT_TDG_dgvCT_Vipham.DataSource = null; QLMT_TDG_dgvCT_Vipham.Refresh(); QLMT_TDG_dgvCT_TLTra.DataSource = null; QLMT_TDG_dgvCT_TLTra.Refresh(); QLMT_TDG_txtTimMaDG.Text = ""; QLMT_TDG_txtTimMaDG.Focus(); QLMT_TDG_lblMaThe.Text = ""; QLMT_TDG_lblTienCoc.Text = ""; QLMT_TDG_lblTTThe.Text = ""; QLMT_TDG_lblHoTen.Text = ""; QLMT_TDG_lblEmail.Text = ""; QLMT_TDG_lblSDT.Text = ""; QLMT_TDG_txtMV.Text = ""; QLMT_TDG_txtMV.Enabled = false; QLMT_TDG_txtTenNV.Text = ""; QLMT_TDG_txtTenNV.Enabled = false; QLMT_TDG_txtGiaTL.Text = ""; QLMT_TDG_txtGiaTL.Enabled = false; QLMT_TDG_lblTongtien.Text = ""; QLMT_TDG_lblTongTienBT.Text = ""; QLMT_TDG_btnXacNhanTra.Enabled = false; QLMT_TDG_btnTinhTien.Enabled = false; QLMT_TDG_btnXoa.Enabled = false; QLMT_TDG_btnChon.Enabled = false; QLMT_TDG_btnHuyChon.Enabled = false; QLMT_TDG_btnXacNhanVP.Enabled = false; QLMT_TDG_txtSoNgayVP.ResetText(); ////QLMT_TDG_chkTraTienCoc.Checked = false; }