using A036.Process;
|
using Bro.Common.Helper;
|
using Bro.Common.Interface;
|
using Bro.Common.Model;
|
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 Bro.Device.Station.Forms
|
{
|
public partial class MonitorSetBindFrm : Form
|
{
|
private Dictionary<string, MonitorSet> monitorSetBind = new Dictionary<string, MonitorSet>();
|
public Dictionary<string, MonitorSet> MonitorSetBind
|
{
|
get
|
{
|
return monitorSetBind;
|
}
|
set
|
{
|
if (value != null)
|
{
|
monitorSetBind = value;
|
RefreshBindView();
|
}
|
}
|
}
|
|
//private string stationCode = "";
|
//public string StationCode
|
//{
|
// get
|
// {
|
// return stationCode;
|
// }
|
// set
|
// {
|
// if (!string.IsNullOrWhiteSpace(value))
|
// {
|
// stationCode = value;
|
// LoadMethodCodes();
|
// }
|
// }
|
//}
|
|
//List<ProcessMethodAttribute> methods = new List<ProcessMethodAttribute>();
|
|
public MonitorSetBindFrm()
|
{
|
InitializeComponent();
|
}
|
|
public MonitorSetBindFrm(Dictionary<string, MonitorSet> bind)
|
{
|
InitializeComponent();
|
|
LoadMethodCodes();
|
|
if (bind != null)
|
{
|
//MonitorSetBind = bind;
|
|
methods.ForEach(u =>
|
{
|
bool isMatch = false;
|
foreach (var pair in bind)
|
{
|
if (pair.Key == u.MethodCode)
|
{
|
isMatch = true;
|
MonitorSetBind.Add(pair.Key, pair.Value);
|
break;
|
}
|
}
|
|
if (!isMatch)
|
{
|
MonitorSetBind.Add(u.MethodCode, new MonitorSet());
|
}
|
});
|
|
var keyList = MonitorSetBind.Select(u => u.Key).ToList();
|
keyList = keyList.OrderBy(u => u).ToList();
|
Dictionary<string, MonitorSet> tempDict = new Dictionary<string, MonitorSet>();
|
keyList.ForEach(k =>
|
{
|
tempDict[k] = MonitorSetBind[k];
|
});
|
|
MonitorSetBind = tempDict;
|
|
RefreshBindView();
|
}
|
|
propGridMonitorSet.PropertyValueChanged += PropGridMonitorSet_PropertyValueChanged;
|
}
|
|
private void PropGridMonitorSet_PropertyValueChanged(object s, PropertyValueChangedEventArgs e)
|
{
|
var ms = propGridMonitorSet.SelectedObject as MonitorSet;
|
lvBinds.Items[selectedIndex].Text = ms.TriggerIndex + "-" + ms.TriggerValue + "-" + String.Join(",", ms.InputDataIndex) + "-" + ms.ReplyDataAddress + "-" + ms.NoticeAddress;
|
}
|
|
private void RefreshBindView()
|
{
|
lvBinds.Items.Clear();
|
|
foreach (var pair in MonitorSetBind)
|
{
|
var ms = pair.Value;
|
ListViewItem item = new ListViewItem(ms.TriggerIndex + "-" + ms.TriggerValue + "-" + String.Join(",", ms.InputDataIndex) + "-" + ms.ReplyDataAddress + "-" + ms.NoticeAddress);
|
|
item.SubItems.Add(pair.Key);
|
|
lvBinds.Items.Add(item);
|
}
|
}
|
|
private void LoadMethodCodes()
|
{
|
IProcess sp = new ProcessControl();
|
|
methods = sp.ProcessMethodCollection;
|
var pms = methods.ConvertAll(u =>
|
{
|
return new { Desc = u.MethodCode + "--" + u.MethodDesc, Value = u.MethodCode };
|
});
|
|
//cboMethods.DataSource = pms;
|
//cboMethods.DisplayMember = "Desc";
|
//cboMethods.ValueMember = "Value";
|
}
|
|
int selectedIndex = -1;
|
private void lvBinds_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
if (lvBinds.SelectedIndices.Count > 0)
|
{
|
selectedIndex = lvBinds.SelectedIndices[0];
|
|
string ms = MonitorSetBind.Keys.ElementAt(selectedIndex);
|
|
propGridMonitorSet.SelectedObject = MonitorSetBind[ms];
|
|
var method = methods.FirstOrDefault(u => u.MethodCode == ms);
|
lblMethodCode.Text = method.MethodCode + "\r\n" + method.MethodDesc;
|
|
//cboMethods.SelectedValue = MonitorSetBind[ms];
|
}
|
}
|
|
private void btnAddBind_Click(object sender, EventArgs e)
|
{
|
MonitorSet ms = new MonitorSet();
|
MonitorSetBind.Add("", ms);
|
|
MonitorSetBind = MonitorSetBind;
|
}
|
|
private void btnRemoveBind_Click(object sender, EventArgs e)
|
{
|
if (lvBinds.SelectedIndices.Count > 0)
|
{
|
int index = lvBinds.SelectedIndices[0];
|
|
var ms = MonitorSetBind.Keys.ElementAt(index);
|
|
MonitorSetBind.Remove(ms);
|
}
|
else
|
{
|
MessageBox.Show("请选择需要删除的绑定关系");
|
}
|
}
|
|
private void cboMethods_SelectedIndexChanged(object sender, EventArgs e)
|
{
|
//if (cboMethods.SelectedValue != null)
|
//{
|
// var ms = propGridMonitorSet.SelectedObject as MonitorSet;
|
// if (ms != null && MonitorSetBind.Values.Contains(ms))
|
// {
|
// MonitorSetBind[ms] = cboMethods.SelectedValue.ToString();
|
|
// lvBinds.Items[selectedIndex].SubItems[1].Text = cboMethods.SelectedValue.ToString();
|
// }
|
//}
|
}
|
}
|
}
|