实验目的:

使用SQL Server 和Visual Studio实现一个学生信息管理系统。

实验内容:

设计并实现“学生信息管理系统”,该系统的主要任务为管理学生的信息。用户为学生和系统管理员。
在进入页面之前需要进行登录,在学生在学号和密码正确的情况下进入系统,管理员在工号和密码对应的情况下进入系统。
管理员可以增加、删除、修改、查询管理员的个人信息,增加、删除、修改、查询学生的个人信息,添加、查询课程,以及对学生的成绩进行录入、统计、修改和查询,还可以修改个人的密码。
学生可以查询学习成绩,修改个人的密码,还可以查询、选择课程。

代码:

数据准备:

DROP DATABASE IF EXISTS student_information_management_system;  CREATE DATABASE student_information_management_system;  USE student_information_management_system;DROP TABLE IF EXISTS Student
DROP TABLE IF EXISTS Manage
DROP TABLE IF EXISTS Course
DROP TABLE IF EXISTS SCCREATE TABLE Student          (  学号 NCHAR(10) PRIMARY KEY NOT NULL,        /* 列级完整性约束条件,学号是主码*/                  姓名 NCHAR(10) NOT NULL,          性别 NCHAR(2) CHECK(性别 IN ('男','女')) NOT NULL,出生日期 CHAR(10),民族 NCHAR(10),专业 NCHAR(20) NOT NULL,年级 NCHAR(4) NOT NULL,籍贯 NCHAR(25),手机号码 CHAR(11)NOT NULL,密码 NCHAR(35) NOT NULL,); CREATE TABLE Manage          (    工号 NCHAR(10) PRIMARY KEY NOT NULL,        /* 列级完整性约束条件,学号是主码*/                  姓名 NCHAR(10) NOT NULL,          性别 NCHAR(2) CHECK(性别 IN ('男','女'))NOT NULL,出生日期 NCHAR(10),籍贯 NCHAR(25),手机号码 CHAR(11)NOT NULL,民族 NCHAR(10),密码 NCHAR(35) NOT NULL,); CREATE TABLE  Course(    课程号 NCHAR(10) PRIMARY KEY NOT NULL,课程名 NCHAR(10) NOT NULL,            学分 SMALLINT NOT NULL,                                       上课地点 NCHAR(20) NOT NULL,上课时间 NCHAR(20)NOT NULL ); CREATE TABLE  SC(学号 NCHAR(10) NOT NULL, 姓名 NCHAR(10),课程号 NCHAR(10)NOT NULL,课程名 NCHAR(10),成绩 SMALLINT CHECK(成绩>=0 AND 成绩<=100),学分 SMALLINT ,PRIMARY KEY (学号,课程号),                     /* 主码由两个属性构成,必须作为表级完整性进行定义*/FOREIGN KEY (学号) REFERENCES Student(学号),  /* 表级完整性约束条件,学号是外码,被参照表是Student */FOREIGN KEY (课程号)REFERENCES Course(课程号),     /* 表级完整性约束条件, 工号是外码,被参照表是Course*/); INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215121','李勇','男','2000-11-03','汉族','数学信息专业','18','北京市','123123213','41b2e380f4ee72d92e4e1b61672d07ed');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215122','刘晨','男','2000-01-03','汉族','网络安全专业','18','上海市','1231232222','4fe3a5afd4d66bc2768870421bef6d80');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215123','佟露露','女','1998-02-13','汉族','生命科学专业','16','福建省','1231239873','aed333517421ba701dcfeaf3ee0da619');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215124','王敏','女','1999-07-30','汉族','通信专业','17','河北省','1231239803','5c15d3390d851205843a7e2c3a3a3d12');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215125','张丽','女','2001-04-21','汉族','航空航天专业','19','江西省','1231234563','f5579fdd1b92e1cecbe534a5e74cecfd');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215126','张扉','男','2000-06-30','汉族','计算机科学与技术专业','18','北京市','1232342213','9f83c11348a0a3a6259963823be1870f');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215127','顾依凉','男','2000-08-20','汉族','生命科学专业','18','贵州省','1231276513','b98a4565eb67c24a9481eb96d202d0e5');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215128','白雪','女','2001-03-23','汉族','通信专业','19','黑龙江省','1311232213','206111b43716ab18328809c64bef1fff');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215129','赵岑','男','2001-04-19','汉族','计算机科学与技术专业','19','吉林省','1345232213','cfb159592100391fce3640ce840dcd3d');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215120','林琳','女','2000-03-09','汉族','生命科学专业','18','四川省','1239802213','4c81c88cd7709d8b28d558c8f8af22d2');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215130','宋言','男','2002-07-03','汉族','航空航天专业','19','安徽','1234562213','415dfeb3e03aa46004ba95342897e702');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215131','卫琬','女','2000-11-03','汉族','通信专业','18','江西省','1231098713','039552cd56eb9fb800416d384052a0b0');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215132','韩晓梦','女','2000-12-09','汉族','数学信息专业','18','黑龙江省','1231342313','a2f5e908f5e96a9e44fea614fc3c0837');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215133','李祁','男','2000-08-17','汉族','计算机科学与技术专业','18','北京市','1239872213','40325844eaa57b823e4cc8f524ac43e7');
INSERT  INTO  Student(学号,姓名,性别,出生日期,民族,专业,年级,籍贯,手机号码,密码) VALUES ('201215134','郑颂雨','男','2002-06-12','汉族','生命科学专业','18','四川省','1231000213','6a9a16592c30de3aed9cb898886b2a6c');SELECT * FROM StudentINSERT  INTO  Manage(工号,姓名,性别,出生日期,籍贯,手机号码,民族,密码) VALUES ('201203','张珊','女','1982-01-01','四川省','13812345678','汉族','9365f8127adaa91c6ed8433cd9f32c24');
INSERT  INTO  Manage(工号,姓名,性别,出生日期,籍贯,手机号码,民族,密码) VALUES ('201204','李姒','女','1993-11-01','江西省','13898762312','汉族','d01bb7551d54d9c0806d79233b6fe10b');
INSERT  INTO  Manage(工号,姓名,性别,出生日期,籍贯,手机号码,民族,密码) VALUES ('201205','王武','男','1989-02-01','黑龙江省','13154342378','汉族','205ded2984e1daf6e3b9373767e8bf6e');
INSERT  INTO  Manage(工号,姓名,性别,出生日期,籍贯,手机号码,民族,密码) VALUES ('201206','钱珥','女','1982-01-01','安徽','13819334328','汉族','2d0cac1b87699da50b07937dcee15a05');
INSERT  INTO  Manage(工号,姓名,性别,出生日期,籍贯,手机号码,民族,密码) VALUES ('201207','赵依','女','1993-11-01','江西省','13898762312','汉族','28689f39401b4eaa9fc79efde978ca11');
INSERT  INTO  Manage(工号,姓名,性别,出生日期,籍贯,手机号码,民族,密码) VALUES ('201208','孙柳','男','1987-05-16','上海市','13159877348','汉族','bef90937301f701a5c39280d255e9e86');
SELECT * FROM ManageINSERT  INTO Course(课程号,课程名,学分,上课地点,上课时间)VALUES ('1','数据库',4,'一教101','周二7-9节');
INSERT  INTO Course(课程号,课程名,学分,上课地点,上课时间)VALUES ('2','高等数学',2,'三教212','周一1-4节');
INSERT  INTO Course(课程号,课程名,学分,上课地点,上课时间)VALUES ('3','信息系统',2,'二教103','周三7-9节');
INSERT  INTO Course(课程号,课程名,学分,上课地点,上课时间)VALUES ('4','操作系统',1,'一教601','周二1-2节');
INSERT  INTO Course(课程号,课程名,学分,上课地点,上课时间)VALUES ('5','数据结构',3,'三教101','周五5-6节');
INSERT  INTO Course(课程号,课程名,学分,上课地点,上课时间)VALUES ('6','数据处理',2,'二教211','周四2-4节');
INSERT  INTO Course(课程号,课程名,学分,上课地点,上课时间)VALUES ('7','Pascal语言',4,'一教101','周三3-4节');
SELECT * FROM CourseINSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215122 ','刘晨','1','数据库',80,4);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215123 ','佟露露','1','数据库',60,4);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215126 ','张扉','1','数据库',70,4);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215129 ','赵岑','1','数据库',97,4);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215131 ','卫琬','1','数据库',84,4);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215134 ','郑颂雨','2','高等数学',88,2);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215121 ','李勇','2','高等数学',56,0);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215125 ','张丽','2','高等数学',70,2);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215127 ','顾依凉','2','高等数学',77,2);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215133 ','李祁','2','高等数学',84,2);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215124 ','王敏','3','信息系统',88,2);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215128 ','白雪','4','操作系统',56,0);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215120 ','林琳','5','数据结构',70,3);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215130 ','宋言','6','数据处理',77,2);
INSERT  INTO SC(学号,姓名,课程号,课程名,成绩,学分) VALUES ('201215132 ','韩晓梦','7','Pascal语言',84,4);
UPDATE SC SET 学分=0 WHERE 成绩<60
SELECT * FROM SC

