| | |
| | | using Bro.UI.Model.Winform; |
| | | using Bro.Common.Helper; |
| | | using Bro.UI.Model.Winform; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | |
| | | |
| | | namespace Bro.M071.Process.UI |
| | | { |
| | | [MenuNode("M071_MainForm", "键盘检测主界面", 3, "M071Node", true)] |
| | | [MenuNode("M071_MainForm", "运行界面", 1, "M071Node", true)] |
| | | public partial class M071_MainForm : MenuFrmBase |
| | | { |
| | | Canvas cvImage = new Canvas(); |
| | | M071Config Config => Process?.IConfig as M071Config; |
| | | |
| | | public M071_MainForm() |
| | | { |
| | | InitializeComponent(); |
| | | |
| | | cvImage.IsShowElementList = false; |
| | | tsmiShowStatusBar.Checked = cvImage.IsShowStatusBar = false; |
| | | tsmiShowToolBar.Checked = cvImage.IsShowToolBar = false; |
| | | cvImage.Dock = DockStyle.Fill; |
| | | plImage.Controls.Add(cvImage); |
| | | |
| | | tscEditLocation.Visible = tsmiShowEditor.Checked = false; |
| | | } |
| | | |
| | | public override void OnProcessUpdated() |
| | | { |
| | | base.OnProcessUpdated(); |
| | | |
| | | if (Config == null) |
| | | return; |
| | | |
| | | if (string.IsNullOrWhiteSpace(Config.BackgroundImagePath)) |
| | | return; |
| | | |
| | | try |
| | | { |
| | | Bitmap image = (Bitmap)Image.FromFile(Config.BackgroundImagePath); |
| | | cvImage.LoadImage(image); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | LogAsync(new LogMsg(DateTime.Now, "载入背景图异常", ex.Message)); |
| | | return; |
| | | } |
| | | |
| | | cvImage.Elements.Clear(); |
| | | lvMeasures.Items.Clear(); |
| | | Config.MeasurementUnitCollection.ForEach(u => |
| | | { |
| | | if (!u.IsEnabled) |
| | | return; |
| | | |
| | | var ele = new KeyIndicator(u.Id, u.DisplayLocation); |
| | | cvImage.Elements.Add(ele); |
| | | |
| | | ListViewItem item = new ListViewItem(u.GetDisplayText()); |
| | | item.Tag = u.Id; |
| | | lvMeasures.Items.Add(item); |
| | | }); |
| | | |
| | | txtBarcode.ReadOnly = Config.IsBarcodeManulInputBlocked; |
| | | |
| | | (Process as M071Process).OnClearBarcode -= M071_MainForm_OnClearBarcode; |
| | | (Process as M071Process).OnClearBarcode += M071_MainForm_OnClearBarcode; |
| | | } |
| | | |
| | | #region 图片区右键菜单 |
| | | private void tsmiShowToolBar_CheckedChanged(object sender, EventArgs e) |
| | | { |
| | | cvImage.IsShowToolBar = tsmiShowToolBar.Checked; |
| | | } |
| | | |
| | | private void tsmiShowStatusBar_CheckedChanged(object sender, EventArgs e) |
| | | { |
| | | cvImage.IsShowStatusBar = tsmiShowStatusBar.Checked; |
| | | } |
| | | |
| | | private void tsmiShowEditor_CheckedChanged(object sender, EventArgs e) |
| | | { |
| | | tscEditLocation.Visible = tsmiShowEditor.Checked; |
| | | tscEditLocation.BringToFront(); |
| | | } |
| | | #endregion |
| | | |
| | | #region 标签编辑区 |
| | | private void lvMeasures_SelectedIndexChanged(object sender, EventArgs e) |
| | | { |
| | | if (lvMeasures.SelectedItems.Count <= 0) |
| | | return; |
| | | |
| | | var ele = cvImage.Elements.FirstOrDefault(u => u.ID == lvMeasures.SelectedItems[0].Tag.ToString()); |
| | | propGridKeyIndicator.SelectedObject = ele; |
| | | } |
| | | |
| | | private void btnCancelEdit_Click(object sender, EventArgs e) |
| | | { |
| | | cvImage.Elements.Clear(); |
| | | lvMeasures.Items.Clear(); |
| | | Config.MeasurementUnitCollection.ForEach(u => |
| | | { |
| | | if (!u.IsEnabled) |
| | | return; |
| | | |
| | | var ele = new KeyIndicator(u.Id, u.DisplayLocation); |
| | | cvImage.Elements.Add(ele); |
| | | |
| | | ListViewItem item = new ListViewItem(u.GetDisplayText()); |
| | | item.Tag = u.Id; |
| | | lvMeasures.Items.Add(item); |
| | | }); |
| | | |
| | | MessageBox.Show("取消标签修改"); |
| | | } |
| | | |
| | | private void btnConfirmEdit_Click(object sender, EventArgs e) |
| | | { |
| | | cvImage.Elements.ToList().ForEach(ele => |
| | | { |
| | | var measure = Config.MeasurementUnitCollection.FirstOrDefault(u => u.Id == ele.ID); |
| | | if (measure != null) |
| | | { |
| | | measure.DisplayLocation = (ele as KeyIndicator).DisplayRect; |
| | | } |
| | | }); |
| | | |
| | | MessageBox.Show("标签修改完成"); |
| | | } |
| | | #endregion |
| | | |
| | | #region 上方状态区 |
| | | |
| | | #region 条码 |
| | | string _barcode = ""; |
| | | private void M071_MainForm_KeyUp(object sender, KeyEventArgs e) |
| | | { |
| | | string keyStr = e.KeyCode.ToString(); |
| | | if (keyStr.Length == 1) |
| | | { |
| | | _barcode += keyStr.ToUpper(); |
| | | } |
| | | |
| | | if (e.KeyValue == 13) |
| | | { |
| | | txtBarcode.Text = _barcode; |
| | | _barcode = ""; |
| | | } |
| | | } |
| | | |
| | | private void txtBarcode_TextChanged(object sender, EventArgs e) |
| | | { |
| | | (Process as M071Process).BarCode = txtBarcode.Text.Trim(); |
| | | } |
| | | |
| | | private void M071_MainForm_OnClearBarcode() |
| | | { |
| | | txtBarcode.BeginInvoke(new Action(() => txtBarcode.Clear())); |
| | | } |
| | | #endregion |
| | | |
| | | #endregion |
| | | |
| | | } |
| | | } |