Ejemplo n.º 1
0
    /// <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();
        }
    }
Ejemplo n.º 2
0
    /// <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 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();
        }
    }
    /// <summary>
    /// 绑定库存明细列表,2014-12-03 王工原有的程序使用的 变为old
    /// </summary>
    protected void BindGridold()
    {
        UStockBB stockBB = new UStockBB();
        SCommBB commBB = new SCommBB();
        try
        {
            DataSet ds = new DataSet();

            ds = stockBB.UStockDeatilReport(this.ddlWare.SelectedValue, this.ddlWareLocater.SelectedValue,
                this.tbFinanceBillNo.Text.Trim().Replace("'", "''").Trim(),
                this.tbMaterial.Text.Trim().Replace("'", "''").Trim(), this.tbBoxNo.Text.Trim().Replace("'", "''").ToUpper(),
                this.tbPalletNo.Text.Trim().Replace("'", "''").ToUpper(), this.ddlIsOutStocking.SelectedValue, this.ddlCheckResult.SelectedValue);

            this.grid.DataSource = ds.Tables[0];
            this.grid.DataBind();

            //赋值记录条数、页面总数
            this.Label3.Text = ds.Tables[0].Rows.Count.ToString();
            this.Label2.Text = this.grid.PageCount.ToString();
            this.currPage.Text = (this.grid.PageIndex + 1).ToString();

        }
        finally
        {
            stockBB.Dispose();
            commBB.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();
        //}
    }
Ejemplo n.º 6
0
    /// <summary>
    /// 指定入库
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnInput_Click(object sender, EventArgs e)
    {
        bool retChecked = false;//是否选择

        foreach (GridViewRow gvrow in this.grid.Rows)
        {
            CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
            if (chkId.Checked == true)
            {
                UStockBB stockBB = new UStockBB();
                BTallyBillBB tallyBillBB = new BTallyBillBB();
                UStockBC stockBC = new UStockBC();

                try
                {
                    BTallyBillData tallyBillModel = tallyBillBB.GetModel(this.IdValue);

                    if (tallyBillModel.instantState != "02")//状态不是“已理货完成”
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前托盘已经指定了库位!\");", true);
                        return;
                    }
                    else
                    {
                        string strwhere = "wareLocatorNo='" + chkId.ValidationGroup + "'";
                        DataSet ds = stockBB.GetList(strwhere);

                        if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
                        {
                            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前库位已经被占用!\");", true);
                            return;
                        }
                        else
                        {
                            tallyBillModel.instantState = "03";//指定状态为“已入库”
                            tallyBillModel.isInStock = true;// 入库状态
                            tallyBillModel.wareLocatorNo = chkId.ValidationGroup;//库位

                            retChecked = stockBC.SetPalletWarelocator(tallyBillModel,this.ddlWare.SelectedValue);
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
                    return;
                }
                finally
                {
                    tallyBillBB.Dispose();
                    stockBB.Dispose();
                    stockBC.Dispose();
                }
            }
        }

        if (retChecked)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"库位指定成功!\"); location.replace('UStockList.aspx?itemNo=" + this.itemNo + "&pTypeNo=main');", true);
            return;
        }

        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"请选择一个库位!\");", true);
        return;
    }
