private void 添加ToolStripMenuItem_Click(object sender, EventArgs e) { RelayModuleSetting relayNameSetting = new RelayModuleSetting(); if (relayNameSetting.ShowDialog() == DialogResult.OK) { if (_relayModules != null) { foreach (UserRelayArray relay in _relayModules) { if (relayNameSetting.Name == relay.Name) { Helper.ShowMessageBox("提示", "已存在相同的名称!"); return; } } UserRelayArray _userelay = new UserRelayArray(relayNameSetting.RelayName, relayNameSetting.RelayCom, relayNameSetting.RelayCount); for (int i = 1; i <= relayNameSetting.RelayCount; i++) { UserRelaySetting _userRelaySetting = new UserRelaySetting(i, relayNameSetting.RelayCount); RelayOperationDataList _relayOperation = new RelayOperationDataList(); _relayOperation.SetOperationData(RelayOperationType.吸合, ""); _relayOperation.SetOperationData(RelayOperationType.断开, ""); _userRelaySetting.AddRelayOperationData(_relayOperation); _userelay.AddRelayData(_userRelaySetting); } AddCommand(_userelay); } else { UserRelayArray _userelay = new UserRelayArray(relayNameSetting.RelayName, relayNameSetting.RelayCom, relayNameSetting.RelayCount); for (int i = 1; i <= relayNameSetting.RelayCount; i++) { UserRelaySetting _userRelaySetting = new UserRelaySetting(i, relayNameSetting.RelayCount); RelayOperationDataList _relayOperation = new RelayOperationDataList(); _relayOperation.SetOperationData(RelayOperationType.吸合, ""); _relayOperation.SetOperationData(RelayOperationType.断开, ""); _userRelaySetting.AddRelayOperationData(_relayOperation); _userelay.AddRelayData(_userRelaySetting); } _relayModules = new List <UserRelayArray>(); _relayModules.Add(_userelay); RefreshRelayList(); } } }
private void 设置ToolStripMenuItem_Click(object sender, EventArgs e) { if (_currentRelayModule != null) { RelayModuleSetting relayNameSetting = new RelayModuleSetting(); relayNameSetting.RelayName = _currentRelayModule.Name; relayNameSetting.RelayCom = _currentRelayModule.RelayCom; relayNameSetting.RelayCount = _currentRelayModule.ApproachCout; if (relayNameSetting.ShowDialog() == DialogResult.OK) { foreach (UserRelayArray relayModules in _relayModules) { if (relayModules.Name == relayNameSetting.RelayName && relayModules.Name != _currentRelayModule.Name) { Helper.ShowMessageBox("提示", "该名称已存在!"); return; } } if (_currentRelayModule.RelayOperationDatas.Count != relayNameSetting.RelayCount) { if (Helper.ShowMessageBox("操作确认", "确定更改?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == System.Windows.Forms.DialogResult.OK) { _currentRelayModule.RelayOperationDatas.Clear(); for (int i = 1; i <= relayNameSetting.RelayCount; i++) { UserRelaySetting _userRelaySetting = new UserRelaySetting(i, relayNameSetting.RelayCount); RelayOperationDataList _relayOperation = new RelayOperationDataList(); _relayOperation.SetOperationData(RelayOperationType.吸合, ""); _relayOperation.SetOperationData(RelayOperationType.断开, ""); _userRelaySetting.AddRelayOperationData(_relayOperation); _currentRelayModule.AddRelayData(_userRelaySetting); } } } _currentRelayModule.Name = relayNameSetting.RelayName; _currentRelayModule.RelayCom = relayNameSetting.RelayCom; _currentRelayModule.ApproachCout = relayNameSetting.RelayCount; RefreshRelayList(); } } }