Exemple #1
0
        // Удаление подраздела.
        private void AddProduct(Node selectedObject, SectorPanel sectorEdit)
        {
            int ammount, price;

            if (sectorEdit.productName.Length == 0 ||
                sectorEdit.productCode.Length == 0 ||
                sectorEdit.productInfo.Length == 0 ||
                !int.TryParse(sectorEdit.productAmmount, out ammount) ||
                !int.TryParse(sectorEdit.productPrice, out price) ||
                ammount < 0 || price < 0)
            {
                var mes = new Message(false, "Invalid parameters");
                mes.ShowDialog();
                return;
            }
            selectedObject.Products.Add(
                new Product(sectorEdit.productName, sectorEdit.productCode, price, ammount)
                );

            updateListView();

            var message = new Message(true, "Product was added");

            message.ShowDialog();
        }
Exemple #2
0
 // Добавление подраздела.
 private void AddSector(Node selectedObject, SectorPanel sectorEdit)
 {
     if (sectorEdit.addSectorName.Length == 0)
     {
         var message = new Message(false, "Invalid subsection name");
         message.ShowDialog();
     }
     else if (selectedObject.HasChildWithName(sectorEdit.addSectorName))
     {
         var message = new Message(false, "Subsection name is already taken");
         message.ShowDialog();
     }
     else
     {
         selectedObject.Children.Add(
             new Node(sectorEdit.addSectorName)
             );
         UpdateTreeView();
         var message = new Message(true, "New subsection was added");
         message.ShowDialog();
     }
 }
Exemple #3
0
        // Событие двойного клика по разделу.
        private void TreeViewNodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            try
            {
                var selectedObject = FindNodesObject(e.Node);

                var sectorEdit = new SectorPanel(e.Node, selectedObject);
                sectorEdit.ShowDialog();

                if (sectorEdit.command == "addSector")
                {
                    AddSector(selectedObject, sectorEdit);
                }
                else if (sectorEdit.command == "delete")
                {
                    DeleteSector(selectedObject, e);
                }
                else if (sectorEdit.command == "generate")
                {
                    GenerateRandom(selectedObject, sectorEdit.ammountOfSectionsToGenerate, sectorEdit.ammountOfProductsToGenerate);
                    UpdateTreeView();
                    var message = new Message(true, "New subsections were generated");
                    message.ShowDialog();
                }
                else if (sectorEdit.command == "renameSection")
                {
                    if (sectorEdit.renameSection.Length == 0)
                    {
                        var mes = new Message(false, "Invalid name");
                        mes.ShowDialog();
                        return;
                    }
                    selectedObject.Name = sectorEdit.renameSection;
                    UpdateTreeView();
                    var message = new Message(true, "Section was renamed");
                    message.ShowDialog();
                }
                else if (sectorEdit.command == "sortingCode")
                {
                    if (sectorEdit.sortingCode == -1)
                    {
                        var mes = new Message(false, "Invalid sorting code");
                        mes.ShowDialog();
                        return;
                    }
                    selectedObject.SortingIndex = sectorEdit.sortingCode;
                    UpdateTreeView();
                    var message = new Message(true, "Sorting code was updated");
                    message.ShowDialog();
                }
                else if (sectorEdit.command == "addProduct")
                {
                    AddProduct(selectedObject, sectorEdit);
                }
            }
            catch (Exception)
            {
                var message = new Message(false, "Something went wrong!");
                message.ShowDialog();
            }
        }