コード例 #1
0
ファイル: DocMaster.cs プロジェクト: xiaopohou/BuildDoc
        /// <summary>
        /// 合成母版和构健
        /// </summary>
        /// <param name="structureInfoList">构建列表</param>
        private void UnionDoc(List<IDocStructure> structureInfoList)
        {
            if (this.buildWord == null)
            {
                bool firstStructure = true;
                this.buildWord = new BuildWord();
                foreach (var structureInfoItem in structureInfoList)
                {
                    var stream = structureInfoItem.BuildDoc();
                    if (stream != null)
                    {
                        if (firstStructure)
                        {
                            this.buildWord.SetStream(stream);
                            this.buildWord.CreateBookmark("MergeDoc");
                            firstStructure = false;
                        }
                        else
                        {
                            this.buildWord.InsertDoc("MergeDoc", stream, structureInfoItem.NewSection);
                        }

                        //this.GetTextLabelValue(dict, structureInfoItem);
                    }
                }
            }
            else
            {
                this.buildWord.CreateBookmark("MergeDoc");
                foreach (var structureInfoItem in structureInfoList)
                {
                    this.buildWord.InsertDoc("MergeDoc", structureInfoItem.BuildDoc(), structureInfoItem.NewSection);
                    //this.GetTextLabelValue(dict, structureInfoItem);
                }
            }

            // 替换页眉页脚
            var dict = new Dictionary<string, string>();
            var inside = this.LabelList.Where(t => !t.RelateValue.Contains('@')).ToList();
            inside.ForEach(item =>
            {
                if (item is TextLabel && item.LabelName != null && !dict.ContainsKey(item.LabelName))
                {
                    var label = item as TextLabel;
                    dict.Add(label.LabelName, label.GetValue());
                }
            });
            this.buildWord.SetPageHeaderFooter(dict);
        }
コード例 #2
0
ファイル: ConditionLabel.cs プロジェクト: xiaopohou/BuildDoc
        /// <summary>
        /// 执行操作
        /// </summary>
        /// <param name="buildWord">文档操作类</param>
        public override void Execute(IBuildWord buildWord)
        {
            if (this.baseLabel == null)
            {
                this.baseLabel = this.ConditionJudgment();
            }

            if (this.baseLabel != null)
            {
                this.baseLabel.Execute(buildWord);
            }
            else
            {
                buildWord.InsertText(this.LabelName, string.Empty);
            }
        }
コード例 #3
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="mergerInstanceDocumentID">实例文档ID</param>
        /// <param name="instanceDocumentIDList">实例文档ID列表</param>
        /// <param name="objectIDList">对象ID列表</param>
        public DocMerger(decimal mergerInstanceDocumentID, List <decimal> instanceDocumentIDList, List <decimal> objectIDList)
        {
            this.buildWord = new BuildWord();

            this.instanceDocumentIDList = instanceDocumentIDList;
            this.objectIDList           = objectIDList;

            InstanceDocumentDTO docInstance = BuildWordInstance.GetInstanceDocument(mergerInstanceDocumentID);

            if (docInstance != null)
            {
                JArray ary = JArray.Parse(docInstance.DOCUMENT_STRUCTURE);
                foreach (var ja in ary)
                {
                    this.orderList.Add(new MergerItem()
                    {
                        InstanceDocumentID = ja["InstanceId"].Value <decimal>(),
                        Key = ja["Key"].Value <decimal>()
                    });
                }
            }
        }
コード例 #4
0
ファイル: DocStructure.cs プロジェクト: xiaopohou/BuildDoc
        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>());
             */
        }
コード例 #5
0
 /// <summary>
 /// 执行操作
 /// </summary>
 /// <param name="buildWord">文档操作类</param>
 public override void Execute(IBuildWord buildWord)
 {
     buildWord.InsertDoc(this.LabelName, this.GetStream(), false);
 }
コード例 #6
0
 /// <summary>
 /// 执行
 /// </summary>
 /// <param name="buildWord">文档操作类</param>
 public override void Execute(IBuildWord buildWord)
 {
     buildWord.InsertText(this.LabelName, this.GetValue());
 }
コード例 #7
0
        /// <summary>
        /// 执行操作
        /// </summary>
        /// <param name="buildWord">文档操作类</param>
        public override void Execute(IBuildWord buildWord)
        {
            var fileIds = this.GetRows();

            buildWord.InsertImage(this.LabelName, fileIds);
        }
コード例 #8
0
ファイル: TableLabel.cs プロジェクト: xiaopohou/BuildDoc
 /// <summary>
 /// 执行
 /// </summary>
 /// <param name="buildWord">文档操作类</param>
 public override void Execute(IBuildWord buildWord)
 {
     buildWord.InsertTable(this.LabelName, this.GetRows(), this.fillType);
 }
コード例 #9
0
ファイル: BaseLabel.cs プロジェクト: xiaopohou/BuildDoc
 /// <summary>
 /// 执行
 /// </summary>
 /// <param name="buildWord">文档操作类</param>
 public abstract void Execute(IBuildWord buildWord);
