Ejemplo n.º 1
0
Archivo: Form1.cs Proyecto: aijam/MGT
        //ProgId: 104
        private void button_Handler(object sender)
        {
            Button button = (Button)sender;

            //检查对应站台是否有任务,如果有,则不允许修改;如果没有,则将有货修改为无货,反之亦然,同时修改站台状态
            using (var ctx = new AMSContext())
            {
                int stationNo             = int.Parse(button.Text);
                List <t_AGVWork> agvWorks = ctx.t_AGVWork
                                            .Where(b => b.Destination == stationNo || b.Origination == stationNo)
                                            .ToList();

                if (agvWorks != null && agvWorks.Count > 0)
                {
                    Console.WriteLine(DateTime.Now + " button_Handler: 站台:" + button.Text + "有作业任务,无法修改站台状态");
                    toolStripStatusLabel1.Text = DateTime.Now + " button_Handler: 站台:" + button.Text + "有作业任务,无法修改站台状态";
                }
                else
                {
                    t_Station tStation7 = ctx.t_Station
                                          .Where(b => b.StationNo == stationNo)
                                          .SingleOrDefault();

                    if (tStation7.OccupiedStatus == 0)
                    {
                        tStation7.OccupiedStatus = 2;
                    }
                    else if (tStation7.OccupiedStatus == 2)
                    {
                        tStation7.OccupiedStatus = 0;
                    }
                    else if (tStation7.OccupiedStatus == 1)
                    {
                        Console.WriteLine(DateTime.Now.ToString() + " button_Handler: 货位 " + tStation7.StationNo + "的状态为: 预约,无法修改");
                        toolStripStatusLabel1.Text = DateTime.Now.ToString() + " button_Handler: 货位 " + tStation7.StationNo + "的状态为: 预约,无法修改";
                        return;
                    }

                    tStation7.ModifyProgID = 104;
                    tStation7.ModifyTime   = DateTime.Now;
                    var setEntry = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager.GetObjectStateEntry(tStation7);
                    setEntry.SetModifiedProperty("OccupiedStatus");
                    setEntry.SetModifiedProperty("ModifyProgID");
                    setEntry.SetModifiedProperty("ModifyTime");
                    ctx.SaveChanges();

                    updateGUIStationStautus(button); //根据控件名称找到控件,并修改颜色

                    Console.WriteLine(DateTime.Now.ToString() + " button_Handler: 修改货位 " + tStation7.StationNo + "的状态为" + stationStuatus(tStation7));
                    toolStripStatusLabel1.Text = DateTime.Now.ToString() + " button_Handler: 修改货位 " + tStation7.StationNo + "的状态为" + stationStuatus(tStation7);
                }
            }
        }
Ejemplo n.º 2
0
Archivo: Form1.cs Proyecto: aijam/MGT
        //ProgID 103
        private Boolean Reset_Channel(int channelNo)
        {
            String channelName;

            if (channelNo == 10000)
            {
                channelName = "A";
            }
            else
            {
                channelName = "B";
            }
            //reset前,检查针对这个channel的执行中的任务,如果有,Messagebox报错,不能reset,请先删除指令
            using (var ctx = new AMSContext())
            {
                List <t_Station> agvStations = ctx.t_Station
                                               .Where(b => b.AvailableStatus == 1 && b.ChannelNo == channelNo)
                                               .OrderBy(b => b.Sequence)
                                               .ToList();
                //Console.WriteLine(agvWork1);

                if (agvStations != null && agvStations.Count > 0)
                {
                    var transaction = ctx.Database.BeginTransaction(); //事务开始
                    try
                    {
                        foreach (t_Station tStation6 in agvStations)
                        {
                            List <t_AGVWork> agvWorks1 = ctx.t_AGVWork
                                                         .Where(b => b.Destination == tStation6.StationNo)
                                                         .ToList();

                            if (agvWorks1.Count > 0)
                            {
                                toolStripStatusLabel1.Text = "通道 " + channelName + " 无法重置,搬送ID: " + agvWorks1.First().ID + "正在驶往站台 " + agvWorks1.First().Destination;
                                Console.WriteLine(DateTime.Now.ToString() + "Reset_Channel 通道 " + channelName + " 无法重置,搬送ID: " + agvWorks1.First().ID + "正在驶往站台 " + agvWorks1.First().Destination);
                                throw new Exception("站台有任务,无法重置");
                            }
                            else
                            {
                                tStation6.OccupiedStatus = 0;
                                tStation6.ModifyProgID   = 103;
                                tStation6.ModifyTime     = DateTime.Now;
                                var setEntry = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager.GetObjectStateEntry(tStation6);
                                setEntry.SetModifiedProperty("OccupiedStatus");
                                setEntry.SetModifiedProperty("ModifyProgID");
                                setEntry.SetModifiedProperty("ModifyTime");
                                ctx.SaveChanges();
                            }
                        }

                        transaction.Commit();

                        Console.WriteLine(DateTime.Now.ToString() + " Reset_Channel:通道" + channelName + " 已重置");
                        toolStripStatusLabel1.Text = DateTime.Now.ToString() + " Reset_Channel:通道" + channelName + " 已重置";
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        Console.WriteLine(DateTime.Now.ToString() + " Reset_Channel:失败了,事务回滚");
                    }
                    finally
                    {
                        transaction.Dispose();
                    }
                }
                else
                {
                    toolStripStatusLabel1.Text = "通道 " + channelNo + " 内没有站台,请确认通道号是否正确";
                    Console.WriteLine(DateTime.Now.ToString() + "Reset_Channel 通道 " + channelNo + " 内没有站台,请确认通道号是否正确");
                    return(false);
                }

                return(true);
            }
        }
