TemplateContentEdit.aspx.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.UI;
  6. using System.Web.UI.WebControls;
  7. using System.IO;
  8. using CB.Common;
  9. using CB.Data;
  10. using CB.Framework;
  11. namespace CB.Admin.Plugins.Template
  12. {
  13. public partial class TemplateContentEdit : AdminPage
  14. {
  15. public string TemplateName;
  16. protected void Page_Load(object sender, EventArgs e)
  17. {
  18. if (!Page.IsPostBack)
  19. {
  20. InitData();
  21. }
  22. }
  23. protected override void InitData()
  24. {
  25. var tid = WRequest.GetQueryInt("tid");
  26. var entity = CB.Data.TemplateService.Get(tid);
  27. if (null == entity)
  28. { ShowMessageBox("参数错误!"); }
  29. labID.Text = entity.Id.ToString();
  30. TemplateName = entity.Name;
  31. string filePath = AppDomain.CurrentDomain.BaseDirectory + CB.Config.BaseConfigs.GetConfig().TemplateRootPath + "\\" + entity.FilePath;
  32. if (File.Exists(filePath))
  33. {
  34. txtTemplateContent.Text = File.ReadAllText(filePath, System.Text.Encoding.UTF8);
  35. }
  36. }
  37. protected void btnEdit_Click(object sender, EventArgs e)
  38. {
  39. var entity = CB.Data.TemplateService.Get(TypeConverter.StrToInt(labID.Text));
  40. if (null == entity)
  41. return;
  42. string filePath = AppDomain.CurrentDomain.BaseDirectory + CB.Config.BaseConfigs.GetConfig().TemplateRootPath + "\\" + entity.FilePath;
  43. if (File.Exists(filePath))
  44. {
  45. CB.Common.FileUtil.WriteFile(filePath, txtTemplateContent.Text.Trim());
  46. CB.Data.TemplateFiles.LoadFile(entity.FilePath);
  47. ShowMessageBox("修改成功!", string.Format("TemplateContentEdit.aspx?tid={0}&authPage={1}", labID.Text, authPage));
  48. }
  49. }
  50. }
  51. }