You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
460 lines
16 KiB
C#
460 lines
16 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.IO;
|
|
using System.Xml;
|
|
using System.Windows.Forms;
|
|
using Mesnac.Equips.SetConfig.DataConfig;
|
|
using Mesnac.Equips.BaseInfo;
|
|
using Mesnac.Equips.SetConfig;
|
|
|
|
|
|
namespace Mesnac.Equips.SetConfig
|
|
{
|
|
public partial class DataConfigForm : Mesnac.PlugIn.View.DefaultViewContent
|
|
{
|
|
private ConfigEquipFactory configEquipFactory = null;
|
|
public DataConfigForm(string configFile, string prjectName)
|
|
{
|
|
configEquipFactory = new ConfigEquipFactory(configFile, prjectName);
|
|
configEquipFactory.OnCurrentEquipChange += myCurrentEquipChange;
|
|
configEquipFactory.OnCurrentGroupChange += myCurrentGroupChange;
|
|
configEquipFactory.OnCurrentDataChange += myCurrentDataChange;
|
|
InitializeComponent();
|
|
}
|
|
public void InitializeConfigInfo()
|
|
{
|
|
configEquipFactory.ReadConfig();
|
|
ShowEquip();
|
|
}
|
|
private void DataConfigForm_Shown(object sender, EventArgs e)
|
|
{
|
|
}
|
|
|
|
#region BaseEquip
|
|
private void ShowEquip()
|
|
{
|
|
myCurrentChange();
|
|
this.listView1.Items.Clear();
|
|
this.listView2.Items.Clear();
|
|
this.listView3.Items.Clear();
|
|
int index = 0;
|
|
foreach (BaseEquip equip in configEquipFactory.AllEquips.Values)
|
|
{
|
|
index++;
|
|
ListViewItem item = this.listView1.Items.Add(equip.Name.ToString());
|
|
item.SubItems.Add(index.ToString());
|
|
item.SubItems.Add(equip.Name);
|
|
item.SubItems.Add(equip.Project);
|
|
item.SubItems.Add(equip.Main.Brand);
|
|
item.SubItems.Add(equip.Main.Model);
|
|
//item.SubItems.Add(equip.Main.ConnType.IP);
|
|
if (equip.Main.ConnType is Mesnac.Equips.Connection.Default.ConnType)
|
|
{
|
|
var type = equip.Main.ConnType as Mesnac.Equips.Connection.Default.ConnType;
|
|
item.SubItems.Add(type.IP);
|
|
}
|
|
else
|
|
{
|
|
item.SubItems.Add("");
|
|
}
|
|
}
|
|
if (configEquipFactory.CurrentEquip == null)
|
|
{
|
|
if (this.listView1.Items.Count > 0)
|
|
{
|
|
this.listView1.Items[0].Selected = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < this.listView1.Items.Count; i++)
|
|
{
|
|
if (this.listView1.Items[i].Text == configEquipFactory.CurrentEquip.Name)
|
|
{
|
|
this.listView1.Items[i].Selected = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (listView1.SelectedItems.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
string ss = listView1.SelectedItems[0].Text;
|
|
foreach (ConfigEquip equip in configEquipFactory.AllEquips.Values)
|
|
{
|
|
if (ss.Trim() == equip.Name.Trim())
|
|
{
|
|
configEquipFactory.CurrentEquip = equip;
|
|
ShowGroup();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
private void toolStripMenuItem7_Click(object sender, EventArgs e)
|
|
{
|
|
NewEquipForm form = new NewEquipForm(configEquipFactory, true);
|
|
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
ShowEquip();
|
|
}
|
|
}
|
|
#region 右键菜单事件
|
|
private void toolStripMenuItem8_Click(object sender, EventArgs e)
|
|
{
|
|
if (configEquipFactory == null
|
|
|| configEquipFactory.CurrentEquip == null)
|
|
{
|
|
MessageBox.Show("请选择需要修改的设备!");
|
|
return;
|
|
}
|
|
NewEquipForm form = new NewEquipForm(configEquipFactory, false);
|
|
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
ShowEquip();
|
|
}
|
|
}
|
|
private void toolStripMenuItem9_Click(object sender, EventArgs e)
|
|
{
|
|
if (configEquipFactory == null
|
|
|| configEquipFactory.CurrentEquip == null)
|
|
{
|
|
MessageBox.Show("请选择需要删除的设备!");
|
|
return;
|
|
}
|
|
if (MessageBox.Show("确认删除此条信息[" + configEquipFactory.CurrentEquip.Name + "]", "提示",
|
|
MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
|
|
{
|
|
return;
|
|
}
|
|
configEquipFactory.AllEquips.Remove(configEquipFactory.CurrentEquip.Name);
|
|
configEquipFactory.CurrentEquip = null;
|
|
ShowEquip();
|
|
}
|
|
|
|
private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
toolStripMenuItem8.PerformClick();
|
|
}
|
|
#endregion
|
|
#endregion
|
|
|
|
#region Group
|
|
|
|
private void ShowGroup()
|
|
{
|
|
myCurrentChange();
|
|
this.listView2.Items.Clear();
|
|
this.listView3.Items.Clear();
|
|
int index = 0;
|
|
foreach (KeyValuePair<string, Group> group in this.configEquipFactory.CurrentEquip.Group)
|
|
{
|
|
index++;
|
|
ListViewItem item = this.listView2.Items.Add(group.Key);
|
|
item.SubItems.Add(index.ToString());
|
|
item.SubItems.Add(group.Value.Name);
|
|
item.SubItems.Add(group.Value.Block.ToString());
|
|
item.SubItems.Add(group.Value.Start.ToString());
|
|
item.SubItems.Add(group.Value.Len.ToString());
|
|
item.SubItems.Add(group.Value.Access.ToString());
|
|
if (group.Value.IsAutoRead)
|
|
{
|
|
item.SubItems.Add("√");
|
|
}
|
|
else
|
|
{
|
|
item.SubItems.Add(string.Empty);
|
|
}
|
|
item.SubItems.Add(group.Value.Remark.ToString());
|
|
}
|
|
|
|
if (configEquipFactory.CurrentGroup == null)
|
|
{
|
|
if (this.listView2.Items.Count > 0)
|
|
{
|
|
this.listView2.Items[0].Selected = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < this.listView2.Items.Count; i++)
|
|
{
|
|
if (this.listView2.Items[i].Text == configEquipFactory.CurrentGroup.Name)
|
|
{
|
|
this.listView2.Items[i].Selected = true;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
private void listView2_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (listView2.SelectedItems.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
string ss = listView2.SelectedItems[0].Text;
|
|
foreach (Group group in configEquipFactory.CurrentEquip.Group.Values)
|
|
{
|
|
if (ss.Trim() == group.Name.Trim())
|
|
{
|
|
configEquipFactory.CurrentGroup = group;
|
|
ShowData();
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
#region 右键菜单事件
|
|
private void toolStripMenuItem1_Click(object sender, EventArgs e)
|
|
{
|
|
if (configEquipFactory == null
|
|
|| configEquipFactory.CurrentEquip == null)
|
|
{
|
|
MessageBox.Show("请选择需要添加信息组的设备!");
|
|
return;
|
|
}
|
|
NewGroupForm form = new NewGroupForm(configEquipFactory, true);
|
|
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
ShowGroup();
|
|
}
|
|
}
|
|
private void toolStripMenuItem2_Click(object sender, EventArgs e)
|
|
{
|
|
if (configEquipFactory == null
|
|
|| configEquipFactory.CurrentEquip == null
|
|
|| configEquipFactory.CurrentGroup == null)
|
|
{
|
|
MessageBox.Show("请选择需要修改的信息组!");
|
|
return;
|
|
}
|
|
NewGroupForm form = new NewGroupForm(configEquipFactory, false);
|
|
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
ShowGroup();
|
|
}
|
|
}
|
|
private void toolStripMenuItem3_Click(object sender, EventArgs e)
|
|
{
|
|
if (configEquipFactory == null
|
|
|| configEquipFactory.CurrentEquip == null
|
|
|| configEquipFactory.CurrentGroup == null)
|
|
{
|
|
MessageBox.Show("请选择需要删除的信息组!");
|
|
return;
|
|
}
|
|
if (MessageBox.Show("确认删除此条信息[" + configEquipFactory.CurrentGroup.Name + "]", "提示",
|
|
MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
|
|
{
|
|
return;
|
|
}
|
|
configEquipFactory.CurrentEquip.Group.Remove(configEquipFactory.CurrentGroup.Name);
|
|
configEquipFactory.CurrentGroup = null;
|
|
ShowGroup();
|
|
}
|
|
private void listView2_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
toolStripMenuItem2.PerformClick();
|
|
}
|
|
#endregion
|
|
#endregion
|
|
|
|
#region Data
|
|
private void ShowData()
|
|
{
|
|
myCurrentChange();
|
|
this.listView3.Items.Clear();
|
|
int index = 0;
|
|
foreach (KeyValuePair<string, Data> data in this.configEquipFactory.CurrentGroup.Data)
|
|
{
|
|
index++;
|
|
ListViewItem item = this.listView3.Items.Add(data.Key);
|
|
item.SubItems.Add(index.ToString());
|
|
item.SubItems.Add(data.Value.Name.ToString());
|
|
item.SubItems.Add(data.Value.RunName.ToString());
|
|
item.SubItems.Add(data.Value.Start.ToString());
|
|
item.SubItems.Add(data.Value.Len.ToString());
|
|
item.SubItems.Add(data.Value.Method.ToString());
|
|
item.SubItems.Add(data.Value.Max.ToString());
|
|
item.SubItems.Add(data.Value.Subtractor.ToString());
|
|
if (data.Value.IsSave)
|
|
{
|
|
item.SubItems.Add("√");
|
|
}
|
|
else
|
|
{
|
|
item.SubItems.Add(string.Empty);
|
|
}
|
|
item.SubItems.Add(data.Value.Remark.ToString());
|
|
}
|
|
|
|
if (configEquipFactory.CurrentData == null)
|
|
{
|
|
if (this.listView3.Items.Count > 0)
|
|
{
|
|
this.listView3.Items[0].Selected = true;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < this.listView3.Items.Count; i++)
|
|
{
|
|
if (this.listView3.Items[i].Text == configEquipFactory.CurrentData.Name)
|
|
{
|
|
this.listView3.Items[i].Selected = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
#region 右键菜单事件
|
|
private void listView3_SelectedIndexChanged(object sender, EventArgs e)
|
|
{
|
|
if (listView3.SelectedItems.Count == 0)
|
|
{
|
|
return;
|
|
}
|
|
string ss = listView3.SelectedItems[0].Text;
|
|
foreach (Data data in configEquipFactory.CurrentGroup.Data.Values)
|
|
{
|
|
if (ss.Trim() == data.Name.Trim())
|
|
{
|
|
configEquipFactory.CurrentData = data;
|
|
}
|
|
}
|
|
}
|
|
private void toolStripMenuItem4_Click(object sender, EventArgs e)
|
|
{
|
|
if (configEquipFactory == null
|
|
|| configEquipFactory.CurrentEquip == null
|
|
|| configEquipFactory.CurrentGroup == null)
|
|
{
|
|
MessageBox.Show("请选择需要添加数据点的信息组!");
|
|
return;
|
|
}
|
|
NewDataForm form = new NewDataForm(configEquipFactory, true);
|
|
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
ShowData();
|
|
}
|
|
}
|
|
private void toolStripMenuItem5_Click(object sender, EventArgs e)
|
|
{
|
|
if (configEquipFactory == null
|
|
|| configEquipFactory.CurrentEquip == null
|
|
|| configEquipFactory.CurrentGroup == null
|
|
|| configEquipFactory.CurrentData == null)
|
|
{
|
|
MessageBox.Show("请选择需要修改的数据点!");
|
|
return;
|
|
}
|
|
NewDataForm form = new NewDataForm(configEquipFactory, false);
|
|
if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
ShowData();
|
|
}
|
|
}
|
|
private void toolStripMenuItem6_Click(object sender, EventArgs e)
|
|
{
|
|
if (configEquipFactory == null
|
|
|| configEquipFactory.CurrentEquip == null
|
|
|| configEquipFactory.CurrentGroup == null
|
|
|| configEquipFactory.CurrentData == null)
|
|
{
|
|
MessageBox.Show("请选择需要删除的数据点!");
|
|
return;
|
|
}
|
|
if (MessageBox.Show("确认删除此条信息[" + configEquipFactory.CurrentData.Name + "]", "提示",
|
|
MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
|
|
{
|
|
return;
|
|
}
|
|
configEquipFactory.CurrentGroup.Data.Remove(configEquipFactory.CurrentData.Name);
|
|
configEquipFactory.CurrentData = null;
|
|
ShowData();
|
|
}
|
|
private void listView3_MouseDoubleClick(object sender, MouseEventArgs e)
|
|
{
|
|
toolStripMenuItem5.PerformClick();
|
|
}
|
|
#endregion
|
|
#endregion
|
|
|
|
#region 事件
|
|
private void myCurrentChange()
|
|
{
|
|
myCurrentEquipChange(this.configEquipFactory.CurrentEquip, EventArgs.Empty);
|
|
myCurrentGroupChange(this.configEquipFactory.CurrentGroup, EventArgs.Empty);
|
|
myCurrentDataChange(this.configEquipFactory.CurrentData, EventArgs.Empty);
|
|
}
|
|
private void myCurrentEquipChange(object sender, EventArgs e)
|
|
{
|
|
ConfigEquip equip = sender as ConfigEquip;
|
|
if (equip == null)
|
|
{
|
|
this.groupBox1.Text = string.Format("请选择设备");
|
|
}
|
|
else
|
|
{
|
|
this.groupBox1.Text = string.Format("选中设备[{0}]", equip.Name);
|
|
}
|
|
}
|
|
private void myCurrentGroupChange(object sender, EventArgs e)
|
|
{
|
|
Group group = sender as Group;
|
|
if (group == null)
|
|
{
|
|
this.groupBox2.Text = string.Format("请选择信息组");
|
|
}
|
|
else
|
|
{
|
|
this.groupBox2.Text = string.Format("选中信息组[{0}]", group.Name);
|
|
}
|
|
}
|
|
private void myCurrentDataChange(object sender, EventArgs e)
|
|
{
|
|
Data data = sender as Data;
|
|
if (data == null)
|
|
{
|
|
this.groupBox3.Text = string.Format("请选择数据点");
|
|
}
|
|
else
|
|
{
|
|
this.groupBox3.Text = string.Format("选中数据点[{0}]", data.Name);
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region 保存配置
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
Factory.Instance.SaveConfig();
|
|
}
|
|
|
|
private void DataConfigForm_FormClosed(object sender, FormClosedEventArgs e)
|
|
{
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
DataConfigForm_Shown(sender, e);
|
|
}
|
|
#endregion
|
|
|
|
|
|
public void SaveConfig()
|
|
{
|
|
configEquipFactory.SaveConfig();
|
|
}
|
|
|
|
}
|
|
|
|
}
|