综合应用算法训练
一任务说明
设计一个用于软件工程系本科导师制双选的系统。
设计要求:
(1) 实现学生信息管理,支持信息更新;
(2) 实现教师信息管理,支持信息更新;
(3) 实现学生填写导师志愿的过程,并提供当前导师的选择情况;
(4) 实现基于规则的志愿调整过程;
(5) 实现导师的学生筛选过程;
(6) 实现各种信息的多类查询。
二实验环境及实验准备
C#编程语言
三系统分析与设计
此部分包括软件程序的需求分析与软件设计部分,最好图文并茂。
(1)需求分析
参照实验要求,实现调用数据库进行信息显示,导师学生互选,更新互选结果,管理员更改教师、学生信息,查询双选结果,调整志愿。
(2)软件设计
数据库:教师表、学生表、管理员表
登录:点选教师/学生/管理员登录,输入正确用户名(教师号、学号)和密码成功登录。
教师:
默认可带5个学生。
邀请学生:列表显示未分配的学生信息,可选。若学生未达上限,即向选中的学生发出邀请,等待学生处理。学生将收到老师的基本信息和教学经历等内容。
处理学生申请:若收到来自学生的申请,可选择同意或拒绝。
刷新:更新显示信息
学生:
只能有一位导师。
修改个人简介:点击在文本框中输入要更改的内容,保存修改个人简介。
申请导师:若无导师,可在选择申请导师,向导师发送申请,等待老师处理。导师将收到学生的基本信息和个人简介。
处理导师邀请:若收到邀请,进入处理界面查看邀请信息,同意或拒绝邀请。
刷新:刷新显示信息
管理员:
进行教师表、学生表、双选表的增删改查。并将结果导出到.xls文件
说明本程序中用到的所有数据结构及数据类型的定义、主程序的流程以及各程序模块之间的调用关系图。
四软件源代码
Form1 登录
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using System.Windows.Forms;
using ;
namespace daoshizhi
{
public partial class Form1 : Form
{
public static string welcome = "";
public static string no = "";
SqlConnection conn = new SqlConnection("server=.;database=tutorManagement;uid=sa;pwd=sa");
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
();
string username = ();
string userpwd = ();
if (username == "" || userpwd == "")
{
= "用?户§名?或ò密ü码?不?能ü为a空?!";
}
else
{
string s1 = "select * from tutor where tno='" + username + "' and pwd='" + userpwd + "'";
string s2 = "select * from student where sno='" + username + "' and pwd='" + userpwd + "'";
string s3 = "select * from manager where mno='" + username + "' and pwd='" + userpwd + "'";
if ()
{
SqlCommand s01 = new SqlCommand(s1, conn);
SqlDataReader t = ();
if (())
{
();
SqlDataAdapter s11 = new SqlDataAdapter(s1, conn);
DataSet ds = new DataSet();
();
(ds, "tutor");
welcome=["tutor"].Rows[0]["tname"].ToString();
no= ["tutor"].Rows[0]["tno"].ToString();
Form Form2 = new Form2();
();
();
}
else = "用?户§名?或ò密ü码?错洙?误ó!";
}
else if ()
{
SqlCommand s02 = new SqlCommand(s2, conn);
SqlDataReader t = ();
if (())
{
();
SqlDataAdapter s22 = new SqlDataAdapter(s2, conn);
DataSet ds = new DataSet();
();
(ds, "student");
welcome = ["student"].Rows[0]["name"].ToString();
no = ["student"].Rows[0]["sno"].ToString();
Form Form3 = new Form3();
();
();
}
else = "用?户§名?或ò密ü码?错洙?误ó!";
}
else
{
SqlCommand s03 = new SqlCommand(s3, conn);
SqlDataReader t = ();
if (())
{
Form Form4 = new Form4();
();
();
}
else = "用?户§名?或ò密ü码?错洙?误ó!";
}
}
();
}
Form2 教师界面
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace daoshizhi
{
public partial class Form2 : Form
{
public static string welcome =;
public static string no = ;
SqlConnection conn = new SqlConnection("server=.;database=tutorManagement;uid=sa;pwd=sa");
public static int k;
public Form2()
{
InitializeComponent();
= "欢?迎?,?"+welcome+"老?师簗!?";
/*显?示?我ò的?学§生Θ?/
();
string s = "select * from student where tno='"+no+"'";
SqlCommand a = new SqlCommand(s,conn);
SqlDataReader dr = ();
while (())
{
(("{0} {1} {2} {3}", dr[0], dr[1],dr[2],dr[3]));
}
();
/*显?示?待鋣分?配?学§生Θ?/
string s2 = "select sno,name,sex,message from student where tno is NULL";
SqlCommand b = new SqlCommand(s2,conn);
SqlDataReader dr2 = ();
while (())
{
(("{0} {1} {2} {3}", dr2[0], dr2[1], dr2[2], dr2[3]));
(dr2[0]);
}
();
();
/*显?示?学§生Θ?邀?请?*/
();
string s3 = "select count(sno) from student where selectno='" + no + "'";
SqlCommand c = new SqlCommand(s3, conn);
SqlDataReader dr3 = ();
if (())
{
();
();
SqlDataAdapter da1 = new SqlDataAdapter(s3, conn);
DataSet ds = new DataSet();
(ds, "学§生Θ?邀?请?人?数簓");
string s4 = ["学§生Θ?邀?请?人?数簓"].Rows[0][0].ToString();
k = (s4);
= "收?到?" + s4 + "个?学§生Θ?申Θ?请?";
}
();
();
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
();
Form1 f1 = new Form1();
();
}
private void Form2_Load(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//邀?请?学§生Θ?
if ( == -1) { ("未′选?中D任?何?项?!?"); return; }
/*计?算?已?选?和í正y在ú邀?请?的?学§生Θ?总哩?人?数簓,?不?能ü超?过y 5*/
string m,n;
int x=0,y=0;
string s1 = "select count(*) from student where tno='" + no + "' group by tno";
string s2 = "select count(*) from student where tnoselect='" + no + "' group by tnoselect";
();
SqlCommand a = new SqlCommand(s1, conn);
SqlDataReader dr1 = ();
DataSet ds = new DataSet();
if (())
{
();
();
SqlDataAdapter da = new SqlDataAdapter(s1, conn);
(ds, "selected");
m = ["selected"].Rows[0][0].ToString();
x = (m);
}
();
();
SqlCommand b = new SqlCommand(s2, conn);
SqlDataReader dr2 = ();
if (())
{
();
();
SqlDataAdapter da1 = new SqlDataAdapter(s1, conn);
(ds, "selecting");
n = ["selecting"].Rows[0][0].ToString();
y = (n);
}
();
if (x + y > 4)
{ ("人?数簓将?超?过y最?大洙?限T制? 5!?"); return; }
else
{
//将?选?择?结á果?添?加ó到?学§生Θ?表括?
y++;
string s3 = "update student set tnoselect='" + no + "' where sno='" + () + "'";
SqlCommand cmd = new SqlCommand(s3, conn);
();
();
();
("向ò" + + "发ぁ?出?邀?请?\n您ú已?有瓺" + () + "个?学§生Θ?,?正y在ú邀?请?" + () + "个?学§生Θ?);
}
}
private void button2_Click(object sender, EventArgs e)
{
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form5 f5 = new Form5();
();
();
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//刷¢新?信?息¢
();
();
//显?示?我ò的?学§生Θ?信?息¢
();
string s = "select * from student where tno='" + no + "'";
SqlCommand a = new SqlCommand(s, conn);
SqlDataReader dr = ();
while (())
{
(("{0} {1} {2} {3}", dr[0], dr[1], dr[2], dr[3]));
}
();
//显?示?待鋣分?配?学§生Θ?
string s2 = "select sno,name,sex,message from student where tno is NULL";
SqlCommand b = new SqlCommand(s2, conn);
SqlDataReader dr2 = ();
while (())
{
(("{0} {1} {2} {3}", dr2[0], dr2[1], dr2[2], dr2[3]));
(dr2[0]);
}
();
();
//显?示?学§生Θ?邀?请?
string s3 = "select count(sno) from student where selectno='" + no + "'";
();
SqlCommand c = new SqlCommand(s3, conn);
SqlDataReader dr3 = ();
if (())
{
();
();
SqlDataAdapter da1 = new SqlDataAdapter(s3, conn);
DataSet ds = new DataSet();
(ds, "学§生Θ?邀?请?人?数簓");
string s4 = ["学§生Θ?邀?请?人?数簓"].Rows[0][0].ToString();
k = (s4);
= "收?到?" + s4 + "个?学§生Θ?申Θ?请?";
}
();
();
}
}
}
Form3 学生界面
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace daoshizhi
{
public partial class Form3 : Form
{
public static int k=0;
public static string welcome =;
public static string no = ;
string sql1 = "select message from student where sno='" + no + "'";
string sql2 = "select * from tutor where tno in (select tno from student where sno='" + no + "')";
SqlConnection conn = new SqlConnection("server=.;database=tutorManagement;uid=sa;pwd=sa");
public Form3()
{
InitializeComponent();
= "欢?迎?,?" + welcome+"!?";
//显?示?个?人?简ò介é
();
SqlDataAdapter da = new SqlDataAdapter(sql1, conn);
DataSet ds = new DataSet();
(ds, "student");
= ["student"].Rows[0]["message"].ToString();
();
//显?示?导?师簗信?息¢
();
SqlCommand c1 = new SqlCommand(sql2, conn);
SqlDataReader dr = ();
if (())
{
k = 1;//表括?示?已?有瓺导?师簗
();
SqlDataAdapter dp = new SqlDataAdapter(sql2, conn);
();
(ds, "tutor");
= ["tutor"].Rows[0]["tname"].ToString();
= ["tutor"].Rows[0]["tno"].ToString();
= ["tutor"].Rows[0]["sex"].ToString();
= ["tutor"].Rows[0]["message"].ToString();
();
}
();
//显?示?导?师簗邀?请?人?数簓
string s3 = "select count(tnoselect) from student where sno='" + no + "'";
();
SqlCommand c = new SqlCommand(s3, conn);
SqlDataReader dr3 = ();
if (())
{
();
();
SqlDataAdapter da1 = new SqlDataAdapter(s3, conn);
(ds, "导?师簗邀?请?人?数簓");
string s4 = ["导?师簗邀?请?人?数簓"].Rows[0][0].ToString();
= "收?到?" + s4 + "个?导?师簗邀?请?";
}
();
();
}
private void button1_Click(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
();
Form1 f1 = new Form1();
();
}
private void button2_Click(object sender, EventArgs e)
{
//显?示?个?人?简ò介é
();
= false;
}
private void buttonSave_Click(object sender, EventArgs e)
{
//修T改?数簓据Y库a个?人?简ò介é
string s1 = "update student set message='" + + "' where sno='" + no + "'";
();
SqlCommand cmd = new SqlCommand(s1, conn);
();
();
("修T改?成é功|");
= "";
= false;
//更ü新?显?示?个?人?简ò介é信?息¢
();
SqlDataAdapter da = new SqlDataAdapter(sql1, conn);
DataSet ds = new DataSet();
(ds, "student");
= ["student"].Rows[0]["message"].ToString();
();
}
private void button6_Click(object sender, EventArgs e)
{
//取?消?简ò介é设Θ?置?
= false;
= "";
}
private void button3_Click(object sender, EventArgs e)
{
();
();
if (k == 0)
{
= false;
= true;
//显?示?导?师簗选?择?框ò
string s2 = "select tno,tname,sex,message from tutor where tno in(select from student join tutor on = group by having count(sno)<5) or tno not in(select from student join tutor on =) ";
();
SqlCommand a = new SqlCommand(s2, conn);
SqlDataReader dr = ();
while (())
{
(("{0} {1} {2} {3}", dr[0], dr[1], dr[2], dr[3]));
(dr[0]);
}
();
();
}
else
("您ú已?经-有瓺导?师簗了?!?");
}
private void button4_Click(object sender, EventArgs e)
{
//选?择?导?师簗
string selectno = ();//获?取?选?择?的?教ì师簗号?
/*教ì师簗所ù带?学§生Θ?是?否?满ú员±*/
string s0 = "select count(*) from student where tno='" + selectno + "' group by tno";
();
SqlCommand a= new SqlCommand(s0,conn);
SqlDataReader dr=();
DataSet ds = new DataSet();
int x=0;
if (() )
{
();
();
SqlDataAdapter da = new SqlDataAdapter(s0, conn);
(ds, "selected");
string m = ["selected"].Rows[0][0].ToString();
x = (m);
();
}
();
();
if (x > 5)
("该?教ì师簗所ù带?学§生Θ?已?经-满ú员±,?请?重?新?选?择?教ì师簗!?");
else
{
/*选?择?结á果?添?加ó到?表括?/
string s1 = "update student set selectno='"+selectno+"' where sno='"+ no + "'";
();
SqlCommand cmd = new SqlCommand(s1, conn);
();
();
/*获?得?教ì师簗姓?名?*/
string s2 = "select tname from tutor where tno='" + selectno + "'";
();
SqlDataAdapter da1 = new SqlDataAdapter(s2, conn);
(ds, "选?择?教ì师簗");
string selectname = ["选?择?教ì师簗"].Rows[0]["tname"].ToString();
();
("向ò " + selectname + " 老?师簗发ぁ?出?了?申Θ?请?");
= false;
();
();
}
}
private void button5_Click(object sender, EventArgs e)
{
//取?消?选?择?导?师簗
= false;
();
();
}
private void linkLabel3_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
//刷¢新?
();
SqlCommand c1 = new SqlCommand(sql2, conn);
SqlDataReader dr = ();
if (())
{
k = 1;
();
SqlDataAdapter dp = new SqlDataAdapter(sql2, conn);
DataSet ds = new DataSet();
();
(ds, "tutor");
= ["tutor"].Rows[0]["tname"].ToString();
= ["tutor"].Rows[0]["tno"].ToString();
= ["tutor"].Rows[0]["sex"].ToString();
= ["tutor"].Rows[0]["message"].ToString();
();
}
();
//显?示?导?师簗邀?请?人?数簓
string s3 = "select count(tnoselect) from student where sno='" + no + "'";
();
SqlCommand c = new SqlCommand(s3, conn);
SqlDataReader dr3 = ();
if (())
{
();
();
SqlDataAdapter da1 = new SqlDataAdapter(s3, conn);
DataSet ds = new DataSet();
(ds, "导?师簗邀?请?人?数簓");
string s4 = ["导?师簗邀?请?人?数簓"].Rows[0][0].ToString();
= "收?到?" + s4 + "个?导?师簗邀?请?";
}
();
();
}
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
Form6 f6 = new Form6();
();
}
}
}
Form4 管理员界面
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using Excel = ;
namespace daoshizhi
{
public partial class Form4 : Form
{
SqlConnection conn = new SqlConnection("server=.;database=tutorManagement;uid=sa;pwd=sa");
string s1 = "select as 教ì师簗号?,tname as 导?师簗姓?名?,sno as 学§号?,name as 学§生Θ?姓?名? from student join tutor on = order by ,sno";
string s2 = "select tno as 教ì师簗号?,tname as 姓?名?,sex as 性?别纄,message as 简ò介é from tutor";
string s3 = "select sno as 学§号?,name as 姓?名?,sex as 性?别纄,message as 自?我ò简ò介é from student";
string s4 = "select count(sno) from student";
string s5 = "select count(sno) from student where tno is not null";
public SqlDataAdapter adap = new SqlDataAdapter();
public DataSet ds = new DataSet();
public Form4()
{
InitializeComponent();
}
private void Form4_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
//显?示?双?选?表括?
= null;
= new SqlCommand(s1, conn);
(ds, "双?选?表括?);
= ["双?选?表括?];
();
SqlDataAdapter da = new SqlDataAdapter(s4,conn);
DataSet ds2 = new DataSet();
(ds2, "学§生Θ?人?数簓");
string x0 = ["学§生Θ?人?数簓"].Rows[0][0].ToString();
();
();
SqlDataAdapter da1 = new SqlDataAdapter(s5, conn);
DataSet ds3 = new DataSet();
(ds3, "已?完?成é双?选?学§生Θ?人?数簓");
string y0 = ["已?完?成é双?选?学§生Θ?人?数簓"].Rows[0][0].ToString();
();
= "已?有瓺" + y0 + "/" +x0+ "学§生Θ?完?成é双?选?";
();
();
();
}
private void button2_Click(object sender, EventArgs e)
{
//显?示?教ì师簗表括?
= null;
= new SqlCommand(s2, conn);
(ds, "教ì师簗表括?);
= ["教ì师簗表括?];
();
/* ();
();
();
();
();
();*/
}
private void button3_Click(object sender, EventArgs e)
{
//显?示?学§生Θ?表括?
= null;
= new SqlCommand(s3, conn);
(ds, "学§生Θ?表括?);
= ["学§生Θ?表括?];
();
/* ();
();
();
();
();
();*/
}
private void button4_Click(object sender, EventArgs e)
{
}
private void button7_Click(object sender, EventArgs e)
{
ExportDataGridview(dataGridView1,true);
}
public bool ExportDataGridview(DataGridView gridView, bool isShowExcle)
{
if ( == 0)
{
return false;
}
//创洹?建¨Excel对?象ó
excel = new ();
(true);
//生Θ?成é字?段?名?称?
for (int i = 0; i < ; i++)
{
[1, i + 1] = [i].HeaderText;
}
//填?充?数簓据Y
for (int i = 0; i < - 1; i++) //循-环·行D
{
for (int j = 0; j < ; j++) //循-环·列
{
if (gridView[j, i].ValueType == typeof(string))
{
[i + 2, j + 1] = "'" + [i].Cells[j].();
}
else
{
[i + 2, j + 1] = [i].Cells[j].();
}
}
}
//设Θ?置?禁?止1弹獭?出?保馈?存?和í覆2盖?询ˉ问ê提?示?框ò
= false;
= false;
= false;
//保馈?存?临ⅷ?时骸?工¤作痢?簿?
//(true).Save();
//保馈?存?文?件t
("D:" + "\\");
();
return true;
}
}
}
Form5 处理学生申请
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace daoshizhi
{
public partial class Form5 : Form
{
SqlConnection conn = new SqlConnection("server=.;database=tutorManagement;uid=sa;pwd=sa");
public static string no = ;
public Form5()
{
InitializeComponent();
();
string s = "select sno,name,sex,message from student where selectno='" + no + "'";
SqlCommand a = new SqlCommand(s, conn);
SqlDataReader dr = ();
while (())
{
(("{0} {1} {2} {3}", dr[0], dr[1], dr[2], dr[3]));
(dr[0]);
}
();
}
private void button1_Click(object sender, EventArgs e)
{//接ó受酣?邀?请?
if ( == -1) { ("未′选?中D任?何?项?!?"); return; }
string s1 = ();
string s2 = "update student set tno='" + no + "' where sno='" + s1 + "'";
string s3 = "update student set tno=null where sno='" + s1 + "'";
();
SqlCommand cmd = new SqlCommand(s2, conn);
();
();
= 0;
();
SqlCommand cmd2 = new SqlCommand(s3, conn);
();
();
("添?加ó学§生Θ?+s1);
();
}
private void button2_Click(object sender, EventArgs e)
{//拒ü绝?邀?请?
if ( == -1) { ("未′选?中D任?何?项?!?"); return; }
string s1 = ();
();
string s2 = "update student set selectno=null where sno='" + s1 + "'";
();
SqlCommand cmd = new SqlCommand(s2, conn);
();
();
("拒ü绝?了?来ぁ?自?"+s1+"的?申Θ?请?");
}
}
}
Form6 处理导师邀请
using System;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
using ;
namespace daoshizhi
{
public partial class Form6 : Form
{
SqlConnection conn = new SqlConnection("server=.;database=tutorManagement;uid=sa;pwd=sa");
public static string no = ;
public Form6()
{
InitializeComponent();
();
string s = "select tno,tname,sex,message from tutor where tno=(select tnoselect from student where sno='" + no + "')";
SqlCommand a = new SqlCommand(s, conn);
SqlDataReader dr = ();
while (())
{
(("{0} {1} {2} {3}", dr[0], dr[1], dr[2], dr[3]));
(dr[0]);
}
();
}
private void button1_Click(object sender, EventArgs e)
{//接ó受酣?邀?请?
if ( == -1) { ("未′选?中D任?何?项?!?"); return; }
string s1 = ();
string s2 = "update student set tno='" + s1 + "' where sno='" + no + "'";
string s3 = "update student set tnoselect=null where sno='" + no + "'";
();
SqlCommand cmd = new SqlCommand(s2, conn);
();
();
();
();
SqlCommand cmd2 = new SqlCommand(s3, conn);
();
();
("添?加ó导?师簗 " + s1);
= 1;
}
private void button2_Click(object sender, EventArgs e)
{
//拒ü绝?邀?请?
if ( == -1) { ("未′选?中D任?何?项?!?"); return; }
string s1 = ();
();
string s2 = "update student set tnoselect=null where sno='" + no + "'";
();
SqlCommand cmd = new SqlCommand(s2, conn);
();
();
("拒ü绝?了?来ぁ?自? " + s1 + " 的?邀?请?");
}
}
}
五软件测试说明
登录界面
无导师时
修改个人简介
申请导师
教师登录
邀请学生
处理学生申请
管理员
此部分包括软件的测试数据与测试截图及说明,最好使用三中的测试用例。
六软件使用说明
登录:点选教师/学生/管理员登录,输入正确用户名(教师号、学号)和密码成功登录。
教师:
默认可带5个学生。界面显示“我的学生”和全部目前无导师的“待分配学生”。
邀请学生:点选下拉框中的学号,点击“邀请”,若学生未达上限,即向选中的学生发出邀请,等待学生处理。学生将收到老师的基本信息和教学经历等内容。
处理学生申请:若收到来自学生的申请,点击进入处理界面,可同意或拒绝。
刷新:点击刷新可更新显示信息
学生:
只能有一位导师。界面显示“个人简介”和导师信息。
修改个人简介:点击在文本框中输入要更改的内容,保存可修改个人简介。
申请导师:若无导师信息,点击“申请导师”按钮可在下拉列表中选择导师,点击“申请”,向导师发送申请,等待老师处理。导师将收到学生的基本信息和个人简介。
处理导师邀请:若收到邀请,点击可进入处理界面查看邀请信息,点选下拉框,点选按钮同意或拒绝邀请。
刷新:刷新显示信息
管理员:
根据按钮提示进行教师表、学生表、双选表的增删改查。