sys_user.aspx.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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.Data;
  14. using System.Collections.Generic;
  15. using System.Web;
  16. using System.Web.UI;
  17. using System.Web.UI.WebControls;
  18. using System.Web.Security;
  19. using iNethinkCMS.Command;
  20. using iNethinkCMS.Web.UI;
  21. namespace iNethinkCMS.Web.admin.sys
  22. {
  23. public partial class sys_user : Admin_BasePage
  24. {
  25. iNethinkCMS.BLL.BLL_iNethinkCMS_User bll = new iNethinkCMS.BLL.BLL_iNethinkCMS_User();
  26. iNethinkCMS.Model.Model_iNethinkCMS_User model = new iNethinkCMS.Model.Model_iNethinkCMS_User();
  27. iNethinkCMS.BLL.BLL_iNethinkCMS_Channel bll_column = new iNethinkCMS.BLL.BLL_iNethinkCMS_Channel();
  28. private string vNavInfo = "当前位置:";
  29. private string vAct = "";
  30. private int vPage = 1;
  31. private int vID = 0;
  32. private string vSQL = "";
  33. private string vKeyType = "";
  34. private string vKey = "";
  35. public int vUserType=1;
  36. private string vUserName;
  37. private string vUserPass;
  38. private string vUserTrueName;
  39. private string vUserEmail;
  40. private string vUserPower;
  41. private string vUserChannelPower;
  42. private bool vUserChannelPowerAll;
  43. private DateTime vUserRegTime;
  44. protected void Page_Load(object sender, EventArgs e)
  45. {
  46. CheckUserPower("e");
  47. #region
  48. vAct = Request.QueryString["Act"] != null ? Request.QueryString["Act"] : "";
  49. if (Request.QueryString["Page"] != null && Request.QueryString["Page"].Trim() != "")
  50. {
  51. if (!int.TryParse(Request.QueryString["Page"], out vPage))
  52. {
  53. vPage = 1;
  54. }
  55. }
  56. if (Request.QueryString["ctype"] != null && Request.QueryString["ctype"].Trim() != "")
  57. {
  58. if (!int.TryParse(Request.QueryString["ctype"], out vUserType))
  59. {
  60. vUserType = 1;
  61. }
  62. }
  63. if (vUserType == 1)
  64. {
  65. vSQL = "(UserType=" + vUserType.ToString() + ") ";
  66. }
  67. else {
  68. vSQL = "(UserType>=2) ";
  69. }
  70. vKeyType = Request.QueryString["sKeyType"] != null ? Request.QueryString["sKeyType"] : "";
  71. vKey = Request.QueryString["sKey"] != null ? Request.QueryString["sKey"] : "";
  72. vKey = vKey.Replace("'", "");
  73. if (Request.QueryString["ID"] != null && Request.QueryString["ID"].Trim() != "")
  74. {
  75. if (!int.TryParse(Request.QueryString["ID"], out vID))
  76. {
  77. Response.Write("ID Error");
  78. Response.End();
  79. }
  80. }
  81. if (vKey.Length > 0)
  82. {
  83. if (vKeyType == "ID")
  84. {
  85. if (iNethinkCMS.Command.Command_Validate.IsNumber(vKey) == true)
  86. {
  87. vSQL += " and "+vKeyType + " = " + vKey + "";
  88. }
  89. else
  90. {
  91. vKey = "";
  92. }
  93. }
  94. else
  95. {
  96. vSQL += " and " + vKeyType + " Like '%" + vKey + "%'";
  97. }
  98. }
  99. #endregion
  100. this.mainID.Visible = false;
  101. this.guideID.Visible = false;
  102. switch (vAct)
  103. {
  104. case "guide":
  105. this.guideID.Visible = true;
  106. if (vID == 0)
  107. {
  108. this.navInfoID.InnerText = vNavInfo + "用户添加";
  109. this.Button_Submit.Click += new EventHandler(Button_Submit_Click_Add);
  110. }
  111. else
  112. {
  113. this.navInfoID.InnerText = vNavInfo + "用户修改";
  114. this.Button_Submit.Click += new EventHandler(Button_Submit_Click_Edit);
  115. }
  116. if (!IsPostBack)
  117. {
  118. if (Request.UrlReferrer != null)
  119. {
  120. ViewState["reJumpUrl"] = Request.UrlReferrer.AbsoluteUri;
  121. }
  122. Fun_SetValue(vID); //获取frm基本信息
  123. }
  124. this.txtUserChannelPowerAll.Attributes.Add("onclick", "change_channelpower();");
  125. break;
  126. case "delete":
  127. Fun_Delete(vID);
  128. break;
  129. default:
  130. if (vUserType == 1)
  131. {
  132. this.navInfoID.InnerText = vNavInfo + "系统用户管理";
  133. }
  134. else {
  135. this.navInfoID.InnerText = vNavInfo + "普通用户管理";
  136. }
  137. this.mainID.Visible = true;
  138. if (!IsPostBack)
  139. {
  140. this.sKeyType.SelectedValue = vKeyType;
  141. this.sKey.Text = vKey;
  142. }
  143. PageListInfo();
  144. break;
  145. }
  146. }
  147. #region mainID 列表
  148. protected void PageListInfo()
  149. {
  150. int vPageSize = int.Parse(siteConfig.PageListNum);
  151. int vRecordCount = bll.GetRecordCount(vSQL);
  152. Repeater.DataSource = bll.GetListByPage(vSQL, "ID Desc", (vPage - 1) * vPageSize, vPage * vPageSize);
  153. Repeater.DataBind();
  154. string pTemp = "";
  155. int vPageCount = 1;
  156. if (vRecordCount > 0)
  157. {
  158. vPageCount = (int)Math.Ceiling((double)vRecordCount / (double)vPageSize);
  159. pTemp = WebUI_PageList.GetPagingInfo_Manage(vPageCount, vRecordCount, vPage, vPageSize);
  160. }
  161. this.pagelist.InnerHtml = pTemp;
  162. this.iNoInfo.Visible = vRecordCount == 0 ? true : false;
  163. }
  164. protected void Button_Search_Click(object sender, EventArgs e)
  165. {
  166. Response.Redirect(Request.Path + "?skeytype=" + this.sKeyType.SelectedValue + "&skey=" + this.sKey.Text);
  167. }
  168. protected string Fun_UserType(object byUserType)
  169. {
  170. if (byUserType.ToString() == "1")
  171. {
  172. return "管理员";
  173. }
  174. else {
  175. int byUType = int.Parse(byUserType.ToString());
  176. if (byUType == 2)
  177. {
  178. return "普通用户";
  179. }
  180. else {
  181. return "VIP" + (byUType-2).ToString() + "用户";
  182. }
  183. }
  184. // return byUserType.ToString() == "1" ? "管理员" : "普通用户";
  185. }
  186. #endregion
  187. #region guideID 信息修改/添加
  188. private void Fun_SetValue(int byID)
  189. {
  190. BindDropdownList(this.txtUserChannelPower);
  191. if (byID == 0)
  192. {
  193. this.txtUserType.Value = vUserType.ToString();
  194. this.txtUserName.Text = "";
  195. this.txtUserPass.Text = "";
  196. this.txtUserTrueName.Text = "";
  197. this.txtUserEmail.Text = "";
  198. this.txtUserRegTime.Text = DateTime.Now.ToString();
  199. this.txtUserChannelPowerAll.Checked = true;
  200. }
  201. else
  202. {
  203. this.txtUserName.ReadOnly = true;
  204. model = bll.GetModel(byID);
  205. this.txtUserType.Value = model.UserType.ToString();
  206. this.DropDownListUType.SelectedValue = model.UserType.ToString();
  207. this.vUserType =int.Parse(model.UserType.ToString());
  208. this.txtUserName.Text = model.UserName;
  209. this.txtUserPass.Attributes["value"] = model.UserPass;
  210. this.txtUserTrueName.Text = model.UserTrueName;
  211. this.txtUserEmail.Text = model.UserEmail;
  212. this.txtUserRegTime.Text = model.UserRegTime.ToString();
  213. string vUserPower = "," + model.UserPower + ",";
  214. foreach (ListItem item in this.txtUserPower.Items)
  215. {
  216. if (vUserPower.IndexOf("," + item.Value + ",") > -1)
  217. {
  218. item.Selected = true;
  219. }
  220. }
  221. this.txtUserChannelPowerAll.Checked = model.UserChannelPower == "0" ? true : false;
  222. if (model.UserChannelPower != "0")
  223. {
  224. string tmpUserChannelPower = "," + model.UserChannelPower + ",";
  225. foreach (ListItem item in this.txtUserChannelPower.Items)
  226. {
  227. if (tmpUserChannelPower == ",0,")
  228. {
  229. item.Selected = true;
  230. }
  231. else if (tmpUserChannelPower.IndexOf("," + item.Value + ",") > -1)
  232. {
  233. item.Selected = true;
  234. }
  235. }
  236. }
  237. }
  238. }
  239. private bool Fun_GetValue()
  240. {
  241. if (this.txtUserType.Value.Trim().Length == 0)
  242. {
  243. MessageBox.Show(this, "请选择用户类型!");
  244. return false;
  245. }
  246. if (this.txtUserName.Text.Trim().Length < 4)
  247. {
  248. MessageBox.Show(this, "用户名不能少于4位!");
  249. return false;
  250. }
  251. if (this.txtUserPass.Text.Trim().Length < 6)
  252. {
  253. MessageBox.Show(this, "用户密码不能少于6位!");
  254. return false;
  255. }
  256. if (vUserType == 1)
  257. {
  258. vUserType = int.Parse(this.txtUserType.Value.Trim());
  259. }
  260. else {
  261. vUserType = int.Parse(this.DropDownListUType.SelectedValue);
  262. }
  263. vUserName = this.txtUserName.Text.Trim();
  264. vUserPass = this.txtUserPass.Text.Trim();
  265. vUserPower = Fun_Get_txtUserPower();
  266. vUserChannelPowerAll = this.txtUserChannelPowerAll.Checked;
  267. vUserTrueName = this.txtUserTrueName.Text.Trim();
  268. vUserEmail = this.txtUserEmail.Text.Trim();
  269. vUserRegTime = DateTime.Parse(this.txtUserRegTime.Text);
  270. if (vUserPass.Length != 32)
  271. {
  272. vUserPass = FormsAuthentication.HashPasswordForStoringInConfigFile(vUserPass, "md5").ToLower();
  273. }
  274. if (vUserChannelPowerAll == true)
  275. {
  276. vUserChannelPower = "0";
  277. }
  278. else
  279. {
  280. vUserChannelPower = Fun_Get_txtUserChannelPower();
  281. }
  282. return true;
  283. }
  284. private string Fun_Get_txtUserPower()
  285. {
  286. string vUserPowerInfo = "";
  287. foreach (ListItem item in this.txtUserPower.Items)
  288. {
  289. if (item.Selected)
  290. {
  291. vUserPowerInfo += item.Value + ",";
  292. }
  293. }
  294. if (vUserPowerInfo.Length > 0)
  295. {
  296. vUserPowerInfo = vUserPowerInfo.Substring(0, vUserPowerInfo.Length - 1);
  297. }
  298. return vUserPowerInfo;
  299. }
  300. private string Fun_Get_txtUserChannelPower()
  301. {
  302. string vUserChannelPowerInfo = "";
  303. foreach (ListItem item in this.txtUserChannelPower.Items)
  304. {
  305. if (item.Selected)
  306. {
  307. vUserChannelPowerInfo += item.Value + ",";
  308. }
  309. }
  310. if (vUserChannelPowerInfo.Length > 0)
  311. {
  312. vUserChannelPowerInfo = vUserChannelPowerInfo.Substring(0, vUserChannelPowerInfo.Length - 1);
  313. }
  314. return vUserChannelPowerInfo;
  315. }
  316. protected void Button_Submit_Click_Add(object sender, EventArgs e)
  317. {
  318. if (Fun_GetValue() == true)
  319. {
  320. if (bll.GetRecordCount("UserName = '" + vUserName + "'") > 0) //判断用户名是否重复
  321. {
  322. MessageBox.Show(this, "用户名 [" + vUserName + "] 已经存在!");
  323. return;
  324. }
  325. model.UserType = vUserType;
  326. model.UserName = vUserName;
  327. model.UserPass = vUserPass;
  328. model.UserTrueName = vUserTrueName;
  329. model.UserEmail = vUserEmail;
  330. model.UserPower = vUserPower;
  331. model.UserChannelPower = vUserChannelPower;
  332. model.UserRegTime = vUserRegTime;
  333. bll.Add(model);
  334. iNethinkCMS.BLL.BLL_iNethinkCMS_User.RefreshAllUserList();
  335. Response.Redirect(Request.Path);
  336. }
  337. }
  338. protected void Button_Submit_Click_Edit(object sender, EventArgs e)
  339. {
  340. if (Fun_GetValue() == true)
  341. {
  342. if (bll.GetRecordCount("ID = " + vID) == 0) //判断该ID是否被删除
  343. {
  344. MessageBox.ShowAndRedirect(this, "你所需要更新的记录 [" + vID + "] 不存在!", ViewState["reJumpUrl"].ToString());
  345. return;
  346. }
  347. if (bll.GetRecordCount("ID <> " + vID + " And UserName = '" + vUserName + "'") > 0) //判断用户名是否重复
  348. {
  349. MessageBox.Show(this, "用户名 [" + vUserName + "] 已经存在!");
  350. return;
  351. }
  352. model.ID = vID;
  353. model.UserType = vUserType;
  354. model.UserName = vUserName;
  355. model.UserPass = vUserPass;
  356. model.UserTrueName = vUserTrueName;
  357. model.UserEmail = vUserEmail;
  358. model.UserPower = vUserPower;
  359. model.UserChannelPower = vUserChannelPower;
  360. model.UserRegTime = vUserRegTime;
  361. bll.Update(model);
  362. iNethinkCMS.BLL.BLL_iNethinkCMS_User.RefreshAllUserList();
  363. Response.Redirect(ViewState["reJumpUrl"].ToString());
  364. }
  365. }
  366. #endregion
  367. #region Delete 数据删除
  368. protected void Fun_Delete(int byID)
  369. {
  370. if (bll.Delete(byID) == true)
  371. {
  372. Response.Redirect(Request.UrlReferrer.AbsoluteUri);
  373. }
  374. }
  375. #endregion
  376. #region 栏目列表输出
  377. /// <summary>
  378. /// 绑定DropDownList;
  379. /// </summary>
  380. protected void BindDropdownList(CheckBoxList byCheckBoxList)
  381. {
  382. DataTable dt = bll_column.GetList(0, "", "OrderNum Desc").Tables[0];
  383. if (dt.Rows.Count > 0)
  384. {
  385. foreach (DataRow row in dt.Rows)
  386. {
  387. if (row["FatherID"].ToString().Trim() == "0")//绑定根节点
  388. {
  389. byCheckBoxList.Items.Add(new ListItem(row["Name"].ToString(), row["CID"].ToString()));
  390. this.bindChildItem(byCheckBoxList, dt, row["CID"].ToString(), 1);
  391. }
  392. }
  393. }
  394. else
  395. {
  396. if (byCheckBoxList.ID == "txtCid")
  397. {
  398. byCheckBoxList.Items.Add(new ListItem("尚未添加任何栏目!", "0"));
  399. }
  400. }
  401. }
  402. protected void bindChildItem(CheckBoxList byCheckBoxList, DataTable dt, string id, int length)
  403. {
  404. DataRow[] rows = dt.Select("FatherID=" + id + "", "OrderNum Desc");
  405. for (int i = 0; i < rows.Length; i++)
  406. {
  407. byCheckBoxList.Items.Add(new ListItem(WebUI_Function.SpaceLength(length) + "├ " + rows[i]["Name"].ToString(), rows[i]["CID"].ToString()));
  408. this.bindChildItem(byCheckBoxList, dt, rows[i]["CID"].ToString(), length + 1);
  409. }
  410. }
  411. #endregion
  412. }
  413. }