//添加模块 private void add_dev_Click(object sender, RoutedEventArgs e) { ButtonOfDevice devb = (sender as ButtonOfDevice).Clone(); switch (devb.Tag1.Content.ToString()) { case "适配器": { if (IsAdapterOnFirst()) { MessageBox.Show("只能有一个适配器"); return; } devicesPanel.Children.Add(devb); NumberBoxOfAdapter adpNum = new NumberBoxOfAdapter(); numPanel.Children.Add(adpNum); SurplusPower += Convert.ToInt32(devb.Power.Content); PowerCheck(); SLCheck(); } break; case "终端模块": { if (IsAdapterOnFirst()) { if (IsEndOnLast()) { MessageBox.Show("只能有一个终端模块"); return; } devb.MouseRightButtonUp += new MouseButtonEventHandler(remove_single_Click); devicesPanel.Children.Add(devb); NumberBoxOfModule modNum = new NumberBoxOfModule(); modNum.Content = string.Format("[ {0} ]", devicesPanel.Children.Count - 1); numPanel.Children.Add(modNum); SLCheck(); return; } MessageBox.Show("请先装配适配器"); } break; default: { if (IsAdapterOnFirst()) { if (!IsModuleOver32() && devb.Tag2.Content.ToString() != "电源模块") { MessageBox.Show("模块不能超过32个"); return; } if (IsEndOnLast()) { MessageBox.Show("不能在终端模块后添加模块"); return; } devb.MouseRightButtonUp += new MouseButtonEventHandler(remove_single_Click); devicesPanel.Children.Add(devb); NumberBoxOfModule modNum = new NumberBoxOfModule(); modNum.Content = string.Format("[ {0} ]", devicesPanel.Children.Count - 1); numPanel.Children.Add(modNum); if (devb.IsFunctionalModule()) { ModuleCount++; } SurplusPower += Convert.ToInt32(devb.Power.Content); PowerCheck(); SLCheck(); return; } MessageBox.Show("请先装配适配器"); } break; } }
//装配区设备编号刷新 public void NumRefresh(int count) { numPanel.Children.Clear(); NumberBoxOfAdapter adpNum = new NumberBoxOfAdapter(); numPanel.Children.Add(adpNum); for (int i = 1; i < count ; i++) { NumberBoxOfModule num = new NumberBoxOfModule(); num.Content = string.Format("[ {0} ]", i); numPanel.Children.Add(num); } }