【C#】学生成绩管理系统设计 终
本帖最后由 夏沫梦影 于 2019-6-6 07:05 编辑功能介绍:
这是一个学生成绩管理系统。包括“登录窗体”、“主窗体”和“学生信息管理模块”、“课程信息管理模块”、“成绩管理模块”。项目运行以后只显示登录窗体,当输入正确的“用户名”和“密码”以后点击登录按钮,打开主窗体。主窗体上通过“主菜单”和“子菜单”触发相应模块功能。
https://i.loli.net/2019/06/02/5cf2bc6e57b5e76402.jpg
https://static.52pojie.cn/static/image/hrline/5.gifhttps://static.52pojie.cn/static/image/hrline/5.gifhttps://static.52pojie.cn/static/image/hrline/5.gifhttps://static.52pojie.cn/static/image/hrline/5.gif
数据库设计:
https://i.loli.net/2019/06/02/5cf2bfb1592b271435.pnghttps://i.loli.net/2019/06/06/5cf83bb3125ab70813.png相关资源下载:(包含数据库文件Access,图片资源以及。。。)蓝奏:https://www.lanzouj.com/i4gmg3g度盘:https://pan.baidu.com/s/10U-Fl9_3BWeCVTW5qeWfhA 提取码: 52pj2019/6/6更新说明: 登录窗体新增注册按钮、权限选项,主窗体新增改密按钮,修复一些异常报错,还有一些想法就不一一实践了,这是最后一次更新。
https://static.52pojie.cn/static/image/hrline/5.gifhttps://static.52pojie.cn/static/image/hrline/5.gifhttps://static.52pojie.cn/static/image/hrline/5.gifhttps://static.52pojie.cn/static/image/hrline/5.gif
1.窗体设计:
https://i.loli.net/2019/06/06/5cf83bb4a1f0212868.png
点击“登录”按钮以后连接数据库,验证用户输入信息是否正确,如正确,打开主窗体,隐藏登录窗体;如不正确,给出提示信息。点击“退出”按钮,关闭程序。
2.创建公共类DataAccess:
class DataAccess
{
string conStr;
OleDbConnection con;
//连接数据库
public void dataCon()
{
conStr = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" + Application.StartupPath + "\\student.mdb";
con = new OleDbConnection(conStr);
}
//查询数据库
public DataSet getDataSet(string sql)
{
DataSet ds = new DataSet();
try
{
con.Open();
OleDbCommand cmd = new OleDbCommand(sql, con);
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
da.Fill(ds);
return ds;
}
catch (Exception ex)
{
throw new Exception(ex.ToString());
}
finally
{
con.Close();
}
}
public bool sqlExec(string sql)
{
try
{
con.Open();
}
catch
{
MessageBox.Show("数据库未连接!");
}
try
{
OleDbCommand oledbCom = new OleDbCommand(sql, con);
oledbCom.ExecuteNonQuery();
return true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "提示");
return false;
}
finally
{
con.Close();
}
}
}
3.“登录”按钮及“退出”按钮点击事件: public static string Uname;
public static string Upsw;
private void BtLogin_Click(object sender, EventArgs e)
{
string username = txtUsername.Text.Trim();
string password = txtPassword.Text.Trim();
if (txtUsername.Text.Trim() != "" && txtPassword.Text.Trim()!=" ")
{
//连接数据库
DataAccess data = new DataAccess();
data.dataCon();
//查询数据库
string cmdStr = "Select * from Userinfo where Userid='"+username+"' and Userpwd='"+password+"'";
DataSet ds;
ds = data.getDataSet(cmdStr);
if (ds.Tables.Rows.Count == 1)
{
Uname = txtUsername.Text.Trim();
Upsw = txtPassword.Text.Trim();
FormMain fmain = new FormMain();
if (ds.Tables.Rows["Userlevel"].ToString() == "学生" && level.SelectedIndex == 0)
{
fmain.学生信息添加ToolStripMenuItem.Enabled = false;
fmain.学生信息修改ToolStripMenuItem.Enabled = false;
fmain.学生信息删除ToolStripMenuItem.Enabled = false;
fmain.课程信息ToolStripMenuItem.Enabled = false;
fmain.课程信息修改ToolStripMenuItem.Enabled = false;
fmain.课程信息删除ToolStripMenuItem.Enabled = false;
fmain.成绩添加ToolStripMenuItem.Enabled = false;
fmain.成绩删除ToolStripMenuItem.Enabled = false;
fmain.成绩修改ToolStripMenuItem.Enabled = false;
fmain.Show();
this.Hide();
}
else if (ds.Tables.Rows["Userlevel"].ToString() == "教师" && level.SelectedIndex == 1)
{
fmain.Show();
this.Hide();
}
else
{
MessageBox.Show("权限选择错误!!");
}
}else
{
MessageBox.Show("账号或密码错误!");
}
}
else
{
MessageBox.Show("用户名和密码不能为空!");
}
}
private void BtCanel_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void FormLogin_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void FormLogin_Load(object sender, EventArgs e)
{
level.SelectedIndex = 0;
}
private void linkLabel_Regist_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
FormRegist Regist = new FormRegist();
Regist.Show();
}
4.主窗体:
https://i.loli.net/2019/06/06/5cf83bb33b44010236.pnghttps://i.loli.net/2019/06/02/5cf2c76e5738b29033.jpg 通过点击各个子菜单项及工具栏按钮打开相应子窗体。
5.主窗体菜单、工具按钮点击事件:private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
private void FormMain_Load(object sender, EventArgs e)
{
timer1.Interval = 1000;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
this.toolStripStatusLabel3.Text = "登录时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
}
private void 学生信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageStu ManageStu = new frmManageStu();
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data = new DataAccess();
data.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds;
ds = data.getDataSet(cmdStr);
if (ds.Tables.Rows["Userlevel"].ToString() == "学生" )
{
ManageStu.btnDel.Enabled = false;
ManageStu.btnEdit.Enabled = false;
}
ManageStu.MdiParent = this;
ManageStu.Show();
}
private void 学生信息添加ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmAddStu Addstu = new frmAddStu();
Addstu.MdiParent = this;
Addstu.Show();
}
private void 学生信息修改ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageStu ManageStu = new frmManageStu();
ManageStu.MdiParent = this;
ManageStu.Show();
}
private void 学生信息删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageStu ManageStu = new frmManageStu();
ManageStu.MdiParent = this;
ManageStu.Show();
}
private void 课程信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageCourse ManageCourse = new frmManageCourse();
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data = new DataAccess();
data.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds;
ds = data.getDataSet(cmdStr);
if (ds.Tables.Rows["Userlevel"].ToString() == "学生")
{
ManageCourse.btnDel.Enabled = false;
ManageCourse.btnEdit.Enabled = false;
}
ManageCourse.MdiParent = this;
ManageCourse.Show();
}
private void 课程信息修改ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmAddCourse AddCourse = new frmAddCourse();
AddCourse.MdiParent = this;
AddCourse.Show();
}
private void 课程信息ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageCourse ManageCourse = new frmManageCourse();
ManageCourse.MdiParent = this;
ManageCourse.Show();
}
private void 课程信息删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageCourse ManageCourse = new frmManageCourse();
ManageCourse.MdiParent = this;
ManageCourse.Show();
}
private void 成绩查询ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageScore ManageScore = new frmManageScore();
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data = new DataAccess();
data.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds;
ds = data.getDataSet(cmdStr);
if (ds.Tables.Rows["Userlevel"].ToString() == "学生")
{
ManageScore.btnDel.Enabled = false;
ManageScore.btnEdit.Enabled = false;
}
ManageScore.MdiParent = this;
ManageScore.Show();
}
private void 成绩修改ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageScore ManageScore = new frmManageScore();
ManageScore.MdiParent = this;
ManageScore.Show();
}
private void 成绩删除ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmManageScore ManageScore = new frmManageScore();
ManageScore.MdiParent = this;
ManageScore.Show();
}
private void 成绩添加ToolStripMenuItem_Click(object sender, EventArgs e)
{
frmAddCredit AddCredit = new frmAddCredit();
AddCredit.MdiParent = this;
AddCredit.Show();
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
frmManageStu ManageStu = new frmManageStu();
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data = new DataAccess();
data.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds;
ds = data.getDataSet(cmdStr);
if (ds.Tables.Rows["Userlevel"].ToString() == "学生")
{
ManageStu.btnDel.Enabled = false;
ManageStu.btnEdit.Enabled = false;
}
ManageStu.MdiParent = this;
ManageStu.Show();
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
frmManageCourse ManageCourse = new frmManageCourse();
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data = new DataAccess();
data.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds;
ds = data.getDataSet(cmdStr);
if (ds.Tables.Rows["Userlevel"].ToString() == "学生")
{
ManageCourse.btnDel.Enabled = false;
ManageCourse.btnEdit.Enabled = false;
}
ManageCourse.MdiParent = this;
ManageCourse.Show();
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
frmManageScore ManageScore = new frmManageScore();
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data = new DataAccess();
data.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds;
ds = data.getDataSet(cmdStr);
if (ds.Tables.Rows["Userlevel"].ToString() == "学生")
{
ManageScore.btnDel.Enabled = false;
ManageScore.btnEdit.Enabled = false;
}
ManageScore.MdiParent = this;
ManageScore.Show();
}
private void 关于AToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("终于完工了。。。开森 ^ _ ^");
}
private void 修改密码PToolStripMenuItem_Click(object sender, EventArgs e)
{
frmPswChange PC = new frmPswChange();
PC.MdiParent = this;
PC.Show();
}
6.学生信息添加窗体。能够将学生信息添加到数据库中。
https://i.loli.net/2019/06/02/5cf2c9efd00b514709.png
按钮点击事件:
private void btnAdd_Click(object sender, EventArgs e)
{
string strSql;
DataAccess data = new DataAccess();
strSql = "insert into Studentinfo (Sid,Sname,Sex,Birthday,Class,Tel,Address) values ('" + txtSid.Text + "','" + txtSname.Text + "','" + cboSex.Text + "','" + txtBirthday.Text + "','" + txtClass.Text + "','" + txtTel.Text + "','" + txtAddress.Text + "')";
data.dataCon();
if (data.sqlExec(strSql))
{
MessageBox.Show("添加成功!!");
}
else
{
MessageBox.Show("添加失败!!");
}
}
private void btnCancle_Click(object sender, EventArgs e)
{
this.Close();
}
7.学生信息管理窗体。能够“查询”、“删除”及“修改”学生信息。
https://i.loli.net/2019/06/02/5cf2cb386651180333.png
按钮点击事件:
public frmManageStu()
{
InitializeComponent();
check();
}
public static string sid;
public static string Sid
{
get { return sid; }
set { sid = value; }
}
public void check()
{
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data1 = new DataAccess();
data1.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds1;
ds1 = data1.getDataSet(cmdStr);
if (ds1.Tables.Rows["Userlevel"].ToString() == "学生")
{
string strSql;
DataAccess data = new DataAccess();
DataSet ds;
strSql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where Sid='" + username + "'";
data.dataCon();
ds = data.getDataSet(strSql);
txtSid.Text = ds.Tables.Rows.ToString();
txtSid.Enabled = false;
txtSname.Text = ds.Tables.Rows.ToString();
txtSname.Enabled = false;
cboSex.Text = ds.Tables.Rows.ToString();
cboSex.Enabled = false;
txtClass.Text = ds.Tables.Rows.ToString();
txtClass.Enabled = false;
}
}
private void btnSeach_Click(object sender, EventArgs e)
{
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data1 = new DataAccess();
data1.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds1;
ds1 = data1.getDataSet(cmdStr);
if (ds1.Tables.Rows["Userlevel"].ToString() == "学生")
{
string strSql;
DataAccess data = new DataAccess();
DataSet ds;
strSql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where Sid='"+username+"'";
data.dataCon();
ds = data.getDataSet(strSql);
dgvInfo.DataSource = ds.Tables;
}
else
{
string strSql;
string condition = "";
DataAccess data = new DataAccess();
DataSet ds;
if (txtSid.Text != "")
{
condition += "and Sid='" + txtSid.Text + "'";
}
if (txtSname.Text != "")
{
condition += "and Sname='" + txtSname.Text + "'";
}
if (txtClass.Text != "")
{
condition += "and Class='" + txtClass.Text + "'";
}
if (cboSex.Text != "")
{
condition += "and Sex='" + cboSex.Text + "'";
}
strSql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where 1=1" + condition;
data.dataCon();
ds = data.getDataSet(strSql);
dgvInfo.DataSource = ds.Tables;
}
}
private void btnDel_Click(object sender, EventArgs e)
{
if (dgvInfo.CurrentRow == null)
{
MessageBox.Show("请先查询!!");
}
else
{
string strSql;
DataAccess data = new DataAccess();
strSql = "delete from Studentinfo where Sid='" + dgvInfo.CurrentRow.Cells.Value.ToString() + "'";
data.dataCon();
if (data.sqlExec(strSql))
{
string Strsql;
DataAccess data1 = new DataAccess();
DataSet ds;
Strsql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where 1=1";
data1.dataCon();
ds = data1.getDataSet(Strsql);
dgvInfo.DataSource = ds.Tables;
MessageBox.Show("删除成功!!");
}
else
{
MessageBox.Show("删除失败!!");
}
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (dgvInfo.CurrentRow == null)
{
MessageBox.Show("请先查询!!");
}
else
{
frmManageStu.sid = dgvInfo.CurrentRow.Cells.Value.ToString();
frmEditStu s1 = new frmEditStu();
s1.txtSid.Enabled = false;
s1.Show();
}
}
8.学生信息修改窗体。当在学生信息管理窗体上点击“修改”按钮时,能弹出修改学生信息窗体,该窗体够修改学生信息。
https://i.loli.net/2019/06/02/5cf2cc2a5b1c978900.png
按钮点击事件:
private void btnEdit_Click(object sender, EventArgs e)
{
string strSql = "";
if (txtSname.Text != "" && txtBirthday.Text != "" && txtClass.Text != "" && txtTel.Text != "" && txtAddress.Text != "")
{
strSql = "update Studentinfo set Sname='" + txtSname.Text + "',Sex='" + cboSex.Text + "',Birthday='" + txtBirthday.Text + "',Class='" + txtClass.Text + "',Tel='" + txtTel.Text + "',Address='" + txtAddress.Text + "' where Sid='" + frmManageStu.sid + "'";
DataAccess data = new DataAccess();
data.dataCon();
if (data.sqlExec(strSql))
{
MessageBox.Show("修改成功!!");
}
else
{
MessageBox.Show("修改失败!!");
}
}
else
{
MessageBox.Show("输入未完全!!");
}
}
private void frmEditStu_Load(object sender, EventArgs e)
{
txtSid.Text = frmManageStu.sid;
}
private void btnCancle_Click(object sender, EventArgs e)
{
this.Close();
}
9.课程信息添加窗体。能够将课程信息添加到数据库中。
https://i.loli.net/2019/06/02/5cf2ccdc52a2d21328.png
按钮点击事件:
private void btnAdd_Click(object sender, EventArgs e)
{
string strSql;
DataAccess data = new DataAccess();
strSql = "insert into Courseinfo (Cid,Cname,Credit) values ('" + txtCid.Text + "','" + txtCname.Text + "','" + txtCredit.Text + "')";
data.dataCon();
if (data.sqlExec(strSql))
{
MessageBox.Show("添加成功!!");
}
else
{
MessageBox.Show("添加失败!!");
}
}
private void btnCancle_Click(object sender, EventArgs e)
{
this.Close();
}
10.课程信息管理窗体。能够“查询”、“删除”及“修改”课程信息。
https://i.loli.net/2019/06/02/5cf2cdb64178316212.png
按钮点击事件:
public static string cid;
public static string Cid
{
get { return cid; }
set { cid = value; }
}
private void btnSeach_Click(object sender, EventArgs e)
{
string strSql;
string condition = "";
DataAccess data = new DataAccess();
DataSet ds;
if (txtCid.Text != "")
{
condition += "and Cid='" + txtCid.Text + "'";
}
if (txtCname.Text != "")
{
condition += "and Cname='" + txtCname.Text + "'";
}
strSql = "select Cid as 课程编号,Cname as 课程名称,Credit as 学分 from Courseinfo where 1=1" + condition;
data.dataCon();
ds = data.getDataSet(strSql);
dgvInfo.DataSource = ds.Tables;
}
private void btnDel_Click(object sender, EventArgs e)
{
if (dgvInfo.CurrentRow == null)
{
MessageBox.Show("请先查询!!");
}
else
{
string strSql;
DataAccess data = new DataAccess();
strSql = "delete from Courseinfo where Cid='" + dgvInfo.CurrentRow.Cells.Value.ToString()+"'";
data.dataCon();
if (data.sqlExec(strSql))
{
string Strsql;
DataAccess data1 = new DataAccess();
DataSet ds;
Strsql = "select Cid as 课程编号,Cname as 课程名称,Credit as 学分 from Courseinfo where 1=1";
data1.dataCon();
ds = data1.getDataSet(Strsql);
dgvInfo.DataSource = ds.Tables;
MessageBox.Show("删除成功!!");
}
else
{
MessageBox.Show("删除失败!!");
}
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (dgvInfo.CurrentRow == null)
{
MessageBox.Show("请先查询!!");
}
else
{
frmManageCourse.cid = dgvInfo.CurrentRow.Cells.Value.ToString();
frmEditCourse s1 = new frmEditCourse();
s1.txtCid.Enabled = false;
s1.Show();
}
}
11.课程信息修改窗体。当在课程信息管理窗体上点击“修改”按钮时,能够弹出修改课程信息窗体,该窗体能够修改课程信息。
https://i.loli.net/2019/06/02/5cf2cf5b78eda26794.png
按钮点击事件:
private void btnEdit_Click(object sender, EventArgs e)
{
string strSql = "";
if (txtCid.Text != "" && txtCname.Text != "" && txtCredit.Text != "")
{
strSql = "update Courseinfo set Cname='" + txtCname.Text + "',Credit='" + txtCredit.Text + "' where Cid='" + frmManageCourse.cid + "'";
DataAccess data = new DataAccess();
data.dataCon();
if (data.sqlExec(strSql))
{
MessageBox.Show("修改成功!!");
}
else
{
MessageBox.Show("修改失败!!");
}
}
else
{
MessageBox.Show("输入未完全!!");
}
}
private void btnCancle_Click(object sender, EventArgs e)
{
this.Close();
}
private void frmEditCourse_Load(object sender, EventArgs e)
{
txtCid.Text = frmManageCourse.cid;
}
12.成绩添加窗体。能够添加学生相应课程的成绩到数据库中。
https://i.loli.net/2019/06/02/5cf2d00417eaa74313.png
按钮点击事件:
private void btnAdd_Click(object sender, EventArgs e)
{
string strSql;
DataAccess data = new DataAccess();
strSql = "insert into Scoreinfo (Sid,Cid,Score) values ('" + txtSid.Text + "','" + txtCid.Text + "','" + txtScore.Text + "')";
data.dataCon();
if (data.sqlExec(strSql))
{
MessageBox.Show("添加成功!!");
}
else
{
MessageBox.Show("添加失败!!");
}
}
private void btnCancle_Click(object sender, EventArgs e)
{
this.Close();
}
13.成绩管理窗体。能够“查询”、“删除”及“修改”学生的成绩。
https://i.loli.net/2019/06/02/5cf2d0b648a1656972.png
按钮点击事件:
public frmManageScore()
{
InitializeComponent();
check();
}
public void check()
{
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data1 = new DataAccess();
data1.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds1;
ds1 = data1.getDataSet(cmdStr);
if (ds1.Tables.Rows["Userlevel"].ToString() == "学生")
{
string strSql;
DataAccess data = new DataAccess();
DataSet ds;
strSql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where Sid='" + username + "'";
data.dataCon();
ds = data.getDataSet(strSql);
txtSid.Text = ds.Tables.Rows.ToString();
txtSid.Enabled = false;
txtSname.Text = ds.Tables.Rows.ToString();
txtSname.Enabled = false;
txtClass.Text = ds.Tables.Rows.ToString();
txtClass.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
DataAccess data1 = new DataAccess();
data1.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds1;
ds1 = data1.getDataSet(cmdStr);
if (ds1.Tables.Rows["Userlevel"].ToString() == "学生")
{
string strSql;
string condition = "";
DataAccess data = new DataAccess();
DataSet ds;
if (txtCid.Text != "")
{
if (txtCid.Text == "all")
{
strSql = " SELECT Courseinfo.Cid as 课程号, Courseinfo.Cname as 课程名称, Studentinfo.Sname as 姓名, Studentinfo.Class as 班级, Studentinfo.Sid as 学号, Scoreinfo.Scoreas 成绩 FROM Studentinfo ,Courseinfo , Scoreinfo where Courseinfo.Cid = Scoreinfo.Cid and Studentinfo.Sid = Scoreinfo.Sid and Studentinfo.Sid='" + txtSid.Text + "' ";
data.dataCon();
ds = data.getDataSet(strSql);
dgvInfo.DataSource = ds.Tables;
}
else
{
MessageBox.Show("输入all查询所有成绩");
condition += "and Courseinfo.Cid='" + txtCid.Text + "'";
strSql = " SELECT Courseinfo.Cid as 课程号, Courseinfo.Cname as 课程名称, Studentinfo.Sname as 姓名, Studentinfo.Class as 班级, Studentinfo.Sid as 学号, Scoreinfo.Scoreas 成绩 FROM Studentinfo ,Courseinfo , Scoreinfo where Courseinfo.Cid = Scoreinfo.Cid and Studentinfo.Sid = Scoreinfo.Sid and Studentinfo.Sid='" + txtSid.Text + "' " + condition;
data.dataCon();
ds = data.getDataSet(strSql);
dgvInfo.DataSource = ds.Tables;
}
}
else
{
MessageBox.Show("请输入要查的课程编号!!");
}
}
else
{
string strSql;
string condition = "";
DataAccess data = new DataAccess();
DataSet ds;
if (txtSid.Text != "")
{
condition += "and Studentinfo.Sid='" + txtSid.Text + "'";
}
if (txtSname.Text != "")
{
condition += "and Sname='" + txtSname.Text + "'";
}
if (txtClass.Text != "")
{
condition += "and Class='" + txtClass.Text + "'";
}
if (txtCid.Text != "")
{
condition += "and Courseinfo.Cid='" + txtCid.Text + "'";
}
strSql = " SELECT Courseinfo.Cid as 课程号, Courseinfo.Cname as 课程名称, Studentinfo.Sname as 姓名, Studentinfo.Class as 班级, Studentinfo.Sid as 学号, Scoreinfo.Scoreas 成绩 FROM Studentinfo ,Courseinfo , Scoreinfo where Courseinfo.Cid = Scoreinfo.Cid and Studentinfo.Sid = Scoreinfo.Sid" + condition;
data.dataCon();
ds = data.getDataSet(strSql);
dgvInfo.DataSource = ds.Tables;
}
}
private void btnEdit_Click(object sender, EventArgs e)
{
if (dgvInfo.CurrentRow == null)
{
MessageBox.Show("请先查询!!");
}
else
{
string strSql;
DataAccess data = new DataAccess();
strSql = " update Scoreinfo set Score='" + dgvInfo.CurrentRow.Cells.Value.ToString() + "' where Sid='" + dgvInfo.CurrentRow.Cells.Value.ToString() + "'and Cid='" + dgvInfo.CurrentRow.Cells.Value.ToString() + "'";
data.dataCon();
if (data.sqlExec(strSql))
{
MessageBox.Show("修改成功!!");
}
else
{
MessageBox.Show("修改失败!!");
}
}
}
private void btnDel_Click(object sender, EventArgs e)
{
if (dgvInfo.CurrentRow == null)
{
MessageBox.Show("请先查询!!");
}
else
{
string strSql;
DataAccess data = new DataAccess();
strSql = "delete from Scoreinfo where Cid='" + dgvInfo.CurrentRow.Cells.Value.ToString() + "' and Sid='" + dgvInfo.CurrentRow.Cells.Value.ToString() + "'";
data.dataCon();
if (data.sqlExec(strSql))
{
string Strsql;
DataAccess data1 = new DataAccess();
DataSet ds;
Strsql = " SELECT Courseinfo.Cid as 课程号, Courseinfo.Cname as 课程名称, Studentinfo.Sname as 姓名, Studentinfo.Class as 班级, Studentinfo.Sid as 学号, Scoreinfo.Scoreas 成绩 FROM Studentinfo ,Courseinfo , Scoreinfo where Courseinfo.Cid = Scoreinfo.Cid and Studentinfo.Sid = Scoreinfo.Sid";
data1.dataCon();
ds = data1.getDataSet(Strsql);
dgvInfo.DataSource = ds.Tables;
MessageBox.Show("删除成功!!");
}
else
{
MessageBox.Show("删除失败!!");
}
}
}
14.注册窗口 https://i.loli.net/2019/06/06/5cf8499dde6e412368.png按钮点击事件:public FormRegist()
{
InitializeComponent();
data();
}
public void data()
{
string strSql;
DataAccess data = new DataAccess();
data.dataCon();
strSql = "select Sid from Studentinfo";
DataSet ds;
ds = data.getDataSet(strSql);
if (ds.Tables.Rows.Count>0)
{
for (int i = 0; i <ds.Tables.Rows.Count; i++)
{
txtUsername.Items.Add(ds.Tables.Rows.ToString());
}
}
}
private void btnRegist_Click(object sender, EventArgs e)
{
string Username = txtUsername.Text.Trim();
string UserPsw = txtPsw.Text.Trim();
string UserRPsw = txtRPsw.Text.Trim();
string UserLevel = cboLevel.Text.Trim();
string StrSql;
DataAccess data0 = new DataAccess();
data0.dataCon();
StrSql = "select Userid from Userinfo where Userid='" + Username + "'";
DataSet ds0;
ds0 = data0.getDataSet(StrSql);
if (ds0.Tables.Rows.Count == 1)
{
MessageBox.Show("该账号已注册,请重新输入!!");
txtUsername.Text = "";
txtUsername.Focus();
}
else
{
if (Username == "")
{
MessageBox.Show("用户名不能为空!!");
}
else
{
if (UserPsw == "")
{
MessageBox.Show("密码不能为空!!");
}
else
{
if (UserPsw != UserRPsw)
{
MessageBox.Show("输入密码不一致!!");
}
else
{
if (cboLevel.Text == "学生")
{
string strSql;
DataAccess data = new DataAccess();
strSql = "insert into Userinfo (Userid,Userpwd,Userlevel) values ('" + Username + "','" + UserPsw + "','" + UserLevel + "')";
data.dataCon();
DialogResult Result = MessageBox.Show("信息无误确定注册", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (Result == DialogResult.Yes)
{
string Strsql;
DataAccess data1 = new DataAccess();
data1.dataCon();
Strsql = "select Sid from Studentinfo where Sid='" + Username + "'";
DataSet ds;
ds = data.getDataSet(Strsql);
if (ds.Tables.Rows.Count == 1)
{
if (data.sqlExec(strSql))
{
MessageBox.Show("成功注册!");
this.Close();
}
else
{
MessageBox.Show("注册失败!");
}
}
else
{
MessageBox.Show("未查找到此学号,请重新输入!!");
txtUsername.Text = "";
txtUsername.Focus();
}
}
}
}
if (cboLevel.Text == "教师")
{
string strSql;
DataAccess data = new DataAccess();
strSql = "insert into Userinfo (Userid,Userpwd,Userlevel) values ('" + Username + "','" + UserPsw + "','" + UserLevel + "')";
data.dataCon();
DialogResult Result = MessageBox.Show("信息无误确定注册", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (Result == DialogResult.Yes)
{
if (data.sqlExec(strSql))
{
MessageBox.Show("成功注册!");
this.Close();
}
else
{
MessageBox.Show("注册失败!");
}
}
}
}
}
}
}
private void btnCancle_Click(object sender, EventArgs e)
{
this.Close();
}
private void FormRegist_Load(object sender, EventArgs e)
{
cboLevel.SelectedIndex =0;
}
15.改密窗口
https://i.loli.net/2019/06/06/5cf83bb5ca24b25661.png
按钮点击事件:
private void PswChange_Load(object sender, EventArgs e)
{
txtUsername.Text = FormLogin.Uname;
}
private void btnchange_Click(object sender, EventArgs e)
{
string username = FormLogin.Uname;
string password = FormLogin.Upsw;
string strSql = "";
DataAccess data = new DataAccess();
data.dataCon();
string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
DataSet ds;
ds = data.getDataSet(cmdStr);
if (txtPassword.Text==password)
{
strSql = "update Userinfo set Userpwd='" + txtNewPsd.Text.Trim()+ "' where Userid='" + username + "'";
DataAccess data1 = new DataAccess();
data1.dataCon();
if (data1.sqlExec(strSql))
{
MessageBox.Show("修改密码成功!!");
this.Close();
}
else
{
MessageBox.Show("修改密码失败!!");
}
}
else
{
MessageBox.Show("原密码不正确!!");
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}相关资源下载请移步数据库设计。。。
本帖最后由 夏沫梦影 于 2020-6-19 10:34 编辑
Yanderedev 发表于 2020-6-18 22:56
怎么登录?小白,总是提示帐号或者密码错误?不是按照ACCESS表里的??怎么连上自己的数据库。
数据库扔在启动目录下,bin/Debug密码见下表,登陆的时候记得选对权限
//连接数据库
public void dataCon()
{
conStr = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" + Application.StartupPath + "\\student.mdb";
con = new OleDbConnection(conStr);
}
想要换自己的数据库,就把DataAccess里的 上段代码中的student.mdb改成自己的,不建议换,修改一下数据库里的东西就可以了 不知道楼主是不是和我一样是大学生 我现在学的.net web里面就有个教育管理系统 里面包含了楼主那个学生成绩系统 还有缴费系统 还有宿舍管理系统
如果是一样的 希望楼主能抽空做个宿舍管理系统 😂 要交作业。。。 不错,谢谢分享.....毕设?? 这个很好👍 可以,谢谢楼主 谢谢分享,学习一下 不错,谢谢楼主。 青鸟的课程对吗 ?
不错,虽然简陋了点儿。 一般情况下,我记得要加上权限管理及报错弹窗比较好 不错,学习了。