Ejemplo n.º 7
0
    public void UpdateOutStockPalletEffectInfo(string strStockUpBillNo, string strPalletNo,
        string strNextWareNo, string strNextWareLocatorNo)
    {
        BForkliftTaskBB forkliftTaskBB = new BForkliftTaskBB();
        UStockBB stockBB = new UStockBB();

        try
        {
            DataTable dtStock = new DataTable();
            BForkliftTaskData forkliftTaskModel = new BForkliftTaskData();

            //获取托盘库存信息
            dtStock = stockBB.GetList("palletNo='" + strPalletNo + "'").Tables[0];

            forkliftTaskModel.taskType = "05";//任务类型为:从正式库区到拣货工作区
            forkliftTaskModel.palletNo = strPalletNo;//托盘号

            //源库位信息
            if (dtStock.Rows.Count > 0)
            {
                forkliftTaskModel.preWareNo = dtStock.Rows[0]["wareNo"].ToString();//源库区
                forkliftTaskModel.preLocatorNo = dtStock.Rows[0]["wareLocatorNo"].ToString();//源库位
            }

            forkliftTaskModel.nextWareNo = strNextWareNo;//目的库区
            forkliftTaskModel.nextLocatorNo = strNextWareLocatorNo;//目的库位
            forkliftTaskModel.effectDt = System.DateTime.Now.ToString();//生效时间
            forkliftTaskModel.isDeal = false;//是否处理
            forkliftTaskModel.stockUpBillNo = strStockUpBillNo;//备货单编号

            forkliftTaskBB.AddRecord(forkliftTaskModel);
        }
        finally
        {
            forkliftTaskBB.Dispose();
            stockBB.Dispose();
        }
    }
