Пример #1
0
        /// <summary>
        /// 将标签数据源中内容替换标签/绑定数据源
        /// </summary>
        /// <param name="dtDataSource">数据源</param>
        /// <param name="labelParseParam">标签参数</param>
        /// <param name="freeLabel">当前解析的标签</param>
        /// <returns></returns>
        private string DataSourceBind(DataTable dtDataSource, LoopLabelParseParam labelParseParam, FreeLabel freeLabel)
        {
            DataTable           dataSource;
            LoopLabelParseParam labelParam;
            string        itemContent;
            StringBuilder sbResult;

            sbResult   = new StringBuilder();
            dataSource = dtDataSource;
            labelParam = labelParseParam;

            switch (Target)  // 链接打开窗口
            {
            case LinkOpenType.Blank:
                labelParam.ItemContent = labelParam.ItemContent.Replace("{$Target}", "_blank");
                break;

            case LinkOpenType.Self:
                labelParam.ItemContent = labelParam.ItemContent.Replace("{$Target}", "_self");
                break;

            default:
                labelParam.ItemContent = labelParam.ItemContent.Replace("{$Target}", "_self");
                break;
            }

            if (dataSource != null && dataSource.Rows.Count > 0)
            {
                if (labelParam.IsLoop)  // 循环
                {
                    foreach (DataRow dr in dataSource.Rows)
                    {
                        itemContent = SingleRecordBind(dr, labelParam.LstField, labelParam.ItemContent, freeLabel.MenuDirUrl, this.FileType, this.SiteDirUrl, this.CSaveType);
                        sbResult.Append(itemContent);
                    }
                }
                else  // 单记录
                {
                    itemContent = SingleRecordBind(dataSource.Rows[0], labelParam.LstField, labelParam.ItemContent, freeLabel.MenuDirUrl, this.FileType, this.SiteDirUrl, this.CSaveType);
                    sbResult.Append(itemContent);
                }
            }

            return(sbResult.ToString());
        }
Пример #2
0
        /// <summary>
        /// 获取自由标签解析后的参数
        /// </summary>
        /// <param name="labelContent">标签内容</param>
        /// <param name="itemContentTag">ItemTemplate内容替换标签</param>
        /// <returns></returns>
        public LoopLabelParseParam GetLoopLabelParam(string labelContent, string itemContentTag)
        {
            LoopLabelParseParam resultParam;     // 解析后的参数
            Regex           loopReg;             // 匹配循环标签
            Regex           fieldReg;            // 匹配字段
            Match           loopMatch;
            MatchCollection fieldMatch;          // 字段匹配内容
            string          itemTemplateContent; // 循环体内容
            List <Field>    lstFieldParam;       // 所有字段参数
            Field           fieldParam;          // 字段参数

            loopReg       = new Regex(@"\[HQB\.Loop\](?<1>.*)\[/HQB\.Loop\]", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            fieldReg      = new Regex(@"\{\$Field\((?<1>\d),(?<2>[^,]+),(?<3>[^)]*)\)\}|\{\$Field\((?<1>\d),(?<2>[^,]+)\)\}", RegexOptions.Singleline | RegexOptions.IgnoreCase);
            resultParam   = new LoopLabelParseParam();
            lstFieldParam = new List <Field>();

            loopMatch = loopReg.Match(labelContent);

            if (loopMatch.Success)  // 循环标签
            {
                resultParam.IsLoop        = true;
                resultParam.LabelTemplate = labelContent.Replace(loopMatch.Value, itemContentTag);
                itemTemplateContent       = loopMatch.Groups[1].Value;
            }
            else
            {
                resultParam.IsLoop        = false;
                resultParam.LabelTemplate = itemContentTag;
                itemTemplateContent       = labelContent;
            }

            fieldMatch = fieldReg.Matches(itemTemplateContent);     // 匹配循环体中的所有字段

            foreach (Match matchItem in fieldMatch)
            {
                fieldParam          = GetFieldParam(matchItem.Groups[2].Value, matchItem.Groups[1].Value, matchItem.Groups[3].Value);
                itemTemplateContent = itemTemplateContent.Replace(matchItem.Value, "{[#" + fieldParam.Name + "#]}");
                lstFieldParam.Add(fieldParam);
            }

            resultParam.LstField    = lstFieldParam;
            resultParam.ItemContent = itemTemplateContent;

            return(resultParam);
        }