| | |
| | | using Bro.Common.Factory; |
| | | using Bro.Common.Helper; |
| | | using Bro.Common.PubSub; |
| | | using Bro.UI.Model.Winform; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | using WeifenLuo.WinFormsUI.Docking; |
| | | using static Bro.Common.Helper.EnumHelper; |
| | | |
| | | namespace Bro.UI.Config.MenuForms |
| | | { |
| | |
| | | public FrmOperation() |
| | | { |
| | | InitializeComponent(); |
| | | PubSubCenter.GetInstance().RemoveSubscribers(PubSubCenterMessageType.UpdateProductionCodes.ToString()); |
| | | PubSubCenter.GetInstance().Subscribe(PubSubCenterMessageType.UpdateProductionCodes.ToString(), OnUpdateProductionCodes); |
| | | |
| | | LoadProcessCode(); |
| | | LoadProductionCode(); |
| | | |
| | | Task.Run(() => |
| | | { |
| | | Thread.Sleep(1000); |
| | | |
| | | if ((!plProcess.Visible) && (!plProduct.Visible) && _isFirstLoad) |
| | | { |
| | | LoadProcess(); |
| | | _isFirstLoad = false; |
| | | } |
| | | }); |
| | | } |
| | | |
| | | #region Load Codes |
| | | string _processCode = ""; |
| | | string _productionCode = ""; |
| | | |
| | | private object OnUpdateProductionCodes(ISubscriber arg1, object arg2, object arg3) |
| | | { |
| | | LoadProductionCode(); |
| | | return null; |
| | | } |
| | | |
| | | private void LoadProcessCode() |
| | | { |
| | |
| | | pCodes = systemProcessCodes; |
| | | } |
| | | |
| | | if (pCodes.Count == 1 && pCodes[0] == "") |
| | | if (pCodes.Count == 1) |
| | | { |
| | | plProcess.Visible = false; |
| | | _processCode = pCodes[0]; |
| | |
| | | } |
| | | else |
| | | { |
| | | pCodes.Remove(""); |
| | | pCodes.RemoveAll(p => string.IsNullOrWhiteSpace(p)); |
| | | } |
| | | |
| | | if (pCodes.Count > 1) |
| | | { |
| | | plProcess.Visible = true; |
| | | |
| | | //if (!string.IsNullOrWhiteSpace(SettingHelper.SettingInfo.DefaultProcess)) |
| | | //{ |
| | | // if (pCodes.Contains(SettingHelper.SettingInfo.DefaultProcess)) |
| | | // { |
| | | // pCodes.Remove(SettingHelper.SettingInfo.DefaultProcess); |
| | | // pCodes.Insert(0, SettingHelper.SettingInfo.DefaultProcess); |
| | | // } |
| | | //} |
| | | |
| | | cboProcessCode.SelectedIndexChanged -= cboProcessCode_SelectedIndexChanged; |
| | | UIHelper.SetCombo(cboProcessCode, pCodes, "", ""); |
| | |
| | | if (pCodes.Count > 1) |
| | | { |
| | | plProduct.Visible = true; |
| | | |
| | | //if (!string.IsNullOrWhiteSpace(SettingHelper.SettingInfo.DefaultProduction)) |
| | | //{ |
| | | // if (pCodes.Contains(SettingHelper.SettingInfo.DefaultProduction)) |
| | | // { |
| | | // pCodes.Remove(SettingHelper.SettingInfo.DefaultProduction); |
| | | // pCodes.Insert(0, SettingHelper.SettingInfo.DefaultProduction); |
| | | // } |
| | | //} |
| | | |
| | | cboProductionCode.SelectedIndexChanged -= cboProductionCode_SelectedIndexChanged; |
| | | UIHelper.SetCombo(cboProductionCode, pCodes, "", ""); |
| | | cboProductionCode.SelectedIndexChanged += cboProductionCode_SelectedIndexChanged; |
| | |
| | | |
| | | LogAsync(DateTime.Now, "载入流程"); |
| | | LoadProcess(); |
| | | |
| | | SettingHelper.SetDefault(_processCode, _productionCode); |
| | | } |
| | | |
| | | bool isStart = true; |
| | | private void btnStart_Click(object sender, System.EventArgs e) |
| | | private async void btnStart_Click(object sender, System.EventArgs e) |
| | | { |
| | | if (Process == null) |
| | | { |
| | |
| | | |
| | | try |
| | | { |
| | | //if (Process.ProcessState != EnumHelper.DeviceState.DSOpen) |
| | | if(isStart) |
| | | if (isStart) |
| | | { |
| | | ProcessOperation(true); |
| | | await ProcessOperation(true); |
| | | } |
| | | else |
| | | { |
| | | ProcessOperation(false); |
| | | await ProcessOperation(false); |
| | | } |
| | | |
| | | isStart = !isStart; |
| | |
| | | return; |
| | | } |
| | | |
| | | //Process.OnProcessStateChanged += Process_OnProcessStateChanged; |
| | | Process.OnLog -= Process_OnLog; |
| | | Process.OnLog += Process_OnLog; |
| | | |
| | | _currentProcssCode = _processCode; |
| | |
| | | LogAsync(dt, prefix, msg); |
| | | } |
| | | |
| | | //private void Process_OnProcessStateChanged(EnumHelper.DeviceState state) |
| | | //{ |
| | | // try |
| | | // { |
| | | // if (InvokeRequired) |
| | | // { |
| | | // this.Invoke(new Action<EnumHelper.DeviceState>(Process_OnProcessStateChanged), state); |
| | | // } |
| | | // else |
| | | // { |
| | | // try |
| | | // { |
| | | // btnStart.Enabled = true; |
| | | |
| | | // switch (state) |
| | | // { |
| | | // case EnumHelper.DeviceState.DSOpen: |
| | | // btnStart.Text = " 停 止"; |
| | | // btnStart.ImageIndex = 1; |
| | | // btnStart.BackColor = Color.FromArgb(0x7f, Color.LimeGreen); |
| | | |
| | | // btnLoad.Enabled = false; |
| | | // break; |
| | | // case EnumHelper.DeviceState.DSClose: |
| | | // btnStart.Text = " 启 动"; |
| | | // btnStart.ImageIndex = 0; |
| | | // btnStart.BackColor = SystemColors.Control; |
| | | |
| | | // btnLoad.Enabled = true; |
| | | // break; |
| | | // default: |
| | | // break; |
| | | // } |
| | | |
| | | // this.Refresh(); |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // } |
| | | // } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // } |
| | | //} |
| | | |
| | | private void ProcessOperation(bool isStart) |
| | | private async Task ProcessOperation(bool isStart) |
| | | { |
| | | if (isStart) |
| | | { |
| | | Process.Open(); |
| | | await Task.Run(() => Process.Open()); |
| | | |
| | | btnStart.Text = " 停 止"; |
| | | btnStart.ImageIndex = 1; |
| | |
| | | } |
| | | else |
| | | { |
| | | Process.Close(); |
| | | await Task.Run(() => Process.Close()); |
| | | |
| | | btnStart.Text = " 启 动"; |
| | | btnStart.ImageIndex = 0; |