/// <summary> /// 将当前登陆对象序列化为XML字符串 /// </summary> public static string SerializeAdmin(AdminInfo ainfo) { StringBuilder sbAdmin = new StringBuilder(); sbAdmin.AppendFormat("<admin AdminID=\"{0}\" GroupID=\"{1}\" AdminAccount=\"{2}\" AdminPwd=\"{3}\" AdminName=\"{4}\" State=\"{5}\" />", ainfo.AdminID, ainfo.GroupID, ainfo.AdminAccount, ainfo.AdminPwd, ainfo.AdminName, ainfo.State); return sbAdmin.ToString(); }
/// <summary> /// 读取cookie中的登陆管理员信息 /// </summary> public static AdminInfo GetCookiAdmin() { string masterStr = HttpContext.Current.Session["AdminInfo"] != null ? HttpContext.Current.Session["AdminInfo"].ToString() : ""; if (masterStr == "") { if ((HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName] != null) && (HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value != "")) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName].Value); masterStr = ticket.UserData; HttpContext.Current.Session.Add("AdminInfo", masterStr); } } if (masterStr == "") return null; XmlDocument xmldoc = new XmlDocument(); try { xmldoc.LoadXml(masterStr); } catch { return null; } AdminInfo ainfo = new AdminInfo(); ainfo.AdminID = int.Parse(xmldoc.DocumentElement.Attributes["AdminID"].Value); ainfo.GroupID = int.Parse(xmldoc.DocumentElement.Attributes["GroupID"].Value); ainfo.AdminAccount = xmldoc.DocumentElement.Attributes["AdminAccount"].Value; ainfo.AdminPwd = xmldoc.DocumentElement.Attributes["AdminPwd"].Value; ainfo.AdminName=xmldoc.DocumentElement.Attributes["AdminName"].Value; ainfo.State = int.Parse(xmldoc.DocumentElement.Attributes["State"].Value); return ainfo; }
/// <summary> /// 页面加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void AdminPageBase_Load(object sender, EventArgs e) { if (!Page.IsPostBack ) { //权限验证 if (Context.User.Identity.IsAuthenticated) { AdminInfo = Function.GetCookiAdmin(); //if (PermissionID != -1) //{ // Response.Clear(); // Response.Write("<script defer>window.alert('您没有权限进入本页!\\n请重新登录或与管理员联系');history.back();</script>"); // Response.End(); //} } else { FormsAuthentication.SignOut(); Session.Clear(); Session.Abandon(); Response.Clear(); Response.Write("<script defer>window.alert('您没有权限进入本页或当前登录用户已过期!\\n请重新登录或与管理员联系!');parent.location='" + virtualPath + "/Login.aspx';</script>"); Response.End(); } } }
/// <summary> /// 获得数据列表 /// </summary> public List<YK.Model.AdminInfo> DataTableToList(DataTable dt) { List<YK.Model.AdminInfo> modelList = new List<YK.Model.AdminInfo>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { YK.Model.AdminInfo model; for (int n = 0; n < rowsCount; n++) { model = new YK.Model.AdminInfo(); if(dt.Rows[n]["AdminID"]!=null && dt.Rows[n]["AdminID"].ToString()!="") { model.AdminID=int.Parse(dt.Rows[n]["AdminID"].ToString()); } if(dt.Rows[n]["GroupID"]!=null && dt.Rows[n]["GroupID"].ToString()!="") { model.GroupID=int.Parse(dt.Rows[n]["GroupID"].ToString()); } if(dt.Rows[n]["AdminAccount"]!=null && dt.Rows[n]["AdminAccount"].ToString()!="") { model.AdminAccount=dt.Rows[n]["AdminAccount"].ToString(); } if(dt.Rows[n]["AdminPwd"]!=null && dt.Rows[n]["AdminPwd"].ToString()!="") { model.AdminPwd=dt.Rows[n]["AdminPwd"].ToString(); } if(dt.Rows[n]["AdminName"]!=null && dt.Rows[n]["AdminName"].ToString()!="") { model.AdminName=dt.Rows[n]["AdminName"].ToString(); } if(dt.Rows[n]["State"]!=null && dt.Rows[n]["State"].ToString()!="") { model.State=int.Parse(dt.Rows[n]["State"].ToString()); } if(dt.Rows[n]["AdminDesc"]!=null && dt.Rows[n]["AdminDesc"].ToString()!="") { model.AdminDesc=dt.Rows[n]["AdminDesc"].ToString(); } if(dt.Rows[n]["LastLoginIP"]!=null && dt.Rows[n]["LastLoginIP"].ToString()!="") { model.LastLoginIP=dt.Rows[n]["LastLoginIP"].ToString(); } if(dt.Rows[n]["LastLoginTime"]!=null && dt.Rows[n]["LastLoginTime"].ToString()!="") { model.LastLoginTime=DateTime.Parse(dt.Rows[n]["LastLoginTime"].ToString()); } if(dt.Rows[n]["CreatetTime"]!=null && dt.Rows[n]["CreatetTime"].ToString()!="") { model.CreateTime=DateTime.Parse(dt.Rows[n]["CreatetTime"].ToString()); } modelList.Add(model); } } return modelList; }
/// <summary> /// 添加/修改管理员 /// </summary> public void AddAdminModel() { int adminid = RequestHelper.GetRequestInt("adminlist-adminid", 0); string adminaccount = RequestHelper.GetRequestStr("adminlist-adminaccount", ""); string adminpwd = RequestHelper.GetRequestStr("adminlist-adminpwd", ""); string adminname = RequestHelper.GetRequestStr("adminlist-adminname", ""); int groupid = RequestHelper.GetRequestInt("adminlist-groupid", 0); int state = RequestHelper.GetRequestInt("adminlist-state", 0); string admindesc = RequestHelper.GetRequestStr("adminlist-admindesc", ""); string ip = Function.GetIP(); AdminInfo ainfo = new AdminInfo(); ainfo.AdminAccount = adminaccount; ainfo.AdminName = adminname; ainfo.GroupID = groupid; ainfo.State = state; ainfo.AdminDesc = admindesc; ainfo.CreateAdminID = adminInfo.AdminID; ainfo.LastLoginIP = ip; ainfo.LastLoginTime = DateTime.Now; ainfo.CreateTime = DateTime.Now; if (adminid == 0)//添加 { ainfo.AdminPwd = DESEncrypt.Encrypt(adminpwd); admin.Add(ainfo); new SysLog().Add(new SysLogInfo("管理员管理", "添加", "添加账号为【" + adminaccount + "】的管理员信息", ip, adminInfo.AdminID, adminInfo.AdminName, DateTime.Now)); AjaxMsg.msg = "\"msg\":\"添加成功\""; } else { ainfo = admin.GetModel(adminid); ainfo.AdminName = adminname; ainfo.AdminDesc = admindesc; ainfo.GroupID = groupid; ainfo.State = state; admin.Update(ainfo); log.Add(new SysLogInfo("管理员管理", "修改", "修改管理帐号为【" + adminaccount + "】的管理员信息", ip, adminInfo.AdminID, adminInfo.AdminName, DateTime.Now)); AjaxMsg.msg = "\"msg\":\"修改成功\""; } }
/// <summary> /// 添加/修改管理员 /// </summary> public void ModifyAdminModel() { int adminid = RequestHelper.GetRequestInt("adminid", 0); string adminname = RequestHelper.GetRequestStr("adminname", ""); AdminInfo ainfo = new AdminInfo(); ainfo = admin.GetModel(adminid); if (ainfo != null)//添加 { ainfo.AdminName = adminname; admin.Update(ainfo); new SysLog().Add(new SysLogInfo("修改帐号信息", "修改", "添加账号为【" + ainfo.AdminAccount + "】的管理员信息", Function.GetIP(), adminInfo.AdminID, adminInfo.AdminName, DateTime.Now)); AjaxMsg.msg = "\"msg\":\"修改成功!\""; } else { AjaxMsg.msgOK = false; AjaxMsg.msg = "\"msg\":\"修改失败!\""; } }