//public int AddPhieuTiepNhanBaoHanh(DtoPhieuTiepNhanBaoHanh dtoPTNBH) //{ // try // { // SqlParameter[] para = // { // new SqlParameter("@MaPTNBH", dtoPTNBH.MaPTNBH), // new SqlParameter("@MaNV", dtoPTNBH.MaNV), // new SqlParameter("@NgayLap", dtoPTNBH.NgayLap), // }; // return SqlHelper.ExecuteNonQuery(Constants.ConnectionString, // CommandType.StoredProcedure, // "sp_InsertPTNBH", para); // } // catch (SqlException) // { // throw new ArgumentException(Constants.MsgExceptionSql); // } // catch (Exception) // { // throw new AggregateException(Constants.MsgExceptionError); // } //} public int AddPhieuTiepNhanBaoHanh(DtoPhieuTiepNhanBaoHanh dtoPTNBH, List<DtoChiTietPhieuTiepNhanBaoHanh> listCTPTNBH) { try { SqlConnection con = new SqlConnection(Constants.ConnectionString); con.Open(); SqlTransaction tran = con.BeginTransaction(); try { SqlParameter[] para = { new SqlParameter("@MaPTNBH", dtoPTNBH.MaPTNBH), new SqlParameter("@MaNV", dtoPTNBH.MaNV), new SqlParameter("@NgayLap", dtoPTNBH.NgayLap), }; SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "sp_InsertPTNBH", para); foreach (DtoChiTietPhieuTiepNhanBaoHanh dtoCTPTNBH in listCTPTNBH) { SqlParameter[] para1 = { //new SqlParameter("@MaCTPTNBH", dtoCTPTNBH.MaCTPTNBH), new SqlParameter("@MaHoaDon", dtoCTPTNBH.MaHoaDon), new SqlParameter("@MaSanPham", dtoCTPTNBH.MaSanPham), new SqlParameter("@MoTaLoi", dtoCTPTNBH.MoTaLoi), new SqlParameter("@SoLuong", dtoCTPTNBH.SoLuong), new SqlParameter("@MaPTNBH", dtoCTPTNBH.MaPTNBH), }; SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "sp_InsertCTPTNBH", para1); } tran.Commit(); } catch (Exception ex) { tran.Rollback(); ex.ToString(); return 0; } } catch (SqlException ex) { throw new Exception("Lỗi cơ sở dữ liệu"); } catch (Exception ex) { throw ex; } return 1; }
public bool AddPhieuTiepNhanBaoHanh(DtoPhieuTiepNhanBaoHanh dtoPTNBH, List<DtoChiTietPhieuTiepNhanBaoHanh> listCTPTNBH) { return dalPTNBH.AddPhieuTiepNhanBaoHanh(dtoPTNBH, listCTPTNBH) == 0 ? false : true; }
private void btnLuu_Click(object sender, EventArgs e) { DtoPhieuTiepNhanBaoHanh dtoPTNBH = new DtoPhieuTiepNhanBaoHanh(); List<DtoChiTietPhieuTiepNhanBaoHanh> listCTPTNBH = new List<DtoChiTietPhieuTiepNhanBaoHanh>(); dtoPTNBH.MaPTNBH = txtMaPTNBH.Text; _maPTNBH = txtMaPTNBH.Text; dtoPTNBH.MaNV = txtMaNV.Text.ToString(); dtoPTNBH.NgayLap = DateTime.Now; foreach (DataGridViewRow row in dgvDetailWarranty.Rows) { DtoChiTietPhieuTiepNhanBaoHanh dtoCTPTNBH = new DtoChiTietPhieuTiepNhanBaoHanh(); //dtoCTPTNBH.MaCTPTNBH = int.Parse(dgvCTPTNBH.Rows[i].Cells[0].Value.ToString()); dtoCTPTNBH.MaHoaDon = row.Cells[1].Value.ToString(); dtoCTPTNBH.MaSanPham = row.Cells[2].Value.ToString(); dtoCTPTNBH.MoTaLoi = row.Cells[4].Value.ToString(); dtoCTPTNBH.SoLuong = int.Parse(row.Cells[5].Value.ToString()); dtoCTPTNBH.MaPTNBH = dtoPTNBH.MaPTNBH; listCTPTNBH.Add(dtoCTPTNBH); } if (listCTPTNBH.Count == 0) { DisplayNotify("Không thể tạo phiếu tiếp nhận không có chi tiết", -1); return; } if (bllPTNBH.AddPhieuTiepNhanBaoHanh(dtoPTNBH, listCTPTNBH)) { try { txtMaPTNBH.Text = bllPTNBH.CreatePTNBH(); } catch (Exception ex) { lblThongBao.Text = "Lỗi không tạo mới! mã lỗi " + ex.Message; } btnClear.PerformClick(); txtAboutError.Clear(); MessageBox.Show(Constants.MsgNotificationSuccessfuly); //btnThoat.PerformClick(); } else { MessageBox.Show(Constants.MsgExceptionError); } }