📄 templateui.cs
字号:
namespace PowerEasy.WebSite.Admin.Template
{
using AjaxControlToolkit;
using PowerEasy.Common;
using PowerEasy.Components;
using PowerEasy.Controls;
using PowerEasy.Model.TemplateProc;
using PowerEasy.Templates;
using PowerEasy.Web.UI;
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
public class TemplateUI : AdminPage
{
protected AlternateLiteral AlternateLiteral1;
protected Button BtnSubmit;
protected string currentPath;
protected DropDownList DropLabelList;
protected DropDownList DropPagerList;
protected Label LblFileName;
protected Label LblLabelList;
protected Label LblPageList;
private string m_action;
protected Label savefilename;
protected ScriptManager ScriptManager1;
protected ExtendedSiteMapPath SmpNavigator;
protected TabContainer TabContainer1;
protected TabPanel TabPanel1;
protected TabPanel TabPanel2;
protected TabPanel TabPanel3;
protected TabPanel TabPanel4;
protected TextBox TxtFileName;
protected TextBox TxtTemplate;
protected System.Web.UI.UpdatePanel UpdatePanel1;
protected System.Web.UI.UpdatePanel UpdatePanel2;
protected RegularExpressionValidator ValeTxtFileName;
protected PowerEasy.Controls.RequiredFieldValidator ValrTxtFileName;
protected void BtnSubmit_Click(object sender, EventArgs e)
{
if (this.Page.IsValid)
{
try
{
if (this.m_action == "Modify")
{
FileSystemObject.WriteFile(this.currentPath, this.TxtTemplate.Text);
AdminPage.WriteSuccessMsg("<li>保存模板数据成功!</li>", this.ViewState["UrlReferrer"].ToString());
}
if (this.m_action == "Add")
{
this.currentPath = this.currentPath + @"\" + this.TxtFileName.Text;
FileInfo info = new FileInfo(this.currentPath);
if (info.Exists)
{
this.savefilename.Text = "文件已存在,请更改文件名";
}
else
{
FileSystemObject.WriteFile(this.currentPath, this.TxtTemplate.Text);
AdminPage.WriteSuccessMsg("<li>保存模板数据成功!</li>", this.ViewState["UrlReferrer"].ToString());
}
}
}
catch (FileNotFoundException)
{
AdminPage.WriteErrMsg("文件未找到");
}
catch (UnauthorizedAccessException)
{
AdminPage.WriteErrMsg("<li>访问文件失败!检查您的服务器是否给模板文件夹写入权限。</li>");
}
}
}
protected void BuildLabelList(string typename)
{
this.LblLabelList.Text = string.Empty;
foreach (LabelManageInfo info in LabelManage.GetLabelList(typename))
{
string text = this.LblLabelList.Text;
this.LblLabelList.Text = text + "<div onclick=\"cit()\" outype=\"1\" class=\"spanfixdiv\" alt=\"" + info.Intro + "\">" + info.Name + "</div>";
}
}
protected void BuildPagerList(string typename)
{
this.LblPageList.Text = string.Empty;
foreach (PagerManageInfo info in PagerManage.GetPagerList(typename))
{
string text = this.LblPageList.Text;
this.LblPageList.Text = text + "<div onclick=\"cit()\" outype=\"2\" class=\"spanfixdiv\" alt=\"" + info.Intro + "\">" + info.Name + "</div>";
}
}
protected void DropLabelList_SelectedIndexChanged(object sender, EventArgs e)
{
this.BuildLabelList(this.DropLabelList.SelectedValue);
}
protected void DropPagerList_SelectedIndexChanged(object sender, EventArgs e)
{
this.BuildPagerList(this.DropPagerList.SelectedValue);
}
protected void InitPage()
{
this.m_action = BasePage.RequestString("Action", "Add");
this.ValeTxtFileName.ValidationExpression = "^[^\\/ :*?\"<>|.]+\\.html$";
string str = BasePage.RequestString("Dir");
this.currentPath = base.Request.PhysicalApplicationPath + SiteConfig.SiteOption.TemplateDir + str;
this.currentPath = this.currentPath.Replace("/", @"\");
if (!this.Page.IsPostBack)
{
string str2 = "TemplateManage.aspx";
if (!string.IsNullOrEmpty(str))
{
if (str.IndexOf('.') > 0)
{
str2 = str2 + "?Dir=" + base.Server.UrlEncode(str.Substring(0, str.LastIndexOf('/')));
}
else
{
str2 = str2 + "?Dir=" + base.Server.UrlEncode(str);
}
}
this.ViewState["UrlReferrer"] = str2;
if (this.m_action == "Modify")
{
this.LblFileName.Text = str;
this.TxtFileName.Visible = false;
this.ValrTxtFileName.Visible = false;
this.ValeTxtFileName.Enabled = false;
try
{
this.TxtTemplate.Text = FileSystemObject.ReadFile(this.currentPath);
}
catch (FileNotFoundException)
{
AdminPage.WriteErrMsg("文件未找到", this.ViewState["UrlReferrer"].ToString());
}
catch (UnauthorizedAccessException)
{
AdminPage.WriteErrMsg("<li>读取文件失败!检查您的服务器是否给模板文件夹写入权限。</li>", this.ViewState["UrlReferrer"].ToString());
}
}
if (this.m_action == "Add")
{
this.LblFileName.Text = str + "/";
}
ListItem item = new ListItem();
item.Text = "全部分类";
this.DropLabelList.DataSource = LabelManage.GetLabelTypeList();
this.DropLabelList.DataTextField = "Name";
this.DropLabelList.DataValueField = "Name";
this.DropLabelList.DataBind();
this.DropLabelList.Items.Insert(0, item);
this.DropPagerList.DataSource = PagerManage.GetPagerTypeList();
this.DropPagerList.DataTextField = "Name";
this.DropPagerList.DataValueField = "Name";
this.DropPagerList.DataBind();
this.DropPagerList.Items.Insert(0, item);
this.BuildLabelList(string.Empty);
this.BuildPagerList(string.Empty);
}
}
protected void Page_Load(object sender, EventArgs e)
{
this.InitPage();
this.TxtTemplate.Attributes.Add("onmouseup", "dragend(this)");
this.TxtTemplate.Attributes.Add("onClick", "savePos(this)");
this.TxtTemplate.Attributes.Add("onmousemove", "DragPos(this)");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -