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

📄 freelabel_addend.aspx.cs

📁 最好用的站点内容管理系统 全部源代码都有
💻 CS
字号:
//======================================================
//==     (c)2008 aspxcms inc by NeTCMS v1.0              ==
//==          Forum:bbs.aspxcms.com                   ==
//==         Website:www.aspxcms.com                  ==
//======================================================
using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class manage_label_FreeLabel_AddEnd : NetCMS.Web.UI.ManagePage
{
    public manage_label_FreeLabel_AddEnd()
    {
        Authority_Code = "T009";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        Response.CacheControl = "no-cache";

        this.LnkBtnSave.Attributes.Add("onclick", "javascript:var s = oUtil.obj.getHTMLBody().trim();if(s.length>4000){alert('标签内容不能长于4000个字符');return false;}if(s.length < 1){ alert('标签内容不能为空');return false;}");
        NetCMS.Content.FreeLabel fb = new NetCMS.Content.FreeLabel();
        this.TxtLabelName.Attributes.Add("readonly","true");
        if (!Page.IsPostBack)
        {
            if(Request.Form["TxtName"] == null || Request.Form["TxtName"].Trim().Equals(""))
                PageError("自由标签名称不能为空!","");
            if(Request.Form["TxtSql"] == null || Request.Form["TxtSql"].Trim().Equals(""))
                PageError("SQL语句不能为空!","");
            this.TxtDescrpt.Text = Request.Form["Descrpt"];
            this.EdtContent.Value = Request.Form["StyleCon"];
            string labelnm = Request.Form["TxtName"].Trim();
            int id = int.Parse(Request.Form["LID"]);
            if (id > 0)
                this.LblNavigt.Text = this.LblCaption.Text = "修改自由标签";
            this.HidName.Value = "{NT_FREE_" + labelnm + "}";
            this.HidID.Value = id.ToString();
            if(fb.IsNameRepeat(id,labelnm))
            {
                PageError("标签名称重复!", "FreeLabel_List.aspx");
            }
            this.TxtLabelName.Text = "{NT_FREE_" + labelnm + "}";
            string dbtb1 = Request.Form["SelPrin"].Trim();
            string dbtb2 = Request.Form["SelSub"].Trim();
            string StrSql = Request.Form["TxtSql"].Trim();
            this.HidSQL.Value = StrSql;
            string pattern = @"select(\s+top\s\d+)?\s+(?<fields>.+?)\s+from";

            Regex reg = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Compiled);
            Match m = reg.Match(StrSql);
            if (m.Success)
            {
                string Fields = m.Groups["fields"].Value.Trim();
                if (Fields.Equals(""))
                {
                    PageError("SQL语句无效,没有要显示的字段名!", "");
                    return;
                }
                if (Fields.IndexOf(",") > 0)
                {
                    bool single = true;
                    if (Fields.IndexOf(dbtb1) >= 0 && Fields.IndexOf(dbtb2) >= 0)
                        single = false;
                    string[] Fld = Fields.Split(',');
                    foreach (string _fld in Fld)
                    {
                        string fd = _fld.Trim();
                        ListItem it = new ListItem();
                        it.Value = "[*"+ fd +"*]";
                        it.Text = fd;
                        if (!single)
                        {
                            if (fd.IndexOf(dbtb1 +".") == 0)
                            {
                                this.DdlField1.Items.Add(it);
                            }
                            else if(fd.IndexOf(dbtb2 +".") == 0)
                            {
                                this.DdlField2.Items.Add(it);
                            }
                        }
                        else
                        {
                            this.DdlField1.Items.Add(it);
                        }
                    }
                    if (single)
                        this.DdlField2.Visible = false;
                    
                }
                else
                {
                    ListItem it = new ListItem();
                    it.Value = "[*"+ Fields +"*]";
                    it.Text = Fields;
                    this.DdlField1.Items.Add(it);
                    this.DdlField2.Visible = false;
                }
            }
            else
            {
                PageError("SQL语句非法或无效!", "");
            }
        }
    }
    protected void LnkBtnSave_Click(object sender, EventArgs e)
    {
        string sname = this.HidName.Value;
        int id = int.Parse(this.HidID.Value);
        string lblsql = this.HidSQL.Value;
        string content = this.EdtContent.Value.Trim();
        content = NetCMS.Common.Input.HtmlDecode(content);
        if (content.Equals(""))
        {
            PageError("标签内容不能为空!", "");
        }
        if (content.Length > 4000)
        {
            PageError("标签内容不能大于4000个字符!", "");
        }
        NetCMS.Model.FreeLabelInfo info = new NetCMS.Model.FreeLabelInfo(id, sname, lblsql, content, this.TxtDescrpt.Text.Trim());
        NetCMS.Content.FreeLabel fb = new NetCMS.Content.FreeLabel();
        if (id > 0)
        {
            if (fb.Update(info))
                PageRight("自由标签修改成功!", "freelabel_list.aspx");
            else
                PageError("自由标签修改失败,已存在同名称的标签!", "");
        }
        else
        {
            if (fb.Add(info))
                PageRight("自由标签添加成功!", "freelabel_list.aspx");
            else
                PageError("自由标签添加失败,已存在同名称的标签!", "");
        }
    }
}

⌨️ 快捷键说明

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