/// <summary> /// 添加一个管理员 /// </summary> /// <param name="m">管理员</param> /// <returns>返回是否添加成功</returns> public Boolean AddMaster(Master m) { try { string sql = "insert into manager(role_id,role_type,user_name,user_pwd,user_pwd1,real_name,telephone,email)" + "values (@RoleId,@RoleType,@UserName,@UserPWD,@UserCzPWD,@RealName,@Phone,@Email)"; SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@RoleId",m.RoleId), new SqlParameter("@RoleType",m.RoleType), new SqlParameter("@UserName",m.UserName), new SqlParameter("@UserPWD", m.UserPWD), new SqlParameter("@UserCzPWD",m.UserCzPWD), new SqlParameter("@RealName",m.RealName), new SqlParameter("@Phone", string.IsNullOrEmpty(m.Phone)?"":m.Phone), new SqlParameter("@Email",string.IsNullOrEmpty(m.Email)?"":m.Email), }; return db.ExecuteNonQuery(sql, sp); } catch (SqlException ex) { throw new Exception("数据库异常!原因:" + ex.Message); } catch (Exception ex) { throw new Exception("未知异常!原因:" + ex.Message); } }
private void AddMasterLog(Master master) { manager_log ml = new manager_log(); ml.user_id = master.Id; ml.user_name = master.UserName; ml.action_type = "Login"; ml.note = master.RoleType + "登录"; ml.login_ip = BBRequest.GetIP(); ml.login_time = DateTime.Now; new MasterManager().AddMasterLog(ml); }
/// <summary> /// 添加一个管理员 /// </summary> /// <param name="m">管理员</param> /// <returns>返回是否添加成功</returns> public Boolean AddMaster(Master m) { return ms.AddMaster(m); }
/// <summary> /// 更新管理员信息 /// </summary> /// <param name="m">管理员</param> /// <returns>返回是否更新成功</returns> public Boolean UpdateMaster(Master m) { return ms.UpdateMaster(m); }
/// <summary> /// 更新管理员信息 /// </summary> /// <param name="m">管理员</param> /// <returns>返回是否更新成功</returns> public Boolean UpdateMaster(Master m) { try { string sql = "update manager set role_id=@RoleId,role_type=@RoleType,user_name=@UserName,user_pwd=@UserPWD,user_pwd1=@UserCzPWD,real_name=@RealName,telephone=@Phone,email=@Email,is_lock=@State where id=@Id"; SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@RoleId",m.RoleId), new SqlParameter("@RoleType",m.RoleType), new SqlParameter("@UserName",m.UserName), new SqlParameter("@UserPWD", m.UserPWD), new SqlParameter("@UserCzPWD",m.UserCzPWD), new SqlParameter("@RealName",m.RealName), new SqlParameter("@Phone", m.Phone), new SqlParameter("@Email",m.Email), new SqlParameter("@State", m.State), new SqlParameter("@Id",m.Id), }; return db.ExecuteNonQuery(sql, sp); } catch (SqlException ex) { throw new Exception("数据库异常!原因:" + ex.Message); } catch (Exception ex) { throw new Exception("未知异常!原因:" + ex.Message); } }
/// <summary> /// 根据用户名和密码获取用户 /// </summary> /// <param name="UserName"></param> /// <param name="CzPassWord"></param> /// <returns>返回用户信息</returns> public Master GetMasterByCz(string UserName, string CzPassWord) { Master master = null; try { string sql = "select * from manager where user_name=@UserName and user_pwd1=@CzPassWord"; SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@UserName",UserName), new SqlParameter("@CzPassWord",CzPassWord) }; using (SqlDataReader reder = db.GetReader(sql, sp)) { while (reder.Read()) { master = new Master((int)reder["id"], (int)reder["role_id"], reder["role_type"].ToString(), reder["user_name"].ToString(), reder["user_pwd"].ToString(), reder["user_pwd1"].ToString(), reder["real_name"].ToString(), reder["telephone"].ToString(), reder["email"].ToString(), (int)reder["is_lock"], (DateTime)reder["add_time"]); } } } catch (SqlException ex) { throw new Exception("数据库异常!原因:" + ex.Message); } catch (Exception ex) { throw new Exception("未知异常!原因:" + ex.Message); } return master; }
/// <summary> /// 通过分页获取管理员 /// </summary> /// <param name="PageSize">页大小</param> /// <param name="PageNum">页码</param> /// <param name="WhereStr">条件</param> /// <param name="OrderBy">排序</param> /// <returns></returns> public List<Master> GetAllMaster(int PageSize, int PageNum, string WhereStr, string OrderBy) { List<Master> list = new List<Master>(); try { SqlParameter[] sp = new SqlParameter[] { new SqlParameter("@PageSize",PageSize), new SqlParameter("@PageNum",PageNum), new SqlParameter("@TableName","manager"), new SqlParameter("@WhereStr",WhereStr), new SqlParameter("@OrderBy",OrderBy) }; using (SqlDataReader reder = db.GetReaderByProc("Proc_Page", sp)) { while (reder.Read()) { Master m = new Master((int)reder["id"], (int)reder["role_id"], reder["role_type"].ToString(), reder["user_name"].ToString(), reder["user_pwd"].ToString(), reder["user_pwd1"].ToString(), reder["real_name"].ToString(), reder["telephone"].ToString(), reder["email"].ToString(), (int)reder["is_lock"], (DateTime)reder["add_time"]); list.Add(m); } } return list; } catch (SqlException ex) { throw new Exception("数据库异常!原因:" + ex.Message); } catch (Exception ex) { throw new Exception("未知异常!原因:" + ex.Message); } }
public Master GetUser() { HttpSessionState Session = HttpContext.Current.Session; HttpResponse Response = HttpContext.Current.Response; Master master = new Master(); try { master = Session[Keys.SESSION_ADMIN_INFO] as Master; } catch (Exception) { Response.Write("<script>location.href='/Admin/Login';</script>"); } return master; }
public Boolean DoAddMaster() { if (Session[Keys.SESSION_ADMIN_INFO] == null) { return false; } else { Master master = Session[Keys.SESSION_ADMIN_INFO] as Master; if (rcm.GetRoleCompetence(master.RoleId, 1442)) { Master m = new Master(); int RoleId = int.Parse(Request["RoleId"]); if (RoleId > 0) { m.RoleId = RoleId; m.RoleType = mm.GetMasterRole(RoleId).RoleName; } else { return false; } m.State = Request["rblIsLock"] == "NoLock" ? 0 : 1; m.UserName = Request["UserName"]; if (Request["UserPWD"] == Request["UserPWDA"]) { m.UserPWD = DESEncrypt.Md5(Request["UserPWD"], 32); } else { return false; } if (Request["UserCzPWD"] == Request["UserCzPWDA"]) { m.UserCzPWD = DESEncrypt.Md5(Request["UserCzPWD"], 32); } else { return false; } m.RealName = Request["RealName"]; m.Phone = Request["Phone"]; m.Email = Request["Email"]; return mm.AddMaster(m); } else { return false; } } }
public ActionResult EditMaster(int M) { if (Session[Keys.SESSION_ADMIN_INFO] == null) { return RedirectToAction("Login", "Admin"); } else { Master master = Session[Keys.SESSION_ADMIN_INFO] as Master; if (rcm.GetRoleCompetence(master.RoleId, 1441)) { string RoleHtml = ""; Master m = new Master(); m = mm.GetMaster(M); ViewData["RoleId"] = m.RoleId; ViewData["UserName"] = m.UserName; ViewData["UserPWD"] = m.UserPWD; ViewData["UserCzPWD"] = m.UserCzPWD; ViewData["RealName"] = m.RealName; ViewData["Phone"] = m.Phone; ViewData["Email"] = m.Email; List<MasterRole> list = mm.GetAllMasterRole(); foreach (MasterRole mr in list) { RoleHtml += "<option value=\"" + mr.RoleId + "\">" + mr.RoleName + "</option>"; } ViewData["Role"] = RoleHtml; ViewData["Function"] = "UpdateData('/Master/UpdateMaster')"; ViewData["MId"] = M; return View(); } else { return RedirectToAction("Login", "Admin"); } } }
public Master GetUser(HttpContext context) { Master master = new Master(); try { master = context.Session[Keys.SESSION_ADMIN_INFO] as Master; } catch (Exception) { context.Response.Write("<script>top.location.href='/Admin/Login';</script>"); } return master; }