/* * private void add_Click(object sender, RoutedEventArgs e) * { * MessageBox.Show(e.Source.ToString()); * } */ private void add_adp_Click(object sender, RoutedEventArgs e) { if (IsAdapterOnFirst()) { MessageBox.Show("只能有一个适配器"); return; } DeviceButtonAsAdapter adp = (sender as DeviceButtonAsAdapter).Clone(); devicesPanel.Children.Add(adp); SurplusPower += Convert.ToInt32(adp.Power.Content); PowerCheck(); }
public DeviceButtonAsAdapter AsAdapter() { DeviceButtonAsAdapter adp = new DeviceButtonAsAdapter(); adp.Code.Content = this.Code; adp.Tag1.Content = this.Tag1; adp.Tag2.Content = this.Tag2; adp.Tag3.Content = this.Tag3; adp.Tag4.Content = this.Tag4; adp.Tag5.Content = this.Tag5; adp.DevicePower = this.Power; adp.Power.Content = this.Power.ToString(); return adp; }
public DeviceButtonAsAdapter Clone() { DeviceButtonAsAdapter adp = new DeviceButtonAsAdapter(); adp.Code.Content = this.Code.Content; adp.Tag1.Content = this.Tag1.Content; adp.Tag2.Content = this.Tag2.Content; adp.Tag3.Content = this.Tag3.Content; adp.Tag4.Content = this.Tag4.Content; adp.Tag5.Content = this.Tag5.Content; adp.DevicePower = this.DevicePower; adp.Power.Content = this.Power.Content; return adp; }
public DeviceButtonAsAdapter Clone() { DeviceButtonAsAdapter adp = new DeviceButtonAsAdapter(); adp.Code.Content = this.Code.Content; adp.Tag1.Content = this.Tag1.Content; adp.Tag2.Content = this.Tag2.Content; adp.Tag3.Content = this.Tag3.Content; adp.Tag4.Content = this.Tag4.Content; adp.Tag5.Content = this.Tag5.Content; adp.DevicePower = this.DevicePower; adp.Power.Content = this.Power.Content; return(adp); }
public DeviceButtonAsAdapter AsAdapter() { DeviceButtonAsAdapter adp = new DeviceButtonAsAdapter(); adp.Code.Content = this.Code; adp.Tag1.Content = this.Tag1; adp.Tag2.Content = this.Tag2; adp.Tag3.Content = this.Tag3; adp.Tag4.Content = this.Tag4; adp.Tag5.Content = this.Tag5; adp.DevicePower = this.Power; adp.Power.Content = this.Power.ToString(); return(adp); }
public MainWindow() { InitializeComponent(); DeviceNumberBoxOfAdapter adpNum = new DeviceNumberBoxOfAdapter(); numPanel.Children.Add(adpNum); for (int i = 0; i < 32; i++) { DeviceNumberBoxOfModule modNum = new DeviceNumberBoxOfModule(); modNum.Content = string.Format("[ {0} ]", i + 1); numPanel.Children.Add(modNum); } this.label.SetBinding(Label.ContentProperty, new Binding("SurplusPower") { Source = this, Path = new PropertyPath("SurplusPower") }); XElement root = XElement.Load(fileName); var devicesQuery = from device in root.Elements("Device") select device; foreach (var dev in devicesQuery) { DeviceButtonFactory btn = new DeviceButtonFactory(); btn.Code = dev.Element("Code").Value.ToString(); btn.Tag1 = dev.Element("Tags").Attribute("tag1").Value; btn.Tag2 = dev.Element("Tags").Attribute("tag2").Value; btn.Tag3 = dev.Element("Tags").Attribute("tag3").Value; btn.Tag4 = dev.Element("Tags").Attribute("tag4").Value; btn.Tag5 = dev.Element("Tags").Attribute("tag5").Value; btn.Power = Convert.ToInt32(dev.Element("OutCurrent").Value) - Convert.ToInt32(dev.Element("InCurrent").Value); switch (dev.Element("Type").Value) { case "adapter": DeviceButtonAsAdapter adp = btn.AsAdapter(); adp.Margin = new Thickness(5, 0, 0, 0); adp.Click += new RoutedEventHandler(add_adp_Click); this.adapterPanel.Children.Add(adp); break; case "IO": DeviceButtonAsIO IO = btn.AsIO(); IO.Margin = new Thickness(5, 0, 0, 0); IO.Click += new RoutedEventHandler(add_IO_Click); IO.MouseRightButtonUp += new MouseButtonEventHandler(right_IO_Click); this.IOPanel.Children.Add(IO); break; case "function": DeviceButtonAsFunction fun = btn.AsFun(); fun.Margin = new Thickness(5, 0, 0, 0); fun.Click += new RoutedEventHandler(add_fun_Click); fun.MouseRightButtonUp += new MouseButtonEventHandler(right_fun_Click); this.functionPanel.Children.Add(fun); break; case "auxiliary": DeviceButtonAsAuxiliary aux = btn.AsAux(); aux.Margin = new Thickness(5, 0, 0, 0); aux.Click += new RoutedEventHandler(add_aux_Click); aux.MouseRightButtonUp += new MouseButtonEventHandler(right_aux_Click); this.auxiliaryPanel.Children.Add(aux); break; default: break; } } }