using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.IO; using CB.Common; using CB.Data; using CB.Framework; namespace CB.Admin.Plugins.Template { public partial class TemplateContentEdit : AdminPage { public string TemplateName; protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { InitData(); } } protected override void InitData() { var tid = WRequest.GetQueryInt("tid"); var entity = CB.Data.TemplateService.Get(tid); if (null == entity) { ShowMessageBox("参数错误!"); } labID.Text = entity.Id.ToString(); TemplateName = entity.Name; string filePath = AppDomain.CurrentDomain.BaseDirectory + CB.Config.BaseConfigs.GetConfig().TemplateRootPath + "\\" + entity.FilePath; if (File.Exists(filePath)) { txtTemplateContent.Text = File.ReadAllText(filePath, System.Text.Encoding.UTF8); } } protected void btnEdit_Click(object sender, EventArgs e) { var entity = CB.Data.TemplateService.Get(TypeConverter.StrToInt(labID.Text)); if (null == entity) return; string filePath = AppDomain.CurrentDomain.BaseDirectory + CB.Config.BaseConfigs.GetConfig().TemplateRootPath + "\\" + entity.FilePath; if (File.Exists(filePath)) { CB.Common.FileUtil.WriteFile(filePath, txtTemplateContent.Text.Trim()); CB.Data.TemplateFiles.LoadFile(entity.FilePath); ShowMessageBox("修改成功!", string.Format("TemplateContentEdit.aspx?tid={0}&authPage={1}", labID.Text, authPage)); } } } }