Example #1
0
        public WDashbordCreate(Object obj)
        {
            InitializeComponent();
            this.obj      = obj;
            label.Content = obj.Name;

            foreach (var p in obj.Properties)
            {
                var list  = new List <UIElement>();
                var child = new StackPanel()
                {
                    Orientation = Orientation.Horizontal
                };
                var l = new Label()
                {
                    Content = p.Name, HorizontalContentAlignment = HorizontalAlignment.Left, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 14, Width = 150
                };
                l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                child.Children.Add(l);
                //l = new Label() { Content = (string)Application.Current.Resources["Editid1"]+"?", HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 12 };
                //l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                //child1.Children.Add(l);
                var tmp = new CheckBox()
                {
                    IsChecked = true
                };
                list.Add(tmp);
                child.Children.Add(tmp);
                //l = new Label() { Content = (string)Application.Current.Resources["WDCid1"], HorizontalContentAlignment = HorizontalAlignment.Center, VerticalContentAlignment = VerticalAlignment.Center, FontSize = 12 };
                //l.SetResourceReference(Control.ForegroundProperty, "OnLightFontColor");
                //child1.Children.Add(l);
                tmp = new CheckBox()
                {
                    Margin = new Thickness(55, 0, 0, 0)
                };
                tmp.SetBinding(Control.IsEnabledProperty, new Binding("IsChecked")
                {
                    Source = (list[0] as CheckBox), Mode = BindingMode.OneWay
                });
                list.Add(tmp);
                child.Children.Add(tmp);
                switch ((TypeCode)p.Type)
                {
                case TypeCode.Boolean:
                case TypeCode.String:
                    break;

                case TypeCode.Int32:
                case TypeCode.Int16:
                case TypeCode.Int64:
                case TypeCode.UInt32:
                case TypeCode.UInt16:
                case TypeCode.UInt64:
                case TypeCode.Double:
                case TypeCode.Decimal:
                case TypeCode.Single:
                    var textbox = new TextBox()
                    {
                        Text = "0", Width = 50, Margin = new Thickness(80, 0, 0, 0)
                    };
                    textbox.SetBinding(Control.IsEnabledProperty, new Binding("IsChecked")
                    {
                        Source = (list[0] as CheckBox), Mode = BindingMode.OneWay
                    });
                    list.Add(textbox);
                    child.Children.Add(textbox);
                    textbox = new TextBox()
                    {
                        Text = "100", Width = 50, Margin = new Thickness(30, 0, 0, 0)
                    };
                    textbox.SetBinding(Control.IsEnabledProperty, new Binding("IsChecked")
                    {
                        Source = (list[0] as CheckBox), Mode = BindingMode.OneWay
                    });
                    list.Add(textbox);
                    child.Children.Add(textbox);
                    break;
                }
                results.Add(p, list);
                sw.Children.Add(child);
            }
        }
Example #2
0
        public void ObjectId()
        {
            var Object = new Object(-1, "Pirozhok", "Пирожок", -1, null);

            Assert.AreEqual <string>(Object.PathUnit, "Pirozhok");
        }
