//定时更新station状态的显示,通过读取station表中的occupiedstatus,来设置背景图片或取消图片。 private void updateGUIStationStautus(Control cc) { using (var ctx = new AMSContext()) { foreach (System.Windows.Forms.Control control in cc.Controls) { if (control is System.Windows.Forms.Button) { System.Windows.Forms.Button btn = (System.Windows.Forms.Button)control; if (btn.Text != "清空") { int stationNo = int.Parse(btn.Text); t_Station agvStation = ctx.t_Station .Where(b => b.StationNo == stationNo) .SingleOrDefault(); if (agvStation.AvailableStatus == 0) { btn.BackgroundImageLayout = ImageLayout.Stretch; btn.BackgroundImage = Properties.Resources.gray_x; } else { if (agvStation.OccupiedStatus == 0) { btn.BackColor = Color.WhiteSmoke; //btn.BackgroundImageLayout = ImageLayout.Stretch; btn.BackgroundImage = Properties.Resources.empty; } else if (agvStation.OccupiedStatus == 1) { btn.BackgroundImageLayout = ImageLayout.Stretch; btn.BackgroundImage = Properties.Resources.pallet_gray; } else if (agvStation.OccupiedStatus == 2) { btn.BackgroundImageLayout = ImageLayout.Stretch; btn.BackgroundImage = Properties.Resources.pallet; } else if (agvStation.OccupiedStatus == 3) { btn.BackgroundImageLayout = ImageLayout.Stretch; btn.BackgroundImage = Properties.Resources.doubt; } } } if (control.Controls.Count > 0) { updateGUIStationStautus(control); } } } } }
//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); } } }
//计算可用路径-业务相关-根据起点找到所有可用路径 private t_AGVPath getPath(t_Station originalStation, int callButtonSignal) { t_AGVPath agvPath1; using (var ctx = new AMSContext()) { //read agvPath1 = ctx.t_AGVPath .Where(b => b.AvailableStatus == 1 && b.Origination == originalStation.StationNo && b.ChannelType == callButtonSignal) .First(); Console.WriteLine(DateTime.Now.ToString() + " 找到对应的通道 " + agvPath1.Destination); } return(agvPath1); }
private string stationStuatus(t_Station agvStation) { if (agvStation.OccupiedStatus == 0) { return("空闲"); } else if (agvStation.OccupiedStatus == 1) { return("预约"); } else if (agvStation.OccupiedStatus == 2) { return("已占用"); } else if (agvStation.OccupiedStatus == 3) { return("存疑"); } return("Unknown"); }
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秒后重新开始 }
//触发任务 private Boolean triggerTask(int materialType, int stationNo) { t_AGVPath agvPath1; t_Station agvStation1; //根据规则找到找路径,一般只能找到一条,如果找到多条,按照规则选一条 using (var ctx = new AMSContext()) { //read agvStation1 = ctx.t_Station .Where(b => b.StationNo == stationNo) .SingleOrDefault(); agvPath1 = getPath(agvStation1, materialType); } if (agvPath1 == null) { Console.WriteLine(DateTime.Now.ToString() + " triggerTask:根据" + agvStation1.StationNo + " 和拉动信号类型 " + materialType + " 找不到对应的路径"); return(false); } //如果路径下有多个站台,按照策略选一个站台 t_Station agvStation2 = getAvailabeStation(agvPath1); //构建任务实体 if (agvStation2 != null) { t_AGVWork agvWork1 = new t_AGVWork { JobType = 0, Origination = agvStation1.StationNo, Destination = agvStation2.StationNo, //JobId = 10000, Priority = 0, JobStatus = 0, TUType = 0, AGVCancelFlag = 0, CancelFlag = 0, WMSCancelFlag = 0, RedirectFlag = 0 }; //创建任务并更新货位状态(货位预约,空满状态 0: 空 1:预约中 2:满) if (createTask(agvWork1)) { //更新界面颜色,将对应货位的颜色改为黄色(预约中) //updateGUIStationStautus(agvStation1, 1); stationRelease = false; checkbox_stationRelease.Checked = false; //站台不可再接收其他的搬运指令 checkbox_stationRelease.Enabled = false; //而且不允许更改 } else { toolStripStatusLabel1.Text = "创建任务失败"; Console.WriteLine(DateTime.Now.ToString() + " triggerTask:根据起始站台: " + agvStation1.StationNo + " 和目的站台 " + agvStation2.StationNo + " 创建任务失败"); return(false); } //更新路径上任务数量-本次不实现(控制一条路径上的流量) } else { //toolStripStatusLabel1.Text = "无可用站台"; Console.WriteLine(DateTime.Now.ToString() + " triggerTask:根据起始站台: " + stationNo + " 和目的通道 " + agvPath1.Destination + " 找不到可用的站台"); return(false); } return(true); }