protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { model.LoginName = Request.Form["User"]; model.Password = Request.Form["password"]; model.Name = Request.Form["contact"]; model.Phone = Request.Form["tel"]; bool success = false; if (string.IsNullOrEmpty(Request.Form["Id"])) { if (Adminbll.Add(model) != 0) { success = true; } } else { model.Id = Convert.ToInt32(Request.Form["Id"]); success = Adminbll.Update(model); } if (success) { Response.Redirect("/Admin/GetAdminInfo.aspx"); } else { msg = "添加失败"; } } else { string action = Request.QueryString["action"]; if (action == "update") { int id1 = Convert.ToInt32(Request.QueryString["id"]); model = Adminbll.GetModel(id1); id = model.Id.ToString(); Name = model.LoginName; password = model.Password; phone = model.Phone; Turename = model.Name; btnName = "更新"; } } }
/* /// <summary> /// 分页获取数据列表 /// </summary> public DataSet GetList(int PageSize,int PageIndex,string strWhere) { SqlParameter[] parameters = { new SqlParameter("@tblName", SqlDbType.VarChar, 255), new SqlParameter("@fldName", SqlDbType.VarChar, 255), new SqlParameter("@PageSize", SqlDbType.Int), new SqlParameter("@PageIndex", SqlDbType.Int), new SqlParameter("@IsReCount", SqlDbType.Bit), new SqlParameter("@OrderType", SqlDbType.Bit), new SqlParameter("@strWhere", SqlDbType.VarChar,1000), }; parameters[0].Value = "Admin"; parameters[1].Value = "Id"; parameters[2].Value = PageSize; parameters[3].Value = PageIndex; parameters[4].Value = 0; parameters[5].Value = 0; parameters[6].Value = strWhere; return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds"); }*/ #endregion BasicMethod #region ExtensionMethod public shaoqi.Model.Admin GetmodleByName(string name) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,LoginName,Password,Name,Phone from Admin "); strSql.Append(" where LoginName=@LoginName"); SqlParameter[] parameters = { new SqlParameter("@LoginName", SqlDbType.Char,40) }; parameters[0].Value = name; shaoqi.Model.Admin model = new shaoqi.Model.Admin(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }
/// <summary> /// 得到一个对象实体 /// </summary> public shaoqi.Model.Admin DataRowToModel(DataRow row) { shaoqi.Model.Admin model = new shaoqi.Model.Admin(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["LoginName"] != null) { model.LoginName = row["LoginName"].ToString(); } if (row["Password"] != null) { model.Password = row["Password"].ToString(); } if (row["Name"] != null) { model.Name = row["Name"].ToString(); } if (row["Phone"] != null) { model.Phone = row["Phone"].ToString(); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public shaoqi.Model.Admin GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,LoginName,Password,Name,Phone from Admin "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; shaoqi.Model.Admin model = new shaoqi.Model.Admin(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }