public int AddChiTietPhieuTiepNhanBaoHanh(DtoChiTietPhieuTiepNhanBaoHanh dtoCTPTNBH)
        {
            try
            {
                SqlParameter[] para =
                {
                    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),
                };
                return SqlHelper.ExecuteNonQuery(Constants.ConnectionString,
                    CommandType.StoredProcedure,
                    "sp_InsertCTPTNBH", para);

            }
            catch (SqlException)
            {
                throw new ArgumentException(Constants.MsgExceptionSql);
            }
            catch (Exception)
            {
                throw new AggregateException(Constants.MsgExceptionError);
            }
        }
 public int AddChiTietPhieuTiepNhanBaoHanh(DtoChiTietPhieuTiepNhanBaoHanh dtoCTPTNBH)
 {
     return dalCTPTNBH.AddChiTietPhieuTiepNhanBaoHanh(dtoCTPTNBH);
 }
        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);
            }
        }