⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 templatetransform.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace PowerEasy.Templates
{
    using PowerEasy.Common;
    using PowerEasy.Components;
    using PowerEasy.Contents;
    using PowerEasy.Model.TemplateProc;
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Text;
    using System.Text.RegularExpressions;
    using System.Xml;

    public sealed class TemplateTransform
    {
        private static IList<PageInfo> tempLabelPageList = new List<PageInfo>();

        private TemplateTransform()
        {
        }

        private static void Charge(TemplateInfo templateInfo)
        {
            if (templateInfo.IsDynamicPage)
            {
                ChargeManage manage = new ChargeManage();
                if (manage.CheckPermission())
                {
                    manage.ExecuteContentCharge();
                }
                if (!string.IsNullOrEmpty(manage.ErrMsg))
                {
                    string pattern = @"{PE\.Charge}(([\s\S](?!{PE\.Charge))*?){\/PE.Charge}";
                    foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase))
                    {
                        templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, manage.ErrMsg);
                    }
                }
            }
            templateInfo.TemplateContent = templateInfo.TemplateContent.Replace("{PE.Charge}", string.Empty).Replace("{/PE.Charge}", string.Empty);
        }

        private static void ContentLabelProc(string OrangeStr, TemplateInfo templateInfo)
        {
            XmlDocument document = new XmlDocument();
            LabelInfo labelInfo = new LabelInfo();
            labelInfo.RootPath = templateInfo.RootPath;
            labelInfo.PageName = templateInfo.PageName;
            try
            {
                document.LoadXml(FormatLabel(OrangeStr));
                foreach (XmlAttribute attribute in document.FirstChild.Attributes)
                {
                    labelInfo.OriginalData[attribute.Name.ToLower()] = attribute.Value;
                }
            }
            catch (XmlException exception)
            {
                templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(OrangeStr, "[err:内容标签" + OrangeStr.Replace("{", string.Empty).Replace("/}", string.Empty) + "错,原因:" + exception.Message + "]");
                return;
            }
            bool flag = DataConverter.CBool(labelInfo.OriginalData["urlpage"]);
            if (flag)
            {
                labelInfo.Page = templateInfo.CurrentPage;
            }
            string key = "CK_Label_TransformCacheData_" + labelInfo.OriginalData["id"] + "_" + labelInfo.OriginalData["cacheid"];
            int seconds = DataConverter.CLng(labelInfo.OriginalData["cachetime"]);
            if ((seconds > 0) && (SiteCache.Get(key) != null))
            {
                labelInfo = (LabelInfo) SiteCache.Get(key);
            }
            else
            {
                labelInfo = LabelTransform.GetLabel(labelInfo);
                if (seconds > 0)
                {
                    SiteCache.Insert(key, labelInfo, seconds);
                }
            }
            string str2 = labelInfo.OriginalData["span"];
            string str3 = labelInfo.OriginalData["id"].ToLower().Trim();
            string str4 = labelInfo.OriginalData["class"];
            if (!string.IsNullOrEmpty(str2))
            {
                if (string.IsNullOrEmpty(str4))
                {
                    labelInfo.LabelContent.Insert(0, "<" + str2 + " id=\"pe100_" + str3 + "\">");
                }
                else
                {
                    labelInfo.LabelContent.Insert(0, "<" + str2 + " id=\"pe100_" + str3 + "\" class=\"" + str4 + "\">");
                }
                labelInfo.LabelContent.Append("</" + str2 + ">");
            }
            templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(OrangeStr, labelInfo.LabelContent.ToString());
            if (DataConverter.CBool(labelInfo.OriginalData["page"]))
            {
                PageInfo item = new PageInfo();
                item.PageName = templateInfo.PageName;
                item.SpanName = str3;
                item.IsDynamicPage = templateInfo.IsDynamicPage;
                if ((labelInfo.PageSize > 0) && (labelInfo.TotalPub > 0))
                {
                    int num2 = labelInfo.TotalPub / labelInfo.PageSize;
                    if ((labelInfo.TotalPub % labelInfo.PageSize) > 0)
                    {
                        num2++;
                    }
                    if (num2 < 1)
                    {
                        num2 = 1;
                    }
                    item.PageNum = num2;
                    item.PageSize = labelInfo.PageSize;
                    item.CurrentPage = templateInfo.CurrentPage;
                    item.TotalPub = labelInfo.TotalPub;
                    if (flag)
                    {
                        item.IsMainPage = true;
                    }
                    tempLabelPageList.Add(item);
                }
            }
        }

        private static void DatasourceLabelProc(string getLabel, TemplateInfo templateInfo)
        {
            XmlDocument document = new XmlDocument();
            string xml = getLabel.Replace("{", "<").Replace("}", ">");
            LabelInfo inLabel = new LabelInfo();
            inLabel.RootPath = templateInfo.RootPath;
            inLabel.PageName = templateInfo.PageName;
            try
            {
                document.LoadXml(xml);
                foreach (XmlAttribute attribute in document.FirstChild.Attributes)
                {
                    inLabel.OriginalData[attribute.Name.ToLower()] = attribute.Value;
                }
            }
            catch (XmlException exception)
            {
                templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, "[err:数据源标签" + getLabel.Replace("{", string.Empty).Replace("}", string.Empty) + "格式错,原因:" + exception.Message + "]");
                return;
            }
            string str2 = inLabel.OriginalData["id"];
            string str3 = inLabel.OriginalData["datasource"];
            if (!string.IsNullOrEmpty(str2))
            {
                str2 = str2.ToLower().Trim();
                if (string.IsNullOrEmpty(str3))
                {
                    templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, "[err:数据源标签" + getLabel.Replace("{", string.Empty).Replace("}", string.Empty) + "错,原因:请指定DataSource]");
                }
                else
                {
                    str3 = str3.ToLower().Trim();
                    bool flag = DataConverter.CBool(inLabel.OriginalData["urlpage"]);
                    if (flag)
                    {
                        inLabel.Page = templateInfo.CurrentPage;
                    }
                    string key = "CK_Label_TransformCacheXmlData_" + str2 + "_" + inLabel.OriginalData["cacheid"];
                    int seconds = DataConverter.CLng(inLabel.OriginalData["cachetime"]);
                    if ((seconds > 0) && (SiteCache.Get(key) != null))
                    {
                        inLabel = (LabelInfo) SiteCache.Get(key);
                    }
                    else
                    {
                        inLabel = LabelTransform.GetLabelDataTable(str3, templateInfo.CurrentPage, inLabel);
                        if (seconds > 0)
                        {
                            SiteCache.Insert(key, inLabel, seconds);
                        }
                    }
                    try
                    {
                        document.LoadXml(inLabel.LabelContent.ToString());
                    }
                    catch (XmlException exception2)
                    {
                        templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, "[err:数据源标签" + getLabel.Replace("{", string.Empty).Replace("}", string.Empty) + "返回数据错,原因:" + exception2.Message + ",源码:" + inLabel.LabelContent.ToString() + "]");
                        return;
                    }
                    templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, string.Empty);
                    string pattern = @"{PE\.Repeat(.*)}(([\s\S](?!{PE\.Repeat))*?)\{\/PE.Repeat}";
                    foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase))
                    {
                        XmlNode firstChild;
                        if (match.Groups.Count < 3)
                        {
                            templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, "[err:循环标签" + match.Value.Replace("{", string.Empty).Replace("}", string.Empty) + "格式错");
                            continue;
                        }
                        XmlDocument document2 = new XmlDocument();
                        xml = "<root " + match.Groups[1].Value + " />";
                        try
                        {
                            document2.LoadXml(xml);
                            firstChild = document2.FirstChild;
                        }
                        catch (XmlException exception3)
                        {
                            templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, "[err:循环标签{PE:Repeat " + match.Groups[1].Value + " /}错,原因:" + exception3.Message + "]");
                            continue;
                        }
                        if (string.Compare(XmlManage.GetAttributesValue(firstChild, "id"), str2, true) == 0)
                        {
                            string str6 = match.Groups[2].Value;
                            int count = DataConverter.CLng(XmlManage.GetAttributesValue(firstChild, "loop"));
                            if (count >= 0)
                            {
                                if ((count == 0) || (count > document.DocumentElement.ChildNodes.Count))
                                {
                                    count = document.DocumentElement.ChildNodes.Count;
                                }
                                StringBuilder builder = new StringBuilder();
                                for (int i = 0; i < count; i++)
                                {
                                    builder.Append(FieldProc(str6.Replace("{PE.Field.AutoId/}", i.ToString()), str2, (XmlElement) document.DocumentElement.ChildNodes[i], 1, templateInfo.IsDynamicPage));
                                }
                                templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, builder.ToString());
                                continue;
                            }
                            templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, string.Empty);
                        }
                    }
                    templateInfo.TemplateContent = FieldProc(templateInfo.TemplateContent, str2, document.DocumentElement, 0, templateInfo.IsDynamicPage);
                    if (DataConverter.CBool(inLabel.OriginalData["page"]))
                    {
                        PageInfo item = new PageInfo();
                        item.PageName = templateInfo.PageName;
                        item.SpanName = str2;
                        item.IsDynamicPage = templateInfo.IsDynamicPage;
                        if ((inLabel.PageSize > 0) && (inLabel.TotalPub > 0))
                        {
                            int num4 = inLabel.TotalPub / inLabel.PageSize;
                            if ((inLabel.TotalPub % inLabel.PageSize) > 0)
                            {
                                num4++;
                            }
                            if (num4 < 1)
                            {
                                num4 = 1;
                            }
                            item.PageNum = num4;
                            item.PageSize = inLabel.PageSize;
                            item.CurrentPage = inLabel.Page;
                            item.TotalPub = inLabel.TotalPub;
                            if (flag)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -