Exemple #1
0
        }/// <summary>

        /// 向下移动一行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDown_Click(object sender, EventArgs e)
        {
            try
            {
                if (gvCmdSet.IsLastRow)
                {
                    return;
                }
                RouteFragmentConfigInfo currAct = bsFragment.Current as RouteFragmentConfigInfo;
                if (currAct == null)
                {
                    return;
                }
                IList <RouteFragmentConfigInfo> acts = bsFragment.List as IList <RouteFragmentConfigInfo>;
                if (acts == null)
                {
                    return;
                }
                if (acts.Count <= 0)
                {
                    return;
                }
                int selectIndex = acts.IndexOf(currAct);
                RouteFragmentConfigInfo NextAct = DataToObject.CreateDeepCopy <RouteFragmentConfigInfo>(acts[selectIndex + 1]);
                NextAct.CmdIndex      = NextAct.CmdIndex - 1;
                acts[selectIndex]     = NextAct;
                currAct.CmdIndex      = currAct.CmdIndex + 1;
                acts[selectIndex + 1] = currAct;
                bsFragment.DataSource = acts;
                bsFragment.ResetBindings(false);
                gvCmdSet.MoveNext();
            }
            catch (Exception ex)
            { MsgBox.ShowError(ex.Message); }
        }
 private void gvDetail_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
 {
     try
     {
         gvPass.BeforeLeaveRow -= gvPass_BeforeLeaveRow;
         labelControl1.Focus();
         gvDetail.CloseEditor();
         labelControl1.Focus();
         e.Allow = Valid();
         if (!e.Allow)
         {
             return;
         }
         if (gvDetail.FocusedRowHandle >= 0)
         {
             TaskConfigDetail CurrDetail = bsDetail[gvDetail.FocusedRowHandle] as TaskConfigDetail;
             if (CurrDetail != null)
             {
                 if (gvPass.FocusedRowHandle >= 0)
                 {
                     TaskConfigMustPass CurrConfigPass = baPass[gvPass.FocusedRowHandle] as TaskConfigMustPass;
                     if (CurrConfigPass != null)
                     {
                         if (string.IsNullOrEmpty(CurrConfigPass.MustPassLandCode))
                         {
                             baPass.RemoveCurrent();
                         }
                     }
                     IList <IOActionInfo> Actions = bsIOActions.List as IList <IOActionInfo>;
                     CurrConfigPass.MustPassIOAction = Actions;
                 }
                 IList <TaskConfigMustPass> ConfigMustPasss = baPass.List as List <TaskConfigMustPass>;
                 if (ConfigMustPasss != null)
                 {
                     CurrDetail.TaskConfigMustPass = DataToObject.CreateDeepCopy <IList <TaskConfigMustPass> >(ConfigMustPasss);
                 }
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
     finally
     { gvPass.BeforeLeaveRow += gvPass_BeforeLeaveRow; }
 }
Exemple #3
0
        /// <summary>
        /// 向上移动一行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUp_Click(object sender, EventArgs e)
        {
            try
            {
                if (gvCmdSet.IsFirstRow)
                {
                    return;
                }


                RouteFragmentConfigInfo frag = bsFragment.Current as RouteFragmentConfigInfo;
                if (frag == null)
                {
                    return;
                }
                IList <RouteFragmentConfigInfo> listfrag = bsFragment.List as IList <RouteFragmentConfigInfo>;
                if (listfrag == null)
                {
                    return;
                }
                if (listfrag.Count <= 0)
                {
                    return;
                }
                int selectIndex             = listfrag.IndexOf(frag);
                RouteFragmentConfigInfo pre = DataToObject.CreateDeepCopy <RouteFragmentConfigInfo>(listfrag[selectIndex - 1]);
                frag.CmdIndex             = frag.CmdIndex - 1;
                listfrag[selectIndex - 1] = frag;
                pre.CmdIndex          = pre.CmdIndex + 1;
                listfrag[selectIndex] = pre;

                bsFragment.DataSource = listfrag;
                bsFragment.ResetBindings(false);
                gvCmdSet.MovePrev();
            }
            catch (Exception ex)
            {
                MsgBox.ShowError(ex.Message);
            }
        }/// <summary>
 private void gvPass_BeforeLeaveRow(object sender, DevExpress.XtraGrid.Views.Base.RowAllowEventArgs e)
 {
     try
     {
         if (gvPass.FocusedRowHandle < 0)
         {
             return;
         }
         TaskConfigMustPass CurrConfigPass = baPass[gvPass.FocusedRowHandle] as TaskConfigMustPass;
         if (CurrConfigPass != null)
         {
             IList <TaskConfigMustPass> AllPassLands = baPass.List as IList <TaskConfigMustPass>;
             if (AllPassLands != null && AllPassLands.Count(p => p.MustPassLandCode == CurrConfigPass.MustPassLandCode) > 1)
             {
                 gvPass.FocusedColumn = colMustPassLandCode;
                 gvPass.ShowEditor();
                 e.Allow = false;
                 return;
             }
             if (string.IsNullOrEmpty(CurrConfigPass.MustPassLandCode))
             {
                 gvPass.FocusedColumn = colMustPassLandCode;
                 gvPass.ShowEditor();
                 e.Allow = false;
                 return;
             }
             IList <IOActionInfo> IOActions = bsIOActions.List as List <IOActionInfo>;
             if (IOActions != null)
             {
                 CurrConfigPass.MustPassIOAction = DataToObject.CreateDeepCopy <IList <IOActionInfo> >(IOActions);
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
 }
 private void btnSave_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     try
     {
         gvPass.BeforeLeaveRow -= gvPass_BeforeLeaveRow;
         gvDetail.CloseEditor();
         labelControl1.Focus();
         if (!Valid())
         {
             return;
         }
         if (gvPass.FocusedRowHandle >= 0)
         {
             TaskConfigMustPass CurrConfigPass = baPass[gvPass.FocusedRowHandle] as TaskConfigMustPass;
             if (CurrConfigPass != null)
             {
                 if (string.IsNullOrEmpty(CurrConfigPass.MustPassLandCode))
                 {
                     baPass.RemoveCurrent();
                 }
                 IList <IOActionInfo> IOActions = bsIOActions.List as List <IOActionInfo>;
                 if (IOActions != null)
                 {
                     CurrConfigPass.MustPassIOAction = DataToObject.CreateDeepCopy <IList <IOActionInfo> >(IOActions);
                 }
             }
         }
         if (gvDetail.FocusedRowHandle >= 0)
         {
             TaskConfigDetail CurrDetail = bsDetail[gvDetail.FocusedRowHandle] as TaskConfigDetail;
             if (CurrDetail != null)
             {
                 IList <TaskConfigMustPass> ConfigMustPasss = baPass.List as List <TaskConfigMustPass>;
                 if (ConfigMustPasss != null)
                 {
                     CurrDetail.TaskConfigMustPass = DataToObject.CreateDeepCopy <IList <TaskConfigMustPass> >(ConfigMustPasss);
                 }
             }
         }
         TaskConfigInfo           CurrTaskConfig      = bsConfig.Current as TaskConfigInfo;
         IList <TaskConfigDetail> AllTaskConfigDetail = bsDetail.List as IList <TaskConfigDetail>;
         if (CurrTaskConfig != null && AllTaskConfigDetail != null && AllTaskConfigDetail.Count > 0)
         {
             if (CurrTaskConfig.IsNew && AllTaskConfigs.Where(p => p.TaskConditonCode == CurrTaskConfig.TaskConditonCode).Count() > 0)
             {
                 MsgBox.ShowWarn("任务条件配置编号已存在!");
                 return;
             }
             CurrTaskConfig.TaskConfigDetail = DataToObject.CreateDeepCopy <IList <TaskConfigDetail> >(AllTaskConfigDetail);
             OperateReturnInfo opr = AGVDAccess.AGVClientDAccess.SaveTaskConfig(CurrTaskConfig);
             MsgBox.Show(opr);
             if (opr.ReturnCode == OperateCodeEnum.Success)
             {
                 this.DialogResult = DialogResult.OK;
             }
         }
     }
     catch (Exception ex)
     { MsgBox.ShowError(ex.Message); }
     finally
     { gvPass.BeforeLeaveRow += gvPass_BeforeLeaveRow; }
 }
Exemple #6
0
        /// <summary>
        /// 分派任务
        /// </summary>
        private async void assignTask()
        {
            try
            {
                lock (HandleTaskobje)
                {
                    timerFreshTask.Enabled = false;
                    foreach (CarMonitor car in MoniCars.Where(p => (!string.IsNullOrEmpty(p.ExcuteTaksNo)) && p.TaskDetailID >= 0))
                    {
                        //将当前的任务明细更新完成
                        if (!string.IsNullOrEmpty(car.ExcuteTaksNo) && car.TaskDetailID != -1)
                        {
                            //HandTaskDetail(car.CurrSite.ToString(), car.ExcuteTaksNo, car.TaskDetailID);
                            if (car.Sate == 0 && car.CurrSite.ToString() == car.ArmLand)
                            {
                                #region 更新储位状态
                                UnLockStorage(car, Stores);
                                #endregion
                                AGVSimulationDAccess.HandTaskDetail(car.AgvID, car.CurrSite.ToString(), car.ExcuteTaksNo, car.TaskDetailID);
                                AGVSimulationDAccess.HandTaskzb(car.ExcuteTaksNo);
                                DispatchTaskInfo CarTaskInfo = AGVSimulationDAccess.CheckTaskIsFinish(car.ExcuteTaksNo);
                                if (CarTaskInfo == null)
                                {
                                    car.ExcuteTaksNo = "";
                                }
                            }
                        }
                    }


                    Hashtable hs = new Hashtable();
                    //查找当前有效任务
                    IList <DispatchTaskInfo> tasks = AGVSimulationDAccess.LoadDispatchTask("0,1");
                    if (tasks != null && tasks.Count > 0)
                    {
                        foreach (DispatchTaskInfo task in tasks)
                        {
                            if (task.TaskDetail.Count <= 0)
                            {
                                continue;
                            }
                            //查找合适的AGV来领取任务
                            CarMonitor NoTaskCar = null;
                            //如果任务为待处理的,就找空闲的车来执行
                            //如果任务是正在执行中的,则找对应的空闲agv来继续执行
                            //查找任务到具体任务明细
                            DispatchTaskDetail TaskDetail = (from a in task.TaskDetail
                                                             where (a.State == 0 || a.State == 1)
                                                             orderby a.DetailID ascending
                                                             select a).FirstOrDefault();
                            if (task.TaskState == 0)
                            {
                                if (TaskDetail != null)
                                {
                                    if (task.ExeAgvID != 0)
                                    {
                                        NoTaskCar = (from a in MoniCars
                                                     where task.ExeAgvID == a.AgvID && !string.IsNullOrEmpty(a.CurrSite.ToString()) && (a.Sate == 0 || a.IsBack) && a.ExcuteTaksNo == "" && /*a.TaskDetailID == -1*/
                                                     getDistant(a.CurrSite.ToString(), TaskDetail.LandCode) >= 0
                                                     orderby getDistant(a.CurrSite.ToString(), TaskDetail.LandCode) ascending
                                                     select a).FirstOrDefault();
                                    }
                                    else
                                    {
                                        NoTaskCar = (from a in MoniCars
                                                     where !string.IsNullOrEmpty(a.CurrSite.ToString()) && (a.Sate == 0 || a.IsBack) && a.ExcuteTaksNo == "" && /*a.TaskDetailID == -1*/
                                                     getDistant(a.CurrSite.ToString(), TaskDetail.LandCode) >= 0
                                                     orderby getDistant(a.CurrSite.ToString(), TaskDetail.LandCode) ascending
                                                     select a).FirstOrDefault();
                                    }
                                }
                            }
                            else if (task.TaskState == 1)
                            {
                                NoTaskCar = MoniCars.FirstOrDefault(p => p.AgvID == task.ExeAgvID && ((p.Sate == 0 || p.Sate == 2 || p.IsBack)));
                            }
                            //找到对应的agv
                            if (NoTaskCar != null && NoTaskCar.CurrSite > 0)
                            {
                                if (NoTaskCar.IsBack)
                                {
                                    NoTaskCar.IsBack = !NoTaskCar.IsBack;
                                }
                            }
                            else
                            {
                                continue;
                            }
                            //如果任务明细全部完成,那么需要将主任务状态更新并且让对应的agv回待命点
                            LandmarkInfo BeginLand, EndLand = null;
                            if (TaskDetail == null)
                            {
                            }
                            else
                            {
                                //判断一下当前小时是否就在任务地标上
                                if (NoTaskCar.CurrSite.ToString() == TaskDetail.LandCode && (TaskDetail.State == 0 || TaskDetail.State == 1))
                                {
                                    NoTaskCar.OperType     = TaskDetail.OperType;
                                    NoTaskCar.PutType      = TaskDetail.PutType;
                                    NoTaskCar.ArmLand      = TaskDetail.LandCode;
                                    NoTaskCar.ExcuteTaksNo = TaskDetail.dispatchNo;
                                    NoTaskCar.TaskDetailID = TaskDetail.DetailID;
                                    AGVSimulationDAccess.HandTaskDetail(NoTaskCar.AgvID, TaskDetail.LandCode, TaskDetail.dispatchNo, TaskDetail.DetailID);
                                    UnLockStorage(NoTaskCar, Stores);
                                    //NoTaskCar.TaskDetailID = -1;
                                    continue;
                                }

                                //判断小车当前的任务明细是否允许需要等待放行命令
                                DispatchTaskDetail PreTaskDetail = (from a in task.TaskDetail
                                                                    where a.LandCode == NoTaskCar.CurrSite.ToString()
                                                                    orderby a.DetailID ascending
                                                                    select a).FirstOrDefault();
                                //如果不允许执行则跳过
                                if (PreTaskDetail != null && PreTaskDetail.IsAllowExcute == 0)
                                {
                                    continue;
                                }
                                //记录当前小车的任务信息
                                //更新任务为执行状态
                                AGVSimulationDAccess.TaskHandle(task.dispatchNo, NoTaskCar.AgvID, 1, TaskDetail.LandCode, TaskDetail.DetailID);
                                NoTaskCar.ExcuteTaksNo = task.dispatchNo;
                                NoTaskCar.TaskDetailID = TaskDetail.DetailID;
                                NoTaskCar.ArmLand      = TaskDetail.LandCode;
                                NoTaskCar.PutType      = TaskDetail.PutType;
                                NoTaskCar.OperType     = TaskDetail.OperType;
                                BeginLand = AllLands.FirstOrDefault(p => p.LandmarkCode == NoTaskCar.CurrSite.ToString());
                                EndLand   = AllLands.FirstOrDefault(p => p.LandmarkCode == TaskDetail.LandCode);
                                if (BeginLand != null && EndLand != null)
                                {
                                    NoTaskCar.CurrRoute = DataToObject.CreateDeepCopy <List <LandmarkInfo> >(CountRoute.GetRoute(BeginLand, EndLand));
                                    string CountRouteResult = string.Join(",", NoTaskCar.CurrRoute.Select(p => p.LandmarkCode));
                                    LogHelper.WriteLog(CountRouteResult);
                                    if (NoTaskCar.CurrRoute.Count <= 0)
                                    {
                                        continue;
                                    }
                                    if (!Traffic.BeforStartTrafficForStop(NoTaskCar))
                                    {
                                        Traffic.GetTrafficResour(NoTaskCar);
                                        //if (Route_Ini != null)
                                        //{ Route_Ini(NoTaskCar.CurrRoute); }
                                        NoTaskCar.StepChange += DoCar_StepChange;
                                        NoTaskCar.Start();
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        List <CarMonitor> NoReleaseCars = MoniCars.Where(p => p.Sate != 1 && p.Sate != 2 && !string.IsNullOrEmpty(p.ExcuteTaksNo)).ToList();
                        foreach (CarMonitor item in NoReleaseCars)
                        {
                            item.ExcuteTaksNo = "";
                        }
                    }
                    List <CarMonitor> NoBackCars = MoniCars.Where(p => p.Sate != 1 && p.Sate != 2 && string.IsNullOrEmpty(p.ExcuteTaksNo) && p.CurrSite.ToString() != p.StandbyLandMark).ToList();
                    foreach (CarMonitor car in NoBackCars)
                    {
                        if (string.IsNullOrEmpty(car.StandbyLandMark))
                        {
                            continue;
                        }
                        LandmarkInfo BeginLand = AllLands.FirstOrDefault(p => p.LandmarkCode == car.CurrSite.ToString());
                        LandmarkInfo EndLand   = AllLands.FirstOrDefault(p => p.LandmarkCode == car.StandbyLandMark);
                        //以车的当前地标为开始地标,待命点为结束地标规划回待命点路线
                        if (BeginLand == null || EndLand == null)
                        {
                            continue;
                        }
                        else
                        {
                            //规划路线
                            car.CurrRoute = DataToObject.CreateDeepCopy <List <LandmarkInfo> >(CountRoute.GetRoute(BeginLand, EndLand));
                            if (car.CurrRoute.Count <= 0)
                            {
                                continue;
                            }
                            if (!Traffic.BeforStartTrafficForStop(car))
                            {
                                Traffic.GetTrafficResour(car);
                                //if (Route_Ini != null)
                                //{ Route_Ini(car.CurrRoute); }
                                car.StepChange += DoCar_StepChange;
                                car.Start();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            { throw ex; }
            finally
            { timerFreshTask.Enabled = true; }
        }