Ejemplo n.º 8
0
    public DataTable GetOutStockPalletList(string strStockUpBillNo, string strStockUpDetailIDs)
    {
        CPickOutPlanBB pickOutPlanBB = new CPickOutPlanBB();
        UStockBB stockBB = new UStockBB();
        CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB();

        try
        {
            DataTable dtPickOutPlan = new DataTable();
            DataTable dtPallet = new DataTable();
            DataTable dtStock = new DataTable();
            DataColumn myDataColumn = null;
            DataRow myDataRow = null;

            dtPallet.TableName = "dtPallet";

            //生成托盘条码号表托盘条码号列
            myDataColumn = new DataColumn();
            myDataColumn.DataType = System.Type.GetType("System.String");
            myDataColumn.ColumnName = "palletNo";
            dtPallet.Columns.Add(myDataColumn);

            foreach (string strStockUpDetialId in strStockUpDetailIDs.Split(','))
            {
                CStockUpDetailData stockUpDetailModel = new CStockUpDetailData();

                stockUpDetailModel = stockUpDetailBB.GetModel(Convert.ToInt32(strStockUpDetialId));

                //获取拣货计划
                dtPickOutPlan = pickOutPlanBB.GetList("stockUpBillNo='" + strStockUpBillNo
                    + "' and palletIndex='" + stockUpDetailModel.palletIndex.ToString()
                    + "' and stockUpMaterialNo='" + stockUpDetailModel.materialNo
                    + "' and docEntry='" + stockUpDetailModel.DocEntry.ToString()
                    + "' and absEntry='" + stockUpDetailModel.absEntry.ToString()
                    + "' and lineNum='" + stockUpDetailModel.lineNum.ToString()
                    + "' and isnull(palletNo,'')<>''").Tables[0];

                foreach (DataRow rowPickOutPlan in dtPickOutPlan.Rows)
                {
                    string strPalletNo = rowPickOutPlan["palletNo"].ToString();//托盘条码号

                    //库存中原物料
                    dtStock = stockBB.GetList("palletNo='" + strPalletNo
                        + "' and not exists(select 1 from dbo.BForkliftTask as t where t.palletNo='" + strPalletNo + "' and t.isDeal=0)").Tables[0];

                    //库存中有托盘
                    if (dtStock.Rows.Count > 0)
                    {
                        //新增一条托盘记录
                        if (dtPallet.Select("palletNo='" + strPalletNo + "'").Length == 0)
                        {
                            myDataRow = dtPallet.NewRow();

                            myDataRow["palletNo"] = strPalletNo;

                            dtPallet.Rows.Add(myDataRow);
                        }
                    }
                }
            }

            ////获取拣货计划
            //dtPickOutPlan = pickOutPlanBB.GetList("stockUpBillNo='" + strStockUpBillNo + "' and isnull(palletNo,'')<>''").Tables[0];

            ////合计备货单明细物料剩余数量
            //strSql.Append(@"select materialNo,sum(num-factNum) as leavingNum ");
            //strSql.Append(@"from dbo.vCStockUpDetail as stockUpDetail ");
            //strSql.Append(@"where id in (" + strStockUpDetailIDs + ") ");
            //strSql.Append(@"group by materialNo ");

            //dtStockUpDetail = commBB.Query(strSql.ToString()).Tables[0];

            ////获取拣货托盘
            //foreach (DataRow row in dtStockUpDetail.Rows)
            //{
            //    string strMaterialNo = "", strConvertMaterialNo = "";
            //    int leavingNum = 0;

            //    strMaterialNo = row["materialNo"].ToString();//物料编号
            //    leavingNum = Convert.ToInt32(row["leavingNum"]);//剩余拣货数量
            //    myDataRowArray = dtPickOutPlan.Select("materialNo='" + strMaterialNo + "'");

            //    //根据物料转换关系查找
            //    if (myDataRowArray.Length == 0)
            //    {
            //        DataTable dtMaterialRelation = new DataTable();

            //        dtMaterialRelation = materialRelationBB.GetList("oldMaterialNo='" + strMaterialNo + "'").Tables[0];
            //        if (dtMaterialRelation.Rows.Count > 0)
            //        {
            //            strConvertMaterialNo = dtMaterialRelation.Rows[0]["newMaterialNo"].ToString();//转换物料号

            //            myDataRowArray = dtPickOutPlan.Select("materialNo='" + strConvertMaterialNo + "'");
            //        }
            //    }

            //    foreach (DataRow rowPickOutPlan in myDataRowArray)
            //    {
            //        if (leavingNum > 0)
            //        {
            //            string strPalletNo = "";

            //            strPalletNo = rowPickOutPlan["palletNo"].ToString();//托盘条码号

            //            //库存中原物料
            //            dtStock = stockBB.GetList("palletNo='" + strPalletNo
            //                + "' and materialNo='" + strMaterialNo
            //                + "' and not exists(select 1 from dbo.BForkliftTask as t where t.palletNo=dbo.UStock.palletNo and t.isDeal=0)").Tables[0];

            //            //库存中转换物料
            //            if (dtStock.Rows.Count == 0)
            //            {
            //                dtStock = stockBB.GetList("palletNo='" + strPalletNo
            //                    + "' and materialNo='" + strConvertMaterialNo
            //                    + "' and not exists(select 1 from dbo.BForkliftTask as t where t.palletNo=dbo.UStock.palletNo and t.isDeal=0)").Tables[0];
            //            }

            //            foreach (DataRow rowStock in dtStock.Rows)
            //            {
            //                //新增一条托盘记录
            //                if (dtPallet.Select("palletNo='" + strPalletNo + "'").Length == 0)
            //                {
            //                    myDataRow = dtPallet.NewRow();

            //                    myDataRow["palletNo"] = strPalletNo;

            //                    dtPallet.Rows.Add(myDataRow);
            //                }

            //                if (Convert.ToInt32(rowStock["num"]) > leavingNum)
            //                {
            //                    leavingNum = 0;
            //                    break;
            //                }
            //                else
            //                {
            //                    leavingNum -= Convert.ToInt32(rowStock["num"]);
            //                }
            //            }
            //        }
            //    }
            //}

            return dtPallet;
        }
        finally
        {
            pickOutPlanBB.Dispose();
            stockBB.Dispose();
            stockUpDetailBB.Dispose();
        }
    }
Ejemplo n.º 9
0
        /// <summary>
        /// 保存备货计划
        /// </summary>
        /// <param name="dtPlan">备货计划数据源</param>
        /// <param name="strStockUpBillNo">备货单编号</param>
        /// <param name="issubmit">是否提交</param>
        /// <returns></returns>
        public bool SavePickOutPlanBill(DataTable dtPlan, string strStockUpBillNo, bool issubmit)
        {
            bool ret = false;
            UStockBB stockBB = new UStockBB(this.connection);
            SCommBB commBB = new SCommBB(this.connection);
            SqlTransaction trans = null;

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TranSave");
                    this.pickOutPlanBB.Transaction = trans;
                    stockBB.Transaction = trans;
                    commBB.Transaction = trans;
                }
                else
                {
                    this.pickOutPlanBB.Transaction = this.transaction;
                    stockBB.Transaction = this.transaction;
                    commBB.Transaction = this.transaction;
                }

                CPickOutPlanData pickOutPlanModel = new CPickOutPlanData();

                #region 逐条保存拣货计划

                //逐条保存拣货计划
                foreach (DataRow dr in dtPlan.Rows)
                {
                    string strWareLocatorNo = "", strFinanceBillNo = "", strMaterialNo = "", strWhere = "", strSql = "";
                    float num = 0;
                    DataTable dtStock = new DataTable();

                    strWareLocatorNo = dr["wareLocatorNo"].ToString();//库位
                    strFinanceBillNo = dr["financeBillNo"].ToString();//采购合同号
                    strMaterialNo = dr["materialNo"].ToString();//物料编号
                    num = Convert.ToSingle(dr["num"]);//数量

                    if (Convert.ToBoolean(dr["isDel"]) == true && Convert.ToInt32(dr["id"]) > 0)
                    {
                        //前期生成拣货计划,现在删除,处理逻辑:删除拣货计划,解除物料箱锁定

                        //删除拣货计划
                        pickOutPlanBB.DeleteRecord(Convert.ToInt32(dr["id"]));

                        #region 解除物料箱锁定

                        ////查询库存
                        //strWhere = "isOutStocking=1 and checkResult=1 and wareLocatorNo='" + strWareLocatorNo
                        //    + "' and materialNo='" + strMaterialNo + "' and num>0";

                        //if (strFinanceBillNo != "")
                        //{
                        //    strWhere += " and financeBillNo='" + strFinanceBillNo + "'";
                        //}

                        //dtStock = stockBB.GetVList(strWhere).Tables[0];

                        //foreach (DataRow row in dtStock.Rows)
                        //{
                        //    int stockId = 0;//库存ID
                        //    float stockNum = 0;//库存数量
                        //    string strBoxNo = "";//箱号

                        //    stockId = Convert.ToInt32(row["id"]);
                        //    stockNum = Convert.ToSingle(row["num"]);//库存数量
                        //    strBoxNo = row["boxNo"].ToString();

                        //    //更改库存锁定状态
                        //    strSql = "update dbo.UStock set isOutStocking=0 where id=" + stockId.ToString();
                        //    commBB.ExecuteSql(strSql);

                        //    //更改原箱库存锁定状态
                        //    strSql = "update dbo.BArrangeBillBox set isOutStocking=0 where boxNo='" + strBoxNo + "'";
                        //    commBB.ExecuteSql(strSql);

                        //    if (stockNum >= num)
                        //    {
                        //        break;
                        //    }
                        //    else
                        //    {
                        //        num = num - stockNum;
                        //    }
                        //}

                        #endregion 解除物料箱锁定
                    }
                    else if (Convert.ToBoolean(dr["isDel"]) == false && Convert.ToInt32(dr["id"]) == 0)
                    {
                        //前期没有生成拣货计划,现在生成,处理逻辑:添加拣货计划,更改物料箱锁定状态

                        #region 更改物料箱锁定状态

                        ////查询库存
                        //strWhere = "isOutStocking=0 and checkResult=1 and wareLocatorNo='" + strWareLocatorNo
                        //    + "' and materialNo='" + strMaterialNo + "' and num>0";

                        //if (strFinanceBillNo != "")
                        //{
                        //    strWhere += " and financeBillNo='" + strFinanceBillNo + "'";
                        //}

                        //dtStock = stockBB.GetVList(strWhere).Tables[0];

                        //foreach (DataRow row in dtStock.Rows)
                        //{
                        //    int stockId = 0;//库存ID
                        //    float stockNum = 0;//库存数量
                        //    string strBoxNo = "";//箱号

                        //    stockId = Convert.ToInt32(row["id"]);
                        //    stockNum = Convert.ToSingle(row["num"]);//库存数量
                        //    strBoxNo = row["boxNo"].ToString();

                        //    //更改库存锁定状态
                        //    strSql = "update dbo.UStock set isOutStocking=1 where id=" + stockId.ToString();
                        //    commBB.ExecuteSql(strSql);

                        //    //更改原箱库存锁定状态
                        //    strSql = "update dbo.BArrangeBillBox set isOutStocking=1 where boxNo='" + strBoxNo + "'";
                        //    commBB.ExecuteSql(strSql);

                        //    if (stockNum >= num)
                        //    {
                        //        break;
                        //    }
                        //    else
                        //    {
                        //        num = num - stockNum;
                        //    }
                        //}

                        #endregion 更改物料箱锁定状态
                    }

                    #region 保存拣货计划

                    if (Convert.ToInt32(dr["id"]) == 0 && Convert.ToBoolean(dr["isDel"]) == false)
                    {
                        pickOutPlanModel = new CPickOutPlanData();

                        pickOutPlanModel.stockUpBillNo = strStockUpBillNo;
                        pickOutPlanModel.palletIndex = Convert.ToInt32(dr["palletIndex"]);
                        pickOutPlanModel.wareNo = dr["wareNo"].ToString();
                        pickOutPlanModel.wareLocatorNo = dr["wareLocatorNo"].ToString();
                        pickOutPlanModel.palletNo = dr["palletNo"].ToString();
                        pickOutPlanModel.stockUpMaterialNo = dr["stockUpMaterialNo"].ToString();//备货物料
                        pickOutPlanModel.materialNo = dr["materialNo"].ToString();//实际拣货物料
                        pickOutPlanModel.num = Convert.ToInt32(dr["num"]);
                        pickOutPlanModel.financeBillNo = dr["financeBillNo"].ToString();//采购合同号
                        pickOutPlanModel.financeBillSort = dr["financeBillSort"].ToString();//采购合同类型
                        pickOutPlanModel.isrtDt = System.DateTime.Now.ToString();
                        pickOutPlanModel.isrtEmpId = this.empId;
                        pickOutPlanModel.saleBillNo =dr["saleBillNo"].ToString();//销售订单号
                        pickOutPlanModel.DocEntry = Convert.ToInt32(dr["docEntry"]);//销售订单ID
                        pickOutPlanModel.absEntry = Convert.ToInt32(dr["absEntry"]);//提货单号
                        pickOutPlanModel.lineNum = Convert.ToInt32(dr["lineNum"]);//销售订单行号

                        if (issubmit)
                        {
                            pickOutPlanModel.instantState = "02";
                        }
                        else
                        {
                            pickOutPlanModel.instantState = "01";
                        }

                        this.pickOutPlanBB.AddRecord(pickOutPlanModel);
                    }
                    else if (Convert.ToInt32(dr["id"]) > 0 && Convert.ToBoolean(dr["isDel"]) == false)
                    {
                        pickOutPlanModel = this.pickOutPlanBB.GetModel(Convert.ToInt32(dr["id"]));

                        if (issubmit)
                        {
                            pickOutPlanModel.instantState = "02";
                        }
                        else
                        {
                            pickOutPlanModel.instantState = "01";
                        }

                        this.pickOutPlanBB.ModifyRecord(pickOutPlanModel);
                    }

                    #endregion 保存拣货计划
                }

                #endregion 逐条保存拣货计划

                #region 修改备货单状态

                //修改备货单状态
                if (issubmit)
                {
                    commBB.ExecuteSql("update dbo.CStockUpBill set instantState='04' where stockUpBillNo='"
                        + strStockUpBillNo + "'");
                }
                else
                {
                    commBB.ExecuteSql("update dbo.CStockUpBill set instantState='03' where stockUpBillNo='"
                        + strStockUpBillNo + "'");
                }

                #endregion 修改备货单状态

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch
            {
                if (transaction == null) trans.Rollback("TranSave");
                throw new Exception("保存拣货单出错了!");
            }
            finally
            {
                stockBB.Dispose();
                commBB.Dispose();
            }

            return ret;
        }