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 int AddWarehouseBillDetail(DtoWarehouseBillDetail data) { SqlParameter[] para = { new SqlParameter("@MaChiTietPhieuNhapKho", data.MaChiTietPhieuNhapKho), new SqlParameter("@MaPhieuNhapKho", data.MaPhieuNhapKho), new SqlParameter("@MaSanPham", data.MaSanPham), new SqlParameter("@SoLuong", data.SoLuong), new SqlParameter("@GhiChu", data.GhiChu), }; try { return SqlHelper.ExecuteNonQuery(Constants.ConnectionString, CommandType.StoredProcedure, "AddWarehouseBillDetail", 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); } }