Пример #1
0
        /// <summary>
        /// 执行叉车任务
        /// </summary>
        /// <returns></returns>
        public bool ExecuteEffectForkliftTask(int taskId)
        {
            bool ret = false;
            SqlTransaction trans = null;
            SCommBB commBB = new SCommBB(this.connection);
            BTallyBillBB tallyBillBB = new BTallyBillBB(this.connection);
            UStockBB stockBB = new UStockBB(this.connection);
            UStockOutInDetailBB stockOutInDetailBB = new UStockOutInDetailBB(this.connection);
            BArrangeBillBoxBB arrangeBillBoxBB = new BArrangeBillBoxBB(this.connection);
            BTallyBillDetailBB tallyBillDetailBB = new BTallyBillDetailBB();
            LMaterialBB materialBB = new LMaterialBB();
            LWareLocatorBB wareLocatorBB = new LWareLocatorBB();
            LWareBB wareBB = new LWareBB();
            CPickOutPlanBB pickOutPlanBB = new CPickOutPlanBB();
            CDEPickOutBoxBB DEPickOutBoxBB = new CDEPickOutBoxBB(this.connection);

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransSave");
                    this.forkliftTaskBB.Transaction = trans;
                    commBB.Transaction = trans;
                    tallyBillBB.Transaction = trans;
                    stockBB.Transaction = trans;
                    stockOutInDetailBB.Transaction = trans;
                    arrangeBillBoxBB.Transaction = trans;
                    DEPickOutBoxBB.Transaction = trans;

                }
                else
                {
                    this.forkliftTaskBB.Transaction = this.transaction;
                    commBB.Transaction = this.transaction;
                    tallyBillBB.Transaction = this.transaction;
                    stockBB.Transaction = this.transaction;
                    stockOutInDetailBB.Transaction = this.transaction;
                    arrangeBillBoxBB.Transaction = this.transaction;
                    DEPickOutBoxBB.Transaction = this.transaction;
                }

                BForkliftTaskData forkliftTaskModel = new BForkliftTaskData();
                UStockData stockModel = new UStockData();
                UStockOutInDetailData stockOutInDetailModel = new UStockOutInDetailData();
                DataTable dtPreWare = new DataTable();
                DataTable dtNextWare = new DataTable();
                DataTable dtBox = new DataTable();
                DataTable dtMaterial = new DataTable();
                DataTable dtPallet = new DataTable();

                string strSql = "";

                #region 修改叉车任务的处理信息

                //修改叉车任务的处理信息
                forkliftTaskModel = forkliftTaskBB.GetModel(taskId);

                forkliftTaskModel.isDeal = true;
                forkliftTaskModel.dealEmpId = this.empId;
                forkliftTaskModel.dealDt = System.DateTime.Now.ToString();

                //if (forkliftTaskModel.taskType == "01")
                //{

                //}
                //forkliftTaskBB.ModifyRecord(forkliftTaskModel);

                #endregion 修改叉车任务的处理信息

                //获取源库区信息
                dtPreWare = wareBB.GetList("wareNo='" + forkliftTaskModel.preWareNo + "'").Tables[0];

                //获取目的库区信息
                dtNextWare = wareBB.GetList("wareNo='" + forkliftTaskModel.nextWareNo + "'").Tables[0];

                //获取托盘上的所有物料箱
                dtPallet = arrangeBillBoxBB.GetList("palletNo='" + forkliftTaskModel.palletNo + "' and isnull(wareNo,'')<>''").Tables[0];

                //2015-01-30 添加 用于增加备货单号
                if (forkliftTaskModel.taskType == "01")
                {
                    if (dtPallet.Rows.Count > 0)
                    {
                        forkliftTaskModel.stockUpBillNo = dtPallet.Rows[0]["arriveBillNo"].ToString();
                    }
                }
                forkliftTaskBB.ModifyRecord(forkliftTaskModel);
                if (dtPallet.Rows.Count == 0)
                {
                    //如果托盘上没有箱,释放库位
                    commBB.ExecuteSql("update dbo.LWareLocator set isUsing=0 where wareLocatorNo='"
                        + forkliftTaskModel.nextLocatorNo + "'");
                }

                #region 更改箱子库位

                //更改流利货架拣货箱库位信息
                commBB.ExecuteSql("update dbo.CDEPickOutBox set isOutStock=1,updtDt=getDate(),updtEmpId="
                        + this.EmpID.ToString() + " where palletNo='" + forkliftTaskModel.palletNo + "' and isOutStock=0");

                //更改排托箱库位信息
                commBB.ExecuteSql("update dbo.BArrangeBillBox set preWareNo=wareNo,wareNo='" + forkliftTaskModel.nextWareNo
                    + "',preWareLocatorNo=wareLocatorNo,wareLocatorNo='" + forkliftTaskModel.nextLocatorNo
                    + "' where palletNo='" + forkliftTaskModel.palletNo + "' and isnull(wareNo,'')<>''");

                #endregion 更改箱子库位

                //释放源库位
                commBB.ExecuteSql("update dbo.LWareLocator set isUsing=0 where wareLocatorNo='"
                    + forkliftTaskModel.preLocatorNo + "'");

                if (forkliftTaskModel.taskType == "03" || forkliftTaskModel.taskType == "11")
                {
                    #region 从理货区到正式库区、从质检区到正式库区(非标准箱)

                    object obj = null;
                    int tallyBillId = 0;
                    BTallyBillData tallyBillModel = new BTallyBillData();

                    obj = commBB.ExecuteScalar("select top 1 id from dbo.BTallyBill where palletNo='"
                        + forkliftTaskModel.palletNo + "' and instantState='02' order by id desc");
                    if (obj != null)
                    {
                        #region 修改排托单信息

                        tallyBillId = Convert.ToInt32(obj);
                        tallyBillModel = tallyBillBB.GetModel(tallyBillId);

                        tallyBillModel.instantState = "03";//指定状态为“已入库”
                        tallyBillModel.isInStock = true;// 入库状态
                        tallyBillModel.wareNo = forkliftTaskModel.nextWareNo;//库区
                        tallyBillModel.wareLocatorNo = forkliftTaskModel.nextLocatorNo;//库位

                        tallyBillBB.ModifyRecord(tallyBillModel);

                        #endregion 修改排托单信息
                    }

                    #region 出入库和出入库明细数据操作

                    if (dtNextWare.Rows[0]["wareSortNo"].ToString() != "D"
                        && dtNextWare.Rows[0]["wareSortNo"].ToString() != "E")
                    {
                        dtBox = arrangeBillBoxBB.GetVList("palletNo='" + forkliftTaskModel.palletNo + "' and isnull(wareNo,'')<>''").Tables[0];

                        for (int i = 0; i < dtBox.Rows.Count; i++)
                        {
                            dtMaterial = materialBB.GetList("materialNo='" + dtBox.Rows[i]["materialNo"].ToString() + "'").Tables[0];

                            //保存库存明细数据
                            stockModel = new UStockData();

                            stockModel.wareNo = forkliftTaskModel.nextWareNo;//仓库
                            stockModel.wareLocatorNo = forkliftTaskModel.nextLocatorNo;//库位
                            stockModel.stockDt = System.DateTime.Today.ToString();//库存日期
                            stockModel.palletNo = forkliftTaskModel.palletNo;//托盘号
                            stockModel.materialNo = dtBox.Rows[i]["materialNo"].ToString();//物料编号
                            stockModel.boxNo = dtBox.Rows[i]["boxNo"].ToString();//箱号
                            stockModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                            stockModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                            stockModel.num = Convert.ToDouble(dtBox.Rows[i]["leavingNum"])
                                + Convert.ToDouble(dtBox.Rows[i]["DEPickOutNum"]);//数量
                            stockModel.isOutStocking = false;//是否正在出库
                            stockModel.stockMark = "从理到正式库2";
                            stockModel.isrtDt = System.DateTime.Now.ToString();//操作时间
                            stockModel.isrtEmpId = this.EmpID;//操作人

                            stockBB.AddRecord(stockModel);

                            //保存出入库明细数据
                            stockOutInDetailModel = new UStockOutInDetailData();

                            stockOutInDetailModel.billNo = dtBox.Rows[i]["arriveBillNo"].ToString();//单据编号
                            stockOutInDetailModel.outInType = "05";//理货入库
                            stockOutInDetailModel.isOut = false;//是否出库
                            stockOutInDetailModel.stockDt = System.DateTime.Today.ToString();//库存日期
                            stockOutInDetailModel.dt = System.DateTime.Today.ToString();//操作日期
                            stockOutInDetailModel.wareNo = forkliftTaskModel.nextWareNo;//仓库
                            stockOutInDetailModel.wareLocatorNo = forkliftTaskModel.nextLocatorNo;//库位
                            stockOutInDetailModel.salverNo = forkliftTaskModel.palletNo;//托盘号
                            stockOutInDetailModel.boxNo = dtBox.Rows[i]["boxNo"].ToString();//箱号
                            stockOutInDetailModel.materialNo = dtBox.Rows[i]["materialNo"].ToString();//物料编号
                            stockOutInDetailModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                            stockOutInDetailModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                            stockOutInDetailModel.num = Convert.ToDouble(dtBox.Rows[i]["leavingNum"])
                                + Convert.ToDouble(dtBox.Rows[i]["DEPickOutNum"]);//数量
                            stockOutInDetailModel.isrtEmpId = this.empId;
                            stockOutInDetailModel.isrtDt = System.DateTime.Now.ToString();

                            stockOutInDetailBB.AddRecord(stockOutInDetailModel);

                            //更改排托箱入库信息
                            commBB.ExecuteSql("update dbo.BArrangeBillBox set inStockDt=getDate(),inStockEmpId="
                                + this.EmpID.ToString() + ",inStockNum='" + stockOutInDetailModel.num.ToString()
                                + "' where boxNo='" + stockOutInDetailModel.boxNo
                                + "' and isnull(wareNo,'')<>'' and inStockDt is null");
                        }
                    }

                    //更改排托箱检测结果
                    commBB.ExecuteSql("update dbo.BArrangeBillBox set checkResult=1,checkResultDt=getDate(),checkResultEmpId="
                        + this.EmpID.ToString() + " where palletNo='" + forkliftTaskModel.palletNo
                        + "' and isnull(wareNo,'')<>'' and checkResult=0 and checkResultDt is null");

                    #endregion 出入库和出入库明细数据操作

                    #endregion 从理货区到正式库区、从质检区到正式库区
                }
                else if (forkliftTaskModel.taskType == "05")
                {
                    #region 05 从正式库区到拣货区

                    //更改排托箱库位信息-库位赋值原库位
                    //commBB.ExecuteSql("update dbo.BArrangeBillBox set wareNo=preWareNo,wareLocatorNo=preWareLocatorNo where palletNo='"
                    //    + forkliftTaskModel.palletNo + "' and isnull(wareNo,'')<>''");

                    //锁定原库位
                    //commBB.ExecuteSql("update dbo.LWareLocator set isUsing=1 where wareLocatorNo='"
                    //    + forkliftTaskModel.preLocatorNo + "'");

                    #endregion 05 从正式库区到拣货区
                }
                else if (forkliftTaskModel.taskType == "06")
                {
                    #region 从拣货区到正式库区

                    //库存处理放在包装线体上

                    ////获取托盘箱明细
                    //dtBox = arrangeBillBoxBB.GetVList("palletNo='" + forkliftTaskModel.palletNo
                    //    + "' and isnull(wareNo,'')<>''").Tables[0];

                    //if (dtNextWare.Rows[0]["wareSortNo"].ToString() != "D"
                    //        && dtNextWare.Rows[0]["wareSortNo"].ToString() != "E")
                    //{
                    //    for (int i = 0; i < dtBox.Rows.Count; i++)
                    //    {
                    //        //保存库存明细数据
                    //        stockModel = new UStockData();

                    //        stockModel.wareNo = forkliftTaskModel.nextWareNo;//仓库
                    //        stockModel.wareLocatorNo = forkliftTaskModel.nextLocatorNo;//库位
                    //        stockModel.stockDt = System.DateTime.Today.ToString();//库存日期
                    //        stockModel.palletNo = forkliftTaskModel.palletNo;//托盘号
                    //        stockModel.materialNo = dtBox.Rows[i]["materialNo"].ToString();//物料编号
                    //        stockModel.boxNo = dtBox.Rows[i]["boxNo"].ToString();//箱号
                    //        stockModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                    //        stockModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                    //        stockModel.num = Convert.ToDouble(dtBox.Rows[i]["leavingNum"])
                    //            + Convert.ToDouble(dtBox.Rows[i]["DEPickOutNum"]);//数量
                    //        //stockModel.isOutStocking = Convert.ToBoolean(dtBox.Rows[i]["isOutStocking"]);//是否正在出库
                    //        stockModel.isOutStocking = false;//是否正在出库
                    //        stockModel.stockMark = "从拣货返回正式库";
                    //        stockModel.isrtDt = System.DateTime.Now.ToString();//操作时间
                    //        stockModel.isrtEmpId = this.EmpID;//操作人

                    //        stockBB.AddRecord(stockModel);

                    //        //保存出入库明细数据
                    //        stockOutInDetailModel = new UStockOutInDetailData();

                    //        stockOutInDetailModel.billNo = "";//单据编号
                    //        stockOutInDetailModel.outInType = "09";//拣货返回正式库
                    //        stockOutInDetailModel.isOut = false;//是否出库
                    //        stockOutInDetailModel.stockDt = System.DateTime.Today.ToString();//库存日期
                    //        stockOutInDetailModel.dt = System.DateTime.Today.ToString();//操作日期
                    //        stockOutInDetailModel.wareNo = forkliftTaskModel.nextWareNo;//仓库
                    //        stockOutInDetailModel.wareLocatorNo = forkliftTaskModel.nextLocatorNo;//库位
                    //        stockOutInDetailModel.salverNo = forkliftTaskModel.palletNo;//托盘号
                    //        stockOutInDetailModel.boxNo = dtBox.Rows[i]["boxNo"].ToString();//箱号
                    //        stockOutInDetailModel.materialNo = dtBox.Rows[i]["materialNo"].ToString();//物料编号
                    //        stockOutInDetailModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                    //        stockOutInDetailModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                    //        stockOutInDetailModel.num = Convert.ToDouble(dtBox.Rows[i]["leavingNum"])
                    //            + Convert.ToDouble(dtBox.Rows[i]["DEPickOutNum"]);//数量

                    //        stockOutInDetailBB.AddRecord(stockOutInDetailModel);

                    //        //更改物料箱是否正在出库状态
                    //        commBB.ExecuteSql("update dbo.BArrangeBillBox set isOutStocking=0 where boxNo='"
                    //            + dtBox.Rows[i]["boxNo"].ToString() + "'");

                    //        //更改排托箱入库信息
                    //        commBB.ExecuteSql("update dbo.BArrangeBillBox set inStockDt=getDate(),inStockEmpId="
                    //            + this.EmpID.ToString() + ",inStockNum='" + stockOutInDetailModel.num.ToString()
                    //            + "' where boxNo='" + stockOutInDetailModel.boxNo
                    //            + "' and isnull(wareNo,'')<>'' and inStockDt is null");
                    //    }
                    //}

                    #endregion 从拣货区到正式库区
                }
                else if (forkliftTaskModel.taskType == "07")
                {
                    #region 从拣货区出库

                    //根据托盘号,更改备货单明细的状态(05 出库完成)
                    strSql = "update dbo.CStockUpDetail set instantState='05' where palletNo='" + forkliftTaskModel.palletNo + "'";
                    commBB.ExecuteSql(strSql);

                    //如果备货单明细的状态全部为“05 出库完成”,更改备货单状态为“10 出库完成”
                    strSql = @"update dbo.CStockUpBill set instantState='10'
                           where not exists(select 1 from dbo.CStockUpDetail as t where t.stockUpBillNo=dbo.CStockUpBill.stockUpBillNo and instantState<>'05')";
                    commBB.ExecuteSql(strSql);
                    //如果备货单明细的状态不全为“05 出库完成”,更改备货单状态为“09 出库中”
                    strSql = @"update dbo.CStockUpBill set instantState='09'
                           where exists(select 1 from dbo.CStockUpDetail as t where t.stockUpBillNo=dbo.CStockUpBill.stockUpBillNo and instantState<>'05')";
                    commBB.ExecuteSql(strSql);

                    #endregion 从拣货区出库
                }
                else if (forkliftTaskModel.taskType == "09")
                {
                    #region 从排托区返回收货区

                    //更改到货箱库位信息
                    commBB.ExecuteSql("update dbo.BArrangeBillBox set isPalletUsing=0 where palletNo='"
                        + forkliftTaskModel.palletNo + "' and isnull(wareNo,'')<>''");

                    #endregion 从排托区返回收货区
                }
                else if (forkliftTaskModel.taskType == "10")
                {
                    #region 从收货区到质检区(非标准箱)

                    //更改到货箱库位信息
                    //commBB.ExecuteSql("update dbo.BArrangeBillBox set isPalletUsing=0 where palletNo='" + forkliftTaskModel.palletNo + "' and isnull(wareNo)<>''");

                    #endregion 从收货区到质检区(非标准箱)
                }
                else if (forkliftTaskModel.taskType == "12")
                {
                    #region 移库处理

                    #region 源库区、库位处理

                    //释放源正式库位
                    commBB.ExecuteSql("update dbo.LWareLocator set isUsing=0 where wareLocatorNo='"
                        + forkliftTaskModel.preLocatorNo + "'");

                    //如果从正式库出,删除库存明细
                    if (dtPreWare.Rows[0]["wareType"].ToString() == "03")//正式库区
                    {
                        //删除库存明细(处理逻辑以后更改成正常的出入库明细)
                        commBB.ExecuteSql("delete from dbo.UStock where palletNo='" + forkliftTaskModel.palletNo + "'");

                        //增加出入库明细-出库
                    }

                    #endregion 源库区、库位处理

                    #region 目的库区、库位处理

                    //占用目的库位
                    commBB.ExecuteSql("update dbo.LWareLocator set isUsing=1 where wareLocatorNo='"
                        + forkliftTaskModel.nextLocatorNo + "'");

                    if (dtNextWare.Rows[0]["wareType"].ToString() == "03")//正式库区
                    {
                        //DataTable dtDEPickOutBox = new DataTable();

                        ////获取原托盘所在库位
                        //dtArrangeBillBox = arrangeBillBoxBB.GetList("palletNo='" + forkliftTaskModel.palletNo + "' and isnull(wareNo,'')<>''").Tables[0];

                        ////获取流利货架拣货箱信息
                        //dtDEPickOutBox = DEPickOutBoxBB.GetList("palletNo='" + forkliftTaskModel.palletNo + "' and isOutStock=0").Tables[0];

                        ////排托箱信息入正式库
                        //for (int i = 0; i < dtArrangeBillBox.Rows.Count; i++)
                        //{
                        //    dtMaterial = materialBB.GetList("materialNo='" + dtArrangeBillBox.Rows[i]["materialNo"].ToString() + "'").Tables[0];

                        //    //保存库存明细数据
                        //    stockModel = new UStockData();

                        //    stockModel.wareNo = forkliftTaskModel.nextWareNo;//仓库
                        //    stockModel.wareLocatorNo = forkliftTaskModel.nextLocatorNo;//库位
                        //    stockModel.stockDt = System.DateTime.Today.ToString();//库存日期
                        //    stockModel.palletNo = forkliftTaskModel.palletNo;//托盘号
                        //    stockModel.materialNo = dtArrangeBillBox.Rows[i]["materialNo"].ToString();//物料编号
                        //    stockModel.boxNo = dtArrangeBillBox.Rows[i]["boxNo"].ToString();//箱号
                        //    stockModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                        //    stockModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                        //    stockModel.num = Convert.ToDouble(dtArrangeBillBox.Rows[i]["leavingNum"]) + Convert.ToDouble(dtArrangeBillBox.Rows[i]["DEPickOutNum"]);//数量
                        //    stockModel.isOutStocking = false;//是否正在出库
                        //    stockModel.stockMark = "移库(正式箱)";

                        //    stockBB.AddRecord(stockModel);
                        //}

                        ////流利货架拣货箱信息入正式库
                        //for (int i = 0; i < dtDEPickOutBox.Rows.Count; i++)
                        //{
                        //    dtMaterial = materialBB.GetList("materialNo='" + dtDEPickOutBox.Rows[i]["materialNo"].ToString() + "'").Tables[0];

                        //    //保存库存明细数据
                        //    stockModel = new UStockData();

                        //    stockModel.wareNo = forkliftTaskModel.nextWareNo;//仓库
                        //    stockModel.wareLocatorNo = forkliftTaskModel.nextLocatorNo;//库位
                        //    stockModel.stockDt = System.DateTime.Today.ToString();//库存日期
                        //    stockModel.palletNo = forkliftTaskModel.palletNo;//托盘号
                        //    stockModel.materialNo = dtDEPickOutBox.Rows[i]["materialNo"].ToString();//物料编号
                        //    stockModel.boxNo = dtDEPickOutBox.Rows[i]["boxNo"].ToString();//箱号
                        //    stockModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                        //    stockModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                        //    stockModel.num = Convert.ToDouble(dtDEPickOutBox.Rows[i]["num"]);//数量
                        //    stockModel.isOutStocking = false;//是否正在出库
                        //    stockModel.stockMark = "移库(拣货箱)";

                        //    stockBB.AddRecord(stockModel);
                        //}
                    }

                    #endregion 目的库区、库位处理

                    #endregion 移库处理
                }
                else if (forkliftTaskModel.taskType == "20")
                {
                    //托盘出库
                    DataTable dt = new DataTable();
                    dt = arrangeBillBoxBB.GetListOnlyStockUpBillNO("palletNo ='" + forkliftTaskModel.palletNo + "' and ISNULL(stockUpBillNo,'')<>''").Tables[0];

                    commBB.ExecuteSql("update dbo.BArrangeBillBox set oldPalletNo=palletNo,palletNo='',preWareNo=wareNo,wareNo='',preWareLocatorNo=wareLocatorNo,wareLocatorNo='',"
                          + "outStockDt=getDate(),outStockEmpId=" + this.EmpID.ToString()
                          + " where palletNo='" + forkliftTaskModel.palletNo + "' and isnull(wareNo,'')<>''");
                    commBB.ExecuteSql("update dbo.LWareLocator set isUsing=0 where wareLocatorNo='"
               + forkliftTaskModel.preLocatorNo + "'");

                    for (int i = 0; i < dt.Rows.Count; i++)
                    {

                        strSql = @"update dbo.CStockUpDetail set instantState='05' where stockUpBillNo ='" + dt.Rows[i]["stockUpBillNo"].ToString() + "'";
                        commBB.ExecuteSql(strSql);
                        //如果备货单明细的状态全部为“05 出库完成”,更改备货单状态为“10 出库完成”,并且是关联到一个被货单的形式下
                        strSql = @"update dbo.CStockUpBill set instantState='10'
                           where stockUpBillNo = '" + dt.Rows[i]["stockUpBillNO"].ToString() + "'";
                        commBB.ExecuteSql(strSql);
                    }

                }
                else if (forkliftTaskModel.taskType == "30")//从质检区到异常区
                {
                    //首先作出库处理
                    //string command = @"Update BArrangeBillBox set oldPalletNo=palletNo,palletNo='',preWareNo=wareNo,wareNo='YCQ',preWareLocatorNo=wareLocatorNo,wareLocatorNo='N01.01',"
                    //      + "outStockDt=getDate(),outStockEmpId=" + this.EmpID.ToString()
                    //      + " where palletNo='" + forkliftTaskModel.palletNo + "' and isnull(wareNo,'')<>''";
                    //commBB.ExecuteSql(command);

                     DataSet ds = commBB.Query("select palletNo from BArrangeBillBox where wareLocatorNo = '" + forkliftTaskModel.preLocatorNo + "' group by palletNo");

                     if (ds.Tables[0].Rows.Count <= 1)
                     {
                         commBB.ExecuteSql("Update dbo.LWareLocator set isUsing=0 where wareLocatorNo='"  + forkliftTaskModel.preLocatorNo + "'");
                     }
                    commBB.ExecuteSql("Update dbo.LWareLocator set isUsing=0 where wareLocatorNo='" + forkliftTaskModel.nextLocatorNo + "'");//N01.01不占用

                }

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch (Exception ex)
            {
                if (this.transaction == null) trans.Rollback("TransSave");
                throw ex;
            }
            finally
            {
                commBB.Dispose();
                tallyBillBB.Dispose();
                stockBB.Dispose();
                stockOutInDetailBB.Dispose();
                tallyBillDetailBB.Dispose();
                arrangeBillBoxBB.Dispose();
                materialBB.Dispose();
                wareLocatorBB.Dispose();
                wareBB.Dispose();
                pickOutPlanBB.Dispose();
                DEPickOutBoxBB.Dispose();
            }

            return ret;
        }
        /// <summary>
        /// 增加一条信息
        /// </summary>
        /// <param name="dtPlan"></param>
        /// <param name="strStockUpBillNo"></param>
        /// <param name="issubmit"></param>
        /// <returns></returns>
        public bool SavePickOutPlanBill(DataTable dtPlan, string strStockUpBillNo, bool issubmit)
        {
            bool ret = false;
            UStockBB stockBB = new UStockBB(this.connection);
            SCommBB commBB = new SCommBB(this.connection);
            SqlTransaction trans = null;

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

                OtherOutInPickOutPlanData pickOutPlanModel = new OtherOutInPickOutPlanData();
                OtherOutInPickOutPlanBB stockUpBillNo = new OtherOutInPickOutPlanBB();
                string stockUpBillNOValue = stockUpBillNo.GetCurrentInBillNoByStockUpBillNoByQT();

                int SAPDocEntry = 0;
                #region 逐条保存拣货计划

                //逐条保存拣货计划
                foreach (DataRow dr in dtPlan.Rows)
                {
                    string strWareLocatorNo = "", strMaterialNo = "", strWhere = "", strSql = "";
                    float num = 0;
                    DataTable dtStock = new DataTable();
                    stockUpBillNo.DeleteRecord(int.Parse(dr["id"].ToString()));
                    strWareLocatorNo = dr["wareLocatorNo"].ToString();//库位
                    //strFinanceBillNo = dr["financeBillNo"].ToString();//采购合同号
                    strMaterialNo = dr["materialNo"].ToString();//物料编号
                    num = Convert.ToSingle(dr["num"]);//数量

                    pickOutPlanModel = new OtherOutInPickOutPlanData();

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

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

                    this.therOutInPickOutPlanBB.AddRecord(pickOutPlanModel);
                    string command = "Update OtherOutInBill set StockUpbillNo = '" + stockUpBillNOValue + "',InstantState = '02' where SAPDocEntry = " + SAPDocEntry + "";
                    SQLHelperDM.ExecuteNonQuery(HS.Config.SqlDataObject.GetJoeyConnectionString, command);
                    ret = true;

                }
                stockUpBillNo.Dispose();

                #endregion 保存拣货计划
            }
            catch
            {

            }
            try
            {
                if (this.transaction == null) trans.Commit();

            }
            catch
            {
                ret = false;
            }

            finally
            {
                stockBB.Dispose();
                commBB.Dispose();
                therOutInPickOutPlanBB.Dispose();

            }

            return ret;
        }
