コード例 #1
0
        public void Initialize(List <ProjectModel> projects, object selectedEntity)
        {
            // 项目级别信息集合
            var projectHierarchyItemsList = new List <NavigatorItemViewModel>();

            foreach (var p in projects)
            {
                // 为项目信息创建导航节点
                var projectHierarchyItem = new NavigatorItemViewModel(p);
                projectHierarchyItemsList.Add(projectHierarchyItem);

                // 判断当前节点是否为选中节点
                if (selectedEntity != null && selectedEntity.GetType() == typeof(ProjectModel) && (selectedEntity as ProjectModel).Equals(p))
                {
                    _selectedItem = projectHierarchyItem;
                }

                // 判断项目下是否有控制器节点
                if (p.Controllers.Count != 0)
                {
                    // 创建“控制器”导航节点
                    var controllerHierarchyItemsList = new List <NavigatorItemViewModel>();

                    foreach (var c in p.Controllers)
                    {
                        // 为“控制器信息”创建导航节点
                        var controllerHierarchyItem = new NavigatorItemViewModel(c);
                        controllerHierarchyItem.Parent = projectHierarchyItem;
                        controllerHierarchyItemsList.Add(controllerHierarchyItem);

                        // 判断当前节点是否为选中节点
                        if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerModel) && (selectedEntity as ControllerModel).Equals(c))
                        {
                            _selectedItem = controllerHierarchyItem;
                        }
                        #region 根据控制器类型获取配置的节点
                        IControllerConfig     config    = ControllerConfigManager.GetConfigObject(c.Type);
                        ControllerNodeModel[] nodeModel = config.GetNodes();
                        #endregion
                        if (nodeModel.Length != 0)
                        {
                            var controllerNodeHierarchyItemList = new List <NavigatorItemViewModel>();
                            foreach (var cNode in nodeModel)
                            {
                                //为“控制器节点类型”创建导航节点
                                var nodeHierarchyItem = new NavigatorItemViewModel(cNode);
                                nodeHierarchyItem.Parent = controllerHierarchyItem;
                                controllerNodeHierarchyItemList.Add(nodeHierarchyItem);
                                if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerNodeModel) && (selectedEntity as ControllerNodeModel).Equals(cNode))
                                {
                                    _selectedItem = controllerHierarchyItem;
                                }
                                //如果节点类型为“回路”,需要为其增加“回路号”导航节点
                                if (cNode.Type == ControllerNodeType.Loop) //回路数据应该加载回路信息
                                {
                                    if (c.Loops.Count > 0)                 //加载回路数据
                                    {
                                        var loopHierarchyItemList = new List <NavigatorItemViewModel>();
                                        foreach (var l in c.Loops)
                                        {
                                            //为回路信息创建导航节点
                                            var loopHierarchyItem = new NavigatorItemViewModel(l);
                                            loopHierarchyItem.Parent = nodeHierarchyItem;
                                            loopHierarchyItemList.Add(loopHierarchyItem);
                                            if (selectedEntity != null && selectedEntity.GetType() == typeof(LoopModel) && (selectedEntity as LoopModel).Equals(l))
                                            {
                                                _selectedItem = loopHierarchyItem;
                                            }
                                        }
                                        nodeHierarchyItem.Children = new CollectionView(loopHierarchyItemList);
                                    }
                                }
                            }
                            controllerHierarchyItem.Children = new CollectionView(controllerNodeHierarchyItemList);
                        }
                    }
                    projectHierarchyItem.Children = new CollectionView(controllerHierarchyItemsList);
                }
            }

            this.Projects = new CollectionView(projectHierarchyItemsList);

            // 设置选中节点状态,并展开当前选中节点
            if (_selectedItem != null)
            {
                _selectedItem.IsSelected = true;
                NavigatorItemViewModel current = _selectedItem.Parent;

                while (current != null)
                {
                    current.IsExpanded = true;
                    current            = current.Parent;
                }
            }
        }
