Exemplo n.º 1
0
        public void AddNode(RadioComponent com, string category, int key)
        {
            XDocument doc = XDocument.Load(FilePath);

            XElement xCategory =
                doc.Root.XPathSelectElement($"{DefaultCategoryName}[@{Name}='{category}']");

            if (xCategory == null)
            {
                throw new InvalidOperationException("Ошибка пути. Переподключитесь к базе.");
            }

            XElement SameKeyElem =
                xCategory.XPathSelectElement($"{DefaultElementName}[@{Key}='{key}']");

            if (SameKeyElem == null)
            {
                XElement addable = ConvertToXElement(ref com, key);
                xCategory.Add(addable);
            }
            else
            {
                throw new InvalidOperationException(
                          $"Элемент с ключем {key} уже имеется\n" +
                          "Для исправления ошибки переподключитесь к базе"
                          );
            }

            doc.Save(FilePath);
        }
Exemplo n.º 2
0
        void EditItem(object sender, EventArgs e)
        {
            RadioComponent editable = Items[_view.SelectedItemKey];

            IViewItem _viewItem = new ItemForm(editable);

            _viewItem.ItemCreated += delegate(RadioComponent rc)
            {
                int    key      = _view.SelectedItemKey;
                string category = _view.SelectedCategoryName;

                try
                {
                    _manager.EditNode(rc, category, key);
                    Items[key] = rc;
                    _view.UpdateItems(Items);
                }
                catch (Exception ex)
                {
                    _messageService.ShowError(ex.Message);
                }
            };

            _viewItem.Show();
        }
Exemplo n.º 3
0
        public void EditNode(RadioComponent com, string category, int key)
        {
            XDocument doc = XDocument.Load(FilePath);

            XElement xCategory =
                doc.Root.XPathSelectElement($"{DefaultCategoryName}[@{Name}='{category}']");

            if (xCategory == null)
            {
                throw new InvalidOperationException("Ошибка пути. Переподключитесь к базе.");
            }

            IEnumerable <XElement> elements = xCategory.Elements();

            XElement editable = SearchByKey(elements, key);

            if (editable != null)
            {
                editable.SetAttributeValue(Model, com.Model);
                editable.SetElementValue(Name, com.Name);
                editable.SetElementValue(Specs, com.Specs);
                editable.SetElementValue(MaxVal, com.MaxVal);
                editable.SetElementValue(Price, com.Price.ToString());
            }

            doc.Save(FilePath);
        }
Exemplo n.º 4
0
        private XElement ConvertToXElement(ref RadioComponent com, int key)
        {
            return(new XElement(DefaultElementName,

                                new XAttribute(Key, key.ToString()),
                                new XAttribute(Model, com.Model),
                                new XElement(Name, com.Name),
                                new XElement(Specs, com.Specs),
                                new XElement(MaxVal, com.MaxVal),
                                new XElement(Price, com.Price.ToString())
                                ));
        }
Exemplo n.º 5
0
        bool IsValidInput(RadioComponent rc)
        {
            Color standard  = Color.FromName("Black");
            Color highlight = Color.FromName("Red");

            InputModelLabel.ForeColor  = rc.Model == "" ? highlight : standard;
            InputNameLabel.ForeColor   = rc.Name == "" ? highlight : standard;
            InputSpecsLabel.ForeColor  = rc.Specs == "" ? highlight : standard;
            InputMaxValLabel.ForeColor = rc.MaxVal == "" ? highlight : standard;
            InputPriceLabel.ForeColor  = rc.Price == 0 ? highlight : standard;

            return(rc.Model != "" && rc.Name != "" &&
                   rc.Specs != "" && rc.MaxVal != "" && rc.Price != 0);
        }
Exemplo n.º 6
0
        public ItemForm(RadioComponent editable)
        {
            InitializeComponent();

            Text = "Редактирование элемента";
            CreateItemBtn.Text = "Применить";

            NameTxtBox.Text          = editable.Name;
            ModelTxtBox.Text         = editable.Model;
            SpecsTxtBox.Text         = editable.Specs;
            MaxValTxtBox.Text        = editable.MaxVal;
            PriceNumericUpDown.Value = (decimal)editable.Price;

            CreateItemBtn.Click += CreateItem;
        }
Exemplo n.º 7
0
        void CreateItem(object sender, EventArgs e)
        {
            RadioComponent rc = new RadioComponent(

                ModelTxtBox.Text,
                NameTxtBox.Text,
                SpecsTxtBox.Text,
                MaxValTxtBox.Text,
                (float)PriceNumericUpDown.Value
                );

            if (IsValidInput(rc))
            {
                ItemCreated?.Invoke(rc);
                Close();
            }
        }