数据库应用系统的开发Word文档格式.docx
《数据库应用系统的开发Word文档格式.docx》由会员分享,可在线阅读,更多相关《数据库应用系统的开发Word文档格式.docx(29页珍藏版)》请在冰豆网上搜索。
护界面、教师信息维护界面、课程信息维护界面。
当用户名的类型为教师的时候,进入的是教师输入成绩的界面,该界面可以
查找本教师所教的课程,并且修改所选该课程的学生的成绩。
当用户名的类型为学生的时候,进入的是学生选课的界面,该界面学生可以
选课并且可以退课,并且可以查询该学生所选的课程。
各界面的关系如下图:
本系统涉及的主要数据的E-R图
4、系统详细设计及数据库表结构设计
(一).数据库表结构设计
设计五张表:
Admin表
CREATEtableadmin
(adminidchar(9)primarykey,
adminnamechar(20)unique,
adminpaschar(10));
Student表
CREATEtablestudent
(学号char(9)primarykey,
姓名char(20)unique,
性别char
(2),
出生时间datetime,
所在系char(20),
班级char(3),
密码char(10));
Teacher表
CREATEtableteacher
(教师号char(9)primarykey,
教师名char(20)unique,
所在系char(20),
密码char(10));
Course表
CREATEtablecourse
(课程号char(4)primarykey,
课程名char(40),
教师号char(9),
学分float(53),
课程简介text,
foreignkey(教师号)referencesteacher(教师号));
Score表
CREATEtablescore
(学号char(9),
课程号char(4),
成绩smallint,
primarykey(学号,课程号),
foreignkey(学号)referencesstudent(学号),
foreignkey(课程号)referencescourse(课程号));
数据库关系图如下:
(二).登陆界面的设计:
1.首先打开VisualStudio2008。
2.新建一个工程,工程名为:
Login
3.在窗体上放置Button组件Button1、Button2,Label组件Label1、Label2,TextBox组件TextBox1、TextBox2,RadioButton组件RadioButton1、RadioButton2、RadioButton3,GroupBox组件GroupBox1。
4.设置Button组件的name属性:
Button1和Button2的name的属性分别为:
btQueding、btQuxiao。
5.设置Button组件的Text属性:
Button1和Button2的Text的属性分别为:
确定和取消。
6.设置Label组件的name属性:
Label1和Label2的name的属性分别为:
lbName,lbPas。
7.设置Label组件的Text属性:
Label1和Label2的Text的属性分别为:
学号和密码。
8.设置TextBox组件的name属性:
TextBox1和TextBox2的name的属性分别为:
tbName和tbPas。
9.设置GroupBox的name属性:
GroupBox的Text的属性为:
登陆类型。
10.设置RadioButton的name属性:
RadioButton1、RadioButton2、RadioButton3的name的属性分别为:
rbAdmin、rbStudent、rbTeacher。
11.设置RadioButton的Text属性:
RadioButton1、RadioButton2、RadioButton3的Text的属性分别为:
管理员、学生、教师。
12.设置RadioButton的checked的属性改为True。
13.双击取消按钮:
输入以下代码:
close();
14.双击确定按钮:
stringLJ=@"
server=.;
database=myd;
uid=sa;
pwd="
;
//建立连接
SqlConnectionconn=newSqlConnection(LJ);
conn.Open();
//读取所输入的用户名和密码
SqlCommandcomm=conn.CreateCommand();
if(rbAdmin.Checked)
{stringsql="
SELECTadminname,adminpasFROMadminWHERE(adminname='
"
+tbName.Text+"
'
)"
comm.CommandText=sql;
SqlDataReaderdatar=comm.ExecuteReader();
DateTimedt=newDateTime(2008,1,1);
if(DateTime.Now>
=dt)
{
MessageBox.Show("
程序已经过期,请联系开发商!
"
系统提示:
MessageBoxButtons.OK,MessageBoxIcon.Information);
Close();
}
//判断是否存在输入的用户
else
if(!
datar.HasRows)
用户名不存在,请重新输入!
);
tbName.Focus();
return;
//读取数据库的内容,并与输入的进行比较;
while(datar.Read())
//判断用户输入是否正确
if(datar["
adminpas"
].ToString().Trim()!
=tbPas.Text.Trim())
用户密码不正确,请重新输入!
tbPas.Focus();
AdminLoginf2=newAdminLogin();
f2.ShowDialog();
elseif(rbStudent.Checked)
stringsql="
SELECTsno,spasFROMstudentWHERE(sno='
spas"
StudentLoginf3=newStudentLogin();
f3.ShowDialog();
else
SELECTtno,tpasFROMteacherWHERE(tno='
tpas"
TeacherLoginf4=newTeacherLogin();
f4.ShowDialog();
完成后的界面效果如下图所示
.管理员登陆界面设计:
AdminLogin
3.在窗体上放置MenuStrip组件
4.在MenuStrip上设置三个菜单,菜单的name属性分别为:
学生信息维护、教师信息维护、课程信息维护。
5.双击学生信息维护输入以下代码:
StudentInfosi=newStudentInfo();
si.ShowDialog();
6.双击教师信息维护输入以下代码:
TeacherInfoti=newTeacherInfo();
ti.ShowDialog();
7.双击课程信息维护输入以下代码:
CourseInfoci=newCourseInfo();
ci.ShowDialog();
.学生信息维护界面:
StudentInfo
3.在新建的项目StudentInfo中添加一个名为SqlHelper.cs的类,并打开此类,找到publicstaticstringCONNSTR="
DataSource=.;
InitialCatalog=myd;
UserID=sa;
Password="
并修改。
4.在窗体上放置数据显示工具DataGridView。
5.设置DataGridView任务,在选择数据源中,选择添加项目数据源,根据数据源配置向导来添加,和数据库名为myd中的学生表连接起来,添加成功时,选择数据源为studentBindingSource。
6.在窗体上放置GroupBox组件GroupBox1,RadioButton组件RadioButton1、RadioButton2、RadioButton3,Label组件Label1、Label2、Label3、Label4、Label5、Label6,Button组件Button1、Button2、Button3,TextBox组件TextBox1到TextBox7
7.设置GroupBox的属性中的Text:
GroupBox1的Text中输入:
查询条件。
8.设置Button的属性中的Text:
Button1到Button5的Text中分别输入:
确认、返回、新增、存盘、删除。
9.设置Button的属性中的Name:
确认、返回、新增、存盘、删除的Name中分别输入:
btnOK、btnCancel、butNew、btnSave、butDel。
10.设置Label的属性中的Text:
Label1到Label6的Text中分别输入:
学号、姓名、所在系、性别、出生日期、密码。
11.设置RadioButton的属性中的Name:
RadioButton1到RadioButton3的Name中分别输入:
rbXh、rbXm、rbSzx。
12.设置RadioButton的属性中的Text:
RadioButton1到RadioButton3的Text中分别输入:
学号、姓名、所在系。
13.设置RadioButton1的属性中的checked设置为True。
14.设置TextBox的属性中的Name:
TextBox1到TextBox7的Name中分别输入:
tbSearch、tbXh、tbXm、tbSzx、tbXb、tbCsrq、tbMm。
15.分别双击确认、返回、新增、存盘、删除切换到代码窗口,输入代码,代码如下:
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Data.SqlClient;
namespacemyd
{
publicpartialclassStudentInfo:
Form
publicStudentInfo()
InitializeComponent();
privateboolInsert_flag=false;
privatevoiddataGridView1_CellClick(objectsender,DataGridViewCellEventArgse)
Insert_flag=false;
privatevoidStudentInfo_Load(objectsender,EventArgse)
//TODO:
这行代码将数据加载到表“mydDataSet1.student”中。
您可以根据需要移动或移除它。
this.studentTableAdapter.Fill(this.mydDataSet1.student);
privatevoidbtnOK_Click(objectsender,EventArgse)
if(tbSearch.Text.Length<
=0)
查询条件不能为空"
系统提示:
inti;
if(rbXh.Checked&
&
int.TryParse(tbSearch.Text,outi))
学号必需为数字"
SqlConnectioncnn=newSqlConnection
("
SqlCommandcmd=newSqlCommand();
cmd.CommandText="
Student_Info_Search"
cmd.Parameters.Add("
@SearchType"
SqlDbType.Decimal);
@SearchText"
SqlDbType.VarChar,50);
if(rbXh.Checked)
i=0;
elseif(rbXm.Checked)
i=1;
i=2;
cmd.Parameters["
].Value=i;
].Value=tbSearch.Text.Trim();
cmd.CommandType=CommandType.StoredProcedure;
cmd.Connection=cnn;
SqlDataAdaptersda=newSqlDataAdapter(cmd);
try
DataSetds=newDataSet();
sda.Fill(ds);
//填充数据集
studentBindingSource.DataSource=ds.Tables[0];
//将数据集显示出来
//把查询出来的数据绑定到相关控件
tbXh.DataBindings.Clear();
tbXm.DataBindings.Clear();
tbSzx.DataBindings.Clear();
tbXb.DataBindings.Clear();
tbCsrq.DataBindings.Clear();
tbMm.DataBindings.Clear();
tbXh.DataBindings.Add("
Text"
studentBindingSource,"
sno"
tbXm.DataBindings.Add("
studentBindingSource,"
sname"
tbSzx.DataBindings.Add("
sdept"
tbXb.DataBindings.Add("
ssex"
tbCsrq.DataBindings.Add("
sdate"
tbMm.DataBindings.Add("
if(ds.Tables[0].Rows.Count<
Insert_flag=true;
catch(Exceptionex)
出现错误,错误原因为"
+ex.Message,
"
MessageBoxButtons.OK,MessageBoxIcon.Error);
privatevoidbtnCancel_Click(objectsender,EventArgse)
privatevoidbutNew_Click(objectsender,EventArgse)
tbXh.Text="
tbXm.Text="
tbSzx.Text="
tbXb.Text="
tbCsrq.Text="
tbMm.Text="
privatevoidbtnSave_Click(objectsender,EventArgse)
stringsql;
if(Insert_flag)
sql="
Insertintostudent(sno,sname,sdept,ssex,sdate,spas)values('
+tbXh.Text+"
'
+tbXm.Text+
+tbSzx.Text+"
+tbXb.Text+"
+tbCsrq.Text+"
+tbMm.Text+"
updatestudentsetsno='
sname='
sdept='
ssex='
sdate='
spas='
whereCID="
+((DataRowView)studentBindingSource.Current)["
CID"
].ToString();
SqlCommandcmd=newSqlCommand(sql,cnn);
cnn.Open();
//打开连接
cmd.ExecuteNonQu