コード例 #2
0
 protected override bool GenerateExcelTemplateLoopSheet(List <string> sheetNames, IControllerConfig config, Model.BusinessModel.ExcelTemplateCustomizedInfo summaryInfo, ref IExcelService excelService)
 {
     try
     {
         #region 生成所有回路页签模板
         int                   currentLoopStartIndex       = 2;
         int                   defaultLoopCodeLength       = 2;                                 //默认回路编码长度
         string                loopSheetNamePrefix         = "";                                //回路页签名称前缀
         short                 maxDeviceAmount             = config.GetMaxDeviceAmountValue();
         int                   maxLoopAmount               = config.GetMaxLoopAmountValue();    //允许最大回路数量
         int                   defaultDeviceTypeCode       = summaryInfo.DefaultDeviceTypeCode; //默认器件编码
         DeviceType            defaultDeviceType           = config.GetDeviceTypeViaDeviceCode(defaultDeviceTypeCode);
         ColumnConfigInfo[]    deviceColumnDefinitionArray = config.GetDeviceColumns();         //取得器件的列定义信息
         List <MergeCellRange> lstMergeCellRange           = new List <MergeCellRange>();
         ControllerNodeModel[] nodes = config.GetNodes();
         for (int i = 0; i < nodes.Length; i++)
         {
             switch (nodes[i].Type)
             {
             case ControllerNodeType.Loop:
                 loopSheetNamePrefix = nodes[i].Name;
                 break;
             }
         }
         for (int i = currentLoopStartIndex; i <= summaryInfo.LoopSheetAmount + 1; i++)
         {
             lstMergeCellRange.Clear();
             for (int j = 0; j < summaryInfo.LoopAmountPerSheet; j++)
             {
                 if (maxLoopAmount < (j + 1 + (i - currentLoopStartIndex) * summaryInfo.LoopAmountPerSheet))//已经超出最大回路编号,退出循环
                 {
                     break;
                 }
                 string loopCode  = summaryInfo.MachineNumberFormatted + (j + 1 + (i - currentLoopStartIndex) * summaryInfo.LoopAmountPerSheet).ToString().PadLeft(defaultLoopCodeLength, '0');
                 int    extraLine = 0;
                 if (j != 0)
                 {
                     extraLine = 2;
                 }
                 //回路标题:回路1
                 excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + j * extraLine, 0, loopSheetNamePrefix + ":" + loopCode, CellStyleType.SubCaption);
                 for (int devColumnCount = 0; devColumnCount < deviceColumnDefinitionArray.Length; devColumnCount++)
                 {
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + 1 + j * extraLine, devColumnCount, deviceColumnDefinitionArray[devColumnCount].ColumnName, CellStyleType.TableHead);
                 }
                 //回路标题行合并
                 MergeCellRange mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + j * extraLine;
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + j * extraLine;
                 mergeCellRange.FirstColumnIndex = 0;
                 mergeCellRange.LastColumnIndex  = deviceColumnDefinitionArray.Length - 1;
                 lstMergeCellRange.Add(mergeCellRange);
                 //回路默认器件信息
                 for (int k = 0; k < maxDeviceAmount; k++)
                 {
                     string deviceCode = (k + 1).ToString().PadLeft(summaryInfo.SelectedDeviceCodeLength - defaultLoopCodeLength - summaryInfo.MachineNumberFormatted.Length, '0');
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 0, loopCode + deviceCode, CellStyleType.Data);  //器件编码
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 1, defaultDeviceType.Name, CellStyleType.Data); //器件类型
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 2, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 3, "0", CellStyleType.Data);                    //屏蔽
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 4, "2", CellStyleType.Data);                    //灵敏度
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 5, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 6, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 7, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 8, null, CellStyleType.Data);
                     excelService.SetCellValue(sheetNames[i], j * maxDeviceAmount + k + (j * extraLine + 2), 9, null, CellStyleType.Data);
                 }
                 mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + (j * extraLine + 2);
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + (j * extraLine + 2) + maxDeviceAmount - 1;
                 mergeCellRange.FirstColumnIndex = 1;
                 mergeCellRange.LastColumnIndex  = 1;
                 excelService.SetSheetValidationForListConstraint(sheetNames[i], RefereceRegionName.DeviceType.ToString(), mergeCellRange);
                 mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + (j * extraLine + 2);
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + (j * extraLine + 2) + maxDeviceAmount - 1;
                 mergeCellRange.FirstColumnIndex = 2;
                 mergeCellRange.LastColumnIndex  = 2;
                 excelService.SetSheetValidationForListConstraint(sheetNames[i], RefereceRegionName.Feature.ToString(), mergeCellRange);
                 mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + (j * extraLine + 2);
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + (j * extraLine + 2) + maxDeviceAmount - 1;
                 mergeCellRange.FirstColumnIndex = 3;
                 mergeCellRange.LastColumnIndex  = 3;
                 excelService.SetSheetValidationForListConstraint(sheetNames[i], RefereceRegionName.Disable.ToString(), mergeCellRange);
                 mergeCellRange = new MergeCellRange();
                 mergeCellRange.FirstRowIndex    = j * maxDeviceAmount + (j * extraLine + 2);
                 mergeCellRange.LastRowIndex     = j * maxDeviceAmount + (j * extraLine + 2) + maxDeviceAmount - 1;
                 mergeCellRange.FirstColumnIndex = 4;
                 mergeCellRange.LastColumnIndex  = 4;
                 excelService.SetSheetValidationForListConstraint(sheetNames[i], RefereceRegionName.SensitiveLevel.ToString(), mergeCellRange);
             }
             excelService.SetColumnWidth(sheetNames[i], 1, 15f);
             excelService.SetColumnWidth(sheetNames[i], 9, 50f);
             excelService.SetMergeCells(sheetNames[i], lstMergeCellRange);//设置"回路页签"合并单元格
         }
         #endregion
     }
     catch (Exception ex)
     {
         return(false);
     }
     return(true);
 }
