Exemple #1
0
 private void right_fun_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 DeviceButtonAsFunction).Code.Content.ToString());
         DD.ShowDialog();
         Console.WriteLine("{0},{1}", DD.pos, DD.c**t);
         if (DD.pos != 0 && DD.c**t != 0)
         {
             for (int i = 0; i < DD.c**t; i++)
             {
                 DeviceButtonAsFunction fun = (sender as DeviceButtonAsFunction).Clone();
                 fun.MouseRightButtonUp += new MouseButtonEventHandler(remove_single_Click);
                 devicesPanel.Children.Insert(DD.pos + i, fun);
                 SurplusPower += Convert.ToInt32(fun.Power.Content);
                 PowerCheck();
             }
         }
         return;
     }
     MessageBox.Show("请先装配适配器");
 }
 public DeviceButtonAsFunction Clone()
 {
     DeviceButtonAsFunction fun = new DeviceButtonAsFunction();
     fun.Code.Content = this.Code.Content;
     fun.Tag1.Content = this.Tag1.Content;
     fun.Tag2.Content = this.Tag2.Content;
     fun.Tag3.Content = this.Tag3.Content;
     fun.Tag4.Content = this.Tag4.Content;
     fun.Tag5.Content = this.Tag5.Content;
     fun.DevicePower = this.DevicePower;
     fun.Power.Content = this.Power.Content;
     return fun;
 }
 public DeviceButtonAsFunction AsFun()
 {
     DeviceButtonAsFunction dev = new DeviceButtonAsFunction();
     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;
 }
        public DeviceButtonAsFunction Clone()
        {
            DeviceButtonAsFunction fun = new DeviceButtonAsFunction();

            fun.Code.Content  = this.Code.Content;
            fun.Tag1.Content  = this.Tag1.Content;
            fun.Tag2.Content  = this.Tag2.Content;
            fun.Tag3.Content  = this.Tag3.Content;
            fun.Tag4.Content  = this.Tag4.Content;
            fun.Tag5.Content  = this.Tag5.Content;
            fun.DevicePower   = this.DevicePower;
            fun.Power.Content = this.Power.Content;
            return(fun);
        }
        public DeviceButtonAsFunction AsFun()
        {
            DeviceButtonAsFunction dev = new DeviceButtonAsFunction();

            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);
        }
Exemple #6
0
 private void add_fun_Click(object sender, RoutedEventArgs e)
 {
     if (IsAdapterOnFirst())
     {
         if (devicesPanel.Children.Count > 32)
         {
             MessageBox.Show("模块不能超过32个");
             return;
         }
         DeviceButtonAsFunction fun = (sender as DeviceButtonAsFunction).Clone();
         fun.MouseRightButtonUp += new MouseButtonEventHandler(remove_single_Click);
         devicesPanel.Children.Add(fun);
         SurplusPower += Convert.ToInt32(fun.Power.Content);
         PowerCheck();
         return;
     }
     MessageBox.Show("请先装配适配器");
 }
Exemple #7
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;
                }
            }
        }