触发器

--在SC表中如果修改学号会对应修改姓名
IF(OBJECT_ID('show_Sname') is not null)        -- 判断名为 show_Sname 的触发器是否存在
DROP TRIGGER show_Sname        -- 删除触发器
GOCREATE TRIGGER show_Sname
ON SC
FOR UPDATE
AS declare @NEWSno NCHAR(10),@Sname NCHAR(10);
IF(UPDATE(学号))BEGINSELECT @NEWSno =学号 FROM INSERTEDSELECT @Sname =姓名 FROM Student WHERE 学号=@NEWSnoUPDATE SC SET 姓名=@Sname WHERE 学号=@NEWSnoEND;--在SC表中如果修改课程号会对应修改课程名
IF(OBJECT_ID('show_Cname') is not null)        -- 判断名为 show_Cname 的触发器是否存在
DROP TRIGGER show_Cname        -- 删除触发器
GOCREATE TRIGGER show_Cname
ON SC
FOR UPDATE
AS declare @NEWCno NCHAR(10),@Cname NCHAR(10),@credit SMALLINT;
IF(UPDATE(课程号))BEGINSELECT @NEWCno =课程号 FROM INSERTEDSELECT @Cname =课程名 FROM Course WHERE 课程号=@NEWCnoSELECT @credit = 学分 FROM Course WHERE 课程号=@NEWCnoUPDATE SC SET 课程名=@Cname WHERE 课程号=@NEWCnoUPDATE SC SET 学分=@credit WHERE 课程号=@NEWCno AND 成绩>=60UPDATE SC SET 学分=0 WHERE 课程号=@NEWCno AND 成绩<60END;--在SC表中如果修改成绩,成绩大于60时,学分获得,否则为0
IF(OBJECT_ID('show_credit') is not null)        -- 判断名为 show_credit 的触发器是否存在
DROP TRIGGER show_credit        -- 删除触发器
GOCREATE TRIGGER show_credit
ON SC
FOR UPDATE
AS declare @NEWgrade SMALLINT,@Sno NCHAR(10),@Cno NCHAR(10),@credit SMALLINT;
IF(UPDATE(成绩))BEGINSELECT @NEWgrade = 成绩 FROM INSERTEDSELECT @Sno = 学号 FROM DELETEDSELECT @Cno = 课程号 FROM DELETED SELECT @credit  =学分 FROM Course WHERE 课程号=@CnoUPDATE SC SET 学分=0 WHERE 课程号=@Cno AND 成绩<60UPDATE SC SET 学分=@credit WHERE 课程号=@Cno AND 成绩>=60END;--在Course表中如果修改学分,SC表中的对应学分也要修改
IF(OBJECT_ID('change_credit') is not null)        -- 判断名为 change_credit 的触发器是否存在
DROP TRIGGER change_credit        -- 删除触发器
GO
CREATE TRIGGER change_credit
ON Course
FOR UPDATE
AS declare @Cno NCHAR(10),@credit SMALLINT;
IF(UPDATE(学分))BEGINSELECT @Cno = 课程号 FROM DELETED SELECT @credit  =学分 FROM INSERTEDUPDATE SC SET 学分=0 WHERE 课程号=@Cno AND 成绩<60UPDATE SC SET 学分=@credit WHERE 课程号=@Cno AND 成绩>=60END;

Class1.cs文件:
目的:定义全局变量,保存输入的账号,以此显示对应的信息。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace 学生信息管理系统
{public class Class1{public static string UserID;}
}

