extend_dict.aspx.cs 9.4 KB

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