Example #1
0
        public FormEditSubnet(TreeNode treeNode, ModeForm modeForm)
        {
            InitializeComponent();
            this.modeForm = modeForm;
            switch (this.modeForm)
            {
            case ModeForm.Edit:
            {
                this.lcTreeNodeSubnet        = (LCTreeNodeSubnet)treeNode;
                this.Text                    = "Сеть : " + this.lcTreeNodeSubnet.Text;
                this.textBoxNameSubnet.Text  = this.lcTreeNodeSubnet.Text;
                this.textBoxIPSubnet.Text    = this.lcTreeNodeSubnet.IPSubnet;
                this.textBoxMaskSubnet.Text  = this.lcTreeNodeSubnet.MaskSubnet;
                this.textBoxDescription.Text = this.lcTreeNodeSubnet.Description;
                this.buttonAddSubnet.Text    = "Сохранить";
                break;
            }

            case ModeForm.New:
            {
                this.lcTreeNodeGroup        = (LCTreeNodeGroup)treeNode;
                this.textBoxNameSubnet.Text = "Новая сеть";
                break;
            }
            }
        }
Example #2
0
        /// <summary>
        /// Метод экспортирует все сети в JSON файл JS
        /// </summary>
        /// <param name="fileExport">Имя файла в которы осуществляется экспорт</param>
        public void ExportNetsToJSON(string fileExport)
        {
            StreamWriter sw = new StreamWriter(fileExport, false, System.Text.Encoding.UTF8);

            sw.WriteLine("var nets = [");
            bool firstNet = false;

            foreach (LCTreeNode node in AllLCTreeNode(treeView.Nodes))
            {
                if (node.LCObjectType == LCObjectType.SubNet)
                {
                    LCTreeNodeSubnet lcSubnet = (LCTreeNodeSubnet)node;
                    if (firstNet)
                    {
                        sw.WriteLine(",");
                    }
                    else
                    {
                        firstNet = true;
                    }
                    string str = "\t{name:'" + lcSubnet.Text + "', gateway:'" + lcSubnet.IPSubnet + "',mask:'" + lcSubnet.MaskSubnet + "'}";
                    sw.Write(str);
                }
            }
            sw.WriteLine();
            sw.Write("];");
            sw.Close();
        }
Example #3
0
        private void ButtonAddSubnet_Click(object sender, EventArgs e)
        {
            if (this.textBoxNameSubnet.Text != "")
            {
                string pattern = @"([01]?\d\d?|2[0-4]\d|25[0-5])\." +
                                 @"([01]?\d\d?|2[0-4]\d|25[0-5])\." +
                                 @"([01]?\d\d?|2[0-4]\d|25[0-5])\." +
                                 @"(25[0-5]|2[0-4]\d|[01]?\d\d?)";
                Regex regex = new Regex(pattern);
                Match match = regex.Match(this.textBoxIPSubnet.Text);
                // Проверяем корректно ли введен IP-адрес сети
                if (match.Success)
                {
                    this.textBoxIPSubnet.Text = match.Value;
                    match = regex.Match(this.textBoxMaskSubnet.Text);
                    if (match.Success)
                    {
                        this.textBoxMaskSubnet.Text = match.Value;
                        switch (this.modeForm)
                        {
                        case ModeForm.New:
                        {
                            this.lcTreeNodeSubnet = this.lcTreeNodeGroup.AddSubnet(this.textBoxNameSubnet.Text,
                                                                                   this.textBoxIPSubnet.Text, this.textBoxMaskSubnet.Text, this.textBoxDescription.Text);
                            break;
                        }

                        case ModeForm.Edit:
                        {
                            this.lcTreeNodeSubnet.Text        = this.textBoxNameSubnet.Text;
                            this.lcTreeNodeSubnet.IPSubnet    = this.textBoxIPSubnet.Text;
                            this.lcTreeNodeSubnet.MaskSubnet  = this.textBoxMaskSubnet.Text;
                            this.lcTreeNodeSubnet.Description = this.textBoxDescription.Text;
                            this.lcTreeNodeSubnet.UpdateLC();
                            break;
                        }
                        }
                        this.Close();
                    }
                    else
                    {
                        this.labelError.Text = "Введенное в поле маска значение не корректно";
                    }
                }
                else
                {
                    this.labelError.Text = "Введенное в поле адрес сети значение не корректно";
                }
            }
            else
            {
                this.labelError.Text = "Не задано имя сети";
            }
        }
