123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- using DbCommon.BusinessCore.BaseCore;
- using ProjectManagementSystem.Common.Core;
- using ProjectManagementSystem.Common.Logger;
- using ProjectManagementSystem.DispatchPack;
- using ProjectManagementSystem.DispatchPack.Entity;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace ProjectManagementSystem.UI
- {
- public partial class DispatchPackUI : UserControl, IDisplayUI
- {
- private StationInfoManager stationInfoManager = new StationInfoManager();
- public DispatchPackUI()
- {
- InitializeComponent();
- }
- public bool Init()
- {
- try
- {
- PackEngine.Instance.OnDisplayInfo += Instance_OnDisplayInfo;
- PackEngine.Instance.OnDisplayEntityInfo += Instance_OnDisplayEntityInfo;
- PackEngine.Instance.OnStart += Instance_OnStart;
- return true;
- }
- catch (Exception ex)
- {
- CLog.Instance.TaskLog.WriteException("UI", ex);
- }
- return false;
- }
- private void Instance_OnStart()
- {
- this.Invoke(new MethodInvoker(delegate
- {
- InitStationUI();
- }));
- }
- private void InitStationUI()
- {
- this.tabControl1.Controls.Clear();
- var entityList = PackEngine.Instance.EntityBaseList;
- for (int i = 0; i < entityList.Count; i++)
- {
- EntityBase entity = entityList[i];
- var tabPage = new System.Windows.Forms.TabPage();
- tabPage.Location = new System.Drawing.Point(8, 39);
- tabPage.Name = string.Format("tabPage{0}", i + 1);
- tabPage.Padding = new System.Windows.Forms.Padding(3);
- tabPage.Size = new System.Drawing.Size(1396, 474);
- tabPage.TabIndex = i;
- tabPage.Text = entity.LineInfo.Name;
- tabPage.UseVisualStyleBackColor = true;
- var flowLayoutPanel = new System.Windows.Forms.FlowLayoutPanel();
- flowLayoutPanel.Name = string.Format("flowLayoutPanel{0}", i + 1);
- flowLayoutPanel.Dock = DockStyle.Fill;
- flowLayoutPanel.AutoScroll = true;
- foreach (var item in entity.StationInfoList)
- {
- StationUI stationUI = new StationUI();
- stationUI.Init(item);
- stationUI.Display();
- flowLayoutPanel.Controls.Add(stationUI);
- PackEngine.Instance.StationUIList.Add(stationUI);
- }
- tabPage.Controls.Add(flowLayoutPanel);
- this.tabControl1.Controls.Add(tabPage);
- }
- }
- public void UpdateDisplay()
- {
- //if (!Visible) return;
- //var stationUIList = CoreEngine.Instance.StationUIList;
- //for (int i = 0; i < stationUIList.Count; i++)
- //{
- // var btn = stationUIList[i];
- // btn.BeginInvoke(new MethodInvoker(delegate
- // {
- // btn.Display();
- // }));
- //}
- }
- private void Instance_OnDisplayEntityInfo(EntityBase arg1, string arg2)
- {
- foreach (Control item in this.tabControl1.Controls)
- {
- if (item.TabIndex == arg1.Index)
- {
- this.BeginInvoke((Action)(() =>
- {
- item.Text = string.Format("{0}({1})", arg1.LineInfo.Name, arg2);
- }));
- break;
- }
- }
- }
- private void Instance_OnDisplayInfo(string obj)
- {
- this.BeginInvoke((Action)(() =>
- {
- label1.Text = obj;
- }));
- }
- private async Task RailAgvOperate(object sender, Action<int> action)
- {
- (sender as Control).Enabled = false;
- int agvMaxNum = PackEngine.Instance.AgvMaxNum;
- await Task.Factory.StartNew(() =>
- {
- for (int index = 0; index < 3; index++)
- {
- for (int i = 1; i <= agvMaxNum; i++)
- {
- action.Invoke(i);
- System.Threading.Thread.Sleep(20);
- }
- System.Threading.Thread.Sleep(100);
- }
- });
- (sender as Control).Enabled = true;
- (sender as Control).Focus();
- }
- private async void button1_Click(object sender, EventArgs e)
- {
- var speed = numericUpDown1.Value;
- await RailAgvOperate(sender, id => DeviceControl.Instance.RailAgv_SpeedChange(id, speed));
- }
- private async void button2_Click(object sender, EventArgs e)
- {
- await RailAgvOperate(sender, id => DeviceControl.Instance.RailAgv_StartButton(id));
- }
- private async void button3_Click(object sender, EventArgs e)
- {
- await RailAgvOperate(sender, id => DeviceControl.Instance.RailAgv_StopButton(id));
- }
- private void button4_Click(object sender, EventArgs e)
- {
- int interval = (int)numericUpDown2.Value;
- int alarm = (int)numericUpDown3.Value;
- CountDown(interval, alarm);
- }
- private void button5_Click(object sender, EventArgs e)
- {
- int interval = 0;
- int alarm = 0;
- CountDown(interval, alarm);
- }
- private void CountDown(int interval, int alarm)
- {
- var dataList = stationInfoManager.GetList();
- for (int i = 0; i < dataList.Count; i++)
- {
- dataList[i].CountInterval = interval;
- dataList[i].CountAlarm = alarm;
- }
- bool result = stationInfoManager.UpdateCountdown(dataList);
- if (result)
- {
- MessageBox.Show("操作成功");
- }
- else
- {
- MessageBox.Show("操作失败");
- }
- }
- }
- }
|