/// <summary> /// 初始化 /// </summary> /// <param name="dataLabelName">数据标签名称</param> /// <param name="docMaster">文档主类</param> /// <param name="structureID">构件ID</param> /// <param name="customerID">客户ID</param> public DataLabel(string dataLabelName, DocMaster docMaster, decimal structureID, decimal customerID) { this.structureID = structureID; this.customerID = customerID; // 没有缓存从数据库取出内容 //string key = string.Format("{0}_{1}", dataSourctName, dataLabelName); //if (!CacheData.ContainsKey(key)) //{ DataLabelModel label = BuildWordInstance.GetLabel((int)customerID, dataLabelName); if (label != null) { JObject config = JObject.Parse(label.CONFIG_CONTENT); if (config["LabelType"].Value <string>() == "TextLabel") { this.DataLabelName = config["LabelName"].Value <string>(); this.textLabel = new TextLabel(this.DataLabelName, config, docMaster, this.structureID); // 添加到缓存 // CacheData.Add(key, this); this.DocControl = this.textLabel.DocControl; } } //} }
/// <summary> /// 初始化 /// </summary> /// <param name="labelName">标签名称</param> /// <param name="labelConfig">配置信息</param> /// <param name="docMaster">文档主类</param> /// <param name="structureID">构件ID</param> public TextLabel(string labelName, JToken labelConfig, DocMaster docMaster, decimal structureID) { this.IsInput = false; this.LabelName = labelName; this.docMaster = docMaster; this.structureID = structureID; JObject config = (JObject)labelConfig["Config"]; string formatString = string.Empty; string formatType = string.Empty; GetDataMethod = (GetDataMethod)Enum.Parse(typeof(GetDataMethod), config["GetDataMethod"].Value <string>()); this.Value = string.Empty; if (GetDataMethod == GetDataMethod.Const || GetDataMethod == GetDataMethod.Formula) { this.InnerValue = this.ConfigValue = config["Value"].Value <string>(); this.dataSource = null; this.FieldName = string.Empty; this.FormatInfo = null; } else if (GetDataMethod == GetDataMethod.Source) { this.DataSourceName = config["DataSourceName"].Value <string>(); this.dataSource = docMaster.DocTemplateType.DataSourceList.FirstOrDefault(t => t.DataSourceName == this.DataSourceName); this.FieldName = config["FieldName"].Value <string>(); this.FilterFieldName = config["FilterFieldName"].Value <string>(); this.FilterOperation = config["FilterOperation"].Value <string>(); this.FilterValue = config["FilterValue"].Value <string>(); } else if (GetDataMethod == GetDataMethod.Dynamic) { this.formType = config["FormType"].Value <int>(); this.fieldID = config["FieldID"].Value <string>(); } else if (GetDataMethod == GetDataMethod.MultiSource) { this.tableID = config["TableID"].Value <string>(); this.fieldID = config["FieldID"].Value <string>(); } if (config["FormatInfo"] != null) { FormatInfo = new FormatInfo(config["FormatInfo"], docMaster.DocTemplateType); } // 控件配置 if (labelConfig["Relate"] != null) { string relate = labelConfig["Relate"].ToString(); if (!string.IsNullOrEmpty(relate)) { this.Relate = JsonTools.JsonToObject2 <List <RelateItem> >(relate); } } this.DocControl = this.CreateControl(labelName, labelConfig, docMaster.DocTemplateType); }
/// <summary> /// 初始化 /// </summary> /// <param name="blockType">文档块</param> /// <param name="fileID">文件ID</param> /// <param name="docMaster">文档主类</param> /// <param name="structureID">构件ID</param> /// <param name="structureName">构件名称</param> /// <param name="customerID">客户ID</param> public CustomDocStructure(BlockType blockType, decimal fileID, DocMaster docMaster, decimal structureID, string structureName) { try { this.BlockType = blockType; this.FileID = fileID; this.docMaster = docMaster; this.StructureName = structureName; this.structureID = structureID; //this.customerID = customerID; this.NewSection = false; //this.buildWord = new BuildWord(FileHelper.GetFileStream(this.FileID)); //this.LabelList = this.GetLabelList(); } catch { throw new Exception("自定义构件'" + structureName + "'出错"); } }
/// <summary> /// 初始化 /// </summary> /// <param name="labelName">标签名称</param> /// <param name="labelConfig">配置信息</param> /// <param name="docTemplateType">模板类型</param> public DocLabel(string labelName, JToken labelConfig, DocMaster docMaster) { this.docMaster = docMaster; 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 = this.docMaster.DocTemplateType.DataSourceList.FirstOrDefault(t => t.DataSourceName == dataSourceName); } if (config["DocName"] != null) { this.docName = config["DocName"].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> /// <returns>文档流</returns> public Stream BuildDoc() { for (var i = 0; i < this.instanceDocumentIDList.Count; i++) { DocMaster docMaster = new DocMaster(this.instanceDocumentIDList[i], this.objectIDList[i], true); foreach (var structureItem in docMaster.StructureInfoList) { var findItem = this.orderList.Find(it => it.InstanceDocumentID == this.instanceDocumentIDList[i] && it.Key == structureItem.GetID); if (findItem != null) { findItem.NewSection = structureItem.NewSection; findItem.StructureStream = structureItem.BuildDoc(); } } } bool firstStructure = true; // 合并文档 foreach (var mergerItem in this.orderList) { if (mergerItem.StructureStream != null) { if (firstStructure) { this.buildWord.SetStream(mergerItem.StructureStream); this.buildWord.CreateBookmark("MergeDoc"); firstStructure = false; } else { this.buildWord.InsertDoc("MergeDoc", mergerItem.StructureStream, mergerItem.NewSection); } } } this.buildWord.DelBookmarks(); this.buildWord.UpdateFields(); var docStream = this.buildWord.GetStream(); docStream.Position = 0; return(docStream); }
/// <summary> /// 初始化 /// </summary> /// <param name="labelName">标签名称</param> /// <param name="labelConfig">配置信息</param> /// <param name="docMaster">文档主类</param> /// <param name="structureID">构件ID</param> public ConditionLabel(string labelName, JToken labelConfig, DocMaster docMaster, decimal structureID) { this.LabelList = new List <ConditionItem>(); this.LabelName = labelName; this.structureID = structureID; JArray configAry = (JArray)labelConfig["Config"]; foreach (var label in configAry) { ConditionItem item = new ConditionItem(); item.Condition = label["Condition"].Value <string>(); if (label["LabelType"] != null && !string.IsNullOrEmpty(label["LabelType"].ToString())) { LabelType labelType = (LabelType)Enum.Parse(typeof(LabelType), label["LabelType"].Value <string>()); switch (labelType) { case LabelType.DocLabel: item.BaseLabel = new DocLabel(labelName, label, docMaster); break; case LabelType.ImageLabel: item.BaseLabel = new ImageLabel(labelName, label, docMaster.DocTemplateType); break; case LabelType.TableLabel: item.BaseLabel = new TableLabel(labelName, label, docMaster.DocTemplateType); break; case LabelType.TextLabel: item.BaseLabel = new TextLabel(labelName, label, docMaster, this.structureID); break; } } this.LabelList.Add(item); } }
public DocStructure(BlockType blockType, decimal structureID, DocMaster docMaster) { //根据structureID从数据库取出相关数据 //BlockType blockType, string docName, decimal fileID, string json this.BlockType = blockType; this.structureID = structureID; //this.DocName = docName; //this.FileID = fileID; //this.Json = json; this.docMaster = docMaster; string error = ""; try { var structure = BuildWordInstance.GetStructure((int)structureID); if (structure != null) { error = "构件'" + structure.STRUCTURE_NAME + "'文件不存在"; this.DocName = structure.STRUCTURE_NAME; this.FileID = structure.FILE_ID.Value; this.Json = structure.SET_CONTENT; this.NewSection = (int)structure.IS_NEW_SECTION == 1; this.buildWord = new BuildWord(FileServerHelper.GetFileStream(this.FileID)); //this.InitLabel(null); } } catch { throw new Exception(error); } /* * if (isInitLabel && this.LabelList != null && this.LabelList.Count > 0) * this.InitLabel(new Dictionary<string, string>()); */ }