Пример #1
0
 private void miDelete_Click(object sender, EventArgs e)
 {
     Area selectedArea = AreasTree.SelectedNode != null ? AreasTree.SelectedNode.Tag as Area : null;
     if (selectedArea != null)
     {
         MessageBox3Buttons mb = new MessageBox3Buttons()
         {
             Text = @"Удаление узла",
             InfoMessage = {Text = @"Удалить узел " + selectedArea.Description},
             btn1 = {Text = @"Только текущий",},
             btn2 = { Text = @"Вместе с подчиненными узлами", Visible = selectedArea.ChildAreas.Any() },
             btn3 = {Text = @"Отмена"}
         };
         mb.btn1.Click += (s, es) =>
         {
             mb.ButtonResult = 1;
             mb.DialogResult = DialogResult.OK;
         };
         mb.btn2.Click += (s, es) =>
         {
             mb.ButtonResult = 2;
             mb.DialogResult = DialogResult.OK;
             };
         mb.btn3.Click += (s, es) =>
         {
             mb.ButtonResult = 0;
             mb.DialogResult = DialogResult.Cancel;
         };
         mb.ShowDialog(this);
         switch (mb.ButtonResult)
         {
             case 1: //Удаление еденичного узла
                 int childEquipments = _dataContext.Equipments.Count(equipment => equipment.Area.AreaId == selectedArea.AreaId);
                 if (childEquipments != 0)
                 {
                     MessageBox.Show(@"На узле [" + selectedArea.Description + @"] есть оборудование, удаление невозможно!");
                     return;
                 }
                 Cursor = Cursors.WaitCursor;
                 Area parentArea = selectedArea.ParentArea;
                 if (selectedArea.ChildAreas.Any())
                 {
                     List<Area> childAreas = new List<Area>();
                     childAreas.AddRange(selectedArea.ChildAreas.ToList());
                     childAreas.ForEach(area =>
                     {
                         area.ParentArea = parentArea;
                     });
                 }
                 _dataContext.Areas.Remove(selectedArea);
                 _dataContext.SaveChanges();
                 RefreshTree();
                 OnHistoryEvent(new HistoryEventArgs("Delete AreaDescription", selectedArea.Description));
                 OnChanged(EventArgs.Empty);
                 Cursor = Cursors.Default;
                 break;
             case 2: //Удаление дерева узлов
                 try
                 {
                     var deletedNodes = GetChilds(AreasTree.SelectedNode).OrderByDescending(node => node.Level).ToList();
                     foreach (var checkArea in deletedNodes)
                     {
                         int childEquipments1 = _dataContext.Equipments.Count(equipment => equipment.Area.AreaId == ((Area)checkArea.Tag).AreaId);
                         if (childEquipments1 != 0)
                         {
                             MessageBox.Show(@"На узле [" + ((Area) checkArea.Tag).Description + @"] есть оборудование, удаление невозможно!");
                             return;
                         }
                     }
                     Cursor = Cursors.WaitCursor;
                     foreach (TreeNodeAdv deletedNode in deletedNodes)
                     {
                         Area area = (Area) deletedNode.Tag;
                         _dataContext.Areas.Remove(area);
                         OnHistoryEvent(new HistoryEventArgs("Delete AreaDescription", area.Description));
                     }
                     _dataContext.SaveChanges();
                     Cursor = Cursors.Default;
                 }
                 catch (Exception)
                 {
                     throw;
                 }
                 RefreshTree();
                 OnChanged(EventArgs.Empty);
                 break;
             case 0:
                 break;
             default:
                 throw new Exception(@"Неизвестная ошибка...");
         }
     }
 }
