Пример #1
0
    /// <summary>
    /// 绑定Grid
    /// </summary>
    protected void BindMateriel()
    {
        LMaterialBB materialBB = new LMaterialBB();
        DataSet ds = new DataSet();

        try
        {
            string strWhere = " 1=1 ";

            if (this.txtNo.Text.Trim() != "")
            {
                strWhere += " and materialNo like '%" + this.txtNo.Text.Replace("'", "''") + "%' ";
            }

            if (this.txtNm.Text.Trim() != "")
            {
                strWhere += " and materialDesc like '%" + this.txtNm.Text.Replace("'", "''") + "%' ";
            }

            ds = materialBB.GetList(strWhere);
            this.grvMateriel.DataSource = ds.Tables[0];
            this.grvMateriel.DataBind();
        }
        finally
        {
            materialBB.Dispose();
        }
    }
Пример #2
0
    /// <summary>
    /// 数据保存
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string strInfo = "";

        if (!this.ValidateData(out strInfo))
        {
            strInfo = strInfo.Replace("\"", "'").Replace("\n", "");
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + strInfo + "');", true);
            return;
        }

        LMaterialData model = new LMaterialData();
        LMaterialBB materialBB = new LMaterialBB();

        try
        {
            if (this.State == "1")
            {
                this.SetModel(ref model);
                model.isrtDt = DateTime.Now.ToString();
                model.isrtEmpId = this.currentUser.empId;
                this.IdValue = materialBB.AddRecord(model);
            }
            else if (this.State == "2")
            {
                model = materialBB.GetModel(this.IdValue);
                this.SetModel(ref model);
                model.updtDt = DateTime.Now.ToString();
                model.updtEmpId = this.currentUser.empId;
                materialBB.ModifyRecord(model);
            }
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            materialBB.Dispose();
        }

        Response.Redirect("LMaterialList.aspx?&itemno=" + this.itemNo + "&pTypeNo=main", false);
    }
Пример #3
0
    protected void BindGrid()
    {
        using (LMaterialBB bb = new LMaterialBB())
        {
            string strwhere = " 1=1 ";
            if (!string.IsNullOrEmpty(txtMaterialno.Text))
            {
                strwhere += "  and materialNo like '%" + txtMaterialno.Text + "%'";
            }

            if (!string.IsNullOrEmpty(txtMaterialnm.Text))
            {
                strwhere += "  and materialDesc like '%" + txtMaterialnm.Text + "%'";
            }
            DataSet ds = bb.GetList(strwhere);
            grid.DataSource = ds;
            grid.DataBind();
        }
    }
