一、简介
使用C#进行可视化应用程序设计,实现一个简单的《学生信息管理系统》,用户可通过账号密码登录系统,进入系统后可以添加、显示、删除、修改、筛选、查询学生信息。
非计算机专业学生学了C#,课设要求做学生信息管理系统 ,本想着网上找一篇,结果全是使用数据库的,但是我没有学过数据库,对于期末赶课设的我来说,短时间内学会数据库并不简单。奈何寻觅无果,于是自己手搓了一个不使用数据库的,以供像我一样的同学参考。
二、原理介绍
该管理系统主要使用类和数组的方式是实现学生信息的管理与储存。通过foreach()函数来遍历数组中的信息达到查询与筛选的作用。使用xxx.Hide()与xxx.Show()两个函数实现窗口的转化以及选项的出现与消失。
原理比较简单,有基本的编程知识的同学看过之后都可以轻松修改和添加自己想要的功能。
三、功能介绍及代码实现
1、登录模块
//登录界面
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if(textBox1.Text=="123"&& textBox2.Text == "123")
{
Form2 Form = new Form2();
Form.Show();
this.Hide();
}
else
MessageBox.Show("信息输入不完整或错误!");
}
private void button2_Click_1(object sender, EventArgs e)
{
if (MessageBox.Show("您确定要退出系统吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
Application.Exit(); // 关闭应用程序窗口
}
}
private void label3_Click(object sender, EventArgs e)
{
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
}
用户操作
输入密码与账户,设置密码与账户都是“123”。若输入错误显示“输入信息不完整或者错误”
输入成功登录系统界面
2、显示模块
private void button1_Click(object sender, EventArgs e) //显示
{
listBox1.Items.Clear();
foreach (var student in students)
{
listBox1.Items.Add($"{student.Id}, {student.Name}, {student.Age}, {student.Grade}");
}
}
用户操作
按下显示学生信息按键显示输入系统中的学生信息(需先添加信息才能显示)
3、添加学生信息
private void button2_Click(object sender, EventArgs e) //添加
{
//listBox1.Items.Clear();
textBox1.Show();
textBox2.Show();
textBox3.Show();
button6.Show();
label3.Show();
label4.Show();
label5.Show();
}
private void button6_Click(object sender, EventArgs e) //增加执行
{
string name = textBox1.Text;
int age = int.Parse(textBox2.Text);
string grade = textBox3.Text;
Student student = new Student { Id = currentStudentId++, Name = name, Age = age, Grade = grade };
students.Add(student);
textBox1.Hide();
textBox2.Hide();
textBox3.Hide();
button6.Hide();
label3.Hide();
label4.Hide();
label5.Hide();
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
}
用户操作
按下添加学生信息按键,界面右上角出现输入姓名、年龄、年级。
输入信息按下确认输入界面随之消失
4、修改学生信息
private void button4_Click_1(object sender, EventArgs e) //修改
{
textBox4.Show();
textBox1.Show();
textBox2.Show();
textBox3.Show();
button9.Show();
label3.Show();
label4.Show();
label5.Show();
label2.Show();
}
private void button9_Click(object sender, EventArgs e) //修改执行
{
int id = int.Parse(textBox4.Text);
int index = int.Parse(textBox4.Text);
string name = textBox1.Text;
int age = int.Parse(textBox2.Text);
string grade = textBox3.Text;
Student student = new Student { Id = id, Name = name, Age = age, Grade = grade };
students[index-1] = student;
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
textBox4.Clear();
textBox1.Hide();
textBox2.Hide();
textBox3.Hide();
button9.Hide();
label3.Hide();
label4.Hide();
label5.Hide();
label2.Hide();
textBox4.Hide();
UpdateListBox();
}
用户操作
按下修改学生信息右上角出现ID、姓名、年龄、年级输入
用户可选择想要修改学生的ID来进行信息的修改
按下修改键、信息修改成功、修改输入消失。
5、删除学生信息
private void button3_Click_1(object sender, EventArgs e) //删除
{
//listBox1.Items.Clear();
textBox4.Show();
label2.Show();
button10.Show();
}
private void button10_Click(object sender, EventArgs e)//删除执行
{
int indx = int.Parse(textBox4.Text);
students.RemoveAt(indx-1);
textBox4.Hide();
label2.Hide();
button10.Hide();
textBox4.Clear();
UpdateListBox();
}
信息管理每一步操作类似不过多赘述
6、筛选学生信息
private void button8_Click(object sender, EventArgs e) //筛选
{
listBox1.Items.Clear();
label4.Show();
button11.Show();
textBox2.Show();
}
private void button11_Click(object sender, EventArgs e)//筛选执行
{
foreach (var student in students)
{
if (student.Age == int.Parse(textBox2.Text))
listBox1.Items.Add($"{student.Id}, {student.Name}, {student.Age}, {student.Grade}");
}
button11.Hide();
textBox2.Hide();
label4.Hide();
textBox2.Clear();
}
此处根据年龄筛选,大家可根据自己的需求更改。
7、查询学生信息
private void button7_Click(object sender, EventArgs e) //查询
{
listBox1.Items.Clear();
button12.Show();
textBox4.Show();
label2.Show();
}
private void button12_Click(object sender, EventArgs e)//查询执行
{
foreach (var student in students)
{
if (student.Id == int.Parse(textBox4.Text))
listBox1.Items.Add($"{student.Id}, {student.Name}, {student.Age}, {student.Grade}");
}
button12.Hide();
textBox4.Hide();
label2.Hide();
textBox4.Clear();
}
根据学生ID查询信息
四、结语
这是作者一个下午赶出来的,有许多地方有缺陷,但作为一个课设作业完成任务是足够了。附源代码文件一份,可以免费下载,代码逻辑简单,大家可再此基础上随意更改或完善以解燃眉之需。