登录界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class Form1 : Form{public Form1(){InitializeComponent();}public string code;private void Login_Load_1(object sender, EventArgs e){//随机实例化 Random ran = new Random();int number;char code1;//取五个数 for (int i = 0; i < 5; i++){number = ran.Next();if (number % 2 == 0)code1 = (char)('0' + (char)(number % 10));elsecode1 = (char)('A' + (char)(number % 26)); //转化为字符 this.code += code1.ToString();}label5.Text = code;}public static string EncryptWithMD5(string source){byte[] sor = Encoding.UTF8.GetBytes(source);MD5 md5 = MD5.Create();byte[] result = md5.ComputeHash(sor);StringBuilder strbul = new StringBuilder(40);for (int i = 0; i < result.Length; i++){strbul.Append(result[i].ToString("x2"));//加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位}return strbul.ToString();}private void Form1_Load(object sender, EventArgs e){//随机实例化 Random ran = new Random();int number;char code1;//取五个数 for (int i = 0; i < 5; i++){number = ran.Next();if (number % 2 == 0)code1 = (char)('0' + (char)(number % 10));elsecode1 = (char)('A' + (char)(number % 26)); //转化为字符 this.code += code1.ToString();}label5.Text = code;}private void textBox1_TextChanged(object sender,EventArgs e){}private void button3_Click(object sender, EventArgs e){Application.Exit();}private void button2_Click(object sender, EventArgs e){textBox1.Text = "";textBox2.Text = "";textBox3.Text = "";}private void button1_Click(object sender, EventArgs e){string username = textBox1.Text.Trim();  //取出账号string password = EncryptWithMD5(textBox2.Text.Trim());  //取出密码并加密// if (username == "admin")//   password = "123";//测试用例,便于初始化时候的 admin 密码 123可以顺利登陆。程序完成后可注释掉这行代码。//string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString(); //读取连接字符串string myConnString = "Data Source=.;Initial Catalog=student_information_management_system;Persist Security Info=True;User ID=sa;Password=***********";SqlConnection sqlConnection = new SqlConnection(myConnString);  //实例化连接对象sqlConnection.Open();string sql1 = "select 学号,密码 from Student where 学号 = '" + username + "' and 密码 = '" + password + "'";                                            //编写SQL命令SqlCommand sqlCommand1 = new SqlCommand(sql1, sqlConnection);SqlDataReader sqlDataReader1 = sqlCommand1.ExecuteReader();if (sqlDataReader1.HasRows && textBox3.Text == code){Class1.UserID = username;student_manage form2 = new student_manage();form2.Show();this.Hide();}sqlDataReader1.Close();string sql2 = "select 工号,密码 from Manage where 工号 = '" + username + "' and 密码 = '" + password + "'";SqlCommand sqlCommand2 = new SqlCommand(sql2, sqlConnection);SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();if (sqlDataReader2.HasRows && textBox3.Text == code){Class1.UserID = username;manager_manage form3 = new manager_manage();form3.Show();this.Hide();}else{label6.Text = "登录失败,输入密码或验证码错误";textBox1.Text = "";textBox2.Text = "";textBox3.Text = "";return;}sqlDataReader2.Close();sqlConnection.Close();}private void button4_Click(object sender, EventArgs e){retrieve_password form3 = new retrieve_password();form3.Show();this.Hide();}}
}

找回密码界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class retrieve_password : Form{public retrieve_password(){InitializeComponent();}public string code;public static string EncryptWithMD5(string source){byte[] sor = Encoding.UTF8.GetBytes(source);MD5 md5 = MD5.Create();byte[] result = md5.ComputeHash(sor);StringBuilder strbul = new StringBuilder(40);for (int i = 0; i < result.Length; i++){strbul.Append(result[i].ToString("x2"));//加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位}return strbul.ToString();}private void label6_Click(object sender, EventArgs e){}private void label5_Click(object sender, EventArgs e){}private void button1_Click(object sender, EventArgs e){string username = textBox1.Text.Trim();  //取出账号string cellphone = textBox2.Text.Trim();  //取出手机号码int flag1 = 0;int flag2 = 0;string myConnString = "Data Source=.;Initial Catalog=student_information_management_system;Persist Security Info=True;User ID=sa;Password=**********";SqlConnection sqlConnection = new SqlConnection(myConnString);  //实例化连接对象sqlConnection.Open();string sql1 = "select 学号,手机号码 from Student where 学号 = '" + username + "' and 手机号码 = '" + cellphone + "'";                                            //编写SQL命令SqlCommand sqlCommand1 = new SqlCommand(sql1, sqlConnection);SqlDataReader sqlDataReader1 = sqlCommand1.ExecuteReader();if (sqlDataReader1.HasRows ){if (textBox3.Text.Trim() != ""){//使用regex(正则表达式)进行格式设置 至少有数字、大写字母、小写字母各一个。最少3个字符、最长20个字符。Regex regex = new Regex(@"(?=.*[0-9]).{3,15}");if (regex.IsMatch(textBox3.Text))//判断格式是否符合要求{flag1 = 1;}}}sqlDataReader1.Close();if (flag1 == 1){string password = EncryptWithMD5(textBox3.Text.Trim());string sql3 = "update Student set 密码='" + password + "' where 学号='"+username+"'";SqlCommand sqlCommand3 = new SqlCommand(sql3, sqlConnection);SqlDataReader sqlDataReader3 = sqlCommand3.ExecuteReader();MessageBox.Show("修改成功");sqlDataReader3.Close();Form1 form1 = new Form1();form1.Show();this.Hide();}string sql2 = "select 工号,手机号码 from Manage where 工号 = '" + username + "' and 手机号码 = '" + cellphone + "'";SqlCommand sqlCommand2 = new SqlCommand(sql2, sqlConnection);SqlDataReader sqlDataReader2 = sqlCommand2.ExecuteReader();if (sqlDataReader2.HasRows){if (textBox3.Text.Trim() != ""){//使用regex(正则表达式)进行格式设置 至少有数字、大写字母、小写字母各一个。最少3个字符、最长20个字符。Regex regex = new Regex(@"(?=.*[0-9]).{3,15}");if (regex.IsMatch(textBox3.Text))//判断格式是否符合要求{flag2 = 1;}}sqlDataReader2.Close();if (flag2 == 1){string password = EncryptWithMD5(textBox3.Text.Trim());string sql4 = "update Manage set 密码='" + password + "' where 工号='" + username + "'";SqlCommand sqlCommand4 = new SqlCommand(sql4, sqlConnection);SqlDataReader sqlDataReader4 = sqlCommand4.ExecuteReader();MessageBox.Show("修改成功");sqlDataReader4.Close();Form1 form1 = new Form1();form1.Show();this.Hide();}}else{label5.Text = "输入密码错误或手机号码错误,请重新输入";textBox1.Text = "";textBox2.Text = "";textBox3.Text = "";return;}sqlConnection.Close();}private void button4_Click(object sender, EventArgs e){Form1 form1 = new Form1();form1.Show();this.Hide();}private void button2_Click(object sender, EventArgs e){textBox1.Text = "";textBox2.Text = "";textBox3.Text = "";}}
}

管理员功能界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class manager_manage : Form{public string MyID;public manager_manage(){InitializeComponent();}private void manager_manage_Load(object sender, EventArgs e){label1.Text = Class1.UserID+" 你好,欢迎进入系统";}private void button6_Click(object sender, EventArgs e){Application.Exit();}private void button5_Click(object sender, EventArgs e){Form1 form1 = new Form1();form1.Show();this.Hide();}private void button1_Click(object sender, EventArgs e){manage_manager_information manage_manager_information1 = new manage_manager_information();manage_manager_information1.Show();this.Hide();}private void button2_Click(object sender, EventArgs e){manage_student_information manage_student_information1 = new manage_student_information();manage_student_information1.Show();this.Hide();}private void button3_Click(object sender, EventArgs e){manage_course manage_course1 = new manage_course();manage_course1.Show();this.Hide();}private void button4_Click(object sender, EventArgs e){manage_SCcs manage_SCcs1 = new manage_SCcs();manage_SCcs1.Show();this.Hide();}}
}

管理员管理管理员信息界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class manage_manager_information : Form{SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=***********");public manage_manager_information(){InitializeComponent();}private void manage_manager_information_Load(object sender, EventArgs e){// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet2.Manage”中。您可以根据需要移动或删除它。this.manageTableAdapter.Fill(this.student_information_management_systemDataSet2.Manage);}public static string EncryptWithMD5(string source){byte[] sor = Encoding.UTF8.GetBytes(source);MD5 md5 = MD5.Create();byte[] result = md5.ComputeHash(sor);StringBuilder strbul = new StringBuilder(40);for (int i = 0; i < result.Length; i++){strbul.Append(result[i].ToString("x2"));//加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位}return strbul.ToString();}private void button1_Click(object sender, EventArgs e){Application.Exit();}private void Close_Click_1(object sender, EventArgs e){manager_manage manager_manage1 = new manager_manage();manager_manage1.Show();this.Hide();}private void Insert_Click_1(object sender, EventArgs e){String Mno = textBox1.Text.Trim();String Mname = textBox2.Text.Trim();String Msex = textBox3.Text.Trim();String Mbirth = textBox4.Text.Trim();String Mnative = textBox5.Text.Trim();//籍贯String Mcelllphone = textBox6.Text.Trim();String Mnation = textBox7.Text.Trim();//民族String Mpassword = EncryptWithMD5(Mno);//密码try{con.Open();string insertStr = "INSERT INTO Manage(工号,姓名,性别,出生日期,籍贯,手机号码,民族,密码) " +"VALUES('" + Mno + "','" + Mname + "','" + Msex + "','" + Mbirth + "','" + Mnative +"','"+Mcelllphone + "','"+Mnation+"','"+ Mpassword + "')";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("输入数据违反要求");}finally{con.Dispose();}this.manageTableAdapter.Fill(this.student_information_management_systemDataSet2.Manage);}private void Delete_Click(object sender, EventArgs e){try{con.Open();string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是IDstring delete_by_id = "delete from Manage where 工号=" + select_id;//sql删除语句SqlCommand cmd = new SqlCommand(delete_by_id, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("请正确选择行!");}finally{con.Dispose();}this.manageTableAdapter.Fill(this.student_information_management_systemDataSet2.Manage);}private void Update_Click(object sender, EventArgs e){String Mno = textBox1.Text.Trim();String Mname = textBox2.Text.Trim();String Msex = textBox3.Text.Trim();String Mbirth = textBox4.Text.Trim();String Mnative = textBox5.Text.Trim();//籍贯String Mcelllphone = textBox6.Text.Trim();String Mnation = textBox7.Text.Trim();//民族try{con.Open();if (Mname != ""){string insertStr = "UPDATE Manage SET 姓名 = '" + Mname + "' WHERE   工号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Msex != ""){string insertStr = "UPDATE Manage SET 性别 = '" + Msex + "' WHERE   工号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mbirth != ""){string insertStr = "UPDATE Manage SET 出生日期 = '" + Mbirth + "' WHERE   工号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mnative != ""){string insertStr = "UPDATE Manage SET 籍贯 = '" + Mnative + "' WHERE   工号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mcelllphone != ""){string insertStr = "UPDATE Manage SET 手机号码 = '" + Mcelllphone + "' WHERE   工号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mnation != ""){string insertStr = "UPDATE Manage SET 民族 = '" + Mnation + "' WHERE   工号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}}catch{MessageBox.Show("输入数据违反要求!");}finally{con.Dispose();}this.manageTableAdapter.Fill(this.student_information_management_systemDataSet2.Manage);}private void Select_Click(object sender, EventArgs e){String Mno = textBox1.Text.Trim();String Mname = textBox2.Text.Trim();String Msex = textBox3.Text.Trim();String Mbirth = textBox4.Text.Trim();String Mnative = textBox5.Text.Trim();//籍贯String Mcelllphone = textBox6.Text.Trim();String Mnation = textBox7.Text.Trim();//民族String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=********";SqlConnection sqlConnection = new SqlConnection(conn);try{if (Mno != ""){sqlConnection.Open();String select_by_id = "select * from Manage where 工号='" + Mno + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mname != ""){sqlConnection.Open();String select_by_id = "select * from Manage where 姓名 Like'" + Mname + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Msex != ""){sqlConnection.Open();String select_by_id = "select * from Manage where 性别='" + Msex + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mbirth != ""){sqlConnection.Open();String select_by_id = "select * from Manage where 出生日期 Like'" + Mbirth + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mnative != ""){sqlConnection.Open();String select_by_id = "select * from Manage where 籍贯 Like'" + Mnative + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mcelllphone != ""){sqlConnection.Open();String select_by_id = "select * from Manage where 手机号码='" + Mcelllphone + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mnation != ""){sqlConnection.Open();String select_by_id = "select * from Manage where 民族 Like'" + Mnation + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}}catch{MessageBox.Show("查询语句有误!");}finally{sqlConnection.Close();}}}
}

