/// <summary>
    /// 提交SAP
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCommit_Click(object sender, EventArgs e)
    {
        DMWJEXECUTE services = new DMWJEXECUTE();
        IList<string> messList = 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)
                {
                    int financeBillId = 0, financeBillLineNum = 0;
                    string strMaterialNo = "", custNo = "", custNm = "";
                    DateTime stockDt, arriveDt;
                    double num = 0;

                    financeBillId = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["financeBillId"]);
                    financeBillLineNum = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["financeBillLineNum"]);
                    strMaterialNo = this.grid.DataKeys[gvrow.RowIndex]["materialNo"].ToString();
                    num = Convert.ToDouble(this.grid.DataKeys[gvrow.RowIndex]["num"]);
                    stockDt = Convert.ToDateTime(this.grid.DataKeys[gvrow.RowIndex]["stockDt"]);
                    arriveDt = Convert.ToDateTime(this.grid.DataKeys[gvrow.RowIndex]["arriveDt"]);
                    custNo = this.grid.DataKeys[gvrow.RowIndex]["custNo"].ToString();
                    custNm = this.grid.DataKeys[gvrow.RowIndex]["custNm"].ToString();

                    string mess = Convert.ToInt32(chkId.ValidationGroup).ToString() + ";" + financeBillId.ToString() + ";" + financeBillLineNum.ToString() + ";" + strMaterialNo + ";" + num.ToString() + ";" + stockDt + ";" + arriveDt + ";" + custNo + ";" + custNm;

                    messList.Add(mess);
                    //strResult = services.SAPInStock(Convert.ToInt32(chkId.ValidationGroup), financeBillId,
                    //    financeBillLineNum, strMaterialNo, num, stockDt, arriveDt, custNo, custNm);

                    //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)
            {
                SapOnlineService.SapOnlineService sapService = new SapOnlineService.SapOnlineService();
                SapOnlineService.POR1[] list = new SapOnlineService.POR1[messList.Count];
                for (int i = 0; i < messList.Count; i++)
                {
                    SapOnlineService.POR1 por1 = new SapOnlineService.POR1();
                    por1.DocEntry = Convert.ToInt32(messList[i].Split(';')[1].ToString());
                    por1.LineNum = Convert.ToInt32(messList[i].Split(';')[2].ToString());
                    por1.ItemCode = messList[i].Split(';')[3].ToString();
                    por1.Quantity = Convert.ToDouble(messList[i].Split(';')[4].ToString());//数量
                    list[i] = por1;
                }
                string strResult = sapService.Web_AddPDN_For_POR1(messList[0].Split(';')[7].ToString(), messList[0].Split(';')[8].ToString(), Convert.ToDateTime(messList[0].Split(';')[5].ToString()), "由WMS同步", Convert.ToDateTime(messList[0].Split(';')[5].ToString()), "由WMS同步", Convert.ToDateTime(messList[0].Split(';')[6].ToString()), list);

                if (strResult.Split('&')[0] == "1")
                {
                    for (int i = 0; i < messList.Count; i++)
                    {
                        BArriveDetailData arriveDetailModel = new BArriveDetailData();
                        BArriveDetailBB arriveDetailBB = new BArriveDetailBB();
                        SCommBB commBB = new SCommBB();
                        arriveDetailModel = arriveDetailBB.GetModel(Convert.ToInt32(messList[i].Split(';')[0]));

                        arriveDetailModel.isSapInStock = true;//是否已提交SAP入库

                        arriveDetailBB.ModifyRecord(arriveDetailModel);

                        //更改物料箱的“是否已提交SAP入库”状态
                        commBB.ExecuteSql(@"update dbo.BArrangeBillBox set isSapInStock=1 where isSapInStock=0
                                       and inStockDt is not null and arriveBillNo='" + arriveDetailModel.arriveBillNo
                                         + "' and financeBillId='" + messList[i].Split(';')[1].ToString() + "' and financeBillLineNum='" + messList[i].Split(';')[2].ToString()
                                         + "' and materialNo='" + messList[i].Split(';')[3].ToString() + "'"
                                         +" or oldMaterialNo ='"+ messList[i].Split(';')[3].ToString() + "'"
                                         +" and  isSapInStock=0  and inStockDt is not null and arriveBillNo='" + arriveDetailModel.arriveBillNo
                                         + "' and financeBillId='" + messList[i].Split(';')[1].ToString() + "' and financeBillLineNum='" + messList[i].Split(';')[2].ToString()+"'");

                    }

                    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);
            }
        }
        catch (Exception error)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + error.Message + "\");", true);
        }
        finally
        {
            services.Dispose();

        }
    }
    /// <summary>
    /// SAP库存收发货
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnToSAPData_Click(object sender, EventArgs e)
    {
        DMWJEXECUTE services = new DMWJEXECUTE();

        try
        {
            //库存收发货
            string strResult = "";

            strResult = services.SAPConverMaterialOutInStock(this.stockUpBillNo.Text, this.mark.Text);

            if (strResult == "1")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"SAP库存收发货成功!\");", true);
            }
            else if (strResult.Split('&')[0] == "0")
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + strResult.Split('&')[1] + "\");", true);
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            services.Dispose();
        }
    }
    /// <summary>
    /// SAP库存收发货
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnToSAPData_Click(object sender, EventArgs e)
    {
        DMWJEXECUTE services = new DMWJEXECUTE();

        try
        {
            //获取选中的数据Id
            foreach (GridViewRow gvrow in this.grid.Rows)
            {
                //库存收发货
                string strStockUpBillNo = "", strResult = "";
                string mark = "";
                strStockUpBillNo = this.grid.DataKeys[gvrow.RowIndex]["stockUpBillNo"].ToString();
                mark = this.grid.DataKeys[gvrow.RowIndex]["mark"].ToString();
                strResult = services.SAPConverMaterialOutInStock(strStockUpBillNo,mark);

                if (strResult == "1")
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"SAP库存收发货成功!\");", true);
                }
                else if (strResult.Split('&')[0] == "0")
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + strResult.Split('&')[1] + "\");", true);
                }
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            services.Dispose();
        }
    }
    /// <summary>
    /// 提交按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCommit_Click(object sender, EventArgs e)
    {
        DMWJEXECUTE services = new DMWJEXECUTE();
        IList<string> messList = 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)
                {
                    int financeBillId = 0, financeBillLineNum = 0;
                    string strMaterialNo = "", custNo = "", custNm = "";
                    string financeBillNo = "";
                    DateTime stockDt, arriveDt;
                    double num = 0;
                    string SAPDocEntry = "";
                    string arrivebillNO = "";
                    //financeBillId = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["financeBillId"]);
                    financeBillLineNum = Convert.ToInt32(this.grid.DataKeys[gvrow.RowIndex]["financeBillLineNum"]);
                    arrivebillNO = this.grid.DataKeys[gvrow.RowIndex]["arriveBillNo"].ToString();
                    financeBillNo = this.grid.DataKeys[gvrow.RowIndex]["financeBillNo"].ToString();
                    SAPDocEntry = arrivebillNO.Remove(0, 2);
                    strMaterialNo = this.grid.DataKeys[gvrow.RowIndex]["materialNo"].ToString();
                    num = Convert.ToDouble(this.grid.DataKeys[gvrow.RowIndex]["num"]);
                    stockDt = Convert.ToDateTime(this.grid.DataKeys[gvrow.RowIndex]["stockDt"]);
                    arriveDt = Convert.ToDateTime(this.grid.DataKeys[gvrow.RowIndex]["arriveDt"]);
                    custNo = this.grid.DataKeys[gvrow.RowIndex]["custNo"].ToString();
                    custNm = this.grid.DataKeys[gvrow.RowIndex]["custNm"].ToString();
                    SapOnlineService.SapOnlineService sapService = new SapOnlineService.SapOnlineService();
                    string strResult = sapService.IGN1_Web_Add_From_WMS(Convert.ToDateTime(stockDt), financeBillNo, int.Parse(SAPDocEntry), strMaterialNo, num, "01");

                    int id = Convert.ToInt32(chkId.ValidationGroup);
                    if (strResult.Split('&')[0] == "1")
                    {

                            BArriveDetailData arriveDetailModel = new BArriveDetailData();
                            BArriveDetailBB arriveDetailBB = new BArriveDetailBB();
                            SCommBB commBB = new SCommBB();
                            arriveDetailModel = arriveDetailBB.GetModel(id);

                            arriveDetailModel.isSapInStock = true;//是否已提交SAP入库

                            arriveDetailBB.ModifyRecord(arriveDetailModel);

                            //更改物料箱的“是否已提交SAP入库”状态
                            commBB.ExecuteSql(@"update dbo.BArrangeBillBox set isSapInStock=1 where isSapInStock=0
                                       and inStockDt is not null and arriveBillNo='" + arriveDetailModel.arriveBillNo
                                             + "'  and financeBillLineNum='" + financeBillLineNum
                                             + "' and materialNo='" +strMaterialNo + "'"
                                             + " or oldMaterialNo ='" +strMaterialNo+ "'"
                                             + " and  isSapInStock=0  and inStockDt is not null and arriveBillNo='" + arriveDetailModel.arriveBillNo
                                             + "'and financeBillLineNum='" + financeBillLineNum + "'");
                            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);
                }

            }

        }
        catch (Exception error)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"" + error.Message + "\");", true);
        }
        finally
        {
            services.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();
        }
    }
    /// <summary>
    /// 生成推荐库位
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSuggetWareLocator_Click(object sender, EventArgs e)
    {
        SCommBB commBB = new SCommBB();

        try
        {
            string strWareLocatorNo = "";

            DMWJEXECUTE dmwj = new DMWJEXECUTE();

            //判断是否生成叉车任务
            DataTable dt = new DataTable();

            dt = commBB.Query("select 1 from dbo.BForkliftTask where palletNo='"
                + this.tbPalletNo.Text.Trim().ToUpper() + "' and isDeal=0").Tables[0];
            if (dt.Rows.Count > 0)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", "alert(\"此托盘已经生成叉车任务\");", true);
                return;
            }

            dt = commBB.Query("select 1 from dbo.BArrangeBillBox where palletNo='" + this.tbPalletNo.Text.Trim().ToUpper() + "'").Tables[0];
            if (dt.Rows.Count == 0)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alertMsg", "alert(\"未收货\");", true);
                return;
            }

            //获取推荐库位信息
            strWareLocatorNo = dmwj.GetPalletWareInfo(this.tbPalletNo.Text.Trim().ToUpper());

            if (strWareLocatorNo != "")
            {
                this.tbWareNo.Text = strWareLocatorNo.Split(',')[0];//推荐库区
                this.tbWareLocatorNo.Text = strWareLocatorNo.Split(',')[1];//推荐库位
            }
        }
        finally
        {
            commBB.Dispose();
        }
    }
    /// <summary>
    /// 生成叉车任务
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnCreateTask_Click(object sender, EventArgs e)
    {
        DMWJEXECUTE dmwj = new DMWJEXECUTE();
        //-----------------------2015-06-26 修改,增加判断是否有不合格的产品,如果有的话,提示并且不生成叉车任务----------------------------
        //-----------------------BarrangBillBox判断boxNo不是拆箱来的,并且checkrusult=0和oldboxNo为null

        //DataTable dt = dmwj.GetBoxByPalletNoWithNoPass(tbPalletNo.Text.Trim());

        //if (dt.Rows.Count > 0)
        //{
        //    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"托盘上有不合格的产品,请确定!\");", true);
        //    return;
        //}

        dmwj.SaveForkliftTask(this.tbPalletNo.Text.Trim(), this.tbWareNo.Text.Trim(), this.tbWareLocatorNo.Text.Trim(), "03", this.currentUser.empId);
        this.tbPalletNo.Text = "T90000";
        this.tbPalletNo.Focus();
        this.tbWareNo.Text = "";
        this.tbWareLocatorNo.Text = "";
    }