using Bro.Common.Base;
|
using Bro.Common.Factory;
|
using Bro.Common.Helper;
|
using Bro.Common.Interface;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Windows.Forms;
|
|
namespace Bro.Process.UI
|
{
|
public partial class OperationConfigBindFrm : Form
|
{
|
//private Dictionary<string, IOperationConfig> opBinds = new Dictionary<string, IOperationConfig>();
|
public Dictionary<string, IOperationConfig> OpBinds { get; set; } = new Dictionary<string, IOperationConfig>();
|
//{
|
// get
|
// {
|
// return opBinds;
|
// }
|
// set
|
// {
|
// if (value != null)
|
// {
|
// opBinds = value;
|
// RefreshBindView();
|
// }
|
// }
|
//}
|
|
//private string stationCode = "";
|
//public string StationCode
|
//{
|
// get
|
// {
|
// return stationCode;
|
// }
|
// set
|
// {
|
// if (!string.IsNullOrWhiteSpace(value))
|
// {
|
// stationCode = value;
|
// LoadMethodCodes();
|
// }
|
// }
|
//}
|
|
Dictionary<string, Type> AllOpDict = new Dictionary<string, Type>();
|
List<ProcessMethodAttribute> ProcessMethodList = new List<ProcessMethodAttribute>();
|
|
public OperationConfigBindFrm()
|
{
|
InitializeComponent();
|
}
|
|
public OperationConfigBindFrm(Dictionary<string, IOperationConfig> bind)
|
{
|
InitializeComponent();
|
|
GetAllOpConfig();
|
|
//StationCode = scode;
|
LoadMethodCodes();
|
|
if (bind != null)
|
{
|
for (int i = 0; i < OpBinds.Keys.Count; i++)
|
{
|
string s = OpBinds.Keys.ElementAt(i);
|
if (bind.Keys.Contains(s))
|
{
|
OpBinds[s] = bind[s];
|
}
|
}
|
|
RefreshBindView();
|
}
|
|
propGridIOP.PropertyValueChanged += PropGridMonitorSet_PropertyValueChanged;
|
}
|
|
private void PropGridMonitorSet_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
|
{
|
var config = propGridIOP.SelectedObject as IOperationConfig;
|
lvBinds.Items[selectedIndex].SubItems[1].Text = JsonConvert.SerializeObject(config);
|
}
|
|
private void RefreshBindView()
|
{
|
lvBinds.Items.Clear();
|
|
foreach (var pair in OpBinds)
|
{
|
var ms = pair.Key;
|
ListViewItem item = new ListViewItem(pair.Key);
|
|
item.SubItems.Add(JsonConvert.SerializeObject(pair.Value as IOperationConfig));
|
|
lvBinds.Items.Add(item);
|
}
|
}
|
|
private void GetAllOpConfig()
|
{
|
this.GetType().Assembly.GetReferencedAssemblies().ToList().ForEach(a =>
|
{
|
Assembly.Load(a).GetTypes().ToList().ForEach(t =>
|
{
|
var attr = t.GetCustomAttribute<DeviceAttribute>();
|
if (attr != null && attr.AttrType == EnumHelper.DeviceAttributeType.OperationConfig)
|
{
|
AllOpDict[attr.TypeCode] = t;
|
}
|
});
|
});
|
|
this.GetType().Assembly.GetTypes().ToList().ForEach(t =>
|
{
|
var attr = t.GetCustomAttribute<DeviceAttribute>();
|
if (attr != null && attr.AttrType == EnumHelper.DeviceAttributeType.OperationConfig)
|
{
|
AllOpDict[attr.TypeCode] = t;
|
}
|
});
|
|
var deviceOpConfigs = ConfigFactory.GetAllOpConfigTypes();
|
|
foreach (string s in deviceOpConfigs.Keys)
|
{
|
AllOpDict[s] = deviceOpConfigs[s];
|
}
|
}
|
|
private void LoadMethodCodes()
|
{
|
IProcess sp = new ProcessControl();
|
//switch (StationCode)
|
//{
|
// case "S1":
|
// sp = new StationProcess_S1(false);
|
// break;
|
// case "S2":
|
// sp = new StationProcess_S2(false);
|
// break;
|
// case "S3":
|
// sp = new StationProcess_S3(false);
|
// break;
|
// case "S4":
|
// sp = new StationProcess_S4(false);
|
// break;
|
// case "S5":
|
// sp = new StationProcess_S5(false);
|
// break;
|
// case "S6":
|
// sp = new StationProcess_S6(false);
|
// break;
|
// case "S7":
|
// sp = new StationProcess_S7(false);
|
// break;
|
// //case "S0":
|
// // sp = new StationProcess_S0(false);
|
// // break;
|
//}
|
|
OpBinds = new Dictionary<string, IOperationConfig>();
|
|
ProcessMethodList = sp.ProcessMethodCollection;
|
|
ProcessMethodList.ForEach(u =>
|
{
|
if (!string.IsNullOrWhiteSpace(u.DeviceType))
|
{
|
OpBinds[u.MethodCode] = Activator.CreateInstance(AllOpDict[u.DeviceType]) as IOperationConfig;
|
}
|
else
|
{
|
OpBinds[u.MethodCode] = new OperationConfigBase();
|
}
|
});
|
}
|
|
int selectedIndex = -1;
|
private void lvBinds_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
if (lvBinds.SelectedIndices.Count > 0)
|
{
|
selectedIndex = lvBinds.SelectedIndices[0];
|
|
var ms = OpBinds.Keys.ElementAt(selectedIndex);
|
|
propGridIOP.SelectedObject = null;
|
propGridIOP.SelectedObject = OpBinds[ms];
|
}
|
}
|
|
private void btnAddBind_Click(object sender, EventArgs e)
|
{
|
//MonitorSet ms = new MonitorSet();
|
//OpBinds.Add("",);
|
|
//OpBinds = OpBinds;
|
}
|
|
private void btnRemoveBind_Click(object sender, EventArgs e)
|
{
|
//if (lvBinds.SelectedIndices.Count > 0)
|
//{
|
// int index = lvBinds.SelectedIndices[0];
|
|
// var ms = OpBinds.Keys.ElementAt(index);
|
|
// OpBinds.Remove(ms);
|
//}
|
//else
|
//{
|
// MessageBox.Show("请选择需要删除的绑定关系");
|
//}
|
}
|
|
private void cboMethods_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
//if (cboMethods.SelectedValue != null)
|
//{
|
// var ms = propGridIOP.SelectedObject as MonitorSet;
|
// if (ms != null && OpBinds.Keys.Contains(ms))
|
// {
|
// OpBinds[ms] = cboMethods.SelectedValue.ToString();
|
|
// lvBinds.Items[selectedIndex].SubItems[1].Text = cboMethods.SelectedValue.ToString();
|
// }
|
//}
|
}
|
|
private void btnClearOpConfig_Click(object sender, EventArgs e)
|
{
|
if (MessageBox.Show("是否确认清空所有操作配置?", "清除提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
{
|
OpBinds.Clear();
|
MessageBox.Show("清除成功!");
|
}
|
}
|
|
private void btnResetCurrentOpConfig_Click(object sender, EventArgs e)
|
{
|
if (lvBinds.SelectedIndices.Count > 0)
|
{
|
if (MessageBox.Show("是否确认重置当前操作配置?", "重置提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
{
|
selectedIndex = lvBinds.SelectedIndices[0];
|
|
var ms = OpBinds.Keys.ElementAt(selectedIndex);
|
|
propGridIOP.SelectedObject = null;
|
propGridIOP.SelectedObject = OpBinds[ms] = Activator.CreateInstance(AllOpDict[ProcessMethodList.FirstOrDefault(u => u.MethodCode == ms).DeviceType]) as IOperationConfig;
|
|
MessageBox.Show("重置成功!");
|
}
|
}
|
else
|
{
|
MessageBox.Show("请选择需要重置的操作");
|
}
|
}
|
}
|
}
|