DROP DATABASE IF EXISTS FinalLogin;
CREATE DATABASE FinalLogin;
USE FinalLogin;
DROP TABLE IF EXISTS SC
DROP TABLE IF EXISTS Student
DROP TABLE IF EXISTS Course
DROP TABLE IF EXISTS SysUser
CREATE TABLE SysUser /*用户登记表*/
(
UserID NCHAR(20) PRIMARY KEY,
UserPassWord NCHAR(32) ,
UserName NCHAR(20),
UserSex char(2) check (UserSex in ('男','女')) default('女'),
UserBirthday datetime,
UserMobile NCHAR(11),
UserMajor NCHAR(20),
UserPhoto image
);
CREATE TABLE Student /*学生记录表*/
(
Sno CHAR(9) PRIMARY KEY, /* 列级完整性约束条件,Sno是主码*/
Sname CHAR(20) UNIQUE, /* Sname取唯一值*/
Ssex CHAR(2) check (SSex in ('男','女')) default('女'),
Sage SMALLINT,
Sdept CHAR(20)
);
CREATE TABLE Course /*课程表*/
(
Cno CHAR(4) PRIMARY KEY,
Cname CHAR(40),
Cpno CHAR(4),
Ccredit SMALLINT,
FOREIGN KEY (Cpno) REFERENCES Course(Cno)
);
CREATE TABLE SC /*成绩表*/
(
Sno CHAR(9),
Cno CHAR(4),
Grade SMALLINT,
PRIMARY KEY (Sno,Cno), /* 主码由两个属性构成,必须作为表级完整性进行定义*/
FOREIGN KEY (Sno) REFERENCES Student(Sno), /* 表级完整性约束条件,Sno是外码,被参照表是Student */
FOREIGN KEY (Cno)REFERENCES Course(Cno) /* 表级完整性约束条件, Cno是外码,被参照表是Course*/
);
INSERT INTO Student (Sno,Sname,Ssex,Sdept,Sage) VALUES ('201215121','李勇','男','CS',20);
INSERT INTO Student (Sno,Sname,Ssex,Sdept,Sage) VALUES ('201215122','刘晨','女','CS',19);
INSERT INTO Student (Sno,Sname,Ssex,Sdept,Sage) VALUES ('201215123','王敏','女','MA',18);
INSERT INTO Student (Sno,Sname,Ssex,Sdept,Sage) VALUES ('201215125','张立','男','IS',19);
INSERT INTO Student (Sno,Sname,Ssex,Sdept,Sage) VALUES ('201215128','陈冬','男','IS',20);
SELECT * FROM Student
INSERT INTO Course(Cno,Cname,Cpno,Ccredit) VALUES ('1','数据库',NULL,4);
INSERT INTO Course(Cno,Cname,Cpno,Ccredit) VALUES ('2','数学',NULL,4);
INSERT INTO Course(Cno,Cname,Cpno,Ccredit) VALUES ('3','信息系统',NULL,4);
INSERT INTO Course(Cno,Cname,Cpno,Ccredit) VALUES ('4','操作系统',NULL,4);
INSERT INTO Course(Cno,Cname,Cpno,Ccredit) VALUES ('5','数据结构',NULL,4);
INSERT INTO Course(Cno,Cname,Cpno,Ccredit) VALUES ('6','数据处理',NULL,4);
INSERT INTO Course(Cno,Cname,Cpno,Ccredit) VALUES ('7','Pascal语言',NULL,4);
UPDATE Course SET Cpno = '5' WHERE Cno = '1'
UPDATE Course SET Cpno = '1' WHERE Cno = '3'
UPDATE Course SET Cpno = '6' WHERE Cno = '4'
UPDATE Course SET Cpno = '7' WHERE Cno = '5'
UPDATE Course SET Cpno = '6' WHERE Cno = '7'
SELECT * FROM Course
INSERT INTO SC(Sno,Cno,Grade) VALUES ('201215121 ','1',92);
INSERT INTO SC(Sno,Cno,Grade) VALUES ('201215121 ','2',85);
INSERT INTO SC(Sno,Cno,Grade) VALUES ('201215121 ','3',88);
INSERT INTO SC(Sno,Cno,Grade) VALUES ('201215122 ','2',90);
INSERT INTO SC(Sno,Cno,Grade) VALUES ('201215122 ','3',80);
SELECT * FROM SC
IF(OBJECT_ID('regist_recorder') is not null) -- 判断名为 regist_recorder 的触发器是否存在
DROP TRIGGER regist_recorder -- 删除触发器
GO
CREATE TRIGGER regist_recorder
ON SysUser
AFTER
INSERT
AS
declare @UserName nchar(20)
declare @DateTime datetime
declare @UserOperation nchar(200)
select @UserName = system_user
select @DateTime = CONVERT(datetime,GETDATE(),120)
declare @op varchar(10)
select @op=case when exists(select 1 from inserted) and exists(select 1 from deleted)
then 'Update'
when exists(select 1 from inserted) and not exists(select 1 from deleted)
then 'Insert'
when not exists(select 1 from inserted) and exists(select 1 from deleted)
then 'Delete' end
select @UserOperation = @op
VS中代码:
全局变量
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Student_System
{
class Class1
{
public static string totalID;
public static string Mobile;
}
}
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 Student_System
{
public partial class 学生系统 : Form
{
public 学生系统()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
STUDENT stu = new STUDENT();
stu.Show();
this.Hide();
}
private void button2_Click(object sender, EventArgs e)
{
TEACHER tea = new TEACHER();
tea.Show();
this.Hide();
}
private void 学生系统_Load(object sender, EventArgs e)
{
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Student_System
{
public partial class STUDENT : Form
{
public STUDENT()
{
InitializeComponent();
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
RESGISTER res = new RESGISTER();
res.Show();
}
public string code;
private void STUDENT_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));
else
code1 = (char)('A' + (char)(number % 26)); //转化为字符
this.code += code1.ToString();
}
label5.Text = code;
}
protected void button1_Click(object sender, EventArgs e) //登录
{
string userID = textBox1.Text.Trim(); //取出账号
string password = EncryptWithMD5(textBox2.Text.Trim()); //取出密码并加密
Class1.totalID = userID;
//string connstr = ConfigurationManager.ConnectionStrings["connectionString"].ToString(); //读取连接字符串
string myConnString = "Data Source=.;Initial Catalog=FinalLogin;Persist Security Info=True;User ID=sa;Password=123456";
SqlConnection sqlConnection = new SqlConnection(myConnString); //实例化连接对象
sqlConnection.Open();
string sql = "select UserID,UserPassword from SysUser where UserID = '" + userID + "' and UserPassword = '" + password + "'"; //编写SQL命令
SqlCommand sqlCommand = new SqlCommand(sql, sqlConnection);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.HasRows && textBox3.Text == code)
{
MessageBox.Show("欢迎使用!"); //登录成功
StuMain form2 = new StuMain();
form2.Show();
}
else
{
MessageBox.Show("登录失败!");
return;
}
sqlDataReader.Close();
sql = "insert into SysLog values ( '" + userID + "' , '" + DateTime.Now + "' , '" + "Login" + "')"; //编写SQL命令
sqlCommand = new SqlCommand(sql, sqlConnection);
sqlCommand.ExecuteNonQuery();
sqlConnection.Close();
}
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();
}
public Byte[] mybyte = new byte[0];
private void textBox1_Leave(object sender, EventArgs e) //当鼠标离开ID框时
{
try
{
string connString = "Data Source=.;Initial Catalog=FinalLogin;Persist Security Info=True;User ID=sa;Password=123456";//数据库连接字符串
SqlConnection connection = new SqlConnection(connString);//创建connection对象
//打开数据库连接
connection.Open();
//创建SQL语句
string sql = "select UserPhoto from SysUser where UserID = '" + textBox1.Text + "'";
//创建SqlCommand对象
SqlCommand command = new SqlCommand(sql, connection);
//创建DataAdapter对象
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
//创建DataSet对象
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "SysUser");
int c = dataSet.Tables["SysUser"].Rows.Count;
if (c > 0)
{
Byte[] mybyte = new byte[0];
mybyte = (Byte[])(dataSet.Tables["SysUser"].Rows[c - 1]["UserPhoto"]);
MemoryStream ms = new MemoryStream(mybyte);
pictureBox1.Image = Image.FromStream(ms);
}
else
pictureBox1.Image = null;
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void pictureBox1_Click(object sender, EventArgs e) //插入图片
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
StuPassword stuPassword = new StuPassword();
stuPassword.Show();
}
}
}
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 Student_System
{
public partial class StuMain : Form
{
public StuMain()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
StuMessage sm = new StuMessage();
sm.Show();
}
private void button2_Click(object sender, EventArgs e)
{
StuGrade sg = new StuGrade();
sg.Show();
}
private void button3_Click(object sender, EventArgs e)
{
StuProject sp = new StuProject();
sp.Show();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Student_System
{
public partial class StuMessage : Form
{
public StuMessage()
{
InitializeComponent();
}
private void label8_Click(object sender, EventArgs e) //学号
{
}
private void label9_Click(object sender, EventArgs e) //姓名
{
}
private void label10_Click(object sender, EventArgs e)
{
}
private void label11_Click(object sender, EventArgs e)
{
}
private void label12_Click(object sender, EventArgs e)
{
}
private void label13_Click(object sender, EventArgs e)
{
}
private void StuMessage_Load(object sender, EventArgs e)
{
label8.Text = Class1.totalID;
try
{
string connString = "Data Source=.;Initial Catalog=FinalLogin;Persist Security Info=True;User ID=sa;Password=123456";//数据库连接字符串
SqlConnection connection = new SqlConnection(connString);//创建connection对象
//打开数据库连接
connection.Open();
//创建SQL语句
string sql = "select UserName,UserSex,UserBirthday,UserMobile,UserMajor,UserPhoto from SysUser where UserID = '" + Class1.totalID + "'";
//创建SqlCommand对象
SqlCommand command = new SqlCommand(sql, connection);
//创建DataAdapter对象
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
//创建DataSet对象
dataAdapter.SelectCommand = command;
DataSet dt = new DataSet();
dataAdapter.Fill(dt);
int b = dt.Tables[0].Rows.Count;
if (b > 0)
{
label9.Text = dt.Tables[0].Rows[0]["username"].ToString();
label10.Text = dt.Tables[0].Rows[0]["usersex"].ToString();
label11.Text = dt.Tables[0].Rows[0]["userbirthday"].ToString();
label12.Text = dt.Tables[0].Rows[0]["usermajor"].ToString();
label13.Text = dt.Tables[0].Rows[0]["usermobile"].ToString();
Class1.Mobile = label13.Text;
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
try
{
string connString = "Data Source=.;Initial Catalog=FinalLogin;Persist Security Info=True;User ID=sa;Password=123456";//数据库连接字符串
SqlConnection connection = new SqlConnection(connString);//创建connection对象
//打开数据库连接
connection.Open();
//创建SQL语句
string sql = "select UserPhoto from SysUser where UserID = '" + Class1.totalID + "'";
//创建SqlCommand对象
SqlCommand command = new SqlCommand(sql, connection);
//创建DataAdapter对象
SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
//创建DataSet对象
DataSet dataSet = new DataSet();
dataAdapter.Fill(dataSet, "SysUser");
int c = dataSet.Tables["SysUser"].Rows.Count;
if (c > 0)
{
Byte[] mybyte = new byte[0];
mybyte = (Byte[])(dataSet.Tables["SysUser"].Rows[c - 1]["UserPhoto"]);
MemoryStream ms = new MemoryStream(mybyte);
pictureBox1.Image = Image.FromStream(ms);
}
else
pictureBox1.Image = null;
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
ChageMobile cm = new ChageMobile();
cm.Show();
}
private void button3_Click(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Dispose();
}
}
}
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 Student_System
{
public partial class StuProject : Form
{
public StuProject()
{
InitializeComponent();
}
private void StuProject_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“finalLoginDataSet3.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter1.Fill(this.finalLoginDataSet3.Course);
// TODO: 这行代码将数据加载到表“finalLoginDataSet1.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet1.Course);
}
private void button1_Click(object sender, EventArgs e) //加课
{
string Cno = textBox1.Text.Trim();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
con.Open();
string insertStr = "INSERT INTO SC(Sno,Cno) " +"VALUES ('" + Class1.totalID + "','" + Cno + "')";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
MessageBox.Show("更改成功!");
con.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
}
private void button4_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Student_System
{
public partial class RESGISTER : Form
{
public RESGISTER()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
public Byte[] mybyte = new byte[0];
private void button1_Click(object sender, EventArgs e) //上传图片
{
//打开浏览图片对话框
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.ShowDialog();
string picturePath = openFileDialog.FileName;//获取图片路径
//文件的名称,每次必须更换图片的名称,这里很为不便
//创建FileStream对象
FileStream fs = new FileStream(picturePath, FileMode.Open, FileAccess.Read);
//声明Byte数组
mybyte = new byte[fs.Length];
//读取数据
fs.Read(mybyte, 0, mybyte.Length);
pictureBox1.Image = Image.FromStream(fs);
fs.Close();
}
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 button2_Click(object sender, EventArgs e)
{
try
{
string connString = "Data Source=.;Initial Catalog=FinalLogin;Persist Security Info=True;User ID=sa;Password=123456";//数据库连接字符串
SqlConnection connection = new SqlConnection(connString);//创建connection对象
String sql = "insert into SysUser (UserID,UserPassWord,UserName,UserSex,UserBirthday,UserMobile,UserMajor ,UserPhoto ) " +
"values (@userid, @userpassword,@username,@usersex,@userbirthday,@usermobile,@usermajor,@userphoto)";
SqlCommand command = new SqlCommand(sql, connection);
SqlParameter sqlParameter = new SqlParameter("@userid", textBox1.Text);
command.Parameters.Add(sqlParameter);
sqlParameter = new SqlParameter("@userpassword", EncryptWithMD5(textBox4.Text));
command.Parameters.Add(sqlParameter);
sqlParameter = new SqlParameter("@username", textBox3.Text);
command.Parameters.Add(sqlParameter);
sqlParameter = new SqlParameter("@usersex", comboBox1.Text);
command.Parameters.Add(sqlParameter);
sqlParameter = new SqlParameter("@userbirthday", dateTimePicker1.Value);
command.Parameters.Add(sqlParameter);
sqlParameter = new SqlParameter("@usermobile", textBox2.Text);
command.Parameters.Add(sqlParameter);
sqlParameter = new SqlParameter("@usermajor", textBox5.Text);
command.Parameters.Add(sqlParameter);
sqlParameter = new SqlParameter("@userphoto", SqlDbType.VarBinary, mybyte.Length, ParameterDirection.Input, false, 0, 0, null, DataRowVersion.Current, mybyte);
command.Parameters.Add(sqlParameter);
//打开数据库连接
connection.Open();
command.ExecuteNonQuery();
connection.Close();
MessageBox.Show("register succeed");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
this.Close();
}
private void RESGISTER_Load(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void textBox1_Leave(object sender, EventArgs e)
{
String ID = textBox1.Text.Trim();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
con.Open();
string sql = "select * from Student where Sno = '" + ID + "'"; //编写SQL命令
SqlCommand sqlCommand = new SqlCommand(sql, con);
SqlDataReader sqlDataReader = sqlCommand.ExecuteReader();
if (sqlDataReader.HasRows)
{
}
else
{
MessageBox.Show("ID账号不匹配!");
return;
}
sqlDataReader.Close();
sqlCommand.ExecuteNonQuery();
con.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 Student_System
{
public partial class StuPassword : Form
{
public StuPassword()
{
InitializeComponent();
}
public string code;
private void StuPassword_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));
else
code1 = (char)('A' + (char)(number % 26)); //转化为字符
this.code += code1.ToString();
}
label7.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 button1_Click(object sender, EventArgs e) //确认
{
String UserID = textBox1.Text.Trim();
String UserMobile = textBox2.Text.Trim();
String UserPassword = textBox3.Text.Trim();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
if ( textBox5.Text == code)
{
con.Open();
string password = EncryptWithMD5(textBox3.Text.Trim());
string insertStr = "UPDATE SysUser SET UserPassword='" + password + "' WHERE UserID ='" + UserID + "' AND UserMobile='" + UserMobile + "'";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("更改成功!");
}
con.Dispose();
}
private void textBox4_Leave(object sender, EventArgs e)
{
String UserOldMobile = textBox3.Text.Trim();
String UserNewMobile = textBox4.Text.Trim();
if (UserOldMobile == UserNewMobile)
{
}
else
{
MessageBox.Show("密码不一样");
textBox4.Text = null;
}
}
private void button2_Click(object sender, EventArgs e)
{
this.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 Student_System
{
public partial class ChageMobile : Form
{
public ChageMobile()
{
InitializeComponent();
}
public string code;
private void ChageMobile_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));
else
code1 = (char)('A' + (char)(number % 26)); //转化为字符
this.code += code1.ToString();
}
label5.Text = code;
}
private void button1_Click(object sender, EventArgs e)
{
String UserOldMobile = textBox1.Text.Trim();
String UserNewMobile = textBox2.Text.Trim();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
try
{
if(textBox4.Text == code &&UserOldMobile==Class1.Mobile)
{
con.Open();
string insertStr = "UPDATE SysUser SET UserMobile='" + UserNewMobile + "' WHERE UserMobile ='" + UserOldMobile + "'";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
MessageBox.Show("更改成功!");
this.Close();
}
}
catch
{
MessageBox.Show("输入数据违反要求!");
}
finally
{
con.Dispose();
}
}
private void textBox3_Leave(object sender, EventArgs e)
{
String UserOldMobile = textBox2.Text.Trim();
String UserNewMobile = textBox3.Text.Trim();
if (UserOldMobile==UserNewMobile)
{
}
else
{
MessageBox.Show("密码不一样");
textBox3.Focus();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.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 Student_System
{
public partial class TEACHER : Form
{
public TEACHER()
{
InitializeComponent();
}
public string code;
private void TEACHER_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));
else
code1 = (char)('A' + (char)(number % 26)); //转化为字符
this.code += code1.ToString();
}
label5.Text = code;
}
private void button1_Click(object sender, EventArgs e)
{
string ID = textBox1.Text.Trim();
string Password = textBox2.Text.Trim();
if (ID == "admin" && Password == "123" && textBox3.Text == code)
{
MessageBox.Show("欢迎使用!");
TeaMain teaMain = new TeaMain();
teaMain.Show();
}
}
}
}
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 Student_System
{
public partial class TeaMain : Form
{
public TeaMain()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
TeaMessage teaMessage = new TeaMessage();
teaMessage.Show();
}
private void button2_Click(object sender, EventArgs e)
{
TeaCourse teaCourse = new TeaCourse();
teaCourse.Show();
}
private void button3_Click(object sender, EventArgs e)
{
TeaGrade teaGrade = new TeaGrade();
teaGrade.Show();
}
}
}
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 Student_System
{
public partial class TeaMessage : Form
{
public TeaMessage()
{
InitializeComponent();
}
private void TeaMessage_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“finalLoginDataSet8.Student”中。您可以根据需要移动或删除它。
this.studentTableAdapter.Fill(this.finalLoginDataSet8.Student);
// TODO: 这行代码将数据加载到表“finalLoginDataSet7.SysUser”中。您可以根据需要移动或删除它。
this.sysUserTableAdapter.Fill(this.finalLoginDataSet7.SysUser);
}
private void button1_Click(object sender, EventArgs e) //增加
{
String Sno = textBox1.Text.Trim();
String Sname = textBox2.Text.Trim();
String Ssex = textBox3.Text.Trim();
String Sage = textBox4.Text.Trim();
String Sdept = textBox5.Text.Trim();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
try
{
con.Open();
string insertStr = "INSERT INTO Student(Sno,Sname,Ssex,Sage,Sdept) " +
"VALUES ('" + Sno + "','" + Sname + "','" + Ssex + "','" + Sage +"','"+Sdept+ "')";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
MessageBox.Show("添加成功!");
}
catch
{
MessageBox.Show("输入数据违反要求!");
}
finally
{
con.Dispose();
}
// TODO: 这行代码将数据加载到表“finalLoginDataSet8.Student”中。您可以根据需要移动或删除它。
this.studentTableAdapter.Fill(this.finalLoginDataSet8.Student);
}
private void button2_Click(object sender, EventArgs e) //删除
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
try
{
con.Open();
string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
//选择的当前行第一列的值,也就是Sno
string delete_by_id = "delete from Student where Sno=" + select_id;
//删除语句
SqlCommand cmd = new SqlCommand(delete_by_id, con);
cmd.ExecuteNonQuery();
MessageBox.Show("删除成功!");
// TODO: 这行代码将数据加载到表“finalLoginDataSet8.Student”中。您可以根据需要移动或删除它。
this.studentTableAdapter.Fill(this.finalLoginDataSet8.Student);
}
catch
{
MessageBox.Show("请选择正确的行!");
}
finally
{
con.Dispose();
}
// TODO: 这行代码将数据加载到表“finalLoginDataSet8.Student”中。您可以根据需要移动或删除它。
this.studentTableAdapter.Fill(this.finalLoginDataSet8.Student);
}
private void button4_Click(object sender, EventArgs e) //查找
{
String Sno = textBox1.Text.Trim();
String Sname = textBox2.Text.Trim();
String Ssex = textBox3.Text.Trim();
String Sage = textBox4.Text.Trim();
String Sdept = textBox5.Text.Trim();
String conn = "Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456";
SqlConnection sqlConnection = new SqlConnection(conn); //实例化连接对象
try
{
if (Sno != "")
{
sqlConnection.Open();
String select_by_id = "select * from Student where Sno='" + Sno + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else if (Sname != "")
{
sqlConnection.Open();
String select_by_id = "select * from Student where Sname='" + Sname + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else if (Ssex != "")
{
sqlConnection.Open();
String select_by_id = "select * from Student where Ssex='" + Ssex + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else if (Sage != "")
{
sqlConnection.Open();
String select_by_id = "select * from Student where Sage='" + Sage + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else if (Sdept != "")
{
sqlConnection.Open();
String select_by_id = "select * from Student where Sdept='" + Sdept + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else
{
sqlConnection.Open();
String select_by_id = "select * from Student";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
// sqlDataReader.Close();
//cmd.ExecuteNonQuery();
MessageBox.Show("查找成功!");
}
catch
{
MessageBox.Show("查询语句有误,请认真检查SQL语句!");
}
finally
{
sqlConnection.Dispose();
}
}
private void button3_Click_1(object sender, EventArgs e) //完成
{
this.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 Student_System
{
public partial class TeaGrade : Form
{
public TeaGrade()
{
InitializeComponent();
}
private void TeaGrade_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“finalLoginDataSet4.SC”中。您可以根据需要移动或删除它。
this.sCTableAdapter.Fill(this.finalLoginDataSet4.SC);
}
private void button1_Click(object sender, EventArgs e)
{
String Sno = textBox1.Text.Trim();
String Cno = textBox2.Text.Trim();
String Grade = textBox3.Text.Trim();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
try
{
con.Open();
string insertStr = "UPDATE SC SET Grade='" + Grade + "' WHERE Sno ='" + Sno +"'AND Cno='" + Cno + "'";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
MessageBox.Show("添加成功!");
}
catch
{
MessageBox.Show("输入数据违反要求!");
}
finally
{
con.Dispose();
}
}
private void button2_Click(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“finalLoginDataSet4.SC”中。您可以根据需要移动或删除它。
this.sCTableAdapter.Fill(this.finalLoginDataSet4.SC);
}
}
}
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 Student_System
{
public partial class TeaCourse : Form
{
public TeaCourse()
{
InitializeComponent();
}
private void TeaCourse_Load(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“finalLoginDataSet6.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet6.Course);
}
private void label3_Click(object sender, EventArgs e)
{
}
private void button5_Click(object sender, EventArgs e)
{
// TODO: 这行代码将数据加载到表“finalLoginDataSet6.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet6.Course);
}
private void button1_Click(object sender, EventArgs e) //增加
{
String Cno = textBox1.Text.Trim();
String Cname = textBox2.Text.Trim();
String Cpno = textBox3.Text.Trim();
if (textBox3.Text.Trim() == "")
Cpno = null;
String Ccredit = textBox4.Text.Trim();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
try
{
con.Open();
string insertStr = "INSERT INTO Course(Cno,Cname,Cpno,Ccredit) " +
"VALUES ('" + Cno + "','" + Cname + "','" + Cpno + "','" + Ccredit + "')";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
MessageBox.Show("添加成功!");
}
catch
{
MessageBox.Show("输入数据违反要求!");
}
finally
{
con.Dispose();
}
// TODO: 这行代码将数据加载到表“finalLoginDataSet6.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet6.Course);
}
private void button2_Click(object sender, EventArgs e) //删除
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
try
{
con.Open();
string select_id = dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
//选择的当前行第一列的值,也就是Sno
string delete_by_id = "delete from Course where Cno=" + select_id;
//删除语句
SqlCommand cmd = new SqlCommand(delete_by_id, con);
cmd.ExecuteNonQuery();
MessageBox.Show("删除成功!");
// TODO: 这行代码将数据加载到表“finalLoginDataSet6.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet6.Course);
}
catch
{
MessageBox.Show("请选择正确的行!");
}
finally
{
con.Dispose();
}
// TODO: 这行代码将数据加载到表“finalLoginDataSet6.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet6.Course);
}
private void button6_Click(object sender, EventArgs e) //完成
{
this.Close();
}
private void button3_Click(object sender, EventArgs e) //修改
{
String Cno = textBox1.Text.Trim();
String Cname = textBox2.Text.Trim();
String Cpno = textBox3.Text.Trim();
String Ccredit = textBox4.Text.Trim();
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456");
try
{
con.Open();
if (Cpno != "")
{
string insertStr = "UPDATE Course SET Cpno='" + Cpno + "' WHERE Cno ='" + Cno + "'";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
}
else if (Cname != "")
{
string insertStr = "UPDATE Course SET Cname='" + Cname + "' WHERE Cno ='" + Cno + "'";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
}
else if (Ccredit != "")
{
string insertStr = "UPDATE Course SET Ccredit='" + Ccredit + "' WHERE Cno ='" + Cno + "'";
SqlCommand cmd = new SqlCommand(insertStr, con);
cmd.ExecuteNonQuery();
}
MessageBox.Show("修改成功!");
}
catch
{
MessageBox.Show("输入数据违反要求!");
}
finally
{
con.Dispose();
}
// TODO: 这行代码将数据加载到表“finalLoginDataSet6.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet6.Course);
}
private void button4_Click(object sender, EventArgs e) //查找
{
String Cno = textBox1.Text.Trim();
String Cname = textBox2.Text.Trim();
String Cpno = textBox3.Text.Trim();
String Ccredit = textBox4.Text.Trim();
String select_by_id=null;
// TODO: 这行代码将数据加载到表“finalLoginDataSet6.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet6.Course);
String conn = "Data Source=.;Initial Catalog=FinalLogin;User ID=sa;Password=123456";
SqlConnection sqlConnection = new SqlConnection(conn); //实例化连接对象
try
{
if (Cpno != "")
{
sqlConnection.Open();
select_by_id = "select * from Course where Cpno='" + Cpno + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else if (Cname != "")
{
sqlConnection.Open();
select_by_id = "select * from Course where Cname='" + Cname + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else if (Ccredit != "")
{
sqlConnection.Open();
select_by_id = "select * from Course where Ccredit='" + Ccredit + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else if (Cno != "")
{
sqlConnection.Open();
select_by_id = "select * from Course where Cno='" + Cno + "'";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
else
{
sqlConnection.Open();
select_by_id = "select * from Course";
SqlCommand cmd = new SqlCommand(select_by_id, sqlConnection);
SqlDataReader sqlDataReader = cmd.ExecuteReader();
BindingSource bindingSource = new BindingSource();
bindingSource.DataSource = sqlDataReader;
dataGridView1.DataSource = bindingSource;
}
// sqlDataReader.Close();
//cmd.ExecuteNonQuery();
MessageBox.Show("查找成功!");
}
catch
{
MessageBox.Show("查询语句有误,请认真检查SQL语句!");
}
finally
{
sqlConnection.Dispose();
}
// TODO: 这行代码将数据加载到表“finalLoginDataSet6.Course”中。您可以根据需要移动或删除它。
this.courseTableAdapter.Fill(this.finalLoginDataSet6.Course);
}
}
}
上面的是整个系统每个板块的理解,以及总体的功能划分。
说一些知识以外的话,再写简易系统方面,我还是太年轻,昨天我把大概框架写出来之后,我认为基本完成了,今天把一些功能在完善就结束了。是我太低估,细节决定成败这句话了,今天我认为要完成时,运行时,出现各种各样我没见过的错误,我就百度加上问同学,一路磕磕绊绊自我认为写好了,下午开始录视频,这个视频是真真的难录呀,一开始说话总时说一句忘一句,每次大概一分钟,后来说多了,也就开始顺利了,结果录到6-7分钟的时候出现报错,我之后灰溜溜的去改错,然后重新录,再然后录到我倒数第二个功能了,突然出现一个非常小的问题,我想要不一会剪一下,应该没啥大问题,录完之后,视频都没看,就下载了剪辑软件,开始剪辑,等待了一个漫长的导出功能之后,打开视频,天呢,这是什么鬼,为啥大半部分都是黑屏,并没有录完整我的屏幕,百度告诉我你的百分比不对,应该调成100%,然后我操作非常娴熟的开始了新的录制,最后终于录制成功。有些许的艰难,也感觉到老师上网课的艰辛,太累了。
以上就是今天的全部心路历程,感谢观看
附上网页链接:https://www.bilibili.com/video/BV1k5411p7rW