Пример #2
0
 private void miDelete_Click(object sender, EventArgs e)
 {
     Department selectedDepartment = DepartmentsGrid.SelectedNode != null ? DepartmentsGrid.SelectedNode.Tag as Department : null;
     if (selectedDepartment != null)
     {
         MessageBox3Buttons mb = new MessageBox3Buttons()
         {
             Text = @"Удаление подразделения",
             InfoMessage = {Text = @"Удалить тип " + selectedDepartment.Description + @"?"},
             btn1 = {Text = @"Да",},
             btn2 = {Visible = false},
             btn3 = {Text = @"Отмена"},
         };
         mb.btn1.Click += (s, es) =>
         {
             mb.DialogResult = DialogResult.OK;
         };
         mb.btn3.Click += (s, es) =>
         {
             mb.DialogResult = DialogResult.Cancel;
         };
         if (mb.ShowDialog(this) == DialogResult.OK)
         {
             try
             {
                 int usedDepartments = _dataContext.Access_Users.Count(user => user.DepartmentId == selectedDepartment.Id);
                 if (usedDepartments != 0)
                 {
                     MessageBox.Show(@"Подразделение используется! Удаление невозможно!");
                     return;
                 }
                 Cursor = Cursors.WaitCursor;
                 string oldValue = selectedDepartment.Description;
                 _dataContext.Departments.Remove(selectedDepartment);
                 _dataContext.SaveChanges();
                 RefreshTree();
                 OnChanged(EventArgs.Empty);
                 Cursor = Cursors.Default;
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
Пример #3
0
 private void miDelete_Click(object sender, EventArgs e)
 {
     PortType selectedType = PortTypesGrid.SelectedNode != null ? PortTypesGrid.SelectedNode.Tag as PortType : null;
     if (selectedType != null)
     {
         MessageBox3Buttons mb = new MessageBox3Buttons()
         {
             Text = @"Удаление типа порта",
             InfoMessage = {Text = @"Удалить тип " + selectedType.Description + @"?"},
             btn1 = {Text = @"Да",},
             btn2 = {Visible = false},
             btn3 = {Text = @"Отмена"},
         };
         mb.btn1.Click += (s, es) =>
         {
             mb.DialogResult = DialogResult.OK;
         };
         mb.btn3.Click += (s, es) =>
         {
             mb.DialogResult = DialogResult.Cancel;
         };
         if (mb.ShowDialog(this) == DialogResult.OK)
         {
             try
             {
                 int usedPortsCount = _dataContext.EquipmentPorts.Count(port => port.PortTypeId == selectedType.PortTypeId);
                 if (usedPortsCount != 0)
                 {
                     MessageBox.Show(@"Тип порта используется! Удаление невозможно!");
                     return;
                 }
                 Cursor = Cursors.WaitCursor;
                 string oldValue = selectedType.Description;
                 _dataContext.PortTypes.Remove(selectedType);
                 _dataContext.SaveChanges();
                 RefreshTree();
                 OnHistoryEvent(new HistoryEventArgs("Delete PortType", oldValue));
                 OnChanged(EventArgs.Empty);
                 Cursor = Cursors.Default;
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
 }
Пример #4
0
 private void DeleteTemplateElement()
 {
     TreeNodeAdv selectedNode = EquipmentTemplatesTree.SelectedNode;
     if (selectedNode == null) return;
     EquipmentTemplate selectedTemplate = (EquipmentTemplate)selectedNode.Tag;
     if (selectedTemplate == null) throw new Exception("Unknown error in template tree!");
     MessageBox3Buttons deForm=new MessageBox3Buttons
     {
         Text = @"Удаление", 
         InfoMessage = {Text = @"Удалить элемент "+selectedTemplate.Description+@"?"},
         btn1 = { Text = @"Да", },
         btn2 = { Text = @"Вместе с подчиненными узлами" },
         btn3 = { Text = @"Отмена" }
     };
     deForm.btn1.Click += (s, es) =>
     {
         deForm.ButtonResult = 1;
         deForm.DialogResult = DialogResult.OK;
     };
     deForm.btn2.Click += (s, es) =>
     {
         deForm.ButtonResult = 2;
         deForm.DialogResult = DialogResult.OK;
     };
     deForm.btn3.Click += (s, es) =>
     {
         deForm.ButtonResult = 0;
         deForm.DialogResult = DialogResult.Cancel;
     };
     if ((selectedTemplate.ChildElementTemplates.Count == 0) | ((ElementType)selectedTemplate.ElementType==ElementType.Device))
         deForm.btn2.Visible = false;
     deForm.ShowDialog(this);
     switch (deForm.ButtonResult)
     {
         case 1: //Удаление еденичного элемента
             if ((ElementType)selectedTemplate.ElementType == ElementType.Device) goto case 2;
             try
             {
                 Cursor = Cursors.WaitCursor;
                 if (selectedTemplate.ChildElementTemplates.Any())
                 {
                     EquipmentTemplate parent = selectedTemplate.ParentElementTemplate;
                     selectedTemplate.ChildElementTemplates.ToList().ForEach(item => item.ParentElementTemplate = parent);
                 }
                 _dataContext.EquipmentTemplates.Remove(selectedTemplate);
                 _dataContext.SaveChanges();
                 OnHistoryEvent(new HistoryEventArgs("Delete Template", selectedTemplate.Description));
                 Cursor = Cursors.Default;
             }
             catch (Exception)
             {
                 throw;
             }
             RefreshTree();
             OnChanged(EventArgs.Empty);
             break;
         case 2:
             Cursor = Cursors.WaitCursor;
             var deletedNodes=GetChilds(selectedNode).OrderByDescending(node => node.Level).ToList();
             try
             {
                 foreach (TreeNodeAdv deletedNode in deletedNodes)
                 {
                     EquipmentTemplate template = (EquipmentTemplate) deletedNode.Tag;
                     _dataContext.EquipmentTemplates.Remove(template);
                     OnHistoryEvent(new HistoryEventArgs("Delete Template", template.Description));
                 }
                 _dataContext.SaveChanges();
             }
             catch (Exception)
             {
                 throw;
             }
             RefreshTree();
             OnChanged(EventArgs.Empty);
             Cursor = Cursors.Default;
             break;
         case 0:
             break;
         default:
             throw new Exception(@"Неизвестная ошибка...");
     }
 }