/// <summary> /// 数据保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { string strInfo = ""; if (!this.ValidateData(out strInfo)) { strInfo = strInfo.Replace("\"", "'").Replace("\n", ""); this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + strInfo + "');", true); return; } LMaterialData model = new LMaterialData(); LMaterialBB materialBB = new LMaterialBB(); try { if (this.State == "1") { this.SetModel(ref model); model.isrtDt = DateTime.Now.ToString(); model.isrtEmpId = this.currentUser.empId; this.IdValue = materialBB.AddRecord(model); } else if (this.State == "2") { model = materialBB.GetModel(this.IdValue); this.SetModel(ref model); model.updtDt = DateTime.Now.ToString(); model.updtEmpId = this.currentUser.empId; materialBB.ModifyRecord(model); } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { materialBB.Dispose(); } Response.Redirect("LMaterialList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false); }
/// <summary> /// 验证排托明细数据 /// </summary> /// <returns></returns> public bool ValidateArrangeDetail() { string strCustomNo = "", strFinaceNo = "", strWareSortNo = ""; bool isSameCustom = true; DataRow[] myDataRowArrayResult = null; DataRow[] myDataRowArray = null; #region 校验排托结果 myDataRowArrayResult = this.DtResult.Select(" isdel=0"); if (myDataRowArrayResult.Length == 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('请首先排托!');", true); return false; } foreach (DataRow dr in myDataRowArrayResult) { for (int i = 0; i <= int.Parse(txtRegionNum.Text); i++) { int regionArrangeBoxNum = 0; DataRow[] myDataRowArrayRegion = this.DtResult.Select(" isdel=0 and palletIndex=" + dr["palletIndex"] + " and region=" + i); foreach (DataRow dataRow in myDataRowArrayRegion) { regionArrangeBoxNum += Convert.ToInt32(dataRow["boxNum"]); } if (regionArrangeBoxNum > int.Parse(txtMaxNum.Text)) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('托盘【" + dr["palletIndex"] + "】的【" + i.ToString() + "】区域排托箱数超出5箱!');", true); return false; } if (i == 0 && myDataRowArrayRegion.Length > 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('托盘区域不能包含0区域!');", true); return false; } else { //同一托盘同一区域只有一条记录 if (myDataRowArrayRegion.Length > 1) { strCustomNo = ""; isSameCustom = true; //判断订单类型是否为按单并且是同一个供应商 foreach (DataRow dataRow in myDataRowArrayRegion) { if (strCustomNo != "" && dataRow["customNo"].ToString() != strCustomNo) { isSameCustom = false; break; } if (dataRow["customNo"].ToString() != "") { strCustomNo = dataRow["customNo"].ToString();//客户编号 } } if (!isSameCustom) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('同一托盘同一区域必须合并!');", true); return false; } } } } //每个托盘每个区域只能有一条记录 DataRow[] drs = this.DtResult.Select(" isdel=0 and palletIndex='" + dr["palletIndex"] + "'"); if (drs.Length > 0) { strFinaceNo = drs[0]["financeBillNo"].ToString();//采购订单编号 strCustomNo = drs[0]["customNo"].ToString();//客户编号 strWareSortNo = drs[0]["wareSortNo"].ToString();//库位类别 } //if (drs.Length > 0 && drs.Length <= 8) //{ // strFinaceNo = drs[0]["financeBillNo"].ToString(); //} //else //{ // this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('每个托盘的区域数不能超过8个!');", true); // return false; //} foreach (DataRow d1 in drs) { //判断是否是同一个供应商 if (d1["financeBillNo"].ToString() != strFinaceNo) { if (strCustomNo != d1["customNo"].ToString() && strWareSortNo != d1["wareSortNo"].ToString()) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('同一托盘只能放置一个采购订单或相同类别库区物料!');", true); return false; } } if (Convert.ToInt32(d1["boxNum"]) <= 0 || Convert.ToInt32(d1["boxNum"]) > int.Parse(txtMaxNum.Text)) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('箱数请输入小于最大箱数的数据!');", true); return false; } if (Convert.ToInt32(d1["region"]) > int.Parse(txtRegionNum.Text) || Convert.ToInt32(d1["region"]) <= 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('区域数量需要小于最大区域!');", true); return false; } } } #endregion 校验排托结果 #region 校验到货明细 foreach (DataRow drn in DtDetail.Rows) { int arrangeBoxNum = 0; myDataRowArray = this.DtResult.Select(" isdel=0 and financeBillNo='" + drn["financeBillNo"] + "' and materialNo='" + drn["materialNo"] + "'"); foreach (DataRow dataRow in myDataRowArray) { arrangeBoxNum += Convert.ToInt32(dataRow["boxNum"]); } //判断排托数量是否超出到货数量 if (arrangeBoxNum != Convert.ToInt32(drn["boxNum"])) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"采购订单【" + drn["financeBillNo"] + "】的物料【" + drn["materialNo"] + "】到货数量为【" + drn["boxNum"].ToString() + "】,排托数量为【" + arrangeBoxNum.ToString() + "】,排托数量与到货数量不相符!\");", true); return false; } if (drn["financeBillSort"].ToString() == "备货")//备货 { LMaterialBB lMaterialBB = new LMaterialBB(); try { LMaterialData lMaterialData = lMaterialBB.GetModel(drn["materialNo"].ToString()); if ((lMaterialData.wareSortNo == "B" || lMaterialData.wareSortNo == "C")) { DataRow[] drns = this.DtResult.Select(" isdel=0 and financeBillNo='" + drn["financeBillNo"] + "' and materialNo='" + drn["materialNo"] + "'"); foreach (DataRow drns1 in drns) { DataRow[] drnss = this.DtResult.Select(" isdel=0 and palletIndex=" + drns1["palletIndex"] + " and materialNo<>'" + drn["materialNo"].ToString() + "'"); if (drnss.Length > 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"放置高位货架托盘只允许放置同一种备货物料!\");", true); return false; } } } else if ((lMaterialData.wareSortNo == "A" || lMaterialData.wareSortNo == "D" || lMaterialData.wareSortNo == "E")) { DataRow[] drns = this.DtResult.Select(" isdel=0 and financeBillNo='" + drn["financeBillNo"] + "' and materialNo='" + drn["materialNo"] + "'"); foreach (DataRow drns1 in drns) { DataRow[] drnss = this.DtResult.Select(" isdel=0 and palletIndex=" + drns1["palletIndex"] + " and wareSortNo<>'" + drn["wareSortNo"].ToString() + "'"); if (drnss.Length > 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"只允许放置同一仓库类别的备货物料!\");", true); return false; } } } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return false; } finally { lMaterialBB.Dispose(); } } } #endregion 校验到货明细 return true; }
/// <summary> /// 新增区域 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnNewArea_Click(object sender, EventArgs e) { try { this.SaveStencilDetailViewState();//保存 bool isChecked = false; foreach (GridViewRow gvrow in this.grid.Rows) { CheckBox chkId = (CheckBox)gvrow.FindControl("chkId"); DataRow[] myDataRowArray = null; if (chkId.Checked == true) { isChecked = true; //所选采购订单信息 string materialNo = this.grid.DataKeys[gvrow.RowIndex].Values["materialNo"].ToString(); string lfinanceBillNo = this.grid.DataKeys[gvrow.RowIndex].Values["financeBillNo"].ToString(); string lCustomNo = this.grid.DataKeys[gvrow.RowIndex].Values["customNo"].ToString(); string lmaterialDesc = this.grid.DataKeys[gvrow.RowIndex].Values["materialDesc"].ToString(); string financeBillSort = this.grid.DataKeys[gvrow.RowIndex].Values["financeBillSort"].ToString(); string wareSortNo = this.grid.DataKeys[gvrow.RowIndex].Values["wareSortNo"].ToString(); string strWareSortNm = this.grid.DataKeys[gvrow.RowIndex].Values["wareSortNm"].ToString(); //判断物料是否有剩余 myDataRowArray = this.DtDetail.Select("financeBillNo='" + this.grid.DataKeys[gvrow.RowIndex].Values["financeBillNo"].ToString() + "' and materialNo='" + this.grid.DataKeys[gvrow.RowIndex].Values["materialNo"].ToString() + "'"); if (myDataRowArray.Length > 0) { if (myDataRowArray[0]["arrangeBoxNum_leaving"].ToString() == "" || myDataRowArray[0]["arrangeBoxNum_leaving"].ToString() == "0") { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此物料已经没有剩余!\");", true); return; } } foreach (GridViewRow grow in this.gridDetail.Rows) { CheckBox chkId1 = (CheckBox)grow.FindControl("chkId"); if (chkId1.Checked == true) { string arriveBillNo = this.gridDetail.DataKeys[grow.RowIndex].Values["arriveBillNo"].ToString(); string financeBillNo = this.gridDetail.DataKeys[grow.RowIndex].Values["financeBillNo"].ToString(); string preMaterialNo = this.gridDetail.DataKeys[grow.RowIndex].Values["materialNo"].ToString(); string pindex = this.gridDetail.DataKeys[grow.RowIndex].Values["palletIndex"].ToString(); string pwareSortNo = this.gridDetail.DataKeys[grow.RowIndex].Values["wareSortNo"].ToString(); string strCustomNo = this.gridDetail.DataKeys[grow.RowIndex].Values["customNo"].ToString(); if (strCustomNo != lCustomNo && financeBillNo != lfinanceBillNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"同一托盘只允许放置同一采购订单或同一客户订单物料!\");", true); return; } LMaterialBB materialBB = new LMaterialBB(); try { LMaterialData materialModel = new LMaterialData(); //判断当前选择物料的货位分类 materialModel = materialBB.GetModel(materialNo); if (financeBillSort == "备货" && (materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C") && materialNo != preMaterialNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"放置高位货架托盘只允许放置同一种备货物料!\");", true); return; } else if (financeBillSort == "备货" && (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D" || materialModel.wareSortNo == "E") && pwareSortNo != wareSortNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此托盘只允许放置同一仓库类别的备货物料!\");", true); return; } //判断上一次选择物料的货位分类 materialModel = materialBB.GetModel(preMaterialNo); if (financeBillSort == "备货" && (materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C") && materialNo != preMaterialNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"放置高位货架托盘只允许放置同一种备货物料!\");", true); return; } else if (financeBillSort == "备货" && (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D" || materialModel.wareSortNo == "E") && pwareSortNo != wareSortNo) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此托盘只允许放置同一仓库类别的备货物料!\");", true); return; } } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { materialBB.Dispose(); } //求出最大的托盘序号 int maxnum = 1; DataRow[] drs = DtResult.Select(" isdel=0 and palletIndex=" + pindex, "region"); for (int i = 0; i < drs.Length; i++) { if (Convert.ToInt32(drs[i]["region"]) > maxnum) { break; } maxnum++; } if (maxnum > int.Parse(txtRegionNum.Text.Trim())) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"区域必须小于等于设定的托盘区域!\");", true); return; } //记录添加到临时表 DataRow dr = this.DtResult.NewRow(); dr["wareSortNo"] = wareSortNo; dr["wareSortNm"] = strWareSortNm; dr["rowId"] = Guid.NewGuid().ToString(); dr["isdel"] = "0"; dr["id"] = 0; dr["boxNum"] = 0; dr["hideAmount"] = 0; dr["ischeck"] = false; dr["arrangeBillNo"] = "PT" + this.ArriveBillNo; dr["arriveBillNo"] = arriveBillNo; dr["materialDesc"] = lmaterialDesc; dr["financeBillNo"] = lfinanceBillNo; dr["materialNo"] = materialNo; dr["region"] = maxnum; dr["palletIndex"] = pindex;//托盘序号 dr["customNo"] = lCustomNo;//客户编号 this.DtResult.Rows.Add(dr); } } } } if (isChecked == false) { this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"请选择采购物料和托盘记录!\");", true); return; } } finally { this.BindDetailTable();//绑定排托明细列表 this.BindGrid();//绑定到货明细列表 } }
/// <summary> /// 自动排托 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAutoArrange_Click(object sender, EventArgs e) { //2015-10-21 董利特修改 //首先用自动排托的功能进行测试 int maxManualRegion = int.Parse(txtRegionNum.Text.Trim()); int maxManualNum = int.Parse(txtMaxNum.Text.Trim()); LMaterialBB materialBB = new LMaterialBB(); try { if (this.DtDetail == null || this.DtDetail.Rows.Count <= 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "AutoArrange", "alert(\"该到货单没有任何明细,无法自动排拖!\");", true); } //判断是否已经生成排托明细 if (this.DtResult.Rows.Count > 0) { this.ClientScript.RegisterStartupScript(this.GetType(), "AutoArrange", "alert(\"该到货单已经生成排托明细,无法自动排拖!\");", true); return; } LMaterialData materialModel = new LMaterialData(); DataView dvArriveDetail = this.DtDetail.DefaultView; dvArriveDetail.Sort = "financeBillSort,wareSortNo,financeBillNo,materialNo";//customNo //遍历所有到货单的所有物料 foreach (DataRow drArriveDetail in dvArriveDetail.ToTable().Rows) { //非标准箱不予排拖 //if (drArriveDetail["isStandardBox"].ToString() == "0" // || drArriveDetail["isStandardBox"].ToString().Trim() == "N" // || drArriveDetail["isStandardBox"].ToString().Trim() == "") //{ // continue; //} if (drArriveDetail["isStandardBox"].ToString().Trim() == "N" || drArriveDetail["isStandardBox"].ToString().Trim() == "") { continue; } int leavingNum = Convert.ToInt32(drArriveDetail["arrangeBoxNum_leaving"]);//到货单明细剩余未排数量 int maxPalletIndex = 0;//最大托盘序号 //int empty = 5;//区域空余数量 int empty = maxManualNum; int maxRegion = 1;//区域 bool isNewPallet = true;//是否需要新托盘 DataView dvResult = null; //采购订单类型 备货 if (drArriveDetail["financeBillSort"].ToString() == "备货") { #region 备货订单排托 materialModel = materialBB.GetModel(drArriveDetail["materialNo"].ToString()); //物料放置高位货架的 if ((materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C")) { #region 物料放置高位货架的,相同物料进行排托 dvResult = this.DtResult.DefaultView; dvResult.Sort = "wareSortNo,materialNo,palletIndex"; dvResult.RowFilter = "isdel=0 and arriveBillNo='" + drArriveDetail["arriveBillNo"] + "' and wareSortNo='" + drArriveDetail["wareSortNo"].ToString() + "'" + " and materialNo='" + drArriveDetail["materialNo"] + "'"; #endregion 物料放置高位货架的,相同物料进行排托 } else if (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D" || materialModel.wareSortNo == "E") { #region 非高位货架 同一区域的排拖 dvResult = this.DtResult.DefaultView; dvResult.Sort = "wareSortNo,palletIndex"; dvResult.RowFilter = "isdel=0 and arriveBillNo='" + drArriveDetail["arriveBillNo"] + "' and wareSortNo='" + drArriveDetail["wareSortNo"].ToString() + "'"; #endregion 非高位货架 同一区域的排拖 } #endregion 备货订单排托 } else { #region 采购订单类型为按单 //找到当前采购订单 同一物料已经排拖的数据 //同一客户的不同采购订单的相同物料可以排在同一托盘 dvResult = this.DtResult.DefaultView; dvResult.Sort = "customNo,materialNo,financeBillNo,palletIndex,region"; dvResult.RowFilter = "isdel=0 and arriveBillNo='" + drArriveDetail["arriveBillNo"] + "' and ((isnull(customNo,'')<>'' and customNo='" + drArriveDetail["customNo"] + "') or (isnull(customNo,'')='' and financeBillNo='" + drArriveDetail["financeBillNo"] + "')) "; #endregion 采购订单类型为按单 } #region 查找有剩余位置的托盘 //找到同种采购订单,同种物料,有剩余位置的托盘 if (dvResult.ToTable() != null && dvResult.ToTable().Rows.Count > 0) { foreach (DataRow dr in dvResult.ToTable().Rows) { //遍历 同采购订单的同物料并且已经排拖的数据 ,找到 最大的托盘号,以及已经排拖的总数量 if (Convert.ToInt32(dr["palletIndex"]) > maxPalletIndex || Convert.ToInt32(dr["region"]) > maxRegion) { //获取当前订单,当前物料的最大托盘号(由于自动排拖,有空余位置的托盘,是最后一个托盘号) maxPalletIndex = Convert.ToInt32(dr["palletIndex"]); maxRegion = Convert.ToInt32(dr["region"]); } } //计算最后一个托盘的空余位置数量 DataRow[] drsLastRegion = this.DtResult.Select("palletIndex='" + maxPalletIndex.ToString() + "' and region='" + maxRegion.ToString() + "'"); if (drsLastRegion.Length > 0 && drsLastRegion[0]["materialNo"] == drArriveDetail["materialNo"]) { //查找到相同物料 // empty = 5 - Convert.ToInt32(drsLastRegion[0]["boxNum"]); empty = maxManualNum - Convert.ToInt32(drsLastRegion[0]["boxNum"]); if (empty > 0) { isNewPallet = false;//不需要新托盘 } } else { if (drsLastRegion.Length > 0 && drsLastRegion[0]["materialNo"] != drArriveDetail["materialNo"]) { maxRegion++; } //if (maxRegion > 8) if (maxRegion > maxManualRegion) { maxPalletIndex = maxPalletIndex + 1; maxRegion = 1; } else { isNewPallet = false;//不需要新托盘 } } } #endregion 查找有剩余位置的托盘 #region 生成排托计划 if (isNewPallet)//需要使用新托盘 { DataView dvMaxPallet = this.DtResult.DefaultView; dvMaxPallet.RowFilter = "isdel=0 "; dvMaxPallet.Sort = "palletIndex"; foreach (DataRow drMaxPallet in dvMaxPallet.ToTable().Rows) { //遍历 同采购订单的同物料并且已经排拖的数据 ,找到 最大的托盘号,以及已经排拖的总数量 if (Convert.ToInt32(drMaxPallet["palletIndex"]) > maxPalletIndex) { //获取 最大托盘号+1为新的托盘 maxPalletIndex = Convert.ToInt32(drMaxPallet["palletIndex"]); } } maxPalletIndex = maxPalletIndex + 1; maxRegion = 1; } int lastNum = leavingNum; do { while (maxRegion <= maxManualRegion && lastNum > 0) { //把之前的托盘不足的补全 DataRow drnew = this.DtResult.NewRow(); drnew["rowId"] = Guid.NewGuid().ToString(); drnew["isdel"] = "0"; drnew["id"] = 0; drnew["boxNum"] = lastNum >= empty ? empty : lastNum;//要补全的托盘,如果剩余不足,数量就等于剩余数量 drnew["hideAmount"] = lastNum >= empty ? empty : lastNum; drArriveDetail["arrangeBoxNum_leaving"] = Convert.ToInt32(drArriveDetail["arrangeBoxNum_leaving"]) - (lastNum >= empty ? empty : lastNum);//采购订单明细扣除相应已经排拖的数量 drArriveDetail["arrangeBoxNum"] = Convert.ToInt32(drArriveDetail["arrangeBoxNum"]) + (lastNum >= empty ? empty : lastNum);//采购订单明细扣除相应已经排拖的数量 drnew["ischeck"] = false; drnew["arrangeBillNo"] = "PT" + this.ArriveBillNo; drnew["arriveBillNo"] = drArriveDetail["arriveBillNo"]; drnew["materialDesc"] = drArriveDetail["materialDesc"]; drnew["financeBillNo"] = drArriveDetail["financeBillNo"]; drnew["materialNo"] = drArriveDetail["materialNo"]; drnew["wareSortNo"] = drArriveDetail["wareSortNo"]; drnew["wareSortNm"] = drArriveDetail["wareSortNm"]; drnew["region"] = maxRegion; drnew["palletIndex"] = maxPalletIndex;//托盘序号 drnew["customNo"] = drArriveDetail["customNo"];//客户编号 this.DtResult.Rows.Add(drnew); maxRegion = maxRegion + 1; lastNum = lastNum - empty; //empty = 5; empty = maxManualNum; } maxPalletIndex += 1; maxRegion = 1; } while (lastNum > 0); #endregion 生成排托计划 } this.BindDetailTable();//绑定排托明细列表 this.SaveStencilDetailViewState();//保存 this.BindGrid();//绑定到货明细列表 } catch (Exception ex) { this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true); return; } finally { materialBB.Dispose(); } }