コード例 #3
0
ファイル: HierarchyViewModel.cs プロジェクト: wpmyj/twilight
        public void Initialize(List <ProjectModel> projects, object selectedEntity)
        {
            // create the top level collectionview for the customers
            var projectHierarchyItemsList = new List <HierarchyItemViewModel>();

            foreach (var p in projects)
            {
                // create the hierarchy item and add to the list
                var projectHierarchyItem = new HierarchyItemViewModel(p);

                projectHierarchyItemsList.Add(projectHierarchyItem);

                // check if this is the selected item
                if (selectedEntity != null && selectedEntity.GetType() == typeof(ProjectModel) && (selectedEntity as ProjectModel).Equals(p))
                {
                    _selectedItem = projectHierarchyItem;
                }

                // if there are any orders in projectHierarchyItem
                if (p.Controllers.Count != 0)
                {
                    // create a new list of HierarchyItems
                    var controllerHierarchyItemsList = new List <HierarchyItemViewModel>();
                    // loop through the orders and add them
                    foreach (var c in p.Controllers)
                    {
                        // create the hierarchy item and add to the list
                        var controllerHierarchyItem = new HierarchyItemViewModel(c);
                        controllerHierarchyItem.Parent = projectHierarchyItem;
                        controllerHierarchyItemsList.Add(controllerHierarchyItem);

                        // check if this is the selected item
                        if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerModel) && (selectedEntity as ControllerModel).Equals(c))
                        {
                            _selectedItem = controllerHierarchyItem;
                        }


                        IControllerConfig     config    = ControllerConfigManager.GetConfigObject(c.Type);
                        ControllerNodeModel[] nodeModel = config.GetNodes();
                        if (nodeModel.Length != 0)
                        {
                            var controllerNodeHierarchyItemList = new List <HierarchyItemViewModel>();
                            foreach (var cNode in nodeModel)
                            {
                                var nodeHierarchyItem = new HierarchyItemViewModel(cNode);
                                nodeHierarchyItem.Parent = controllerHierarchyItem;
                                controllerNodeHierarchyItemList.Add(nodeHierarchyItem);
                                if (selectedEntity != null && selectedEntity.GetType() == typeof(ControllerNodeModel) && (selectedEntity as ControllerNodeModel).Equals(cNode))
                                {
                                    _selectedItem = controllerHierarchyItem;
                                }
                                if (cNode.Type == ControllerNodeType.Loop) //回路数据应该加载回路信息
                                {
                                    if (c.Loops.Count > 0)                 //加载回路数据
                                    {
                                        var loopHierarchyItemList = new List <HierarchyItemViewModel>();
                                        foreach (var l in c.Loops)
                                        {
                                            var loopHierarchyItem = new HierarchyItemViewModel(l);
                                            loopHierarchyItem.Parent = nodeHierarchyItem;
                                            loopHierarchyItemList.Add(loopHierarchyItem);
                                            if (selectedEntity != null && selectedEntity.GetType() == typeof(LoopModel) && (selectedEntity as LoopModel).Equals(l))
                                            {
                                                _selectedItem = loopHierarchyItem;
                                            }
                                        }
                                        nodeHierarchyItem.Children = new CollectionView(loopHierarchyItemList);
                                    }
                                }
                            }
                            controllerHierarchyItem.Children = new CollectionView(controllerNodeHierarchyItemList);
                        }
                    }
                    // create the children of the customer
                    projectHierarchyItem.Children = new CollectionView(controllerHierarchyItemsList);
                }
            }

            this.Projects = new CollectionView(projectHierarchyItemsList);

            // select the selected item and expand it'type parents
            if (_selectedItem != null)
            {
                _selectedItem.IsSelected = true;
                HierarchyItemViewModel current = _selectedItem.Parent;

                while (current != null)
                {
                    current.IsExpanded = true;
                    current            = current.Parent;
                }
            }
        }