private void btnThem_Click(object sender, EventArgs e) { List<DtoWarehouseBillDetail> list = new List<DtoWarehouseBillDetail>(); DtoWarehouseBill warehouseBill = new DtoWarehouseBill(); warehouseBill.MaPhieuNhapKho = txtMaPhieuNhapKho.Text; warehouseBill.NgayLapPhieu = DateTime.Now; warehouseBill.MaNguoiLapPhieu = nguoiLapPhieuComboBox.SelectedValue.ToString(); warehouseBill.GhiChu = txtGhiChu.Text; for (int i = 0; i < dgvDetailWarehouseBill.Rows.Count - 1; i++) { DtoWarehouseBillDetail detail = new DtoWarehouseBillDetail(); detail.MaChiTietPhieuNhapKho = dgvDetailWarehouseBill.Rows[i].Cells[0].Value.ToString(); detail.MaPhieuNhapKho = warehouseBill.MaPhieuNhapKho; detail.MaSanPham = dgvDetailWarehouseBill.Rows[i].Cells[1].Value.ToString(); detail.SoLuong = int.Parse(dgvDetailWarehouseBill.Rows[i].Cells[3].Value.ToString()); detail.GhiChu = dgvDetailWarehouseBill.Rows[i].Cells[4].Value.ToString(); list.Add(detail); } if (_bllWarehouseBill.AddWarehouseBillTran(warehouseBill, list)) { MessageBox.Show(Constants.MsgNotificationSuccessfuly); btnThoat.PerformClick(); } else { MessageBox.Show(Constants.MsgExceptionError); } }
public bool AddWarehouseBillTran(DtoWarehouseBill warehouseBill, List<DtoWarehouseBillDetail> list) { try { return _dalWarehouseBill.AddWarehouseBillTran(warehouseBill, list) == 0 ? false : true; } catch (Exception ex) { throw ex; } }
public int AddWarehouseBillTran(DtoWarehouseBill warehouseBill, List<DtoWarehouseBillDetail> list) { SqlConnection con = new SqlConnection(Constants.ConnectionString); con.Open(); SqlTransaction tran = con.BeginTransaction(); try { SqlParameter[] para = { new SqlParameter("@MaPhieuNhapKho", warehouseBill.MaPhieuNhapKho), new SqlParameter("@NgayLapPhieu", warehouseBill.NgayLapPhieu), new SqlParameter("@MaNguoiLapPhieu", warehouseBill.MaNguoiLapPhieu), new SqlParameter("@GhiChu", warehouseBill.GhiChu), }; SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "AddWarehouseBill", para); foreach (DtoWarehouseBillDetail detail in list) { SqlParameter[] para1 = { new SqlParameter("@MaPhieuNhapKho", detail.MaPhieuNhapKho), new SqlParameter("@MaSanPham", detail.MaSanPham), new SqlParameter("@SoLuong", detail.SoLuong), new SqlParameter("@GhiChu", detail.GhiChu), }; SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "AddWarehouseBillDetail", para1); SqlParameter[] para2 = { new SqlParameter("@MaSanPham", detail.MaSanPham), new SqlParameter("@SoLuong", detail.SoLuong), }; SqlHelper.ExecuteNonQuery(tran, CommandType.StoredProcedure, "UpdateCountProduct", para2); } tran.Commit(); } catch (SqlException sqlEx) { throw new Exception("Lỗi kết nối cơ sở dữ liệu!"); } catch (Exception ex) { tran.Rollback(); return 0; } return 1; }
public int AddWarehouseBill(DtoWarehouseBill data) { SqlParameter[] para = { new SqlParameter("@MaPhieuNhapKho", data.MaPhieuNhapKho), new SqlParameter("@NgayLapPhieu", data.NgayLapPhieu), new SqlParameter("@MaNguoLapPhieu", data.MaNguoiLapPhieu), new SqlParameter("@GhiChu", data.GhiChu), }; try { return SqlHelper.ExecuteNonQuery(Constants.ConnectionString, CommandType.StoredProcedure, "AddWarehouseBill", para); } catch (SqlException) { throw new ArgumentException(Constants.MsgExceptionSql); } catch (Exception) { throw new AggregateException(Constants.MsgExceptionError); } }
private void btnThem_Click(object sender, EventArgs e) { try { List<DtoWarehouseBillDetail> list = new List<DtoWarehouseBillDetail>(); DtoWarehouseBill warehouseBill = new DtoWarehouseBill(); warehouseBill.MaPhieuNhapKho = txtWarehouseBillID.Text; warehouseBill.NgayLapPhieu = DateTime.Now; warehouseBill.MaNguoiLapPhieu = maNV; warehouseBill.GhiChu = txtGhiChu.Text; for (int i = 0; i < dgvDetailWarehouseBill.Rows.Count - 1; i++) { DtoWarehouseBillDetail detail = new DtoWarehouseBillDetail(); detail.MaPhieuNhapKho = warehouseBill.MaPhieuNhapKho; detail.MaSanPham = dgvDetailWarehouseBill.Rows[i].Cells[1].Value.ToString(); detail.SoLuong = int.Parse(dgvDetailWarehouseBill.Rows[i].Cells[3].Value.ToString()); if (dgvDetailWarehouseBill.Rows[i].Cells[4].Value != null) { detail.GhiChu = dgvDetailWarehouseBill.Rows[i].Cells[4].Value.ToString(); } else { detail.GhiChu = ""; } list.Add(detail); } if (_bllWarehouseBill.AddWarehouseBillTran(warehouseBill, list)) { txtWarehouseBillID.Text = CreateNewWarehouseBillID(); DisplayNotify("Thêm phiếu nhập kho thành công!", 1); btnThem.Enabled = false; // MessageBox.Show("Thêm phiếu nhập kho thành công!"); cleandgv(dgvDetailWarehouseBill); } } catch (Exception ex) { DisplayNotify("Lỗi không thể thêm phiếu nhập kho, mã lỗi:" + ex.Message, -1); } }
public bool AddWarehouseBillTran(DtoWarehouseBill warehouseBill, List<DtoWarehouseBillDetail> list) { return _dalWarehouseBill.AddWarehouseBillTran(warehouseBill, list) == 0 ? false : true; }