Ejemplo n.º 3
0
Archivo: Form1.cs Proyecto: aijam/MGT
        private void timer1_updateJobStatus(object sender)
        {
            t_AGVWork agvWork1 = null;

            if (autoUpdateJobStatus)
            {
                using (var ctx = new AMSContext())
                {
                    var transaction = ctx.Database.BeginTransaction();
                    try
                    {
                        //read
                        List <t_AGVWork> agvWorks = ctx.t_AGVWork
                                                    //.OrderBy(b => b.BlogId)
                                                    .Where(b => b.JobStatus == 5 || b.JobStatus == 8 || b.JobStatus == 11 || b.JobStatus == 14 || b.JobStatus == 100)
                                                    .ToList();
                        //Console.WriteLine(agvWork1);

                        if (agvWorks != null && agvWorks.Count > 0)
                        {
                            //按照任务状态 5,8,11,14更新不同的数值
                            agvWork1 = agvWorks.First();
                            if (agvWork1.JobStatus == 5)
                            {
                                agvWork1.JobStatus = 6;
                            }
                            else if (agvWork1.JobStatus == 8)
                            {
                                agvWork1.JobStatus = 9;
                                //stationRelease = true; //取货完成确认后才允许接收新的搬送请求
                            }
                            else if (agvWork1.JobStatus == 11)
                            {
                                //检查站台状态,如果发现站台不可卸货,则修改目的地
                                if (checkDestinationStation())
                                {
                                    agvWork1.JobStatus = 12;
                                }
                                else
                                {
                                    updateTask2Clearing(agvWork1);
                                }
                            }
                            else if (agvWork1.JobStatus == 14)
                            {
                                agvWork1.JobStatus = 15;
                            }

                            ctx.t_AGVWork.Attach(agvWork1);

                            if (agvWork1.JobStatus == 100) //删除
                            {
                                ctx.t_AGVWork.Remove(agvWork1);
                                ctx.SaveChanges();

                                t_Station tStation5 = ctx.t_Station
                                                      .Where(b => b.StationNo == agvWork1.Destination).SingleOrDefault();

                                ctx.t_Station.Attach(tStation5);
                                tStation5.OccupiedStatus = 2;
                                tStation5.ModifyProgID   = 201;
                                tStation5.ModifyTime     = DateTime.Now;
                                var setEntry = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager.GetObjectStateEntry(tStation5);
                                setEntry.SetModifiedProperty("OccupiedStatus");
                                setEntry.SetModifiedProperty("ModifyProgID");
                                setEntry.SetModifiedProperty("ModifyTime");
                                ctx.SaveChanges();

                                //updateGUIStationStautus(tStation5, 2);
                                toolStripStatusLabel1.Text = "任务从 " + agvWork1.Origination + " 到 " + agvWork1.Destination + " 已经正常完成,站台 " + tStation5.StationNo + " 当前已有托盘";
                            }
                            else
                            {
                                agvWork1.ModifyProgID = 201;

                                var setEntry = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager.GetObjectStateEntry(agvWork1);
                                //只修改实体的Name属性和Age属性
                                setEntry.SetModifiedProperty("JobStatus");
                                setEntry.SetModifiedProperty("ModifyProgID");
                                ctx.SaveChanges();
                            }

                            //Console.WriteLine("update status:", updateFlag);
                            transaction.Commit();

                            String jobStatus     = agvWork1.JobStatus.ToString();
                            String jobStatusName = ctx.t_Code
                                                   .Where(b => b.codetype == jobStatus && b.code == "jobstatus").First().name;
                            toolStripStatusLabel1.Text = "从 " + agvWork1.Origination + " 到 " + agvWork1.Destination + " 的任务 " + jobStatusName;
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        Console.WriteLine(DateTime.Now.ToString() + " timer1_updateJobStatus 更新任务状态失败" + agvWork1.ID);
                        MessageBox.Show(ex.ToString());
                    }
                    finally
                    {
                        transaction.Dispose();
                    }
                }
            }

            //System.Threading.Thread.Sleep(2000); //用一个线程控制,睡2秒后重新开始
        }
Ejemplo n.º 4
0
Archivo: Form1.cs Proyecto: aijam/MGT
        //更新任务,将AGV送到clearing station ProgID 105
        private Boolean updateTask2Clearing(t_AGVWork agvWork2)
        {
            t_Station agvStation1;

            //更新任务
            using (var ctx = new AMSContext())
            {
                var transaction = ctx.Database.BeginTransaction();
                try
                {
                    agvWork2.ModifyProgID     = 105;
                    agvWork2.ModifyTime       = DateTime.Now;
                    agvWork2.RedirectFlag     = 1;
                    agvWork2.RedirectPosition = 9999;
                    agvWork2.JobStatus        = 61;
                    ctx.t_AGVWork.Attach(agvWork2);
                    var setEntry = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager.GetObjectStateEntry(agvWork2);
                    setEntry.SetModifiedProperty("ModifyProgID");
                    setEntry.SetModifiedProperty("ModifyTime");
                    setEntry.SetModifiedProperty("RedirectFlag");
                    setEntry.SetModifiedProperty("RedirectPosition");
                    setEntry.SetModifiedProperty("JobStatus");
                    ctx.SaveChanges();

                    //更新新的站台为预约


                    //更新站台状态为疑问
                    agvStation1 = ctx.t_Station
                                  .Where(b => b.StationNo == agvWork2.Destination)
                                  .SingleOrDefault();
                    agvStation1.OccupiedStatus = 3; //空满状态 0: 空 1:预约中 2:满 3: 存疑
                    agvStation1.ModifyProgID   = 105;
                    agvStation1.ModifyTime     = DateTime.Now;
                    ctx.t_Station.Attach(agvStation1);
                    var setEntry1 = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager.GetObjectStateEntry(agvStation1);
                    setEntry1.SetModifiedProperty("OccupiedStatus");
                    setEntry1.SetModifiedProperty("ModifyProgID");
                    setEntry1.SetModifiedProperty("ModifyTime");
                    ctx.SaveChanges();

                    transaction.Commit();

                    Console.WriteLine(DateTime.Now.ToString() + " updateTask:任务" + agvWork2.ID + " 已更新,站台 " + agvWork2.Destination + " 状态更新为(存疑)");
                    toolStripStatusLabel1.Text = " 从 " + agvWork2.Origination + " 到 " + agvWork2.Destination + " 的搬运任务已更新";

                    return(true);
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    Console.WriteLine(DateTime.Now.ToString() + " createTask:失败了,事务回滚");
                }
                finally
                {
                    transaction.Dispose();
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
Archivo: Form1.cs Proyecto: aijam/MGT
        //创建任务-事务,插入作业任务agvwork数据和更新站台状态agvstation在同一个事务内完成
        private Boolean createTask(t_AGVWork agvWork2)
        {
            t_Station agvStation1;

            //创建任务
            using (var ctx = new AMSContext())
            {
                //检查是否有目的地为同一个站台的任务还在执行中
                List <t_AGVWork> agvWorks = ctx.t_AGVWork
                                            .Where(b => b.Destination == agvWork2.Destination)
                                            .ToList();
                //Console.WriteLine(agvWork1);

                if (agvWorks.Count > 0)
                {
                    toolStripStatusLabel1.Text = DateTime.Now.ToString() + " 已经存在一条目的地为" + agvWork2.Destination + "的任务了,不能重复创建";
                    Console.WriteLine(DateTime.Now.ToString() + " createTask:已经存在一条目的地为" + agvWork2.Destination + "的任务了,不能重复创建");
                    return(false);
                }

                var transaction = ctx.Database.BeginTransaction();
                try
                {
                    agvWork2.ModifyProgID = 101;
                    agvWork2.ModifyTime   = DateTime.Now;
                    ctx.t_AGVWork.Add(agvWork2); //插入agv作业任务
                    ctx.SaveChanges();

                    agvWork2.JobId = agvWork2.ID;
                    var setEntry = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager.GetObjectStateEntry(agvWork2);
                    setEntry.SetModifiedProperty("JobId");
                    ctx.SaveChanges();

                    //更新站台状态为预约
                    agvStation1 = ctx.t_Station
                                  .Where(b => b.StationNo == agvWork2.Destination)
                                  .First();
                    agvStation1.OccupiedStatus = 1; //空满状态 0: 空 1:预约中 2:满
                    agvStation1.ModifyProgID   = 101;
                    agvStation1.ModifyTime     = DateTime.Now;
                    ctx.t_Station.Attach(agvStation1);
                    var setEntry1 = ((IObjectContextAdapter)ctx).ObjectContext.ObjectStateManager.GetObjectStateEntry(agvStation1);
                    setEntry1.SetModifiedProperty("OccupiedStatus");
                    setEntry1.SetModifiedProperty("ModifyProgID");
                    setEntry1.SetModifiedProperty("ModifyTime");
                    ctx.SaveChanges();

                    transaction.Commit();

                    Console.WriteLine(DateTime.Now.ToString() + " createTask:任务" + agvWork2.ID + " 已创建,站台 " + agvWork2.Destination + " 状态更新为(预约中)");
                    toolStripStatusLabel1.Text = " 从 " + agvWork2.Origination + " 到 " + agvWork2.Destination + " 的搬运任务已创建";

                    return(true);
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    Console.WriteLine(DateTime.Now.ToString() + " createTask:失败了,事务回滚");
                }
                finally
                {
                    transaction.Dispose();
                }
            }

            return(false);
        }