extend_blogroll.aspx.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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 System.Data;
  18. using System.Data.SqlClient;
  19. using System.Web.Security;
  20. using iNethinkCMS.Command;
  21. using iNethinkCMS.Web.UI;
  22. namespace iNethinkCMS.Web.admin.extend
  23. {
  24. public partial class extend_blogroll : Admin_BasePage
  25. {
  26. iNethinkCMS.BLL.BLL_iNethinkCMS_Extend_Blogroll bll = new iNethinkCMS.BLL.BLL_iNethinkCMS_Extend_Blogroll();
  27. iNethinkCMS.Model.Model_iNethinkCMS_Extend_Blogroll model = new iNethinkCMS.Model.Model_iNethinkCMS_Extend_Blogroll();
  28. iNethinkCMS.BLL.BLL_iNethinkCMS_Dict bll_dict = new BLL.BLL_iNethinkCMS_Dict();
  29. iNethinkCMS.BLL.BLL_iNethinkCMS_Upload bll_upload = new iNethinkCMS.BLL.BLL_iNethinkCMS_Upload();
  30. private string vNavInfo = "当前位置:";
  31. private string vAct = "";
  32. private int vPage = 1;
  33. private int vID = 0;
  34. private string vSQL = "";
  35. private string vKeyType = "";
  36. private string vKey = "";
  37. private int vBlogrollClass;
  38. private string vBlogrollName;
  39. private string vBlogrollImg;
  40. private string vBlogrollUrl;
  41. private int vDisplay;
  42. private int vOrderNum;
  43. protected void Page_Load(object sender, EventArgs e)
  44. {
  45. CheckUserPower("c");
  46. #region
  47. vAct = Request.QueryString["Act"] != null ? Request.QueryString["Act"] : "";
  48. if (Request.QueryString["Page"] != null && Request.QueryString["Page"].Trim() != "")
  49. {
  50. if (!int.TryParse(Request.QueryString["Page"], out vPage))
  51. {
  52. vPage = 1;
  53. }
  54. }
  55. vKeyType = Request.QueryString["sKeyType"] != null ? Request.QueryString["sKeyType"] : "";
  56. vKey = Request.QueryString["sKey"] != null ? Request.QueryString["sKey"] : "";
  57. vKey = vKey.Replace("'", "");
  58. if (Request.QueryString["ID"] != null && Request.QueryString["ID"].Trim() != "")
  59. {
  60. if (!int.TryParse(Request.QueryString["ID"], out vID))
  61. {
  62. Response.Write("ID Error");
  63. Response.End();
  64. }
  65. }
  66. if (vKey.Length > 0)
  67. {
  68. if (vKeyType == "ID")
  69. {
  70. if (iNethinkCMS.Command.Command_Validate.IsNumber(vKey) == true)
  71. {
  72. vSQL += vKeyType + " = " + vKey + "";
  73. }
  74. else
  75. {
  76. vKey = "";
  77. }
  78. }
  79. else
  80. {
  81. vSQL += vKeyType + " Like '%" + vKey + "%'";
  82. }
  83. }
  84. #endregion
  85. this.mainID.Visible = false;
  86. this.guideID.Visible = false;
  87. switch (vAct)
  88. {
  89. case "guide":
  90. this.guideID.Visible = true;
  91. if (vID == 0)
  92. {
  93. this.navInfoID.InnerText = vNavInfo + "友情链接添加";
  94. this.Button_Submit.Click += new EventHandler(Button_Submit_Click_Add);
  95. }
  96. else
  97. {
  98. this.navInfoID.InnerText = vNavInfo + "友情链接修改";
  99. this.Button_Submit.Click += new EventHandler(Button_Submit_Click_Edit);
  100. }
  101. if (!IsPostBack)
  102. {
  103. if (Request.UrlReferrer != null)
  104. {
  105. ViewState["reJumpUrl"] = Request.UrlReferrer.AbsoluteUri;
  106. }
  107. Fun_SetValue(vID); //获取frm基本信息
  108. }
  109. break;
  110. case "delete":
  111. Fun_Delete(vID);
  112. break;
  113. default:
  114. this.navInfoID.InnerText = vNavInfo + "友情链接管理";
  115. this.mainID.Visible = true;
  116. if (!IsPostBack)
  117. {
  118. this.sKeyType.SelectedValue = vKeyType;
  119. this.sKey.Text = vKey;
  120. }
  121. PageListInfo();
  122. break;
  123. }
  124. }
  125. #region mainID 列表
  126. protected void PageListInfo()
  127. {
  128. int vPageSize = int.Parse(siteConfig.PageListNum);
  129. int vRecordCount = bll.GetRecordCount(vSQL);
  130. Repeater.DataSource = bll.GetListByPage(vSQL, "ID Desc", (vPage - 1) * vPageSize, vPage * vPageSize);
  131. Repeater.DataBind();
  132. string pTemp = "";
  133. int vPageCount = 1;
  134. if (vRecordCount > 0)
  135. {
  136. vPageCount = (int)Math.Ceiling((double)vRecordCount / (double)vPageSize);
  137. pTemp = WebUI_PageList.GetPagingInfo_Manage(vPageCount, vRecordCount, vPage, vPageSize);
  138. }
  139. this.pagelist.InnerHtml = pTemp;
  140. this.iNoInfo.Visible = vRecordCount == 0 ? true : false;
  141. }
  142. protected void Button_Search_Click(object sender, EventArgs e)
  143. {
  144. Response.Redirect(Request.Path + "?skeytype=" + this.sKeyType.SelectedValue + "&skey=" + this.sKey.Text);
  145. }
  146. #endregion
  147. #region guideID 信息修改/添加
  148. private void Fun_SetValue(int byID)
  149. {
  150. BindDropdownList_Dict(this.txtBlogrollClass);
  151. if (byID == 0)
  152. {
  153. this.txtBlogrollClass.Text = "0";
  154. this.txtBlogrollName.Text = "";
  155. this.txtBlogrollImg.Text = "";
  156. this.txtBlogrollUrl.Text = "http://";
  157. this.txtDisplay.Checked = true;
  158. this.txtOrderNum.Text = "0";
  159. }
  160. else
  161. {
  162. model = bll.GetModel(byID);
  163. this.txtBlogrollClass.Text = model.BlogrollClass.ToString();
  164. this.txtBlogrollName.Text = model.BlogrollName;
  165. this.txtBlogrollImg.Text = model.BlogrollImg;
  166. this.txtBlogrollUrl.Text = model.BlogrollUrl;
  167. this.txtDisplay.Checked = model.Display == 1 ? true : false;
  168. this.txtOrderNum.Text = model.OrderNum.ToString();
  169. }
  170. }
  171. private bool Fun_GetValue()
  172. {
  173. if (this.txtBlogrollClass.Text.Trim() == "0")
  174. {
  175. MessageBox.Show(this, "请选择友情链接分类!");
  176. return false;
  177. }
  178. if (this.txtBlogrollName.Text.Trim().Length == 0)
  179. {
  180. MessageBox.Show(this, "请输入友情链接名称!");
  181. return false;
  182. }
  183. if (this.txtBlogrollUrl.Text.Trim().Replace("http://","").Length == 0)
  184. {
  185. MessageBox.Show(this, "请输入友情链接地址!");
  186. return false;
  187. }
  188. if (!Command_Validate.IsNumber(this.txtOrderNum.Text.Trim()))
  189. {
  190. MessageBox.Show(this, "排序权重只能输入数字!");
  191. return false;
  192. }
  193. vBlogrollClass = int.Parse(this.txtBlogrollClass.Text);
  194. vBlogrollName = this.txtBlogrollName.Text;
  195. vBlogrollImg = this.txtBlogrollImg.Text;
  196. vBlogrollUrl = this.txtBlogrollUrl.Text;
  197. vDisplay = this.txtDisplay.Checked == true ? 1 : 0;
  198. vOrderNum = int.Parse(this.txtOrderNum.Text);
  199. return true;
  200. }
  201. protected void Button_Submit_Click_Add(object sender, EventArgs e)
  202. {
  203. if (Fun_GetValue() == true)
  204. {
  205. if (bll.GetRecordCount("BlogrollClass = " + vBlogrollClass + " And BlogrollName = '" + vBlogrollName + "'") > 0)
  206. {
  207. MessageBox.Show(this, "友情链接分类[" + this.txtBlogrollClass.Text + "]中的友情链接名称 [" + vBlogrollName + "] 已经存在!");
  208. return;
  209. }
  210. model.BlogrollClass = vBlogrollClass;
  211. model.BlogrollName = vBlogrollName;
  212. model.BlogrollImg = vBlogrollImg;
  213. model.BlogrollUrl = vBlogrollUrl;
  214. model.Display = vDisplay;
  215. model.OrderNum = vOrderNum;
  216. bll.Add(model);
  217. bll_upload.UpdateUploadFile_One(vBlogrollImg, 6, bll.GetMaxID(), 0);
  218. Response.Redirect(Request.Path);
  219. }
  220. }
  221. protected void Button_Submit_Click_Edit(object sender, EventArgs e)
  222. {
  223. if (Fun_GetValue() == true)
  224. {
  225. if (bll.GetRecordCount("ID = " + vID) == 0) //判断该ID是否被删除
  226. {
  227. MessageBox.ShowAndRedirect(this, "你所需要更新的记录 [" + vID + "] 不存在!", ViewState["reJumpUrl"].ToString());
  228. return;
  229. }
  230. if (bll.GetRecordCount("ID <> " + vID + " And BlogrollClass = " + vBlogrollClass + " And BlogrollName = '" + vBlogrollName + "'") > 0)
  231. {
  232. MessageBox.Show(this, "友情链接分类[" + this.txtBlogrollClass.Text + "]中的友情链接名称 [" + vBlogrollName + "] 已经存在!");
  233. return;
  234. }
  235. model.ID = vID;
  236. model.BlogrollClass = vBlogrollClass;
  237. model.BlogrollName = vBlogrollName;
  238. model.BlogrollImg = vBlogrollImg;
  239. model.BlogrollUrl = vBlogrollUrl;
  240. model.Display = vDisplay;
  241. model.OrderNum = vOrderNum;
  242. bll.Update(model);
  243. bll_upload.UpdateUploadFile_Reset(6, vID, 0);
  244. bll_upload.UpdateUploadFile_One(vBlogrollImg, 6, vID, 0);
  245. Response.Redirect(ViewState["reJumpUrl"].ToString());
  246. }
  247. }
  248. #endregion
  249. #region Delete 数据删除
  250. protected void Fun_Delete(int byID)
  251. {
  252. if (bll.Delete(byID) == true)
  253. {
  254. bll_upload.UpdateUploadFile_Reset(6, byID, 0); //重置上传表中的数据
  255. Response.Redirect(Request.UrlReferrer.AbsoluteUri);
  256. }
  257. }
  258. #endregion
  259. #region 友情链接分类下拉列表输出
  260. protected void BindDropdownList_Dict(DropDownList byDropDownList)
  261. {
  262. DataTable dt = bll_dict.GetList(0, "[DictType] = 1 And [Display] = 1", "OrderNum Desc").Tables[0];
  263. for (int i = 0; i < dt.Rows.Count; i++)
  264. {
  265. byDropDownList.Items.Add(new ListItem(dt.Rows[i]["DictName"].ToString(), dt.Rows[i]["ID"].ToString()));
  266. }
  267. }
  268. #endregion
  269. protected string Fun_DisplayInfo(object byDisplay)
  270. {
  271. return byDisplay.ToString() == "0" ? "<font color=\"#ff0000\">不显示</font>" : "显示";
  272. }
  273. protected string Fun_GetDictName(int byDictID)
  274. {
  275. return bll_dict.GetDictName(byDictID);
  276. }
  277. }
  278. }