Example #4
0
 /// <summary>
 /// Поиск сети по имени
 /// </summary>
 /// <param name="nameNet">Имя сети</param>
 /// <returns>Возвращает найденую сеть.</returns>
 public LCTreeNodeSubnet FindSubnet(string nameNet)
 {
     foreach (LCTreeNode node in AllLCTreeNode(treeView.Nodes))
     {
         if (node.LCObjectType == LCObjectType.SubNet)
         {
             LCTreeNodeSubnet lcSubNet = (LCTreeNodeSubnet)node;
             if (lcSubNet.Text == nameNet)
             {
                 this.WriteListBox("Найдена сеть с именем: " + lcSubNet.Text + ".");
                 return(lcSubNet);
             }
         }
     }
     return(null);
 }
Example #5
0
 /// <summary>
 /// Поиск сети по ip адресу.
 /// </summary>
 /// <param name="ip">ip адрес.</param>
 /// <returns>Возвращает сеть.</returns>
 public LCTreeNodeSubnet FindSubnetIP(string ip)
 {
     foreach (LCTreeNode node in AllLCTreeNode(treeView.Nodes))
     {
         if (node.LCObjectType == LCObjectType.SubNet)
         {
             // Этот узел сеть, приводим объект к нужному классу
             LCTreeNodeSubnet lcSubnet = (LCTreeNodeSubnet)node;
             if (lcSubnet.CompareIPtoSubnet(ip))
             {
                 this.WriteListBox("IP адрес " + ip + " принадлежит сети " + lcSubnet.Text);
                 return(lcSubnet);
             }
         }
     }
     return(null);
 }
Example #6
0
        /// <summary>
        /// Метод добавления сети
        /// </summary>
        /// <param name="nameSubnet">Имя сети.</param>
        /// <param name="ipSubnet">IP адрес сети.</param>
        /// <param name="maskSubnet">Маска сети.</param>
        /// <returns>Возвращает созданную сеть</returns>
        public LCTreeNodeSubnet AddSubnet(string nameSubnet, string ipSubnet, string maskSubnet, string description)
        {
            // созадем новую сеть
            LCTreeNodeSubnet lcTreeNodeSubnet = new LCTreeNodeSubnet
            {
                Text             = nameSubnet,
                Description      = description,
                ContextMenuStrip = LCTreeNode.subnetContextMenuStrip,
                IPSubnet         = ipSubnet,
                MaskSubnet       = maskSubnet,
                ToolTipText      = nameSubnet
            };

            this.Nodes.Add(lcTreeNodeSubnet);
            lcTreeNodeSubnet.UpdateLC();
            this.WriteListBoxOperation("Добавлена группа : " + nameSubnet);
            return(lcTreeNodeSubnet);
        }
