using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StudentSystem.DAL
{
using StudentSystem.Entity;
using System.Data.SqlClient;
public class StudentDAL
{
/// <summary>
/// 添加
/// </summary>
/// <param name="StudentName"></param>
/// <param name="Gender"></param>
/// <param name="ClassesCode"></param>
/// <returns></returns>
public int StudentAdd(Student student)
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@StudentName",student.StudentName),
new SqlParameter("@Gender",student.Gender),
new SqlParameter("@ClassesCode",student.ClassesCode)
};
return DBHelper.ExecuteNonQuery("exec p_StudentAdd @StudentName,@Gender,@ClassesCode",parms);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="ID"></param>
/// <returns></returns>
public int StudentDel(int ID )
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@ID",ID)
};
return DBHelper.ExecuteNonQuery("exec p_StudentDel @ID", parms);
}
/// <summary>
/// 显示+分页+查询
/// </summary>
/// <param name="PageIndex"></param>
/// <param name="Pagesize"></param>
/// <param name="PageCount"></param>
/// <param name="StudentName"></param>
/// <param name="ClassesCode"></param>
/// <returns></returns>
public PageBox GetStudentList(int PageIndex,int Pagesize,string StudentName,string ClassesCode, string SchoolCode)
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@PageIndex",PageIndex),
new SqlParameter("@Pagesize",Pagesize),
new SqlParameter("@PageCount",System.Data.SqlDbType.Int),
new SqlParameter("@StudentName",StudentName),
new SqlParameter("@ClassesCode",ClassesCode),
new SqlParameter("@SchoolCode",SchoolCode)
};
parms[2].Direction = System.Data.ParameterDirection.Output;
PageBox pagebox = new PageBox();
pagebox.CurrentPage = PageIndex;
var page = DBHelper.ExecuteObjects<Student>("exec p_GetStudentList @PageIndex,@Pagesize,@PageCount output,@StudentName,@ClassesCode,@SchoolCode", parms);
pagebox.TotlePage = (int)parms[2].Value;
pagebox.Data = page;
return pagebox;
}
/// <summary>
/// 根据ID 查询信息
/// </summary>
/// <param name="ID"></param>
/// <returns></returns>
public List<Student> GetStudentListByID(int ID )
{
return DBHelper.ExecuteObjects<Student>("exec p_GetStudentListByID @ID", new SqlParameter("@ID", ID));
}
/// <summary>
/// 修改保存
/// </summary>
/// <param name="StudentName"></param>
/// <param name="Gender"></param>
/// <param name="ClassesCode"></param>
/// <param name="ID"></param>
/// <returns></returns>
public int StudentUpdate(Student student )
{
SqlParameter[] parms = new SqlParameter[]
{
new SqlParameter("@StudentName",student.StudentName),
new SqlParameter("@Gender",student.Gender),
new SqlParameter("@ClassesCode",student.ClassesCode),
new SqlParameter("@ID",student.ID)
};
return DBHelper.ExecuteNonQuery("EXEC dbo.p_UpdateStudentList @StudentName,@Gender,@ClassesCode,@ID",parms);
}
}
}
public class PageBox { /// <summary> /// 当前页 /// </summary> public int CurrentPage { get; set; } /// <summary> /// 总页数 /// </summary> public int TotlePage { get; set; } /// <summary> /// 要显示的数据 /// </summary> public object Data { get; set; } } |