Пример #4
0
    /// <summary>
    /// 绑定Grid
    /// </summary>
    protected void BindGrid()
    {
        LMaterialBB materialBB = new LMaterialBB();
        DataSet ds = new DataSet();

        try
        {
            string strWhere = this.StrWhere;

            //物料编码
            if (this.tbMaterialNo.Text.Trim() != "")
            {
                strWhere += " and materialNo like '%" + this.tbMaterialNo.Text.Trim().Replace("'", "''") + "%'";
            }

            //物料名称
            if (this.tbMaterialNm.Text.Trim() != "")
            {
                strWhere += " and materialDesc like '%" + this.tbMaterialNm.Text.Trim().Replace("'", "''") + "%'";
            }

            //货位分类
            if (this.ddlWareSort.SelectedValue != "")
            {
                strWhere += " and wareSortNo='" + this.ddlWareSort.SelectedValue + "'";
            }

            ds = materialBB.GetVList(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
        {
            materialBB.Dispose();
        }
    }
    /// <summary>
    /// 绑定到货物料明细表
    /// </summary>
    protected void BindMateriel()
    {
        string strWhere = "1=1";
        DataSet ds = new DataSet();
        LMaterialBB materialBB = new LMaterialBB();

        //物料
        if (this.txtC.Text.Trim() != "")
        {
            strWhere += " and (materialNo like '%" + this.txtC.Text.Replace("'", "''")
                + "%' or materialDesc like '%" + this.txtC.Text.Replace("'", "''") + "%')";
        }
        ds = materialBB.GetVList(strWhere);
        this.grvMateriel.DataSource = ds.Tables[0];
        this.grvMateriel.DataBind();

        //赋值记录条数、页面总数
        this.Label3.Text = ds.Tables[0].Rows.Count.ToString();
        this.Label2.Text = this.grvMateriel.PageCount.ToString();
        this.currPage.Text = (this.grvMateriel.PageIndex + 1).ToString();
    }
Пример #6
0
    /// <summary>
    /// 展示数据
    /// </summary>
    /// <param name="id">记录Id</param>
    private void ShowInfo(int id)
    {
        LMaterialBB materialBB = new LMaterialBB();
        vLMaterialData model = new vLMaterialData();
        try
        {
            model = materialBB.GetVModel(id);
            this.id.Text = model.id.ToString();
            this.materialNo.Text = model.materialNo;
            this.materialDesc.Text = model.materialDesc;
            this.materialGroup.Text = model.materialGroup.ToString();
            this.invntItem.Text = model.invntItem;
            this.buyUnitMsr.Text = model.buyUnitMsr;
            this.numInBuy.Text = model.numInBuy.ToString();
            this.salUnitMsr.Text = model.salUnitMsr;
            this.numInSale.Text = model.numInSale.ToString();
            this.isStocked.Text = model.isStocked;
            this.isRoutinePackage.Text = model.isRoutinePackage;
            this.isStandardBox.Text = model.isStandardBox;
            this.manBtchNum.Text = model.manBtchNum;
            this.validFor.Text = model.validFor;

            if (model.validFrom != string.Empty && model.validFrom != null)
            {
                DateTime validFrom = Convert.ToDateTime(model.validFrom);
                this.validFrom.Text = validFrom.ToShortDateString();
            }

            if (model.validTo != string.Empty && model.validTo != null)
            {
                DateTime validTo = Convert.ToDateTime(model.validTo);
                this.validTo.Text = validTo.ToShortDateString();
            }

            this.frozenFor.Text = model.frozenFor;

            if (model.frozenFrom != string.Empty && model.frozenFrom != null)
            {
                DateTime frozenFrom = Convert.ToDateTime(model.frozenFrom);
                this.frozenFrom.Text = frozenFrom.ToShortDateString();
            }

            if (model.frozenTo != string.Empty && model.frozenTo != null)
            {
                DateTime frozenTo = Convert.ToDateTime(model.frozenTo);
                this.frozenTo.Text = frozenTo.ToShortDateString();
            }

            this.invntryUom.Text = model.invntryUom;
            this.U_CNSize.Text = model.U_CNSize;
            this.U_ENSize.Text = model.U_ENSize;
            this.U_StanWiht.Text = model.U_StanWiht.ToString();
            this.U_PullStan.Text = model.U_PullStan;
            this.U_DrawHlink.Text = model.U_DrawHlink;
            this.U_LablHlink.Text = model.U_LablHlink;
            this.U_CCVOHlink.Text = model.U_CCVOHlink;
            this.U_UintQty.Text = model.U_UintQty.ToString();
            this.U_BoxQty.Text = model.U_BoxQty.ToString();
            this.U_CodeNo.Text = model.U_CodeNo;
            this.U_BoxSize.Text = model.U_BoxSize;
            this.materialNm_CH.Text = model.materialNm_CH;
            this.materialNm_EN.Text = model.materialNm_EN;
            this.U_PackWay.Text = model.U_PackWay;
            this.wareSortNo.Text = model.wareSortNo;
            this.weightDiffWaring.Text = model.weightDiffWaring.ToString();
        }
        finally
        {
            materialBB.Dispose();
        }
    }
Пример #7
0
    /// <summary>
    /// 绑定Grid
    /// </summary>
    protected void BindGrid()
    {
        LMaterialBB bOMBB = new LMaterialBB();
        DataSet ds = new DataSet();

        try
        {
            string wherestr = " 1=1 ";
            if (!string.IsNullOrEmpty(txtMaterialnm.Text))
            {
                wherestr += "  and  materialDesc='%" + txtMaterialnm.Text.Replace("'", "''") + "%'";
            }
            if (!string.IsNullOrEmpty(txtMaterialno.Text))
            {
                wherestr += "  and  materialno like '%" + txtMaterialno.Text.Replace("'", "''") + "%'";
            }

            ds = bOMBB.GetVList(wherestr);
            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
        {
            bOMBB.Dispose();
        }
    }
    /// <summary>
    /// 验证排托明细数据
    /// </summary>
    /// <returns></returns>
    public bool ValidateArrangeDetail()
    {
        string strCustomNo = "", strFinaceNo = "", strWareSortNo = "";
        bool isSameCustom = true;
        DataRow[] myDataRowArrayResult = null;
        DataRow[] myDataRowArray = null;

        #region 校验排托结果

        myDataRowArrayResult = this.DtResult.Select(" isdel=0");

        if (myDataRowArrayResult.Length == 0)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('请首先排托!');", true);
            return false;
        }

        foreach (DataRow dr in myDataRowArrayResult)
        {
            for (int i = 0; i <= int.Parse(txtRegionNum.Text); i++)
            {
                int regionArrangeBoxNum = 0;
                DataRow[] myDataRowArrayRegion = this.DtResult.Select(" isdel=0 and palletIndex=" + dr["palletIndex"] + " and region=" + i);

                foreach (DataRow dataRow in myDataRowArrayRegion)
                {
                    regionArrangeBoxNum += Convert.ToInt32(dataRow["boxNum"]);
                }

                if (regionArrangeBoxNum > int.Parse(txtMaxNum.Text))
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('托盘【" + dr["palletIndex"] + "】的【"
                        + i.ToString() + "】区域排托箱数超出5箱!');", true);
                    return false;
                }

                if (i == 0 && myDataRowArrayRegion.Length > 0)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('托盘区域不能包含0区域!');", true);
                    return false;
                }
                else
                {
                    //同一托盘同一区域只有一条记录
                    if (myDataRowArrayRegion.Length > 1)
                    {
                        strCustomNo = "";
                        isSameCustom = true;

                        //判断订单类型是否为按单并且是同一个供应商
                        foreach (DataRow dataRow in myDataRowArrayRegion)
                        {
                            if (strCustomNo != "" && dataRow["customNo"].ToString() != strCustomNo)
                            {
                                isSameCustom = false;
                                break;
                            }

                            if (dataRow["customNo"].ToString() != "")
                            {
                                strCustomNo = dataRow["customNo"].ToString();//客户编号
                            }
                        }

                        if (!isSameCustom)
                        {
                            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('同一托盘同一区域必须合并!');", true);
                            return false;
                        }
                    }
                }
            }

            //每个托盘每个区域只能有一条记录
            DataRow[] drs = this.DtResult.Select(" isdel=0 and palletIndex='" + dr["palletIndex"] + "'");
            if (drs.Length > 0)
            {
                strFinaceNo = drs[0]["financeBillNo"].ToString();//采购订单编号
                strCustomNo = drs[0]["customNo"].ToString();//客户编号
                strWareSortNo = drs[0]["wareSortNo"].ToString();//库位类别
            }

            //if (drs.Length > 0 && drs.Length <= 8)
            //{
            //    strFinaceNo = drs[0]["financeBillNo"].ToString();
            //}
            //else
            //{
            //    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('每个托盘的区域数不能超过8个!');", true);
            //    return false;
            //}

            foreach (DataRow d1 in drs)
            {
                //判断是否是同一个供应商
                if (d1["financeBillNo"].ToString() != strFinaceNo)
                {
                    if (strCustomNo != d1["customNo"].ToString() && strWareSortNo != d1["wareSortNo"].ToString())
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('同一托盘只能放置一个采购订单或相同类别库区物料!');", true);
                        return false;
                    }
                }

                if (Convert.ToInt32(d1["boxNum"]) <= 0 || Convert.ToInt32(d1["boxNum"]) > int.Parse(txtMaxNum.Text))
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('箱数请输入小于最大箱数的数据!');", true);
                    return false;
                }

                if (Convert.ToInt32(d1["region"]) > int.Parse(txtRegionNum.Text) || Convert.ToInt32(d1["region"]) <= 0)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('区域数量需要小于最大区域!');", true);
                    return false;
                }
            }
        }

        #endregion 校验排托结果

        #region 校验到货明细

        foreach (DataRow drn in DtDetail.Rows)
        {
            int arrangeBoxNum = 0;

            myDataRowArray = this.DtResult.Select(" isdel=0 and financeBillNo='" + drn["financeBillNo"]
                + "' and materialNo='" + drn["materialNo"] + "'");
            foreach (DataRow dataRow in myDataRowArray)
            {
                arrangeBoxNum += Convert.ToInt32(dataRow["boxNum"]);
            }

            //判断排托数量是否超出到货数量
            if (arrangeBoxNum != Convert.ToInt32(drn["boxNum"]))
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"采购订单【" + drn["financeBillNo"]
                    + "】的物料【" + drn["materialNo"] + "】到货数量为【" + drn["boxNum"].ToString()
                    + "】,排托数量为【" + arrangeBoxNum.ToString() + "】,排托数量与到货数量不相符!\");", true);
                return false;
            }

            if (drn["financeBillSort"].ToString() == "备货")//备货
            {
                LMaterialBB lMaterialBB = new LMaterialBB();

                try
                {
                    LMaterialData lMaterialData = lMaterialBB.GetModel(drn["materialNo"].ToString());

                    if ((lMaterialData.wareSortNo == "B" || lMaterialData.wareSortNo == "C"))
                    {

                        DataRow[] drns = this.DtResult.Select(" isdel=0 and financeBillNo='" + drn["financeBillNo"] + "' and materialNo='" + drn["materialNo"] + "'");
                        foreach (DataRow drns1 in drns)
                        {
                            DataRow[] drnss = this.DtResult.Select(" isdel=0 and   palletIndex=" + drns1["palletIndex"] + " and materialNo<>'" + drn["materialNo"].ToString() + "'");
                            if (drnss.Length > 0)
                            {
                                this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"放置高位货架托盘只允许放置同一种备货物料!\");", true);
                                return false;
                            }
                        }
                    }
                    else if ((lMaterialData.wareSortNo == "A" || lMaterialData.wareSortNo == "D" || lMaterialData.wareSortNo == "E"))
                    {
                        DataRow[] drns = this.DtResult.Select(" isdel=0 and financeBillNo='" + drn["financeBillNo"] + "' and materialNo='" + drn["materialNo"] + "'");
                        foreach (DataRow drns1 in drns)
                        {

                            DataRow[] drnss = this.DtResult.Select(" isdel=0 and   palletIndex=" + drns1["palletIndex"] + " and wareSortNo<>'" + drn["wareSortNo"].ToString() + "'");
                            if (drnss.Length > 0)
                            {
                                this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"只允许放置同一仓库类别的备货物料!\");", true);
                                return false;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
                    return false;
                }
                finally
                {
                    lMaterialBB.Dispose();
                }
            }
        }

        #endregion 校验到货明细

        return true;
    }
    /// <summary>
    /// 新增区域
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnNewArea_Click(object sender, EventArgs e)
    {
        try
        {
            this.SaveStencilDetailViewState();//保存
            bool isChecked = false;

            foreach (GridViewRow gvrow in this.grid.Rows)
            {
                CheckBox chkId = (CheckBox)gvrow.FindControl("chkId");
                DataRow[] myDataRowArray = null;

                if (chkId.Checked == true)
                {
                    isChecked = true;

                    //所选采购订单信息
                    string materialNo = this.grid.DataKeys[gvrow.RowIndex].Values["materialNo"].ToString();
                    string lfinanceBillNo = this.grid.DataKeys[gvrow.RowIndex].Values["financeBillNo"].ToString();
                    string lCustomNo = this.grid.DataKeys[gvrow.RowIndex].Values["customNo"].ToString();
                    string lmaterialDesc = this.grid.DataKeys[gvrow.RowIndex].Values["materialDesc"].ToString();
                    string financeBillSort = this.grid.DataKeys[gvrow.RowIndex].Values["financeBillSort"].ToString();
                    string wareSortNo = this.grid.DataKeys[gvrow.RowIndex].Values["wareSortNo"].ToString();
                    string strWareSortNm = this.grid.DataKeys[gvrow.RowIndex].Values["wareSortNm"].ToString();

                    //判断物料是否有剩余
                    myDataRowArray = this.DtDetail.Select("financeBillNo='" + this.grid.DataKeys[gvrow.RowIndex].Values["financeBillNo"].ToString()
                        + "' and materialNo='" + this.grid.DataKeys[gvrow.RowIndex].Values["materialNo"].ToString() + "'");

                    if (myDataRowArray.Length > 0)
                    {
                        if (myDataRowArray[0]["arrangeBoxNum_leaving"].ToString() == "" || myDataRowArray[0]["arrangeBoxNum_leaving"].ToString() == "0")
                        {
                            this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此物料已经没有剩余!\");", true);
                            return;
                        }
                    }

                    foreach (GridViewRow grow in this.gridDetail.Rows)
                    {
                        CheckBox chkId1 = (CheckBox)grow.FindControl("chkId");
                        if (chkId1.Checked == true)
                        {
                            string arriveBillNo = this.gridDetail.DataKeys[grow.RowIndex].Values["arriveBillNo"].ToString();
                            string financeBillNo = this.gridDetail.DataKeys[grow.RowIndex].Values["financeBillNo"].ToString();
                            string preMaterialNo = this.gridDetail.DataKeys[grow.RowIndex].Values["materialNo"].ToString();
                            string pindex = this.gridDetail.DataKeys[grow.RowIndex].Values["palletIndex"].ToString();
                            string pwareSortNo = this.gridDetail.DataKeys[grow.RowIndex].Values["wareSortNo"].ToString();
                            string strCustomNo = this.gridDetail.DataKeys[grow.RowIndex].Values["customNo"].ToString();

                            if (strCustomNo != lCustomNo && financeBillNo != lfinanceBillNo)
                            {
                                this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"同一托盘只允许放置同一采购订单或同一客户订单物料!\");", true);
                                return;
                            }

                            LMaterialBB materialBB = new LMaterialBB();

                            try
                            {
                                LMaterialData materialModel = new LMaterialData();

                                //判断当前选择物料的货位分类
                                materialModel = materialBB.GetModel(materialNo);

                                if (financeBillSort == "备货"
                                    && (materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C")
                                    && materialNo != preMaterialNo)
                                {
                                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"放置高位货架托盘只允许放置同一种备货物料!\");", true);
                                    return;
                                }
                                else if (financeBillSort == "备货"
                                    && (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D" || materialModel.wareSortNo == "E")
                                    && pwareSortNo != wareSortNo)
                                {
                                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此托盘只允许放置同一仓库类别的备货物料!\");", true);
                                    return;
                                }

                                //判断上一次选择物料的货位分类
                                materialModel = materialBB.GetModel(preMaterialNo);
                                if (financeBillSort == "备货" && (materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C") && materialNo != preMaterialNo)
                                {
                                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"放置高位货架托盘只允许放置同一种备货物料!\");", true);
                                    return;
                                }
                                else if (financeBillSort == "备货" && (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D" || materialModel.wareSortNo == "E") && pwareSortNo != wareSortNo)
                                {
                                    this.ClientScript.RegisterStartupScript(this.GetType(), "alert1", "alert(\"此托盘只允许放置同一仓库类别的备货物料!\");", true);
                                    return;
                                }
                            }
                            catch (Exception ex)
                            {
                                this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
                                return;
                            }
                            finally
                            {
                                materialBB.Dispose();
                            }

                            //求出最大的托盘序号
                            int maxnum = 1;
                            DataRow[] drs = DtResult.Select(" isdel=0 and palletIndex=" + pindex, "region");

                            for (int i = 0; i < drs.Length; i++)
                            {
                                if (Convert.ToInt32(drs[i]["region"]) > maxnum)
                                {
                                    break;
                                }

                                maxnum++;
                            }

                            if (maxnum > int.Parse(txtRegionNum.Text.Trim()))
                            {
                                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"区域必须小于等于设定的托盘区域!\");", true);
                                return;
                            }

                            //记录添加到临时表
                            DataRow dr = this.DtResult.NewRow();

                            dr["wareSortNo"] = wareSortNo;
                            dr["wareSortNm"] = strWareSortNm;
                            dr["rowId"] = Guid.NewGuid().ToString();
                            dr["isdel"] = "0";
                            dr["id"] = 0;
                            dr["boxNum"] = 0;
                            dr["hideAmount"] = 0;
                            dr["ischeck"] = false;
                            dr["arrangeBillNo"] = "PT" + this.ArriveBillNo;
                            dr["arriveBillNo"] = arriveBillNo;
                            dr["materialDesc"] = lmaterialDesc;
                            dr["financeBillNo"] = lfinanceBillNo;
                            dr["materialNo"] = materialNo;
                            dr["region"] = maxnum;
                            dr["palletIndex"] = pindex;//托盘序号
                            dr["customNo"] = lCustomNo;//客户编号

                            this.DtResult.Rows.Add(dr);
                        }
                    }
                }
            }

            if (isChecked == false)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"请选择采购物料和托盘记录!\");", true);
                return;
            }
        }
        finally
        {
            this.BindDetailTable();//绑定排托明细列表
            this.BindGrid();//绑定到货明细列表
        }
    }
