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

📄 managecategory.aspx.cs

📁 ASP.NET多线程编程(二),ASP.NET多线程编程(二) .
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Zeroone.FileSystem;
using Zeroone;
using Zeroone.Custom;
using Zeroone.IndexEngine;
using Zeroone.Framework.Jobs;
using System.Xml;

public partial class Admin_ManageCategory : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string path = Path.CheckRepairPath(Request.QueryString["path"]);
            string dataProviderAction = string.IsNullOrEmpty(Request.QueryString["action"]) ? "insert" : Request.QueryString["action"];

            if (dataProviderAction.ToLower() == "update")
            {
                Category category = null;
                category = CategoryController.GetCategory(path);
                this.tbName.Text = category.Name;
                this.tbPath.Text = category.Path;
                this.btnManageCategory.Text = "更新";
            }
            else if (dataProviderAction.ToLower() == "delete")
            {
                CategoryController.Delete(path);

                //删除该栏目下的评论和分页
                string pagePath = CategoryController.SystemPagesPath + path.Substring(1);
                string commentPath = CategoryController.SystemCommentPath + path.Substring(1);
                //string auditPath = CategoryController.SystemAuditPath + path.Substring(1);
                if (CategoryController.Exists(pagePath))
                {
                    CategoryController.Delete(pagePath);
                }
                if (CategoryController.Exists(commentPath))
                {
                    CategoryController.Delete(commentPath);
                }
                //if (CategoryController.Exists(auditPath))
                //{
                //    CategoryController.Delete(auditPath);
                //}
                //----------------------------------------------


                //-----------维护索引---------------------
                JobsConfiguration jobsConfig = JobsConfiguration.GetJobsConfiguration();
                foreach (XmlNode jobNode in jobsConfig.JobsList)
                {
                    if (jobNode.NodeType != XmlNodeType.Comment)
                    {
                        XmlAttribute pathAttribute = jobNode.Attributes["path"];
                        if (pathAttribute != null)
                        {
                            string indexCategoryPath = jobNode.Attributes["path"].Value;
                            if (path.StartsWith(indexCategoryPath))
                            {
                                Search.Delete(indexCategoryPath, path);
                            }
                        }
                    }
                }
                //------------------------------------

                Response.Redirect(Globals.ApplicationPath + "/admin" + Path.GetParentPath(path) + "CategoriesList.aspx");

            }
            else
            {
                tbPath.Text = path + "栏目路径名称";
                this.btnManageCategory.Text = "添加";
            }
            customPropertyValues.Path = path;
        }
    }
    protected void btnManageCategory_Click(object sender, EventArgs e)
    {
        string path = Path.CheckRepairPath(Request.QueryString["path"]);
        string dataProviderAction = string.IsNullOrEmpty(Request.QueryString["action"]) ? "insert" : Request.QueryString["action"];
        Category c = null;
        if (dataProviderAction.ToLower() == "update")
        {
            //更新
            c = CategoryController.GetCategory(path);
            c.Name = tbName.Text;
            c.Path = tbPath.Text;
            c.SetPropertyValues(customPropertyValues.Values);
            c.Update();

            //更新该栏目下的评论和分页、删除原栏目下索引文档
            if (c.Path != path)
            {
                string oldPagePath = CategoryController.SystemPagesPath + path.Substring(1);
                string oldCommentPath = CategoryController.SystemCommentPath + path.Substring(1);
                //string oldAuditPath = CategoryController.SystemAuditPath + path.Substring(1);
                string pagePath = CategoryController.SystemPagesPath + c.Path.Substring(1);
                string commentPath = CategoryController.SystemCommentPath + c.Path.Substring(1);
                //string auditPath = CategoryController.SystemAuditPath + c.Path.Substring(1);
                if (CategoryController.Exists(oldPagePath))
                {
                    Category pageCategory = CategoryController.GetCategory(oldPagePath);
                    pageCategory.Path = pagePath;
                    pageCategory.Update();
                }
                if (CategoryController.Exists(oldCommentPath))
                {
                    Category commentCategory = CategoryController.GetCategory(oldCommentPath);
                    commentCategory.Path = commentPath;
                    commentCategory.Update();
                }
                //if (CategoryController.Exists(oldAuditPath))
                //{
                //    Category auditCategory = CategoryController.GetCategory(oldAuditPath);
                //    auditCategory.Path = auditPath;
                //    auditCategory.Update();
                //}

                //-----------维护索引---------------------
                JobsConfiguration jobsConfig = JobsConfiguration.GetJobsConfiguration();
                foreach (XmlNode jobNode in jobsConfig.JobsList)
                {
                    if (jobNode.NodeType != XmlNodeType.Comment)
                    {
                        XmlAttribute pathAttribute = jobNode.Attributes["path"];
                        if (pathAttribute != null)
                        {
                            string indexCategoryPath = jobNode.Attributes["path"].Value;
                            //如果原栏目是需要索引的栏目,则把原栏目索引下的文档删除
                            if (path.StartsWith(indexCategoryPath))
                            {
                                Search.Delete(indexCategoryPath, path);
                            }

                            //如果目标栏目是需要索引的栏目,则把目标索引删除,让系统重新索引
                            if (c.Path.StartsWith(indexCategoryPath))
                            {
                                try
                                {
                                    SearchLock.AquireWriter(30);
                                    string directory = HttpRuntime.AppDomainAppPath + "zeroone_searchIndexFile" + indexCategoryPath + "indexFiles";
                                    string[] files = System.IO.Directory.GetFiles(directory);
                                    for (int i = 0; i < files.Length; i++)
                                    {
                                        System.IO.File.Delete(files[i]);
                                    }
                                }
                                finally
                                {
                                    SearchLock.ReleaseWriter();
                                }
                            }
                        }
                    }
                }
                //------------------------------------
            }
        }
        else if (dataProviderAction.ToLower() == "insert")
        {
            c = new Category();
            c.Name = tbName.Text;
            c.Path = tbPath.Text;
            c.SetPropertyValues(customPropertyValues.Values);
            c.Create();
        }

        Response.Redirect(Globals.ApplicationPath + "/admin" + Path.GetParentPath(c.Path) + "CategoriesList.aspx");
    }
    protected void lbtnCancel_Click(object sender, EventArgs e)
    {
        string path = Request.QueryString["path"];
        Response.Redirect(Globals.ApplicationPath + "/admin" + path + "CategoriesList.aspx");
    }
}

⌨️ 快捷键说明

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