Beispiel #1
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 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;
                }
            }
        }