/// <summary> /// 自动生成拣货计划 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnPlan_click(object sender, EventArgs e) { UStockBB stockBB = new UStockBB(); CStockUpBillBB stockUpBillBB = new CStockUpBillBB(); CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB(); LMaterialRelationBB materialRelationBB = new LMaterialRelationBB(); CSaleDetailBB saleDetailBB = new CSaleDetailBB(); LMaterialBB materialBB = new LMaterialBB(); try { CStockUpBillData stockUpBillModel = new CStockUpBillData(); DataSet dsStock = new DataSet(); DataSet dsStockUpDetail = new DataSet(); DataRow[] drsStock = null; string strInfo = ""; stockUpBillModel = stockUpBillBB.GetModel(this.IdValue);//销售备货单实例 #region 生成按单的拣货信息 //如果是按单,则直接查找按单采购物料 //dsStock = stockBB.GetVListByGroup("(saleBillNo in ('" + stockUpBillModel.saleBillNos.Replace(",", "','") // + "') or substring(financeBillNo,1,charindex('-',financeBillNo)) like '%" // + this.hidCustNo.Value + "%') and isOutStocking=0 and wareLocatorNo<>''"); //如果是按单,则直接查找按单采购物料 dsStock = stockBB.GetVListByGroup_ByFinanceBillNo("(stock.saleBillNo in ('" + stockUpBillModel.saleBillNos.Replace(",", "','") + "') or '," + stockUpBillModel.financeBillNos + ",' like '%,'+stock.financeBillNo+',%') and stock.financeBillSortNo='01' and stock.isOutStocking=0 and stock.wareLocatorNo<>''"); //获取定向的备货单明细 dsStockUpDetail = stockUpDetailBB.GetMaterielVList("stockUpBillNo='" + stockUpBillModel.stockUpBillNo + "' and financeBillSort='按单'");//and isnull(financeBillNo,'')<>'' if (dsStock.Tables[0].Rows.Count > 0) { foreach (DataRow drStockUpDetail in dsStockUpDetail.Tables[0].Rows) { //备货单明细合计出来的某种物料总数量 int needCount = Convert.ToInt32(drStockUpDetail["num"]); string strMaterialNo = drStockUpDetail["materialno"].ToString();//物料号 string strFinanceBillNo = drStockUpDetail["financeBillNo"].ToString(); //string strFinanceBillSort = drStockUpDetail["financeBillSort"].ToString(); string strFinanceBillSort = "按单"; string strDocEntry = drStockUpDetail["docEntry"].ToString();//销售订单ID string strSaleBillNo = drStockUpDetail["saleBillNo"].ToString();//销售订单号 string strLineNum = drStockUpDetail["lineNum"].ToString();//行号 string strAbsEntry = drStockUpDetail["absEntry"].ToString();//提货单编号 #region 按单的需原物料拣货 while (needCount > 0) { //根据先进先出,尽量使用同一托盘原则 //找到仓库内的同种物料所在的库位以及数量 //首先查找不少于此需要物料数量的库位 drsStock = dsStock.Tables[0].Select("financeBillNo='" + strFinanceBillNo + "' and materialNo='" + strMaterialNo + "' and num>=" + needCount.ToString()); if (drsStock.Length == 0) { drsStock = dsStock.Tables[0].Select("financeBillNo='" + strFinanceBillNo + "' and materialNo='" + strMaterialNo + "' and num>0"); } if (drsStock.Length > 0) { //当前库位所拥有该物料的数量 int haveCount = Convert.ToInt32(drsStock[0]["num"]); //如果当前库位的物料数量大于备货单所需数量,就保存当前库位 DataRow drnew = this.DtResult.NewRow(); drnew["rowId"] = Guid.NewGuid().ToString(); drnew["id"] = 0; if (haveCount >= needCount) { drnew["num"] = needCount; } else { drnew["num"] = haveCount; } drsStock[0]["num"] = Convert.ToInt32(drsStock[0]["num"]) - Convert.ToInt32(drnew["num"]);//库存数量减去已备货数量 needCount = needCount - Convert.ToInt32(drnew["num"]); drnew["stockUpBillNo"] = stockUpBillModel.stockUpBillNo; drnew["palletIndex"] = drStockUpDetail["palletIndex"].ToString(); drnew["wareNo"] = drsStock[0]["wareNo"]; drnew["wareLocatorNo"] = drsStock[0]["wareLocatorNo"]; drnew["palletNo"] = drsStock[0]["palletNo"]; drnew["stockUpMaterialNo"] = strMaterialNo;//备货物料编号 drnew["materialNo"] = drsStock[0]["materialNo"];//实际拣货物料编号 drnew["wareNm"] = drsStock[0]["wareNm"]; drnew["wareLocatorNm"] = drsStock[0]["wareLocatorNm"]; drnew["materialDesc"] = drsStock[0]["materialDesc"]; drnew["financeBillNo"] = strFinanceBillNo;//采购合同号 drnew["financeBillSort"] = strFinanceBillSort;//采购合同类型 drnew["saleBillNo"] = strSaleBillNo;//销售订单号 drnew["docEntry"] = strDocEntry;//销售订单ID drnew["lineNum"] = strLineNum;//行号 drnew["absEntry"] = strAbsEntry;//提货单号 drnew["instantState"] = "01"; drnew["isDel"] = false; this.DtResult.Rows.Add(drnew); drStockUpDetail["num"] = needCount;//重新赋值拣货数量 } else { needCount = 0; } } #endregion 按单的需原物料拣货 } } #endregion 生成按单的拣货信息 #region 销售订单没有按单采购 //备货需要逐个库位查找 dsStock = stockBB.GetVListByGroup("stock.financeBillSortNo='02' and stock.isOutStocking=0 and stock.wareLocatorNo<>''"); //获取备货的备货单明细 dsStockUpDetail = stockUpDetailBB.GetMaterielVList("stockUpBillNo='" + stockUpBillModel.stockUpBillNo + "' and financeBillSort='备货'");//根据采购合同类型,不根据采购合同号判断 and (isnull(financeBillNo,'')='' if (dsStock.Tables[0].Rows.Count > 0) { foreach (DataRow drStockUpDetail in dsStockUpDetail.Tables[0].Rows) { //备货单明细合计出来的某种物料总数量 int needCount = Convert.ToInt32(drStockUpDetail["num"]); string strMaterialNo = drStockUpDetail["materialno"].ToString();//物料号 string strFinanceBillNo = ""; string strFinanceBillSort = "备货"; string strSaleBillNo = drStockUpDetail["saleBillNo"].ToString();//销售订单号 string strLineNum = drStockUpDetail["lineNum"].ToString();//行号 string strAbsEntry = drStockUpDetail["absEntry"].ToString();//提货单编号 string strDocEntry = drStockUpDetail["docEntry"].ToString();//销售订单ID while (needCount > 0) { #region 原物料拣货 //找到仓库内的同种物料所在的库位以及数量 drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo + "' and num>=" + needCount.ToString()); if (drsStock.Length == 0) { drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo + "' and num>0"); } if (drsStock.Length > 0) { //当前库位所拥有该物料的数量 int haveCount = Convert.ToInt32(drsStock[0]["num"]); //如果当前库位的物料数量大于备货单所需数量,就保存当前库位 DataRow drnew = this.DtResult.NewRow(); drnew["rowId"] = Guid.NewGuid().ToString(); drnew["id"] = 0; if (haveCount >= needCount) { drnew["num"] = needCount; } else { drnew["num"] = haveCount; } drsStock[0]["num"] = Convert.ToInt32(drsStock[0]["num"]) - Convert.ToInt32(drnew["num"]);//库存数量减去已备货数量 needCount = needCount - Convert.ToInt32(drnew["num"]); drnew["stockUpBillNo"] = stockUpBillModel.stockUpBillNo; drnew["palletIndex"] = drStockUpDetail["palletIndex"].ToString(); drnew["wareNo"] = drsStock[0]["wareNo"]; drnew["wareLocatorNo"] = drsStock[0]["wareLocatorNo"]; drnew["palletNo"] = drsStock[0]["palletNo"]; drnew["stockUpMaterialNo"] = strMaterialNo;//备货物料编号 drnew["materialNo"] = drsStock[0]["materialNo"];//实际拣货物料编号 drnew["wareNm"] = drsStock[0]["wareNm"]; drnew["wareLocatorNm"] = drsStock[0]["wareLocatorNm"]; drnew["materialDesc"] = drsStock[0]["materialDesc"]; drnew["instantState"] = "01"; drnew["financeBillNo"] = strFinanceBillNo;//采购合同号 drnew["financeBillSort"] = strFinanceBillSort;//采购合同类型 drnew["saleBillNo"] = strSaleBillNo;//销售订单号 drnew["docEntry"] = strDocEntry;//销售订单ID drnew["lineNum"] = strLineNum;//行号 drnew["absEntry"] = strAbsEntry;//提货单号 drnew["isDel"] = false; this.DtResult.Rows.Add(drnew); drStockUpDetail["num"] = needCount;//重新赋值拣货数量 } else { break; } #endregion 原物料拣货 } #region 根据物料对应关系拣货 while (needCount > 0) { //需要根据物料对应关系拣其他物料 DataTable dtConvertMaterial = new DataTable(); dtConvertMaterial = materialRelationBB.GetList("oldMaterialNo='" + strMaterialNo + "'").Tables[0]; if (dtConvertMaterial.Rows.Count == 0) { break; } foreach (DataRow row in dtConvertMaterial.Rows) { //找到仓库内的有对应关系物料所在的库位以及数量 drsStock = dsStock.Tables[0].Select("materialno='" + row["newMaterialNo"].ToString() + "' and num>=" + needCount.ToString()); if (drsStock.Length == 0) { drsStock = dsStock.Tables[0].Select("materialno='" + row["newMaterialNo"].ToString() + "' and num>0"); } if (drsStock.Length > 0) { //当前库位所拥有该物料的数量 int haveCount = Convert.ToInt32(drsStock[0]["num"]); //如果当前库位的物料数量大于备货单所需数量,就保存当前库位 DataRow drnew = this.DtResult.NewRow(); drnew["rowId"] = Guid.NewGuid().ToString(); drnew["id"] = 0; if (haveCount >= needCount) { drnew["num"] = needCount; } else { drnew["num"] = haveCount; } drsStock[0]["num"] = Convert.ToInt32(drsStock[0]["num"]) - Convert.ToInt32(drnew["num"]);//库存数量减去已备货数量 needCount = needCount - Convert.ToInt32(drnew["num"]); drnew["stockUpBillNo"] = stockUpBillModel.stockUpBillNo; drnew["palletIndex"] = drStockUpDetail["palletIndex"].ToString(); drnew["wareNo"] = drsStock[0]["wareNo"]; drnew["wareLocatorNo"] = drsStock[0]["wareLocatorNo"]; drnew["palletNo"] = drsStock[0]["palletNo"]; drnew["stockUpMaterialNo"] = strMaterialNo;//备货物料编号 drnew["materialNo"] = drsStock[0]["materialNo"];//实际拣货物料编号 drnew["wareNm"] = drsStock[0]["wareNm"]; drnew["wareLocatorNm"] = drsStock[0]["wareLocatorNm"]; drnew["materialDesc"] = drsStock[0]["materialDesc"]; drnew["instantState"] = "01"; drnew["financeBillNo"] = strFinanceBillNo;//采购合同号 drnew["financeBillSort"] = strFinanceBillSort;//采购合同类型 drnew["saleBillNo"] = strSaleBillNo;//销售订单号 drnew["docEntry"] = strDocEntry;//销售订单ID drnew["lineNum"] = strLineNum;//行号 drnew["absEntry"] = strAbsEntry;//提货单号 drnew["isDel"] = false; this.DtResult.Rows.Add(drnew); drStockUpDetail["num"] = needCount;//重新赋值拣货数量 } else { needCount = 0; break; } } } #endregion 根据物料对应关系拣货 } } #endregion 销售订单没有按单采购 #region 判断是否完全拣货 DataSet dsStockUpDetail_Temp = stockUpDetailBB.GetMaterielVList("stockUpBillNo='" + stockUpBillModel.stockUpBillNo + "'"); foreach (DataRow rowStockUpDetail in dsStockUpDetail_Temp.Tables[0].Rows) { int planNum = 0, factNum = 0; DataRow[] myDataRowArray = null; string strNewMaterialNo = ""; DataTable dtConvertMaterial = new DataTable(); //计算计划备货数量 myDataRowArray = dsStockUpDetail_Temp.Tables[0].Select("materialNo='" + rowStockUpDetail["materialNo"].ToString() + "'"); foreach (DataRow row in myDataRowArray) { planNum += Convert.ToInt32(row["num"]); } //计算原物料可拣货数量 //20140725 update //myDataRowArray = this.DtResult.Select("isDel=0 and materialNo='" // + rowStockUpDetail["materialNo"].ToString() + "'"); myDataRowArray = this.DtResult.Select("isDel=0 and materialNo=stockupmaterialNo and materialNo='" + rowStockUpDetail["materialNo"].ToString() + "'"); foreach (DataRow row in myDataRowArray) { factNum += Convert.ToInt32(row["num"]); } // 20140807 add if (planNum != factNum) { //获取转换物料的拣货数量 dtConvertMaterial = materialRelationBB.GetList("oldMaterialNo='" + rowStockUpDetail["materialNo"].ToString() + "'").Tables[0]; if (dtConvertMaterial.Rows.Count > 0) { // 20140725 update //strNewMaterialNo = dtConvertMaterial.Rows[0]["newMaterialNo"].ToString(); //myDataRowArray = this.DtResult.Select("isDel=0 and materialNo='" + strNewMaterialNo + "'"); strNewMaterialNo = dtConvertMaterial.Rows[0]["oldMaterialNo"].ToString(); myDataRowArray = this.DtResult.Select("isDel=0 and stockupmaterialNo='" + strNewMaterialNo + "' and materialNo<>stockupmaterialNo "); foreach (DataRow row in myDataRowArray) { factNum += Convert.ToInt32(row["num"]); } } } //判断是否完成拣货 if (planNum != factNum) { strInfo += "物料【" + rowStockUpDetail["materialNo"].ToString() + "】,计划拣货【" + planNum.ToString() + "】件,实际拣货【" + factNum.ToString() + "】件;"; } } if (strInfo != "") { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前未完成拣货,不允许保存!提示信息:" + strInfo + "\");", true); } #endregion 判断是否完全拣货 this.BindGridPickOutPlan();//绑定拣货计划列表 } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { stockBB.Dispose(); stockUpBillBB.Dispose(); stockUpDetailBB.Dispose(); materialRelationBB.Dispose(); saleDetailBB.Dispose(); materialBB.Dispose(); } }
/// <summary> /// 保存或保存并提交公用方法 /// </summary> /// <param name="isSubmit"></param> protected void SubmitArrangeBill(bool isSubmit) { //要保存之前判断状态是否被改变 CStockUpBillBB stockUpBillBB = new CStockUpBillBB(); string stockUpState = stockUpBillBB.GetVList("stockUpBillNo = '" + stockUpBillNo.Text.Trim() + "'").Tables[0].Rows[0]["instantState"].ToString(); stockUpBillNo.Dispose(); if (stockUpState != StockUpinstantState) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert12", "alert(\"拣货单已经被别人生成\");", true); return; } using (CPickOutPlanBC planBC = new CPickOutPlanBC()) { CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB(); LMaterialRelationBB materialRelationBB = new LMaterialRelationBB(); try { #region 判断是否完全拣货 DataSet dsStockUpDetail_Temp = stockUpDetailBB.GetMaterielVList("stockUpBillNo='" + this.stockUpBillNo.Text.Trim() + "'"); foreach (DataRow rowStockUpDetail in dsStockUpDetail_Temp.Tables[0].Rows) { int planNum = 0, factNum = 0; DataRow[] myDataRowArray = null; string strNewMaterialNo = ""; DataTable dtConvertMaterial = new DataTable(); //计算计划备货数量 myDataRowArray = dsStockUpDetail_Temp.Tables[0].Select("materialNo='" + rowStockUpDetail["materialNo"].ToString() + "'"); foreach (DataRow row in myDataRowArray) { planNum += Convert.ToInt32(row["num"]); } //计算原物料可拣货数量 //7月25号修改 //解决拣货单下发不下去的问题 //myDataRowArray = this.DtResult.Select("isDel=0 and materialNo='" // + rowStockUpDetail["materialNo"].ToString() + "'"); myDataRowArray = this.DtResult.Select("isDel=0 and materialNo=stockupmaterialNo and materialNo='" + rowStockUpDetail["materialNo"].ToString() + "'"); foreach (DataRow row in myDataRowArray) { factNum += Convert.ToInt32(row["num"]); } //获取转换物料的拣货数量 //20140807 add if (planNum != factNum) { dtConvertMaterial = materialRelationBB.GetList("oldMaterialNo='" + rowStockUpDetail["materialNo"].ToString() + "'").Tables[0]; if (dtConvertMaterial.Rows.Count > 0) { //7月25号修改 //解决拣货单下发不下去的问题 //strNewMaterialNo = dtConvertMaterial.Rows[0]["newMaterialNo"].ToString(); //myDataRowArray = this.DtResult.Select("isDel=0 and materialNo='" + strNewMaterialNo + "'"); strNewMaterialNo = dtConvertMaterial.Rows[0]["oldMaterialNo"].ToString(); myDataRowArray = this.DtResult.Select("isDel=0 and stockupmaterialNo='" + strNewMaterialNo + "' and materialNo<>stockupmaterialNo"); foreach (DataRow row in myDataRowArray) { factNum += Convert.ToInt32(row["num"]); } } } if (planNum != factNum) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前未完成拣货,不允许保存!\");", true); return; } } #endregion 判断是否完全拣货 planBC.EmpID = this.currentUser.empId; planBC.SavePickOutPlanBill(this.DtResult, this.stockUpBillNo.Text.Trim(), isSubmit); this.DtResult = null; this.InitDtPickOutPlan(); if (isSubmit)//保存并提交 { this.ClientScript.RegisterStartupScript(this.GetType(), "alert12", "alert(\"拣货单维护成功!\");window.location='" + Request.Params["backurl"] + "';", true); } else//保存 { this.ClientScript.RegisterStartupScript(this.GetType(), "alert12", "alert(\"拣货单维护成功!\");", true); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { stockUpDetailBB.Dispose(); materialRelationBB.Dispose(); } } }