|
- using Glorysoft.SECS.EQP;
- using Glorysoft.SECS.EQP.Common;
- using Glorysoft.SECS.EQP.Utilities;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Windows.Forms;
- using Glorysoft.EAP.Core.Constant;
- using ARI.EAP.HOST.SRD;
- using Glorysoft.SECS.EQP.Commands;
- using Glorysoft.SECS.EQP.Message;
- using ARI.EAP.HOST.Common;
- using System.Threading.Tasks;
- using ARI.EAP.HOST.Utilities;
- using ARI.EAP.HOST.MQ;
- using Glorysoft.SECSwell;
- using System.Data;
- using ExcelDataReader;
- using System.Threading;
-
- namespace ARI.EAP.HOST
- {
- public partial class MainForm : Form
- {
- public static List<SECSContext> eqpContexts;
- public static Scenario scenario;
- public static Mq mq;
- private string previousEditValue;
-
- public MainForm()
- {
- InitializeComponent();
- Configurations.conf = XmlSerializeUtil.Deserialize<Configurations>(File.ReadAllText(Constants.configuerPath));
- eqpContexts = new List<SECSContext>();
- mq = new Mq();
- Global.MF = this;
- }
-
- private void MainForm_Load(object sender, EventArgs e)
- {
- this.ConnectStatus.Text = EquipmentStatus.EqConnectState;
- this.MQStatus.Text = EquipmentStatus.MQstate;
- this.Text = Configurations.conf.connectSetting.equipmentName1;
- this.editIPaddress.Text = Configurations.conf.connectSetting.remoteIp;
- this.editDeviceID.Text = Configurations.conf.connectSetting.deviceId;
- this.editPort.Text = Configurations.conf.connectSetting.remotePort;
- VIDLoad();
- EquipmentStatus.EapState = RunState.Run;
- this.Connect.PerformClick();
- }
-
- #region IP等设置输入相关验证
- private void editIPaddress_KeyPress(object sender, KeyPressEventArgs e)
- {
- int kc = (int)e.KeyChar;
- if ((kc < 48 || kc > 57) && kc != 8 && kc != 46)
- {
- e.Handled = true;
- }
- }
-
- private void editDeviceID_KeyPress(object sender, KeyPressEventArgs e)
- {
- int kc = (int)e.KeyChar;
- if ((kc < 48 || kc > 57) && kc != 8)
- {
- e.Handled = true;
- }
- }
-
- private void editPort_KeyPress(object sender, KeyPressEventArgs e)
- {
- int kc = (int)e.KeyChar;
- if ((kc < 48 || kc > 57) && kc != 8)
- {
- e.Handled = true;
- }
- }
-
- private void editIPaddress_Leave(object sender, EventArgs e)
- {
- if (JudgeIPFormat(editIPaddress.Text) == true)
- {
- IPError.Visible = false;
- }
- else
- {
- IPError.Visible = true;
- }
- }
-
- private void editDeviceID_Leave(object sender, EventArgs e)
- {
- if (JudgePortFormat(editDeviceID.Text) == true)
- {
- ErrorDeviceID.Visible = false;
- }
- else
- {
- ErrorDeviceID.Visible = true;
- }
- }
-
- private void editPort_Leave(object sender, EventArgs e)
- {
- if (JudgePortFormat(editPort.Text) == true)
- {
- ErrorPort.Visible = false;
- }
- else
- {
- ErrorPort.Visible = true;
- }
- }
-
- //IP地址合法性检测
- public static bool JudgeIPFormat(string strJudgeString)
- {
- bool blnTest;
- bool _Result = true;
-
- System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$");
- blnTest = regex.IsMatch(strJudgeString);
- if (blnTest == true)
- {
- string[] strTemp = strJudgeString.Split(new char[] { '.' }); // textBox1.Text.Split(new char[] { ‘.’ });
- int nDotCount = strTemp.Length - 1; //字符串中.的数量,若.的数量小于3,则是非法的ip地址
- if (3 == nDotCount)//判断字符串中.的数量
- {
- for (int i = 0; i < strTemp.Length; i++)
- {
- if (Convert.ToInt32(strTemp[i]) > 255)
- { //大于255则提示,不符合IP格式
- _Result = false;
- }
- }
- }
- else
- {
- _Result = false;
- }
- }
- else
- {//输入非数字则提示,不符合IP格式
- _Result = false;
- }
- return _Result;
- }
-
- //deviceID 和 Port 合法性检测
- public static bool JudgePortFormat(string strJudgeString)
- {
- bool blnTest;
-
- System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("^[0-9]{1,5}$");
- blnTest = regex.IsMatch(strJudgeString);
- return blnTest;
- }
- #endregion
-
- #region IP配置保存和取消
- private void Save_Click(object sender, EventArgs e)
- {
- //配置出错时不进行保存
- if (IPError.Visible == true || ErrorPort.Visible == true || ErrorDeviceID.Visible == true)
- {
- MessageBox.Show("Please check configuration", "NOTICE");
- return;
- }
-
- Configurations.conf.connectSetting.deviceId = editDeviceID.Text;
- Configurations.conf.connectSetting.remoteIp = editIPaddress.Text;
- Configurations.conf.connectSetting.remotePort = editPort.Text;
- XmlSerializeUtil.Serializer<Configurations>(Configurations.conf);
- MessageBox.Show("Save Successful", "NOTICE");
- }
-
- private void Cancle_Click(object sender, EventArgs e)
- {
- this.editIPaddress.Text = Configurations.conf.connectSetting.remoteIp;
- this.editDeviceID.Text = Configurations.conf.connectSetting.deviceId;
- this.editPort.Text = Configurations.conf.connectSetting.remotePort;
- IPError.Visible = false;
- ErrorDeviceID.Visible = false;
- ErrorPort.Visible = false;
- }
- #endregion
-
- #region 连接和断开连接点击事件
- private void Connect_Click(object sender, EventArgs e)
- {
- try
- {
- EquipmentStatus.initStatus = false;
- if (SimulatorInfo.Instance.Context != null && SimulatorInfo.Instance.Context.IsConnected)
- {
- SimulatorInfo.Instance.Context.Close();
- }
- EquipmentStatus.EqConnectState = ConnectState.connecting;
- ConnectThread();
- }
- catch(Exception ee)
- {
- MessageBox.Show(ee.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- LoggerService.SYSLogger.Error(ee);
- }
- }
-
- private void Disconnect_Click(object sender, EventArgs e)
- {
- try
- {
- if (SimulatorInfo.Instance.Context != null && SimulatorInfo.Instance.Context.IsConnected)
- {
- SimulatorInfo.Instance.Context.Close();
- }
- }
- catch (Exception ee)
- {
- MessageBox.Show(ee.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- LoggerService.SYSLogger.Error(ee);
- }
- }
- #endregion
-
- #region 指令点击事件
- private void S1F3Request_Click(object sender, EventArgs e)
- {
- if (this.ConnectStatus.Text != ConnectState.connected)
- {
- return;
- }
- Command.S1F3Command(null);
- }
-
- private void S5F3_Click(object sender, EventArgs e)
- {
- if (this.ConnectStatus.Text != ConnectState.connected)
- {
- return;
- }
- S5F3Item item = new S5F3Item();
- if (EquipmentStatus.S5F3 == "AlarmDisable")
- {
-
- item.ALED = 128;
- item.ALID = 0;
- Command.S5F3Command(item, null);
- }
- else
- {
- item.ALED = 0;
- item.ALID = 0;
- Command.S5F3Command(item, null);
- }
- }
-
- public void S5F3BottonUpdate(string name)
- {
- if (this.ConnectStatus.Text != ConnectState.connected)
- {
- return;
- }
- Action act = delegate
- {
- this.S5F3.Text = name;
- };
- this.BeginInvoke(act);
- }
-
- private void S5F5_Click(object sender, EventArgs e)
- {
- if (this.ConnectStatus.Text != ConnectState.connected)
- {
- return;
- }
- Command.S5F5Command();
- }
-
- private void S7F19_Click(object sender, EventArgs e)
- {
- if (this.ConnectStatus.Text != ConnectState.connected)
- {
- return;
- }
- Command.S7F19Command();
- }
-
- private void S2F13_Click(object sender, EventArgs e)
- {
- if (this.ConnectStatus.Text != ConnectState.connected)
- {
- return;
- }
- Command.S2F13Command();
- }
-
- private void Local_Click(object sender, EventArgs e)
- {
- if (this.ConnectStatus.Text != ConnectState.connected)
- {
- return;
- }
- try
- {
- S2F15Item item = new S2F15Item();
- var content = Configurations.conf.commandContentCollection.findContent("S2F15_ControlState").content;
- foreach (string value in content)
- {
- EC ec = new EC();
- var ecv = Configurations.conf.sRDConfiguration.findEC(value);
- ec.ECID = ecv.ecid;
- item.ECs.Add(ec);
- }
- item.ECs[0].ECV = 4;
- item.ECs[1].ECV = 4;
- int tag = 1;
- Command.S2F15Command(item, tag);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- LoggerService.SYSLogger.Error(ex.Message);
- }
- }
-
- private void Remote_Click(object sender, EventArgs e)
- {
- if (this.ConnectStatus.Text != ConnectState.connected)
- {
- return;
- }
- try
- {
- S2F15Item item = new S2F15Item();
- var content = Configurations.conf.commandContentCollection.findContent("S2F15_ControlState").content;
- foreach (string value in content)
- {
- EC ec = new EC();
- var ecv = Configurations.conf.sRDConfiguration.findEC(value);
- ec.ECID = ecv.ecid;
- item.ECs.Add(ec);
- }
- item.ECs[0].ECV = 5;
- item.ECs[1].ECV = 5;
- int tag = 1;
- Command.S2F15Command(item, tag);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
- LoggerService.SYSLogger.Error(ex.Message);
- }
- }
- #endregion
-
- #region 窗口关闭事件
- private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
- {
- if (EquipmentStatus.EqConnectState.Equals(ConnectState.connected))
- {
- SimulatorInfo.Instance.Context.Close();
- }
- mq.Close();
- EquipmentStatus.socketClient.Disconnected();
- EquipmentStatus.EapState = RunState.Stop;
- }
- #endregion
-
- #region log详细内容展示
- private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- string eventName, eventContent;
- eventName = dataGridView1.CurrentRow.Cells[3].Value.ToString();
- eventContent = dataGridView1.CurrentRow.Cells[4].Value.ToString();
- LogForm LF = new LogForm(eventName, eventContent);
- Task.Run(() =>
- {
- try
- {
- LF.ShowDialog();
- }
- finally
- {
- LF.Dispose();
- }
- });
-
- }
-
- private void dataGridView2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
- {
- string eventContent, eventName;
- eventContent = dataGridView2.CurrentRow.Cells[3].Value.ToString();
- eventName = dataGridView2.CurrentRow.Cells[2].Value.ToString();
-
- LogForm LF = new LogForm(eventName, eventContent);
- Task.Run(() =>
- {
- try
- {
- LF.ShowDialog();
- }
- finally
- {
- LF.Dispose();
- }
- });
- }
- #endregion
-
- #region 设备连接初始化
- public void ConnectThread()
- {
- try
- {
- AppSettingsConf.Conf = JsonConvert.DeserializeObject<AppSettingsConf>(File.ReadAllText(ReCache.EapSettingsFilePath),
- new JsonSerializerSettings() { StringEscapeHandling = StringEscapeHandling.EscapeNonAscii });
- SimulatorInfo.Instance.Scenarios = Configurations.conf.scenarioCollection;
- var eqpid = Configurations.conf.connectSetting.name;
- SimulatorInfo.Instance.Context = new SECSContext(eqpid, (short)Convert.ToInt32(Configurations.conf.connectSetting.deviceId), Configurations.conf.connectSetting.remoteIp, Convert.ToInt32(Configurations.conf.connectSetting.remotePort));
- SimulatorInfo.Instance.Context.Open();
- }
- catch (Exception ee)
- {
- LoggerService.SECSLogger.Error($"程序错误:{ee.Message}");
- }
- }
- #endregion
-
- #region 界面log显示
- /// <summary>
- /// addlog 的摘要说明
- /// {transfer:Receive or Send;
- /// commandName:消息名称;
- /// type: 0为Primary消息,1为Secondary消息}
- /// </summary>
- public void addlog(SECSTransaction trans, string transfer, string commandName,int type)
- {
- string time = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- string SxFy = (type == 0 ? $"S{trans.Primary.Stream}F{trans.Primary.Function}" : $"S{trans.Secondary.Stream}F{trans.Secondary.Function}");
- Action act = delegate
- {
- int index = this.dataGridView1.Rows.Add();
- this.dataGridView1.Rows[index].Cells[0].Value = time;
- this.dataGridView1.Rows[index].Cells[1].Value = SxFy;
- this.dataGridView1.Rows[index].Cells[2].Value = transfer;
- this.dataGridView1.Rows[index].Cells[3].Value = commandName;
- this.dataGridView1.Rows[index].Cells[4].Value = (type == 0 ? trans.Primary : trans.Secondary);
- this.dataGridView1.FirstDisplayedScrollingRowIndex = this.dataGridView1.Rows.Count - 1;
- //界面日志只保留一千行
- if(this.dataGridView1.Rows.Count > 1000)
- {
- this.dataGridView1.Rows.RemoveAt(0);
- }
- };
- this.BeginInvoke(act);
- }
-
- public void addMQlog(string time, string trans, string name,string content)
- {
- Action act = delegate
- {
- int index = this.dataGridView2.Rows.Add();
- this.dataGridView2.Rows[index].Cells[0].Value = time;
- this.dataGridView2.Rows[index].Cells[1].Value = trans;
- this.dataGridView2.Rows[index].Cells[2].Value = name;
- this.dataGridView2.Rows[index].Cells[3].Value = content;
- this.dataGridView2.FirstDisplayedScrollingRowIndex = this.dataGridView2.Rows.Count - 1;
- //界面日志只保留一千行
- if (this.dataGridView2.Rows.Count > 1000)
- {
- this.dataGridView2.Rows.RemoveAt(0);
- }
- };
- this.BeginInvoke(act);
- }
- #endregion
-
- #region 界面连接状态显示
- public void ConnectStatusSet(string value)
- {
- Action act = delegate
- {
- this.ConnectStatus.Text = value;
- };
- this.BeginInvoke(act);
- }
-
- #endregion
-
- #region MQ界面连接状态显示
- public void MQConnectStatusSet(string value)
- {
- Action act = delegate
- {
- this.MQStatus.Text = value;
- };
- this.BeginInvoke(act);
- }
-
- #endregion
-
- #region 外部调用EAP界面各按钮接口
- public void pushBotton(string buttonName)
- {
- try
- {
- ToolStripButton toolStripButton = null;
- ToolStripMenuItem toolStripMenuItem = null;
- if (buttonName.Equals("Connect"))
- {
- toolStripButton = (ToolStripButton)toolStrip1.Items.Find(buttonName, true)[0];
- }
- else
- {
- toolStripMenuItem = (ToolStripMenuItem)toolStrip1.Items.Find(buttonName, true)[0];
- }
- Action act = delegate
- {
- if (toolStripButton != null)
- toolStripButton.PerformClick();
- if (toolStripMenuItem != null)
- toolStripMenuItem.PerformClick();
- };
- this.BeginInvoke(act);
- }
- catch(Exception e)
- {
- LoggerService.SYSLogger.Error(e);
- }
- }
- #endregion
-
- #region VID加载与保存
- public void VIDLoad()
- {
- foreach(SV sv in Configurations.conf.sRDConfiguration.svs)
- {
- int index = this.dgv_sv.Rows.Add();
- this.dgv_sv.Rows[index].Cells[0].Value = sv.svid;
- this.dgv_sv.Rows[index].Cells[1].Value = sv.name;
- this.dgv_sv.Rows[index].Cells[2].Value = sv.format;
- this.dgv_sv.Rows[index].Cells[3].Value = sv.min;
- this.dgv_sv.Rows[index].Cells[4].Value = sv.max;
- this.dgv_sv.Rows[index].Cells[5].Value = sv.defaultValue;
- this.dgv_sv.Rows[index].Cells[6].Value = sv.description;
- }
-
- foreach (DV dv in Configurations.conf.sRDConfiguration.dvs)
- {
- int index = this.dgv_dv.Rows.Add();
- this.dgv_dv.Rows[index].Cells[0].Value = dv.dvid;
- this.dgv_dv.Rows[index].Cells[1].Value = dv.name;
- this.dgv_dv.Rows[index].Cells[2].Value = dv.format;
- this.dgv_dv.Rows[index].Cells[3].Value = dv.min;
- this.dgv_dv.Rows[index].Cells[4].Value = dv.max;
- this.dgv_dv.Rows[index].Cells[5].Value = dv.defaultValue;
- this.dgv_dv.Rows[index].Cells[6].Value = dv.description;
- }
-
- foreach (ECV ecv in Configurations.conf.sRDConfiguration.ecvs)
- {
- int index = this.dgv_ec.Rows.Add();
- this.dgv_ec.Rows[index].Cells[0].Value = ecv.ecid;
- this.dgv_ec.Rows[index].Cells[1].Value = ecv.name;
- this.dgv_ec.Rows[index].Cells[2].Value = ecv.format;
- this.dgv_ec.Rows[index].Cells[3].Value = ecv.min;
- this.dgv_ec.Rows[index].Cells[4].Value = ecv.max;
- this.dgv_ec.Rows[index].Cells[5].Value = ecv.defaultValue;
- this.dgv_ec.Rows[index].Cells[6].Value = ecv.description;
- }
- }
-
- private void saveToolStripMenuItem_Click(object sender, EventArgs e)
- {
- var svs = new List<SV>();
- var dvs = new List<DV>();
- var ecvs = new List<ECV>();
- foreach(DataGridViewRow row in dgv_sv.Rows)
- {
- SV sv = new SV();
- if (row.Cells[0].Value != null)
- sv.svid = uint.Parse(row.Cells[0].Value.ToString());
- if (row.Cells[1].Value != null)
- sv.name = row.Cells[1].Value.ToString();
- if (row.Cells[2].Value != null)
- sv.format = row.Cells[2].Value.ToString();
- if (row.Cells[3].Value != null)
- sv.min = row.Cells[3].Value.ToString();
- if (row.Cells[4].Value != null)
- sv.max = row.Cells[4].Value.ToString();
- if (row.Cells[5].Value != null)
- sv.defaultValue = row.Cells[5].Value.ToString();
- if (row.Cells[6].Value != null)
- sv.description = row.Cells[6].Value.ToString();
- svs.Add(sv);
- }
- foreach (DataGridViewRow row in dgv_dv.Rows)
- {
- DV dv = new DV();
- if (row.Cells[0].Value != null)
- dv.dvid = uint.Parse(row.Cells[0].Value.ToString());
- if (row.Cells[1].Value != null)
- dv.name = row.Cells[1].Value.ToString();
- if (row.Cells[2].Value != null)
- dv.format = row.Cells[2].Value.ToString();
- if (row.Cells[3].Value != null)
- dv.min = row.Cells[3].Value.ToString();
- if (row.Cells[4].Value != null)
- dv.max = row.Cells[4].Value.ToString();
- if (row.Cells[5].Value != null)
- dv.defaultValue = row.Cells[5].Value.ToString();
- if (row.Cells[6].Value != null)
- dv.description = row.Cells[6].Value.ToString();
- dvs.Add(dv);
- }
- foreach (DataGridViewRow row in dgv_ec.Rows)
- {
- ECV ecv = new ECV();
- if (row.Cells[0].Value != null)
- ecv.ecid = uint.Parse(row.Cells[0].Value.ToString());
- if (row.Cells[1].Value != null)
- ecv.name = row.Cells[1].Value.ToString();
- if (row.Cells[2].Value != null)
- ecv.format = row.Cells[2].Value.ToString();
- if (row.Cells[3].Value != null)
- ecv.min = row.Cells[3].Value.ToString();
- if (row.Cells[4].Value != null)
- ecv.max = row.Cells[4].Value.ToString();
- if (row.Cells[5].Value != null)
- ecv.defaultValue = row.Cells[5].Value.ToString();
- if (row.Cells[6].Value != null)
- ecv.description = row.Cells[6].Value.ToString();
- ecvs.Add(ecv);
- }
- Configurations.conf.sRDConfiguration.svs = svs;
- Configurations.conf.sRDConfiguration.dvs = dvs;
- Configurations.conf.sRDConfiguration.ecvs = ecvs;
- XmlSerializeUtil.Serializer<Configurations>(Configurations.conf);
- MessageBox.Show("Save Successful", "NOTICE");
- }
-
- private void createSVToolStripMenuItem_Click(object sender, EventArgs e)
- {
- int index = this.dgv_sv.Rows.Add();
- dgv_sv.FirstDisplayedScrollingRowIndex = index;
- }
-
- private void createDVToolStripMenuItem_Click(object sender, EventArgs e)
- {
- int index = this.dgv_dv.Rows.Add();
- dgv_dv.FirstDisplayedScrollingRowIndex = index;
- }
-
- private void createECToolStripMenuItem_Click(object sender, EventArgs e)
- {
- int index = this.dgv_ec.Rows.Add();
- dgv_ec.FirstDisplayedScrollingRowIndex = index;
- }
-
- private void dgv_sv_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
- {
- previousEditValue = "";
- if (this.dgv_sv.CurrentCell.Value != null)
- {
- previousEditValue = this.dgv_sv.CurrentCell.Value.ToString();
- }
- }
-
- private void dgv_dv_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
- {
- previousEditValue = "";
- if (this.dgv_dv.CurrentCell.Value != null)
- {
- previousEditValue = this.dgv_dv.CurrentCell.Value.ToString();
- }
- }
-
- private void dgv_ec_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
- {
- previousEditValue = "";
- if (this.dgv_ec.CurrentCell.Value != null)
- {
- previousEditValue = this.dgv_ec.CurrentCell.Value.ToString();
- }
- }
-
- private void dgv_sv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
- {
- if (this.dgv_sv.CurrentCell.ColumnIndex == 0)
- {
- if(this.dgv_sv.CurrentCell.Value == null || dgv_sv.CurrentCell.Value.ToString() == "")
- {
- this.dgv_sv.CurrentCell.Value = previousEditValue;
- dgv_sv.CancelEdit();
- return;
- }
- foreach (DataGridViewRow row in dgv_sv.Rows)
- {
- if (row.Index == this.dgv_sv.CurrentCell.RowIndex)
- continue;
- if (row.Cells[0].Value.ToString() == this.dgv_sv.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_sv.CurrentCell.Value = previousEditValue;
- dgv_sv.CancelEdit();
- return;
- }
- }
- foreach (DataGridViewRow row in dgv_dv.Rows)
- {
- if (row.Cells[0].Value.ToString() == this.dgv_sv.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_sv.CurrentCell.Value = previousEditValue;
- dgv_sv.CancelEdit();
- return;
- }
- }
- foreach (DataGridViewRow row in dgv_ec.Rows)
- {
- if (row.Cells[0].Value.ToString() == this.dgv_sv.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_sv.CurrentCell.Value = previousEditValue;
- dgv_sv.CancelEdit();
- return;
- }
- }
- }
- }
-
- private void dgv_dv_CellEndEdit(object sender, DataGridViewCellEventArgs e)
- {
- if (this.dgv_dv.CurrentCell.ColumnIndex == 0)
- {
- if (this.dgv_dv.CurrentCell.Value == null || dgv_dv.CurrentCell.Value.ToString() == "")
- {
- this.dgv_dv.CurrentCell.Value = previousEditValue;
- dgv_dv.CancelEdit();
- return;
- }
- foreach (DataGridViewRow row in dgv_sv.Rows)
- {
- if (row.Cells[0].Value.ToString() == this.dgv_dv.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_dv.CurrentCell.Value = previousEditValue;
- dgv_dv.CancelEdit();
- return;
- }
- }
- foreach (DataGridViewRow row in dgv_dv.Rows)
- {
- if (row.Index == this.dgv_dv.CurrentCell.RowIndex)
- continue;
- if (row.Cells[0].Value.ToString() == this.dgv_dv.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_dv.CurrentCell.Value = previousEditValue;
- dgv_dv.CancelEdit();
- return;
- }
- }
- foreach (DataGridViewRow row in dgv_ec.Rows)
- {
- if (row.Cells[0].Value.ToString() == this.dgv_dv.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_dv.CurrentCell.Value = previousEditValue;
- dgv_dv.CancelEdit();
- return;
- }
- }
- }
- }
-
- private void dgv_ec_CellEndEdit(object sender, DataGridViewCellEventArgs e)
- {
- if (this.dgv_ec.CurrentCell.ColumnIndex == 0)
- {
- if (this.dgv_ec.CurrentCell.Value == null || dgv_ec.CurrentCell.Value.ToString() == "")
- {
- this.dgv_ec.CurrentCell.Value = previousEditValue;
- dgv_ec.CancelEdit();
- return;
- }
- foreach (DataGridViewRow row in dgv_sv.Rows)
- {
- if (row.Cells[0].Value.ToString() == this.dgv_ec.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_ec.CurrentCell.Value = previousEditValue;
- dgv_ec.CancelEdit();
- return;
- }
- }
- foreach (DataGridViewRow row in dgv_dv.Rows)
- {
- if (row.Cells[0].Value.ToString() == this.dgv_ec.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_ec.CurrentCell.Value = previousEditValue;
- dgv_ec.CancelEdit();
- return;
- }
- }
- foreach (DataGridViewRow row in dgv_ec.Rows)
- {
- if (row.Index == this.dgv_ec.CurrentCell.RowIndex)
- continue;
- if (row.Cells[0].Value.ToString() == this.dgv_ec.CurrentCell.Value.ToString())
- {
- MessageBox.Show("VID重复");
- this.dgv_ec.CurrentCell.Value = previousEditValue;
- dgv_ec.CancelEdit();
- return;
- }
- }
- }
- }
- #endregion
-
- private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
- {
- if(this.TabControl1.SelectedIndex == 1)
- {
- this.editIPaddress.Text = Configurations.conf.connectSetting.remoteIp;
- this.editDeviceID.Text = Configurations.conf.connectSetting.deviceId;
- this.editPort.Text = Configurations.conf.connectSetting.remotePort;
- IPError.Visible = false;
- ErrorDeviceID.Visible = false;
- ErrorPort.Visible = false;
- }
- else if(this.TabControl1.SelectedIndex == 2)
- {
- this.dgv_sv.Rows.Clear();
- this.dgv_dv.Rows.Clear();
- this.dgv_ec.Rows.Clear();
- VIDLoad();
- }
- }
- #region VID删除
- private void deleteSVToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- this.dgv_sv.Rows.Remove(this.dgv_sv.CurrentRow);
- }
-
- private void deleteDVToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.dgv_dv.Rows.Remove(this.dgv_dv.CurrentRow);
- }
-
- private void deleteECVToolStripMenuItem_Click(object sender, EventArgs e)
- {
- this.dgv_ec.Rows.Remove(this.dgv_ec.CurrentRow);
- }
- #endregion
-
- private void s1F1ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (this.s1F1ToolStripMenuItem.Checked)
- {
- EquipmentStatus.S1F1FuntionStatus = true;
- }
- else
- {
- EquipmentStatus.S1F1FuntionStatus = false;
- }
- }
-
- private void importDVListToolStripMenuItem_Click(object sender, EventArgs e)
- {
- using (var openFileDialog = new OpenFileDialog { Filter = @"Excel表格|*.xlsx|Excel|*.xls" })
- {
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
- using (var stream = File.Open(openFileDialog.FileName, FileMode.Open, FileAccess.Read))
- {
- using (var reader = ExcelReaderFactory.CreateReader(stream))
- {
- DataSet result = reader.AsDataSet();
- DataTable dt = result.Tables[0];
- foreach(DataRow row in dt.Rows)
- {
- int index = this.dgv_dv.Rows.Add();
- this.dgv_dv.Rows[index].Cells[0].Value = row[0];
- this.dgv_dv.Rows[index].Cells[1].Value = row[1];
- this.dgv_dv.Rows[index].Cells[2].Value = row[2];
- this.dgv_dv.Rows[index].Cells[3].Value = row[3];
- this.dgv_dv.Rows[index].Cells[4].Value = row[4];
- this.dgv_dv.Rows[index].Cells[5].Value = row[5];
- this.dgv_dv.Rows[index].Cells[6].Value = row[6];
- }
- }
- }
- }
- }
- }
- }
-
- public static class Global
- {
- public static MainForm MF{get;set;}
- }
- }
|