学生成绩管理系统设计说明书

更新时间:2024-06-03 22:58:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

重庆三峡学院

VC++.net课程设计 学生管理系统设计说明书

学校: 重庆。。大学 系别: 计算机科学与技术 班别: 计本1班 姓名: 学号: 2009060156

重庆三峡学院

目录

一、课程设计项目 ............................................................................................................................................. 3 二、 学生管理系统需求分析 ........................................................................................................................... 3

1. 学生管理系统功能需求 ....................................................................................................................... 3

1.1信息操作功能 ............................................................................................................................... 3 1.2查询功能 ....................................................................................................................................... 3 1.3统计功能 ....................................................................................................................................... 3 1.4分析功能 ....................................................................................................................................... 3 2. 学生管理系统性能需求 ....................................................................................................................... 4

2.1时间相应 ....................................................................................................................................... 4 2.2容错能力 ....................................................................................................................................... 4

三. 学生管理系统设计 ...................................................................................................................................... 4

1. 学生管理系统模块设计 ....................................................................................................................... 4

1.1主模块 ........................................................................................................................................... 4 1.2信息插入模块 ............................................................................................................................... 5 1.3信息删除模块 ............................................................................................................................... 5 1.4信息修改模块 ............................................................................................................................... 5 1.5信息查询模块 ............................................................................................................................... 6 2. 学生管理系统数据库设计 ................................................................................................................... 6

2.1学生表 ........................................................................................................................................... 6 2.2班级信息表 ................................................................................................................................... 6 2.3课程表 ........................................................................................................................................... 7 2.4成绩表 ........................................................................................................................................... 7 3.内部类设计 .............................................................................................................................................. 7

3.1学生类 ........................................................................................................................................... 7 3.2班级类 ........................................................................................................................................... 8 3.3课程类 ........................................................................................................................................... 8 3.4成绩类 ........................................................................................................................................... 9

共 42 页 第 1 页

重庆三峡学院

四、 学生管理系统代码实现 ........................................................................................................................... 9

1. 学生管理系统模块代码实现 ............................................................................................................... 9

1.1主模块 ........................................................................................................................................... 9 1.2信息插入模块 ............................................................................................................................. 12 1.2信息删除模块 ............................................................................................................................. 15 1.3信息修改模块 ............................................................................................................................. 19 1.4信息查询模块 ............................................................................................................................. 23 2. 内部类代码实现 ................................................................................................................................. 25

2.1学生类 ......................................................................................................................................... 25 2.2班级类 ......................................................................................................................................... 28 2.3课程类 ......................................................................................................................................... 31 2.4成绩类 ......................................................................................................................................... 34

五、学生管理系统功能测试 ........................................................................................................................... 37

1插入信息测试 ........................................................................................................................................ 37 2删除信息测试 ........................................................................................................................................ 38 3修改信息测试 ........................................................................................................................................ 40 4查询信息测试 ........................................................................................................................................ 41 六 课程设计总结和感想 ................................................................................................................................. 42

共 42 页 第 2 页

重庆三峡学院

一、课程设计项目

学生管理系统。

二、学生管理系统需求分析

1.学生管理系统功能需求

本次.net课程设计实习所涉及的学生信息管理系统是一个简单的管理系统,用于为某个院系按专业管理学生的基本信息、课程信息和学生成绩信息以及班级信息。

系统功能主要分为:信息操作功能、查询功能、统计功能和分析功能。

1.1信息操作功能

1) 学生基本信息的增加、删除、修改。学生信息包括:学号,姓名,性别,出生日期,籍贯和家庭

住址。

2) 学生成绩信息的添加、删除、修改。学生成绩信息包括:学号、课程号和成绩。

3) 班级信息添加、删除、修改。班级信息包括:班号、所在院系、专业名称、学制和入学时间。 4) 课程信息的添加、删除、修改。课程信息包括:课程号、课程名称、课程类型、开课学期、课时

数和学分。

1.2查询功能

1) 2) 3) 4)

查询学生基本信息。(通过学号、姓名、系别、籍贯等) 查询成绩基本信息。(通过学号、课程号、等) 查询课程基本信息。(通过课程号、课程名等) 查询班级基本信息。(通过班级号、班级名、所在院系等)