コード例 #10
0
ファイル: DocMaster.cs プロジェクト: xiaopohou/BuildDoc
        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="jsonStructure">构件结构</param>
        /// <param name="inputParams">输入参数</param>
        private void InitData(string jsonStructure, Dictionary<string, string> inputParams)
        {
            try
            {
                MotherSetDTO motherSet = BuildWordInstance.GetMotherSet((int)this.masterID);
                if (motherSet != null)
                {
                    Dictionary<BlockType, List<Structure>> structureCofing;
                    this.FileID = motherSet.FILE_ID.Value;
                    this.DocTemplateType = new DocTemplateType(motherSet.TEMPLATE_TYPE.Value, this.InstanceID, inputParams);
                    var fileStream = FileServerHelper.GetFileStream(motherSet.FILE_ID.Value);
                    if (fileStream != null)
                        this.buildWord = new BuildWord(fileStream);
                    if (jsonStructure == null)
                    {
                        structureCofing = this.GetStructureDictionary(motherSet.SET_CONTENT);
                    }
                    else
                    {
                        structureCofing = this.GetStructureDictionary(jsonStructure);
                    }
                    //获取构建信息
                    this.StructureInfoList = this.GetStructureInfoList(structureCofing);
                }

                //处理返回结果
                if (!string.IsNullOrEmpty(this.resultJson))
                {
                    JArray ary = JArray.Parse(this.resultJson);
                    decimal id;
                    StructureType type;
                    foreach (var v in ary)
                    {
                        id = v["ID"].Value<decimal>();
                        type = (StructureType)Enum.Parse(typeof(StructureType), v["StructureType"].Value<string>());

                        if (!this.InputValue.ContainsKey(v["LabelName"].Value<string>()))
                        {
                            this.InputValue.Add(v["LabelName"].Value<string>(), v["Value"].Value<string>());
                        }
                    }
                }

                // 应用替换值
                if (this.InputValue != null && this.InputValue.Count > 0)
                {
                    this.LabelList.ForEach(label =>
                    {
                        if (label is TextLabel)
                        {
                            var textLabel = label as TextLabel;
                            var input = this.InputValue.FirstOrDefault(t => t.Key == label.LabelName);
                            if (!string.IsNullOrEmpty(input.Key))
                            {
                                textLabel.IsInput = true;
                                textLabel.Value = input.Value;
                            }
                        }
                    });
                }

                //处理条件标签
                // 1.这种判断有误,当条件标签的条件没有@标签的时候,内容不会被替换
                // 2.条件标签应该都算outside  modify by huzy 2016.4.5
                var inside = this.LabelList.Where(t => !t.RelateValue.Contains('@')).ToList();
                var outside = this.LabelList.Where(t => t.RelateValue.Contains('@')).ToList();
                var conditionS = this.LabelList.Where(t => t is ConditionLabel).ToList();
                foreach (var c in conditionS)
                {
                    inside.Remove(c);
                    if (!outside.Contains(c))
                        outside.Add(c);
                }

                var tmpList = new List<BaseLabel>();
                while (true)
                {
                    bool isBreak = true;
                    foreach (var oItem in outside)
                    {                        
                        foreach (var iItem in inside)
                        {
                            if (oItem.RelateValue.IndexOf(iItem.LabelName) > 0)
                            {
                                if (iItem is TextLabel)
                                {
                                    var textLabel = iItem as TextLabel;
                                    //var value = string.IsNullOrEmpty(textLabel.RelateValue) ? textLabel.GetValue() : textLabel.RelateValue;

                                    var value = textLabel.GetValue();
                                    if (!textLabel.IsAfterCompute)
                                        value = textLabel.InnerValue;

                                    bool pass = oItem.Replace(iItem.LabelName, value);
                                    if (!tmpList.Contains(oItem) && pass)
                                        tmpList.Add(oItem);
                                    if (isBreak && pass)
                                        isBreak = false;
                                }
                                else if (iItem is ConditionLabel) //条件引用条件标签
                                {
                                    var conditionLabel = iItem as ConditionLabel;
                                    BaseLabel baseLabel = conditionLabel.ConditionJudgment();
                                    if (baseLabel is TextLabel)
                                    {
                                        var textLabel = baseLabel as TextLabel;
                                        var value = textLabel.GetValue();
                                        bool pass = oItem.Replace(iItem.LabelName, value);
                                        if (!tmpList.Contains(oItem) && pass)
                                            tmpList.Add(oItem);
                                        if (isBreak && pass)
                                            isBreak = false;
                                    }
                                }
                            }
                        }
                    }
                    foreach (var item in tmpList)
                    {
                        inside.Add(item);
                        outside.Remove(item);
                    }
                    tmpList.Clear();
                    if (isBreak)
                        break;
                }

                //处理构建里无匹配的标签  匹配常量中的书名号《》
                this.LabelList.ForEach(label =>
                {
                    if (label is ConditionLabel)
                    {
                        var cl = label as ConditionLabel;
                        cl.LabelList.ForEach(l =>
                        {
                            string key = DocHelper.PatternString(l.Condition);
                            var findLable = inside.FirstOrDefault(i => i.LabelName == key);
                            if (findLable != null && findLable is TextLabel)
                            {
                                try
                                {
                                    var textLabel = findLable as TextLabel;
                                    var value = string.IsNullOrEmpty(textLabel.RelateValue) ? textLabel.GetValue() : textLabel.RelateValue;
                                    l.Condition = l.Condition.Replace("@" + key, value);
                                }
                                catch { }
                            }
                            if (DocHelper.CalcByJs(l.Condition) && l.BaseLabel is TextLabel)
                            {
                                var tl = l.BaseLabel as TextLabel;
                                tl.ReplaceWithConst(inside);
                            }
                        });
                    }

                    if (label is TextLabel)
                    {
                        var tl = label as TextLabel;
                        tl.ReplaceWithConst(inside);
                    }
                });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }