/// <summary>
    /// 手工保存拣货计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSaveDetail_Click(object sender, EventArgs e)
    {
        LWareLocatorBB wareLocatorBB = new LWareLocatorBB();
        LMaterialBB materialBB = new LMaterialBB();
        UStockBB stockBB = new UStockBB();
        SCommBB commBB = new SCommBB();
        CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB();
        LMaterialRelationBB materialRelationBB = new LMaterialRelationBB();

        try
        {
            #region 验证数据是否填写完整

            string strErrorInfo = "", strWareNo = "", strWareNm = "", strWareLocatorNm = "", strMaterialDesc = "",
                strWhere = "";
            //strStockUpMaterialNo = "", strPalletIndex = ""
            DataTable dtWareLocator = new DataTable();
            DataTable dtMaterial = new DataTable();
            DataTable dtStock = new DataTable();
            DataTable dtStockUpDetail = new DataTable();
            DataRow[] myDataRowArray = null;
            bool isRightMaterial = false;
            int planNum = 0, factNum = 0;

            #region 校验填写库位

            if (this.txtWareLocarorNo.Value.Trim() == "")
            {
                strErrorInfo = "请首先填写库位!";
                this.txtWareLocarorNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            dtWareLocator = wareLocatorBB.GetVList("wareLocatorNo='" + this.txtWareLocarorNo.Value.Trim() + "'").Tables[0];
            if (dtWareLocator.Rows.Count == 0)
            {
                strErrorInfo = "请首先填写正确库位!";
                this.txtWareLocarorNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            strWareNo = dtWareLocator.Rows[0]["wareNo"].ToString();//库区编码
            strWareNm = dtWareLocator.Rows[0]["wareNm"].ToString();//库区名称
            strWareLocatorNm = dtWareLocator.Rows[0]["wareLocatorNm"].ToString();//库位名称

            if (strWareNo != "GLHJ01" && strWareNo != "GLHJ02" && this.txtPalletNo.Value.Trim() == "")
            {
                strErrorInfo = "请首先填写托盘号!";
                this.txtPalletNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            #endregion 校验填写库位

            #region 校验填写物料

            if (this.txtMaterialNo.Value.Trim() == "")
            {
                strErrorInfo = "请首先填写物料编号!";
                this.txtMaterialNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            dtMaterial = materialBB.GetVList("materialNo='" + this.txtMaterialNo.Value.Trim() + "'").Tables[0];
            if (dtMaterial.Rows.Count == 0)
            {
                strErrorInfo = "请首先填写正确物料!";
                this.txtMaterialNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            strMaterialDesc = dtMaterial.Rows[0]["materialNm_CH"].ToString();//物料描述
            //strStockUpMaterialNo = this.txtMaterialNo.Value.Trim().ToUpper();//计划备货物料

            #endregion 校验填写物料

            #region 校验填写数量

            if (this.tbNum.Text.Trim() == "")
            {
                strErrorInfo = "请首先填写数量!";
                this.tbNum.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            if (!CommFunction.IsInt(this.tbNum.Text.Trim()))
            {
                strErrorInfo = "数量格式错误!";
                this.tbNum.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            if (Convert.ToInt32(this.tbNum.Text.Trim()) <= 0)
            {
                strErrorInfo = "数量必须大于0!";
                this.tbNum.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            //校验拣货数量是否超出计划备货数量
            strWhere = "stockUpBillNo='" + this.stockUpBillNo.Text.Trim() + "' and palletIndex='" + this.PalletIndex
                + "' and materialNo='" + this.StockUpMaterialNo + "'";

            if (this.txtFinanceBillNo.Value.Trim() != "")
            {
                strWhere += " and financeBillNo='" + this.txtFinanceBillNo.Value.Trim() + "'";
            }

            if (this.SaleBillNo != "" && this.SaleBillNo != "0")
            {
                strWhere += " and saleBillNo='" + this.SaleBillNo + "'";
            }

            if (this.LineNum != "" && this.LineNum != "0")
            {
                strWhere += " and lineNum='" + this.LineNum + "'";
            }

            if (this.AbsEntry != "" && this.AbsEntry != "0")
            {
                strWhere += " and absEntry='" + this.AbsEntry + "'";
            }

            dtStockUpDetail = stockUpDetailBB.GetList(strWhere).Tables[0];
            foreach (DataRow row in dtStockUpDetail.Rows)
            {
                planNum += Convert.ToInt32(dtStockUpDetail.Rows[0]["num"]);//计算计划备货数量
            }

            //计算实际备货数量
            strWhere = "isDel=0 and stockUpBillNo='" + this.stockUpBillNo.Text.Trim() + "' and palletIndex='" + this.PalletIndex
                + "' and stockUpMaterialNo='" + this.StockUpMaterialNo + "'";

            if (this.txtFinanceBillNo.Value.Trim() != "")
            {
                strWhere += " and financeBillNo='" + this.txtFinanceBillNo.Value.Trim() + "'";
            }

            if (this.SaleBillNo != "" && this.SaleBillNo != "0")
            {
                strWhere += " and saleBillNo='" + this.SaleBillNo + "'";
            }

            if (this.LineNum != "" && this.LineNum != "0")
            {
                strWhere += " and lineNum='" + this.LineNum + "'";
            }

            if (this.AbsEntry != "" && this.AbsEntry != "0")
            {
                strWhere += " and absEntry='" + this.AbsEntry + "'";
            }

            myDataRowArray = this.DtResult.Select(strWhere);
            foreach (DataRow row in myDataRowArray)
            {
                factNum += Convert.ToInt32(row["num"]);
            }

            if (factNum + Convert.ToInt32(this.tbNum.Text.Trim()) > planNum)
            {
                if (this.SaleBillNo != "" && this.SaleBillNo != "0")
                {
                    strErrorInfo = "托盘【" + this.PalletIndex + "】的提货单【" + this.AbsEntry
                        + "】销售订单【" + this.SaleBillNo + "】行号【" + this.LineNum + "】物料【" + this.StockUpMaterialNo + "】计划备货【"
                        + planNum.ToString() + "】,已经备货【" + factNum + "】,填写数量超出还需要备货数量!";
                }
                else
                {
                    strErrorInfo = "托盘【" + this.PalletIndex + "】的物料【" + this.StockUpMaterialNo + "】计划备货【"
                        + planNum.ToString() + "】,已经备货【" + factNum + "】,填写数量超出还需要备货数量!";
                }

                this.tbNum.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            #endregion 校验填写数量

            #region 判断是否重复拣货

            strWhere = "isDel=0 and palletIndex='" + this.PalletIndex + "' and wareLocatorNo='" + this.txtWareLocarorNo.Value.Trim()
                + "' and materialNo='" + this.txtMaterialNo.Value.Trim() + "'";

            if (this.txtFinanceBillNo.Value.Trim() != "")
            {
                strWhere += " and financeBillNo='" + this.txtFinanceBillNo.Value.Trim() + "'";
            }

            if (this.SaleBillNo != "" && this.SaleBillNo != "0")
            {
                strWhere += " and saleBillNo='" + this.SaleBillNo + "'";
            }

            if (this.LineNum != "" && this.LineNum != "0")
            {
                strWhere += " and lineNum='" + this.LineNum + "'";
            }

            if (this.AbsEntry != "" && this.AbsEntry != "0")
            {
                strWhere += " and absEntry='" + this.AbsEntry + "'";
            }

            myDataRowArray = this.DtResult.Select(strWhere);
            if (myDataRowArray.Length > 0)
            {
                if (this.txtFinanceBillNo.Value.Trim() == "")
                {
                    if (this.SaleBillNo != "" && this.SaleBillNo != "0")
                    {
                        strErrorInfo = "托盘【" + this.PalletIndex + "】的提货单【" + this.AbsEntry
                            + "】销售订单【" + this.SaleBillNo + "】行号【" + this.LineNum + "】已经从库位【" + this.txtWareLocarorNo.Value.Trim() + "】中拣出物料【"
                            + this.txtMaterialNo.Value.Trim() + "】,请首先删除原有记录,再添加新记录!";
                    }
                    else
                    {
                        strErrorInfo = "托盘【" + this.PalletIndex + "】已经从库位【" + this.txtWareLocarorNo.Value.Trim() + "】中拣出物料【"
                            + this.txtMaterialNo.Value.Trim() + "】,请首先删除原有记录,再添加新记录!";
                    }
                }
                else
                {
                    if (this.SaleBillNo != "" && this.SaleBillNo != "0")
                    {
                        strErrorInfo = "托盘【" + this.PalletIndex + "】的提货单【" + this.AbsEntry
                            + "】销售订单【" + this.SaleBillNo + "】行号【" + this.LineNum + "】已经从库位【" + this.txtWareLocarorNo.Value.Trim() + "】中拣出采购合同【"
                            + this.txtFinanceBillNo.Value.Trim() + "】的物料【"
                            + this.txtMaterialNo.Value.Trim() + "】,请首先删除原有记录,再添加新记录!";
                    }
                    else
                    {
                        strErrorInfo = "托盘【" + this.PalletIndex + "】已经从库位【" + this.txtWareLocarorNo.Value.Trim() + "】中拣出采购合同【"
                            + this.txtFinanceBillNo.Value.Trim() + "】的物料【"
                            + this.txtMaterialNo.Value.Trim() + "】,请首先删除原有记录,再添加新记录!";
                    }
                }

                this.txtMaterialNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            #endregion 判断是否重复拣货

            #region 根据库位、物料、采购合同号,判断是否有货

            strWhere = "wareLocatorNo='" + this.txtWareLocarorNo.Value.Trim() + "' and materialNo='" + this.txtMaterialNo.Value.Trim() + "'";

            if (this.txtFinanceBillNo.Value.Trim() != "")
            {
                strWhere += " and financeBillNo='" + this.txtFinanceBillNo.Value.Trim() + "'";
            }

            dtStock = stockBB.GetVList(strWhere).Tables[0];
            if (dtStock.Rows.Count == 0)
            {
                if (this.txtFinanceBillNo.Value.Trim() == "")
                {
                    strErrorInfo = "库位【" + this.txtWareLocarorNo.Value.Trim() + "】中不存在物料【" + this.txtMaterialNo.Value.Trim() + "】!";
                }
                else
                {
                    strErrorInfo = "库位【" + this.txtWareLocarorNo.Value.Trim() + "】中不存在采购合同【"
                        + this.txtFinanceBillNo.Value.Trim() + "】的物料【" + this.txtMaterialNo.Value.Trim() + "】!";
                }

                this.txtMaterialNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            #endregion 根据库位、物料、采购合同号,判断是否有货

            #region 校验物料是否是需要拣出的物料

            if (this.StockUpMaterialNo == this.txtMaterialNo.Value.Trim())
            {
                isRightMaterial = true;
            }
            else
            {
                DataTable dtConvertMaterial = new DataTable();

                dtConvertMaterial = materialRelationBB.GetList("newMaterialNo='" + this.txtMaterialNo.Value.Trim() + "'").Tables[0];
                if (dtConvertMaterial.Rows.Count > 0)
                {
                    foreach (DataRow row in dtConvertMaterial.Rows)
                    {
                        if (this.StockUpMaterialNo == row["oldMaterialNo"].ToString())
                        {
                            isRightMaterial = true;
                            break;
                        }
                    }
                }
            }

            if (isRightMaterial == false)
            {
                strErrorInfo = "当前物料不在备货计划内!";

                this.txtMaterialNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            #endregion 校验物料是否是需要拣出的物料

            #endregion 验证数据是否填写完整

            DataRow myDataRow = this.DtResult.NewRow();

            myDataRow["rowId"] = Guid.NewGuid().ToString();
            myDataRow["id"] = 0;
            myDataRow["num"] = this.tbNum.Text.Trim();
            myDataRow["stockUpBillNo"] = "";
            myDataRow["palletIndex"] = this.PalletIndex;//托盘序号
            myDataRow["wareNo"] = strWareNo;
            myDataRow["wareLocatorNo"] = this.txtWareLocarorNo.Value.Trim().ToUpper();
            myDataRow["palletNo"] = this.txtPalletNo.Value.Trim();
            myDataRow["stockUpMaterialNo"] = this.StockUpMaterialNo;//计划备货物料
            myDataRow["materialNo"] = this.txtMaterialNo.Value.Trim();//实际拣货物料
            myDataRow["wareNm"] = strWareNm;
            myDataRow["wareLocatorNm"] = strWareLocatorNm;
            myDataRow["materialDesc"] = strMaterialDesc;
            myDataRow["instantState"] = "01";
            myDataRow["financeBillNo"] = this.txtFinanceBillNo.Value.Trim().ToUpper();//采购合同号
            myDataRow["financeBillSort"] = this.txtFinanceBillNo.Value.Trim() == "" ? "备货" : "按单";//采购合同类型
            myDataRow["saleBillNo"] = this.SaleBillNo;//销售订单号
            myDataRow["docEntry"] = this.DocEntry;//销售订单ID
            myDataRow["lineNum"] = this.LineNum;//销售订单行号
            myDataRow["absEntry"] = this.AbsEntry;//提货单号
            myDataRow["isDel"] = false;

            this.DtResult.Rows.Add(myDataRow);

            this.BindGridPickOutPlan();//绑定拣货明细列表
        }
        finally
        {
            wareLocatorBB.Dispose();
            materialBB.Dispose();
            stockBB.Dispose();
            commBB.Dispose();
            stockUpDetailBB.Dispose();
            materialRelationBB.Dispose();
        }
    }
    /// <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();
            }
        }
    }
    /// <summary>
    /// 手动填写 增加拣货计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSaveDetail_Click(object sender, EventArgs e)
    {
        LWareLocatorBB wareLocatorBB = new LWareLocatorBB();
        LMaterialBB materialBB = new LMaterialBB();
        UStockBB stockBB = new UStockBB();
        SCommBB commBB = new SCommBB();
        LMaterialRelationBB materialRelationBB = new LMaterialRelationBB();

        try
        {

            string strErrorInfo = "", strWareNo = "", strWareNm = "",
            strWareLocatorNm = "", strMaterialDesc = "";

            DataTable dtWareLocator = new DataTable();
            DataTable dtMaterial = new DataTable();
            DataTable dtStock = new DataTable();
            DataTable dtStockUpDetail = new DataTable();

            if (this.txtWareLocarorNo.Value.Trim() == "")
            {
                strErrorInfo = "请首先填写库位!";
                this.txtWareLocarorNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            dtWareLocator = wareLocatorBB.GetVList("wareLocatorNo='" + this.txtWareLocarorNo.Value.Trim() + "'").Tables[0];
            if (dtWareLocator.Rows.Count == 0)
            {
                strErrorInfo = "请首先填写正确库位!";
                this.txtWareLocarorNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            strWareNo = dtWareLocator.Rows[0]["wareNo"].ToString();//库区编码
            strWareNm = dtWareLocator.Rows[0]["wareNm"].ToString();//库区名称
            strWareLocatorNm = dtWareLocator.Rows[0]["wareLocatorNm"].ToString();//库位名称

            if (strWareNo != "GLHJ01" && strWareNo != "GLHJ02" && this.txtPalletNo.Value.Trim() == "")
            {
                strErrorInfo = "请首先填写托盘号!";
                this.txtPalletNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            if (this.txtMaterialNo.Value.Trim() == "")
            {
                strErrorInfo = "请首先填写物料编号!";
                this.txtMaterialNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            dtMaterial = materialBB.GetVList("materialNo='" + this.txtMaterialNo.Value.Trim() + "'").Tables[0];
            if (dtMaterial.Rows.Count == 0)
            {
                strErrorInfo = "请首先填写正确物料!";
                this.txtMaterialNo.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            strMaterialDesc = dtMaterial.Rows[0]["materialNm_CH"].ToString();//物料描述
            //strStockUpMaterialNo = this.txtMaterialNo.Value.Trim().ToUpper();//计划备货物料

            if (this.tbNum.Text.Trim() == "")
            {
                strErrorInfo = "请首先填写数量!";
                this.tbNum.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            if (!CommFunction.IsInt(this.tbNum.Text.Trim()))
            {
                strErrorInfo = "数量格式错误!";
                this.tbNum.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            if (Convert.ToInt32(this.tbNum.Text.Trim()) <= 0)
            {
                strErrorInfo = "数量必须大于0!";
                this.tbNum.Focus();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showFloatDetail();alert('" + strErrorInfo + "');", true);
                return;
            }

            DataRow drnew = this.DtResultNew.NewRow();

            drnew["rowId"] = Guid.NewGuid().ToString();
            drnew["id"] = 0;
            drnew["num"] = this.tbNum.Text.Trim();
            drnew["palletIndex"] = "1";
            drnew["wareNo"] = strWareNo;
            drnew["wareLocatorNo"] = this.txtWareLocarorNo.Value.Trim().ToUpper();
            drnew["palletNo"] = this.txtPalletNo.Value.Trim();
            drnew["stockUpMaterialNo"] = this.StockUpMaterialNo;//计划备货物料
            drnew["materialNo"] = this.txtMaterialNo.Value.Trim();//实际拣货物料
            //drnew["materialDesc"] = strMaterialDesc;
            drnew["instantState"] = "01";
            drnew["financeBillNo"] = this.txtFinanceBillNo.Value.Trim().ToUpper();//采购合同号
            //drnew["financeBillSort"] = this.txtFinanceBillNo.Value.Trim() == "" ? "备货" : "按单";//采购合同类型
            drnew["saleBillNo"] = this.SaleBillNo;//销售订单号
            drnew["docEntry"] = this.DocEntry;//销售订单ID
            drnew["lineNum"] = this.LineNum;//销售订单行号

            drnew["isDel"] = false;

            //去除判断属性 直接进行数据的保存 将校验数据去除

            this.DtResultNew.Rows.Add(drnew);

            this.BindGridPickOutPlan();//绑定拣货明细列表
            this.btnSubmit.Enabled = true;
        }
        finally
        {
            wareLocatorBB.Dispose();
            materialBB.Dispose();
            stockBB.Dispose();
            commBB.Dispose();

            materialRelationBB.Dispose();
        }
    }
    protected void btnPlan_click(object sender, EventArgs e)
    {
        //首先要查看是否有选中的物料 如果没有选中物料 提示 并且返回
        //Response.Write(this.gridSaleBill.Rows.Count.ToString());
        string ids = "";
        foreach (GridViewRow gvrow in this.gridSaleBill.Rows)
        {
            CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");

            if (chkId.Checked == true)
            {
                string id = this.gridSaleBill.DataKeys[gvrow.RowIndex].Values["id"].ToString();
                ids += id + ",";//使用逗号将数据进行处理
            }

        }
        if (ids == "")
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"没有选中任何销售物料\");", true);
            return;
        }
        else
        {

            DtResultNew.Rows.Clear();//将所有的行删除掉 用来解决数据不断重复往上加的问题
            string rowFilterString = "";
            string[] idChoose = ids.Split(',');//将id取出来
            for (int i = 0; i < idChoose.Length - 1; i++)
            {
                rowFilterString += "id = " + idChoose[i] + " or ";
            }

            DtResult.DefaultView.RowFilter = rowFilterString.Remove(rowFilterString.Length - 3, 2);
            DtResultCondtion = DtResult.DefaultView.ToTable();
        }
        //首先是遍历全部的数据
        //生成相应的CpickOutPlan
        //显示出来
        UStockBB stockBB = new UStockBB();
        LMaterialRelationBB materialRelationBB = new LMaterialRelationBB();
        OtherOutInDetailBB otherOutInDetailBB = new OtherOutInDetailBB();
        LMaterialBB materialBB = new LMaterialBB();
        DataSet dsStock = new DataSet();

        DataRow[] drsStock = null;

        foreach (DataRow drStockUpDetail in DtResultCondtion.Rows)
        {
            int needCount = Convert.ToInt32(drStockUpDetail["Number"]);
            string strLineNum = drStockUpDetail["lineNumber"].ToString();//行号
            string strDocEntry = drStockUpDetail["SAPdocEntry"].ToString();//销售订单ID
            string strMaterialNo = drStockUpDetail["MaterialNo"].ToString();
            string U_PCNo = drStockUpDetail["U_PCNo"].ToString();//增加采购合同号

            if (string.IsNullOrEmpty(U_PCNo))
            {
                //找到仓库内的同种物料所在的库位以及数量
                //首先是判断同一个库位下的信息是否能够满足所有的需求
                //不带采购合同号
                dsStock = stockBB.GetVListByGroupOtherWithOutFinanceBillNo("stock.financeBillSortNo='02' and stock.isOutStocking=0 and stock.wareLocatorNo<>''");
                if (dsStock.Tables[0].Rows.Count > 0)
                {
                    drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo
                        + "' and num>=" + needCount.ToString());
                }
            }
            else
            {
                //带采购合同号
                dsStock = stockBB.GetVListByGroupOtherWithFinanceBillNo("stock.financeBillSortNo='02' and stock.isOutStocking=0 and stock.wareLocatorNo<>''");
                if (dsStock.Tables[0].Rows.Count > 0)
                {
                    drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo
                       + "' and num>=" + needCount.ToString() + " and financeBillNo='" + U_PCNo + "'");
                }
            }

            if (drsStock.Length == 0)
            {
                if (string.IsNullOrEmpty(U_PCNo))
                {
                    dsStock = stockBB.GetVListByGroupOtherWithOutFinanceBillNo("stock.financeBillSortNo='02' and stock.isOutStocking=0 and stock.wareLocatorNo<>''");
                    if (dsStock.Tables[0].Rows.Count > 0)
                        drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo + "' and num>0");
                }
                else
                {
                    dsStock = stockBB.GetVListByGroupOtherWithFinanceBillNo("stock.financeBillSortNo='02' and stock.isOutStocking=0 and stock.wareLocatorNo<>''");
                    if (dsStock.Tables[0].Rows.Count > 0)
                        drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo
                        + "' and num>0 and financeBillNo='" + U_PCNo + "'");
                }
            }
            while (needCount > 0)
            {
                #region 原物料拣货

                //2015-08-24修改 在此处增加采购合同号的判断

                if (string.IsNullOrEmpty(U_PCNo))
                {
                    //找到仓库内的同种物料所在的库位以及数量
                    //首先是判断同一个库位下的信息是否能够满足所有的需求
                    //不带采购合同号

                    if (dsStock.Tables[0].Rows.Count > 0)
                    {
                        drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo
                            + "' and num>=" + needCount.ToString());
                    }
                }
                else
                {
                    //带采购合同号

                    if (dsStock.Tables[0].Rows.Count > 0)
                    {
                        drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo
                           + "' and num>=" + needCount.ToString() + " and financeBillNo='" + U_PCNo + "'");
                    }
                }

                if (drsStock.Length == 0)
                {
                    if (string.IsNullOrEmpty(U_PCNo))
                    {

                        if (dsStock.Tables[0].Rows.Count > 0)
                            drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo + "' and num>0");
                    }
                    else
                    {

                        if (dsStock.Tables[0].Rows.Count > 0)
                            drsStock = dsStock.Tables[0].Select("materialno='" + strMaterialNo
                            + "' and num>0 and financeBillNo='" + U_PCNo + "'");
                    }
                }

                if (drsStock.Length > 0)
                {
                    //当前库位所拥有该物料的数量
                    int haveCount = Convert.ToInt32(drsStock[0]["num"]);

                    //如果当前库位的物料数量大于备货单所需数量,就保存当前库位
                    DataRow drnew = this.DtResultNew.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"] = "1";
                    drnew["wareNo"] = drsStock[0]["wareNo"];
                    drnew["wareLocatorNo"] = drsStock[0]["wareLocatorNo"];
                    drnew["palletNo"] = drsStock[0]["palletNo"];
                    drnew["stockUpMaterialNo"] = strMaterialNo;//备货物料编号
                    drnew["materialNo"] = drsStock[0]["materialNo"];//实际拣货物料编号
                    drnew["instantState"] = "01";
                    drnew["financeBillNo"] = U_PCNo;
                    drnew["docEntry"] = strDocEntry;//销售订单ID
                    drnew["lineNum"] = strLineNum;//行号
                    drnew["isDel"] = false;
                    this.DtResultNew.Rows.Add(drnew);
                    drStockUpDetail["number"] = needCount;//重新赋值拣货数量
                }
                else
                {
                    needCount = 0;
                    // break;
                }

                #endregion 原物料拣货
            }
        }

        OtherOutInBillBB otherOutInBill = new OtherOutInBillBB();
        OtherOutInDetailBB otherOutInDetailBill = new OtherOutInDetailBB();
        string id2 = Request.Params["id"];
        vOtherOutInBillData otherOutInBIllData = otherOutInBill.GetVModel(Convert.ToInt32(id2));
        string SAPDocEntry = otherOutInBIllData.SAPDocEntry;
        string strInfo = "";
        foreach (DataRow otherOutInBillRow in DtResultCondtion.Rows)
        {
            int planNum = 0;
            int factNum = 0;
            DataRow[] myDataRowArray = null;
            if (!string.IsNullOrEmpty(otherOutInBillRow["U_PCNo"].ToString()))
            {
                myDataRowArray = DtResultCondtion.Select("materialNo='"
                    + otherOutInBillRow["materialNo"].ToString() + "' and U_PCNo = '" + otherOutInBillRow["U_PCNo"] + "'");
            }
            else
            {
                myDataRowArray = DtResultCondtion.Select("materialNo='"
                       + otherOutInBillRow["materialNo"].ToString() + "'");
            }
            foreach (DataRow row in myDataRowArray)
            {
                planNum += Convert.ToInt32(row["hadNum"]);
            }
            if (!string.IsNullOrEmpty(otherOutInBillRow["U_PCNo"].ToString()))
            {
                myDataRowArray = this.DtResultNew.Select("materialNo=stockupmaterialNo and materialNo='"
                   + otherOutInBillRow["materialNo"].ToString() + "'and financeBillNo = '" + otherOutInBillRow["U_PCNo"] + "'");
            }
            else
            {
                myDataRowArray = this.DtResultNew.Select("materialNo=stockupmaterialNo and materialNo='"
                   + otherOutInBillRow["materialNo"].ToString() + "'");
            }
            foreach (DataRow row in myDataRowArray)
            {
                factNum += Convert.ToInt32(row["num"]);
            }

            if (planNum != factNum)
            {
                strInfo += "物料【" + otherOutInBillRow["materialNo"].ToString() + "】,计划拣货【"
                    + planNum.ToString() + "】件,实际拣货【" + factNum.ToString() + "】件;";
                btnSubmit.Enabled = false;
            }
        }
        if (strInfo != "")
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前未完成拣货,不允许保存!提示信息:" + strInfo + "\");", true);
            btnSubmit.Enabled = false;
        }
        BindGridPickOutPlan();
        //}
    }
示例#6
0
    public DataTable GetMaterialRelationByNewMaterial(string strNewMaterialNo)
    {
        LMaterialRelationBB materialRelationBB = new LMaterialRelationBB();

        try
        {
            DataTable dt = new DataTable();

            dt = materialRelationBB.GetList("newMaterialNo='" + strNewMaterialNo + "'").Tables[0];
            return dt;
        }
        finally
        {
            materialRelationBB.Dispose();
        }
    }