1.3统计功能

1) 统计某个学生的在所有学期课程总平均分,并且在状态栏上显示。

1.4分析功能

1) 对某个班级某一门课程的成绩分布进行分析,并且以直方图的形式显示出来。

共 42 页 第 3 页

重庆三峡学院

2.学生管理系统性能需求 2.1时间相应

1) 在用户可以忍受的范围内,相应用户的操作。

2.2容错能力

1) 能够有一定的容错提示,数据库连接出错时或者查询出错时候给出错误提示。

三.学生管理系统设计

1.学生管理系统模块设计 1.1主模块

共 42 页 第 4 页

重庆三峡学院

1.2信息插入模块

1.3信息删除模块

1.4信息修改模块

共 42 页 第 5 页

重庆三峡学院

1.5信息查询模块

2.学生管理系统数据库设计 2.1学生表

2.2班级信息表

共 42 页 第 6 页

重庆三峡学院

2.3课程表

2.4成绩表

3.内部类设计

我单独分别设计了4个类,来完成对数据库中的表进行操作。这些类把用户界面和数据库操作分离开来,实现了用户界面层和数据操作层的分离,更加清晰的把整个软件架构表达出来。

3.1学生类

class Student {

public String strCon;

public OleDbConnection conn; public OleDbCommand cmd;

public Student();

public void insert(string studentno, string studentname, string studentsex, string studentbirth, stringstudentnative, string studentaddress);

public void delete(string studentno);

public DataSet select(string selectype,string item);

public DataSet selectAll();

共 42 页 第 7 页

重庆三峡学院

public void update(string studentno, string studentname, string studentsex, string studentbirth, string studentnative, string studentaddress); }

3.2班级类

class Classinfo {

public String strCon;

public OleDbConnection conn; public OleDbCommand cmd;

public Classinfo();

public void insert(string classno, string classdepart, string special, string studyyears, string entertime);

public void delete(string classno);

public DataSet select(string selectype,string item);

public DataSet selectAll();

public void update(string classno, string classdepart, string special, string studyyears, string entertime); }

3.3课程类

class Course { public String strCon; public OleDbConnection conn; public OleDbCommand cmd; public Course(); public void insert(string courseno, string coursename, string coursetype, string courseopenteam, string coursehours, string coursecredi); public void delete(string courseno);

共 42 页 第 8 页

重庆三峡学院

public DataSet select(string selectype,string item); public DataSet selectAll();

public void update(string courseno, string coursename, string coursetype, string courseopenteam, string coursehours, string coursecredi); }

3.4成绩类

class Score {

public String strCon;

public OleDbConnection conn; public OleDbCommand cmd;

public Score() ;

public void insert(string studentno, string courseno, string coursescore);

public void delete(string studnetno,string courseno);

public DataSet select(string type, string studentno, string courseno);

public DataSet selectAll();

public void update(string studentno, string courseno, string coursescore); }

四、学生管理系统代码实现

1.学生管理系统模块代码实现 1.1主模块

namespace StudentManagerSys {

public partial class Form1 : Form {

public Form1()

共 42 页 第 9 页

重庆三峡学院

{

InitializeComponent(); }

private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) {

switch (e.Node.Text) {

case \学生信息\

shouwStudentInfo(); break;

case \班级信息\

shouwClassInfo(); break;

case \课程信息\

shouwCoureinfo(); break;

case \成绩信息\

shouwScoreInfo(); break; } }

private void shouwStudentInfo() {

Student stu = new Student();

DataSet stuInfo;

stuInfo = stu.selectAll();

dataGridView1.DataSource = stuInfo; dataGridView1.DataMember = \ }

private void shouwClassInfo() {

Classinfo cla = new Classinfo();

DataSet claInfo;

claInfo = cla.selectAll();

dataGridView1.DataSource = claInfo; dataGridView1.DataMember = \

共 42 页 第 10 页

重庆三峡学院

}

private void shouwCoureinfo() {

Course cou = new Course();

DataSet couInfo;

couInfo = cou.selectAll();

dataGridView1.DataSource = couInfo; dataGridView1.DataMember = \ }

private void shouwScoreInfo() {

Score sco = new Score();

DataSet scoInfo;

scoInfo = sco.selectAll();

dataGridView1.DataSource = scoInfo; dataGridView1.DataMember = \ }

private void 插入数据ToolStripMenuItem_Click(object sender, EventArgs e) {

InsertFrom from = new InsertFrom(); from.Show(); }

private void 删除数据ToolStripMenuItem_Click(object sender, EventArgs e) {

DeleteForm from = new DeleteForm(); from.Show(); }

private void 修改数据ToolStripMenuItem_Click(object sender, EventArgs e) {

ModifyForm from = new ModifyForm(); from.Show(); }

private void 查询数据ToolStripMenuItem_Click(object sender, EventArgs e) {

SearchForm from = new SearchForm(); from.Show();

共 42 页 第 11 页

重庆三峡学院

}

private void 关于这个软件ToolStripMenuItem_Click(object sender, EventArgs e) {

MessageBox.Show(\作者信息:计Y052班 罗鑫 200502001071\\n\ } } }

