public static List <admininfo> getAdminListPage(pageinfo item) { List <admininfo> adminlist = new List <admininfo>(); try { DataTable dt = pagehelper.getpagedt(item); if (dt != null) { foreach (DataRow reader in dt.Rows) { admininfo data = new admininfo(); data.adminid = TypeParse.DbObjToInt(reader["adminid"], 0); data.adminname = TypeParse.DbObjToString(reader["adminname"], ""); data.adddate = TypeParse.DbObjToDateTime(reader["adddate"], DateTime.Now); data.updatedate = TypeParse.DbObjToDateTime(reader["updatedate"], DateTime.Now); adminlist.Add(data); } } return(adminlist); } catch (Exception E) { throw new Exception(E.Message); } finally { } }
/// <summary> /// 读取系统管理员信息 /// </summary> /// <param name="adminid"></param> /// <returns></returns> public static admininfo getAdminInfo(int adminid) { SqlParameter[] parms = new SqlParameter[1]; parms[0] = new SqlParameter("@adminid", SqlDbType.Int); parms[0].Value = adminid; admininfo data = new admininfo(); string sql = "SELECT adminid,adminname,roleid,adddate,updatedate FROM SysAdmin WHERE adminid=@adminid"; try { SqlDataReader reader = SqlHelper.ExecuteReader(SqlHelper.connectionstring, CommandType.Text, sql, parms); if (reader.Read()) { data.adminid = TypeParse.DbObjToInt(reader["adminid"], 0); data.adminname = TypeParse.DbObjToString(reader["adminname"], ""); data.adddate = TypeParse.DbObjToDateTime(reader["adddate"], DateTime.Now); data.updatedate = TypeParse.DbObjToDateTime(reader["updatedate"], DateTime.Now); reader.Close(); reader.Dispose(); } return(data); } catch (Exception E) { throw new Exception(E.Message); } finally { } }
/// <summary> /// 添加新管理员 /// </summary> /// <param name="data"></param> /// <returns></returns> public static bool AddNewAdmin(admininfo data) { SqlParameter[] parms = new SqlParameter[5]; parms[0] = new SqlParameter("@adminname", SqlDbType.VarChar, 20); parms[0].Value = data.adminname; parms[1] = new SqlParameter("@adminpwd", SqlDbType.VarChar, 50); parms[1].Value = data.adminpwd; parms[2] = new SqlParameter("@adddate", SqlDbType.DateTime); parms[2].Value = data.adddate; parms[3] = new SqlParameter("@updatedate", SqlDbType.DateTime); parms[3].Value = data.updatedate; parms[4] = new SqlParameter("@roleid", SqlDbType.Int); parms[4].Value = data.roleid; string sql = "INSERT INTO SysAdmin (adminname,adminpwd,adddate,updatedate,roleid) " + "values (@adminname,@adminpwd,@adddate,@updatedate,@roleid)"; int result = 0; try { result = SqlHelper.ExecuteNonQuery(SqlHelper.connectionstring, CommandType.Text, sql, parms); } catch (Exception E) { throw new Exception(E.Message); } finally { } return(result > 0); }
/// <summary> /// 得到管理员信息列表 /// </summary> /// <param name="pdata"></param> /// <returns></returns> public static List <admininfo> getAdminList() { List <admininfo> adminlist = new List <admininfo>(); string sql = "SELECT adminid,adminname,roleid,adddate,updatedate FROM SysAdmin"; try { DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.connectionstring, CommandType.Text, sql).Tables[0]; if (dt != null) { foreach (DataRow reader in dt.Rows) { admininfo data = new admininfo(); data.adminid = TypeParse.DbObjToInt(reader["adminid"], 0); data.adminname = TypeParse.DbObjToString(reader["adminname"], ""); data.adddate = TypeParse.DbObjToDateTime(reader["adddate"], DateTime.Now); data.updatedate = TypeParse.DbObjToDateTime(reader["updatedate"], DateTime.Now); adminlist.Add(data); } } return(adminlist); } catch (Exception E) { throw new Exception(E.Message); } finally { } }
protected void Page_Load(object sender, EventArgs e) { admininfo item = new admininfo(); if (Request.QueryString["adminid"] != null) { string aid = Request.QueryString["adminid"].ToString(); item = admin.getAdminInfo(TypeParse.DbObjToInt(aid, 0)); adminnameHTML = item.adminname; } }
protected void Page_Load(object sender, EventArgs e) { if (Request.Cookies["g_adminid"] != null) { string userid = Request.Cookies["g_adminid"].Value.ToString(); int adminid = Int32.Parse(userid); admininfo data = admin.getAdminInfo(adminid); accountsHtml = "<span class=\"yellow\">" + data.adminname + "</span>"; } else { Response.Redirect("/Login/AdminLogin.aspx"); } }
public string editadminpwd(string newpwd, string adminid) { admininfo data = new admininfo(); data.adminid = TypeParse.DbObjToInt(adminid, 0); data.adminpwd = TextEncrypt.EncryptPassword(newpwd); data.updatedate = DateTime.Now; bool result = admin.updatepwd(data); if (result) { return("t"); } else { return("f"); } }
public async Task <ActionResult> AdminPage(FormCollection formCollection) { adminVM adminVM = new adminVM(); admininfo admininfo = new admininfo(); admininfo adminL = new admininfo(); string adminEmail = formCollection[1]; string adminPassword = formCollection[2]; admininfo.adminEmail = adminEmail; admininfo.adminPassword = adminPassword; var json = JsonConvert.SerializeObject(new adminVM { adminEmail = adminEmail, adminPassword = adminPassword }); var data = new StringContent(json, Encoding.UTF8, "application/json"); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Shared.ServerConfig.GetBaseUrl()); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage result = await client.PostAsync("admin/adminLogin/", data); var response = result.Content.ReadAsStringAsync().Result; Console.WriteLine(response); //adminL = JsonConvert.DeserializeObject<admininfo>(response); if (response == "null") { //means login credentials were wrong return(View("AdminLogin")); } else { //adminVM.admininfos = adminL; return(View("Index")); //succeed logging in } } }
public string addadmin(string pwd, string adminname) { admininfo data = new admininfo(); data.adminname = adminname; data.adminpwd = TextEncrypt.EncryptPassword(pwd); data.adddate = DateTime.Now; data.updatedate = DateTime.Now; data.roleid = 0; bool result = admin.AddNewAdmin(data); if (result) { return("t"); } else { return("f"); } }
/// <summary> /// 修改登录密码 /// </summary> /// <param name="item"></param> /// <returns></returns> public static bool updatepwd(admininfo item) { SqlParameter[] parms = new SqlParameter[2]; parms[0] = new SqlParameter("@npwd", SqlDbType.VarChar, 50); parms[0].Value = item.adminpwd; parms[1] = new SqlParameter("@AdminID", SqlDbType.Int); parms[1].Value = item.adminid; string sql = "UPDATE SysAdmin SET adminpwd=@npwd WHERE adminid=@adminid"; int result = 0; try { result = SqlHelper.ExecuteNonQuery(SqlHelper.connectionstring, CommandType.Text, sql, parms); } catch (Exception E) { throw new Exception(E.Message); } finally { } return(result > 0); }