/// <summary> /// 初始化 /// </summary> /// <param name="dbName">数据库名称</param> /// <param name="dataSourceName">数据源名称</param> /// <param name="dataSourceCNName">数据中文名称</param> /// <param name="isMultiItem">是否多值数据</param> /// <param name="sql">SQL语句</param> /// <param name="docTemplateType">模板类型</param> public DataSource(string dbName, string dataSourceName, string dataSourceCNName, bool isMultiItem, string sql, DocTemplateType docTemplateType) { this.DBName = dbName; this.DataSourceName = dataSourceName; this.DataSourceCNName = dataSourceCNName; this.IsMultiItem = isMultiItem; this.docTemplateType = docTemplateType; this.sql = this.BuildSql(sql, this.docTemplateType.ParamsCache); }
/// <summary> /// 初始化 /// </summary> /// <param name="labelName">标签名称</param> /// <param name="labelConfig">标签配置信息</param> /// <param name="docTemplateType">模板类型</param> /// <param name="relate">关联控件</param> public DropdownWithDataSourceControl(string labelName, JToken labelConfig, DocTemplateType docTemplateType, List <RelateItem> relate) { this.docTemplateType = docTemplateType; this.relate = relate; JObject control = (JObject)labelConfig["Control"]; this.LabelName = labelName; this.FillType = BuildDoc.FillType.DataSource.ToString(); this.Required = control["Required"].Value <bool>(); this.DataSource = control["DataSource"].Value <string>(); this.ValueField = control["ValueField"].Value <string>(); this.TextField = control["TextField"].Value <string>(); this.IsMultiMode = control["IsMultiMode"].Value <bool>(); }
/// <summary> /// 界面控件 /// </summary> /// <param name="labelName">标签名称</param> /// <param name="labelConfig">配置信息</param> /// <param name="docTemplateType">模板类型</param> /// <returns>控件</returns> private BaseControl CreateControl(string labelName, JToken labelConfig, DocTemplateType docTemplateType) { JObject controlConfig = (JObject)labelConfig["Control"]; if (controlConfig == null) { return(null); } BaseControl control = null; ControlType controlType = (ControlType)Enum.Parse(typeof(ControlType), controlConfig["ControlType"].Value <string>()); switch (controlType) { case ControlType.Text: control = new TextControl(labelName, labelConfig); break; case ControlType.Date: control = new DateControl(labelName, labelConfig); break; case ControlType.Dropdown: FillType fillType = (FillType)Enum.Parse(typeof(FillType), controlConfig["FillType"].Value <string>()); if (fillType == FillType.DataSource) { control = new DropdownWithDataSourceControl(labelName, labelConfig, docTemplateType, this.Relate); } else { control = new DropdownWithCustomControl(labelName, labelConfig); } break; } if (control != null) { control.ControlType = controlType; } return(control); }
/// <summary> /// 初始化 /// </summary> /// <param name="labelName">标签名称</param> /// <param name="labelConfig">配置信息</param> /// <param name="docTemplateType">模板类型</param> public ImageLabel(string labelName, JToken labelConfig, DocTemplateType docTemplateType) { JObject config = (JObject)labelConfig["Config"]; string dataSourceName = string.Empty; this.LabelName = labelName; this.getDataMethod = (GetDataMethod)Enum.Parse(typeof(GetDataMethod), config["GetDataMethod"].Value <string>()); if (config["DataSourceName"] != null) { dataSourceName = config["DataSourceName"].Value <string>(); this.dataSource = docTemplateType.DataSourceList.FirstOrDefault(t => t.DataSourceName == dataSourceName); } if (config["ImageName"] != null) { this.imageName = config["ImageName"].Value <string>(); } if (config["FileID"] != null) { this.fileID = config["FileID"].Value <decimal>(); } if (config["FieldName"] != null) { this.fieldName = config["FieldName"].Value <string>(); } if (config["FilterFieldName"] != null) { this.filterFieldName = config["FilterFieldName"].Value <string>(); } if (config["FilterOperation"] != null) { this.filterOperation = config["FilterOperation"].Value <string>(); } if (config["FilterValue"] != null) { this.filterValue = config["FilterValue"].Value <string>(); } }
/// <summary> /// 初始化 /// </summary> /// <param name="labelName">标签名称</param> /// <param name="labelConfig">配置信息</param> /// <param name="docTemplateType">模板类型fieldName</param> public TableLabel(string labelName, JToken labelConfig, DocTemplateType docTemplateType) { JObject config = (JObject)labelConfig["Config"]; string dataSourceName = string.Empty; string fieldName = string.Empty; FormatInfo formatInfo = null; string formatString = string.Empty; string formatType = string.Empty; this.LabelName = labelName; dataSourceName = config["DataSourceName"].Value <string>(); this.dataSource = docTemplateType.DataSourceList.FirstOrDefault(t => t.DataSourceName == dataSourceName); this.filterFieldName = config["FilterFieldName"].Value <string>(); this.filterOperation = config["FilterOperation"].Value <string>(); this.filterValue = config["FilterValue"].Value <string>(); this.fillType = (TableFillType)Enum.Parse(typeof(TableFillType), config["FillType"].Value <string>()); if (config["From"] != null && !string.IsNullOrEmpty(config["From"].ToString())) { this.from = config["From"].Value <int>(); this.from--; } if (config["From"] != null && !string.IsNullOrEmpty(config["To"].ToString())) { this.to = config["To"].Value <int>(); } this.columns = new List <ColumnInfo>(); JArray cols = (JArray)config["ColumnInfo"]; int columnIndex = 0; foreach (var col in cols) { fieldName = col["FieldName"].Value <string>(); columnIndex = col["ColumnIndex"].Value <int>(); formatInfo = new FormatInfo(col["FormatInfo"], docTemplateType); this.columns.Add(new ColumnInfo(fieldName, columnIndex, formatInfo)); } }
/// <summary> /// 初始化 /// </summary> /// <param name="config">格式化信息</param> /// <param name="docTemplateType">模板类型</param> public FormatInfo(JToken config, DocTemplateType docTemplateType) { this.HasValues = config.HasValues; string formatType = string.Empty; if (!this.HasValues) { return; } if (config["FormatString"] != null) { this.formatString = config["FormatString"].Value<string>(); } if (config["FormatType"] != null) { formatType = config["FormatType"].Value<string>(); } if (!string.IsNullOrEmpty(formatType) && Enum.IsDefined(typeof(FormatType), formatType)) { this.formatType = (FormatType)Enum.Parse(typeof(FormatType), formatType); } if (config["ValueField"] != null) { this.ValueField = config["ValueField"].Value<string>(); } if (config["TextField"] != null) { this.TextField = config["TextField"].Value<string>(); } if (config["DecimalCount"] != null) { int.TryParse(config["DecimalCount"].Value<string>(), out this.decimalCount); } if (config["Dividend"] != null) { decimal.TryParse(config["Dividend"].Value<string>(), out this.dividend); } if (config["DataSourceName"] != null) { string sourceName = config["DataSourceName"].Value<string>(); this.dataSource = docTemplateType.DataSourceList.FirstOrDefault(t => t.DataSourceName == sourceName); } if (config["DateFormatString"] != null) { this.DateFormatString = config["DateFormatString"].Value<string>(); } if (config["IsUpperDate"] != null) { bool.TryParse(config["IsUpperDate"].Value<string>(), out this.isUpperDate); } if (config["IsAfterCompute"] != null) { bool.TryParse(config["IsAfterCompute"].Value<string>(), out this.isAfterCompute); } if (config["IsThousand"] != null) { bool.TryParse(config["IsThousand"].Value<string>(), out this.isThousand); } }