public override void Execute()
        {
            try
            {
                object state = AutomationContext.Read(memoryServiceName, memoryItemName);
                if (state == null || state.ToString() != "InventoryWholePalletScan")
                {
                    return;
                }

                int taskID = 0, positionID = 0;
                state = AutomationContext.Read(memoryServiceName1, memoryItemName1);
                object obj = ObjectUtil.GetObjects(state);
                if (obj is Array)
                {
                    Array arrayObj = (Array)obj;
                    if (arrayObj.Length == 2)
                    {
                        taskID     = Convert.ToInt32(arrayObj.GetValue(0));
                        positionID = Convert.ToInt32(arrayObj.GetValue(1));
                    }
                }
                if (taskID == 0 || positionID == 0)
                {
                    return;
                }

                //弹出输入窗,获取数量;
                state = AutomationContext.Read(memoryServiceName2, memoryItemName2);
                if (state != null)
                {
                    UserLookAndFeel.Default.SetSkinStyle(state.ToString());
                }

                InventoryDialog inventoryDialog = new InventoryDialog(taskID);
                if (inventoryDialog.ShowDialog() == DialogResult.OK)
                {
                    RestClient rest = new RestClient();
                    taskID = rest.FinishInventoryTask(taskID, inventoryDialog.RealQuantity);
                    if (taskID > 0)
                    {
                        string positionName = taskDal.GetTaskNextPosition(taskID);
                        if (positionName != string.Empty)
                        {
                            int[] data = new int[] { taskID, Convert.ToInt32(positionName), 1 };
                            AutomationContext.Write(plcServiceName, O_Whole_Pallet_StockIn_Task_Info, data);
                            Thread.Sleep(sleepTime);
                            obj = AutomationContext.Read(plcServiceName, I_Whole_Pallet_StockIn_Task_Info);
                            obj = ObjectUtil.GetObjects(obj);
                            if (obj is Array)
                            {
                                Array arrayObj = (Array)obj;
                                if (arrayObj.Length == 3 &&
                                    data[0] == Convert.ToInt32(arrayObj.GetValue(0)) &&
                                    data[1] == Convert.ToInt32(arrayObj.GetValue(1)) &&
                                    data[2] == Convert.ToInt32(arrayObj.GetValue(2)))
                                {
                                    AutomationContext.Write(plcServiceName, O_Whole_Pallet_StockIn_Task_Info_Complete, 1);
                                    AutomationContext.Write(memoryServiceName1, memoryItemName1, 0);
                                    positionDal.UpdateHasGoodsToFalse(positionID);
                                }
                            }
                        }
                    }
                    else if (taskID == -1)
                    {
                        positionDal.UpdateHasGoodsToFalse(positionID);
                        AutomationContext.Write(memoryServiceName1, memoryItemName1, 0);
                    }
                }
                inventoryDialog = null;
                GC.Collect();
            }
            catch (Exception ex)
            {
                Logger.Error("InventoryWholePalletScanProcess 出错,原因:" + ex.Message + "/n" + ex.StackTrace);
            }
        }
Exemple #2
0
        private void FinishTask()
        {
            try
            {
                if (CurrentTask != null)
                {
                    using (TransactionScopeManager TM = new TransactionScopeManager(true, IsolationLevel.Serializable))
                    {
                        TaskDal     taskDal     = new TaskDal();
                        PositionDal positionDal = new PositionDal();

                        taskDal.TransactionScopeManager     = TM;
                        positionDal.TransactionScopeManager = TM;

                        positionDal.UpdateHasGoodsToFalse(CurrentTask.CurrentPositionID);
                        positionDal.UpdateHasGoodsToTrue(CurrentTask.NextPositionID);

                        taskDal.UpdateTaskPosition(CurrentTask.ID, CurrentTask.NextPositionID);
                        taskDal.UpdateTaskPositionStateToArrived(CurrentTask.ID);
                        taskDal.UpdateTaskStateToWaiting(CurrentTask.ID);

                        if (CurrentTask.NextPositionID == CurrentTask.EndPositionID &&
                            (CurrentTask.TaskType == "03" || CurrentTask.EndPositionType != "03") &&
                            (CurrentTask.TaskType == "03" || CurrentTask.EndPositionType != "04"))   //小品种,异型烟,由手持PDA完成;
                        {
                            if (CurrentTask.TaskType == "02")
                            {
                                string orderType         = taskDal.GetOrderType(CurrentTask.ID);
                                string orderID           = taskDal.GetOrderID(CurrentTask.ID);
                                int    allotID           = taskDal.GetAllotID(CurrentTask.ID);
                                string originCellCode    = taskDal.GetOriginCellCode(CurrentTask.ID);
                                string targetCellCode    = taskDal.GetTargetCellCode(CurrentTask.ID);
                                string originStorageCode = taskDal.GetOriginStorageCode(CurrentTask.ID);
                                string targetStorageCode = taskDal.GetTargetStorageCode(CurrentTask.ID);

                                RestClient rest = new RestClient();
                                if (!rest.FinishTask(CurrentTask.ID, orderType, orderID, allotID, originCellCode, targetCellCode, originStorageCode, targetStorageCode))
                                {
                                    Logger.Error(string.Format("{0} 完成[{1}]任务失败!", Name, CurrentTask.ID));
                                    return;
                                }
                                else
                                {
                                    taskDal.UpdateTaskStateToExecuted(CurrentTask.ID);
                                }
                            }
                            else
                            {
                                if (!Ops.Write(memoryServiceName, memoryItemName, CurrentTask.ID))
                                {
                                    Logger.Error(string.Format("{0} 完成[{1}]任务失败!", Name, CurrentTask.ID));
                                    return;
                                }
                            }
                        }
                        TM.Commit();

                        CurrentTask        = null;
                        CurrentTaskFactory = null;
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error("SRM.FinishTask 出错,原因:" + ex.Message + "/n" + ex.StackTrace);
            }
        }