/// <summary> /// 删除学生信息 /// </summary> /// <param name="category">下拉列表传值</param> /// <param name="keyWord">查询关键字</param> /// <param name="pageIndex">每页索引数</param> /// <returns></returns> public ActionResult DeleteStu(string category, string keyWord, int pageIndex = 1) { string id = Request.QueryString["id"];//获取学生id StuManager manager = new StuManager(); manager.DeleteStuById(id); //调用删除学生方法 List <Stu> stu = new List <Stu>(); //定义学生列表对象 //判断查询关键字是否为空 if (!String.IsNullOrEmpty(category)) { StuQuery cate = (StuQuery)Enum.Parse(typeof(StuQuery), category); stu = new StuManager().GetStu(cate, keyWord); } else { stu = new StuManager().GetStu(); } //定义一个pagedList对象 PagedList <Stu> pagedStus = new PagedList <Stu>(stu, pageIndex, pageSize); //提供教师查询方式的下拉框 //调用查询方式 SetDropDownList(category); ViewData["keyWord"] = keyWord; return(View("StuList", pagedStus)); }
public List <Stu> GetStu(StuQuery category, string keyWord) { List <Stu> list = new List <Stu>(); //category.CompareTo(StuQueryCategories.书名) string sql = "SELECT * FROM Stu where "; if (String.Compare(category.ToString(), "学号", true) == 0) { sql = sql + " StuID LIKE '%" + keyWord + "%'"; } else if (String.Compare(category.ToString(), "姓名", true) == 0) { sql = sql + " StuName LIKE '%" + keyWord + "%'"; } else if (String.Compare(category.ToString(), "年级", true) == 0) { sql = sql + " StuGrade LIKE '%" + keyWord + "%'"; } else if (String.Compare(category.ToString(), "班级", true) == 0) { sql = sql + " StuClass LIKE '%" + keyWord + "%'"; } //DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, "sp_QueryStus", category, keyWord); DataSet ds = SqlHelper.ExecuteDataset(SqlHelper.ConnString, CommandType.Text, sql); if (ds.Tables.Count > 0) { DataTable dt = ds.Tables[0]; foreach (DataRow row in dt.Rows) { Stu stu = new Stu(); stu.StuID = (int)row["StuID"]; stu.StuName = (string)row["StuName"]; stu.StuClass = (int)row["StuClass"]; stu.StuGrade = row["StuGrade"] != DBNull.Value ? (int)row["StuGrade"] : 0; stu.StuTel = (string)row["StuTel"]; list.Add(stu); } } return(list); }
/// <summary> /// 学生列表 /// </summary> /// <param name="category"></param> /// <param name="keyWord"></param> /// <param name="pageIndex"></param> /// <returns></returns> public ActionResult StuList(string category, string keyWord, int pageIndex = 1) { List <Stu> stu = new List <Stu>();//定义学生列表对象 //判断查询关键字是否为空 if (!String.IsNullOrEmpty(category)) { StuQuery cate = (StuQuery)Enum.Parse(typeof(StuQuery), category); stu = new StuManager().GetStu(cate, keyWord); } else { stu = new StuManager().GetStu(); } //定义一个PagedList对象 PagedList <Stu> pagedStus = new PagedList <Stu>(stu, pageIndex, pageSize); //提供学生查询方式的下拉框书籍 // SetDropDownList(category); ViewData["keyWord"] = keyWord; return(View("StuList", pagedStus)); }
public List <Stu> GetStu(StuQuery category, string keyWord) { return(new StuService().GetStu(category, keyWord)); }