/// <summary> /// 更新一条数据 /// </summary> /// <param name="model">Admin对象</param> /// <returns>影响行数</returns> public int Update(ClassLibrary.Model.Admin model) { StringBuilder strSql = new StringBuilder(); strSql.Append(string.Format("UPDATE {0} SET ", table)); strSql.Append("UserName=@UserName,"); strSql.Append("Password=@Password,"); strSql.Append("Power=@Power,"); strSql.Append("CreatedTime=@CreatedTime"); strSql.Append(" WHERE ID=@ID"); SqlParameter[] parameters = { new SqlParameter("@ID", SqlDbType.Int, 4), new SqlParameter("@UserName", SqlDbType.NVarChar, 60), new SqlParameter("@Password", SqlDbType.NVarChar, 64), new SqlParameter("@Power", SqlDbType.NVarChar, 2000), new SqlParameter("@CreatedTime", SqlDbType.DateTime, 8) }; parameters[0].Value = model.ID; parameters[1].Value = model.UserName; parameters[2].Value = model.Password; parameters[3].Value = model.Power; parameters[4].Value = model.CreatedTime; return(SQLHelper.Execute(strSql.ToString(), parameters)); }
private void EditAdmin() { ClassLibrary.Model.Admin adminModel = new ClassLibrary.Model.Admin(); adminModel.ID = adminId; if (string.IsNullOrEmpty(Request.Form["UserName"])) { Response.Write("<script>alert('请输入管理员账号!');history.back(-1);</script>"); return; } else { adminModel.UserName = Request.Form["UserName"]; } if (!string.IsNullOrEmpty(Request.Form["OldPassword"])) { if (Function.MD5(Request.Form["OldPassword"]) == Request.Form["Password"]) { if (!string.IsNullOrEmpty(Request.Form["NewPassword"])) { adminModel.Password = Function.MD5(Request.Form["NewPassword"]); } else { Response.Write("<script>alert('请输入新密码!');history.back(-1);</script>"); return; } } else { Response.Write("<script>alert('旧密码错误!');history.back(-1);</script>"); return; } } else { Response.Write("<script>alert('请输入旧密码!');history.back(-1);</script>"); return; } if (adminBLL.Update(adminModel) > 0) { Function.goMessagePage("修改管理员密码", "操作成功", "Admin/AdminList.aspx"); } else { Function.goMessagePage("修改管理员密码", "操作失败,请稍后再试", "Admin/AdminList.aspx"); } }
public void AddLinks() { ClassLibrary.BLL.Admin adminBLL = new ClassLibrary.BLL.Admin(); ClassLibrary.Model.Admin adminModel = new ClassLibrary.Model.Admin(); if (string.IsNullOrEmpty(Request.Form["UserName"])) { Response.Write("<script>alert('请输入管理员账号!');history.back(-1);</script>"); return; } else { adminModel.UserName = Request.Form["UserName"]; } if (!string.IsNullOrEmpty(Request.Form["Password"])) { if (Request.Form["Password"] == Request.Form["RePassword"]) { adminModel.Password = Function.MD5(Request.Form["Password"]); } else { Response.Write("<script>alert('管理员密码和确认密码不一致!');history.back(-1);</script>"); return; } } else { Response.Write("<script>alert('请输入管理员密码!');history.back(-1);</script>"); return; } if (adminBLL.Add(adminModel) > 0) { Function.goMessagePage("添加管理员", "操作成功", "Admin/AdminList.aspx"); } else { Function.goMessagePage("添加管理员", "操作失败,请稍后再试", "Admin/AdminList.aspx"); } }
/// <summary> /// 增加一条数据 /// </summary> /// <param name="model">Admin对象</param> public int Add(ClassLibrary.Model.Admin model) { StringBuilder strSql = new StringBuilder(); strSql.Append(string.Format("INSERT INTO {0}(", table)); strSql.Append("UserName,Password,Power,CreatedTime"); strSql.Append(") VALUES ("); strSql.Append("@UserName,@Password,@Power,@CreatedTime)"); SqlParameter[] parameters = { new SqlParameter("@UserName", SqlDbType.NVarChar, 60), new SqlParameter("@Password", SqlDbType.NVarChar, 64), new SqlParameter("@Power", SqlDbType.NVarChar, 2000), new SqlParameter("@CreatedTime", SqlDbType.DateTime, 8) }; parameters[0].Value = model.UserName; parameters[1].Value = model.Password; parameters[2].Value = model.Power; parameters[3].Value = model.CreatedTime; return(SQLHelper.Execute(strSql.ToString(), parameters)); }
/// <summary> /// 得到一个对象实体 /// </summary> /// <param name="ID">主键ID</param> /// <returns>Admin对象</returns> public ClassLibrary.Model.Admin GetModel(int ID) { StringBuilder strSql = new StringBuilder(); strSql.Append("SELECT ID,UserName,Password,Power,CreatedTime"); strSql.Append(" FROM "); strSql.Append(table); strSql.Append(string.Format(" WHERE {0}=@{0}", pk)); SqlParameter[] parameters = { new SqlParameter("@" + pk, SqlDbType.Int, 4) }; parameters[0].Value = ID; ClassLibrary.Model.Admin model = new ClassLibrary.Model.Admin(); DataTable dt = SQLHelper.Query(strSql.ToString(), parameters); model.ID = ID; if (dt.Rows.Count > 0) { if (dt.Rows[0]["UserName"] != DBNull.Value) { model.UserName = Convert.ToString(dt.Rows[0]["UserName"]); } if (dt.Rows[0]["Password"] != DBNull.Value) { model.Password = Convert.ToString(dt.Rows[0]["Password"]); } if (dt.Rows[0]["Power"] != DBNull.Value) { model.Power = Convert.ToString(dt.Rows[0]["Power"]); } if (dt.Rows[0]["CreatedTime"] != DBNull.Value) { model.CreatedTime = Convert.ToDateTime(dt.Rows[0]["CreatedTime"]); } } return(model); }
private void binderInfo() { ClassLibrary.Model.Admin model = bll.GetModel(adminID); adminName = model.UserName; adminPower = model.Power; }