protected void BindGrid()
    {
        CSaleDetailBB saleBillBB = new CSaleDetailBB();
        DataSet ds = new DataSet();

        try
        {

            string strwhere = this.StrWhere;

            //销售订单编号
            if (!string.IsNullOrEmpty(this.txtSaleBillNo.Text))
            {
                strwhere += " and saleBillNo like '%" + this.txtSaleBillNo.Text.Trim().Replace("'", "''").Trim() + "%'";
            }

            //客户
            if (!string.IsNullOrEmpty(this.txtMaterialNo.Text))
            {
                strwhere += " and (MaterialNo like '%" + this.txtMaterialNo.Text.Replace("'", "''").Trim()
                    + "%')";
            }

            //订单状态
            if (!string.IsNullOrEmpty(this.txtStockUpBillNo.Text))
            {
                strwhere += " and stockupBillNo = '" + this.txtStockUpBillNo.Text.Replace("'", "''").Trim() + "'";
            }

            ds = saleBillBB.GetVListChange(strwhere);
            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
        {
            saleBillBB.Dispose();
        }
    }
    /// <summary>
    /// 显示销售订单信息
    /// </summary>
    private void ShowInfo()
    {
        CSaleBillBB saleBillBB = new CSaleBillBB();
        CSaleDetailBB saleDetailBB = new CSaleDetailBB();

        try
        {
            string id = Request.Params["id"];
            vCSaleBillData saleBillModel = saleBillBB.GetVModel(Convert.ToInt32(id));
            DataSet ds = new DataSet();

            this.saleBillNo.Text = saleBillModel.saleBillNo;
            this.saleBillDt.Text = Convert.ToDateTime(saleBillModel.saleBillDt).ToString("yyyy-MM-dd");
            this.custNo.Text = saleBillModel.custNo;
            this.custNm.Text = saleBillModel.custNm;
            this.saleEmpNo.Text = saleBillModel.saleEmpNo;
            this.saleBillType.Text = saleBillModel.saleBillType;
            this.mark.Text = saleBillModel.mark;

            //根据提货单号、销售订单号、采购合同号,查找销售订单明细
            ds = saleDetailBB.GetVList(" absEntry='" + saleBillModel.AbsEntry
                    + "' and saleBillNo = '" + saleBillModel.saleBillNo
                    + "' and lineNum='" + saleBillModel.lineNum.ToString() + "'");

            if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
            {
                this.grid.DataSource = ds;
                this.grid.DataBind();
            }
        }
        finally
        {
            saleBillBB.Dispose();
            saleDetailBB.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>
    private void ShowStockUpBillInfo()
    {
        CStockUpBillBB stockUpBillBB = new CStockUpBillBB();
        CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB();
        CSaleDetailBB saleDetailBB = new CSaleDetailBB();

        try
        {
            vCStockUpBillData stockUpBillModel = stockUpBillBB.GetVModel(this.IdValue);
            string strSaleBillNos = "", strAbsEntrys = "", strLineNums = "", strWhere = "1=1";
            DataSet ds = new DataSet();

            this.stockUpBillNo.Text = stockUpBillModel.stockUpBillNo;
            this.shippingMarkNo.Text = stockUpBillModel.shippingMarkNo;
            this.hidCustNo.Value = stockUpBillModel.custNo;//客户编号
            this.lblCustNm.Text = stockUpBillModel.custNm;
            this.invoiceNo.Text = stockUpBillModel.invoiceNo;
            this.empNm.Text = stockUpBillModel.stockUpEmpNm;
            this.mark.Text = stockUpBillModel.mark;
            this.outBillDate.Text = Convert.ToDateTime(stockUpBillModel.outStockDt).ToString("yyyy-MM-dd");

            strSaleBillNos = "'" + stockUpBillModel.saleBillNos.Replace(",", "','") + "'";//销售订单编号组合
            strAbsEntrys = "'" + stockUpBillModel.absEntrys.Replace(",", "','") + "'";//提货单编号组合
            strLineNums = "'" + stockUpBillModel.lineNums.Replace(",", "','") + "'";//行号组合

            //绑定销售订单明细列表
            string[] saleBillNoArray = strSaleBillNos.Split(',');
            string[] absEntryArray = strAbsEntrys.Split(',');
            string[] lineNumArray = strLineNums.Split(',');

            strWhere += " and (";

            for (int i = 0; i < saleBillNoArray.Length; i++)
            {
                if (i == 0)
                {
                    strWhere += " (absEntry=" + absEntryArray[i] + " and saleBillNo=" + saleBillNoArray[i]
                        + " and lineNum=" + lineNumArray[i] + ")";
                }
                else
                {
                    strWhere += " or (absEntry=" + absEntryArray[i] + " and saleBillNo=" + saleBillNoArray[i]
                        + " and lineNum=" + lineNumArray[i] + ")";
                }
            }

            strWhere += ")";

            ds = saleDetailBB.GetVList(strWhere);

            this.gridSaleBill.DataSource = ds;
            this.gridSaleBill.DataBind();

            //绑定备货单明细列表
            ds = stockUpDetailBB.GetVList("stockUpBillNo='" + stockUpBillModel.stockUpBillNo + "'");
            this.gridStockUpDetail.DataSource = ds;
            this.gridStockUpDetail.DataBind();
        }
        finally
        {
            stockUpBillBB.Dispose();
            stockUpDetailBB.Dispose();
            saleDetailBB.Dispose();
        }
    }
Example #5
0
    public string SAPOutStock(int saleDetailId, int docEntry, int lineNum, string strMaterialNo, double num, string strInvoiceNo, String palletNO)
    {
        SapOnlineService.SapOnlineService sapService = new SapOnlineService.SapOnlineService();
        CSaleDetailBB saleDetailBB = new CSaleDetailBB();

        try
        {
            SapOnlineService.DLN1New[] list = null;
            SapOnlineService.DLN1New por1 = new SapOnlineService.DLN1New();
            CSaleDetailData saleDetailModel = new CSaleDetailData();
            string strResult = "";

            //生成SAP出库单
            //需要传递:销售订单ID、行号、物料号、数量
            list = new SapOnlineService.DLN1New[1];

            por1.DocEntry = docEntry;
            por1.LineNum = lineNum;
            por1.ItemCode = strMaterialNo;
            por1.Quantity = num;

            list[0] = por1;

            //strResult = sapService.AddODLN(por1.DocEntry, System.DateTime.Today, "从仓库系统生成", strInvoiceNo, list);

            ////更改销售中间表数据
            //if (strResult.Split('&')[0] == "1")
            //{
            //    saleDetailModel = saleDetailBB.GetModel(saleDetailId);

            //    //首先要进行判断在CstockUpdetail当中是否所有的数据都已经是‘06’状态,新增06状态用于表示SAP出库已近完成
            //    //首先是将状态从05改为06,然后再进行别的处理

            //    CStockUpDetailBB bb = new CStockUpDetailBB();
            //    bb.ModifyRecord("06",palletNO);//首先将05的状态改成06 然后
            //    if (bb.GetStatus(saleDetailId))
            //    {
            //    saleDetailModel.isSapOutStock = true;//是否已提交SAP出库
            //    saleDetailBB.ModifyRecord(saleDetailModel);
            //    }
            //}

            return strResult;
        }
        finally
        {
            sapService.Dispose();
            saleDetailBB.Dispose();
        }
    }
Example #6
0
    public string SAPConverMaterialOutInStock(string strStockUpBillNo, string MarkText)
    {
        SapOnlineService.SapOnlineService sapService = new SapOnlineService.SapOnlineService();
        CSaleDetailBB saleDetailBB = new CSaleDetailBB();
        SCommBB commBB = new SCommBB();

        try
        {
            SapOnlineService.WebFaHuoModel2[] faHuoList = null;
            SapOnlineService.WebShouHuoModel2[] shouHuoList = null;
            SapOnlineService.IGE1_Return IGEReturn = null;
            SapOnlineService.IGN1_Return IGNReturn = null;
            SapOnlineService.IGE1[] IGEArray = null;
            StringBuilder struFaHuo = new StringBuilder();
            StringBuilder struShouHuo = new StringBuilder();
            DataTable dtPickOutPlan = new DataTable();
            string strResult = "", strError = "";

            //获取所有需要收发货的拣货计划
            dtPickOutPlan = commBB.Query("exec Proc_GetSAPKCSFH '" + strStockUpBillNo + "'").Tables[0];
            if (dtPickOutPlan.Rows.Count == 0)
            {
                strResult = "0&当前拣货单没有需要收发货物料!";
                return strResult;
            }

            #region 库存发货

            foreach (DataRow rowPickOutPlan in dtPickOutPlan.Rows)
            {
                double num = 0;
                string strAbsEntry = "", strDocEntry = "", strMaterialNo_FH = "", strMaterialNo_SH = "";

                strAbsEntry = rowPickOutPlan["absEntry"].ToString();//提货单ID
                strDocEntry = rowPickOutPlan["docEntry"].ToString();//销售订单ID
                strMaterialNo_FH = rowPickOutPlan["materialNo_FH"].ToString();//库存发货物料
                strMaterialNo_SH = rowPickOutPlan["materialNo_SH"].ToString();//库存收货物料
                num = Convert.ToDouble(rowPickOutPlan["num"]);//剩余未SAP库存收发货数量

                //库存发货
                if (Convert.ToBoolean(rowPickOutPlan["isSAPOutStock"]) == false)
                {
                    struFaHuo.Append(strMaterialNo_FH + "," + num + ",01,"
                        + strDocEntry + "," + strAbsEntry + ","
                        + strMaterialNo_SH + ",GHBZ-WMS;");
                }
            }

            if (struFaHuo.ToString() != "")
            {
                string[] array_FaHuo = struFaHuo.ToString().Trim(';').Split(';');

                faHuoList = new SapOnlineService.WebFaHuoModel2[array_FaHuo.Length];

                //发货
                for (int i = 0; i < array_FaHuo.Length; i++)
                {
                    string[] array_FaHuoDetail = array_FaHuo[i].Split(',');
                    SapOnlineService.WebFaHuoModel2 faHuo = new SapOnlineService.WebFaHuoModel2();

                    faHuo.ItemCode = array_FaHuoDetail[0];//ItemCode
                    faHuo.Quantity = Convert.ToDouble(array_FaHuoDetail[1]);//Quantity
                    faHuo.WhsCode = array_FaHuoDetail[2];//WhsCode
                    faHuo.U_ORDR = array_FaHuoDetail[3];//U_ORDR
                    faHuo.U_PKL = array_FaHuoDetail[4];//U_PKL
                    faHuo.U_ItemCode = array_FaHuoDetail[5];//U_ItemCode
                    faHuo.U_YongT = "GHBZ-WMS";//U_YongT

                    faHuoList[i] = faHuo;
                }

                //库存发货
                IGEReturn = sapService.IGE1_Web_Add_ForCangKu(System.DateTime.Now, "由WMS提交-" + MarkText, faHuoList);

                strResult = IGEReturn.ResultSucess;
                strError = IGEReturn.ErrMesg;

                if (strResult == "1")
                {
                    IGEArray = IGEReturn.ListIGE1;

                    for (int i = 0; i < IGEArray.Length; i++)
                    {
                        //更改发货状态
                        commBB.ExecuteSql("update dbo.CPickOutPlan set isSAPOutStock=1,sapStockPrice=" + IGEArray[i].StockPrice
                            + " where absEntry='" + IGEArray[i].U_PKL + "' and docEntry='" + IGEArray[i].U_ORDR
                            + "' and materialNo='" + IGEArray[i].ItemCode + "'");
                    }
                }
                else
                {
                    return "0&" + strError;
                }
            }

            #endregion 库存发货

            #region 库存收货

            //获取所有需要收货的拣货计划
            dtPickOutPlan = commBB.Query("exec Proc_GetSAPKCSFH '" + strStockUpBillNo + "'").Tables[0];

            foreach (DataRow rowPickOutPlan in dtPickOutPlan.Rows)
            {
                double num = 0, price = 0;
                string strAbsEntry = "", strDocEntry = "", strMaterialNo_FH = "", strMaterialNo_SH = "";

                strAbsEntry = rowPickOutPlan["absEntry"].ToString();//提货单ID
                strDocEntry = rowPickOutPlan["docEntry"].ToString();//销售订单ID
                strMaterialNo_FH = rowPickOutPlan["materialNo_FH"].ToString();//库存发货物料
                strMaterialNo_SH = rowPickOutPlan["materialNo_SH"].ToString();//库存收货物料
                num = Convert.ToDouble(rowPickOutPlan["num"]);//剩余未SAP库存收发货数量
                price = Convert.ToDouble(rowPickOutPlan["sapStockPrice"]);//价格

                //库存收货
                if (Convert.ToBoolean(rowPickOutPlan["isSAPInStock"]) == false)
                {
                    struShouHuo.Append(strMaterialNo_SH + "," + num + ",01,"
                        + strDocEntry + "," + strAbsEntry + ","
                        + strMaterialNo_FH + ",GHBZ-WMS," + price.ToString() + ";");
                }
            }

            //组织库存收发货数据
            if (struShouHuo.ToString() != "")
            {
                string[] array_ShouHuo = struShouHuo.ToString().Trim(';').Split(';');

                shouHuoList = new SapOnlineService.WebShouHuoModel2[array_ShouHuo.Length];

                //收货
                for (int i = 0; i < array_ShouHuo.Length; i++)
                {
                    string[] array_ShouHuoDetail = array_ShouHuo[i].Split(',');
                    SapOnlineService.WebShouHuoModel2 shouHuo = new SapOnlineService.WebShouHuoModel2();

                    shouHuo.ItemCode = array_ShouHuoDetail[0];//ItemCode
                    shouHuo.Quantity = Convert.ToDouble(array_ShouHuoDetail[1]);//Quantity
                    shouHuo.WhsCode = array_ShouHuoDetail[2];//WhsCode
                    shouHuo.U_ORDR = array_ShouHuoDetail[3];//U_ORDR
                    shouHuo.U_PKL = array_ShouHuoDetail[4];//U_PKL
                    shouHuo.U_ItemCode = array_ShouHuoDetail[5];//U_ItemCode
                    shouHuo.U_YongT = "GHBZ-WMS";//U_YongT
                    shouHuo.Price = Convert.ToDouble(array_ShouHuoDetail[7]);//Price

                    shouHuoList[i] = shouHuo;
                }

                //库存收货
                IGNReturn = sapService.IGN1_Web_Add_ForCangKu(System.DateTime.Now, "由WMS提交-库存收货", shouHuoList);

                strResult = IGNReturn.ResultSucess;
                strError = IGNReturn.ErrMesg;

                //更改收货状态
                if (IGNReturn.ResultSucess == "1")
                {
                    foreach (SapOnlineService.WebShouHuoModel2 shouHuo in shouHuoList)
                    {
                        commBB.ExecuteSql("update dbo.CPickOutPlan set isSAPInStock=1 where absEntry='" + shouHuo.U_PKL
                            + "' and docEntry='" + shouHuo.U_ORDR + "' and materialNo='" + shouHuo.U_ItemCode + "'");
                    }
                }
                else
                {
                    return "0&" + strError;
                }
            }

            #endregion 库存收货

            return strResult;
        }
        finally
        {
            sapService.Dispose();
            saleDetailBB.Dispose();
            commBB.Dispose();
        }
    }
    /// <summary>
    /// 显示备货单信息
    /// </summary>
    private void ShowInfo()
    {
        CStockUpBillBB stockUpBillBB = new CStockUpBillBB();
        LCustBB custBB = new LCustBB();
        CSaleDetailBB saleDetailBB = new CSaleDetailBB();

        try
        {
            string strCustNo = Request.QueryString["custNo"];
            string strSaleBillNos = Request.QueryString["saleBillNos"];//销售订单号
            string strAbsEntrys = Request.QueryString["absEntrys"];//提货单号
            string strFinanceBillNos = Request.QueryString["financeBillNos"];//采购合同号组合
            string strLineNums = Request.QueryString["lineNums"];//行号组合
            string strWhere = "1=1";
            DataSet ds = new DataSet();

            if (Request.Params["id"] != null && Request.Params["id"] != "")
            {
                this.IdValue = Convert.ToInt32(Request.Params["id"]);
                vCStockUpBillData stockUpBillModel = stockUpBillBB.GetVModel(this.IdValue);

                this.StockBillNo = stockUpBillModel.stockUpBillNo;
                this.stockUpBillNo.Text = stockUpBillModel.stockUpBillNo;
                this.shippingMarkNo.Text = stockUpBillModel.shippingMarkNo;
                this.lblCustNm.Text = stockUpBillModel.custNm;
                this.invoiceNo.Text = stockUpBillModel.invoiceNo;
                this.txtstockEmpNm.Text = stockUpBillModel.stockUpEmpNm;
                this.empId.Value = stockUpBillModel.stockUpEmpId.ToString();

                strSaleBillNos = "'" + stockUpBillModel.saleBillNos.Replace(",", "','") + "'";//销售订单编号组合
                strAbsEntrys = "'" + stockUpBillModel.absEntrys.Replace(",", "','") + "'";//提货单编号组合
                strLineNums = "'" + stockUpBillModel.lineNums.Replace(",", "','") + "'";//行号组合

                if (stockUpBillModel.financeBillNos != "")//采购合同号组合
                {
                    strFinanceBillNos = "'" + stockUpBillModel.financeBillNos.Replace(",", "','") + "'";
                }

                this.mark.Text = stockUpBillModel.mark;
                this.outStockDt.Text = Convert.ToDateTime(stockUpBillModel.outStockDt).ToString("yyyy-MM-dd");
            }
            else
            {
                if (strCustNo == null || strCustNo == "")
                {
                    return;
                }

                DataSet dsCust = custBB.GetList(" custNo ='" + strCustNo.Trim() + "'");

                if (dsCust != null && dsCust.Tables[0] != null && dsCust.Tables[0].Rows.Count > 0)
                {
                    this.stockUpBillNo.Text = stockUpBillBB.GetCurrentInBillNoByStockUpBillNo();
                    this.StockBillNo = this.stockUpBillNo.Text;
                    this.CustomNo = strCustNo;
                    this.shippingMarkNo.Text = dsCust.Tables[0].Rows[0]["shippingMark"].ToString();
                    this.lblCustNm.Text = dsCust.Tables[0].Rows[0]["custNm"].ToString();
                }
            }

            //绑定销售订单明细列表
            string[] saleBillNoArray = strSaleBillNos.Split(',');
            string[] absEntryArray = strAbsEntrys.Split(',');
            string[] lineNumArray = strLineNums.Split(',');

            strWhere += " and (";

            for (int i = 0; i < saleBillNoArray.Length; i++)
            {
                if (i == 0)
                {
                    strWhere += " (absEntry=" + absEntryArray[i] + " and saleBillNo=" + saleBillNoArray[i]
                        + " and lineNum=" + lineNumArray[i] + ")";
                }
                else
                {
                    strWhere += " or (absEntry=" + absEntryArray[i] + " and saleBillNo=" + saleBillNoArray[i]
                        + " and lineNum=" + lineNumArray[i] + ")";
                }
            }

            strWhere += ")";

            ds = saleDetailBB.GetVList(strWhere);

            //ds = saleDetailBB.GetVList(" saleBillNo in (" + strSaleBillNos
            //    + ") and absEntry in (" + strAbsEntrys + ") and lineNum in (" + strLineNums + ")");

            this.DtSaleList = ds.Tables[0];
        }
        finally
        {
            stockUpBillBB.Dispose();
            custBB.Dispose();
            saleDetailBB.Dispose();
        }
    }
    /// <summary>
    /// 提交SAP
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCommit_Click(object sender, EventArgs e)
    {
        CSaleDetailBB saleDetailBB = new CSaleDetailBB();
        DMWJEXECUTE services = new DMWJEXECUTE();
        IList<string> messList = new List<string>();
        IList<string> datalist = new List<string>();
        messList.Clear();
        try
        {
            bool isChecked = false;

            //获取选中的数据Id
            foreach (GridViewRow gvrow in this.grid.Rows)
            {
                CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
                if (chkId.Checked == true)
                {
                    string strMaterialNo = "", strInvoiceNo = "", palletNO = "", custNo = "", custNm = "", outdata = ""; ;
                    int docEntry = 0, lineNum = 0;
                    double num = 0;
                    bool isSapOutstock = true;
                    CSaleDetailData saleDetailModel = new CSaleDetailData();

                    docEntry = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["docEntry"].ToString());
                    lineNum = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["lineNum"].ToString());
                    strMaterialNo = this.grid.DataKeys[gvrow.RowIndex]["materialNo"].ToString();
                    num = Convert.ToDouble(this.grid.DataKeys[gvrow.RowIndex]["num"]);
                    strInvoiceNo = this.grid.DataKeys[gvrow.RowIndex]["invoiceNo"].ToString();
                    palletNO = this.grid.DataKeys[gvrow.RowIndex]["palletNo"].ToString();
                   // palletNO = "1";
                    custNo = this.grid.DataKeys[gvrow.RowIndex]["custNo"].ToString();
                    custNm = this.grid.DataKeys[gvrow.RowIndex]["custNm"].ToString();
                    outdata = this.grid.DataKeys[gvrow.RowIndex]["outStockDt"].ToString();
                    string suid = this.grid.DataKeys[gvrow.RowIndex]["suid"].ToString();
                    //获取销售单明细实例
                    saleDetailModel = saleDetailBB.GetModel(Convert.ToInt32(chkId.ValidationGroup));

                    if (Convert.ToBoolean(saleDetailModel.isSapOutStock) == false)
                    {
                        isSapOutstock = false;
                    }

                    if (isSapOutstock == true)
                    {
                        this.BindGrid();
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前到货单下的物料已经提交SAP入库!\");", true);
                        return;
                    }

                    string mess = docEntry + ";" + lineNum + ";"  + strMaterialNo + ";"  + num +";" + strInvoiceNo+";"+Convert.ToString(Convert.ToInt32(chkId.ValidationGroup))+";"+palletNO+";"+custNo+";"+custNm+";"+outdata+";"+suid;
                    messList.Add(mess);
                    datalist.Add(mess);
                    //if (datalist.Count == 0)
                    //{
                    //    datalist.Add(docEntry.ToString() + lineNum.ToString());
                    //}
                    //else
                    //{

                    //    int m = 0;
                    //    for (int i = 0; i < datalist.Count; i++)
                    //    {
                    //        if (docEntry.ToString() + lineNum.ToString() == datalist[i].ToString().ToString())
                    //        {
                    //            m = 1;
                    //            break;
                    //        }

                    //    }
                    //    if (m == 0)
                    //    {
                    //        datalist.Add(docEntry.ToString() + lineNum.ToString());
                    //    }

                    //}

                   // strResult = services.SAPOutStock(Convert.ToInt32(chkId.ValidationGroup), docEntry, lineNum, strMaterialNo, num, strInvoiceNo, palletNO);

                    //if (strResult.Split('&')[0] == "1")
                    //{
                    //    isChecked = true;
                    //}
                    //else if (strResult.Split('&')[0] == "0")
                    //{
                    //    this.BindGrid();
                    //    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + strResult.Split('&')[1] + "\");", true);
                    //    return;
                    //}
                }
            }
            if (messList.Count > 0)
            {
                try
                {
                    IList<string> newMessList = new List<string>();

                    for (int j = 0; j < datalist.Count; j++)
                    {
                        int num =0;
                        for(int i=0;i<messList.Count;i++)
                        {

                            if ((datalist[j].Split(';')[0].ToString() + datalist[j].Split(';')[1].ToString() + datalist[j].Split(';')[2].ToString() ) == (messList[i].Split(';')[0].ToString() + messList[i].Split(';')[1].ToString() + messList[i].Split(';')[2].ToString() ))
                            {
                                num=num+Convert.ToInt32(messList[i].Split(';')[3].ToString());
                               //num =Convert.ToInt32(messList[i].Split(';')[3].ToString());

                                //datalist[i].Split(';')[3] =Convert.ToString(Convert.ToInt32(datalist[i].Split(';')[3].ToString())+Convert.ToInt32(messList[i].Split(';')[3].ToString()));
                            }
                        }
                        string compare =datalist[j].Split(';')[0].ToString() + ";" + datalist[j].Split(';')[1].ToString() + ";" + datalist[j].Split(';')[2].ToString() + ";" + num + ";" + datalist[j].Split(';')[4].ToString() + ";" + datalist[j].Split(';')[5].ToString() + ";" + datalist[j].Split(';')[6].ToString() + ";" + datalist[j].Split(';')[7].ToString() + ";" + datalist[j].Split(';')[8].ToString() + ";" + datalist[j].Split(';')[9].ToString();
                        //datalist[j].Split(';')[3] =Convert.ToString(num);
                        if (newMessList.Count == 0)
                        {
                            newMessList.Add(compare);
                        }
                        else
                        {
                            int nn = 0;
                            for (int m = 0; m < newMessList.Count; m++)
                            {
                                if ((newMessList[m].Split(';')[0].ToString() + newMessList[m].Split(';')[1].ToString() + newMessList[m].Split(';')[2].ToString()) == (compare.Split(';')[0].ToString() + compare.Split(';')[1].ToString() + compare.Split(';')[2].ToString()))
                                {
                                    nn = 1;
                                    break;
                                }

                            }
                            if (nn == 0)
                            {
                                newMessList.Add(compare);
                            }
                        }

                    }

                        SapOnlineService.SapOnlineService sapService = new SapOnlineService.SapOnlineService();
                        SapOnlineService.DLN1New[] list = new SapOnlineService.DLN1New[newMessList.Count];

                        for (int i = 0; i < newMessList.Count; i++)
                        {
                            SapOnlineService.DLN1New por1 = new SapOnlineService.DLN1New();
                            por1.DocEntry = Convert.ToInt32(newMessList[i].Split(';')[0].ToString());
                            por1.LineNum = Convert.ToInt32(newMessList[i].Split(';')[1].ToString());
                            por1.ItemCode = newMessList[i].Split(';')[2].ToString();
                            por1.Quantity = Convert.ToInt32(newMessList[i].Split(';')[3].ToString());
                            list[i] = por1;
                        }

                      string strResult = sapService.AddODLN(newMessList[0].Split(';')[7].ToString(), newMessList[0].Split(';')[8].ToString(), Convert.ToDateTime(newMessList[0].Split(';')[9].ToString()), "由WMS同步", Convert.ToDateTime(newMessList[0].Split(';')[9].ToString()), "由WMS同步", newMessList[0].Split(';')[4].ToString(), list);

                        if (strResult.Split('&')[0] == "1")

                        {
                            for (int i = 0; i < datalist.Count; i++)
                            {
                                CSaleDetailData saleDetailModel = new CSaleDetailData();
                                saleDetailModel = saleDetailBB.GetModel(Convert.ToInt32(datalist[i].Split(';')[5]));

                                //首先要进行判断在CstockUpdetail当中是否所有的数据都已经是‘06’状态,新增06状态用于表示SAP出库已近完成
                                //首先是将状态从05改为06,然后再进行别的处理

                                CStockUpDetailBB bb = new CStockUpDetailBB();

                                bb.ModifyRecord1("06", datalist[i].Split(';')[10]);
                                //bb.ModifyRecord("06", datalist[i].Split(';')[6]);//首先将05的状态改成06 然后
                                if (bb.GetStatus(Convert.ToInt32(datalist[i].Split(';')[5])))
                                {
                                    saleDetailModel.isSapOutStock = true;//是否已提交SAP出库
                                    saleDetailBB.ModifyRecord(saleDetailModel);
                                }
                            }
                            isChecked = true;
                        }
                        else if (strResult.Split('&')[0] == "0")
                        {
                            this.BindGrid();
                            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + strResult.Split('&')[1] + "\");", true);
                            return;
                        }

                        if (isChecked)
                        {
                            this.BindGrid();
                            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"SAP出库成功!\");", true);
                        }

                        // this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + datalist[j].ToString() + "\");", true);

                        //SapOnlineService.SapOnlineService sapService = new SapOnlineService.SapOnlineService();

                        //SapOnlineService.DLN1New[] list = new SapOnlineService.DLN1New[messList.Count];
                        //IList<string> newMessList = new List<string>();
                        //for (int i = 0; i < messList.Count; i++)
                        //{
                        //    if (Convert.ToDateTime(messList[i].Split(';')[9].ToString()).ToString("yyyy-MM-dd") == datalist[j].ToString())
                        //    {
                        //        newMessList.Add(messList[i]);
                        //    }
                        //}
                        //SapOnlineService.SapOnlineService sapService = new SapOnlineService.SapOnlineService();
                        //SapOnlineService.DLN1New[] list = new SapOnlineService.DLN1New[newMessList.Count];

                        //for (int i = 0; i < newMessList.Count; i++)
                        //{
                        //    SapOnlineService.DLN1New por1 = new SapOnlineService.DLN1New();
                        //    por1.DocEntry = Convert.ToInt32(newMessList[i].Split(';')[0].ToString());
                        //    por1.LineNum = Convert.ToInt32(newMessList[i].Split(';')[1].ToString());
                        //    por1.ItemCode = newMessList[i].Split(';')[2].ToString();
                        //    por1.Quantity = Convert.ToInt32(newMessList[i].Split(';')[3].ToString());
                        //    list[i] = por1;
                        //}
                        //string strResult = sapService.AddODLN(newMessList[0].Split(';')[7].ToString(), newMessList[0].Split(';')[8].ToString(), Convert.ToDateTime(newMessList[0].Split(';')[9].ToString()), "由WMS同步", Convert.ToDateTime(newMessList[0].Split(';')[9].ToString()), "由WMS同步", newMessList[0].Split(';')[4].ToString(), list);
                        //if (strResult.Split('&')[0] == "1")
                        //{

                        //    for (int i = 0; i < newMessList.Count; i++)
                        //    {
                        //        CSaleDetailData saleDetailModel = new CSaleDetailData();
                        //        saleDetailModel = saleDetailBB.GetModel(Convert.ToInt32(newMessList[i].Split(';')[5]));

                        //        //首先要进行判断在CstockUpdetail当中是否所有的数据都已经是‘06’状态,新增06状态用于表示SAP出库已近完成
                        //        //首先是将状态从05改为06,然后再进行别的处理

                        //        CStockUpDetailBB bb = new CStockUpDetailBB();
                        //        bb.ModifyRecord("06", newMessList[i].Split(';')[6]);//首先将05的状态改成06 然后
                        //        if (bb.GetStatus(Convert.ToInt32(newMessList[i].Split(';')[5])))
                        //        {
                        //            saleDetailModel.isSapOutStock = true;//是否已提交SAP出库
                        //            saleDetailBB.ModifyRecord(saleDetailModel);
                        //        }
                        //    }
                       // isChecked = true;
                    //    }
                    //    //else if (strResult.Split('&')[0] == "0")
                    //    //{
                    //    //    isChecked = false;
                    //    //    this.BindGrid();
                    //    //    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"日期是" + newMessList[0].Split(';')[9].ToString() + "的数据没有同步成功,SAP返回:"+strResult+"\");", true);
                    //    //    return;
                    //    //}
                    //}

                    //if (isChecked)
                    //{
                    //    this.BindGrid();
                    //    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"SAP出库成功!\");", true);
                    //}
                }
                catch { }
            }
            else if (messList.Count == 0)
            {
                this.BindGrid();
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"对不起你没有选择数据!\");", true);
            }

            //if(messList.Count>0)
            //{
            //    SapOnlineService.SapOnlineService sapService = new SapOnlineService.SapOnlineService();

            //    SapOnlineService.DLN1New[] list = new SapOnlineService.DLN1New[messList.Count];
            //    for (int i = 0; i < messList.Count; i++)
            //    {
            //        SapOnlineService.DLN1New por1 = new SapOnlineService.DLN1New();
            //        por1.DocEntry = Convert.ToInt32(messList[i].Split(';')[0].ToString());
            //        por1.LineNum = Convert.ToInt32(messList[i].Split(';')[1].ToString());
            //        por1.ItemCode = messList[i].Split(';')[2].ToString();
            //        por1.Quantity = Convert.ToInt32(messList[i].Split(';')[3].ToString());
            //        list[i] = por1;
            //    }

            //    string strResult = sapService.AddODLN(messList[0].Split(';')[7].ToString(), messList[0].Split(';')[8].ToString(), Convert.ToDateTime(messList[0].Split(';')[9].ToString()), "由WMS同步", Convert.ToDateTime(messList[0].Split(';')[9].ToString()), "由WMS同步", messList[0].Split(';')[4].ToString(), list);
            //    // string strResult = sapService.AddODLN(Convert.ToInt32(messList[0].Split(';')[0].ToString()), System.DateTime.Today, "从仓库系统生成", messList[0].Split(';')[4].ToString(), list);
            //    // string  strResult = services.SAPOutStock(Convert.ToInt32(chkId.ValidationGroup), docEntry, lineNum, strMaterialNo, num, strInvoiceNo, palletNO);

            //    if (strResult.Split('&')[0] == "1")
            //    {

            //        for (int i = 0; i < messList.Count; i++)
            //        {
            //            CSaleDetailData saleDetailModel = new CSaleDetailData();
            //            saleDetailModel = saleDetailBB.GetModel(Convert.ToInt32(messList[i].Split(';')[5]));

            //            //首先要进行判断在CstockUpdetail当中是否所有的数据都已经是‘06’状态,新增06状态用于表示SAP出库已近完成
            //            //首先是将状态从05改为06,然后再进行别的处理

            //            CStockUpDetailBB bb = new CStockUpDetailBB();
            //            bb.ModifyRecord("06", messList[i].Split(';')[6]);//首先将05的状态改成06 然后
            //            if (bb.GetStatus(Convert.ToInt32(messList[i].Split(';')[5])))
            //            {
            //                saleDetailModel.isSapOutStock = true;//是否已提交SAP出库
            //                saleDetailBB.ModifyRecord(saleDetailModel);
            //            }
            //        }
            //        isChecked = true;
            //    }
            //    else if (strResult.Split('&')[0] == "0")
            //    {
            //        this.BindGrid();
            //        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + strResult.Split('&')[1] + "\");", true);
            //        return;
            //    }

            //    if (isChecked)
            //    {
            //        this.BindGrid();
            //        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"SAP出库成功!\");", true);
            //    }
            //}
            //else if (messList.Count == 0)
            //{
            //    this.BindGrid();
            //    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"对不起你没有选择数据!\");", true);
            //}

        }
        finally
        {
            saleDetailBB.Dispose();
            services.Dispose();
        }
    }