学生管理系统
来源:互联网 发布:js中new date 的参数 编辑:程序博客网 时间:2024/04/30 05:55
表示层UIBLLDAL
namespace MySchool03.UI{ public class StudentDAL { //方法1 //添加学生信息 // LoginPwd, StudentName, Gender, GradeId, Phone, Address, Birthday, Email) public bool AddStudnetAgo(Studnet stu) { bool flag = false; string str = SqlHelper.constr; SqlConnection con = new SqlConnection(str); string sql = "insert into student (LoginPwd, StudentName, Gender, " + " GradeId, Phone, Address, Birthday, Email) values ('" + stu.LoginPwd + "','" +stu.StudentName+ "','" + stu.Gender + "','" + stu.GradeId + "','" + stu.Phone + "','" + stu.Address + "','" + stu.Birthday + "','" + stu.Email + "')"; SqlCommand command = new SqlCommand(sql, con); con.Open(); int count = command.ExecuteNonQuery(); con.Close(); if (count > 0) { flag = true; } return flag; } //方法2 //添加学生信息 public bool AddStudnet(string LoginPwd, string studentName, string Gender, int GradeId, string Phone, string Address, DateTime Birthday, string Email) { bool flag = false; string sql = "insert into student (LoginPwd, StudentName, Gender, " + " GradeId, Phone, Address, Birthday, Email) values ('" + LoginPwd + "','" + studentName + "','" + Gender + "','" + GradeId + "','" + Phone + "','" + Address + "','" + Birthday + "','" + Email + "')"; int count = SqlHelper.ExecuteNonQuery(sql); if (count > 0) { flag = true; } return flag; } //--------------显示方法 //Form4 public DataTable GetAllStudent() { //写访问数据库的代码 string str = SqlHelper.constr; SqlConnection con = new SqlConnection(str); //数据库 表名 列名 关键字 不区分大小写 //数据库记录 区分大小写 列如:"sz" "SZ"是不一样的 string sql = "select * from Student"; SqlCommand command = new SqlCommand(sql, con); //()里是方法重载 SqlDataAdapter da = new SqlDataAdapter(sql, con); //SqlDataAdapter自动管理con.Open打开数据库 DataSet ds = new DataSet(); try { da.Fill(ds, "随意写不必须写Student"); } catch (DivideByZeroException e) { throw new DivideByZeroException(""); } catch (SqlException e) //数据库异常 { throw new Exception("数据获取异常!!!!!!!!!!!!"); } catch (Exception e) { throw new Exception("类型转换异常!!!!!!!!!!!!"); } return ds.Tables[0]; } //Form6传值练习 public DataTable GetAllStudent123(string name) { //写访问数据库的代码 string str = SqlHelper.constr; SqlConnection con = new SqlConnection(str); //数据库 表名 列名 关键字 不区分大小写 //数据库记录 区分大小写 列如:"sz" "SZ"是不一样的 string sql = "select StudentName from Student where studentName like '%'+@name+'%'"; SqlParameter para = new SqlParameter("@name", name); SqlCommand command = new SqlCommand(sql, con); command.Parameters.Add(para); SqlDataAdapter da = new SqlDataAdapter(sql, con); da.SelectCommand = command; DataSet ds = new DataSet(); da.Fill(ds, "stuInfo"); return ds.Tables["stuInfo"]; } //From6 通过存储过程查 public DataTable GetAllStudentByProcedure(string name,int gid) { //写访问数据库的代码 string str = SqlHelper.constr; SqlConnection con = new SqlConnection(str); //数据库 表名 列名 关键字 不区分大小写 //数据库记录 区分大小写 列如:"sz" "SZ"是不一样的 // string sql = "select * from Student where studentName like '%'+@name+'%'"; string sql = "usp_0319"; SqlCommand command = new SqlCommand(sql, con); //SqlParameter para = new SqlParameter("@name", name); //SqlParameter para2 = new SqlParameter("@GradeId",gid); //command.Parameters.Add(para); //command.Parameters.Add(para2); //或 SqlParameter[] paras = { new SqlParameter("@name", name), new SqlParameter("@GradeId", gid) }; command.Parameters.AddRange(paras); //编译器 是调度后台的存储过程 command.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(sql, con); da.SelectCommand = command; DataSet ds = new DataSet(); da.Fill(ds, "stuInfo"); return ds.Tables["stuInfo"]; } //输出参数 //From6 通过存储过程查 public DataTable GetAllStudentoutProcedure(string gender, int gid, out int total, out int name) { //写访问数据库的代码 string str = SqlHelper.constr; SqlConnection con = new SqlConnection(str); string sql = "usp_0320"; SqlCommand command = new SqlCommand(sql, con); SqlParameter[] paras = { new SqlParameter("@gender", gender), new SqlParameter("@genderid", gid), new SqlParameter("@countnum",SqlDbType.Int) , new SqlParameter("@return",SqlDbType.Int) }; command.Parameters.AddRange(paras); paras[2].Direction = ParameterDirection.Output; paras[3].Direction = ParameterDirection.ReturnValue; //编译器 是调度后台的存储过程 command.CommandType = CommandType.StoredProcedure; SqlDataAdapter da = new SqlDataAdapter(sql, con); da.SelectCommand = command; DataSet ds = new DataSet(); da.Fill(ds, "stuInfo"); //输出参数 拿到参数的值 total = Convert.ToInt32(paras[2].Value); // Console.WriteLine(total); name = Convert.ToInt32(paras[3].Value); // Console.WriteLine(myreturn); return ds.Tables["stuInfo"]; } //方法1 //按名字查询 public DataTable SelectStudentNameAgo(string name) { string con = SqlHelper.constr; //string sql = "select * from Student where StudentName='" + name + "'"; string sql = @"SELECT TOP 1000 [StudentNo] ,[LoginPwd] ,[StudentName] ,[Gender] ,[GradeId] ,[Phone] ,[Address] ,[Birthday] ,[Email] ,[MyTT] FROM student where studentname like '%" + name + "%'"; SqlConnection conn = new SqlConnection(con); SqlDataAdapter sqa = new SqlDataAdapter(sql, conn); DataSet ds = new DataSet(); sqa.Fill(ds, "info"); return ds.Tables["info"]; } //方法2 //按名字查询 public DataTable SelectStudentName(string name) { string sql = @"SELECT TOP 1000 [StudentNo] ,[LoginPwd] ,[StudentName] ,[Gender] ,[GradeId] ,[Phone] ,[Address] ,[Birthday] ,[Email] ,[MyTT] FROM student where studentname like '%" + name + "%'"; return SqlHelper.ExecuteDataTable(sql); } //方法1 //按年级查询 public DataTable SearchAgo(string gradeid) { string str = SqlHelper.constr; string sql = @"select * from student where GradeId='" + gradeid + "'"; SqlConnection con = new SqlConnection(str); con.Open(); SqlDataAdapter da = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); da.Fill(ds, "Info"); return ds.Tables["Info"]; } //方法2 //按年级查询 public DataTable Search(string gradeid) { ; string sql = @"select * from student where GradeId='" + gradeid + "'"; return SqlHelper.ExecuteDataTable(sql); } //方法一 // 删除的方法 public bool deleteAgo(string studentNo) { bool flag = false; string str = SqlHelper.constr; SqlConnection con = new SqlConnection(str); string sql = @"delete from student where StudentNo='" + studentNo + "'"; con.Open(); SqlCommand com = new SqlCommand(sql, con); int count = com.ExecuteNonQuery(); //con.Close(); if (count > 0) { flag = true; } return flag; } //方法二 // 删除的方法 public bool delete(string studentNo) { bool flag = false; string sql = @"delete from student where StudentNo='" + studentNo + "'"; int count = SqlHelper.ExecuteNonQuery(sql); if (count > 0) { flag = true; } return flag; } //修改方法 public bool Update(string pwd, string gender, string name, string gradeid, string phone, string address, string email) { bool flag = false; string str = SqlHelper.constr; SqlConnection con = new SqlConnection(str); string sql = @"update student set LoginPwd='" + pwd + "',Gender='" + gender + "',StudentName='" + name + "',GradeId='" + gradeid + "',Phone='" + phone + "',Address='" + address + "',Email='" + email + "'"; con.Open(); SqlCommand com = new SqlCommand(sql, con); int count = com.ExecuteNonQuery(); if (count > 0) { flag = true; } return flag; } //方法一 public bool GetAllStudentAgo(string studentName, string loginPwd) { bool flag = false; string str = SqlHelper.constr; SqlConnection con = new SqlConnection(str); string sql = "select count(*) from Student where studentName='" + studentName + "'and LoginPwd='" + loginPwd + "'"; SqlCommand command = new SqlCommand(sql, con); try { con.Open(); int count = Convert.ToInt32(command.ExecuteScalar()); if (count > 0) { flag = true; } } catch (Exception ex) { Console.WriteLine("错误" + ex.Message); } finally { con.Close(); } return flag; } //方法二 public bool GetAllStudent(string studentName, string loginPwd) { bool flag = false; string sql = "select count(*) from Student where studentName='" + studentName + "'and LoginPwd='" + loginPwd + "'"; int count = Convert.ToInt32(SqlHelper.ExecuteScalar(sql)); if (count > 0) { flag = true; } return flag; } //Day03 public DataTable Day03GetAllStudent(string Name,string gid,string subjectName) { //////写访问数据库的代码 ////string str = SqlHelper.constr; ////SqlConnection con = new SqlConnection(str); ////string sql = "usp_0319"; ////SqlCommand command = new SqlCommand(sql, con); ////SqlParameter[] paras = ////{ //// new SqlParameter("@name", name), //// new SqlParameter("@GradeName", gid), //// new SqlParameter("@SubjectName",subjectName), ////}; ////command.Parameters.AddRange(paras); //////编译器 是调度后台的存储过程 ////command.CommandType = CommandType.StoredProcedure; ////SqlDataAdapter da = new SqlDataAdapter(sql, con); ////da.SelectCommand = command; ////DataSet ds = new DataSet(); ////da.Fill(ds, "stuInfo"); ////return ds.Tables["stuInfo"];//--------------------------- ----------------------------------------------------------------------------------------------------------- string str = SqlHelper.constr; //string sql = "select studentName,subjectName,studentResult,classHour from Student,subject,grade,result " + // " where student.gradeid=subject.gradeid and subject.subjectid=grade.gradeid and" + // " grade.gradeid=result.id and studentName like '%'" + name + "'%' and grade.gradeid in(select gradeid " + // "from grade where gradename" + gid + ")" + gid + "and subjectname" + subjectName; string sql = @"select studentName,subjectName,studentResult,classHour from Student,subject,grade,result where student.gradeid=subject.gradeid and subject.subjectid=grade.gradeid and grade.gradeid=result.id and StudentName like '%'+@StudentName+'%' and grade.Gradeid in (Select Gradeid from Grade where Gradename=@Gradename) and subjectname=@SubjectName"; using (SqlConnection con = new SqlConnection(str)) { using (SqlDataAdapter da = new SqlDataAdapter(sql, con)) { SqlParameter[] para = { new SqlParameter("@StudentName", Name), new SqlParameter("@Gradename", gid), new SqlParameter("@SubjectName",subjectName), }; SqlCommand com = new SqlCommand(sql, con); com.Parameters.AddRange(para); da.SelectCommand = com; DataSet ds = new DataSet(); da.Fill(ds, "info"); return ds.Tables["info"]; } } }//---------------------------------------------------------------------------------------------------------------------------------------------- //得到年级绑定 public DataTable GetGradeName() { string str = SqlHelper.constr; string sql = "select Gradeid,GradeName from Grade"; using (SqlConnection con = new SqlConnection(str)) { using (SqlDataAdapter sqa = new SqlDataAdapter(sql, con)) { DataSet ds = new DataSet(); sqa.Fill(ds, "info"); return ds.Tables["info"]; } } } //得到kemv绑定 public DataTable GetSubjectName() { string str = SqlHelper.constr; string sql = "select SubjectId,subjectName from subject"; using (SqlConnection con = new SqlConnection(str)) { using (SqlDataAdapter sqa = new SqlDataAdapter(sql, con)) { DataSet ds = new DataSet(); sqa.Fill(ds, "info"); return ds.Tables["info"]; } } } }}
namespace MySchool.BLL{ public class StudentBLL { StudentDAL stuDAL=new StudentDAL(); //方法1 //添加学生信息 // LoginPwd, StudentName, Gender, GradeId, Phone, Address, Birthday, Email) public bool AddStudnetAgo(Studnet stu) { return stuDAL.AddStudnetAgo(stu); } //方法2 //添加学生信息 public bool AddStudnet(string LoginPwd, string studentName, string Gender, int GradeId, string Phone, string Address, DateTime Birthday, string Email) { return stuDAL.AddStudnet(LoginPwd, studentName, Gender, GradeId, Phone, Address, Birthday, Email); } //--------------显示方法 //Form4 public DataTable GetAllStudent() { return stuDAL.GetAllStudent(); } //Form6传值练习 public DataTable GetAllStudent123(string name) { return stuDAL.GetAllStudent123(name); } //From6 通过存储过程查 public DataTable GetAllStudentByProcedure(string name, int gid) { return stuDAL.GetAllStudentByProcedure(name, gid); } //输出参数 //From6 通过存储过程查 public DataTable GetAllStudentoutProcedure(string gender, int gid, out int total, out int name) { return stuDAL.GetAllStudentoutProcedure(gender, gid,out total,out name); } //方法2 //按名字查询 public DataTable SelectStudentName(string name) { return stuDAL.SelectStudentName(name); } //方法2 //按年级查询 public DataTable Search(string gradeid) { return stuDAL.Search(gradeid); } //方法二 // 删除的方法 public bool delete(string studentNo) { return stuDAL.delete(studentNo); } //修改方法 public bool Update(string pwd, string gender, string name, string gradeid, string phone, string address, string email) { return stuDAL.Update(pwd, gender, name, gradeid, phone, address,email); } //方法二 public bool GetAllStudent(string studentName, string loginPwd) { return stuDAL.GetAllStudent(studentName, loginPwd); } //Day03 public DataTable Day03GetAllStudent(string Name, string gid, string subjectName) { return stuDAL.Day03GetAllStudent(Name, gid, subjectName); } //得到年级绑定 public DataTable GetGradeName() { return stuDAL.GetGradeName(); } //得到kemv绑定 public DataTable GetSubjectName() { return stuDAL.GetSubjectName(); } }}
等等。。。。。。省略代码
0 0
- 一个学生管理系统
- 学生同学录管理系统
- 学生管理系统
- 销售学生管理系统
- 学生通讯管理系统
- 学生管理系统
- 学生管理系统
- 学生管理系统
- 学生管理系统
- 学生学籍管理系统
- 学生管理系统
- 学生通讯录管理系统
- 学生管理系统
- 学生管理系统源程序
- 学生管理系统源程序
- 学生管理系统实现
- 学生管理系统
- 学生管理系统
- kali Linux中安装谷歌中文输入法
- 关于C的小程序-3
- Android Arcgis入门(一) Arcgis开发配置
- javascript点击空白位置关闭弹出层/点击包含指定区域但不属于指定区域的部分响应点击事件
- [问题]第一行代码_生命周期_you need to use a theme.appcompat theme (or descendant) with this activity
- 学生管理系统
- 题目1188:约瑟夫环
- 美团实习生面试题
- 练习系统 实验四 red and black
- SSH整合问题
- CentOS 6.5上升级openssh7.5
- DB2客户端连接不上db2默认端口50000
- L1-001. Hello World
- 蓝桥杯 数组排序去重