Example #3
0
 private void EditEvent(object sender, RoutedEventArgs e)
 {
     if (EIsOpen)
     {
         return;
     }
     if ((sender as Button).Tag is Property)
     {
         labelName.Visibility      = Visibility.Visible;
         labelType.Visibility      = Visibility.Hidden;
         labelValue.Visibility     = Visibility.Visible;
         labelScript.Visibility    = Visibility.Hidden;
         TBName.Visibility         = Visibility.Visible;
         TBName.Text               = ((sender as Button).Tag as Property).Name;
         TBValue.Visibility        = Visibility.Visible;
         TBValue.Text              = ((sender as Button).Tag as Property).Value;
         TBScript.Visibility       = Visibility.Hidden;
         CBType.Visibility         = Visibility.Hidden;
         CBType.SelectedItem       = ((sender as Button).Tag as Property).Type;
         CBType.IsEnabled          = false;
         ELproperties.SelectedItem = (sender as Button).Tag;
         editmode = 10;
         iop      = ((sender as Button).Tag as Property);
         OPShowHide();
     }
     if ((sender as Button).Tag is Script)
     {
         labelName.Visibility   = Visibility.Visible;
         labelType.Visibility   = Visibility.Hidden;
         labelValue.Visibility  = Visibility.Hidden;
         labelScript.Visibility = Visibility.Visible;
         TBName.Visibility      = Visibility.Visible;
         TBName.Text            = ((sender as Button).Tag as Script).Name;
         TBValue.Visibility     = Visibility.Hidden;
         TBScript.Visibility    = Visibility.Visible;
         TBScript.Text          = ((sender as Button).Tag as Script).Value;
         CBType.Visibility      = Visibility.Hidden;
         CBType.IsEnabled       = false;
         ELscripts.SelectedItem = (sender as Button).Tag;
         editmode = 11;
         ios      = ((sender as Button).Tag as Script);
         OPShowHide();
     }
     if ((sender as Button).Tag is Object)
     {
         labelName.Visibility   = Visibility.Visible;
         labelType.Visibility   = Visibility.Hidden;
         labelValue.Visibility  = Visibility.Hidden;
         labelScript.Visibility = Visibility.Hidden;
         TBName.Visibility      = Visibility.Visible;
         TBName.Text            = ((sender as Button).Tag as Object).Name;
         TBValue.Visibility     = Visibility.Hidden;
         TBScript.Visibility    = Visibility.Hidden;
         CBType.Visibility      = Visibility.Hidden;
         CBType.IsEnabled       = false;
         ELobjects.SelectedItem = (sender as Button).Tag;
         editmode = 12;
         ioo      = ((sender as Button).Tag as Object);
         OPShowHide();
     }
     if ((sender as Button).Tag is Model)
     {
         labelName.Visibility   = Visibility.Visible;
         labelType.Visibility   = Visibility.Hidden;
         labelValue.Visibility  = Visibility.Hidden;
         labelScript.Visibility = Visibility.Hidden;
         TBName.Visibility      = Visibility.Visible;
         TBName.Text            = ((sender as Button).Tag as Model).Name;
         TBValue.Visibility     = Visibility.Hidden;
         TBScript.Visibility    = Visibility.Hidden;
         CBType.Visibility      = Visibility.Hidden;
         CBType.IsEnabled       = false;
         ELobjects.SelectedItem = (sender as Button).Tag;
         editmode = 12;
         iom      = ((sender as Button).Tag as Model);
         OPShowHide();
     }
 }
