public int ThemChiTietPhieuTra(CT_PhieuTraDTO CTPT) { int nRow = 0; try { string strSQL = "INSERT INTO CT_PHIEUTRA VALUES(@MaPT, @MaSach,@NgayMuon,@SoNgayMuon,@TienPhat)"; provider.Connect(); nRow = provider.ExecuteNonQuery(CommandType.Text, strSQL, new SqlParameter { ParameterName = "@MaPT", Value = CTPT.MaPT }, new SqlParameter { ParameterName = "@MaSach", Value = CTPT.MaSach }, new SqlParameter { ParameterName = "@NgayMuon", Value = CTPT.NgayMuon }, new SqlParameter { ParameterName = "@SoNgayMuon", Value = CTPT.SoNgayMuon }, new SqlParameter { ParameterName = "@TienPhat", Value = CTPT.TienPhat }); } catch (SqlException ex) { throw ex; } finally { provider.DisConnect(); } return(nRow); }
public int ThemChiTietPhieuTra(CT_PhieuTraDTO CTPT) { try { QuanLyPhieuTraDAO DAO = new QuanLyPhieuTraDAO(); return(DAO.ThemChiTietPhieuTra(CTPT)); } catch (SqlException ex) { throw ex; } }
private void btnLapPhieu_Click(object sender, EventArgs e) { if (txtMaDG.Text != "" && STTSach > 1 && dtgrPhieuTra[1, 0].Value.ToString() != "") { if (KiemTraNgayTraHopLe() == false) { MessageBox.Show("Trong phiếu có sách không hợp lệ với ngày trả xin vui lòng kiểm tra lại", "THÔNG BÁO"); } else { PhieuTraDTO PhieuTraDTO = new PhieuTraDTO(); PhieuTraDTO.MaPT = txtMaPhieuTra.Text; PhieuTraDTO.NgayTra = dtNgayTra.Value; PhieuTraDTO.MaPM = MaPM; PhieuTraDTO.TienPhatKyNay = float.Parse(txtTienPhatKyNay.Text); PhieuTraDTO.TienNo = float.Parse(txtTongNo.Text); PhieuTraDTO.SoNgayTraTre = SoNgayTraTre; QuanLyPhieuTraBUS BUS = new QuanLyPhieuTraBUS(); int nRow = BUS.ThemPhieuTra(PhieuTraDTO); CT_PhieuTraDTO CTPT; for (int i = 0; i < dtgrPhieuTra.RowCount; i++) { if (Convert.ToString(dtgrPhieuTra.Rows[i].Cells[1].Value) != "") { CTPT = new CT_PhieuTraDTO(); CTPT.MaPT = txtMaPhieuTra.Text; CTPT.MaSach = Convert.ToString(dtgrPhieuTra.Rows[i].Cells[1].Value); CTPT.NgayMuon = Convert.ToDateTime(dtgrPhieuTra.Rows[i].Cells[2].Value); CTPT.SoNgayMuon = int.Parse(dtgrPhieuTra.Rows[i].Cells[3].Value.ToString()); CTPT.TienPhat = float.Parse(dtgrPhieuTra.Rows[i].Cells[4].Value.ToString()); BUS.ThemChiTietPhieuTra(CTPT); BUS.CapNhatTinhTrangSach(CTPT.MaSach); } } if (nRow > 0) { MessageBox.Show("Lập phiếu trả thành công", "THÔNG BÁO"); LoadThemThanhCong(); } else { MessageBox.Show("Lập phiếu trả thất bại", "THÔNG BÁO"); } } } else if (txtMaDG.Text == "") { MessageBox.Show("Xin vui lòng nhập mã độc giả", "THÔNG BÁO"); txtMaDG.Focus(); return; } else if (STTSach == 1 || dtgrPhieuTra[1, 0].Value.ToString() == "") { MessageBox.Show("Vui lòng thêm sách vào phiếu trả", "THÔNG BÁO"); } }