public BllProductBuildTable GetModel(string SLIP_NUMBER) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 SLIP_NUMBER,WAREHOUSE_CODE,PRODUCT_CODE,QUANTITY,BUILD_DATE,COMPANY_CODE,UNIT_CODE,STATUS_FLAG,CREATE_USER,CREATE_DATE_TIME,LAST_UPDATE_TIME,LAST_UPDATE_USER from BLL_PRODUCT_BUILD "); strSql.Append(" where SLIP_NUMBER=@SLIP_NUMBER "); SqlParameter[] parameters = { new SqlParameter("@SLIP_NUMBER", SqlDbType.VarChar, 50) }; parameters[0].Value = SLIP_NUMBER; BllProductBuildTable PBModel = new BllProductBuildTable(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { PBModel.SLIP_NUMBER = ds.Tables[0].Rows[0]["SLIP_NUMBER"].ToString(); PBModel.WAREHOUSE_CODE = ds.Tables[0].Rows[0]["WAREHOUSE_CODE"].ToString(); PBModel.PRODUCT_CODE = ds.Tables[0].Rows[0]["PRODUCT_CODE"].ToString(); if (ds.Tables[0].Rows[0]["QUANTITY"].ToString() != "") { PBModel.QUANTITY = decimal.Parse(ds.Tables[0].Rows[0]["QUANTITY"].ToString()); } if (ds.Tables[0].Rows[0]["BUILD_DATE"].ToString() != "") { PBModel.BUILD_DATE = DateTime.Parse(ds.Tables[0].Rows[0]["BUILD_DATE"].ToString()); } PBModel.COMPANY_CODE = ds.Tables[0].Rows[0]["COMPANY_CODE"].ToString(); PBModel.UNIT_CODE = ds.Tables[0].Rows[0]["UNIT_CODE"].ToString(); if (ds.Tables[0].Rows[0]["STATUS_FLAG"].ToString() != "") { PBModel.STATUS_FLAG = int.Parse(ds.Tables[0].Rows[0]["STATUS_FLAG"].ToString()); } PBModel.CREATE_USER = ds.Tables[0].Rows[0]["CREATE_USER"].ToString(); if (ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString() != "") { PBModel.CREATE_DATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_DATE_TIME"].ToString()); } if (ds.Tables[0].Rows[0]["LAST_UPDATE_TIME"].ToString() != "") { PBModel.LAST_UPDATE_TIME = DateTime.Parse(ds.Tables[0].Rows[0]["LAST_UPDATE_TIME"].ToString()); } PBModel.LAST_UPDATE_USER = ds.Tables[0].Rows[0]["LAST_UPDATE_USER"].ToString(); strSql = new StringBuilder(); strSql.Append("select SLIP_NUMBER,LINE_NUMBER,PRODUCT_PARTS_CODE,PARTS_QUANTITY,UNIT_CODE,STATUS_FLAG from BLL_PRODUCT_BUILD_LINE "); strSql.Append(" where SLIP_NUMBER=@SLIP_NUMBER "); SqlParameter[] lineParam = { new SqlParameter("@SLIP_NUMBER", SqlDbType.VarChar, 50) }; lineParam[0].Value = SLIP_NUMBER; ds = DbHelperSQL.Query(strSql.ToString(), lineParam); BllProductBuildLineTable LModel = null; foreach (DataRow row in ds.Tables[0].Rows) { LModel = new BllProductBuildLineTable(); LModel.SLIP_NUMBER = row["SLIP_NUMBER"].ToString(); LModel.LINE_NUMBER = CConvert.ToInt32(row["LINE_NUMBER"]); LModel.PRODUCT_PARTS_CODE = row["PRODUCT_PARTS_CODE"].ToString(); LModel.PARTS_QUANTITY = CConvert.ToDecimal(row["PARTS_QUANTITY"].ToString()); LModel.UNIT_CODE = row["UNIT_CODE"].ToString(); LModel.STATUS_FLAG = CConvert.ToInt32(row["STATUS_FLAG"].ToString()); if (LModel.SLIP_NUMBER != null) { PBModel.AddItem(LModel); } } return(PBModel); } else { return(null); } }
public int AddRelieve(BllProductBuildTable PBModel) { int i = 0; int result = 0; while (i < 10) { try { List <CommandInfo> listSql = new List <CommandInfo>(); StringBuilder strSql = null; strSql = new StringBuilder(); strSql.Append("insert into BLL_PRODUCT_BUILD("); strSql.Append("SLIP_NUMBER,WAREHOUSE_CODE,PRODUCT_CODE,QUANTITY,BUILD_DATE,COMPANY_CODE,UNIT_CODE,STATUS_FLAG,CREATE_USER,CREATE_DATE_TIME,LAST_UPDATE_TIME,LAST_UPDATE_USER)"); strSql.Append(" values ("); strSql.Append("@SLIP_NUMBER,@WAREHOUSE_CODE,@PRODUCT_CODE,@QUANTITY,@BUILD_DATE,@COMPANY_CODE,@UNIT_CODE,@STATUS_FLAG,@CREATE_USER,GETDATE(),GETDATE(),@LAST_UPDATE_USER)"); SqlParameter[] buildParam = { new SqlParameter("@SLIP_NUMBER", SqlDbType.VarChar, 20), new SqlParameter("@WAREHOUSE_CODE", SqlDbType.VarChar, 20), new SqlParameter("@PRODUCT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@QUANTITY", SqlDbType.Decimal, 9), new SqlParameter("@BUILD_DATE", SqlDbType.DateTime), new SqlParameter("@COMPANY_CODE", SqlDbType.VarChar, 20), new SqlParameter("@UNIT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@CREATE_USER", SqlDbType.VarChar, 20), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; buildParam[0].Value = PBModel.SLIP_NUMBER; buildParam[1].Value = PBModel.WAREHOUSE_CODE; buildParam[2].Value = PBModel.PRODUCT_CODE; buildParam[3].Value = PBModel.QUANTITY; buildParam[4].Value = PBModel.BUILD_DATE; buildParam[5].Value = PBModel.COMPANY_CODE; buildParam[6].Value = PBModel.UNIT_CODE; buildParam[7].Value = PBModel.STATUS_FLAG; buildParam[8].Value = PBModel.CREATE_USER; buildParam[9].Value = PBModel.LAST_UPDATE_USER; listSql.Add(new CommandInfo(strSql.ToString(), buildParam)); //库存中组成品数量的减少 strSql = new StringBuilder(); strSql.Append("update BASE_STOCK set "); strSql.Append("QUANTITY=QUANTITY - @QUANTITY,"); strSql.Append("LAST_UPDATE_TIME=GETDATE(),"); strSql.Append("LAST_UPDATE_USER=@LAST_UPDATE_USER"); strSql.Append(" where WAREHOUSE_CODE=@WAREHOUSE_CODE and PRODUCT_CODE=@PRODUCT_CODE "); SqlParameter[] minusParam = { new SqlParameter("@WAREHOUSE_CODE", SqlDbType.VarChar, 20), new SqlParameter("@PRODUCT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@QUANTITY", SqlDbType.Decimal, 9), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; minusParam[0].Value = PBModel.WAREHOUSE_CODE; minusParam[1].Value = PBModel.PRODUCT_CODE; minusParam[2].Value = PBModel.QUANTITY; minusParam[3].Value = PBModel.LAST_UPDATE_USER; listSql.Add(new CommandInfo(strSql.ToString(), minusParam)); foreach (BllProductBuildLineTable PBLModel in PBModel.Items) { strSql = new StringBuilder(); strSql.Append("insert into BLL_PRODUCT_BUILD_LINE("); strSql.Append("SLIP_NUMBER,LINE_NUMBER,PRODUCT_PARTS_CODE,PARTS_QUANTITY,UNIT_CODE,STATUS_FLAG)"); strSql.Append(" values ("); strSql.Append("@SLIP_NUMBER,@LINE_NUMBER,@PRODUCT_PARTS_CODE,@PARTS_QUANTITY,@UNIT_CODE,@STATUS_FLAG)"); SqlParameter[] BLParam = { new SqlParameter("@SLIP_NUMBER", SqlDbType.VarChar, 20), new SqlParameter("@LINE_NUMBER", SqlDbType.Int, 4), new SqlParameter("@PRODUCT_PARTS_CODE", SqlDbType.VarChar, 20), new SqlParameter("@PARTS_QUANTITY", SqlDbType.Decimal, 9), new SqlParameter("@UNIT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4) }; BLParam[0].Value = PBLModel.SLIP_NUMBER; BLParam[1].Value = PBLModel.LINE_NUMBER; BLParam[2].Value = PBLModel.PRODUCT_PARTS_CODE; BLParam[3].Value = PBLModel.PARTS_QUANTITY; BLParam[4].Value = PBLModel.UNIT_CODE; BLParam[5].Value = PBLModel.STATUS_FLAG; listSql.Add(new CommandInfo(strSql.ToString(), BLParam)); if (Existstock(PBModel.WAREHOUSE_CODE, PBLModel.PRODUCT_PARTS_CODE)) { //库存中材料商品数量的增加 strSql = new StringBuilder(); strSql.Append("update BASE_STOCK set "); strSql.Append("QUANTITY=QUANTITY + @QUANTITY,"); strSql.Append("LAST_UPDATE_TIME=GETDATE(),"); strSql.Append("LAST_UPDATE_USER=@LAST_UPDATE_USER"); strSql.Append(" where WAREHOUSE_CODE=@WAREHOUSE_CODE and PRODUCT_CODE=@PRODUCT_CODE "); SqlParameter[] addParam = { new SqlParameter("@WAREHOUSE_CODE", SqlDbType.VarChar, 20), new SqlParameter("@PRODUCT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@QUANTITY", SqlDbType.Decimal, 9), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; addParam[0].Value = PBModel.WAREHOUSE_CODE; addParam[1].Value = PBLModel.PRODUCT_PARTS_CODE; addParam[2].Value = PBLModel.PARTS_QUANTITY; addParam[3].Value = PBModel.LAST_UPDATE_USER; listSql.Add(new CommandInfo(strSql.ToString(), addParam)); } else { strSql = new StringBuilder(); strSql.Append("insert into BASE_STOCK("); strSql.Append("WAREHOUSE_CODE,PRODUCT_CODE,UNIT_CODE,QUANTITY,STATUS_FLAG,CREATE_USER,CREATE_DATE_TIME,LAST_UPDATE_TIME,LAST_UPDATE_USER)"); strSql.Append(" values ("); strSql.Append("@WAREHOUSE_CODE,@PRODUCT_CODE,@UNIT_CODE,@QUANTITY,@STATUS_FLAG,@CREATE_USER,GETDATE(),GETDATE(),@LAST_UPDATE_USER)"); SqlParameter[] stockParam = { new SqlParameter("@WAREHOUSE_CODE", SqlDbType.VarChar, 20), new SqlParameter("@PRODUCT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@UNIT_CODE", SqlDbType.VarChar, 20), new SqlParameter("@QUANTITY", SqlDbType.Decimal, 9), new SqlParameter("@STATUS_FLAG", SqlDbType.Int, 4), new SqlParameter("@CREATE_USER", SqlDbType.VarChar, 20), new SqlParameter("@LAST_UPDATE_USER", SqlDbType.VarChar, 20) }; stockParam[0].Value = PBModel.WAREHOUSE_CODE; stockParam[1].Value = PBLModel.PRODUCT_PARTS_CODE; stockParam[2].Value = PBLModel.UNIT_CODE; stockParam[3].Value = PBLModel.PARTS_QUANTITY; stockParam[4].Value = CConstant.INIT; stockParam[5].Value = PBModel.CREATE_USER; stockParam[6].Value = PBModel.LAST_UPDATE_USER; listSql.Add(new CommandInfo(strSql.ToString(), stockParam)); } } result = DbHelperSQL.ExecuteSqlTran(listSql); } catch (SqlException ex) { if (i != 9) { int maxLlipNumber = CConvert.ToInt32(GetBuildMaxSlipNumber()) + 1; PBModel.SLIP_NUMBER = maxLlipNumber.ToString().PadLeft(4, '0'); i++; continue; } } break; } return(result); }
private void btnRelieve_Click(object sender, EventArgs e) { if (RelieveCheck()) { BllProductBuildTable PBModel = new BllProductBuildTable(); BllProductBuildLineTable PBLModel = null; int i = 1; PBModel.SLIP_NUMBER = CConvert.ToString(CConvert.ToInt32(bProductBuild.GetBuildMaxSlipNumber()) + 1).PadLeft(4, '0'); BaseProductTable product = bProduct.GetModel(txtProduct.Text.Trim()); PBModel.PRODUCT_CODE = txtProduct.Text.Trim(); PBModel.WAREHOUSE_CODE = txtWarehouse.Text.Trim(); PBModel.QUANTITY = CConvert.ToDecimal(txtRelieveQuantity.Text.Trim()); PBModel.COMPANY_CODE = _userInfo.COMPANY_CODE; PBModel.BUILD_DATE = txtSlipDate.Value; BaseStockTable stock = new BaseStockTable(); stock = bPurchaseOrder.GetStockModel(txtWarehouse.Text.Trim(), txtProduct.Text.Trim()); PBModel.UNIT_CODE = stock.UNIT_CODE; PBModel.STATUS_FLAG = CConstant.RELIEVE_STATUS; PBModel.CREATE_USER = _userInfo.CODE; PBModel.LAST_UPDATE_USER = _userInfo.CODE; DataSet ds = bProductBuild.getParts(txtProduct.Text.Trim()); foreach (DataRow row in ds.Tables[0].Rows) { PBLModel = new BllProductBuildLineTable(); PBLModel.SLIP_NUMBER = PBModel.SLIP_NUMBER; PBLModel.LINE_NUMBER = i; PBLModel.PRODUCT_PARTS_CODE = CConvert.ToString(row["PRODUCT_PART_CODE"]); PBLModel.PARTS_QUANTITY = CConvert.ToDecimal(row["QUANTITY"]) * PBModel.QUANTITY; BaseStockTable stock1 = new BaseStockTable(); stock1 = bPurchaseOrder.GetStockModel(txtWarehouse.Text.Trim(), PBLModel.PRODUCT_PARTS_CODE); PBLModel.UNIT_CODE = stock1.UNIT_CODE; PBLModel.STATUS_FLAG = CConstant.INIT_STATUS; if (PBLModel.SLIP_NUMBER != null) { PBModel.AddItem(PBLModel); } i++; } int result = 0; try { result = bProductBuild.AddRelieve(PBModel); if (result <= 0) { string errorLog = "解除失败,请重试或与管理员联系."; MessageBox.Show(errorLog, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { txtWarehouse.Text = ""; txtWarehouseName.Text = ""; txtProduct.Text = ""; txtProductName.Text = ""; txtNoAlloation.Text = ""; txtRelieveQuantity.Text = ""; txtSlipDate.Value = DateTime.Now; MessageBox.Show("保存成功", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("保存失败,系统错误,请与管理员联系.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); Logger.Error("组成失败!", ex); } } }
public int AddRelieve(BllProductBuildTable PBModel) { return(dal.AddRelieve(PBModel)); }
public int AddBuild(BllProductBuildTable PBModel) { return(dal.AddBuild(PBModel)); }
public void OperateInit(int currentPage) { BllProductBuildTable PBModel = bProductBuild.GetModel(_slip_number); txtWarehouse.Text = PBModel.WAREHOUSE_CODE; txtWarehouseName.Text = bCommon.GetBaseMaster("WAREHOUSE", PBModel.WAREHOUSE_CODE).Name; txtProduct.Text = PBModel.PRODUCT_CODE; txtProductName.Text = bCommon.GetBaseMaster("PRODUCT", PBModel.PRODUCT_CODE).Name; txtQuantity.Text = CConvert.ToString(PBModel.QUANTITY); txtPossibleQuantity.Text = CConvert.ToString(PBModel.QUANTITY); txtFormDate.Value = PBModel.BUILD_DATE; dgvData.Rows.Clear(); //foreach (BllProductBuildLineTable LModel in PBModel.Items) //{ // int currentRowIndex = dgvData.Rows.Add(1); // DataGridViewRow row = dgvData.Rows[currentRowIndex]; // row.Cells[1].Selected = false; // row.Cells["No"].Value = LModel.LINE_NUMBER; // row.Cells["PARTS_CODE"].Value = LModel.PRODUCT_PARTS_CODE; // BaseProductTable product = new BaseProductTable(); // BProduct bProduct = new BProduct(); // product = bProduct.GetModel(LModel.PRODUCT_PARTS_CODE); // row.Cells["PARTS_NAME"].Value = product.NAME; // row.Cells["SPEC"].Value = product.SPEC; // BAlloation bAlloation = new BAlloation(); // decimal alloationQuantity = bAlloation.GetAlloationQuantity(PBModel.WAREHOUSE_CODE, LModel.PRODUCT_PARTS_CODE); // BaseStockTable stock = new BaseStockTable(); // stock = bPurchaseOrder.GetStockModel(PBModel.WAREHOUSE_CODE, LModel.PRODUCT_PARTS_CODE); // row.Cells["NO_ALLOATION"].Value = stock.QUANTITY - alloationQuantity; // row.Cells["UNIT_CODE"].Value = PBModel.UNIT_CODE; // row.Cells["UNIT_NAME"].Value = bCommon.GetBaseMaster("UNIT", PBModel.UNIT_CODE).Name; // row.Cells["PURCHASE_QUANTITY"].Value = LModel.PARTS_QUANTITY; // row.Cells["STATUE_FLAG"].Value = "OK"; //} for (int i = (currentPage - 1) * PageSize + 1; i <= PBModel.Items.Count && (i - (currentPage - 1) * PageSize) < PageSize; i++) { int currentRowIndex = dgvData.Rows.Add(1); DataGridViewRow row = dgvData.Rows[currentRowIndex]; row.Cells[1].Selected = false; row.Cells["No"].Value = PBModel.Items[i - 1].LINE_NUMBER; row.Cells["PARTS_CODE"].Value = PBModel.Items[i - 1].PRODUCT_PARTS_CODE; row.Cells["MIN_QUANTITY"].Value = PBModel.Items[i - 1].PARTS_QUANTITY / PBModel.QUANTITY; BaseProductTable product = new BaseProductTable(); BProduct bProduct = new BProduct(); product = bProduct.GetModel(PBModel.Items[i - 1].PRODUCT_PARTS_CODE); row.Cells["PARTS_NAME"].Value = product.NAME; row.Cells["SPEC"].Value = product.SPEC; BAlloation bAlloation = new BAlloation(); decimal alloationQuantity = bAlloation.GetAlloationQuantity(PBModel.WAREHOUSE_CODE, PBModel.Items[i - 1].PRODUCT_PARTS_CODE); BaseStockTable stock = new BaseStockTable(); stock = bPurchaseOrder.GetStockModel(PBModel.WAREHOUSE_CODE, PBModel.Items[i - 1].PRODUCT_PARTS_CODE); row.Cells["NO_ALLOATION"].Value = stock.QUANTITY - alloationQuantity; row.Cells["UNIT_CODE"].Value = PBModel.UNIT_CODE; row.Cells["UNIT_NAME"].Value = bCommon.GetBaseMaster("UNIT", PBModel.UNIT_CODE).Name; row.Cells["PURCHASE_QUANTITY"].Value = PBModel.Items[i - 1].PARTS_QUANTITY; row.Cells["STATUE_FLAG"].Value = "OK"; } if (PBModel.Items.Count < PageSize * currentPage) { dgvData.Rows.Add(PageSize - PBModel.Items.Count); } }
private void btnSave_Click(object sender, EventArgs e) { if (isSearch) { if (saveCheck()) { BllProductBuildTable PBModel = new BllProductBuildTable(); BllProductBuildLineTable PBLModel = null; //组成编号 PBModel.SLIP_NUMBER = CConvert.ToString(CConvert.ToInt32(bProductBuild.GetBuildMaxSlipNumber()) + 1).PadLeft(4, '0'); //仓库 PBModel.WAREHOUSE_CODE = txtWarehouse.Text.Trim(); PBModel.PRODUCT_CODE = txtProduct.Text.Trim(); PBModel.QUANTITY = CConvert.ToDecimal(txtQuantity.Text.Trim()); PBModel.BUILD_DATE = txtFormDate.Value; PBModel.COMPANY_CODE = _userInfo.COMPANY_CODE; BaseStockTable stock = new BaseStockTable(); stock = bPurchaseOrder.GetStockModel(txtWarehouse.Text.Trim(), txtProduct.Text.Trim()); PBModel.UNIT_CODE = stock.UNIT_CODE; PBModel.STATUS_FLAG = CConstant.BUILD_STATUS; PBModel.CREATE_USER = _userInfo.CODE; PBModel.LAST_UPDATE_USER = _userInfo.CODE; foreach (DataGridViewRow row in dgvData.Rows) { if (row.Cells["PARTS_CODE"].Value != null) { PBLModel = new BllProductBuildLineTable(); PBLModel.SLIP_NUMBER = PBModel.SLIP_NUMBER; PBLModel.LINE_NUMBER = row.Index + 1; PBLModel.PRODUCT_PARTS_CODE = CConvert.ToString(row.Cells["PARTS_CODE"].Value); PBLModel.PARTS_QUANTITY = CConvert.ToDecimal(row.Cells["MIN_QUANTITY"].Value) * PBModel.QUANTITY; PBLModel.UNIT_CODE = CConvert.ToString(row.Cells["UNIT_CODE"].Value); PBLModel.STATUS_FLAG = CConstant.INIT; if (PBLModel.SLIP_NUMBER != null) { PBModel.AddItem(PBLModel); } } } int result = 0; try { result = bProductBuild.AddBuild(PBModel); if (result <= 0) { string errorLog = "保存失败,请重试或与管理员联系."; MessageBox.Show(errorLog, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } else { dgvData.Rows.Clear(); init(); txtWarehouse.Text = ""; txtWarehouseName.Text = ""; txtProduct.Text = ""; txtProductName.Text = ""; txtQuantity.Text = ""; txtPossibleQuantity.Text = ""; txtFormDate.Value = DateTime.Now; MessageBox.Show("保存成功", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("保存失败,系统错误,请与管理员联系.", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information); Logger.Error("组成失败!", ex); } } } }