Exemplo n.º 1
0
        private void EquipmentManage_Shown(object sender, EventArgs e)
        {
            EquipmentOwner owner;
            EquipmentSide side;
            switch (_buttonTag)
            {
                case 1: case 2: case 3:
                    owner = EquipmentOwner.Provider;
                    side = EquipmentSide.ProviderArea;
                    break;
                case 11: case 12: case 13:
                    owner = EquipmentOwner.Provider;
                    side = EquipmentSide.ClientArea;
                    break;
                case 21: case 22: case 23:
                    owner = EquipmentOwner.Client;
                    side = EquipmentSide.ProviderArea;
                    break;
                default:
                    throw new Exception("Unknown tag in button, invalid form");
            }
            SuspendLayout();
            cbOwner.DataSource = _owners;
            cbOwner.SelectedIndex = (int)owner;
            cbSide.DataSource = _placesAll;
            cbSide.SelectedIndex = (int) side;
            if (_manageEquipment == null)
            {
                MiniSplash splash = new MiniSplash
                {
                    TaskName = "LoadTemplateEquipments",
                    Text = "",
                    Working = (worker) =>
                    {
                        try
                        {
                            if (worker == null) throw new Exception("Invalid background worker process");
                            worker.ReportProgress(0, "Загрузка шаблонов");
                            _templates = _dataContexts.AccEquipmentV2Entities.EquipmentTemplates.Where(template => template.ParentElementTemplate == null).Include(templ => templ.ChildElementTemplates).OrderBy(item => item.Description).ToList();
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                };
                splash.ShowDialog(this);
                Text = @"Добавление оборудования";
                _clonedEquipment = new Equipment { EquipmentId = Guid.NewGuid(), Area = _area, OwnerType = (int)owner ,PlaceType = (int)side};
                TemplateSelectionControl control=new TemplateSelectionControl(_templates) { BorderStyle = BorderStyle.None };
                control.templatesTree.MouseClick += (_, __) =>
                {
                    NodeControlInfo info = control.templatesTree.GetNodeControlInfoAt(__.Location);
                    if (info.Node == null) return;
                    var data = info.Node.Tag as TemplateTreeItem;
                    if (data == null) return;
                    if (!data.IsLeaf) return;
                    var newTemplate=data.Tag as EquipmentTemplate;
                    if (newTemplate == null) return;

                    if (_selectedTemplate!=null && _selectedTemplate.ElementId == newTemplate.ElementId) return;
                    _selectedTemplate = data.Tag as EquipmentTemplate;
                    cbDescription.Text = _selectedTemplate.Description;
                    ChangeTemplate(_selectedTemplate);
                    cbDescription.HideDropDown();
                };
                cbDescription.DropDownControl = control;
                cbDescription.Visible = true;
                cbDescription.Text = string.Empty;
            }
            else
            {
                MiniSplash splash = new MiniSplash
                {
                    TaskName = "LoadTemplateEquipments",
                    Text = "",
                    Working = (worker) =>
                    {
                        try
                        {
                            if (worker == null) throw new Exception("Invalid background worker process");
                            worker.ReportProgress(0, "Загрузка данных оборудования");
                            _dataContexts.AccEquipmentV2Entities.Configuration.ProxyCreationEnabled = false;
                            _clonedEquipment =
                                _dataContexts.AccEquipmentV2Entities.Equipments.Where(equ => equ.EquipmentId == _manageEquipment.EquipmentId)
                                    .Include(equ => equ.ChildEquipments)
                                    .Include(equ => equ.EquipmentPorts)
                                    .Include(equ => equ.EquipmentPorts.Select(port => port.PortType))
                                    .Include(equ => equ.EquipmentPorts.Select(port => port.SideLink))
                                    .Include(equ => equ.SideLink)
                                    .Include(equ => equ.SideLink.CustomerSide)
                                    .AsNoTracking()
                                    .First();
                            _dataContexts.AccEquipmentV2Entities.Configuration.ProxyCreationEnabled = true;
                            if (_clonedEquipment == null)
                                throw new Exception("Invalid detach entry from data context");
                        }
                        catch (Exception)
                        {
                            throw;
                        }
                    }
                };
                splash.ShowDialog(this);
                Text = @"Изменение оборудования " +
                       string.Format("{0} {1}", _clonedEquipment.Description, _clonedEquipment.NetworkDescription != string.Empty ? "[" + _clonedEquipment.NetworkDescription + "]" : "");
                tbDescription.Text = _clonedEquipment.Description;
                tbDescription.Visible = true;
                tbNetworkDescription.Text = _clonedEquipment.NetworkDescription;
                tbComments.Text = _clonedEquipment.Comments;
                tbSerialNumber.Text = _clonedEquipment.SerialNumber;
                lbCards.DataSource = _clonedEquipment.ChildEquipments.OrderBy(equ => equ.Description).ToList();
                lbPorts.DataSource = _clonedEquipment.EquipmentPorts.OrderBy(portn => portn, new PortNameComparer()).ThenBy(port => port.PortType.Description).ToList();
            }
            if (_clonedEquipment.SideLink != null)
                tbCustomer.Text = _dataContexts.GetSideLinkDescription2(_clonedEquipment.SideLink);
            ResumeLayout();
        }
Exemplo n.º 2
0
 private void ChangeTemplate(EquipmentTemplate newTemplate)
 {
     EquipmentTemplate selectedTemplate = newTemplate;
     if (selectedTemplate == null) return;
     Cursor = Cursors.WaitCursor;
     _clonedEquipment.Description = selectedTemplate.Description;
     var allTemplates = selectedTemplate.ChildElementTemplates.Flatten(x => x.ChildElementTemplates).ToList();
     List<Equipment> equipmentCards=new List<Equipment>();
     List<EquipmentPort> equipmentPorts=new List<EquipmentPort>();
     if (allTemplates.Count != 0)
     {
         List<EquipmentTemplate> cardTemplates = allTemplates.Where(eqt => eqt.ElementType == (int) ElementType.Card).ToList();
         if (cardTemplates.Any())
         {
             equipmentCards.AddRange(cardTemplates.Select(template => new Equipment()
             {
                 EquipmentId = Guid.NewGuid(),
                 Description = template.Description,
                 OwnerType = cbOwner.SelectedIndex,
                 PlaceType = cbSide.SelectedIndex,
                 Area = _area,
                 ParentEquipment = _clonedEquipment
             }));
         }
         List<EquipmentTemplate> portTemplates = allTemplates.Where(eqt => eqt.ElementType == (int)ElementType.Port).ToList();
         if (portTemplates.Any())
         {
             foreach (EquipmentTemplate template in portTemplates)
             {
                 string prefix = GetPrefixedName(template);
                 for (int i = template.NumberStart; i < (template.NumberStart+template.PortCount) ; i++)
                 {
                     EquipmentPort port = new EquipmentPort {PortId = Guid.NewGuid(), Equipment = _clonedEquipment, PortType = template.PortType, Description = prefix + i};
                     equipmentPorts.Add(port);
                 }
             }
         }
     }
     _clonedEquipment.ChildEquipments.Clear();
     _clonedEquipment.EquipmentPorts.Clear();
     foreach (Equipment equipmentCard in equipmentCards)
     {
         _clonedEquipment.ChildEquipments.Add(equipmentCard);
     }
     foreach (EquipmentPort equipmentPort in equipmentPorts)
     {
         _clonedEquipment.EquipmentPorts.Add(equipmentPort);
     }
     lbCards.DataSource = _clonedEquipment.ChildEquipments.OrderBy(equ=>equ.Description).ToList();
     lbPorts.DataSource = _clonedEquipment.EquipmentPorts.OrderBy(portn => portn, new PortNameComparer()).ThenBy(port => port.PortType.Description).ToList();
     Cursor = Cursors.Default;
 }
Exemplo n.º 3
0
 private string GetPrefixedName(EquipmentTemplate template)
 {
     EquipmentTemplate parent = template.ParentElementTemplate;
     List<int> positions = new List<int>();
     while (parent != null)
     {
         if (!parent.IgnoredCalc) positions.Add(parent.Position);
         parent = parent.ParentElementTemplate;
     }
     positions.Reverse();
     if (positions.Count == 0)
         return template.PortPrefix;
     return positions.Count > 0 ? template.PortPrefix + string.Join(template.PortDelimiter, positions) + template.PortDelimiter : template.PortPrefix != string.Empty ? template.PortPrefix + template.PortDelimiter : "";
 }
Exemplo n.º 4
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;
                }
            }
        }