Example #7
0
        /// <summary>
        /// Метод переопределения сети для хостов из группы "Не в списке"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolStripMenuItemFindSubnet_Click(object sender, EventArgs e)
        {
            List <String> list = new List <String>();
            TreeNode      node = this.lCDirectory.ReturnGroupNoList();

            foreach (TreeNode tn in node.Nodes)
            {
                LCTreeNodeHost lc = (LCTreeNodeHost)tn;
                list.Add(lc.IP);
                if (lc.Tag != null)
                {
                    ((ListViewItem)lc.Tag).Remove();
                }
            }
            // Удаляем группу "Не в списке"
            node.Remove();
            // проверяем на всякий пожарный, не пустое ли дерево справочника
            if (this.treeViewObject.Nodes.Count > 0)
            {
                this.treeViewObject.BeginUpdate();
                foreach (string st in list)
                {
                    // Ищем принадлежность ПК к какой либо сети
                    LCTreeNodeSubnet lcSubnet = this.lCDirectory.FindSubnetIP(st);
                    if (lcSubnet != null)
                    {
                        // и сразу же выделяем этот объект
                        this.OpenLCTreeNode(lcSubnet.AddHost(st, st, ""));
                    }
                    else
                    {
                        LCTreeNodeNoList lcNoList = lCDirectory.ReturnGroupNoList();
                        // и сразу же выделяем этот объект
                        this.OpenLCTreeNode(lcNoList.AddHost(st, st, ""));
                    }
                }
                this.treeViewObject.EndUpdate();
            }
        }
Example #8
0
 private void FindAndOpenHost(string st)
 {
     if (this.lCDirectory.CorrectIP(ref st))
     {
         this.toolStripTextBoxIP.Text = st;
         this.WriteListBox("Поиск компьютера с IP " + this.toolStripTextBoxIP.Text + " запущен.");
         LCTreeNodeHost lcHost = this.lCDirectory.FindHost(st);
         if (lcHost != null)
         {
             //Выделяем найденый хост в дереве
             LCDirectory.treeView.SelectedNode = lcHost;
             this.OpenLCTreeNode(lcHost);
             this.WriteListBox("Найден хост с именем: " + lcHost.Text + ".");
         }
         else
         {
             //Определяем принадлежность хоста сети
             LCTreeNodeSubnet findSubnet = this.lCDirectory.FindSubnetIP(st);
             if (findSubnet != null)
             {
                 this.OpenLCTreeNode(findSubnet.AddHost(st, st, ""));
                 this.WriteListBox("IP адрес " + st + " принадлежит сети " + findSubnet.Text);
             }
             else
             {
                 LCTreeNodeNoList lcNoList = (LCTreeNodeNoList)this.lCDirectory.ReturnGroupNoList();
                 //добавляем хост и сразу же выделяем этот объект
                 this.OpenLCTreeNode(lcNoList.AddHost(st, st, ""));
                 this.WriteListBox("IP адрес " + st + " добавлен в группу " + lcNoList.Text);
             }
         }
     }
     else
     {
         this.WriteListBox("Введенное значение не является IP адресом");
     }
 }
Example #9
0
        private XElement SaveChildren(LCTreeNode item, XElement current)
        {
            LCTreeNode xnodWorking;

            switch (item.LCObjectType)
            {
            case LCObjectType.Group:
            {
                if (item.Name != "Root")
                {
                    LCTreeNodeGroup lcGroup  = (LCTreeNodeGroup)item;
                    XElement        xElement = new XElement("Group",
                                                            new XAttribute("NameGroup", lcGroup.Text),
                                                            new XAttribute("Description", lcGroup.Description));
                    current = xElement;
                }
            }
            break;

            case LCObjectType.Host:
            {
                LCTreeNodeHost lcHost   = (LCTreeNodeHost)item;
                XElement       xElement = new XElement("Host",
                                                       new XAttribute("TypeHost", lcHost.TypeHost.ToString()),
                                                       new XAttribute("NameHost", lcHost.Text),
                                                       new XAttribute("IP", lcHost.IP),
                                                       new XAttribute("Barcode", lcHost.Barcode),
                                                       new XAttribute("Login", lcHost.Login),
                                                       new XAttribute("Password", lcHost.Password),
                                                       new XAttribute("Description", lcHost.Description));;
                current = xElement;
            }
            break;

            case LCObjectType.NoList:
            {
                LCTreeNodeNoList lcNoList = (LCTreeNodeNoList)item;
                XElement         xElement = new XElement("NoList",
                                                         new XAttribute("NameGroup", lcNoList.Text),
                                                         new XAttribute("Description", lcNoList.Description));
                current = xElement;
            }
            break;

            case LCObjectType.SubNet:
            {
                LCTreeNodeSubnet lcSubnet = (LCTreeNodeSubnet)item;
                XElement         xElement = new XElement("Subnet",
                                                         new XAttribute("NameSubnet", lcSubnet.Text),
                                                         new XAttribute("IPSubnet", lcSubnet.IPSubnet),
                                                         new XAttribute("MaskSubnet", lcSubnet.MaskSubnet),
                                                         new XAttribute("Description", lcSubnet.Description));
                current = xElement;
            }
            break;
            }
            //рекурсивный перебор всех дочерних узлов
            if (item.Nodes.Count > 0)
            {
                xnodWorking = (LCTreeNode)item.FirstNode;
                while (xnodWorking != null)
                {
                    current.Add(SaveChildren(xnodWorking, current));
                    xnodWorking = (LCTreeNode)xnodWorking.NextNode;
                }
            }
            return(current);
        }
