guestbook_manage.aspx.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*******************************************************************************
  2. * iNethinkCMS - 网站内容管理系统
  3. * Copyright (C) 2012-2013 inethink.com
  4. *
  5. * @author jackyang <69991000@qq.com>
  6. * @website http://cms.inethink.com
  7. * @version 1.3.6.0 (2013-08-14)
  8. *
  9. * This is licensed under the GNU LGPL, version 3.0 or later.
  10. * For details, see: http://www.gnu.org/licenses/gpl-3.0.html
  11. *******************************************************************************/
  12. using System;
  13. using System.Collections.Generic;
  14. using System.Web;
  15. using System.Web.UI;
  16. using System.Web.UI.WebControls;
  17. using iNethinkCMS.Command;
  18. using iNethinkCMS.Web.UI;
  19. namespace iNethinkCMS.Web.plugs.guestbook
  20. {
  21. public partial class guestbook_manage : Admin_BasePage
  22. {
  23. iNethinkCMS.BLL.BLL_iNethinkCMS_Plugs_Guestbook bll = new iNethinkCMS.BLL.BLL_iNethinkCMS_Plugs_Guestbook();
  24. iNethinkCMS.Model.Model_iNethinkCMS_Plugs_Guestbook model = new iNethinkCMS.Model.Model_iNethinkCMS_Plugs_Guestbook();
  25. private string vNavInfo = "当前位置:";
  26. private string vAct = "";
  27. private int vPage = 1;
  28. private int vID = 0;
  29. private string vSQL = "";
  30. private string vKeyType = "";
  31. private string vKey = "";
  32. private string vGuestbookUserName;
  33. private string vGuestbookUserIP;
  34. private string vGuestbookCompany;
  35. private string vGuestbookAddress;
  36. private string vGuestbookTel;
  37. private string vGuestbookEmail;
  38. private string vGuestbookQQ;
  39. private string vGuestbookContent;
  40. private DateTime vGuestbookTime;
  41. private string vReplyUserName;
  42. private string vReplyContent;
  43. private DateTime vReplyTime;
  44. private int vDisplay;
  45. private int vOrderNum;
  46. protected void Page_Load(object sender, EventArgs e)
  47. {
  48. CheckUserPower("a");
  49. #region
  50. vAct = Request.QueryString["Act"] != null ? Request.QueryString["Act"] : "";
  51. if (Request.QueryString["Page"] != null && Request.QueryString["Page"].Trim() != "")
  52. {
  53. if (!int.TryParse(Request.QueryString["Page"], out vPage))
  54. {
  55. vPage = 1;
  56. }
  57. }
  58. vKeyType = Request.QueryString["sKeyType"] != null ? Request.QueryString["sKeyType"] : "";
  59. vKey = Request.QueryString["sKey"] != null ? Request.QueryString["sKey"] : "";
  60. vKey = vKey.Replace("'", "");
  61. if (Request.QueryString["ID"] != null && Request.QueryString["ID"].Trim() != "")
  62. {
  63. if (!int.TryParse(Request.QueryString["ID"], out vID))
  64. {
  65. Response.Write("ID Error");
  66. Response.End();
  67. }
  68. }
  69. if (vKey.Length > 0)
  70. {
  71. if (vKeyType == "ID")
  72. {
  73. if (iNethinkCMS.Command.Command_Validate.IsNumber(vKey) == true)
  74. {
  75. vSQL += vKeyType + " = " + vKey + "";
  76. }
  77. else
  78. {
  79. vKey = "";
  80. }
  81. }
  82. else
  83. {
  84. vSQL += vKeyType + " Like '%" + vKey + "%'";
  85. }
  86. }
  87. #endregion
  88. this.mainID.Visible = false;
  89. this.guideID.Visible = false;
  90. switch (vAct)
  91. {
  92. case "guide":
  93. this.guideID.Visible = true;
  94. if (vID == 0)
  95. {
  96. this.navInfoID.InnerText = vNavInfo + "留言添加";
  97. this.Button_Submit.Click += new EventHandler(Button_Submit_Click_Add);
  98. }
  99. else
  100. {
  101. this.navInfoID.InnerText = vNavInfo + "留言管理";
  102. this.Button_Submit.Click += new EventHandler(Button_Submit_Click_Edit);
  103. }
  104. if (!IsPostBack)
  105. {
  106. if (Request.UrlReferrer != null)
  107. {
  108. ViewState["reJumpUrl"] = Request.UrlReferrer.AbsoluteUri;
  109. }
  110. Fun_SetValue(vID); //获取frm基本信息
  111. }
  112. break;
  113. case "delete":
  114. Fun_Delete(vID);
  115. break;
  116. default:
  117. this.navInfoID.InnerText = vNavInfo + "留言管理";
  118. this.mainID.Visible = true;
  119. if (!IsPostBack)
  120. {
  121. this.sKeyType.SelectedValue = vKeyType;
  122. this.sKey.Text = vKey;
  123. }
  124. PageListInfo();
  125. break;
  126. }
  127. }
  128. #region mainID 列表
  129. protected void PageListInfo()
  130. {
  131. int vPageSize = int.Parse(siteConfig.PageListNum);
  132. int vRecordCount = bll.GetRecordCount(vSQL);
  133. Repeater.DataSource = bll.GetListByPage(vSQL, "ID Desc", (vPage - 1) * vPageSize, vPage * vPageSize);
  134. Repeater.DataBind();
  135. string pTemp = "";
  136. int vPageCount = 1;
  137. if (vRecordCount > 0)
  138. {
  139. vPageCount = (int)Math.Ceiling((double)vRecordCount / (double)vPageSize);
  140. pTemp = WebUI_PageList.GetPagingInfo_Manage(vPageCount, vRecordCount, vPage, vPageSize);
  141. }
  142. this.pagelist.InnerHtml = pTemp;
  143. this.iNoInfo.Visible = vRecordCount == 0 ? true : false;
  144. }
  145. protected void Button_Search_Click(object sender, EventArgs e)
  146. {
  147. Response.Redirect(Request.Path + "?skeytype=" + this.sKeyType.SelectedValue + "&skey=" + this.sKey.Text);
  148. }
  149. #endregion
  150. #region guideID 信息修改/添加
  151. private void Fun_SetValue(int byID)
  152. {
  153. if (byID == 0)
  154. {
  155. this.txtGuestbookUserName.Text = "";
  156. this.txtGuestbookUserIP.Text = "";
  157. this.txtGuestbookCompany.Text = "";
  158. this.txtGuestbookAddress.Text = "";
  159. this.txtGuestbookTel.Text = "";
  160. this.txtGuestbookEmail.Text = "";
  161. this.txtGuestbookQQ.Text = "";
  162. this.txtGuestbookContent.Text = "";
  163. this.txtGuestbookTime.Text = "";
  164. this.txtReplyUserName.Text = SysLoginUserTrueName;
  165. this.txtReplyContent.Text = "";
  166. this.txtReplyTime.Text = DateTime.Now.ToString();
  167. this.txtDisplay.Checked = false;
  168. this.txtOrderNum.Text = "0";
  169. }
  170. else
  171. {
  172. model = bll.GetModel(byID);
  173. this.txtGuestbookUserName.Text = model.GuestbookUserName;
  174. this.txtGuestbookUserIP.Text = model.GuestbookUserIP;
  175. this.txtGuestbookCompany.Text = model.GuestbookCompany;
  176. this.txtGuestbookAddress.Text = model.GuestbookAddress;
  177. this.txtGuestbookTel.Text = model.GuestbookTel;
  178. this.txtGuestbookEmail.Text = model.GuestbookEmail;
  179. this.txtGuestbookQQ.Text = model.GuestbookQQ;
  180. this.txtGuestbookContent.Text = model.GuestbookContent;
  181. this.txtGuestbookTime.Text = model.GuestbookTime.ToString();
  182. this.txtReplyUserName.Text = String.IsNullOrEmpty(model.ReplyUserName) == true ? SysLoginUserTrueName : model.ReplyUserName;
  183. this.txtReplyContent.Text = model.ReplyContent;
  184. this.txtReplyTime.Text = String.IsNullOrEmpty(model.ReplyTime.ToString()) == true ? DateTime.Now.ToString() : model.ReplyTime.ToString(); ;
  185. this.txtDisplay.Checked = model.Display == 1 ? true : false;
  186. this.txtOrderNum.Text = String.IsNullOrEmpty(model.OrderNum.ToString()) == true ? "0" : model.OrderNum.ToString();
  187. }
  188. }
  189. private bool Fun_GetValue()
  190. {
  191. if (this.txtGuestbookUserName.Text.Trim().Length == 0)
  192. {
  193. MessageBox.Show(this, "请输入留言人!");
  194. return false;
  195. }
  196. if (this.txtGuestbookContent.Text.Trim().Length == 0)
  197. {
  198. MessageBox.Show(this, "请输入留言内容!");
  199. return false;
  200. }
  201. if (this.txtDisplay.Checked == true)
  202. {
  203. if (this.txtReplyUserName.Text.Trim().Length == 0)
  204. {
  205. MessageBox.Show(this, "请输入回复人!");
  206. return false;
  207. }
  208. if (this.txtReplyContent.Text.Trim().Length == 0)
  209. {
  210. MessageBox.Show(this, "请输入回复内容!");
  211. return false;
  212. }
  213. if (!Command_Validate.IsNumber(this.txtOrderNum.Text.Trim()))
  214. {
  215. MessageBox.Show(this, "排序权重只能输入数字!");
  216. return false;
  217. }
  218. }
  219. vGuestbookUserName = this.txtGuestbookUserName.Text.Trim();
  220. vGuestbookUserIP = this.txtGuestbookUserIP.Text.Trim();
  221. vGuestbookCompany = this.txtGuestbookCompany.Text.Trim();
  222. vGuestbookAddress = this.txtGuestbookAddress.Text.Trim();
  223. vGuestbookTel = this.txtGuestbookTel.Text.Trim();
  224. vGuestbookEmail = this.txtGuestbookEmail.Text.Trim();
  225. vGuestbookQQ = this.txtGuestbookQQ.Text.Trim();
  226. vGuestbookContent = this.txtGuestbookContent.Text.Trim();
  227. vGuestbookTime = DateTime.Parse(this.txtGuestbookTime.Text.Trim());
  228. vReplyUserName = this.txtReplyUserName.Text.Trim();
  229. vReplyContent = this.txtReplyContent.Text.Trim();
  230. vReplyTime = DateTime.Parse(this.txtReplyTime.Text.Trim());
  231. vDisplay = this.txtDisplay.Checked == true ? 1 : 0;
  232. vOrderNum = int.Parse(this.txtOrderNum.Text.Trim());
  233. return true;
  234. }
  235. protected void Button_Submit_Click_Add(object sender, EventArgs e)
  236. {
  237. if (Fun_GetValue() == true)
  238. {
  239. model.GuestbookUserName = vGuestbookUserName;
  240. model.GuestbookUserIP = vGuestbookUserIP;
  241. model.GuestbookCompany = vGuestbookCompany;
  242. model.GuestbookAddress = vGuestbookAddress;
  243. model.GuestbookTel = vGuestbookTel;
  244. model.GuestbookEmail = vGuestbookEmail;
  245. model.GuestbookQQ = vGuestbookQQ;
  246. model.GuestbookContent = vGuestbookContent;
  247. model.GuestbookTime = vGuestbookTime;
  248. model.ReplyUserName = vReplyUserName;
  249. model.ReplyContent = vReplyContent;
  250. model.ReplyTime = vReplyTime;
  251. model.Display = vDisplay;
  252. model.OrderNum = vOrderNum;
  253. bll.Add(model);
  254. Response.Redirect(Request.Path);
  255. }
  256. }
  257. protected void Button_Submit_Click_Edit(object sender, EventArgs e)
  258. {
  259. if (Fun_GetValue() == true)
  260. {
  261. if (bll.GetRecordCount("ID = " + vID) == 0) //判断该ID是否被删除
  262. {
  263. MessageBox.ShowAndRedirect(this, "你所需要更新的记录 [" + vID + "] 不存在!", ViewState["reJumpUrl"].ToString());
  264. return;
  265. }
  266. model.ID = vID;
  267. model.GuestbookUserName = vGuestbookUserName;
  268. model.GuestbookUserIP = vGuestbookUserIP;
  269. model.GuestbookCompany = vGuestbookCompany;
  270. model.GuestbookAddress = vGuestbookAddress;
  271. model.GuestbookTel = vGuestbookTel;
  272. model.GuestbookEmail = vGuestbookEmail;
  273. model.GuestbookQQ = vGuestbookQQ;
  274. model.GuestbookContent = vGuestbookContent;
  275. model.GuestbookTime = vGuestbookTime;
  276. model.ReplyUserName = vReplyUserName;
  277. model.ReplyContent = vReplyContent;
  278. model.ReplyTime = vReplyTime;
  279. model.Display = vDisplay;
  280. model.OrderNum = vOrderNum;
  281. bll.Update(model);
  282. Response.Redirect(ViewState["reJumpUrl"].ToString());
  283. }
  284. }
  285. #endregion
  286. #region Delete 数据删除
  287. protected void Fun_Delete(int byID)
  288. {
  289. if (bll.Delete(byID) == true)
  290. {
  291. Response.Redirect(Request.UrlReferrer.AbsoluteUri);
  292. }
  293. }
  294. #endregion
  295. }
  296. }