1.2信息插入模块

namespace StudentManagerSys {

public partial class InsertFrom : Form {

//插入学生信息用到的数据 public string studnetno; public string studentname; public string sex; public string ative; public string address; public string birth;

//插入班级信息用到的数据 public string classno; public string depart; public string specical; public string studyears; public string entertime;

//插入课程信息用到的数据 public string courseno; public string coursename; public string coursetype; public string openterm; public string ccoursehours; public string credit;

//插入成绩信息需要的数据 public string score;

public InsertFrom() {

InitializeComponent();

共 42 页第 12 页

重庆三峡学院

}

//插入学生信息,确认按钮消息相应函数

private void button1_makesure_Click(object sender, EventArgs e) {

studnetno = textBox1.Text; studentname = textBox2.Text; if (comboBox1.Text == \男\ sex = \ else

sex = \

ative = textBox3.Text; address = textBox4.Text;

birth = dateTimePicker1.Value.ToString(\ Student stu = new Student();

stu.insert(studnetno, studentname, sex, birth, ative, address); this.Close(); }

//插入学生信息,重置按钮消息相应函数

private void button1_reset_Click(object sender, EventArgs e) {

textBox1.Text = \ textBox2.Text = \ textBox3.Text = \ textBox4.Text = \

dateTimePicker1.Text = \ comboBox1.Text = \男\ }

//插入班级信息,确认按钮消息相应函数

private void button1_Click(object sender, EventArgs e) {

classno = textBox5.Text; depart = textBox8.Text; specical = textBox9.Text; studyears = textBox6.Text;

entertime = dateTimePicker2.Value.ToString(\ Classinfo cla = new Classinfo();

cla.insert(classno, depart, specical, studyears, entertime); this.Close(); }

//插入班级信息,重置按钮消息相应函数

共 42 页 第 13 页

重庆三峡学院

private void button2_Click(object sender, EventArgs e) {

textBox5.Text = \ textBox8.Text = \ textBox9.Text = \ textBox6.Text = \

dateTimePicker2.Text = \ }

//插入课程信息,确认按钮消息相应函数

private void button4_Click(object sender, EventArgs e) {

courseno = textBox10.Text; coursename = textBox11.Text; coursetype = textBox12.Text; openterm = textBox13.Text; ccoursehours = textBox14.Text; credit = textBox15.Text;

Course cou = new Course();

cou.insert(courseno, coursename, coursetype, openterm, ccoursehours, credit); this.Close(); }

//插入课程信息,重置按钮消息相应函数

private void button3_Click(object sender, EventArgs e) {

textBox10.Text = \ textBox11.Text = \ textBox12.Text = \ textBox13.Text = \ textBox14.Text = \ textBox15.Text = \ }

//插入成绩信息,确认按钮消息相应函数

private void button6_Click(object sender, EventArgs e) {

courseno = textBox16.Text; studnetno = textBox17.Text; score = textBox18.Text; Score sco = new Score();

sco.insert(studnetno, courseno, score);

共 42 页 第 14 页

重庆三峡学院

this.Close(); }

//插入成绩信息,取消按钮消息相应函数

private void button5_Click(object sender, EventArgs e) {

textBox16.Text = \ textBox17.Text = \ textBox18.Text = \ } } }

1.2信息删除模块

namespace StudentManagerSys {

public partial class DeleteForm : Form {

public string delStudentNo = \ public string delClassNo = \ public string delCourseNo = \ public string delScoreid = \

public DeleteForm() {

InitializeComponent(); }

//显示所有相应表格的数据

public void ShowAllData(string type) {

DataSet set;

if (type == \学生\ {

Student stu = new Student(); set = stu.selectAll();

dataGridView1.DataSource = set;

dataGridView1.DataMember = \ }

else if (type == \班级\ {

Classinfo cla = new Classinfo(); set = cla.selectAll();

共 42 页 第 15 页

重庆三峡学院

dataGridView2.DataSource = set;

dataGridView2.DataMember = \ }

else if (type == \课程\ {

Course cou = new Course(); set = cou.selectAll();

dataGridView3.DataSource = set;

dataGridView3.DataMember = \ }

else if (type == \成绩\ {

Score sco = new Score(); set = sco.selectAll();

dataGridView4.DataSource = set;

dataGridView4.DataMember = \ } }

private void tabControl1_Selected(object sender, TabControlEventArgs e) {

if (e.TabPage == tabPage1) {

ShowAllData(\学生\ }

else if (e.TabPage == tabPage2) {

ShowAllData(\班级\ }

else if (e.TabPage == tabPage3) {

ShowAllData(\课程\ }

else if (e.TabPage == tabPage4) {

ShowAllData(\成绩\ } }

//删除学生信息

private void button1_delstu_Click(object sender, EventArgs e) {

if (MessageBox.Show(this, \要删除所选记录吗?\请确认\ MessageBoxButtons.YesNo,

共 42 页 第 16 页

重庆三峡学院

MessageBoxIcon.Question,

MessageBoxDefaultButton.Button1,

MessageBoxOptions.RightAlign) == DialogResult.No) return;

foreach (Control ctrl in this.Controls)//通过个一循环得到信息 {

string ctrlName = ctrl.Name.Trim();

if (ctrlName.StartsWith(\查询信息根据的主键 {

ctrl.Enabled = false; }

delStudentNo

dataGridView1.Rows[dataGridView1.CurrentRow.Index].Cells[0].Value.ToString(); Student stu = new Student();

stu.delete(delStudentNo); } }

//删除成绩信息

private void button1_delsco_Click(object sender, EventArgs e) {

if (MessageBox.Show(this, \要删除所选记录吗?\请确认\ MessageBoxButtons.YesNo, MessageBoxIcon.Question,

MessageBoxDefaultButton.Button1,

MessageBoxOptions.RightAlign) == DialogResult.No) return;

if (delStudentNo != \ {

Score sco = new Score();

sco.delete(delStudentNo, delClassNo); }

}

//删除课程信息

private void button1_delCou_Click(object sender, EventArgs e) {

if (MessageBox.Show(this, \要删除所选记录吗?\请确认\ MessageBoxButtons.YesNo, MessageBoxIcon.Question,

共 42 页 第 17 页

=

重庆三峡学院

MessageBoxDefaultButton.Button1,

MessageBoxOptions.RightAlign) == DialogResult.No) return;

foreach (Control ctrl in this.Controls)//通过个一循环得到信息 {

string ctrlName = ctrl.Name.Trim();

if (ctrlName.StartsWith(\查询信息根据的主键 {

ctrl.Enabled = false; }

delCourseNo

dataGridView3.Rows[dataGridView3.CurrentRow.Index].Cells[0].Value.ToString(); Course cou = new Course();

cou.delete(delCourseNo); } }

//删除班级信息

private void button1_delcla_Click(object sender, EventArgs e) {

if (MessageBox.Show(this, \要删除所选记录吗?\请确认\ MessageBoxButtons.YesNo, MessageBoxIcon.Question,

MessageBoxDefaultButton.Button1,

MessageBoxOptions.RightAlign) == DialogResult.No) return;

foreach (Control ctrl in this.Controls)//通过个一循环得到信息 {

string ctrlName = ctrl.Name.Trim();

if (ctrlName.StartsWith(\查询信息根据的主键 {

ctrl.Enabled = false; }

delClassNo=

dataGridView2.Rows[dataGridView2.CurrentRow.Index].Cells[0].Value.ToString(); Classinfo cla = new Classinfo(); cla.delete(delClassNo); } }

private void DeleteForm_Load(object sender, EventArgs e) {

共 42 页 第 18 页

=

重庆三峡学院

ShowAllData(\学生\ }

private void dataGridView4_CellValidated(object sender, DataGridViewCellEventArgs e) {

delStudentNo = dataGridView4.Rows[e.RowIndex].Cells[0].Value.ToString(); delClassNo = dataGridView4.Rows[e.RowIndex].Cells[1].Value.ToString(); } } }

1.3信息修改模块

namespace StudentManagerSys {

public partial class ModifyForm : Form {

//修改学生信息用到的数据 public string modifyStudnetno; public string modifyStudnetname; public string modifySex; public string modifyAtive; public string modifyAddress; public string modifyBirth;

//修改班级信息用到的数据 public string modifyClassno; public string modifyDepart; public string modifySpecical; public string modifyStudyears; public string modifyEntertime;

//修改课程信息用到的数据 public string modifyCourseno; public string modifyCoursename; public string modifyCoursetype; public string modifyOpenterm; public string modifyCcoursehours; public string modifyCredit;

//修改成绩信息需要的数据 public string modifyScore;

public ModifyForm()

共 42 页第 19 页

重庆三峡学院

{

InitializeComponent(); }

//显示所有相应表格的数据s

public void ShowAllData(string type) {

DataSet set;

if (type == \学生\ {

Student stu = new Student(); set = stu.selectAll();

dataGridView1.DataSource = set;

dataGridView1.DataMember = \ }

else if (type == \班级\ {

Classinfo cla = new Classinfo(); set = cla.selectAll();

dataGridView2.DataSource = set;

dataGridView2.DataMember = \ }

else if (type == \课程\ {

Course cou = new Course(); set = cou.selectAll();

dataGridView3.DataSource = set;

dataGridView3.DataMember = \ }

else if (type == \成绩\ {

Score sco = new Score(); set = sco.selectAll();

dataGridView4.DataSource = set;

dataGridView4.DataMember = \ } }

private void button_edit_stu_Click(object sender, EventArgs e) {

if (MessageBox.Show(this, \要修改所选记录吗?\请确认\ MessageBoxButtons.YesNo, MessageBoxIcon.Question,

MessageBoxDefaultButton.Button1,

共 42 页 第 20 页

重庆三峡学院

MessageBoxOptions.RightAlign) == DialogResult.No) return;

Student stu = new Student();

stu.update(modifyStudnetno, modifyStudnetname, modifySex, modifyBirth, modifyAtive, modifyAddress); }

private void button_edit_class_Click(object sender, EventArgs e) {

if (MessageBox.Show(this, \要修改所选记录吗?\请确认\ MessageBoxButtons.YesNo, MessageBoxIcon.Question,

MessageBoxDefaultButton.Button1,

MessageBoxOptions.RightAlign) == DialogResult.No) return;

Classinfo cla = new Classinfo(); cla.update(modifyClassno, modifyDepart, modifySpecical, modifyEntertime); }

private void button_edit_course_Click(object sender, EventArgs e) {

if (MessageBox.Show(this, \要修改所选记录吗?\请确认\ MessageBoxButtons.YesNo, MessageBoxIcon.Question,

MessageBoxDefaultButton.Button1,

MessageBoxOptions.RightAlign) == DialogResult.No) return;

Course cou = new Course();

cou.update(modifyCourseno, modifyCoursename, modifyCoursetype, modifyCcoursehours, modifyCredit); }

private void button_edit_score_Click(object sender, EventArgs e) {

if (MessageBox.Show(this, \要修改所选记录吗?\请确认\ MessageBoxButtons.YesNo, MessageBoxIcon.Question,

MessageBoxDefaultButton.Button1,

MessageBoxOptions.RightAlign) == DialogResult.No) return;

共 42 页 第 21 页

modifyStudyears, modifyOpenterm, 重庆三峡学院

Score sco = new Score();

sco.update(modifyStudnetno, modifyCourseno, modifyScore); }

private void ModifyForm_Load(object sender, EventArgs e) {

ShowAllData(\学生\ }

private void tabControl2_Selected(object sender, TabControlEventArgs e) {

if (e.TabPage == tabPage5) {

ShowAllData(\学生\ }

else if (e.TabPage == tabPage6) {

ShowAllData(\班级\ }

else if (e.TabPage == tabPage7) {

ShowAllData(\课程\ }

else if (e.TabPage == tabPage8) {

ShowAllData(\成绩\ } }

private void dataGridView1_CellValidated(object sender, DataGridViewCellEventArgs e) {

modifyStudnetno = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); modifyStudnetname = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); modifySex = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); modifyBirth = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); modifyAtive = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); modifyAddress = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); }

private void dataGridView2_CellValidated(object sender, DataGridViewCellEventArgs e) {

modifyClassno = dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString(); modifyDepart = dataGridView2.Rows[e.RowIndex].Cells[1].Value.ToString();

共 42 页 第 22 页

重庆三峡学院

modifySpecical = dataGridView2.Rows[e.RowIndex].Cells[2].Value.ToString(); modifyStudyears = dataGridView2.Rows[e.RowIndex].Cells[3].Value.ToString(); modifyEntertime = dataGridView2.Rows[e.RowIndex].Cells[4].Value.ToString(); }

private void dataGridView3_CellValidated(object sender, DataGridViewCellEventArgs e) {

modifyCourseno = dataGridView3.Rows[e.RowIndex].Cells[0].Value.ToString(); modifyCoursename = dataGridView3.Rows[e.RowIndex].Cells[1].Value.ToString(); modifyCoursetype = dataGridView3.Rows[e.RowIndex].Cells[2].Value.ToString(); modifyOpenterm = dataGridView3.Rows[e.RowIndex].Cells[3].Value.ToString(); modifyCcoursehours = dataGridView3.Rows[e.RowIndex].Cells[4].Value.ToString(); modifyCredit = dataGridView3.Rows[e.RowIndex].Cells[5].Value.ToString(); }

private void dataGridView4_CellValidated(object sender, DataGridViewCellEventArgs e) {

modifyStudnetno = dataGridView4.Rows[e.RowIndex].Cells[0].Value.ToString(); modifyCourseno = dataGridView4.Rows[e.RowIndex].Cells[1].Value.ToString(); modifyScore = dataGridView4.Rows[e.RowIndex].Cells[2].Value.ToString(); } } }

1.4信息查询模块

using System;

using System.Collections.Generic; using System.Text; using System.Data;

using System.Data.OleDb; using System.IO;

using System.Windows.Forms;

namespace StudentManagerSys {

public partial class SearchForm : Form {

public SearchForm() {

InitializeComponent(); }

private void button_search_stu_Click(object sender, EventArgs e)

共 42 页 第 23 页

重庆三峡学院

{

string type = comboBox1.Text; string item = textBox1.Text; Student stu = new Student();

DataSet dstu = stu.select(type, item); dataGridView1.DataSource = dstu;

dataGridView1.DataMember = \ }

private void button_search_cla_Click(object sender, EventArgs e) {

string type = comboBox2.Text; string item = textBox2.Text; Classinfo cla = new Classinfo(); DataSet dcla = cla.select(type, item); dataGridView2.DataSource = dcla;

dataGridView2.DataMember = \ }

private void button_search_cou_Click(object sender, EventArgs e) {

string type = comboBox3.Text; string item = textBox3.Text; Course cou = new Course();

DataSet dcou = cou.select(type, item); dataGridView3.DataSource = dcou; dataGridView3.DataMember = \ }

private void button_search_sco_Click(object sender, EventArgs e) {

string studnetno = textBox5.Text; string courseno = textBox4.Text; Score sco = new Score();

DataSet dsco = sco.select(\ dataGridView4.DataSource = dsco; dataGridView4.DataMember = \ }

private void button1_Click(object sender, EventArgs e) {

Score sco = new Score();

共 42 页 第 24 页

重庆三峡学院

DataSet dsco = sco.select(\ dataGridView4.DataSource = dsco;

dataGridView4.DataMember = \ }

private void button_sql_Click(object sender, EventArgs e) {

string sql = textBox6.Text;

string strCon = \Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =\+ System.Windows.Forms.Application.StartupPath + @\ OleDbConnection conn = new OleDbConnection(strCon); OleDbCommand cmd = new OleDbCommand(); try {

cmd.CommandText = sql; cmd.Connection = conn; OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText, conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \

dataGridView5.DataSource = ds;

dataGridView5.DataMember = \ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\查询失败!\ } } } }

2.内部类代码实现 2.1学生类

namespace StudentManagerSys {

class Student {

public String strCon;

共 42 页 第 25 页

重庆三峡学院

public OleDbConnection conn; public OleDbCommand cmd;

public Student() {

strCon = \Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =\+ System.Windows.Forms.Application.StartupPath + @\ conn = new OleDbConnection(strCon); cmd = new OleDbCommand(); }

public void insert(string studentno, string studentname, string studentsex, string studentbirth, string studentnative, string studentaddress) {

cmd.CommandText = \\ cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\添加成功\ } catch {

MessageBox.Show(\添加失败!\ } }

public void delete(string studentno) {

cmd.CommandText = \ cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\删除成功!\ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\删除失败!\

共 42 页 第 26 页

重庆三峡学院

} }

public DataSet select(string selectype,string item) {

try {

cmd.CommandText = \ cmd.Connection = conn; OleDbDataAdapter dr = new conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; } catch {

conn.Close();

MessageBox.Show(\查询失败!\ }

return null; }

public DataSet selectAll() {

try {

cmd.CommandText = \ cmd.Connection = conn; OleDbDataAdapter dr = new conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; } catch {

conn.Close();

MessageBox.Show(\查询失败!\ }

return null; }

共 42 页 第 27 页

OleDbDataAdapter(cmd.CommandText, OleDbDataAdapter(cmd.CommandText, 重庆三峡学院

public void update(string studentno, string studentname, string studentsex, string studentbirth, string studentnative, string studentaddress) {

int student_sex = 0; if (studentsex == \ student_sex = 0; else

student_sex = 1;

cmd.CommandText = %update student set \+ \+ studentname + \studentsex=\+ student_sex + \studentbirth='\+ studentbirth + \studentnative='\+ studentnative + \studentaddress='\ cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\修改成功!\ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\修改失败!\ } } } }

2.2班级类

namespace StudentManagerSys {

class Classinfo {

public String strCon;

public OleDbConnection conn; public OleDbCommand cmd;

public Classinfo() {

strCon = \Provider = Microsoft.Jet.OLEDB.4.0 System.Windows.Forms.Application.StartupPath + @\

共 42 页 第 28 页

; Data Source =\+

重庆三峡学院

conn = new OleDbConnection(strCon); cmd = new OleDbCommand(); }

public void insert(string classno, string classdepart, string special, string studyyears, string entertime) {

cmd.CommandText = \+ special + \ cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\添加成功\ } catch {

MessageBox.Show(\添加失败!\ } }

public void delete(string classno) {

cmd.CommandText = \ cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\删除成功!\ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\删除失败!\ } }

public DataSet select(string selectype,string item) {

try {

共 42 页 第 29 页

重庆三峡学院

cmd.CommandText = \\

cmd.Connection = conn; OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText, conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; } catch {

conn.Close();

MessageBox.Show(\查询失败!\ }

return null; }

public DataSet selectAll() {

try {

cmd.CommandText = \ cmd.Connection = conn; OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText, conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; } catch {

conn.Close();

MessageBox.Show(\查询失败!\ }

return null; }

public void update(string classno, string classdepart, string special, string studyyears, string entertime) {

cmd.CommandText = %update classinfo set \special='\studyyears='\entertime='\where classno='\classno +

共 42 页 第 30 页

重庆三峡学院

\

cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\修改成功!\ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\修改失败!\ } } } }

2.3课程类

namespace StudentManagerSys {

class Course {

public String strCon;

public OleDbConnection conn; public OleDbCommand cmd;

public Course() {

strCon = \Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =\+ System.Windows.Forms.Application.StartupPath + @\ conn = new OleDbConnection(strCon); cmd = new OleDbCommand(); }

public void insert(string courseno, string coursename, string coursetype, string courseopenteam, string coursehours, string coursecredi) {

cmd.CommandText = \+ coursetype + \ cmd.Connection = conn; try {

共 42 页 第 31 页

重庆三峡学院

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\添加成功\ } catch {

MessageBox.Show(\添加失败!\ } }

public void delete(string courseno) {

cmd.CommandText = \ cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\删除成功!\ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\删除失败!\ } }

public DataSet select(string selectype,string item) {

try {

if (selectype == \ {

cmd.CommandText = \\

cmd.Connection = conn;

OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText, conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; }

共 42 页 第 32 页

重庆三峡学院

else {

cmd.CommandText = \ cmd.Connection = conn;

OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText, conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; } } catch {

conn.Close();

MessageBox.Show(\查询失败!\ }

return null; }

public DataSet selectAll() {

try {

cmd.CommandText = \ cmd.Connection = conn; OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText, conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; } catch {

conn.Close();

MessageBox.Show(\查询失败!\ }

return null; }

public void update(string courseno, string coursename, string coursetype, string courseopenteam, string coursehours, string coursecredi) {

共 42 页 第 33 页

重庆三峡学院

cmd.CommandText = %update course set \+ \+ coursename + \coursetype='\coursecredi=\ cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\修改成功!\ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\修改失败!\ } } } }

2.4成绩类

namespace StudentManagerSys {

class Score {

public String strCon;

public OleDbConnection conn; public OleDbCommand cmd;

public Score() {

strCon = \Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =\+ System.Windows.Forms.Application.StartupPath + @\ conn = new OleDbConnection(strCon); cmd = new OleDbCommand(); }

public void insert(string studentno, string courseno, string coursescore) {

cmd.CommandText = \into score(studentno,courseno,coursescore) values(\+ \+ studentno + \ cmd.Connection = conn; try

共 42 页 第 34 页

重庆三峡学院

{

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\添加成功\ } catch {

MessageBox.Show(\添加失败!\ } }

public void delete(string studnetno,string courseno) {

cmd.CommandText = \* from score where studentno = '\+ studnetno + \courseno = '\

cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\删除成功!\ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\删除失败!\ } }

public DataSet select(string type, string studentno, string courseno) {

try {

if (type == \ {

string sql = \coursescore\

sql += \

sql += \WHERE (student.studentno = score.studentno) AND (course.courseno = score.courseno)\

cmd.CommandText = sql; cmd.Connection = conn;

OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText,

共 42 页 第 35 页

重庆三峡学院

conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; }

else if(type == \ {

string sql = \coursescore\

sql += \

sql += \where student.studentno = '\+ studentno + \score.courseno = '\+ courseno + \

sql += \AND(student.studentno = score.studentno) AND (course.courseno = score.courseno)\

cmd.CommandText = sql; cmd.Connection = conn;

OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText, conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close(); return ds; } } catch {

conn.Close();

MessageBox.Show(\查询失败!\ }

return null; }

public DataSet selectAll() {

try {

cmd.CommandText = \ cmd.Connection = conn; OleDbDataAdapter dr = new OleDbDataAdapter(cmd.CommandText, conn.ConnectionString);

DataSet ds = new DataSet(); dr.Fill(ds, \ conn.Close();

共 42 页 第 36 页

重庆三峡学院

return ds; } catch {

conn.Close();

MessageBox.Show(\查询失败!\ }

return null; }

public void update(string studentno, string courseno, string coursescore)

{ cmd.CommandText = %update score set \+ \+ coursescore + \where studentno='\ cmd.Connection = conn; try {

conn.Open();

cmd.ExecuteNonQuery();

MessageBox.Show(\修改成功!\ conn.Close(); } catch {

conn.Close();

MessageBox.Show(\修改失败!\ } } } }

五、学生管理系统功能测试

1插入信息测试

插入学生数据

共 42 页 第 37 页

重庆三峡学院

插入班级数据

插入课程数据

插入成绩数据

2删除信息测试

删除学生数据

共 42 页 第 38 页

重庆三峡学院

删除班级信息

删除课程信息

删除成绩信息

共 42 页 第 39 页

本文来源:https://www.bwwdw.com/article/5q16.html

Top