Exemplo n.º 1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            List<DtoDeliveryBillDetail> list = new List<DtoDeliveryBillDetail>();
            DtoDeliveryBill DeliveryBill = new DtoDeliveryBill();
            DeliveryBill.MaPhieuXuatKho = txtMaPhieuXuatKho.Text;
            DeliveryBill.NgayLapPhieu = DateTime.Now;
            DeliveryBill.MaNguoiNhan = maNguoiNhanComboBox.SelectedValue.ToString();
            DeliveryBill.MaNguoiLapPhieu = nguoiLapPhieuComboBox.SelectedValue.ToString();
            DeliveryBill.GhiChu = txtGhiChu.Text;

            for (int i = 0; i < dgvDetailDeliveryBill.Rows.Count - 1; i++)
            {
                DtoDeliveryBillDetail detail = new DtoDeliveryBillDetail();
                detail.MaChiTietPhieuXuatKho = dgvDetailDeliveryBill.Rows[i].Cells[0].Value.ToString();
                detail.MaPhieuXuatKho = DeliveryBill.MaPhieuXuatKho;
                detail.MaSanPham = dgvDetailDeliveryBill.Rows[i].Cells[1].Value.ToString();
                detail.SoLuong = int.Parse(dgvDetailDeliveryBill.Rows[i].Cells[3].Value.ToString());
                detail.GhiChu = dgvDetailDeliveryBill.Rows[i].Cells[4].Value.ToString();
                list.Add(detail);
            }

            if (_bllDeliveryBill.AddDeliveryBillTran(DeliveryBill, list))
            {
                MessageBox.Show(Constants.MsgNotificationSuccessfuly);
                btnThoat.PerformClick();
            }
            else
            {
                MessageBox.Show(Constants.MsgExceptionError);
            }
        }
Exemplo n.º 2
0
 public int AddDeliveryBill(DtoDeliveryBill data)
 {
     SqlParameter[] para =
     {
         new SqlParameter("@MaPhieuXuatKho", data.MaPhieuXuatKho),
         new SqlParameter("@NgayLapPhieu", data.NgayLapPhieu),
         new SqlParameter("@MaNguoiNhan", data.MaNguoiNhan),
         new SqlParameter("@MaNguoLapPhieu", data.MaNguoiLapPhieu),
         new SqlParameter("@GhiChu", data.GhiChu),
     };
     try
     {
         return SqlHelper.ExecuteNonQuery(Constants.ConnectionString, CommandType.StoredProcedure,
             "AddDeliveryBill",
             para);
     }
     catch (SqlException)
     {
         throw new ArgumentException(Constants.MsgExceptionSql);
     }
     catch (Exception)
     {
         throw new AggregateException(Constants.MsgExceptionError);
     }
 }
Exemplo n.º 3
0
        public int AddDeliveryBillTran(DtoDeliveryBill DeliveryBill, List<DtoDeliveryBillDetail> list)
        {
            SqlConnection con = new SqlConnection(Constants.ConnectionString);
            con.Open();
            SqlTransaction tran = con.BeginTransaction();
            try
            {
                SqlParameter[] para =
                {
                    new SqlParameter("@MaPhieuXuatKho", DeliveryBill.MaPhieuXuatKho),
                    new SqlParameter("@NgayLapPhieu", DeliveryBill.NgayLapPhieu),
                    new SqlParameter("@MaNguoiNhan", DeliveryBill.MaNguoiNhan),
                    new SqlParameter("@MaNguoiLapPhieu", DeliveryBill.MaNguoiLapPhieu),
                    new SqlParameter("@GhiChu", DeliveryBill.GhiChu),
                };
                SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "AddDeliveryBill", para);

                foreach (DtoDeliveryBillDetail detail in list)
                {
                    SqlParameter[] para1 =
                    {
                        new SqlParameter("@MaChiTietPhieuXuatKho", detail.MaChiTietPhieuXuatKho),
                        new SqlParameter("@MaPhieuXuatKho", detail.MaPhieuXuatKho),
                        new SqlParameter("@MaSanPham", detail.MaSanPham),
                        new SqlParameter("@SoLuong", detail.SoLuong),
                        new SqlParameter("@GhiChu", detail.GhiChu),
                    };
                    SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure,
                    "AddDeliveryBillDetail",
                    para1);

                    SqlParameter[] para2 =
                    {
                        new SqlParameter("@MaSanPham", detail.MaSanPham),
                        new SqlParameter("@SoLuong", detail.SoLuong),
                    };
                    SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "UpdateCountProductOut", para2);
                }
                tran.Commit();
            }
            catch (Exception ex)
            {
                tran.Rollback();
                return 0;
            }
            return 1;
        }
Exemplo n.º 4
0
 public bool AddDeliveryBillTran(DtoDeliveryBill DeliveryBill, List<DtoDeliveryBillDetail> list)
 {
     return _dalDeliveryBill.AddDeliveryBillTran(DeliveryBill, list) == 0 ? false : true;
 }