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

📄 templatemanage.aspx.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
namespace PowerEasy.WebSite.Admin.Template
{
    using AjaxControlToolkit;
    using PowerEasy.Common;
    using PowerEasy.Components;
    using PowerEasy.Controls;
    using PowerEasy.ExtendedControls;
    using PowerEasy.Templates;
    using PowerEasy.Web.UI;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class TemplateManage : AdminPage
    {
        protected Button BtnHiddenCopyDir;
        protected Button BtnHiddenCopyFile;
        protected Button BtnHiddenCreateDir;
        protected Button BtnHiddenDirRename;
        protected Button BtnHiddenFileRename;
        protected Button BtnMove;
        protected CheckBox ChkUpdateFileContactinformation;
        protected CheckBox ChkUpdateFolderContactinformation;
        protected string currentDirectory;
        protected DropDownList DrpMove;
        protected ExtendedButton EBtnBatchDel;
        protected ExtendedButton EBtnCopyDir;
        protected ExtendedButton EBtnCopyFile;
        protected ExtendedButton EBtnCreateTemplate;
        protected ExtendedButton EBtnDirReName;
        protected ExtendedButton EBtnFileReName;
        protected ExtendedButton EBtnNewDir;
        protected ExtendedButton EBtnTemplateReplace;
        protected ExtendedGridView EgvFiles;
        protected HiddenField HdnCopyDir;
        protected HiddenField HdnCopyFile;
        protected HiddenField HdnName;
        protected HiddenField HdnTemplateManage;
        protected HiddenField HdnType;
        protected Label LblCopyDir;
        protected Label LblCopyFile;
        protected Label LblCurrentDir;
        protected Label LblNavigation;
        protected Literal LitMessageText;
        protected Literal LitParentDirButton;
        protected Literal LitParentDirLink;
        protected string m_UrlReferrer;
        protected ModalPopupExtender MpeCopyDir;
        protected ModalPopupExtender MpeCopyFile;
        protected ModalPopupExtender MpeCreateDir;
        protected ModalPopupExtender MpeDirRename;
        protected ModalPopupExtender MpeFileRename;
        protected AspNetPager Pager;
        protected Panel PanButton;
        protected string parentDir;
        protected Panel PnlCopyDir;
        protected Panel PnlCopyFile;
        protected Panel PnlCreateDir;
        protected Panel PnlDirRename;
        protected Panel PnlFileRename;
        protected StringBuilder replaceData = new StringBuilder();
        protected StringBuilder replaceResult = new StringBuilder();
        protected StringBuilder searchResult = new StringBuilder();
        protected ExtendedSiteMapPath SmpNavigator;
        protected ScriptManager SmTemplateManage;
        protected TextBox TxtCopyDir;
        protected TextBox TxtCopyFile;
        protected TextBox TxtDirName;
        protected TextBox TxtFileName;
        protected TextBox TxtNewDir;
        protected RegularExpressionValidator ValeTxtCopyDir;
        protected RegularExpressionValidator ValeTxtCopyFile;
        protected RegularExpressionValidator ValeTxtDirName;
        protected RegularExpressionValidator ValeTxtFileName;
        protected RegularExpressionValidator ValeTxtNewDir;
        protected PowerEasy.Controls.RequiredFieldValidator ValrTxtCopyDir;
        protected PowerEasy.Controls.RequiredFieldValidator ValrTxtCopyFile;
        protected PowerEasy.Controls.RequiredFieldValidator ValrTxtDirName;
        protected PowerEasy.Controls.RequiredFieldValidator ValrTxtFileName;
        protected PowerEasy.Controls.RequiredFieldValidator ValrTxtNewDir;

        protected void BindData()
        {
            DataTable directoryInfos;
            string str4;
            if (((str4 = BasePage.RequestString("Action")) != null) && (str4 == "TemplateSearch"))
            {
                int num = BasePage.RequestInt32("DropSearch");
                string str = BasePage.RequestString("TxtSearch");
                string str2 = BasePage.RequestString("Dir");
                string str3 = SiteConfig.SiteOption.TemplateDir + str2 + "/";
                if (num == 0)
                {
                    directoryInfos = FileSystemObject.SearchTemplateFiles(base.Request.PhysicalApplicationPath + str3, str.Trim());
                }
                else
                {
                    directoryInfos = FileSystemObject.SearchFileContent(base.Request.PhysicalApplicationPath + str3, str.Trim());
                }
            }
            else
            {
                directoryInfos = FileSystemObject.GetDirectoryInfos(this.currentDirectory, FsoMethod.All);
            }
            DataView defaultView = directoryInfos.DefaultView;
            defaultView.RowFilter = "Name <> '标签库' AND Name<> '分页标签库'";
            this.Pager.RecordCount = defaultView.Count;
            int num2 = (this.Pager.CurrentPageIndex - 1) * this.Pager.PageSize;
            int num3 = num2 + this.Pager.PageSize;
            List<DataRowView> list = new List<DataRowView>();
            for (int i = num2; i < num3; i++)
            {
                if (i < defaultView.Count)
                {
                    list.Add(defaultView[i]);
                }
            }
            this.EgvFiles.DataSource = list;
            this.EgvFiles.DataBind();
        }

        protected void BtnMove_Click(object sender, EventArgs e)
        {
            if (this.EgvFiles.SelectList.Length == 0)
            {
                AdminPage.WriteErrMsg("未选中文件或文件夹", this.m_UrlReferrer);
            }
            else
            {
                string[] strArray = this.EgvFiles.SelectList.ToString().Split(new char[] { ',' });
                string path = base.Request.PhysicalApplicationPath + SiteConfig.SiteOption.TemplateDir;
                if (string.IsNullOrEmpty(this.DrpMove.SelectedValue))
                {
                    AdminPage.WriteErrMsg("<li>请选择目标文件夹</li>", this.m_UrlReferrer);
                }
                try
                {
                    DirectoryInfo info = new DirectoryInfo(path);
                    if (info.Exists)
                    {
                        foreach (string str2 in strArray)
                        {
                            if (!string.IsNullOrEmpty(str2))
                            {
                                string str3 = info.FullName + this.DrpMove.SelectedValue + str2;
                                DirectoryInfo info2 = new DirectoryInfo(this.currentDirectory + str2 + "/");
                                DirectoryInfo info3 = new DirectoryInfo(info.FullName + this.DrpMove.SelectedValue);
                                DirectoryInfo info4 = new DirectoryInfo(str3);
                                if (info2.Exists)
                                {
                                    if (info3.FullName == info2.FullName)
                                    {
                                        AdminPage.WriteErrMsg("<li>不能移动到自己目录下</li>", this.m_UrlReferrer);
                                    }
                                    if (info2.FullName == info4.FullName)
                                    {
                                        AdminPage.WriteErrMsg("<li>不能移动到相同目录下</li>", this.m_UrlReferrer);
                                    }
                                    if (info4.Exists)
                                    {
                                        AdminPage.WriteErrMsg("<li>目标目录已经存在</li>", this.m_UrlReferrer);
                                    }
                                    FileSystemObject.Move(info2.FullName, str3, FsoMethod.Folder);
                                    Template.UpdateFileName(BasePage.RequestString("Dir") + "/" + str2, this.DrpMove.SelectedValue + str2);
                                }
                                FileInfo info5 = new FileInfo(this.currentDirectory + str2);
                                FileInfo info6 = new FileInfo(str3);
                                if (info5.Exists)
                                {
                                    if (info5.FullName == info6.FullName)
                                    {
                                        AdminPage.WriteErrMsg("<li>目标路径与源路径相同</li>", this.m_UrlReferrer);
                                    }
                                    if (info6.Exists)
                                    {
                                        AdminPage.WriteErrMsg("<li>目标文件已经存在</li>", this.m_UrlReferrer);
                                    }
                                    FileSystemObject.Move(info5.FullName, str3, FsoMethod.File);
                                    Template.UpdateFileName(BasePage.RequestString("Dir") + "/" + str2, this.DrpMove.SelectedValue + str2);
                                }
                            }
                        }
                        base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
                        AdminPage.WriteSuccessMsg("移动成功", this.m_UrlReferrer);
                    }
                }
                catch (FileNotFoundException)
                {
                    AdminPage.WriteErrMsg("<li>文件未找到</li>", this.m_UrlReferrer);
                }
                catch (UnauthorizedAccessException)
                {
                    AdminPage.WriteErrMsg("<li>移动文件夹或文件时失败!检查您的服务器是否给模板文件夹写入权限。</li>", this.m_UrlReferrer);
                }
            }
        }

        protected void EBtnBatchDel_Click(object sender, EventArgs e)
        {
            if (this.EgvFiles.SelectList.Length == 0)
            {
                AdminPage.WriteErrMsg("未选中文件或文件夹", this.m_UrlReferrer);
            }
            else
            {
                string[] strArray = this.EgvFiles.SelectList.ToString().Split(new char[] { ',' });
                try
                {
                    foreach (string str in strArray)
                    {
                        if (!string.IsNullOrEmpty(str))
                        {
                            if (string.IsNullOrEmpty(Path.GetExtension(str)))
                            {
                                FileSystemObject.Delete(this.currentDirectory + str, FsoMethod.Folder);
                            }
                            else
                            {
                                FileSystemObject.Delete(this.currentDirectory + str, FsoMethod.File);
                            }
                        }
                    }
                    base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
                    AdminPage.WriteSuccessMsg("删除成功", this.m_UrlReferrer);
                }
                catch (FileNotFoundException)
                {
                    AdminPage.WriteErrMsg("<li>文件未找到</li>", this.m_UrlReferrer);
                }
                catch (UnauthorizedAccessException)
                {
                    AdminPage.WriteErrMsg("<li>删除文件夹或文件时失败!检查您的服务器是否给模板文件夹写入权限。</li>", this.m_UrlReferrer);
                }
            }
        }

        protected void EBtnCopyDir_Click(object sender, EventArgs e)
        {
            if (!FileSystemObject.IsExist(this.currentDirectory + this.TxtCopyDir.Text, FsoMethod.Folder))
            {
                base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
                FileSystemObject.CopyDirectory(this.currentDirectory + this.HdnCopyDir.Value, this.currentDirectory + this.TxtCopyDir.Text);
                AdminPage.WriteSuccessMsg("<li>复制目录成功。</li>", this.m_UrlReferrer);
            }
            else
            {
                AdminPage.WriteErrMsg("<li>重命名的目录已经存在了。</li>", this.m_UrlReferrer);
            }
        }

        protected void EBtnCopyFile_Click(object sender, EventArgs e)
        {
            base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
            FileSystemObject.CopyFile(this.currentDirectory + this.HdnCopyFile.Value, this.currentDirectory + this.TxtCopyFile.Text);
            AdminPage.WriteSuccessMsg("<li>复制文件成功。</li>", this.m_UrlReferrer);
        }

        protected void EBtnCreateTemplate_Click(object sender, EventArgs e)
        {
            BasePage.ResponseRedirect("Template.aspx?Dir=" + base.Server.UrlEncode(base.Request.QueryString["Dir"]));
        }

        protected void EBtnModifyName_Click(object sender, EventArgs e)
        {
            if (this.Page.IsValid)
            {
                string str = this.currentDirectory + @"\";
                string oldFile = str + this.HdnName.Value;
                string successMessage = "";
                try
                {
                    if (this.HdnType.Value == "1")
                    {
                        string file = str + this.TxtDirName.Text;
                        if (oldFile == file)
                        {
                            AdminPage.WriteErrMsg("重命名目录名不能和原来目录名一样!", this.m_UrlReferrer);
                        }
                        if (!FileSystemObject.IsExist(file, FsoMethod.Folder))
                        {
                            FileSystemObject.Move(oldFile, file, FsoMethod.Folder);
                            base.Response.Write("<script type='text/javascript'>parent.frames[\"left\"].location.reload();</script>");
                            successMessage = "重命名目录成功!";
                            if (this.ChkUpdateFolderContactinformation.Checked)
                            {
                                DirectoryInfo info = new DirectoryInfo(base.Request.PhysicalApplicationPath + SiteConfig.SiteOption.TemplateDir);
                                DirectoryInfo info2 = new DirectoryInfo(oldFile);
                                DirectoryInfo info3 = new DirectoryInfo(file);
                                oldFile = info2.FullName.Replace(info.FullName, "");
                                file = info3.FullName.Replace(info.FullName, "");
                                oldFile = oldFile.Replace(@"\", "/");
                                Template.ReplaceTemplateDir(oldFile + "/", file.Replace(@"\", "/") + "/");
                                successMessage = successMessage + "相关联该目录的模版引用已改变!";
                            }
                        }
                        else
                        {
                            AdminPage.WriteErrMsg("<li>重命目标目录名已经存在。</li>", this.m_UrlReferrer);
                        }
                    }

⌨️ 快捷键说明

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