Пример #3
0
        //*****************************************************************************
        //do it later      do it later      do it later
        //*****************************************************************************
        /// <summary>
        /// 保存排托出库信息
        /// </summary>
        /// <param name="stockUpDetailID">备货单明细ID</param>
        /// <param name="strNewPalletNo">新托盘号</param>
        /// <param name="strOldBoxNo">原箱号</param>
        /// <param name="strNewBoxNo">新箱号</param>
        /// <param name="num">数量</param>
        /// <returns></returns>
        public bool SaveOutStockInfo(int stockUpDetailID, string strNewPalletNo, string strOldBoxNo,
            string strNewBoxNo, double num)
        {
            bool ret = false;
            SqlTransaction trans = null;
            BArrangeBillBoxBB arraneBillBoxBB = new BArrangeBillBoxBB(this.connection);
            BForkliftTaskBC forkliftTaskBC = new BForkliftTaskBC(this.connection);
            CDEPickOutBoxBB DEPickOutBoxBB = new CDEPickOutBoxBB(this.connection);
            CStockUpDetailBB stockUpDetailBB = new CStockUpDetailBB(this.connection);
            CSaleDetailBB saleDetailBB = new CSaleDetailBB(this.connection);
            SCommBB commBB = new SCommBB(this.connection);
            UStockBB stockBB = new UStockBB(this.connection);
            UStockOutInDetailBB stockOutInDetailBB = new UStockOutInDetailBB(this.connection);
            LMaterialBB materialBB = new LMaterialBB(this.connection);

            try
            {
                if (this.transaction == null)
                {
                    trans = this.connection.BeginTransaction("TransSaveOutStockInfo");
                    this.pickOutBillBB.Transaction = trans;
                    arraneBillBoxBB.Transaction = trans;
                    forkliftTaskBC.Transaction = trans;
                    DEPickOutBoxBB.Transaction = trans;
                    stockUpDetailBB.Transaction = trans;
                    saleDetailBB.Transaction = trans;
                    commBB.Transaction = trans;
                    stockBB.Transaction = trans;
                    stockOutInDetailBB.Transaction = trans;
                    materialBB.Transaction = trans;
                }
                else
                {
                    this.pickOutBillBB.Transaction = this.transaction;
                    arraneBillBoxBB.Transaction = this.transaction;
                    forkliftTaskBC.Transaction = this.transaction;
                    DEPickOutBoxBB.Transaction = this.transaction;
                    stockUpDetailBB.Transaction = this.transaction;
                    saleDetailBB.Transaction = this.transaction;
                    commBB.Transaction = this.transaction;
                    stockBB.Transaction = this.transaction;
                    stockOutInDetailBB.Transaction = this.transaction;
                    materialBB.Transaction = this.transaction;
                }

                CStockUpDetailData stockUpDetailModel = new CStockUpDetailData();
                vCStockUpDetailData vStockUpDetailModel = new vCStockUpDetailData();
                DataTable dtArrangeBillBox = new DataTable();
                DataTable dtDEPickOutBox = new DataTable();
                DataTable dtWareLocator = new DataTable();
                DataTable dtStockUpDetail = new DataTable();
                string strSql = "", strPrePalletNo = "", strPreWareLocatorNo = "";

                //获取备货单明细实例
                stockUpDetailModel = stockUpDetailBB.GetModel(stockUpDetailID);

                //拆托拣货箱信息
                dtDEPickOutBox = DEPickOutBoxBB.GetVList("boxNo='" + strOldBoxNo + "'").Tables[0];

                //普通拣货箱信息
                dtArrangeBillBox = arraneBillBoxBB.GetVList("boxNo='" + strOldBoxNo + "' and wareNo<>''").Tables[0];

                //扫描箱以前所在库位
                if (dtArrangeBillBox.Rows[0]["preWareLocatorNo"].ToString() != "")
                {
                    strPrePalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘条码号
                    strPreWareLocatorNo = dtArrangeBillBox.Rows[0]["preWareLocatorNo"].ToString();//物料箱以前所在库位
                }

                //获取排托区下线库位信息
                strSql = @"select wareLocator.wareNo,wareLocator.downWareLocatorNo as wareLocatorNo
                           from dbo.BArrangeBillBox as arrangeBillBoxBox
                           left join dbo.LWareLocator as wareLocator on wareLocator.wareLocatorNo=arrangeBillBoxBox.wareLocatorNo
                           where arrangeBillBoxBox.boxNo='" + strOldBoxNo + "'";

                dtWareLocator = commBB.Query(strSql).Tables[0];

                #region 新增销售拣货单信息

                CPickOutBillData pickOutBillModel = new CPickOutBillData();

                //新增销售拣货单信息
                pickOutBillModel.stockUpDetailID = stockUpDetailID;//备货单明细ID

                //从哪个拣货库区、库位赋值
                if (dtDEPickOutBox.Rows.Count > 0)
                {
                    pickOutBillModel.wareNo = dtDEPickOutBox.Rows[0]["preWareNo"].ToString();//以前的仓库编号
                    pickOutBillModel.wareLocatorNo = dtDEPickOutBox.Rows[0]["preWareLocatorNo"].ToString();//以前的库位编号
                }
                else
                {
                    pickOutBillModel.wareNo = dtArrangeBillBox.Rows[0]["preWareNo"].ToString();//以前的仓库编号
                    pickOutBillModel.wareLocatorNo = dtArrangeBillBox.Rows[0]["preWareLocatorNo"].ToString();//以前的库位编号
                }

                pickOutBillModel.preWareNo = "";//以前的仓库编号
                pickOutBillModel.preWareLocatorNo = "";//以前的库位编号
                pickOutBillModel.oldPalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘号
                pickOutBillModel.oldRegion = dtArrangeBillBox.Rows[0]["region"].ToString();//原托内区域
                pickOutBillModel.oldBoxNo = strOldBoxNo;//原箱号
                pickOutBillModel.newBoxNo = strNewBoxNo;//新箱号
                pickOutBillModel.num = num;//数量
                pickOutBillModel.isrtEmpId = this.empId;//添加人
                pickOutBillModel.isrtDt = System.DateTime.Now.ToString();//添加时间
                pickOutBillModel.instantState = "01";//未发货

                pickOutBillBB.AddRecord(pickOutBillModel);

                #endregion 新增销售拣货单信息

                #region 新增新的排托箱

                DataTable dtArrangeBillBoxNew = new DataTable();

                dtArrangeBillBoxNew = arraneBillBoxBB.GetVList("boxNo='" + strNewBoxNo + "'").Tables[0];

                //新增新的排托箱
                if (dtArrangeBillBoxNew.Rows.Count == 0)
                {
                    BArrangeBillBoxData newArrangeBillBoxModel = new BArrangeBillBoxData();

                    newArrangeBillBoxModel.arriveBillNo = "";//到货单号
                    newArrangeBillBoxModel.financeBillNo = dtArrangeBillBox.Rows[0]["financeBillNo"].ToString();//采购订单号
                    newArrangeBillBoxModel.arrangeBillNo = "";//排托单号
                    newArrangeBillBoxModel.stockUpBillNo = stockUpDetailModel.stockUpBillNo;//备货单编号
                    newArrangeBillBoxModel.boxNo = strNewBoxNo;//箱号
                    newArrangeBillBoxModel.oldBoxNo = strOldBoxNo;//原箱号
                    newArrangeBillBoxModel.materialNo = stockUpDetailModel.materialNo;//转换后物料编号
                    newArrangeBillBoxModel.oldMaterialNo = dtArrangeBillBox.Rows[0]["materialNo"].ToString();//转换前物料编号
                    newArrangeBillBoxModel.factNum = 0;//数量赋0,通过拣货箱明细计算数量
                    newArrangeBillBoxModel.palletNo = strNewPalletNo;//托盘号
                    newArrangeBillBoxModel.region = "";//区域
                    newArrangeBillBoxModel.oldPalletNo = dtArrangeBillBox.Rows[0]["palletNo"].ToString();//原托盘号
                    newArrangeBillBoxModel.oldRegion = dtArrangeBillBox.Rows[0]["region"].ToString();//原托内区域

                    //新箱库区、库位赋值,值为下线线体
                    if (dtWareLocator.Rows.Count > 0
                       && dtWareLocator.Rows[0]["wareLocatorNo"] != DBNull.Value
                       && dtWareLocator.Rows[0]["wareLocatorNo"].ToString() != "")
                    {
                        newArrangeBillBoxModel.wareNo = dtWareLocator.Rows[0]["wareNo"].ToString();//库区
                        newArrangeBillBoxModel.wareLocatorNo = dtWareLocator.Rows[0]["wareLocatorNo"].ToString();//库位
                    }

                    newArrangeBillBoxModel.preWareNo = "";//原库区
                    newArrangeBillBoxModel.preWareLocatorNo = "";//原库位
                    newArrangeBillBoxModel.isBoxArrange = true;//是否排托
                    newArrangeBillBoxModel.isPalletUsing = true;//托盘是否正在使用
                    newArrangeBillBoxModel.acceptEmpId = this.EmpID;//接收人
                    newArrangeBillBoxModel.acceptDt = System.DateTime.Now.ToString();//接收时间
                    newArrangeBillBoxModel.isOutStocking = false;//是否正在出库

                    arraneBillBoxBB.AddRecord(newArrangeBillBoxModel);
                }

                #endregion 新增新的排托箱

                #region 库存所有操作

                DataTable dtStock = new DataTable();
                DataTable dtMaterial = new DataTable();
                UStockOutInDetailData stockOutInDetailModel = new UStockOutInDetailData();

                //更改正式库存信息
                commBB.ExecuteSql("update dbo.UStock set num=num-" + num.ToString() + " where boxNo='" + strOldBoxNo + "'");

                //增加出入库明细-拣货箱出库
                dtStock = stockBB.GetList("boxNo='" + strOldBoxNo + "'").Tables[0];
                if (dtStock.Rows.Count > 0)//原箱有库存
                {
                    dtMaterial = materialBB.GetList("materialNo='" + dtStock.Rows[0]["materialNo"].ToString() + "'").Tables[0];

                    //保存出入库明细数据
                    stockOutInDetailModel = new UStockOutInDetailData();

                    stockOutInDetailModel.billNo = stockUpDetailModel.stockUpBillNo;//单据编号
                    stockOutInDetailModel.outInType = "06";//销售出库
                    stockOutInDetailModel.isOut = true;//是否出库
                    stockOutInDetailModel.stockDt = System.DateTime.Today.ToString();//库存日期
                    stockOutInDetailModel.dt = System.DateTime.Today.ToString();//操作日期
                    stockOutInDetailModel.wareNo = dtStock.Rows[0]["wareNo"].ToString();//仓库
                    stockOutInDetailModel.wareLocatorNo = dtStock.Rows[0]["wareLocatorNo"].ToString();//库位
                    stockOutInDetailModel.salverNo = dtStock.Rows[0]["palletNo"].ToString();//托盘号
                    stockOutInDetailModel.boxNo = strOldBoxNo;//箱号
                    stockOutInDetailModel.materialNo = dtStock.Rows[0]["materialNo"].ToString();//物料编号
                    stockOutInDetailModel.factMonomerNum = Convert.ToDouble(dtMaterial.Rows[0]["U_UintQty"]);//单体数量
                    stockOutInDetailModel.factPackNum = Convert.ToDouble(dtMaterial.Rows[0]["U_BoxQty"]);//整箱数量
                    stockOutInDetailModel.num = num;//数量
                    stockOutInDetailModel.isrtEmpId = this.empId;
                    stockOutInDetailModel.isrtDt = System.DateTime.Now.ToString();

                    stockOutInDetailBB.AddRecord(stockOutInDetailModel);
                }

                #endregion 库存所有操作

                #region 更改备货单明细的新托盘号、状态

                //更改备货单明细的新托盘号、状态
                vStockUpDetailModel = stockUpDetailBB.GetVModel(stockUpDetailID);

                stockUpDetailModel.palletNo = strNewPalletNo;//新托盘号

                if (vStockUpDetailModel.num > vStockUpDetailModel.factNum)
                {
                    stockUpDetailModel.instantState = "02";//更改状态为“备货中”
                }
                else
                {
                    stockUpDetailModel.instantState = "03";//更改状态为“备货完成”
                }

                stockUpDetailBB.ModifyRecord(stockUpDetailModel);

                #endregion 更改备货单明细的新托盘号、状态

                #region 生成从拣货区到打托区叉车任务

                bool isFinish = true;

                //如果某个托盘的备货单明细已经全部备货完成,生成托盘的叉车任务
                strSql = @"select palletNo,instantState from dbo.CStockUpDetail where stockUpBillNo='" + stockUpDetailModel.stockUpBillNo
                    + "' and palletIndex='" + stockUpDetailModel.palletIndex.ToString() + "'";

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

                foreach (DataRow row in dtStockUpDetail.Rows)
                {
                    if (row["instantState"].ToString() == "01" || row["instantState"].ToString() == "02")
                    {
                        isFinish = false;
                        break;
                    }
                }

                if (isFinish)
                {
                    //保存从拣货区到打托区叉车任务
                    forkliftTaskBC.SaveForkliftTask(dtStockUpDetail.Rows[0]["palletNo"].ToString(), "", "", "14", this.empId);
                }

                #endregion 生成从拣货区到打托区叉车任务

                #region 更改备货单状态

                //如果备货单明细的状态全部为“03 备货完成”,更改备货单状态为“08 备货完成”
                strSql = @"update dbo.CStockUpBill set instantState='08'
                           where not exists(select 1 from dbo.CStockUpDetail as t where t.stockUpBillNo=dbo.CStockUpBill.stockUpBillNo and instantState<>'03')";

                commBB.ExecuteSql(strSql);

                #endregion 更改备货单状态

                #region 更改箱锁定状态

                int stockId = 0, boxId = 0;
                object obj = null;

                //查找库存
                obj = commBB.ExecuteScalar("select top 1 id from dbo.UStock where boxNo='" + strOldBoxNo + "' and num>0 and isOutStocking=1");
                if (obj == null)
                {
                    obj = commBB.ExecuteScalar("select top 1 id from dbo.UStock where palletNo='" + strPrePalletNo + "' and num>0 and isOutStocking=1 order by id");
                    if (obj != null)
                    {
                        stockId = Convert.ToInt32(obj);
                    }
                }
                else
                {
                    stockId = Convert.ToInt32(obj);
                }

                //查找物料箱
                obj = commBB.ExecuteScalar("select top 1 id from dbo.BArrangeBillBox where boxNo='" + strOldBoxNo + "' and wareNo<>'' and isOutStocking=1");
                if (obj == null)
                {
                    obj = commBB.ExecuteScalar("select top 1 id from dbo.BArrangeBillBox where palletNo='" + strPrePalletNo + "' and wareNo<>'' and isOutStocking=1 order by id");
                    if (obj != null)
                    {
                        boxId = Convert.ToInt32(obj);
                    }
                }
                else
                {
                    boxId = Convert.ToInt32(obj);
                }

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

                //更改原箱的是否锁定状态
                strSql = "update dbo.BArrangeBillBox set isOutStocking=0 where id='" + boxId.ToString() + "'";
                commBB.ExecuteSql(strSql);

                #endregion 更改箱锁定状态

                #region 如果原箱剩余数量为零,更改原箱的托盘号

                if (strNewBoxNo == strOldBoxNo)
                {
                    if (dtWareLocator.Rows.Count > 0
                        && dtWareLocator.Rows[0]["wareLocatorNo"] != DBNull.Value
                        && dtWareLocator.Rows[0]["wareLocatorNo"].ToString() != "")
                    {
                        strSql = @"update dbo.BArrangeBillBox set oldMaterialNo=materialNo,materialNo='" + stockUpDetailModel.materialNo
                            + "',oldPalletNo=palletNo,palletNo='" + strNewPalletNo + "',preWareNo=wareNo,preWareLocatorNo=wareLocatorNo,wareNo='"
                            + dtWareLocator.Rows[0]["wareNo"].ToString() + "',wareLocatorNo='" + dtWareLocator.Rows[0]["wareLocatorNo"].ToString()
                            + "',oldRegion=region,region='' where boxNo='" + strOldBoxNo + "'";

                        commBB.ExecuteSql(strSql);
                    }
                }

                //如果箱内剩余数量为0,清空托盘号和库区、库位信息
                dtArrangeBillBox = arraneBillBoxBB.GetVList("boxNo='" + strOldBoxNo + "'").Tables[0];
                if (Convert.ToInt32(dtArrangeBillBox.Rows[0]["leavingNum"]) == 0)
                {
                    commBB.ExecuteSql(@"update dbo.BArrangeBillBox set oldPalletNo=palletNo,palletNo='',preWareNo=wareNo,preWareLocatorNo=wareLocatorNo,
                                        wareNo='',wareLocatorNo='' where boxNo='" + strOldBoxNo + "'");
                }

                #endregion 如果原箱剩余数量为零,更改原箱的托盘号

                #region 原库位释放

                //释放库位,首先判断原托盘上是否有物料
                strSql = @"update dbo.LWareLocator set isUsing=0
                           where not exists(select 1 from dbo.BArrangeBillBox as t where t.palletNo='"
                    + strPrePalletNo + "' and isnull(t.wareNo,'')<>'') and wareLocatorNo='"
                    + strPreWareLocatorNo + "' and isUsing=1 and isDel=0";

                commBB.ExecuteSql(strSql);

                #endregion 原库位释放

                #region 出入库所有操作

                //库存明细数量为0,删除信息
                strSql = "delete from dbo.UStock where num=0";
                commBB.ExecuteSql(strSql);

                #endregion 出入库所有操作

                if (this.transaction == null) trans.Commit();
                ret = true;
            }
            catch (Exception ex)
            {
                if (this.transaction == null) trans.Rollback("TransSaveOutStockInfo");
                throw ex;
            }
            finally
            {
                arraneBillBoxBB.Dispose();
                forkliftTaskBC.Dispose();
                stockUpDetailBB.Dispose();
                commBB.Dispose();
                saleDetailBB.Dispose();
                DEPickOutBoxBB.Dispose();
                stockBB.Dispose();
                stockOutInDetailBB.Dispose();
                materialBB.Dispose();
            }

            return ret;
        }