TopicEdit.aspx.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Services;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using CB.Admin.Ajax;
  9. using CB.Common;
  10. using CB.Data;
  11. using CB.Entity;
  12. using CB.Framework;
  13. namespace CB.Admin.Plugins.Basic
  14. {
  15. public partial class TopicEdit : AdminPage
  16. {
  17. private int _tid = 0;
  18. protected void Page_Load(object sender, EventArgs e)
  19. {
  20. _tid = WRequest.GetQueryInt("Tid", 0);
  21. if (!Page.IsPostBack)
  22. {
  23. InitData();
  24. }
  25. }
  26. protected override void InitData()
  27. {
  28. IList<TopicClassInfo> list = TopicClassService.ToList();
  29. if (null != list && list.Count > 0)
  30. {
  31. foreach (var item in list)
  32. {
  33. dpCid.Items.Add(new ListItem(item.Name, item.Cid.ToString()));
  34. }
  35. }
  36. if (0 < _tid)
  37. {
  38. TopicInfo entity = TopicService.Get(_tid);
  39. if (null == entity) return;
  40. dpCid.SelectedValue = entity.Cid.ToString();
  41. txtTitle.Text = entity.Title;
  42. txtContent.Value = entity.Context;
  43. this.Image1.ImageUrl = entity.FileURL;
  44. this.Image1.Visible = true;
  45. this.txb_FileName.Value = entity.FileName;
  46. this.txb_FileSize.Value = entity.FileSize;
  47. this.txb_FileUrl.Value = entity.FileURL;
  48. this.txb_FilteType.Value = entity.FilteType;
  49. this.txb_thumbsSize.Value = entity.thumbsSize;
  50. this.txb_thumbsURL.Value = entity.thumbsURL;
  51. labID.Text = entity.Tid.ToString();
  52. }
  53. }
  54. //创建实体
  55. private TopicInfo GetEntity()
  56. {
  57. TopicInfo entity = new TopicInfo();
  58. entity.Tid = TypeConverter.StrToInt(labID.Text);
  59. entity.Cid = TypeConverter.StrToInt(dpCid.SelectedValue);
  60. entity.Title = txtTitle.Text.Trim();
  61. entity.Context = txtContent.InnerText.Trim();
  62. entity.Uid = Uid;
  63. entity.UserName = UserName;
  64. entity.Status = string.IsNullOrEmpty(entity.Context) ? 1 : 0;
  65. entity.FileName = txb_FileName.Value.Trim();
  66. entity.FileSize = txb_FileSize.Value.Trim();
  67. entity.FileURL = txb_FileUrl.Value.Trim();
  68. entity.thumbsSize = txb_thumbsSize.Value.Trim();
  69. entity.thumbsURL = txb_thumbsURL.Value.Trim();
  70. entity.FilteType = txb_FilteType.Value.Trim();
  71. return entity;
  72. }
  73. private static Tuple<bool, string> Violation(TopicInfo entity)
  74. {
  75. if (entity.Cid <= 0)
  76. {
  77. return new Tuple<bool, string>(false, "请选择文章类型");
  78. }
  79. if (string.IsNullOrEmpty(entity.Title))
  80. {
  81. return new Tuple<bool, string>(false, "请填写标题");
  82. }
  83. return new Tuple<bool, string>(true, "");
  84. }
  85. protected void btnEdit_Click(object sender, EventArgs e)
  86. {
  87. TopicInfo entity = GetEntity();
  88. Tuple<bool, string> validate = Violation(entity);
  89. if (!validate.Item1)
  90. {
  91. ShowMessageBox(validate.Item2);
  92. return;
  93. }
  94. if (entity.Tid > 0)
  95. {
  96. TopicService.Update(entity);
  97. ShowMessageBox("提示:修改成功!", "TopicEdit.aspx?authPage=" + authPage + "&Tid=" + entity.Tid);
  98. }
  99. else
  100. {
  101. TopicService.Save(entity);
  102. ShowMessageBox("提示:添加成功!", "TopicEdit.aspx?authPage=" + authPage);
  103. }
  104. }
  105. protected void Button1_Click(object sender, EventArgs e)
  106. {
  107. UpLoadTopicMessageInfo info = new UpLoadTopicMessageInfo();
  108. int imgHight = WRequest.GetInt("thumb_Hight", 320);
  109. int imgWidth = WRequest.GetInt("thumb_Width", 96);
  110. string path = "topic";
  111. int size = 3;
  112. FileUpLoadManager fm = new FileUpLoadManager();
  113. info = fm.UpLoadPhotoAndThumbnailByTv(path, size, 320, 0, "W");
  114. if (info.error != 0)
  115. {
  116. ShowMessageBox(info.message);
  117. return;
  118. }
  119. Image1.Visible = true;
  120. Image1.ImageUrl = info.FileUrl;
  121. txb_FileName.Value = info.FileName;
  122. txb_FileSize.Value = info.FileSize;
  123. txb_FileUrl.Value = info.FileUrl;
  124. txb_FilteType.Value = info.FilteType;
  125. txb_thumbsSize.Value = info.thumbsSize;
  126. txb_thumbsURL.Value = info.thumbsURL;
  127. }
  128. protected void btn_ClearImg_Click(object sender, EventArgs e)
  129. {
  130. Image1.ImageUrl = "";
  131. Image1.Visible = false;
  132. txb_FileName.Value = "";
  133. txb_FileSize.Value = "";
  134. txb_FileUrl.Value = "";
  135. txb_FilteType.Value = "";
  136. txb_thumbsSize.Value = "";
  137. txb_thumbsURL.Value = "";
  138. }
  139. }
  140. }