Esempio n. 1
0
 private void right_IO_Click(object sender, MouseButtonEventArgs e)
 {
     if (IsAdapterOnFirst())
     {
         if (devicesPanel.Children.Count > 32)
         {
             MessageBox.Show("模块不能超过32个");
             return;
         }
         DeviceDialog DD = new DeviceDialog(devicesPanel.Children.Count);
         DD.Title = string.Format("自定义添加 {0}", (sender as DeviceButtonAsIO).Code.Content.ToString());
         DD.ShowDialog();
         if (DD.pos != 0 && DD.c**t != 0)
         {
             for (int i = 0; i < DD.c**t; i++)
             {
                 DeviceButtonAsIO IO = (sender as DeviceButtonAsIO).Clone();
                 IO.MouseRightButtonUp += new MouseButtonEventHandler(remove_single_Click);
                 devicesPanel.Children.Insert(DD.pos + i, IO);
                 SurplusPower += Convert.ToInt32(IO.Power.Content);
                 PowerCheck();
             }
         }
         return;
     }
     MessageBox.Show("请先装配适配器");
 }
 public DeviceButtonAsIO Clone()
 {
     DeviceButtonAsIO IO = new DeviceButtonAsIO();
     IO.Code.Content = this.Code.Content;
     IO.Tag1.Content = this.Tag1.Content;
     IO.Tag2.Content = this.Tag2.Content;
     IO.Tag3.Content = this.Tag3.Content;
     IO.Tag4.Content = this.Tag4.Content;
     IO.Tag5.Content = this.Tag5.Content;
     IO.DevicePower = this.DevicePower;
     IO.Power.Content = this.Power.Content;
     return IO;
 }
        public DeviceButtonAsIO Clone()
        {
            DeviceButtonAsIO IO = new DeviceButtonAsIO();

            IO.Code.Content  = this.Code.Content;
            IO.Tag1.Content  = this.Tag1.Content;
            IO.Tag2.Content  = this.Tag2.Content;
            IO.Tag3.Content  = this.Tag3.Content;
            IO.Tag4.Content  = this.Tag4.Content;
            IO.Tag5.Content  = this.Tag5.Content;
            IO.DevicePower   = this.DevicePower;
            IO.Power.Content = this.Power.Content;
            return(IO);
        }
        public DeviceButtonAsIO AsIO()
        {
            DeviceButtonAsIO dev = new DeviceButtonAsIO();

            dev.Code.Content  = this.Code;
            dev.Tag1.Content  = this.Tag1;
            dev.Tag2.Content  = this.Tag2;
            dev.Tag3.Content  = this.Tag3;
            dev.Tag4.Content  = this.Tag4;
            dev.Tag5.Content  = this.Tag5;
            dev.DevicePower   = this.Power;
            dev.Power.Content = this.Power.ToString();
            return(dev);
        }
Esempio n. 5
0
 private void add_IO_Click(object sender, RoutedEventArgs e)
 {
     if (IsAdapterOnFirst())
     {
         if (devicesPanel.Children.Count > 32)
         {
             MessageBox.Show("模块不能超过32个");
             return;
         }
         DeviceButtonAsIO IO = (sender as DeviceButtonAsIO).Clone();
         IO.MouseRightButtonUp += new MouseButtonEventHandler(remove_single_Click);
         devicesPanel.Children.Add(IO);
         SurplusPower += Convert.ToInt32(IO.Power.Content);
         PowerCheck();
         return;
     }
     MessageBox.Show("请先装配适配器");
 }
Esempio n. 6
0
        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;
                }
            }
        }
 public DeviceButtonAsIO AsIO()
 {
     DeviceButtonAsIO dev = new DeviceButtonAsIO();
     dev.Code.Content = this.Code;
     dev.Tag1.Content = this.Tag1;
     dev.Tag2.Content = this.Tag2;
     dev.Tag3.Content = this.Tag3;
     dev.Tag4.Content = this.Tag4;
     dev.Tag5.Content = this.Tag5;
     dev.DevicePower = this.Power;
     dev.Power.Content = this.Power.ToString();
     return dev;
 }