void btnImport_Click(object sender, EventArgs e) { try { OpenFileDialog dialog = new OpenFileDialog(); dialog.Filter = "XML文件 (*.xml)| *.xml|All files (*.*)|*.*"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string fullName = dialog.FileName; var data = new MB.Util.Serializer.DataContractFileSerializer <List <DynamicColumnInfo> >(fullName); List <DynamicColumnInfo> list = data.Read(); if (list == null || list.Count == 0) { throw new MB.Util.APPException("读取文件失败!", Util.APPMessageType.DisplayToUser); } _DsDynamic = MB.Util.MyConvert.Instance.ConvertEntityToDataSet <DynamicColumnInfo>(list, new string[] { "Name", "Description" }); if (_DsDynamic == null || _DsDynamic.Tables.Count == 0) { throw new MB.Util.APPException(string.Format("动态列实体对象转换失败!"), Util.APPMessageType.DisplayToUser); } mergeColumnsWithDynamic(); this.gridColumn.RefreshDataSource(); } } catch (Exception ex) { MB.WinBase.ApplicationExceptionTerminate.DefaultInstance.ExceptionTerminate(ex); } }
/// <summary> /// 根据模板名称获取列配置信息 /// </summary> /// <param name="clientRuleObject"></param> /// <param name="templateName"></param> /// <returns></returns> public static List <DynamicColumnInfo> GetDynamicColumnByTemplateName(IClientRuleQueryBase clientRuleObject, string templateName) { try { string sectionName = clientRuleObject.GetType().FullName + " " + clientRuleObject.ClientLayoutAttribute.UIXmlConfigFile + " " + templateName + ".xml"; var dynamicColumn = new MB.Util.Serializer.DataContractFileSerializer <List <DynamicColumnInfo> >(GRID_FILE_PATH + sectionName); return(dynamicColumn.Read()); } catch (Exception ex) { throw new MB.Util.APPException(ex.Message, Util.APPMessageType.SysErrInfo); } }