Example #10
0
        /// <summary>
        /// Метод добавления дочерних узлов в дерево
        /// </summary>
        /// <param name="xnod">XML элемент</param>
        /// <param name="newNode">Компонент TreeNode в котором создаются узлы</param>
        private void AddChildrenDOMXML(XElement xnod, TreeNode newNode)
        {
            if (xnod.NodeType == System.Xml.XmlNodeType.Element)
            {
                switch (xnod.Name.ToString())
                {
                case "Group":
                {
                    LCTreeNodeGroup lcTreeNodeGroup = new LCTreeNodeGroup
                    {
                        Text             = xnod.Attribute("NameGroup").Value,
                        Description      = xnod.Attribute("Description").Value,
                        ContextMenuStrip = LCTreeNode.groupContextMemuStrip,
                        ImageIndex       = 2
                    };
                    newNode.Nodes.Add(lcTreeNodeGroup);
                    lcTreeNodeGroup.UpdateLC();
                    newNode = lcTreeNodeGroup;
                }
                break;

                case "NoList":
                {
                    LCTreeNodeNoList lcTreeNodeNoList = new LCTreeNodeNoList
                    {
                        Text             = xnod.Attribute("NameGroup").Value,
                        Description      = xnod.Attribute("Description").Value,
                        ContextMenuStrip = LCTreeNode.noListContextMenuStrip,
                        ImageIndex       = 2
                    };
                    lcTreeNodeNoList.ToolTipText += lcTreeNodeNoList.Text;
                    lcTreeNodeNoList.ToolTipText += "\n" + lcTreeNodeNoList.Description;
                    newNode.Nodes.Add(lcTreeNodeNoList);
                    newNode = lcTreeNodeNoList;
                }
                break;

                case "Host":
                {
                    LCTreeNodeHost lcTreeNodeHost = new LCTreeNodeHost
                    {
                        Text             = xnod.Attribute("NameHost").Value,
                        IP               = xnod.Attribute("IP").Value,
                        Barcode          = xnod.Attribute("Barcode").Value,
                        Login            = xnod.Attribute("Login").Value,
                        Password         = xnod.Attribute("Password").Value,
                        Description      = xnod.Attribute("Description").Value,
                        TypeHost         = (LCTypeHost)Enum.Parse(typeof(LCTypeHost), xnod.Attribute("TypeHost").Value),
                        ContextMenuStrip = LCTreeNode.computerContextMenuStrip
                    };
                    newNode.Nodes.Add(lcTreeNodeHost);
                    lcTreeNodeHost.UpdateLC();
                    return;
                }

                case "Subnet":
                {
                    LCTreeNodeSubnet lcTreeNodeSubnet = new LCTreeNodeSubnet
                    {
                        Text             = xnod.Attribute("NameSubnet").Value,
                        IPSubnet         = xnod.Attribute("IPSubnet").Value,
                        MaskSubnet       = xnod.Attribute("MaskSubnet").Value,
                        Description      = xnod.Attribute("Description").Value,
                        ContextMenuStrip = LCTreeNode.subnetContextMenuStrip,
                        ImageIndex       = 5
                    };
                    newNode.Nodes.Add(lcTreeNodeSubnet);
                    lcTreeNodeSubnet.UpdateLC();
                    newNode = lcTreeNodeSubnet;
                }
                break;

                case "Root":
                {
                    //MessageBox.Show("yes");
                    //newNode.ImageIndex = 1;
                    //newNode.Text = mapAttributes.Item(1).Value;
                }
                break;
                }
                foreach (XElement element in xnod.Elements())
                {
                    AddChildrenDOMXML(element, newNode);
                }
            }
        }