Example #4
0
 private void CopyEvent(object sender, RoutedEventArgs e)
 {
     if ((sender as Button) == null)
     {
         return;
     }
     if (((Button)sender).Tag is Model)
     {
         Model model;
         try
         {
             model = new Model((sender as Button).Tag as Model)
             {
                 Id = !Platform.Current.Models.Any() ? -1 : Platform.Current.Models.Min(i => i.Id) - 1
             };
             //model = Network.IoTFactory.CreateModel(new Model((sender as Button).Tag as Model));
         }
         catch
         {
             Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid1"], (string)Application.Current.Resources["Dialogid5"]); return;
         }
         if (model == null)
         {
             Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid1"], (string)Application.Current.Resources["Dialogid5"]); return;
         }
         Platform.Current.Models.Add(model);
     }
     if (((Button)sender).Tag is Object)
     {
         if (ELmodels.SelectedItem != null)
         {
             Object obj;
             try
             {
                 obj = new Object(((Button)sender).Tag as Object)
                 {
                     Id =
                         !Platform.Current.Models.SelectMany(x => x.Objects).Any()
                             ? -1
                             : Platform.Current.Models.SelectMany(x => x.Objects).Min(i => i.Id) - 1
                 };
                 //obj = Network.IoTFactory.CreateObject(new Object((sender as Button).Tag as Object));
             }
             catch
             {
                 Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid2"], (string)Application.Current.Resources["Dialogid5"]); return;
             }
             if (obj == null)
             {
                 Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid2"], (string)Application.Current.Resources["Dialogid5"]); return;
             }
             (ELmodels.SelectedItem as Model)?.Objects.Add(obj);
         }
     }
     if (((Button)sender).Tag is Property)
     {
         if (ELobjects.SelectedItem != null)
         {
             Property prop;
             try
             {
                 prop = new Property(((Button)sender).Tag as Property)
                 {
                     Id =
                         !Platform.Current.Models.SelectMany(x => x.Objects).SelectMany(y => y.Properties).Any()
                             ? -1
                             : Platform.Current.Models.SelectMany(x => x.Objects)
                         .SelectMany(y => y.Properties)
                         .Min(i => i.Id) - 1
                 };
                 //prop = Network.IoTFactory.CreateProperty(new Property((sender as Button).Tag as Property));
             }
             catch
             {
                 Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid2"], (string)Application.Current.Resources["Dialogid5"]); return;
             }
             if (prop == null)
             {
                 Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid2"], (string)Application.Current.Resources["Dialogid5"]); return;
             }
             (ELobjects.SelectedItem as Object)?.Properties.Add(prop);
         }
     }
     if (((Button)sender).Tag is Script)
     {
         if (ELproperties.SelectedItem != null)
         {
             Script script;
             try
             {
                 script = new Script((sender as Button).Tag as Script)
                 {
                     Id =
                         !Platform.Current.Models.SelectMany(x => x.Objects)
                         .SelectMany(y => y.Properties)
                         .SelectMany(z => z.Scripts)
                         .Any()
                             ? -1
                             : Platform.Current.Models.SelectMany(x => x.Objects)
                         .SelectMany(y => y.Properties)
                         .SelectMany(z => z.Scripts)
                         .Min(i => i.Id) - 1
                 };
                 //script = Network.IoTFactory.CreateScript(new Script((sender as Button).Tag as Script));
             }
             catch
             {
                 Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid5"], (string)Application.Current.Resources["Dialogid5"]);
                 return;
             }
             if (script == null)
             {
                 Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid5"], (string)Application.Current.Resources["Dialogid5"]);
                 return;
             }
             (ELproperties.SelectedItem as Property)?.Scripts.Add(script);
         }
     }
 }
