예제 #1
0
        /// <summary>
        /// 下载数据 最后修改日期 2010-10-30
        /// </summary>
        private void DownloadData()
        {
            try
            {
                using (PersistentManager pm = new PersistentManager())
                {
                    ChannelDao       channelDao       = new ChannelDao();
                    StockOutBatchDao stockOutBatchDao = new StockOutBatchDao();
                    StockInBatchDao  stockInBatchDao  = new StockInBatchDao();
                    StockOutDao      stockOutDao      = new StockOutDao();
                    StockInDao       stockInDao       = new StockInDao();
                    SupplyDao        supplyDao        = new SupplyDao();

                    if (supplyDao.FindCount() != stockOutDao.FindOutQuantity())
                    {
                        if (DialogResult.Cancel == MessageBox.Show("还有未处理的数据,您确定要重新下载数据吗?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question))
                        {
                            return;
                        }
                    }

                    using (PersistentManager pmServer = new PersistentManager("ServerConnection"))
                    {
                        ServerDao serverDao = new ServerDao();
                        serverDao.SetPersistentManager(pmServer);

                        //ORDER BY ORDERDATE,BATCHNO  查找第一批次(符合已优化,并已上传一号工程,未下载的批次)
                        DataTable table = serverDao.FindBatch();
                        if (table.Rows.Count != 0)
                        {
                            using (PersistentManager pmWES = new PersistentManager("WESConnection"))
                            {
                                StockInBatchDao stockInBatchDaoWES = new StockInBatchDao();
                                stockInBatchDaoWES.SetPersistentManager(pmWES);
                                stockInBatchDaoWES.Delete();
                            }

                            string batchID   = table.Rows[0]["BATCHID"].ToString();
                            string orderDate = table.Rows[0]["ORDERDATE"].ToString();
                            string batchNo   = table.Rows[0]["BATCHNO"].ToString();

                            Context.ProcessDispatcher.WriteToProcess("monitorView", "ProgressState", new ProgressState("清空作业表", 5, 1));
                            channelDao.Delete();
                            stockOutBatchDao.Delete();
                            stockOutDao.Delete();
                            stockInBatchDao.Delete();
                            stockInDao.Delete();
                            supplyDao.Delete();
                            System.Threading.Thread.Sleep(100);

                            Context.ProcessDispatcher.WriteToProcess("monitorView", "ProgressState", new ProgressState("下载补货烟道表", 5, 2));
                            table = serverDao.FindStockChannel(orderDate, batchNo);
                            channelDao.InsertChannel(table);
                            System.Threading.Thread.Sleep(100);

                            Context.ProcessDispatcher.WriteToProcess("monitorView", "ProgressState", new ProgressState("下载补货混合烟道表", 5, 3));
                            table = serverDao.FindMixChannel(orderDate, batchNo);
                            channelDao.InsertMixChannel(table);
                            System.Threading.Thread.Sleep(100);

                            Context.ProcessDispatcher.WriteToProcess("monitorView", "ProgressState", new ProgressState("下载分拣烟道表", 5, 4));
                            table = serverDao.FindChannelUSED(orderDate, batchNo);
                            channelDao.InsertChannelUSED(table);
                            System.Threading.Thread.Sleep(100);

                            Context.ProcessDispatcher.WriteToProcess("monitorView", "ProgressState", new ProgressState("下载补货计划表", 5, 5));
                            table = serverDao.FindSupply(orderDate, batchNo);
                            supplyDao.Insert(table);
                            System.Threading.Thread.Sleep(100);

                            serverDao.UpdateBatchStatus(batchID);
                            Context.ProcessDispatcher.WriteToProcess("monitorView", "ProgressState", new ProgressState());
                            Logger.Info("数据下载完成");

                            //初始化PLC数据(叠垛线PLC,补货线PLC)
                            Context.ProcessDispatcher.WriteToService("StockPLC_01", "RestartData", 3);
                            Context.ProcessDispatcher.WriteToService("StockPLC_02", "RestartData", 1);

                            //初始化入库扫码器
                            Context.ProcessDispatcher.WriteToProcess("ScanProcess", "Init", null);

                            //初始化状态管理器
                            Context.ProcessDispatcher.WriteToProcess("LedStateProcess", "Init", null);
                            Context.ProcessDispatcher.WriteToProcess("OrderDataStateProcess", "Init", null);
                            Context.ProcessDispatcher.WriteToProcess("ScannerStateProcess", "Init", null);

                            //生成入库请求任务数据
                            Context.ProcessDispatcher.WriteToProcess("StockInRequestProcess", "FirstBatch", null);
                            //生成补货请求任务数据
                            //Context.ProcessDispatcher.WriteToProcess("SupplyFirstRequestProcess", "FirstBatch", null);
                        }
                        else
                        {
                            MessageBox.Show("没有补货计划数据!", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error("数据下载处理失败,原因:" + e.Message);
            }
        }