Пример #10
0
    public DataTable GetMaterial(string strMaterialNo)
    {
        LMaterialBB materialBB = new LMaterialBB();

        try
        {
            DataTable dt = new DataTable();

            dt = materialBB.GetList("materialNo='" + strMaterialNo + "'").Tables[0];
            return dt;
        }
        finally
        {
            materialBB.Dispose();
        }
    }
Пример #11
0
    /// <summary>
    /// 展示数据
    /// </summary>
    /// <param name="id">记录Id</param>
    private void ShowInfo(int id)
    {
        LMaterialBB materialBB = new LMaterialBB();
        vLMaterialData model = new vLMaterialData();

        try
        {
            model = materialBB.GetVModel(id);

            this.lbMaterialNo.Text = model.materialNo;//物料编码
            this.lbMaterialDesc.Text = model.materialDesc;//物料描述
            this.lbIsRoutinePackageDesc.Text = model.isRoutinePackageDesc;//是否常规包装
            this.lbIsStandardBoxDesc.Text = model.isStandardBoxDesc;//是否标准箱
            this.lbInvntryUom.Text = model.invntryUom;//计量单位
            this.lbU_CNSize.Text = model.U_CNSize;//规格型号
            this.lbU_UintQty.Text = model.U_UintQty.ToString();//单体数量
            this.lbU_BoxQty.Text = model.U_BoxQty.ToString();//整箱数量
            this.lbU_Material.Text = model.U_Material.ToString();//材质
            this.lbU_StanWiht.Text = model.U_StanWiht.ToString();//标准重量
            this.tbSystemWeight.Text = model.systemWeight.ToString();
            this.tbWeightDiffWaring.Text = model.weightDiffWaring.ToString();//单个称重差异预警值(KG)
            this.ddlWareSort.SelectedValue = model.wareSortNo;//库位分类
        }
        finally
        {
            materialBB.Dispose();
        }
    }
    /// <summary>
    /// 手动填写 增加拣货计划
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSaveDetail_Click(object sender, EventArgs e)
    {
        LWareLocatorBB wareLocatorBB = new LWareLocatorBB();
        LMaterialBB materialBB = new LMaterialBB();
        UStockBB stockBB = new UStockBB();
        SCommBB commBB = new SCommBB();
        LMaterialRelationBB materialRelationBB = new LMaterialRelationBB();

        try
        {

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

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

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

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

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

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

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

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

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

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

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

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

            DataRow drnew = this.DtResultNew.NewRow();

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

            drnew["isDel"] = false;

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

            this.DtResultNew.Rows.Add(drnew);

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

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

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

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

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

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

        DataRow[] drsStock = null;

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

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

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

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

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

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

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

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

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

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

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

                    //如果当前库位的物料数量大于备货单所需数量,就保存当前库位
                    DataRow drnew = this.DtResultNew.NewRow();

                    drnew["rowId"] = Guid.NewGuid().ToString();
                    drnew["id"] = 0;

                    if (haveCount >= needCount)
                    {
                        drnew["num"] = needCount;
                    }
                    else
                    {
                        drnew["num"] = haveCount;
                    }

                    drsStock[0]["num"] = Convert.ToInt32(drsStock[0]["num"]) - Convert.ToInt32(drnew["num"]);//库存数量减去已备货数量

                    needCount = needCount - Convert.ToInt32(drnew["num"]);

                    //drnew["stockUpBillNo"] = stockUpBillModel.stockUpBillNo;
                    drnew["palletIndex"] = "1";
                    drnew["wareNo"] = drsStock[0]["wareNo"];
                    drnew["wareLocatorNo"] = drsStock[0]["wareLocatorNo"];
                    drnew["palletNo"] = drsStock[0]["palletNo"];
                    drnew["stockUpMaterialNo"] = strMaterialNo;//备货物料编号
                    drnew["materialNo"] = drsStock[0]["materialNo"];//实际拣货物料编号
                    drnew["instantState"] = "01";
                    drnew["financeBillNo"] = U_PCNo;
                    drnew["docEntry"] = strDocEntry;//销售订单ID
                    drnew["lineNum"] = strLineNum;//行号
                    drnew["isDel"] = false;
                    this.DtResultNew.Rows.Add(drnew);
                    drStockUpDetail["number"] = needCount;//重新赋值拣货数量
                }
                else
                {
                    needCount = 0;
                    // break;
                }

                #endregion 原物料拣货
            }
        }

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

            if (planNum != factNum)
            {
                strInfo += "物料【" + otherOutInBillRow["materialNo"].ToString() + "】,计划拣货【"
                    + planNum.ToString() + "】件,实际拣货【" + factNum.ToString() + "】件;";
                btnSubmit.Enabled = false;
            }
        }
        if (strInfo != "")
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert(\"当前未完成拣货,不允许保存!提示信息:" + strInfo + "\");", true);
            btnSubmit.Enabled = false;
        }
        BindGridPickOutPlan();
        //}
    }