Example #5
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var name = TBName.Text.Trim(' ');

            if (!string.IsNullOrEmpty(name))
            {
                switch (editmode)
                {
                case 1:
                    Model model;
                    try
                    {
                        model    = new Model(name);
                        model.Id = Platform.Current.Models.Count == 0 ? -1 : Platform.Current.Models.Min(i => i.Id) - 1;
                        //model = Network.IoTFactory.CreateModel(new Model(name));
                    }
                    catch
                    {
                        Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid1"], (string)Application.Current.Resources["Dialogid5"]); return;
                    }
                    if (model == null)
                    {
                        Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid1"], (string)Application.Current.Resources["Dialogid5"]); return;
                    }
                    Platform.Current.Models.Add(model);
                    break;

                case 2:
                    Object obj;
                    try
                    {
                        obj    = new Object(name, (long)(ELmodels.SelectedItem as Model).Id);
                        obj.Id = Platform.Current.Models.Count == 0 || Platform.Current.Models.SelectMany(x => x.Objects).Count() == 0 ? -1 : Platform.Current.Models.SelectMany(x => x.Objects).Min(i => i.Id) - 1;
                        //obj = Network.IoTFactory.CreateObject(new Object(name, (long)(Lmodels.SelectedItem as Model).id));
                    }
                    catch
                    {
                        Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid2"], (string)Application.Current.Resources["Dialogid5"]); return;
                    }
                    if (obj == null)
                    {
                        Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid2"], (string)Application.Current.Resources["Dialogid5"]); return;
                    }
                    (ELmodels.SelectedItem as Model)?.Objects.Add(obj);
                    break;

                case 3:
                    if (CBType.SelectedItem != null)
                    {
                        TypeCode type = TypeCode.Object;
                        types.TryGetValue((CBType.SelectedItem as string), out type);
                        if (type != TypeCode.Object)
                        {
                            Property prop;
                            try
                            {
                                prop    = new Property(name, (long)(ELobjects.SelectedItem as Object).Id, (int)type, TBValue.Text);
                                prop.Id = Platform.Current.Models.Count == 0 || Platform.Current.Models.SelectMany(x => x.Objects).Count() == 0 || Platform.Current.Models.SelectMany(x => x.Objects).SelectMany(y => y.Properties).Count() == 0 ? -1 : Platform.Current.Models.SelectMany(x => x.Objects).SelectMany(y => y.Properties).Min(i => i.Id) - 1;
                                //prop = Network.IoTFactory.CreateProperty(new Property(name, (long)(Lobjects.SelectedItem as Object).id, (int)type, TBValue.Text));
                            }
                            catch
                            {
                                Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid2"], (string)Application.Current.Resources["Dialogid5"]); return;
                            }
                            if (prop == null)
                            {
                                Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid2"], (string)Application.Current.Resources["Dialogid5"]); return;
                            }
                            (ELobjects.SelectedItem as Object)?.Properties.Add(prop);
                        }
                    }
                    // MessageBox.Show((string)Application.Current.Resources["Errid2"]);
                    break;

                case 4:
                    Script script;
                    try
                    {
                        script    = new Script(name, (long)(ELproperties.SelectedItem as Property).Id, TBScript.Text);
                        script.Id = Platform.Current.Models.Count == 0 || Platform.Current.Models.SelectMany(x => x.Objects).Count() == 0 || Platform.Current.Models.SelectMany(x => x.Objects).SelectMany(y => y.Properties).Count() == 0 || Platform.Current.Models.SelectMany(x => x.Objects).SelectMany(y => y.Properties).SelectMany(z => z.Scripts).Count() == 0 ? -1 : Platform.Current.Models.SelectMany(x => x.Objects).SelectMany(y => y.Properties).SelectMany(z => z.Scripts).Min(i => i.Id) - 1;
                        //script = Network.IoTFactory.CreateScript(new Script(name, (long)(Lproperties.SelectedItem as Property).id, TBScript.Text));
                    }
                    catch
                    {
                        Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid5"], (string)Application.Current.Resources["Dialogid5"]); return;
                    }
                    if (script == null)
                    {
                        Message.Show((string)Application.Current.Resources["Dialogid9"] + (string)Application.Current.Resources["Viewid5"], (string)Application.Current.Resources["Dialogid5"]); return;
                    }
                    (ELproperties.SelectedItem as Property)?.Scripts.Add(script);
                    break;

                case 10:
                    if (iop != null)
                    {
                        iop.Name  = name;
                        iop.Value = TBValue.Text;
                        //Network.IoTFactory.UpdateProperty(iop);//добавить проверку на 1/0, а лучше сделать другую модель одновления
                        int t = ELobjects.SelectedIndex;
                        ELobjects.SelectedIndex = -1;
                        ELobjects.SelectedItem  = ELobjects.Items[t];
                    }
                    break;

                case 11:
                    if (ios != null)
                    {
                        ios.Name  = name;
                        ios.Value = TBScript.Text;
                        //Network.IoTFactory.UpdateScript(ios);
                        int t = ELproperties.SelectedIndex;
                        ELproperties.SelectedIndex = -1;
                        ELproperties.SelectedItem  = ELproperties.Items[t];
                    }
                    break;

                case 12:
                    if (ioo != null)
                    {
                        ioo.Name = name;
                        //Network.IoTFactory.UpdateObject(ioo);
                        int t = ELmodels.SelectedIndex;
                        ELmodels.SelectedIndex = -1;
                        ELmodels.SelectedItem  = ELmodels.Items[t];
                    }
                    break;

                case 13:
                    if (iom != null)
                    {
                        iom.Name = name;
                        try
                        {
                            int t = ELmodels.SelectedIndex == -1 ? 0 : ELmodels.SelectedIndex;
                            ELmodels.SelectedIndex = -1;
                            ELmodels.SelectedItem  = ELmodels.Items[t];
                        }
                        catch { }
                        //Network.IoTFactory.UpdateModel(iom);
                    }
                    break;
                }
            }
            TBName.Text = TBScript.Text = TBValue.Text = "";
            Tag         = null;
            editmode    = -1;
            Notified(null, null);
            OPShowHide();
        }