void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e) { NewPhysicsCode = (comboBox.SelectedValue ?? string.Empty).ToString(); PortPairInfo portPairInfo; if (!NewPhysicsCode.Equals("-----")) { portPairInfo = AppConfigInfos.PortPairInfos.Find(p => p.PortCode.Equals(NewPhysicsCode) && !p.Index.Equals(InventedIndex.ToString())); if (portPairInfo != null) { int countPort = AppConfigInfos.AppStateInfos.FaceplateColumn * AppConfigInfos.AppStateInfos.FaceplateRow; // 只提示在面板中有显示的端口占用情况 if (Convert.ToInt32(portPairInfo.Index) <= countPort) { comboBox.SelectionChanged -= comboBox_SelectionChanged; comboBox.SelectedValue = lastOldValue; comboBox.SelectionChanged += comboBox_SelectionChanged; NewMessageBox.Show(string.Format(TryFindResource("GatherPortRePair").ToString(), portPairInfo.Index)); return; } else { portPairInfo.PortCode = lastOldValue; } } } portPairInfo = AppConfigInfos.PortPairInfos.Find(p => p.Index.Equals(InventedIndex.ToString())); if (portPairInfo == null) { AppConfigInfos.PortPairInfos.Add(new PortPairInfo() { Index = InventedIndex.ToString(), PortCode = NewPhysicsCode }); } else { portPairInfo.PortCode = NewPhysicsCode; } if (ChangeValueHandler != null) { ChangeValueHandler(this, NewPhysicsCode); } }
/// <summary> /// 重置 /// </summary> public void ResetValue() { comboBox.SelectionChanged -= comboBox_SelectionChanged; comboBox.SelectedValue = OldPhysicsCode; lastOldValue = OldPhysicsCode; PortPairInfo portPairInfo = AppConfigInfos.PortPairInfos.Find(p => p.PortCode.Equals(OldPhysicsCode) && p.Index.Equals(InventedIndex.ToString())); if (portPairInfo != null) { if (string.IsNullOrEmpty(OldPhysicsCode)) { AppConfigInfos.PortPairInfos.Remove(portPairInfo); } else { portPairInfo.PortCode = OldPhysicsCode; } } comboBox.SelectionChanged += comboBox_SelectionChanged; }