Пример #14
0
    public string GetPalletWareInfo(string strPalletNo)
    {
        string strWareLocatorNo = "";
        BArrangeBillBoxBB arrangeBillBoxBB = new BArrangeBillBoxBB();
        LWareBB wareBB = new LWareBB();
        LWareLocatorBB wareLocatorBB = new LWareLocatorBB();
        LMaterialBB materialBB = new LMaterialBB();
        SCommBB commBB = new SCommBB();

        try
        {
            DataTable dtArrangeBillBox = new DataTable();
            DataTable dtWare = new DataTable();
            DataTable dtWareLocator = new DataTable();

            //获取托盘下的所有箱子
            dtArrangeBillBox = arrangeBillBoxBB.GetVList("palletNo='" + strPalletNo + "' and isnull(wareNo,'')<>''").Tables[0];
            if (dtArrangeBillBox.Rows.Count > 0)
            {
                string strFinanceBillSort = "", strFinanceBillNo = "";

                strFinanceBillSort = dtArrangeBillBox.Rows[0]["financeBillSort"].ToString();//采购合同类型
                strFinanceBillNo = dtArrangeBillBox.Rows[0]["financeBillNo"].ToString();//采购合同号
                if (strFinanceBillSort == "按单" || strFinanceBillNo.IndexOf("EB16") == -1)
                {
                    #region 按单

                    //按单的物料,放置在正式库的平面库区
                    dtWareLocator = wareLocatorBB.GetVList("wareSortNo='A' and wareType='03' and isUsing=0 and isDel=0").Tables[0];
                    if (dtWareLocator.Rows.Count > 0)
                    {
                        strWareLocatorNo = dtWareLocator.Rows[0]["wareNo"].ToString() + ","
                            + dtWareLocator.Rows[0]["wareLocatorNo"].ToString();//库位
                    }

                    #endregion 按单
                }
                else if (strFinanceBillSort == "备货" || strFinanceBillNo.IndexOf("EB16") != -1)
                {
                    #region 备货

                    string strMaterialNos = "", strUCodeNos = "", strWareSortNos = "B";
                    int materialNum = 1;
                    DataTable dtMaterial = new DataTable();

                    //判断当前托盘是否存在多个物料
                    strMaterialNos = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//物料编号
                    strUCodeNos = dtArrangeBillBox.Rows[0]["U_CodeNo"].ToString();//物料U_CodeNo
                    foreach (DataRow row in dtArrangeBillBox.Rows)
                    {
                        if (strMaterialNos.IndexOf(row["materialNo"].ToString()) == -1)
                        {
                            materialNum++;
                            strMaterialNos += "," + row["materialNo"].ToString();//物料编号
                        }

                        if (strUCodeNos.IndexOf(row["U_CodeNo"].ToString()) == -1)
                        {
                            strUCodeNos += "," + row["U_CodeNo"].ToString();//物料U_CodeNo
                        }
                    }

                    if (materialNum == 1)//托盘上只有一种物料
                    {
                        dtMaterial = materialBB.GetList("materialNo='" + strMaterialNos + "'").Tables[0];//获取物料信息
                        strWareSortNos = dtMaterial.Rows[0]["wareSortNo"].ToString();//获取物料的货位分类
                    }
                    else
                    {
                        foreach (DataRow row in dtArrangeBillBox.Rows)
                        {
                            dtMaterial = materialBB.GetList("materialNo='" + row["materialNo"].ToString() + "'").Tables[0];//获取物料信息
                            if (dtMaterial.Rows[0]["wareSortNo"].ToString() != "B")//查找货位分类为非高位货架所有类别
                            {
                                if (strWareSortNos == "B")//如果当前类型为高位货架
                                {
                                    strWareSortNos = dtMaterial.Rows[0]["wareSortNo"].ToString();//货架分类赋新值
                                }
                                else
                                {
                                    if (strWareSortNos.IndexOf(dtMaterial.Rows[0]["wareSortNo"].ToString()) == -1)
                                    {
                                        strWareSortNos += "," + dtMaterial.Rows[0]["wareSortNo"].ToString();
                                    }
                                }
                            }
                        }
                    }

                    if (strWareSortNos == "D" || strWareSortNos == "E")//流利货架摆放不分库位,推荐到库区即可
                    {
                        //获取推荐库区信息
                        dtWare = wareBB.GetVList("wareSortNo='" + strWareSortNos + "' and wareType='03' and isDel=0").Tables[0];
                        if (dtWare.Rows.Count > 0)
                        {
                            strWareLocatorNo = dtWare.Rows[0]["wareNo"].ToString() + ",";//库区
                        }
                    }
                    else//其他货架,推荐到库位
                    {
                        //获取推荐库位信息
                        dtWareLocator = commBB.Query("exec Proc_GetSuggestWareLocator '" + strWareSortNos.Trim(',')
                            + "','" + strUCodeNos.Trim(',') + "','" + strMaterialNos.Trim(',') + "'").Tables[0];
                        if (dtWareLocator.Rows.Count > 0)
                        {
                            strWareLocatorNo = dtWareLocator.Rows[0]["wareNo"].ToString() + ","
                                + dtWareLocator.Rows[0]["wareLocatorNo"].ToString();//库位
                        }
                    }

                    #endregion 备货
                }
            }
        }
        finally
        {
            arrangeBillBoxBB.Dispose();
            wareBB.Dispose();
            wareLocatorBB.Dispose();
            materialBB.Dispose();
            commBB.Dispose();
        }

        return strWareLocatorNo;
    }
