Пример #1
0
 private void ChangeTemplateElement()
 {
     TreeNodeAdv selectedNode = EquipmentTemplatesTree.SelectedNode;
     if (selectedNode == null) return;
     EquipmentTemplate selectedTemplate = (EquipmentTemplate) selectedNode.Tag;
     if (selectedTemplate == null) throw new Exception("Unknown error in template tree!");
     TemplateEditForm teForm = new TemplateEditForm();
     switch ((ElementType)selectedTemplate.ElementType)
     {
         case ElementType.Device:
             teForm.cbxPosition.Visible = false;
             teForm.ComboBoxLabel.Visible = false;
             teForm.tlPortTemplate.Visible = false;
             teForm.LabelText.Text = @"Название шаблона устройста";
             teForm.Text = @"Изменение названия шаблона устройства";
             break;
         case ElementType.Slot:
             teForm.tlPortTemplate.Visible = false;
             teForm.LabelText.Text = @"Название шаблона слота";
             teForm.Text = @"Изменение названия слота";
             break;
         case ElementType.Card:
             teForm.tlPortTemplate.Visible = false;
             teForm.LabelText.Text = @"Название шаблона линейной карты";
             teForm.Text = @"Изменение названия шаблона линейной карты";
             break;
         case ElementType.Port:
             teForm.tbDescription.Validating -= teForm.InputText_Validating;
             teForm.tlPortTemplate.Visible = true;
             teForm.cbIgnoreCalc.Visible = false;
             teForm.LabelText.Text = @"Префикс шаблона портов";
             teForm.Text = @"Изменение шаблона портов";
             teForm.cbxTypes.DataSource = _dataContext.PortTypes.OrderBy(typep => typep.Description).ToList();
             teForm.cbxTypes.SelectedItem = selectedTemplate.PortType;
             break;
         default:
             throw new ArgumentOutOfRangeException();
     }
     teForm.tbDescription.Text = selectedTemplate.Description;
     teForm.cbIgnoreCalc.Checked = selectedTemplate.IgnoredCalc;
     teForm.cbxPosition.SelectedItem = selectedTemplate.Position;
     teForm.tbNumberStart.Text = selectedTemplate.NumberStart.ToString();
     if ((ElementType)selectedTemplate.ElementType!=ElementType.Device)
         foreach (EquipmentTemplate childTemplate in selectedTemplate.ParentElementTemplate.ChildElementTemplates.Where(temp => temp.Position != selectedTemplate.Position)) teForm.cbxPosition.Items.Remove(childTemplate.Position);
     teForm.tbCount.Text = selectedTemplate.PortCount.ToString();
     teForm.tbDelimiter.Text = selectedTemplate.PortDelimiter;
     if (teForm.ShowDialog(this) == DialogResult.OK)
     {
         try
         {
             selectedTemplate.PortPrefix = selectedTemplate.Description = teForm.tbDescription.Text;
             selectedTemplate.IgnoredCalc = teForm.cbIgnoreCalc.Checked;
             selectedTemplate.Position = Convert.ToInt16(teForm.cbxPosition.SelectedItem);
             selectedTemplate.PortCount = teForm.tbCount.Text.Equals(string.Empty) ? (int?)null : Convert.ToInt16(teForm.tbCount.Text);
             selectedTemplate.PortDelimiter = teForm.tbDelimiter.Text;
             selectedTemplate.PortType =  ((PortType) teForm.cbxTypes.SelectedItem);
             selectedTemplate.NumberStart = Convert.ToInt16(teForm.tbNumberStart.Text);
             Cursor = Cursors.WaitCursor;
             _dataContext.SaveChanges();
             RefreshTree();
             OnChanged(EventArgs.Empty);
             OnHistoryEvent(new HistoryEventArgs("Change Template", selectedTemplate.Description));
             Cursor = Cursors.Default;
         }
         catch (Exception)
         {
             throw;
         }
         
     }
 }
Пример #2
0
        private void AddTemplateElement(ElementType type)
        {
            TreeNodeAdv selectedNode = EquipmentTemplatesTree.SelectedNode;
            EquipmentTemplate selectedTemplate = selectedNode != null ? (EquipmentTemplate) selectedNode.Tag : null;
            TemplateEditForm teForm = new TemplateEditForm();
            switch (type)
            {
                case ElementType.Device:
                    teForm.cbxPosition.Visible = false;
                    teForm.ComboBoxLabel.Visible = false;
                    teForm.tlPortTemplate.Visible = false;
                    teForm.LabelText.Text = @"Название нового шаблона устройста";
                    teForm.Text = @"Добавление нового устройства";
                    break;
                case ElementType.Slot:
                    if (selectedNode == null) return;
                    if (selectedTemplate == null) throw new Exception("Unknown error in template tree!");
                    teForm.tlPortTemplate.Visible = false;
                    teForm.LabelText.Text = @"Название нового шаблона слота";
                    teForm.Text = @"Добавление нового слота в элемент";
                    break;
                case ElementType.Card:
                    if (selectedNode == null) return;
                    if (selectedTemplate == null) throw new Exception("Unknown error in template tree!");
                    if ((ElementType) selectedTemplate.ElementType != ElementType.Slot) return;
                    teForm.tlPortTemplate.Visible = false;
                    teForm.LabelText.Text = @"Название нового шаблона линейной карты";
                    teForm.Text = @"Добавление новой линейной карты в элемент";
                    break;
                case ElementType.Port:
                    if (selectedNode == null) return;
                    if (selectedTemplate == null) throw new Exception("Unknown error in template tree!");
                    teForm.tlPortTemplate.Visible = true;
                    teForm.cbIgnoreCalc.Visible = false;
                    teForm.LabelText.Text = @"Префикс шаблона портов";
                    teForm.Text = @"Добавление шаблона портов в элемент";
                    teForm.cbxTypes.DataSource = _dataContext.PortTypes.OrderBy(typep=>typep.Description).ToList();
                    teForm.tbDescription.Validating -= teForm.InputText_Validating;
                    break;
            }
            if (type != ElementType.Device)
            {
                if (selectedTemplate != null && selectedTemplate.ChildElementTemplates.Count > 0)
                    foreach (EquipmentTemplate childTemplate in selectedTemplate.ChildElementTemplates) teForm.cbxPosition.Items.Remove(childTemplate.Position);
                teForm.cbxPosition.SelectedIndex = 0;
            }
            if (teForm.ShowDialog(this) == DialogResult.OK)
            {
                try
                {
                    if (type == ElementType.Device)
                    {
                        var pData = _dataContext.EquipmentTemplates.SingleOrDefault(eq => eq.Description == teForm.tbDescription.Text);
                        if (pData != null)
                        {
                            MessageBox.Show(string.Format(@"'{0}' существует в списке шаблонов.", teForm.tbDescription.Text), @"Информация", MessageBoxButtons.OK);
                            return;
                        }
                    }
                    EquipmentTemplate newTemplate = null;
                    switch (type)
                    {
                        case ElementType.Device:
                            newTemplate = new EquipmentTemplate()
                            {
                                ElementId = Guid.NewGuid(),
                                Description = teForm.tbDescription.Text,
                                ParentElementId = (Guid?) null,
                                IgnoredCalc = teForm.cbIgnoreCalc.Checked,
                                Position = 0,
                                ElementType = (short) ElementType.Device,
                            };
                            break;
                        case ElementType.Card:
                        case ElementType.Slot:
                            newTemplate = new EquipmentTemplate
                            {
                                ElementId = Guid.NewGuid(),
                                Description = teForm.tbDescription.Text,
                                ParentElementTemplate = selectedTemplate,
                                IgnoredCalc = teForm.cbIgnoreCalc.Checked,
                                Position = Convert.ToInt16(teForm.cbxPosition.SelectedItem),
                                ElementType = (short) type
                            };
                            break;
                        case ElementType.Port:
                            newTemplate = new EquipmentTemplate()
                            {
                                ElementId = Guid.NewGuid(),
                                IgnoredCalc = false,
                                Description = teForm.tbDescription.Text,
                                ParentElementTemplate = selectedTemplate,
                                Position = Convert.ToInt16(teForm.cbxPosition.SelectedItem),
                                ElementType = (short) type,
                                NumberStart = Convert.ToInt16(teForm.tbNumberStart.Text),
                                PortPrefix = teForm.tbDescription.Text,
                                PortDelimiter = teForm.tbDelimiter.Text,
                                PortCount = Convert.ToInt32(teForm.tbCount.Text),
                                PortTypeId = ((PortType) teForm.cbxTypes.SelectedItem).PortTypeId
                            };
                            break;
                    }
                    if (newTemplate == null) throw new NotImplementedException(type + " not implement!");
                    Cursor = Cursors.WaitCursor;
                    _dataContext.EquipmentTemplates.Add(newTemplate);
                    _dataContext.SaveChanges();
                    RefreshTree();
                    if (selectedNode != null) selectedNode.Expand();
                    OnHistoryEvent(new HistoryEventArgs("Add Template", newTemplate.Description));
                    OnChanged(EventArgs.Empty);
                    Cursor = Cursors.Default;

                }
                catch (Exception)
                {
                    throw;
                }
            }
        }