private bool AddNextSupply(string lineCode, string channelGroup, string channelType, int sortNo)
        {
            bool result = false;

            try
            {
                using (PersistentManager pm = new PersistentManager())
                {
                    StockOutBatchDao batchDao  = new StockOutBatchDao();
                    SupplyDao        supplyDao = new SupplyDao();
                    StockOutDao      outDao    = new StockOutDao();
                    batchDao.SetPersistentManager(pm);
                    supplyDao.SetPersistentManager(pm);
                    outDao.SetPersistentManager(pm);

                    DataTable supplyTable = supplyDao.FindNextSupply(lineCode, channelGroup, channelType, sortNo);

                    if (supplyTable.Rows.Count != 0)
                    {
                        Logger.Info(string.Format("收到补货请求,分拣线 '{0}',烟道组 '{1}',烟道类型 '{2}',流水号 '{3}'", lineCode, channelGroup, channelType, sortNo));
                        try
                        {
                            pm.BeginTransaction();

                            int batchNo = batchDao.FindMaxBatchNo() + 1;
                            batchDao.InsertBatch(batchNo, lineCode, channelGroup, channelType, sortNo, supplyTable.Rows.Count);

                            int outID = outDao.FindMaxOutID();
                            outDao.Insert(outID, supplyTable);

                            pm.Commit();
                            result = true;

                            Logger.Info("生成出库任务成功");
                        }
                        catch (Exception e)
                        {
                            Logger.Error("生成出库任务失败,原因:" + e.Message);
                            pm.Rollback();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("生成出库任务失败,原因:" + e.Message);
            }

            return(result);
        }
Exemple #2
0
        private bool AddFirstSupply()
        {
            bool result = false;

            try
            {
                using (PersistentManager pm = new PersistentManager())
                {
                    StockOutBatchDao batchDao  = new StockOutBatchDao();
                    SupplyDao        supplyDao = new SupplyDao();
                    StockOutDao      outDao    = new StockOutDao();
                    batchDao.SetPersistentManager(pm);
                    supplyDao.SetPersistentManager(pm);
                    outDao.SetPersistentManager(pm);

                    DataTable supplyTable = supplyDao.FindFirstSupply();

                    if (supplyTable.Rows.Count != 0)
                    {
                        try
                        {
                            pm.BeginTransaction();

                            int batchNo = batchDao.FindMaxBatchNo() + 1;
                            batchDao.InsertBatch(batchNo, "00", "0", "0", 0, supplyTable.Rows.Count);

                            int outID = outDao.FindMaxOutID();
                            outDao.Insert(outID, supplyTable);

                            pm.Commit();
                            result = true;

                            Logger.Info("生产第一批次出库任务成功");
                        }
                        catch (Exception e)
                        {
                            Logger.Error("生成第一批次出库任务失败,原因:" + e.Message);
                            pm.Rollback();
                        }
                    }
                }
            }
            catch (Exception ee)
            {
                Logger.Error("生成第一批次出库任务失败,原因:" + ee.Message);
            }

            return(result);
        }
Exemple #3
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            try
            {
                using (PersistentManager pm = new PersistentManager())
                {
                    StockOutBatchDao stockOutBatchDao = new StockOutBatchDao();
                    StockOutDao      stockOutDao      = new StockOutDao();
                    StockInDao       stockInDao       = new StockInDao();
                    stockOutBatchDao.SetPersistentManager(pm);
                    stockOutDao.SetPersistentManager(pm);
                    stockInDao.SetPersistentManager(pm);

                    try
                    {
                        DataTable outTable     = stockOutDao.FindSupply();
                        DataTable stockInTable = stockInDao.FindStockInForIsInAndNotOut();

                        if (outTable.Rows.Count > 0)
                        {
                            pm.BeginTransaction();

                            for (int i = 0; i < outTable.Rows.Count; i++)
                            {
                                DataRow[] stockInRows = stockInTable.Select(string.Format("CIGARETTECODE='{0}' AND STATE ='1' AND ( STOCKOUTID IS NULL OR STOCKOUTID = 0 )",
                                                                                          outTable.Rows[i]["CIGARETTECODE"].ToString()), "STOCKINID");

                                if (stockInRows.Length <= Convert.ToInt32(Context.Attributes["StockInRequestRemainQuantity"]) + 1)
                                {
                                    WriteToProcess("StockInRequestProcess", "StockInRequest", outTable.Rows[i]["CIGARETTECODE"].ToString());
                                }
                                else if (stockInRows.Length > 0 && stockInRows.Length + Convert.ToInt32(stockInRows[0]["STOCKINQUANTITY"]) <= Convert.ToInt32(Context.Attributes["StockInCapacityQuantity"]) + 1)
                                {
                                    WriteToProcess("StockInRequestProcess", "StockInRequest", outTable.Rows[i]["CIGARETTECODE"].ToString());
                                }

                                if (stockInRows.Length > 0)
                                {
                                    stockInRows[0]["STOCKOUTID"] = outTable.Rows[i]["STOCKOUTID"].ToString();
                                    outTable.Rows[i]["STATE"]    = 1;
                                }
                                else
                                {
                                    Logger.Error(string.Format("[{0}] [{1}] 库存不足!", outTable.Rows[i]["CIGARETTECODE"].ToString(), outTable.Rows[i]["CIGARETTENAME"].ToString()));
                                    WriteToProcess("LEDProcess", "StockInRequestShow", outTable.Rows[0]["CIGARETTENAME"]);
                                    break;
                                }
                            }

                            stockOutDao.UpdateStatus(outTable);
                            stockInDao.UpdateStockOutIdToStockIn(stockInTable);

                            pm.Commit();
                            Logger.Info("处理出库数据成功。");
                        }
                    }
                    catch (Exception e)
                    {
                        Logger.Error("处理出库数据失败,原因:" + e.Message);
                        pm.Rollback();
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("处理出库数据失败,原因:" + e.Message);
            }
        }