Exemple #1
0
        /// <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;
                }
            }


            //}
        }
Exemple #2
0
        // GET: Report
        public ActionResult GetMontherSet()
        {
            int customer     = 389;
            var lstMethodSet = BuildWordInstance.GetMotherSetByCustomer(customer, 40016003);;

            return(Json(lstMethodSet, JsonRequestBehavior.AllowGet));
        }
 /// <summary>
 /// 根据m_SQL,获取数据,把列和相应的值生成参数
 /// </summary>
 /// <returns>返回参数</returns>
 public Dictionary<string, string> GetParams()
 {
     Dictionary<string, string> dic = new Dictionary<string, string>();
     TemplateTypeDTO templateType = BuildWordInstance.GetTemplateType((int)this.templateTypeID);
     if (templateType != null)
     {
         this.DocTemplateTypeName = templateType.TEMPLATE_TYPE_NAME;
         this.sql = templateType.SQL_CONTENT;
         if (this.keyRegex.IsMatch(this.sql))
             this.sql = this.keyRegex.Replace(this.sql, this.instanceID.ToString());
         dic = BuildWordInstance.GetTemplateParms(this.sql);
     }
     return dic;
 }
Exemple #4
0
        /// <summary>
        /// 初始化相关变量
        /// </summary>
        /// <param name="instanceDocumentID">实例文档ID</param>
        /// <param name="objID">对象ID</param>
        public DocMaster(decimal instanceDocumentID, decimal objID, bool isBuildDoc)
        {
            this.LabelList = new List<BaseLabel>();

            var docInstance = BuildWordInstance.GetInstanceDocument(instanceDocumentID);
            
            // 根据instanceDocumentID从数据库取出相关数据 masterID instanceID resultJson jsonStructure
            if (docInstance != null)
            {
                this.IsBuildDoc = isBuildDoc;
                this.masterID = docInstance.MOTHER_SET_ID.Value;
                this.InstanceID = objID;
                this.resultJson = docInstance.MANUAL_EDITING_RETURN;
                this.InitData(docInstance.DOCUMENT_STRUCTURE, null);
            }

        }
 /// <summary>
 /// 获取数据源
 /// </summary>
 private void GetDataSourceList()
 {
     try
     {
         this.DataSourceList = new List<DataSource>();
         IList<DataSourceDTO> dataSource = BuildWordInstance.GetDataSource((int)this.templateTypeID);
         if (dataSource != null)
         {
             foreach (var ds in dataSource)
             {
                 this.DataSourceList.Add(
                     new DataSource(ds.FSQ_DB_NAME, ds.DATA_SOURCE_NAME, ds.DATA_SOURCE_NAME, false,
                         ds.SQL_CONTENT, this)
                     );
             }
         }
          
     }
     catch {
         System.Console.Write("获取数据源报错");
     }
 }
Exemple #6
0
        /// <summary>
        /// 从CacheData获取,不存在则根据SQL变量创建
        /// </summary>
        /// <returns>数据</returns>
        public DataTable GetDataTable()
        {

            DataTable dt = new DataTable();
            try
            {
                string cacheKey = string.Format("{0}_{1}", this.DBName, this.DataSourceName);
                dt = this.docTemplateType.CacheData.Tables[cacheKey];
                if (dt == null && this.sql.IndexOf("@") == -1)
                {
                    dt = BuildWordInstance.GetDataSource(this.DBName, this.sql);
                    dt.TableName = cacheKey;
                    this.docTemplateType.CacheData.Tables.Add(dt);
                }
            }
            catch
            {
                System.Console.Write(this.DataSourceName + "的数据源取值异常");
                throw;
            }

            return dt;
        }
Exemple #7
0
        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>());
             */
        }
Exemple #8
0
        /// <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;
            }
        }