c#语言管理员系统代码,【2020.04.13改】c#学生管理系统三层架构(源码)

本帖最后由 凌凌壹 于 2020-4-13 11:08 编辑

噔噔噔    2020.04.13改  链接:https://lanzous.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[0].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 获取选中行

///

/// 获取选中行

///

private void SelectedRows()

{

comboBoxNo.Text = this.dataGridView1.SelectedCells[0].Value.ToString();

comboBoxName.Text = this.dataGridView1.SelectedCells[1].Value.ToString();

comboBoxCredit.Text = this.dataGridView1.SelectedCells[2].Value.ToString();

comboBoxTime.Text = this.dataGridView1.SelectedCells[3].Value.ToString();

comboBoxTeacher.Text = this.dataGridView1.SelectedCells[4].Value.ToString();

comboBoxGrade.Text = this.dataGridView1.SelectedCells[5].Value.ToString();

}

#endregion

#region 查询功能

///

/// 查询功能

///

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 非空验证

///

/// 非空验证

///

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数据源绑定

///

/// Combox数据源绑定

///

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

加入打印功能,新建的数据库,所以内容跟图片表格中的内容不一致。

对于线程问题还未考虑,有大神亦可赐教。作为初学者做个小作品,大神勿喷,更希望大神可以指导。

附部分界面(备注:需连接数据库内部并不含数据库仅有界面,并不能直接运行)

55fd2b2273b5a8b4531f72773c469d6e.gif

登陆界面.png (134.96 KB, 下载次数: 1)

主界面

2020-3-14 14:46 上传

55fd2b2273b5a8b4531f72773c469d6e.gif

系统界面.png (36.89 KB, 下载次数: 1)

管理员界面

2020-3-14 14:46 上传

55fd2b2273b5a8b4531f72773c469d6e.gif

修改.png (71.39 KB, 下载次数: 1)

修改操作

2020-3-14 14:46 上传

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值