private void SetErrorInfo(string errorMessage) { string[] errorMessages = errorMessage.Split(';'); CheckItemCollection errorMessageColection = new CheckItemCollection(); for (int i = 0; i < errorMessages.Length; i++) { if (errorMessages[i] != "") { CheckItem errorItem = new CheckItem(); errorItem.Value = errorMessages[i]; errorMessageColection.Add(errorItem); } } ErrorInfoCollection = errorMessageColection; }
/// <summary> /// 初始化页面展示数据 /// </summary> public void InitilizeData(string errorMessage) { #region 错误信息显示 if (errorMessage != null && errorMessage != "") { ImportDataSelectorVisibility = Visibility.Collapsed; ErrorContentVisibility = Visibility.Visible; Title = ERROR_PAGE_TITLE; ErrorInfo = errorMessage; SetErrorInfo(errorMessage); return; } else { ImportDataSelectorVisibility = Visibility.Visible; ErrorContentVisibility = Visibility.Collapsed; Title = SELECTOR_PAGE_TITLE; } #endregion ControllerModel controller = ProjectManager.GetInstance.TheControllerViaImporting; #region 可见性设置 if (controller.Loops.Count > 0) { LoopInfoInSelectorVisibility = Visibility.Visible; } else { LoopInfoInSelectorVisibility = Visibility.Collapsed; PromptInfoInSelectorVisibility = Visibility.Visible; PromptInfo = "EXCEL文件中没有回路配置信息;"; } if (controller.StandardConfig.Count > 0 || controller.MixedConfig.Count > 0 || controller.GeneralConfig.Count > 0 || controller.ControlBoard.Count > 0) { OtherInfoInSelectorVisibility = Visibility.Visible; } else { OtherInfoInSelectorVisibility = Visibility.Collapsed; PromptInfo = PromptInfo + "EXCEL文件没有组态或网络手控盘配置信息;"; } //如果没有可导入的信息,此方法直接返回 if (LoopInfoInSelectorVisibility == Visibility.Collapsed && OtherInfoInSelectorVisibility == Visibility.Collapsed) { PromptInfoInSelectorVisibility = Visibility.Visible; PromptInfo = "EXCEL文件中没有可导入的配置信息"; return; } #endregion #region 创建显示内容 CheckItemCollection loopItems = new CheckItemCollection(); CheckItemCollection otherItems = new CheckItemCollection(); int rowIndex = 0; int columnIndex = 0; const int MAX_COLUMN = 8; if (controller != null) { foreach (var loop in controller.Loops) { // List<DeviceInfo8001> lstDevices = loop.GetDevices<DeviceInfo8001>(); //foreach (var device in lstDevices) //{ CheckItem item = new CheckItem(); item.Value = loop.Name; item.RowIndex = rowIndex; item.ColumnIndex = columnIndex; loopItems.Add(item); columnIndex++; if (columnIndex == (MAX_COLUMN)) { columnIndex = 0; rowIndex++; } //} } LoopNameCollection = loopItems; if (controller.StandardConfig.Count > 0) { CheckItem item = new CheckItem(); FieldInfo fi = ControllerNodeType.Standard.GetType().GetField(ControllerNodeType.Standard.ToString()); if (fi != null) { var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); item.Value = ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description)) ? attributes[0].Description : ControllerNodeType.Standard.ToString()); } otherItems.Add(item); } if (controller.MixedConfig.Count > 0) { CheckItem item = new CheckItem(); FieldInfo fi = ControllerNodeType.Mixed.GetType().GetField(ControllerNodeType.Mixed.ToString()); if (fi != null) { var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); item.Value = ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description)) ? attributes[0].Description : ControllerNodeType.Mixed.ToString()); } otherItems.Add(item); } if (controller.GeneralConfig.Count > 0) { CheckItem item = new CheckItem(); FieldInfo fi = ControllerNodeType.General.GetType().GetField(ControllerNodeType.General.ToString()); if (fi != null) { var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); item.Value = ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description)) ? attributes[0].Description : ControllerNodeType.General.ToString()); } otherItems.Add(item); } if (controller.ControlBoard.Count > 0) { CheckItem item = new CheckItem(); FieldInfo fi = ControllerNodeType.Board.GetType().GetField(ControllerNodeType.Board.ToString()); if (fi != null) { var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); item.Value = ((attributes.Length > 0) && (!String.IsNullOrEmpty(attributes[0].Description)) ? attributes[0].Description : ControllerNodeType.Board.ToString()); } otherItems.Add(item); } OtherSettingsCollection = otherItems; } #endregion }