一、系统概述
学生管理系统是一个旨在帮助学校、教育机构和教育者有效管理学生信息、课程安排和成绩记录的应用程序。该系统旨在简化学生管理的各个方面,提供高效的解决方案,以满足教育机构的需求。
二、功能模块
1. 学生信息管理
添加学生:录入学生基本信息(姓名、性别、学号等)
编辑学生:修改已经录入的学生信息
删除学生:通过学号删除指定学生信息
全部学生查询:查询所有录入学生信息
个别学生查询:支持按学号或姓名进行精确查询
2.班级管理
- 查询班级列表
- 按条件查询
- 新增班级
3.年级
- 查询所有年级
三、开发技术
前端:C# WinForm
后端:mysql
IDE:Visual Studio
四、数据库分析
1. ClassInfos(班级表)
- ClassId:班级编号(主键)
- ClassName:班级名称
- GradeId:年级编号(外键关联GradeInfos表)
- Remark:备注
主要记录每个年级下的各个班级名称等信息。
2. GradeInfos(年级表)
- GradeId:年级编号(主键)
- GradeName:年级名称
记录学校的各个年级名称。
3. StudentInfos(学生表)
- StuId:学生编号(主键)
- StuName:姓名
- ClassId:班级编号(外键关联ClassInfos表)
- Sex:性别
- Phone:电话
- CreateTime:创建时间(默认当前时间)
- IsDeleted:逻辑删除(默认0,不删除)
记录每个学生的详细信息。
4. UserInfos(用户表)
- UserId:用户编号(主键)
- UserName:用户名
- UserPwd:密码
记录应用的管理用户信息。
5. 总体关系:
班级表与年级表一对多,学生表与班级表一对多,表之间定义好外键关系。
基本上五张表记录了学生管理系统需要跟踪的所有实体信息,关系定义合理,能够很好支持学生管理相关业务开发。
四、程序截图
五、联系与交流
q:969060742 文档、代码、sql、程序资源
六、部分代码
FrmAddClass.cs
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 WinStudent
{
public partial class FrmAddClass : Form
{
public FrmAddClass()
{
InitializeComponent();
}
/// <summary>
/// 初始化年级列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmAddClass_Load(object sender, EventArgs e)
{
InitGradeList();//加载年级列表
}
//一个班级,必须属于某个年级
private void InitGradeList()
{
string sql = "select GradeId,GradeName from GradeInfos";
DataTable dtGradeList = SqlHelper.GetDataTable(sql);
cboGrades.DataSource = dtGradeList;
//年级名称 ---- 项
cboGrades.DisplayMember = "GradeName";//显示的内容
cboGrades.ValueMember = "GradeId";//值
cboGrades.SelectedIndex = 0;
}
/// <summary>
/// 添加班级
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnAdd_Click(object sender, EventArgs e)
{
//信息获取
string className = txtClassName.Text.Trim();
int gradeId = (int)cboGrades.SelectedValue;
string remark = txtRemark.Text.Trim();
//判断是否为空
if (string.IsNullOrEmpty(className))
{
MessageBox.Show("班级名称不能为空!", "添加班级提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//判断是否已存在 数据库里去检查--- 与数据库进行交互
{
string sqlExists = "select count(1) from ClassInfos where ClassName=@ClassName and GradeId=@GradeId";
SqlParameter[] paras =
{
new SqlParameter("@ClassName",className),
new SqlParameter("@GradeId",gradeId)
};
object oCount = SqlHelper.ExecuteScalar(sqlExists, paras);
if (oCount == null || oCount == DBNull.Value || ((int)oCount) == 0)
{
//添加操作
string sqlAdd = "insert into ClassInfos (ClassName,GradeId,Remark) values (@ClassName,@GradeId,@Remark)";
SqlParameter[] parasAdd =
{
new SqlParameter("@ClassName",className),
new SqlParameter("@GradeId",gradeId),
new SqlParameter("@Remark",remark)
};
//执行并返回值
int count = SqlHelper.ExecuteNonQuery(sqlAdd, parasAdd);
if(count>0)
{
MessageBox.Show($"班级:{className} 添加成功!", "添加班级提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("班级添加失败!", "添加班级提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
else
{
MessageBox.Show("班级名称已存在!", "添加班级提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
DrmAddClass.Designer.cs
namespace WinStudent
{
partial class FrmAddClass
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.btnClose = new System.Windows.Forms.Button();
this.btnAdd = new System.Windows.Forms.Button();
this.txtRemark = new System.Windows.Forms.TextBox();
this.cboGrades = new System.Windows.Forms.ComboBox();
this.txtClassName = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.panel1.AutoScroll = true;
this.panel1.Controls.Add(this.btnClose);
this.panel1.Controls.Add(this.btnAdd);
this.panel1.Controls.Add(this.txtRemark);
this.panel1.Controls.Add(this.cboGrades);
this.panel1.Controls.Add(this.txtClassName);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.label1);
this.panel1.Location = new System.Drawing.Point(25, 26);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(275, 257);
this.panel1.TabIndex = 0;
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(162, 222);
this.btnClose.Name = "btnClose";
this.btnClose.Size = new System.Drawing.Size(75, 23);
this.btnClose.TabIndex = 7;
this.btnClose.Text = "关闭";
this.btnClose.UseVisualStyleBackColor = true;
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// btnAdd
//
this.btnAdd.Location = new System.Drawing.Point(60, 222);
this.btnAdd.Name = "btnAdd";
this.btnAdd.Size = new System.Drawing.Size(75, 23);
this.btnAdd.TabIndex = 6;
this.btnAdd.Text = "添加";
this.btnAdd.UseVisualStyleBackColor = true;
this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
//
// txtRemark
//
this.txtRemark.Location = new System.Drawing.Point(60, 96);
this.txtRemark.Multiline = true;
this.txtRemark.Name = "txtRemark";
this.txtRemark.Size = new System.Drawing.Size(212, 93);
this.txtRemark.TabIndex = 5;
//
// cboGrades
//
this.cboGrades.FormattingEnabled = true;
this.cboGrades.Location = new System.Drawing.Point(60, 47);
this.cboGrades.Name = "cboGrades";
this.cboGrades.Size = new System.Drawing.Size(138, 20);
this.cboGrades.TabIndex = 4;
//
// txtClassName
//
this.txtClassName.Location = new System.Drawing.Point(60, 9);
this.txtClassName.Name = "txtClassName";
this.txtClassName.Size = new System.Drawing.Size(212, 21);
this.txtClassName.TabIndex = 3;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(5, 99);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(35, 12);
this.label3.TabIndex = 2;
this.label3.Text = "描述:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(5, 50);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(35, 12);
this.label2.TabIndex = 1;
this.label2.Text = "年级:";
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(3, 12);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(35, 12);
this.label1.TabIndex = 0;
this.label1.Text = "班名:";
//
// FrmAddClass
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(326, 313);
this.Controls.Add(this.panel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "FrmAddClass";
this.Text = "班级信息页面";
this.Load += new System.EventHandler(this.FrmAddClass_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TextBox txtRemark;
private System.Windows.Forms.ComboBox cboGrades;
private System.Windows.Forms.TextBox txtClassName;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnAdd;
}
}
FrmAddStudent.cs
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 WinStudent
{
public partial class FrmAddStudent : Form
{
public FrmAddStudent()
{
InitializeComponent();
}
private void btnAdd_Click(object sender, EventArgs e)
{
//1)获取页面信息输入
string stuName = txtStuName.Text.Trim();
int classId = (int)cboClasses.SelectedValue;
string sex = rbtMale.Checked ? rbtMale.Text.Trim() : rbtFemale.Text.Trim();
string phone = txtPhone.Text.Trim();
//2)判空处理 姓名不可以为空 电话不可以为空
if (string.IsNullOrEmpty(stuName))
{
MessageBox.Show("姓名不能为空!", "添加学生提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (string.IsNullOrEmpty(phone))
{
MessageBox.Show("电话不能为空!", "添加学生提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//3)判断 姓名+电话 是否在数据库里已存在 姓名+电话
string sql = "select count(1) from StudentInfos where StuName=@StuName and Phone=@phone";
SqlParameter[] paras =
{
new SqlParameter("@StuName",stuName),
new SqlParameter("@phone",phone)
};
object o = SqlHelper.ExecuteScalar(sql, paras);
if (o != null && o != DBNull.Value && ((int)o) > 0)
{
MessageBox.Show("该学生已存在!", "添加学生提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
//4)添加入库 sql 参数 执行 完成返回受影响行数
string sqlAdd = "insert into StudentInfos(StuName,ClassId,Sex,Phone) values(@StuName,@ClassId,@Sex,@Phone)";
SqlParameter[] parasAdd =
{
new SqlParameter("@StuName",stuName),
new SqlParameter("@ClassId",classId),
new SqlParameter("@Sex",sex),
new SqlParameter("@phone",phone)
};
int count = SqlHelper.ExecuteNonQuery(sqlAdd, parasAdd);
if(count>0)
{
MessageBox.Show($"学生:{stuName} 添加成功!", "添加学生提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MessageBox.Show("该学生添加失败,请检查!", "添加学生提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
}
/// <summary>
/// 加载班级列表\性别默认选择男
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FrmAddStudent_Load(object sender, EventArgs e)
{
InitClasses();//加载班级列表
rbtMale.Checked = true;
}
private void InitClasses()
{
//获取数据 ---- 查询 ---写sql
string sql = "select ClassId,ClassName,GradeName from ClassInfos c,GradeInfos g where c.GradeId=g.GradeId";
DataTable dtClasses = SqlHelper.GetDataTable(sql);
//组合班级列表显示项的过程
if (dtClasses.Rows.Count > 0)
{
foreach (DataRow dr in dtClasses.Rows)
{
string className = dr["ClassName"].ToString();
string gradeName = dr["GradeName"].ToString();
dr["ClassName"] = className + "--" + gradeName;
}
}
//指定数据源
cboClasses.DataSource = dtClasses;
cboClasses.DisplayMember = "ClassName";
cboClasses.ValueMember = "ClassId";
cboClasses.SelectedIndex = 0;
}
private void btnClose_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
FrmGradeList.cs
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 WinStudent
{
public partial class FrmGradeList : Form
{
public FrmGradeList()
{
InitializeComponent();
}
private void FrmGradeList_Load(object sender, EventArgs e)
{
string sql = "select GradeId,GradeName from GradeInfos";
DataTable dtGradeList = SqlHelper.GetDataTable(sql);
dgvGradeList.DataSource = dtGradeList;
}
}
}
FrmLogin.cs
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;
using System.Data.SqlClient;
namespace WinStudent
{
public partial class FrmLogin : Form
{
public FrmLogin()
{
InitializeComponent();
}
/// <summary>
/// 登录系统
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnLogin_Click(object sender, EventArgs e)
{
//获取用户输入信息
string uName = txtUserName.Text.Trim();
string uPwd = txtUserPwd.Text.Trim();
//判断是否为空
if(string.IsNullOrEmpty(uName))
{
MessageBox.Show("请输入账号!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUserName.Focus();
return;
}
if (string.IsNullOrEmpty(uPwd))
{
MessageBox.Show("请输入密码!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
txtUserPwd.Focus();
return;
}
//与数据库通信 检查输入与数据库中是否一致
{
//写查询语句 拼接式 Sql注入 推荐大家使用参数化Sql
string sql = "select count(1) from UserInfos where UserName=@UserName and UserPwd=@UserPwd";
SqlParameter[] paras =
{
new SqlParameter("@UserName", uName),
new SqlParameter("@UserPwd", uPwd)
};
建立与数据库的连接
连接字符串 --- 钥匙
string connString = "server=.;database=StudentDB;Integrated Security=true";//字符串 Windows身份验证
//string connString = "server=.;database=StudentDB;uid=lyc;pwd=123456;";//Sql Server 身份验证 Data Source Initial Catalog User Id Password
//SqlConnection conn = new SqlConnection(connString);
//添加参数
//SqlParameter paraUName = new SqlParameter("@UserName", uName);
//SqlParameter paraUPwd = new SqlParameter("@UserPwd", uPwd);
创建Command对象
//SqlCommand cmd = new SqlCommand(sql, conn);
cmd.CommandType = CommandType.StoredProcedure;//存储过程
//cmd.Parameters.Clear();
cmd.Parameters.Add(paraUName);
cmd.Parameters.Add(paraUPwd);
//cmd.Parameters.AddRange(paras);
打开连接
//conn.Open(); //最晚打开 最早关闭
执行命令 要求必须在连接状态 Opened
//object o = cmd.ExecuteScalar();//执行查询,返回结果集第一行第一列的值,忽略其他行或列
关闭连接
//conn.Close();
//调用
object o = SqlHelper.ExecuteScalar(sql, paras);
//处理结果
if (o==null||o==DBNull.Value ||((int)o)==0)
{
MessageBox.Show("登录账号或密码有错,请检查!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
else
{
MessageBox.Show("登录成功!", "登录提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
//转到主页面
FrmMain fMain = new FrmMain();
fMain.Show();
this.Hide();
}
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
// Application.Exit();
}
}
}