Пример #15
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();
        }
    }
Пример #16
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 btnAutoArrange_Click(object sender, EventArgs e)
    {
        //2015-10-21 董利特修改
        //首先用自动排托的功能进行测试
        int maxManualRegion = int.Parse(txtRegionNum.Text.Trim());
        int maxManualNum = int.Parse(txtMaxNum.Text.Trim());
        LMaterialBB materialBB = new LMaterialBB();

        try
        {
            if (this.DtDetail == null || this.DtDetail.Rows.Count <= 0)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "AutoArrange", "alert(\"该到货单没有任何明细,无法自动排拖!\");", true);
            }

            //判断是否已经生成排托明细
            if (this.DtResult.Rows.Count > 0)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "AutoArrange", "alert(\"该到货单已经生成排托明细,无法自动排拖!\");", true);
                return;
            }

            LMaterialData materialModel = new LMaterialData();
            DataView dvArriveDetail = this.DtDetail.DefaultView;

            dvArriveDetail.Sort = "financeBillSort,wareSortNo,financeBillNo,materialNo";//customNo

            //遍历所有到货单的所有物料
            foreach (DataRow drArriveDetail in dvArriveDetail.ToTable().Rows)
            {
                //非标准箱不予排拖
                //if (drArriveDetail["isStandardBox"].ToString() == "0"
                //    || drArriveDetail["isStandardBox"].ToString().Trim() == "N"
                //    || drArriveDetail["isStandardBox"].ToString().Trim() == "")
                //{
                //    continue;
                //}

                if (drArriveDetail["isStandardBox"].ToString().Trim() == "N"
                  || drArriveDetail["isStandardBox"].ToString().Trim() == "")
                {
                    continue;
                }
                int leavingNum = Convert.ToInt32(drArriveDetail["arrangeBoxNum_leaving"]);//到货单明细剩余未排数量
                int maxPalletIndex = 0;//最大托盘序号
                //int empty = 5;//区域空余数量
                int empty = maxManualNum;
                int maxRegion = 1;//区域
                bool isNewPallet = true;//是否需要新托盘
                DataView dvResult = null;

                //采购订单类型  备货
                if (drArriveDetail["financeBillSort"].ToString() == "备货")
                {
                    #region 备货订单排托

                    materialModel = materialBB.GetModel(drArriveDetail["materialNo"].ToString());

                    //物料放置高位货架的
                    if ((materialModel.wareSortNo == "B" || materialModel.wareSortNo == "C"))
                    {
                        #region 物料放置高位货架的,相同物料进行排托

                        dvResult = this.DtResult.DefaultView;
                        dvResult.Sort = "wareSortNo,materialNo,palletIndex";
                        dvResult.RowFilter = "isdel=0  and arriveBillNo='" + drArriveDetail["arriveBillNo"]
                            + "' and wareSortNo='" + drArriveDetail["wareSortNo"].ToString() + "'"
                            + " and materialNo='" + drArriveDetail["materialNo"] + "'";

                        #endregion 物料放置高位货架的,相同物料进行排托
                    }
                    else if (materialModel.wareSortNo == "A" || materialModel.wareSortNo == "D"
                        || materialModel.wareSortNo == "E")
                    {
                        #region 非高位货架 同一区域的排拖

                        dvResult = this.DtResult.DefaultView;
                        dvResult.Sort = "wareSortNo,palletIndex";
                        dvResult.RowFilter = "isdel=0  and arriveBillNo='" + drArriveDetail["arriveBillNo"]
                            + "' and wareSortNo='" + drArriveDetail["wareSortNo"].ToString() + "'";

                        #endregion 非高位货架 同一区域的排拖
                    }

                    #endregion 备货订单排托
                }
                else
                {
                    #region 采购订单类型为按单

                    //找到当前采购订单 同一物料已经排拖的数据
                    //同一客户的不同采购订单的相同物料可以排在同一托盘
                    dvResult = this.DtResult.DefaultView;
                    dvResult.Sort = "customNo,materialNo,financeBillNo,palletIndex,region";
                    dvResult.RowFilter = "isdel=0  and arriveBillNo='" + drArriveDetail["arriveBillNo"]
                        + "' and ((isnull(customNo,'')<>'' and customNo='" + drArriveDetail["customNo"]
                        + "') or (isnull(customNo,'')='' and financeBillNo='" + drArriveDetail["financeBillNo"] + "')) ";

                    #endregion 采购订单类型为按单
                }

                #region 查找有剩余位置的托盘

                //找到同种采购订单,同种物料,有剩余位置的托盘
                if (dvResult.ToTable() != null && dvResult.ToTable().Rows.Count > 0)
                {
                    foreach (DataRow dr in dvResult.ToTable().Rows)
                    {
                        //遍历 同采购订单的同物料并且已经排拖的数据 ,找到 最大的托盘号,以及已经排拖的总数量
                        if (Convert.ToInt32(dr["palletIndex"]) > maxPalletIndex
                            || Convert.ToInt32(dr["region"]) > maxRegion)
                        {
                            //获取当前订单,当前物料的最大托盘号(由于自动排拖,有空余位置的托盘,是最后一个托盘号)
                            maxPalletIndex = Convert.ToInt32(dr["palletIndex"]);
                            maxRegion = Convert.ToInt32(dr["region"]);
                        }
                    }

                    //计算最后一个托盘的空余位置数量
                    DataRow[] drsLastRegion = this.DtResult.Select("palletIndex='" + maxPalletIndex.ToString()
                        + "' and region='" + maxRegion.ToString() + "'");

                    if (drsLastRegion.Length > 0
                        && drsLastRegion[0]["materialNo"] == drArriveDetail["materialNo"])
                    {
                        //查找到相同物料
                        // empty = 5 - Convert.ToInt32(drsLastRegion[0]["boxNum"]);
                        empty = maxManualNum - Convert.ToInt32(drsLastRegion[0]["boxNum"]);

                        if (empty > 0)
                        {
                            isNewPallet = false;//不需要新托盘
                        }
                    }
                    else
                    {
                        if (drsLastRegion.Length > 0
                            && drsLastRegion[0]["materialNo"] != drArriveDetail["materialNo"])
                        {
                            maxRegion++;
                        }
                        //if (maxRegion > 8)
                        if (maxRegion > maxManualRegion)
                        {
                            maxPalletIndex = maxPalletIndex + 1;
                            maxRegion = 1;
                        }
                        else
                        {
                            isNewPallet = false;//不需要新托盘
                        }
                    }
                }

                #endregion 查找有剩余位置的托盘

                #region 生成排托计划

                if (isNewPallet)//需要使用新托盘
                {
                    DataView dvMaxPallet = this.DtResult.DefaultView;

                    dvMaxPallet.RowFilter = "isdel=0 ";
                    dvMaxPallet.Sort = "palletIndex";

                    foreach (DataRow drMaxPallet in dvMaxPallet.ToTable().Rows)
                    {
                        //遍历 同采购订单的同物料并且已经排拖的数据 ,找到 最大的托盘号,以及已经排拖的总数量
                        if (Convert.ToInt32(drMaxPallet["palletIndex"]) > maxPalletIndex)
                        {
                            //获取 最大托盘号+1为新的托盘
                            maxPalletIndex = Convert.ToInt32(drMaxPallet["palletIndex"]);
                        }
                    }

                    maxPalletIndex = maxPalletIndex + 1;
                    maxRegion = 1;
                }

                int lastNum = leavingNum;
                do
                {
                    while (maxRegion <= maxManualRegion && lastNum > 0)
                    {
                        //把之前的托盘不足的补全
                        DataRow drnew = this.DtResult.NewRow();

                        drnew["rowId"] = Guid.NewGuid().ToString();
                        drnew["isdel"] = "0";
                        drnew["id"] = 0;
                        drnew["boxNum"] = lastNum >= empty ? empty : lastNum;//要补全的托盘,如果剩余不足,数量就等于剩余数量
                        drnew["hideAmount"] = lastNum >= empty ? empty : lastNum;
                        drArriveDetail["arrangeBoxNum_leaving"] = Convert.ToInt32(drArriveDetail["arrangeBoxNum_leaving"]) - (lastNum >= empty ? empty : lastNum);//采购订单明细扣除相应已经排拖的数量
                        drArriveDetail["arrangeBoxNum"] = Convert.ToInt32(drArriveDetail["arrangeBoxNum"]) + (lastNum >= empty ? empty : lastNum);//采购订单明细扣除相应已经排拖的数量
                        drnew["ischeck"] = false;
                        drnew["arrangeBillNo"] = "PT" + this.ArriveBillNo;
                        drnew["arriveBillNo"] = drArriveDetail["arriveBillNo"];
                        drnew["materialDesc"] = drArriveDetail["materialDesc"];
                        drnew["financeBillNo"] = drArriveDetail["financeBillNo"];
                        drnew["materialNo"] = drArriveDetail["materialNo"];
                        drnew["wareSortNo"] = drArriveDetail["wareSortNo"];
                        drnew["wareSortNm"] = drArriveDetail["wareSortNm"];
                        drnew["region"] = maxRegion;
                        drnew["palletIndex"] = maxPalletIndex;//托盘序号
                        drnew["customNo"] = drArriveDetail["customNo"];//客户编号

                        this.DtResult.Rows.Add(drnew);

                        maxRegion = maxRegion + 1;
                        lastNum = lastNum - empty;
                        //empty = 5;
                        empty = maxManualNum;
                    }

                    maxPalletIndex += 1;
                    maxRegion = 1;
                } while (lastNum > 0);

                #endregion 生成排托计划
            }

            this.BindDetailTable();//绑定排托明细列表
            this.SaveStencilDetailViewState();//保存
            this.BindGrid();//绑定到货明细列表
        }
        catch (Exception ex)
        {
            this.ClientScript.RegisterStartupScript(this.GetType(), "ShowErr", "ShowErr(\"" + Server.UrlEncode(ex.Message) + "\",3);", true);
            return;
        }
        finally
        {
            materialBB.Dispose();
        }
    }