示例#1
0
文件: Main.cs 项目: dongdong-2009/AAA
        /// <summary>
        /// 状态切换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string ItemName = ((ToolStripMenuItem)sender).Name;
            string State    = ItemName.Replace("ToolStripMenuItem", "");

            if (this.dgvMain.CurrentCell != null)
            {
                BLL.BLLBase bll    = new BLL.BLLBase();
                string      TaskNo = this.dgvMain.Rows[this.dgvMain.CurrentCell.RowIndex].Cells[0].Value.ToString();

                DataParameter[] param = new DataParameter[] { new DataParameter("@TaskNo", TaskNo), new DataParameter("@State", State) };
                bll.ExecNonQueryTran("WCS.Sp_UpdateTaskState", param);

                BindData();

                try
                {
                    App.Dispatching.Process.Report report = new Dispatching.Process.Report();
                    if (State == "7")
                    {
                        report.Send2MES(TaskNo);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("切换状态,上报MES时发生错误:" + ex.Message);
                }
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void tmWorker(object sender, ElapsedEventArgs e)
 {
     lock (this)
     {
         try
         {
             DataTable dt = bllAGV.FillDataTable("WCS.SelectAGVTask", new DataParameter[] { new DataParameter("{0}", "Status=2") });
             for (int i = 0; i < dt.Rows.Count; i++)
             {
                 string TaskNo = dt.Rows[i]["Call_from"].ToString();
                 int    count  = bll.GetRowCount("WCS_Task", "TaskNo='{0}' and State not in (7,9)");
                 if (count == 1)
                 {
                     bll.ExecNonQuery("WCS.UpdateTaskState", new DataParameter[] { new DataParameter("{0}", "State=7,AGV_FinishDate=getdate()"), new DataParameter("{1}", string.Format("TaskNo='{0}'", TaskNo)) });
                     App.Dispatching.Process.Report rpt = new Report();
                     rpt.Send2MES(TaskNo);
                     Logger.Info("任务号:" + TaskNo + " 出库完成!");
                 }
             }
         }
         finally
         {
             tmWorkTimer.Start();
         }
     }
 }
示例#3
0
        protected override void StateChanged(StateItem stateItem, IProcessDispatcher dispatcher)
        {
            try
            {
                switch (stateItem.ItemName)
                {
                case "TaskFinish":
                    object obj = ObjectUtil.GetObject(stateItem.State);
                    if (obj == null)
                    {
                        return;
                    }
                    string TaskFinish = obj.ToString();
                    if (TaskFinish.Equals("True") || TaskFinish.Equals("1"))
                    {
                        string TaskNo = Util.ConvertStringChar.BytesToString(ObjectUtil.GetObjects(Context.ProcessDispatcher.WriteToService(stateItem.Name, "CraneTaskNo")));
                        if (TaskNo == "")
                        {
                            return;
                        }
                        DataParameter[] para = new DataParameter[] { new DataParameter("{0}", string.Format("WCS_Task.TaskNo='{0}'", TaskNo)) };
                        DataTable       dt   = bll.FillDataTable("WCS.SelectTask", para);


                        if (dt.Rows.Count > 0)
                        {
                            string TaskType   = dt.Rows[0]["TaskType"].ToString();
                            string State      = dt.Rows[0]["State"].ToString();
                            string PalletCode = dt.Rows[0]["PalletCode"].ToString();

                            bll.ExecNonQuery("WCS.Sp_TaskProcess", new DataParameter[] { new DataParameter("@TaskNo", TaskNo) });
                            Logger.Info("堆垛机任务完成,任务号:" + TaskNo + " 料箱号:" + PalletCode);
                            if (TaskType == "11" || TaskType == "14" && State == "3")     //入库,盘点上架
                            {
                                report.Send2MES(TaskNo);
                            }
                            else if (TaskType == "12" || TaskType == "15" || TaskType == "14" && State == "4") //出库,空箱出库,盘点下架
                            {
                                //下达输送线
                                string ConveyID    = dt.Rows[0]["ConveyFromStation"].ToString();
                                string Destination = dt.Rows[0]["ConveyToStation"].ToString();
                                int[]  iTaskNo     = new int[3];
                                iTaskNo[0] = int.Parse(TaskNo.Substring(0, 2));
                                iTaskNo[1] = int.Parse(TaskNo.Substring(2, 4));
                                iTaskNo[2] = int.Parse(TaskNo.Substring(6, 4));
                                WriteToService(ConveyServer, ConveyID + "_WTaskNo", iTaskNo);
                                WriteToService(ConveyServer, ConveyID + "_WPalletCode", PalletCode);
                                WriteToService(ConveyServer, ConveyID + "_Destination", Destination);     //目的地
                                if (WriteToService(ConveyServer, ConveyID + "_WriteFinished", 1))
                                {
                                    bll.ExecNonQuery("WCS.UpdateTaskState", new DataParameter[] { new DataParameter("{0}", "State=6,Convey_StartDate=getdate()"), new DataParameter("{1}", string.Format("TaskNo='{0}'", TaskNo)) });
                                    Logger.Info("任务号:" + TaskNo + " 料箱号:" + PalletCode + " 已下输送线:" + ConveyID + " 目的地址:" + Destination);
                                }
                                if (TaskType == "12")
                                {
                                    //插入AGV出库任务
                                    BLL.BLLBase bllAGV = new BLL.BLLBase("AGVDB");
                                    bllAGV.ExecNonQuery("WCS.InsertAGVTask", new DataParameter[] { new DataParameter("@from_station", ""),     //填入实际值,在Main.cs中,重下AGV任务Send2PLCAGV 也同时修改
                                                                                                   new DataParameter("@to_station", ""),
                                                                                                   new DataParameter("@TaskNo", TaskNo) });
                                }
                            }


                            sbyte[] taskNo = new sbyte[20];
                            Util.ConvertStringChar.stringToBytes("", 20).CopyTo(taskNo, 0);
                            WriteToService(stateItem.Name, "TaskNo", taskNo);
                        }
                    }
                    break;

                case "PLCCheck":
                    obj = ObjectUtil.GetObject(stateItem.State);
                    if (obj == null)
                    {
                        return;
                    }
                    string ack = obj.ToString();
                    if (ack.Equals("True") || ack.Equals("1"))
                    {
                        WriteToService(stateItem.Name, "WriteFinished", 0);
                        Logger.Debug(stateItem.Name + " Receive ACK 1");
                    }
                    break;

                case "CraneAlarmCode":
                    if (ObjectUtil.GetObject(stateItem.State) == null)
                    {
                        return;
                    }
                    if (ObjectUtil.GetObject(stateItem.State).ToString() == "0")
                    {
                        return;
                    }
                    string    strWarningCode = ObjectUtil.GetObject(stateItem.State).ToString();
                    DataRow[] drs            = null;
                    string    strError       = "";
                    if (drs.Length > 0)
                    {
                        strError = drs[0]["AlarmDesc"].ToString();
                    }
                    else
                    {
                        strError = "未知错误,错误号:" + strWarningCode;
                    }
                    report.SendCraneError(int.Parse(strWarningCode), strError);
                    Logger.Error("堆垛机发生错误: " + strError);
                    break;

                case "Run":
                    blRun = (int)stateItem.State == 1;
                    if (blRun)
                    {
                        tmWorkTimer.Start();
                        Logger.Info("堆垛机联机");
                    }
                    else
                    {
                        tmWorkTimer.Stop();
                        Logger.Info("堆垛机脱机");
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.Error("CraneProcess StateChanged方法出错,原因:" + ex.Message);
            }
        }