好友
阅读权限 10
听众
最后登录 1970-1-1
凌凌壹
发表于 2020-3-14 14:52
本帖最后由 凌凌壹 于 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[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 获取选中行
/// <summary>
/// 获取选中行
/// </summary>
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 查询功能
/// <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
加入打印功能,新建的数据库,所以内容跟图片表格中的内容不一致。
对于线程问题还未考虑,有大神亦可赐教。作为初学者做个小作品,大神勿喷,更希望大神可以指导。
附部分界面(备注:需连接数据库内部并不含数据库仅有界面,并不能直接运行)
主界面
管理员界面
修改操作
免费评分
查看全部评分
发帖前要善用【论坛搜索 】 功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。