Example #11
0
        /// <summary>
        /// Событие удаления объекта LC
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DeleteLCTreeNode(object sender, EventArgs e)
        {
            LCTreeNode lcTreeNode = (LCTreeNode)this.treeViewObject.SelectedNode;
            string     tempStr    = lcTreeNode.Text;

            // Проверяем есть ли у этого узла дочерние объекты
            if (lcTreeNode.Nodes.Count > 0)
            {
                // надо перебрать все узлы
                if (MessageBox.Show("Объект имеет дочерние узлы! Все равно удалить?", "Удаление", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    // Здесь нужен код для удаления из таблиц объектов, которые являются дочерними по отношению к удаляемому объекту

                    // Удаляем текущий
                    //lcTreeNode.Remove();
                    MessageBox.Show("Пока не реализовано удаление элементов с дочерними объектами!");
                    // Сообщаем об удалении
                    this.WriteListBox("Группа " + tempStr + " и её дочерние объекты удалены.");
                }
            }
            else
            {
                if (MessageBox.Show("Вы дейстительно хотите удалить этот объект ?", "Удаление", MessageBoxButtons.YesNo,
                                    MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
                {
                    switch (lcTreeNode.LCObjectType)
                    {
                    case LCObjectType.Host:
                    {
                        LCTreeNodeHost lcHost = (LCTreeNodeHost)lcTreeNode;
                        lcHost.RemoveLC();
                        tempStr = "Компьютер: " + tempStr + " удалён.";
                        // Сообщаем об удалении
                        this.WriteListBox(tempStr);
                        break;
                    }

                    case LCObjectType.SubNet:
                    {
                        LCTreeNodeSubnet lcSubnet = (LCTreeNodeSubnet)lcTreeNode;
                        lcSubnet.RemoveLC();
                        tempStr = "Сеть: " + tempStr + " удалена.";
                        this.WriteListBox(tempStr);
                        break;
                    }

                    case LCObjectType.Group:
                    {
                        LCTreeNodeGroup lcGroup = (LCTreeNodeGroup)lcTreeNode;
                        lcGroup.RemoveLC();
                        tempStr = "Группа: " + tempStr + " удалена.";
                        this.WriteListBox(tempStr);
                        break;
                    }

                    case LCObjectType.NoList:
                    {
                        LCTreeNodeNoList lcNoList = (LCTreeNodeNoList)lcTreeNode;
                        lcNoList.Remove();
                        tempStr = "Группа: " + tempStr + " удалена.";
                        this.WriteListBox(tempStr);
                        break;
                    }
                    }
                }
            }
        }
Example #12
0
        /// <summary>
        /// Метод открытия узла дерева.
        /// </summary>
        /// <param name="treeNode">Открываемый узел.</param>
        private void OpenLCTreeNode(TreeNode treeNode)
        {
            if (treeNode == null)
            {
                return;
            }

            LCTreeNode lcTreeNode = (LCTreeNode)treeNode;

            switch (lcTreeNode.LCObjectType)
            {
            case LCObjectType.Host:
            {
                this.tabControlObject.SelectedTab = this.tabPageHosts;
                LCTreeNodeHost lcHost = (LCTreeNodeHost)lcTreeNode;
                // Делаем активным список хостов
                this.listViewHosts.Focus();
                foreach (ListViewItem curilv in this.listViewHosts.Items)
                {
                    if (curilv.Tag == lcHost)
                    {
                        // Выделяем нужный элемент в списке
                        curilv.Selected = true;
                        return;
                    }
                }
                // определяем родительскую группу элемента
                LCTreeNode lcNode = (LCTreeNode)lcHost.Parent;
                // Пока сделано так, в будущем предполагаются что ПК состоят только в сетях. Кроме группы <Не в списке>
                if (lcNode.LCObjectType == LCObjectType.SubNet)
                {
                    ListViewGroup lvg = null;
                    foreach (ListViewGroup curGroup in this.listViewHosts.Groups)
                    {
                        if (curGroup.Tag == lcNode)
                        {
                            // Группа существует
                            lvg = curGroup;
                            break;
                        }
                    }
                    if (lvg == null)
                    {
                        // Такой группы еще нет, надо её создать
                        lvg = new ListViewGroup(lcNode.Text);
                    }
                    lvg.Tag = lcNode;
                    this.listViewHosts.Groups.Add(lvg);
                    ListViewItem lvi = new ListViewItem(new string[] { lcHost.TypeHost.ToString(), lcHost.IP, lcHost.Text, lcHost.ParentGroup, lcHost.DescriptionStr }, lvg)
                    {
                        Tag = lcHost
                    };
                    lcHost.Tag = lvi;
                    this.listViewHosts.Items.Add(lvi);
                    lcHost.UpdateLC();
                    lvi.Selected = true;
                }
                else
                {
                    ListViewItem lvi = new ListViewItem(new string[] { lcHost.TypeHost.ToString(), lcHost.IP, lcHost.Text, lcHost.ParentGroup, lcHost.DescriptionStr })
                    {
                        Tag = lcHost
                    };
                    lcHost.Tag = lvi;
                    this.listViewHosts.Items.Add(lvi);
                    lcHost.UpdateLC();
                    lvi.Selected = true;
                }
                break;
            }

            case LCObjectType.SubNet:
            {
                this.tabControlObject.SelectedTab = this.tabPageSubnets;
                this.listViewSubnets.Focus();
                LCTreeNodeSubnet lcSubnet = (LCTreeNodeSubnet)lcTreeNode;
                foreach (ListViewItem cutilv in this.listViewSubnets.Items)
                {
                    if (cutilv.Tag == lcSubnet)
                    {
                        cutilv.Selected = true;
                        return;
                    }
                }
                ListViewItem lvi = new ListViewItem(new string[] { lcSubnet.Text, lcSubnet.IPSubnet,
                                                                   lcSubnet.MaskSubnet, lcSubnet.ParentGroup, lcSubnet.DescriptionStr })
                {
                    Tag = lcSubnet
                };
                lcSubnet.Tag = lvi;
                this.listViewSubnets.Items.Add(lvi);
                lvi.Selected = true;
                break;
            }

            case LCObjectType.Group:
            {
                this.tabControlObject.SelectedTab = this.tabPageGroups;
                this.listViewGroups.Focus();
                LCTreeNodeGroup lcGroup = (LCTreeNodeGroup)lcTreeNode;
                foreach (ListViewItem curilv in this.listViewGroups.Items)
                {
                    if (curilv.Tag == lcGroup)
                    {
                        curilv.Selected = true;
                        return;
                    }
                }
                ListViewItem lvi = new ListViewItem(new string[] { lcGroup.Text, lcGroup.ParentGroup, lcGroup.DescriptionStr })
                {
                    Tag = lcGroup
                };
                lcGroup.Tag = lvi;
                this.listViewGroups.Items.Add(lvi);
                lvi.Selected = true;
                break;
            }
            }
        }