【2020.04.13改】c#学生管理系统三层架构(源码)
本帖最后由 凌凌壹 于 2020-4-13 11:08 编辑噔噔噔 2020.04.13改链接:https://lanzouj.com/ibbjg9g
在学习的路上一去不返,今日将这几天学习的一点点内容上传,望大佬赐教。
这次做成了三层架构,内含数据库。由于目前想不到太多的功能只做了增删改查询。各个模块功能也大体一致,所以只做了管理员的。
下面贴上一部分源码:
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 Bill;
using Model;
namespace StudentManagement.Admin
{
public partial class SubjectManagement : Form
{
#region 常量变量
public Subject subject = new Subject();
private SubjectManager subManager = new SubjectManager();
private TeacherManager teatManager = new TeacherManager();
private GradeManager graManager = new GradeManager();
#endregion
public SubjectManagement()
{
InitializeComponent();
}
//窗体初始化
private void CourseManagement_Load(object sender, EventArgs e)
{
//初始化使能
comboBoxCredit.Enabled = false;
comboBoxTime.Enabled = false;
comboBoxNo.Enabled = false;
comboBoxName.Enabled = false;
this.dataGridView1.DataSource = subManager.GetSujectData();//数据绑定
BindCombox();
}
#region 按钮事件
//单击添加按钮事件
private void toolStripButtonAdd_Click(object sender, EventArgs e)
{
//初始化使能
comboBoxCredit.Enabled = true;
comboBoxTime.Enabled = true;
comboBoxNo.Enabled = true;
comboBoxName.Enabled = true;
buttonFunction.Text = "保存添加";
}
//单击删除按钮
private void toolStripButtonDelete_Click(object sender, EventArgs e)
{
DialogResult r = MessageBox.Show("请确认是否删除选中信息", "提示", MessageBoxButtons.YesNo);
if (r == DialogResult.Yes)
{
int result;
string subNo = dataGridView1.SelectedCells.Value.ToString();
result = subManager.DeleteSubject(subNo);
if (result > 0)
{
this.dataGridView1.DataSource = subManager.GetSujectData();//数据绑定
BindCombox();
MessageBox.Show("已删除课程号为" + subNo + "的课程");
}
else
{
MessageBox.Show("删除课程号为" + subNo + "的课程失败");
}
}
}
//单击修改按钮事件
private void toolStripButtonChange_Click(object sender, EventArgs e)
{
//初始化使能
comboBoxCredit.Enabled = true;
comboBoxTime.Enabled = true;
//comboBoxNo.Enabled = true;
comboBoxName.Enabled = true;
buttonFunction.Text = "保存修改";
SelectedRows();
}
//单击搜索按钮事件
private void toolStripButtonSearch_Click(object sender, EventArgs e)
{
//初始化使能
comboBoxCredit.Enabled = false;
comboBoxTime.Enabled = false;
comboBoxNo.Enabled = false;
comboBoxName.Enabled = false;
buttonFunction.Text = "查询";
BindCombox();
}
//单击刷新按钮
private void toolStripButtonRefresh_Click(object sender, EventArgs e)
{
this.dataGridView1.DataSource = subManager.GetSujectData();//数据绑定
BindCombox();
}
//单击保存/查询按钮事件
private void buttonFunction_Click(object sender, EventArgs e)
{
if (buttonFunction.Text == "保存添加")
{
if (CheckNullValue())
{
subManager.AddSubject(subject);
this.dataGridView1.DataSource = subManager.GetSujectData();//数据绑定
BindCombox();
}
}
else if (buttonFunction.Text == "保存修改")
{
if (CheckNullValue())
{
subManager.UpdateSubject(subject);
this.dataGridView1.DataSource = subManager.GetSujectData();//数据绑定
BindCombox();
}
}
else
{
QueryFunction();
}
}
#endregion
#region 获取选中行
/// <summary>
/// 获取选中行
/// </summary>
private void SelectedRows()
{
comboBoxNo.Text = this.dataGridView1.SelectedCells.Value.ToString();
comboBoxName.Text = this.dataGridView1.SelectedCells.Value.ToString();
comboBoxCredit.Text = this.dataGridView1.SelectedCells.Value.ToString();
comboBoxTime.Text = this.dataGridView1.SelectedCells.Value.ToString();
comboBoxTeacher.Text = this.dataGridView1.SelectedCells.Value.ToString();
comboBoxGrade.Text = this.dataGridView1.SelectedCells.Value.ToString();
}
#endregion
#region 查询功能
/// <summary>
/// 查询功能
/// </summary>
private void QueryFunction()
{
if (comboBoxTeacher.Text != "")
{
if (comboBoxGrade.Text != "")
{
this.dataGridView1.DataSource = subManager.GetSujectByTeacherNameAndGradeName(comboBoxTeacher.Text.Trim(), comboBoxGrade.Text.Trim());//数据绑定
}
else
{
this.dataGridView1.DataSource = subManager.GetSujectByTeacherName(comboBoxTeacher.Text.Trim());//数据绑定
}
}
else
{
if (comboBoxGrade.Text != "")
{
this.dataGridView1.DataSource = subManager.GetSujectByGradeName(comboBoxGrade.Text.Trim());//数据绑定
}
else
{
this.dataGridView1.DataSource = subManager.GetSujectData();//数据绑定
MessageBox.Show("查询条件为空,请输入查询条件。");
}
}
}
#endregion
#region 非空验证
/// <summary>
/// 非空验证
/// </summary>
public bool CheckNullValue()
{
bool flag = false;
if (comboBoxNo.Text == "")
{ MessageBox.Show("课程代号为空"); }
else if (comboBoxName.Text == "")
{ MessageBox.Show("课程名称为空"); }
else if (comboBoxCredit.Text == "")
{ MessageBox.Show("课程学分为空"); }
else if (comboBoxTime.Text == "")
{ MessageBox.Show("课程学时为空"); }
else if (comboBoxTeacher.Text == "")
{ MessageBox.Show("授课教师为空"); }
else if (comboBoxGrade.Text == "")
{ MessageBox.Show("课程班级为空"); }
else
{
subject.SubNo = this.comboBoxNo.Text.Trim();
subject.SubName = this.comboBoxName.Text.Trim();
subject.SubCredit = this.comboBoxCredit.Text.Trim();
subject.SubTimes = this.comboBoxTime.Text.Trim();
subject.TeaName = this.comboBoxTeacher.Text.Trim();
subject.GraName = this.comboBoxGrade.Text.Trim();
flag = true;
}
return flag;
}
#endregion
#region Combox数据源绑定
/// <summary>
/// Combox数据源绑定
/// </summary>
public void BindCombox()
{
this.comboBoxNo.DataSource = subManager.GetSujectData();
this.comboBoxNo.DisplayMember = "subNo";//绑定到课程号
this.comboBoxName.DataSource = subManager.GetSujectData();
this.comboBoxName.DisplayMember = "subName";//绑定到课程名
this.comboBoxCredit.DataSource = subManager.GetSubjectCredit();//Model.Subject
this.comboBoxCredit.DisplayMember = "subCredit";//绑定到课程学分
this.comboBoxTime.DataSource = subManager.GetSubjectTimes();
this.comboBoxTime.DisplayMember = "subTimes";//绑定到课程学时
this.comboBoxTeacher.DataSource = teatManager.GetTeacherData();
this.comboBoxTeacher.DisplayMember = "TeaName";//绑定到授课教师
this.comboBoxGrade.DataSource = graManager.GetGradeData();
this.comboBoxGrade.DisplayMember = "graName";//绑定到班级名
//绑定后显示为空
this.comboBoxNo.Text = null;
this.comboBoxName.Text = null;
this.comboBoxCredit.Text = null;
this.comboBoxTime.Text = null;
this.comboBoxTeacher.Text = null;
this.comboBoxGrade.Text = null;
}
#endregion
}
}
2020.03改链接: https://pan.baidu.com/s/1PUF5b5lZRaqfCUekeR7jRg
提取码: p6rg
加入打印功能,新建的数据库,所以内容跟图片表格中的内容不一致。
对于线程问题还未考虑,有大神亦可赐教。作为初学者做个小作品,大神勿喷,更希望大神可以指导。
附部分界面(备注:需连接数据库内部并不含数据库仅有界面,并不能直接运行)
最好分一下层,ui,业务逻辑,数据访问一起都放在form里面不专业,项目完成后维护起来很可怕,如果是自己写得小玩意无所谓,但是用来学习的话对自己要求严一点更容易进步!login页面最好放在program里面启动,启动成功后直接close掉! 2014miss 发表于 2020-5-15 01:15
我最近也在用C#写管理系统,我写的是进销存系统但是遇到了许多问题,我想请问一下楼主,怎么样才能实现在da ...
链接: https://pan.baidu.com/s/11xFb6O6BMShM4arn5vCYAA 提取码: fbvm
这是一个百度云连接你可以看看参考一下希望对你有帮助。 很好,正在学习这个 你这学生名有点皮啊 刚好有在学习,谢谢大佬 明月照何处 发表于 2020-3-14 20:51
你这学生名有点皮啊
为了娱乐嘛 嘿嘿 qiuyang 发表于 2020-3-15 08:41
刚好有在学习,谢谢大佬
不不不,共同用进步,数据库需要你自己建立了,软件连接不到我的数据库的,把数据库连接字符串换成你自己慢慢调试吧, 凌凌壹 发表于 2020-3-15 09:50
不不不,共同用进步,数据库需要你自己建立了,软件连接不到我的数据库的,把数据库连接字符串换成你自己 ...
好的,谢谢了:lol 跟我前段时间学C#的时候写的小项目差不多,只是功能不太一样{:301_988:}