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

📄 templatetransform.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
                            {
                                item.IsMainPage = true;
                            }
                            tempLabelPageList.Add(item);
                        }
                    }
                }
            }
            else
            {
                templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(getLabel, "[err:数据源标签" + getLabel.Replace("{", string.Empty).Replace("}", string.Empty) + "错,原因:请指定ID]");
            }
        }

        private static string FieldProc(string templateStr, string dataSourceid, XmlElement inode, int proctype, bool isDynamicPage)
        {
            XmlDocument document = new XmlDocument();
            string pattern = @"{PE\.Field([\s\S](?!{PE))*?\/}";
            foreach (Match match in Regex.Matches(templateStr, pattern, RegexOptions.IgnoreCase))
            {
                XmlElement firstChild;
                try
                {
                    document.LoadXml(match.Value.Replace("{", "<").Replace("}", ">"));
                    firstChild = (XmlElement) document.FirstChild;
                }
                catch (XmlException exception)
                {
                    templateStr = templateStr.Replace(match.Value, "[err:数据字段标签" + match.Value.Replace("{", string.Empty).Replace("}", string.Empty) + "错,原因:" + exception.Message + "]");
                    continue;
                }
                if ((proctype == 1) || (string.Compare(dataSourceid, XmlManage.GetAttributesValue(firstChild, "id"), true) == 0))
                {
                    if (firstChild.HasAttribute("fieldname"))
                    {
                        string xpath = string.Empty;
                        if (proctype == 1)
                        {
                            xpath = firstChild.GetAttribute("fieldname");
                        }
                        else
                        {
                            xpath = "//" + firstChild.GetAttribute("fieldname");
                        }
                        string str = (inode.SelectSingleNode(xpath) == null) ? string.Empty : inode.SelectSingleNode(xpath).InnerText;
                        if (DataConverter.CBool(XmlManage.GetAttributesValue(firstChild, "htmldecode")))
                        {
                            str = DataSecurity.HtmlDecode(str);
                        }
                        if (DataConverter.CLng(XmlManage.GetAttributesValue(firstChild, "length")) > 0)
                        {
                            str = StringHelper.SubString(str, DataConverter.CLng(XmlManage.GetAttributesValue(firstChild, "length")), "");
                        }
                        if (DataConverter.CBool(XmlManage.GetAttributesValue(firstChild, "charge")) && isDynamicPage)
                        {
                            ChargeManage manage = new ChargeManage();
                            if (manage.CheckPermission())
                            {
                                manage.ExecuteContentCharge();
                            }
                            if (!string.IsNullOrEmpty(manage.ErrMsg))
                            {
                                if (DataConverter.CBool(XmlManage.GetAttributesValue(firstChild, "showerr")))
                                {
                                    str = manage.ErrMsg;
                                }
                                else
                                {
                                    str = "";
                                }
                            }
                        }
                        templateStr = templateStr.Replace(match.Value, str);
                        continue;
                    }
                    templateStr = templateStr.Replace(match.Value, string.Empty);
                }
            }
            return templateStr;
        }

        private static void FiltPage(TemplateInfo templateInfo)
        {
            XmlDocument document = new XmlDocument();
            string pattern = @"{PE\.Page([\s\S](?!{PE))*?\/}";
            foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase))
            {
                try
                {
                    document.LoadXml(FormatLabel(match.Value));
                }
                catch (XmlException exception)
                {
                    templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.ToString(), "[err:分页标签" + match.Value.Replace("{", string.Empty).Replace("/}", string.Empty) + "错,原因:" + exception.Message + "]");
                    continue;
                }
                XmlElement firstChild = (XmlElement) document.FirstChild;
                foreach (PageInfo info in tempLabelPageList)
                {
                    string str2;
                    if (string.Compare(info.SpanName, XmlManage.GetAttributesValue(firstChild, "datasource"), true) != 0)
                    {
                        continue;
                    }
                    if (templateInfo.PageType == 1)
                    {
                        str2 = LabelTransform.GetListPage(XmlManage.GetAttributesValue(firstChild, "id"), info, XmlManage.GetAttributesValue(firstChild, "unitname"));
                    }
                    else
                    {
                        str2 = LabelTransform.GetPage(XmlManage.GetAttributesValue(firstChild, "id"), info, XmlManage.GetAttributesValue(firstChild, "unitname"));
                    }
                    string attributesValue = XmlManage.GetAttributesValue(firstChild, "span");
                    string str4 = XmlManage.GetAttributesValue(firstChild, "class");
                    if (!string.IsNullOrEmpty(attributesValue))
                    {
                        string str5 = "<" + attributesValue + " id=\"pe100_page_" + info.SpanName + "\"";
                        if (!string.IsNullOrEmpty(str4))
                        {
                            str5 = str5 + " class=\"" + str4 + "\"";
                        }
                        str5 = str5 + ">";
                        str2 = str5 + str2 + "</" + attributesValue + ">";
                    }
                    templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, str2);
                    if ((info.PageNum > 0) && info.IsMainPage)
                    {
                        templateInfo.PageNum = info.PageNum;
                        templateInfo.TotalPub = info.TotalPub;
                    }
                }
                templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, string.Empty);
            }
        }

        private static void FiltPageContent(TemplateInfo templateInfo)
        {
            string pattern = @"{PE\.ContentPage(.*)}(([\s\S](?!{PE\.ContentPage))*?){\/PE.ContentPage}";
            foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase))
            {
                XmlElement firstChild;
                XmlDocument document = new XmlDocument();
                try
                {
                    document.LoadXml("<root " + match.Groups[1].Value + " />");
                    firstChild = (XmlElement) document.FirstChild;
                }
                catch (XmlException exception)
                {
                    templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.ToString(), "[err:内容分页标签" + match.Groups[1].Value + "错,原因:" + exception.Message + "]");
                    continue;
                }
                string attributesValue = XmlManage.GetAttributesValue(firstChild, "id");
                bool flag = DataConverter.CBool(XmlManage.GetAttributesValue(firstChild, "urlpage"));
                if (!string.IsNullOrEmpty(attributesValue))
                {
                    attributesValue = attributesValue.ToLower().Trim();
                    ContentPageInfo contentPageInfo = new ContentPageInfo();
                    contentPageInfo.Parameter = "<root " + match.Groups[1].Value + " />";
                    contentPageInfo.Content = match.Groups[2].Value;
                    contentPageInfo.PageName = templateInfo.PageName;
                    if (flag)
                    {
                        contentPageInfo.CurrentPage = templateInfo.CurrentPage;
                    }
                    else
                    {
                        contentPageInfo.CurrentPage = 1;
                    }
                    contentPageInfo.IsDynamicPage = templateInfo.IsDynamicPage;
                    LabelTransform.TransContentPageLabel(contentPageInfo);
                    templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, contentPageInfo.Content);
                    PageInfo item = new PageInfo();
                    item.PageName = templateInfo.PageName;
                    item.SpanName = attributesValue;
                    item.IsDynamicPage = templateInfo.IsDynamicPage;
                    item.CurrentPage = contentPageInfo.CurrentPage;
                    if (flag)
                    {
                        item.IsMainPage = true;
                    }
                    item.PageNum = contentPageInfo.PageNum;
                    item.TotalPub = contentPageInfo.Content.Length;
                    string str3 = @"\<PageSet\>([\s\S]*?)\<\/PageSet\>";
                    foreach (Match match2 in Regex.Matches(match.Groups[2].Value, str3, RegexOptions.IgnoreCase))
                    {
                        item.PageOtherSet = match2.ToString();
                        templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match2.Value, string.Empty);
                    }
                    tempLabelPageList.Add(item);
                }
            }
        }

        private static string FormatLabel(string ilabelstr)
        {
            return ilabelstr.Replace("/n", string.Empty).Replace("{", "<").Replace("}", ">");
        }

        public static TemplateInfo GetHtml(TemplateInfo templateInfo)
        {
            if (!string.IsNullOrEmpty(templateInfo.TemplateContent))
            {
                bool flag = false;
                string pattern = @"{PE\.Label([\s\S](?!{PE))*?\/}";
                string str2 = @"{PE\.DataSource([\s\S](?!{PE))*?\/}";
                tempLabelPageList = new List<PageInfo>();
                do
                {
                    flag = false;
                    SystemLabeTransform(templateInfo, templateInfo.QueryList);
                    foreach (Match match in Regex.Matches(templateInfo.TemplateContent, str2, RegexOptions.IgnoreCase))
                    {
                        DatasourceLabelProc(match.Value, templateInfo);
                    }
                    foreach (Match match2 in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase))
                    {
                        ContentLabelProc(match2.Value, templateInfo);
                        flag = true;
                    }
                }
                while (flag);
                FiltPageContent(templateInfo);
                FiltPage(templateInfo);
                Charge(templateInfo);
            }
            return templateInfo;
        }

        private static void SystemLabeTransform(TemplateInfo templateInfo, NameValueCollection queryList)
        {
            for (int i = 0; i < queryList.Count; i++)
            {
                templateInfo.TemplateContent = templateInfo.TemplateContent.Replace("@Request_" + queryList.GetKey(i), DataSecurity.FilterBadChar(queryList.Get(i)));
            }
            string pattern = @"{PE\.SiteConfig\.(([\s\S](?!{PE))*?)\/}";
            foreach (Match match in Regex.Matches(templateInfo.TemplateContent, pattern, RegexOptions.IgnoreCase))
            {
                if (match.Groups.Count > 1)
                {
                    string siteConfigLabel = LabelTransform.GetSiteConfigLabel(match.Groups[1].Value.Trim().ToLower());
                    templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, siteConfigLabel);
                    continue;
                }
                templateInfo.TemplateContent = templateInfo.TemplateContent.Replace(match.Value, "[err:系统标签'" + match.Value.Replace("{", string.Empty).Replace("}", string.Empty) + "'错误!]");
            }
        }
    }
}

⌨️ 快捷键说明

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