管理员管理学生信息界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class manage_student_information : Form{SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=***********");public manage_student_information(){InitializeComponent();}public static string EncryptWithMD5(string source){byte[] sor = Encoding.UTF8.GetBytes(source);MD5 md5 = MD5.Create();byte[] result = md5.ComputeHash(sor);StringBuilder strbul = new StringBuilder(40);for (int i = 0; i < result.Length; i++){strbul.Append(result[i].ToString("x2"));//加密结果"x2"结果为32位,"x3"结果为48位,"x4"结果为64位}return strbul.ToString();}private void button1_Click(object sender, EventArgs e){Application.Exit();}private void Close_Click(object sender, EventArgs e){manager_manage manager_manage1 = new manager_manage();manager_manage1.Show();this.Hide();}private void Insert_Click(object sender, EventArgs e){String Mno = textBox1.Text.Trim();String Mname = textBox2.Text.Trim();String Msex = textBox3.Text.Trim();String Mbirth = textBox4.Text.Trim();String Mnative = textBox5.Text.Trim();//籍贯String Mcelllphone = textBox6.Text.Trim();String Mnation = textBox7.Text.Trim();//民族String Mgrade = textBox8.Text.Trim();String Mdept = textBox9.Text.Trim();String Mpassword = EncryptWithMD5(Mno);//密码try{con.Open();string insertStr = "INSERT INTO Student(学号,姓名,性别,出生日期,籍贯,手机号码,民族,年级,专业,密码) " +"VALUES('" + Mno + "','" + Mname + "','" + Msex + "','" + Mbirth + "','" + Mnative + "','" + Mcelllphone + "','" + Mnation + "','" + Mgrade + "','" + Mdept + "','" + Mpassword + "')";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("输入数据违反要求");}finally{con.Dispose();}this.studentTableAdapter.Fill(this.student_information_management_systemDataSet3.Student);}private void manage_student_information_Load(object sender, EventArgs e){// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet3.Student”中。您可以根据需要移动或删除它。this.studentTableAdapter.Fill(this.student_information_management_systemDataSet3.Student);}private void Delete_Click(object sender, EventArgs e){try{con.Open();string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是IDstring delete_by_id = "delete from Student where 学号=" + select_id;//sql删除语句SqlCommand cmd = new SqlCommand(delete_by_id, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("请正确选择行!");}finally{con.Dispose();}this.studentTableAdapter.Fill(this.student_information_management_systemDataSet3.Student);}private void Update_Click(object sender, EventArgs e){String Mno = textBox1.Text.Trim();String Mname = textBox2.Text.Trim();String Msex = textBox3.Text.Trim();String Mbirth = textBox4.Text.Trim();String Mnative = textBox5.Text.Trim();//籍贯String Mcelllphone = textBox6.Text.Trim();String Mnation = textBox7.Text.Trim();//民族String Mgrade = textBox8.Text.Trim();String Mdept = textBox9.Text.Trim();try{con.Open();if (Mname != ""){string insertStr = "UPDATE Student SET 姓名 = '" + Mname + "' WHERE   学号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Msex != ""){string insertStr = "UPDATE Student SET 性别 = '" + Msex + "' WHERE   学号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mbirth != ""){string insertStr = "UPDATE Student SET 出生日期 = '" + Mbirth + "' WHERE   学号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mnative != ""){string insertStr = "UPDATE Student SET 籍贯 = '" + Mnative + "' WHERE   学号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mcelllphone != ""){string insertStr = "UPDATE Student SET 手机号码 = '" + Mcelllphone + "' WHERE   学号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mnation != ""){string insertStr = "UPDATE Student SET 民族 = '" + Mnation + "' WHERE   学号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mgrade != ""){string insertStr = "UPDATE Student SET 年级 = '" + Mgrade + "' WHERE   学号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Mdept != ""){string insertStr = "UPDATE Student SET 专业 = '" + Mdept + "' WHERE   学号='" + Mno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}}catch{MessageBox.Show("输入数据违反要求!");}finally{con.Dispose();}this.studentTableAdapter.Fill(this.student_information_management_systemDataSet3.Student);}private void Select_Click(object sender, EventArgs e){String Mno = textBox1.Text.Trim();String Mname = textBox2.Text.Trim();String Msex = textBox3.Text.Trim();String Mbirth = textBox4.Text.Trim();String Mnative = textBox5.Text.Trim();//籍贯String Mcelllphone = textBox6.Text.Trim();String Mnation = textBox7.Text.Trim();//民族String Mgrade = textBox8.Text.Trim();String Mdept = textBox9.Text.Trim();String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=***********";SqlConnection sqlConnection = new SqlConnection(conn);try{if (Mno != ""){sqlConnection.Open();String select_by_id = "select * from Manage where 工号='" + Mno + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mname != ""){sqlConnection.Open();String select_by_id = "select * from Student where 姓名 Like'" + Mname + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Msex != ""){sqlConnection.Open();String select_by_id = "select * from Student where 性别='" + Msex + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mbirth != ""){sqlConnection.Open();String select_by_id = "select * from Student where 出生日期 Like'" + Mbirth + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mnative != ""){sqlConnection.Open();String select_by_id = "select * from Student where 籍贯 Like'" + Mnative + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mcelllphone != ""){sqlConnection.Open();String select_by_id = "select * from Student where 手机号码='" + Mcelllphone + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mnation != ""){sqlConnection.Open();String select_by_id = "select * from Student where 民族 Like'" + Mnation + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mgrade != ""){sqlConnection.Open();String select_by_id = "select * from Student where 年级='" + Mgrade + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Mdept != ""){sqlConnection.Open();String select_by_id = "select * from Student where 专业 Like'" + Mdept + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}}catch{MessageBox.Show("查询语句有误!");}finally{sqlConnection.Close();}}}
}

管理员管理课程界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class manage_course : Form{SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=**********");public manage_course(){InitializeComponent();}private void button1_Click(object sender, EventArgs e){Application.Exit();}private void Close_Click(object sender, EventArgs e){manager_manage manager_manage1 = new manager_manage();manager_manage1.Show();this.Hide();}private void Insert_Click(object sender, EventArgs e){String Cno = textBox1.Text.Trim();//课程号String Cname = textBox2.Text.Trim();//课程名String Credit = textBox3.Text.Trim();//学分String Cplace = textBox4.Text.Trim();//上课地点String Ctime = textBox5.Text.Trim();//上课时间try{con.Open();string insertStr = "INSERT INTO Course(课程号,课程名,学分,上课地点,上课时间) " +"VALUES('" + Cno + "','" + Cname + "','" + Credit + "','" + Cplace + "','" + Ctime + "')";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("输入数据违反要求");}finally{con.Dispose();}this.courseTableAdapter.Fill(this.student_information_management_systemDataSet4.Course);}private void manage_course_Load(object sender, EventArgs e){// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet4.Course”中。您可以根据需要移动或删除它。this.courseTableAdapter.Fill(this.student_information_management_systemDataSet4.Course);}private void Delete_Click(object sender, EventArgs e){try{con.Open();string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是IDstring delete_by_id = "delete from Course where 课程号=" + select_id;//sql删除语句SqlCommand cmd = new SqlCommand(delete_by_id, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("请正确选择行!");}finally{con.Dispose();}this.courseTableAdapter.Fill(this.student_information_management_systemDataSet4.Course);}private void Update_Click(object sender, EventArgs e){String Cno = textBox1.Text.Trim();//课程号String Cname = textBox2.Text.Trim();//课程名String Credit = textBox3.Text.Trim();//学分String Cplace = textBox4.Text.Trim();//上课地点String Ctime = textBox5.Text.Trim();//上课时间try{con.Open();if (Cname != ""){string insertStr = "UPDATE Course SET 课程名 = '" + Cname + "' WHERE   课程号='" + Cno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Credit != ""){string insertStr = "UPDATE Course SET 学分 = '" + Credit + "' WHERE   课程号='" + Cno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Cplace != ""){string insertStr = "UPDATE Course SET 上课地点 = '" + Cplace + "' WHERE   课程号='" + Cno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}if (Ctime != ""){string insertStr = "UPDATE Course SET 上课时间 = '" + Ctime + "' WHERE   课程号='" + Cno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}}catch{MessageBox.Show("输入数据违反要求!");}finally{con.Dispose();}this.courseTableAdapter.Fill(this.student_information_management_systemDataSet4.Course);}private void Select_Click(object sender, EventArgs e){String Cno = textBox1.Text.Trim();//课程号String Cname = textBox2.Text.Trim();//课程名String Credit = textBox3.Text.Trim();//学分String Cplace = textBox4.Text.Trim();//上课地点String Ctime = textBox5.Text.Trim();//上课时间String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=********";SqlConnection sqlConnection = new SqlConnection(conn);try{if (Cno != ""){sqlConnection.Open();String select_by_id = "select * from Course where 课程号='" + Cno + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Cname != ""){sqlConnection.Open();String select_by_id = "select * from Course where 课程名 Like'" + Cname + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Credit != ""){sqlConnection.Open();String select_by_id = "select * from Course where 学分='" + Credit + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Cplace != ""){sqlConnection.Open();String select_by_id = "select * from Course where 上课地点 Like'" + Cplace + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Ctime != ""){sqlConnection.Open();String select_by_id = "select * from Course where 上课时间 Like'" + Ctime + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}}catch{MessageBox.Show("查询语句有误!");}finally{sqlConnection.Close();}}}
}

管理员管理成绩界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class manage_SCcs : Form{SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=*********");public manage_SCcs(){InitializeComponent();}private void manage_SCcs_Load(object sender, EventArgs e){// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet12.SC”中。您可以根据需要移动或删除它。this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet12.SC);// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet5.SC”中。您可以根据需要移动或删除它。//this.sCTableAdapter.Fill(this.student_information_management_systemDataSet5.SC);}private void button1_Click(object sender, EventArgs e){Application.Exit();}private void Close_Click(object sender, EventArgs e){manager_manage manager_manage1 = new manager_manage();manager_manage1.Show();this.Hide();}private void Insert_Click(object sender, EventArgs e){String Sno = textBox1.Text.Trim();String Sname = textBox2.Text.Trim();String Cno = textBox3.Text.Trim();String Cname = textBox4.Text.Trim();String Grade = textBox5.Text.Trim();String Credit = textBox6.Text.Trim();try{con.Open();if(Grade!="" && Credit != ""){string insertStr = "INSERT INTO SC(学号,姓名,课程号,课程名,成绩,学分) " +"VALUES('" + Sno + "','" + Sname + "','" + Cno + "','" + Cname + "'," + Grade + "," + Credit + ")";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}}catch{MessageBox.Show("输入数据违反要求");}finally{con.Dispose();}this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet12.SC);}private void Delete_Click(object sender, EventArgs e){try{con.Open();string select_id1 = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();//选择的当前行第一列的值,也就是IDstring select_id2 = dataGridView1.SelectedRows[0].Cells[2].Value.ToString().Trim();string delete_by_id = "delete from SC where 学号='" + select_id1+ "' AND 课程号='"+select_id2+ "'";//sql删除语句SqlCommand cmd = new SqlCommand(delete_by_id, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("请正确选择行!");}finally{con.Dispose();}this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet12.SC);}private void Update_Click(object sender, EventArgs e){String Sno = textBox1.Text.Trim();String Cno = textBox3.Text.Trim();String Grade = textBox5.Text.Trim();try{con.Open();string insertStr = "UPDATE SC SET 成绩 = " + Grade + " WHERE   学号='" + Sno + "' AND 课程号='"+ Cno + "'";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("输入数据违反要求!");}finally{con.Dispose();}this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet12.SC);}private void Select_Click(object sender, EventArgs e){String Sno = textBox1.Text.Trim();String Sname = textBox2.Text.Trim();String Cno = textBox3.Text.Trim();String Cname = textBox4.Text.Trim();String  Grade =textBox5.Text.Trim();String Credit = textBox6.Text.Trim();String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=********";SqlConnection sqlConnection = new SqlConnection(conn);try{if (Sno != ""){sqlConnection.Open();String select_by_id = "select * from SC where 学号='" + Sno + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Sname != ""){sqlConnection.Open();String select_by_id = "select * from SC where 姓名 Like'" + Sname + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Cno != ""){sqlConnection.Open();String select_by_id = "select * from SC where 课程号='" + Cno + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Cname != ""){sqlConnection.Open();String select_by_id = "select * from SC where 课程名 Like'" + Cname + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Grade != ""){sqlConnection.Open();String select_by_id = "select * from SC where 成绩 =" + Grade ;SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Credit != ""){sqlConnection.Open();String select_by_id = "select * from SC where 学分=" + Credit;SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}}catch{MessageBox.Show("查询语句有误!");}finally{sqlConnection.Close();}}}
}

学生功能界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class student_manage : Form{public student_manage(){InitializeComponent();}private void student_manage_Load(object sender, EventArgs e){label1.Text = Class1.UserID + " 你好,欢迎进入系统";}private void button5_Click(object sender, EventArgs e){Form1 form1 = new Form1();form1.Show();this.Hide();}private void button6_Click(object sender, EventArgs e){Application.Exit();}private void button1_Click(object sender, EventArgs e){student_SC student_SC1 = new student_SC();student_SC1.Show();this.Hide();}private void button2_Click(object sender, EventArgs e){student_course student_course1 = new student_course();student_course1.Show();this.Hide();}}
}

学生查询成绩界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class student_SC : Form{SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=************");public student_SC(){InitializeComponent();}private void student_SC_Load(object sender, EventArgs e){// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet11.SC”中。您可以根据需要移动或删除它。this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet11.SC);// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet7.SC”中。您可以根据需要移动或删除它。this.sCTableAdapter.Fill(this.student_information_management_systemDataSet7.SC);String Sno = Class1.UserID;String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=**************";SqlConnection sqlConnection = new SqlConnection(conn);try{sqlConnection.Open();String select_by_id = "select * from SC where 学号='" + Sno + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}catch{}finally{sqlConnection.Close();}}private void Close_Click(object sender, EventArgs e){student_manage student_manage1 = new student_manage();student_manage1.Show();this.Hide();}private void button1_Click(object sender, EventArgs e){Application.Exit();}private void button2_Click(object sender, EventArgs e){String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=****************";SqlConnection sqlConnection = new SqlConnection(conn);String str = Class1.UserID;try{sqlConnection.Open();String select_by_id = "select * from SC where 成绩<60 AND 学号='" + str + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}catch{MessageBox.Show("查询语句有误!");}finally{sqlConnection.Close();}}private void Select_Click(object sender, EventArgs e){String Cno = textBox1.Text.Trim();String Cname = textBox2.Text.Trim();String str = Class1.UserID;String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=****************";SqlConnection sqlConnection = new SqlConnection(conn);try{if (Cno != ""){sqlConnection.Open();String select_by_id = "select * from SC where 学号='" + str + "'AND 课程号='"+Cno+"'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Cname != ""){sqlConnection.Open();String select_by_id = "select * from SC where 学号='" + str + "'AND 课程名 Like'" + Cname + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}}catch{MessageBox.Show("查询语句有误!");}finally{sqlConnection.Close();}}}
}

学生选择课程、查询课程界面:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;namespace 学生信息管理系统
{public partial class student_course : Form{SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=***********");public student_course(){InitializeComponent();}private void student_course_Load(object sender, EventArgs e){// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet10.SC”中。您可以根据需要移动或删除它。this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet10.SC);// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet9.SC”中。您可以根据需要移动或删除它。this.sCTableAdapter.Fill(this.student_information_management_systemDataSet9.SC);// TODO: 这行代码将数据加载到表“student_information_management_systemDataSet8.Course”中。您可以根据需要移动或删除它。this.courseTableAdapter.Fill(this.student_information_management_systemDataSet8.Course);String Sno = Class1.UserID;String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=**********";SqlConnection sqlConnection = new SqlConnection(conn);try{sqlConnection.Open();String select_by_id = "select * from SC where 学号='" + Sno + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView2.DataSource = bindingSource;}catch{}finally{sqlConnection.Close();}}private void Select_Click(object sender, EventArgs e){String Cno = textBox1.Text.Trim();//课程号String Cname = textBox2.Text.Trim();//课程名String Credit = textBox3.Text.Trim();//学分String Cplace = textBox4.Text.Trim();//上课地点String Ctime = textBox5.Text.Trim();//上课时间String conn = "Data Source=.;Initial Catalog=student_information_management_system;User ID=sa;Password=**********";SqlConnection sqlConnection = new SqlConnection(conn);try{if (Cno != ""){sqlConnection.Open();String select_by_id = "select * from Course where 课程号='" + Cno + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Cname != ""){sqlConnection.Open();String select_by_id = "select * from Course where 课程名 Like'" + Cname + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Credit != ""){sqlConnection.Open();String select_by_id = "select * from Course where 学分='" + Credit + "'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Cplace != ""){sqlConnection.Open();String select_by_id = "select * from Course where 上课地点 Like'" + Cplace + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}if (Ctime != ""){sqlConnection.Open();String select_by_id = "select * from Course where 上课时间 Like'" + Ctime + "%'";SqlCommand sqlCommand = new SqlCommand(select_by_id, sqlConnection);SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();BindingSource bindingSource = new BindingSource();bindingSource.DataSource = sqlDataReader;dataGridView1.DataSource = bindingSource;}}catch{MessageBox.Show("查询语句有误!");}finally{sqlConnection.Close();}}private void Close_Click(object sender, EventArgs e){student_manage student_manage1 = new student_manage();student_manage1.Show();this.Hide();}private void button1_Click(object sender, EventArgs e){Application.Exit();}private void Insert_Click(object sender, EventArgs e){String Cno = textBox1.Text.Trim();//课程号String Cname = textBox2.Text.Trim();//课程名String Sno = Class1.UserID;//学号try{con.Open();string insertStr = "INSERT INTO SC(课程号,课程名,学号) " +"VALUES('" + Cno + "','" + Cname + "','" + Sno + "')";SqlCommand cmd = new SqlCommand(insertStr, con);cmd.ExecuteNonQuery();}catch{MessageBox.Show("输入数据违反要求");}finally{con.Dispose();}this.sCTableAdapter.Fill(this.student_information_management_systemDataSet9.SC);/*this.sCTableAdapter1.Fill(this.student_information_management_systemDataSet10.SC);*/}}
}

实验效果讲解视频链接:

【2019-2020春学期】数据库实验大作业——学生信息管理系统功能讲解

代码链接:

链接:https://pan.baidu.com/s/1OVCWYgidhP81K8aMl7rQDA
提取码:2psx

心得:

终于完成大作业啦,开心

【2019-2020春学期】数据库实验大作业相关推荐

  1. 西工大数据库实验大作业 火锅店菜品管理系统

    西工大数据库实验大作业 火锅店菜品管理系统 文章目录 西工大数据库实验大作业 火锅店菜品管理系统 前言: 一.大作业简单的需求分析: 二.数据流图: 三.数据字典: 四.E-R图: 五.关系模式设计: ...

  2. 哈工大(威海)算法实验一:分治算法实验大作业

    哈工大(威海)算法实验一:分治算法实验大作业 题目 某一高等院校有汽车学院.材料学院.计算机学院.软件学院:每个学院的一年级第一学期都开英语.高数.线代课程.每个学院每学期的成绩已经分别登录在同一个E ...

  3. 南开大学20春计算机应用基础在线作业,南开大学20春学期计算机应用基础在线作业参考答案...

    1.南开大学20春学期计算机应用基础在线作业试卷总分:100 得分:100一.单选题 (共 40 道试题,共 40 分)1.在Excel 2003中,电子工作表中的行号为_.A.第一个为字母其余为数字 ...

  4. 象棋快棋赛电子裁判计时器的设计——《数字逻辑与数字系统设计》实验大作业设计报告

    数电Github资源 <数字逻辑与数字系统设计>实验大作业设计报告 实验题目 象棋快棋赛电子裁判计时器的设计 实验难度 ★★ 成员 姓名 班号 学号 1 郭茁宁 1837101 11837 ...

  5. 计算机应用基18春在线作业,南开18春学期计算机应用基础在线作业3

    <南开18春学期计算机应用基础在线作业3>由会员分享,可在线阅读,更多相关<南开18春学期计算机应用基础在线作业3(6页珍藏版)>请在技术文库上搜索. 1. www.vu8o. ...

  6. 数字图像处理课程(作业+实验+大作业)相关文章 传送门

    数字图像处理课程(作业+实验+大作业)相关文章 传送门 博文说明 本文所使用代码或多或少参考了以往博文的同类or相似文章的代码,并非纯原创 本文仅用于记录并提供一种代码思路,供大家参考 文章目录 数字 ...

  7. matlab数学实验 南邮,matlab实验练习题(计算机)-南邮-matlab-数学实验大作业答案

    matlab实验练习题(计算机)-南邮-matlab-数学实验大作业答案 1"MATLAB"练习题练习题要求:抄题.写出操作命令.运行结果,并根据要求,贴上运行图.1.求的所有根. ...

  8. MYSQL:餐厅点菜、管理员工的数据库。大学数据库课程大作业(初学者,入门,用的基础知识)

    mysql数据库:点餐系统和管理员工的数据库 大二做的数据库课程大作业,作者是初学者,分享给大家参考,内容参考了很多篇数据库文章才拼凑出来,所以本数据库很粗糙,很简单,需要的同学复制粘贴然后自行修改交 ...

  9. 基于eNSP的IPv4加IPv6的企业/校园网络规划设计(综合实验/大作业)

    作者:BSXY_19计科_陈永跃 BSXY_信息学院_名片v位于结尾处 注:未经允许禁止转发任何内容 基于eNSP的IPv4加IPv6的企业/校园网络规划设计_综合实验/大作业 前言及技术/资源下载说 ...

  10. 吉大20春学期计算机系统结构在线作业一,吉大20春学期《计算机原理及系统结构》在线作业一【奥鹏百分答案】...

    案来源:(www.)-[吉林大学]吉大20春学期<计算机原理及系统结构>在线作业一 试卷总分:100    得分:100 第1题,DMA方式的接口电路中有程序中断部件,其作用是______ ...

最新文章

  1. 腾讯服务器“上天”、大疆云台会飞、淘宝被掰弯了……这是昨天各大科技公司的最新产品...
  2. 从Openvswitch代码看网络包的旅程
  3. python 正则search 所有_python之路----正则re(search,match,findall……)
  4. JavaScript基础二
  5. NOIP练习赛题目6
  6. 并发编程(1): volatile、原子变量、自旋锁和互斥锁
  7. 第五章项目整体管理重点--转载
  8. lotus Domino调用webservice
  9. 简单说说路由器和交换机的区别
  10. 通信原理及系统系列4—— AWGN信道(信噪比SNR、Es/N0和Eb/N0概念的辨析、转换及使用)
  11. 三维实时云渲染平台解决方案
  12. ubuntu搜狗输入法显示简体中文,输入却是繁体中文解决方案
  13. 图片url显示服务器,服务器上图片的url地址
  14. java定时从数据库抓取数据库,java查询数据库java如何实现定时从数据库查询新增的数据?...
  15. 九峰影业创始人_以终为始 逐梦青春——九峰实验学校2020届高三毕业典礼
  16. 如何选购笔记本电脑?
  17. 有所为有所不为,泽塔云异军突起的背后
  18. css在线编辑器html,html5+css3编辑器
  19. 2015-4-11更新的pdf
  20. c 标准和c++标准

热门文章

  1. Python.translate(table).maketrans(‘str1‘,‘str2‘)字符串翻译
  2. Spring Boot 2.3.0配置Graceful-Shutdown,Readiness和Liveness
  3. word刷子刷格式_用word格式刷快速调整文档格式-word技巧-电脑技巧收藏家
  4. 淘宝上买东西,怎么买最便宜?
  5. 嵌入式Linux——学习经历
  6. [转载]Android开发网上的一些重要知识点
  7. 基于MATLAB的无线信道性能仿真
  8. 知道Ping的最后一个返回值TTL是什么意思吗?
  9. 2019JAVA面试题精粹附答案
  10. 新手使用PHPCUSTOM打开php文件变下载的原因分析