资源描述
.
武汉产业学院
数据库使用零碎计划
试验讲演
学号:090501102
姓名:
班级:
毕波
盘算机091
指点老师:
.
武汉产业学院数据库使用零碎计划
人事人为治理零碎
计划总阐明:在当今社会,人为治理是一项须要并且非常要害的任务。现在跟着企业数目
的急剧增加,处置人们的人为数据变的越来越繁缛艰难。现在,盘算机曾经遍及到了简直每
个黉舍、家庭,咱们的进修跟生涯曾经到处离不开盘算机的存在。
本零碎依照开辟请求要紧使用于企业人事零碎,实现对一样平常的人为增删查改的数字化管
理。比拟零碎地对员工的信息跟人为进展治理,查问、增加、修正、删除都变的特别轻便,
节约了少量的任务量。
本课程计划是在进修了《数据库使用零碎》跟相干开辟软件课程之后,让先生经过实践
工程的计划、开辟,培育先生独破进展数据库软件的建模、在盘算机中进展数据库计划、并
经过相干软件开辟零碎的才干。
本零碎的根本功用包含:部分信息的治理〔查问、增加、修正、删除先生部分等〕
信息的治理〔录入、查问、修正、删除员工的信息等〕、人为信息的治理〔录入、查问、修正
员工的人为等〕。
、人员
本零碎要紧用于对员工人为进展治理,能够进展拔出、删除、修正、查问跟表现员工的
信息。登录该零碎时,用户需要输出口令跟暗码,以确保数据的平安性,胜利登录的用户,
能够拔出员工的信息跟人为,并对员工的信息跟人为进展增、删、改操纵。
基于上述办法,咱们将员工数据保管到数据库中。咱们请求零碎能够高效疾速的处置数
据,同时要保障数据的准确性、相容性跟平安性。因而在数据库中需要界说非常多触发器,比
如删除了某个员工的信息那么删除对应的一切人为信息、在世删除了某部分那么删除该部分一切
的信息等。
因而咱们要从数据库中读取数据,同时跟界面联络起来,同时也能将用户界面上的数据
存储到数据库中。以上是计划此零碎应当留意的地点跟计划原那么,以下确实是遵照这些原那么跟
规范计划出的一套完好的治理零碎。
第1页共18页
武汉产业学院数据库使用零碎计划
一零碎需要:
依照标题需要,能够把零碎分为三个局部:部分信息治理局部、人员信息治理局部跟工
资信息治理局部。本次试验中,我要紧担任部分信息治理模块,题中需要对部分信息进展查
询、增加、修正、删除操纵,这些操纵按能否改动数据库数据可分为两类:查问操纵,只读
取数据库信息,过错信息做修正;删除、更新跟增加操纵,需要对数据库中的数据进展读写
操纵。因而只需写两局部代码,查问局部:deptinfo_Query进展部分信息查问,查问数据库信
息;信息治理局部:deptinfo_Manage,对信息进展更新、增加跟删除。
二数据库计划
1.数据需要
人事人为治理零碎需要实现的要紧功用有:
1员工的根本信息录入
2.人为信息表的录入。
3.部分信息表的查问、拔出、修正、删除等操纵。
2.相干表
表1职工表:Employee_Info
第2页共18页
武汉产业学院数据库使用零碎计划
表2人为表:Salary
第3页共18页
武汉产业学院数据库使用零碎计划
表3部分表:Dept_Info
表4零碎用户表:User_Info
3.数据流程图
第4页共18页
武汉产业学院数据库使用零碎计划
人事人为治理零碎
登录
零碎治理员
职
工
资
表
部
门
表
工
表
图数据流程图
三员工人为相干操纵
1.查问局部
相干代码:
dateGrid1数据绑定
privatevoidBindData(Stringsql)
{
SqlConnectionconnection=
SqlDataAdapterdataAdapter=
newSqlConnection(connString);
newSqlDataAdapter(sql,connection);
DataSetdataSet=
newDataSet();
dataAdapter.Fill(dataSet);
dataGridView1.DataSource=dataSet.Tables[0];
dataGridView1.Columns[0].DataPropertyName=
dataGridView1.Columns[1].DataPropertyName=
dataGridView1.Columns[2].DataPropertyName=
dataGridView1.Columns[3].DataPropertyName=
"职工è号";
"年份";
"月份";
"人为o";
}
部分组合框的数据绑定
第5页共18页
武汉产业学院数据库使用零碎计划
private
voidBindDeptComBox()
{
stringsql="SELECT*FROM[Dept_Info]";
SqlConnectionconnection=
SqlDataAdapterdataAdapter=
newSqlConnection(connString);
newSqlDataAdapter(sql,connection);
DataSetdataSet=
newDataSet();
dataAdapter.Fill(dataSet);
DeptcomBox.DataSource=dataSet.Tables[0];
DeptcomBox.DisplayMember=
DeptcomBox.ValueMember=
DeptcomBox.SelectedIndex=0;
"DeptName";
"DeptID";
}
{
按部分查问
private
voidcheck1_CheckedChanged(objectsender,EventArgse)
if(check1.Checked)
{
btnYes.Enabled=
true;
true;
DeptcomBox.Enabled=
check4.Checked=
check4.Enabled=
false;
false;
}
{
else
DeptcomBox.Enabled=
check4.Enabled=
false;
true;
}
}
{
按年份查问
private
voidcheck2_CheckedChanged(objectsender,EventArgse)
btnYes.Enabled=
true;
if(check2.Checked)
{
}
{
}
YearComBox.Enabled=
else
true;
YearComBox.Enabled=
false;
YearComBox.SelectedIndex=0;
}
按月份Y查问
private
voidcheck3_CheckedChanged(objectsender,EventArgse)
第6页共18页
武汉产业学院数据库使用零碎计划
{
if(check3.Checked)
{
btnYes.Enabled=
true;
true;
MonthComBox.Enabled=
}
{
}
else
MonthComBox.Enabled=
false;
}
{
仅查问本人的人为
private
voidcheck4_CheckedChanged(objectsender,EventArgse)
if(check4.Checked)
{
btnYes.Enabled=
true;
check1.Enabled=
false;
DeptcomBox.Enabled=
false;
}
{
else
check1.Enabled=
check1.Checked=
true;
false;
}
}
{
private
voidbtnYes_Click(objectsender,EventArgse)
count=0;
StringYearStr;
intMonthStr;
StringDeptStr;
StringsqlStr=
"";
"";
sql=
DeptStr=
Convert.ToString(DeptcomBox.SelectedValue.ToString());
部分号
if(check1.Checked)
{
DeptStr=
sqlStr=
月份',Salaryas'
Convert.ToString(DeptcomBox.SelectedValue.ToString());
String.Format("select[Salary].EmpIDas'
职工号',Yearas'
年份',Monthas'
人为o'from[Salary],[Employee_Info]whereDeptID='{0}'and
Salary.EmpID=Employee_Info.EmpID",DeptStr);
if(count==0)
{
第7页共18页
武汉产业学院数据库使用零碎计划
sql+=sqlStr;
count=1;
}
{
}
else
sql+=
"intersect"
+sqlStr;
check1.Checked=
false;
}
{
年份
if(check2.Checked)
YearStr=
Convert.ToString(YearComBox.SelectedItem.ToString());
if(this.mainForm.operatorRight==2)
{
sqlStr=
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份',
Salaryas'人为'from[Salary]whereYear='{0}'"
,YearStr);
}
elseif(this.mainForm.operatorRight==1)
{
sqlStr=年份',Monthas'
月',Salaryas'人为'fromSalary,Employee_Info,Dept_InfowhereYear='{0}'and
Salary.EmpID=Employee_Info.EmpIDandEmployee_Info.DeptID=Dept_Info.DeptIDandDept_Info.DeptIDin
String.Format("selectSalary.EmpIDas'
职工号',Yearas'
(selectDeptIDfromEmployee_InfowhereEmpID='{1}')"
,YearStr,this.mainForm.person.userName);
}
else
{
sqlStr=
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份
',Salaryas'
人为á'from[Salary]whereYear='{0}'andEmpID='{1}'"
,
YearStr,this.mainForm.person.userName);
}
if(count==0)
{
sql+=sqlStr;
count=1;
}
else
{
sql+=
"intersect"
+sqlStr;
}
check2.Checked=
false;
}
月份
第8页共18页
武汉产业学院数据库使用零碎计划
if(check3.Checked)
{
MonthStr=
Convert.ToInt32(MonthComBox.SelectedItem.ToString());
if(this.mainForm.operatorRight==2)
{
sqlStr=
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份',
Salaryas'人为'from[Salary]whereMonth='{0}'"
,MonthStr);
}
elseif(this.mainForm.operatorRight==1)
{
sqlStr=年份',Monthas'
月份',Salaryas'
Salary.EmpID=Employee_Info.EmpIDandEmployee_Info.DeptID=Dept_Info.DeptIDandDept_Info.DeptIDin
String.Format("selectSalary.EmpIDas'
职工号',Yearas'
人为'fromSalary,Employee_Info,Dept_InfowhereMonth='{0}'and
(selectDeptIDfromEmployee_InfowhereEmpID='{1}')"
,MonthStr,
this.mainForm.person.userName);
}
else
{
sqlStr=
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份',
Salaryas'工'from[Salary]whereMonth='{0}'andEmpID='{1}'"
,
MonthStr,this.mainForm.person.userName);
}
if(count==0)
{
sql+=sqlStr;
count=1;
}
else
{
sql+=
"intersect"
+sqlStr;
}
check3.Checked=
false;
}
{
本人人为
if(check4.Checked)
sql=
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份',Salary
as'人为'fromSalarywhereEmpID='{0}'"
,this.mainForm.person.userName);
if(count==0)
{
sql+=sqlStr;
count=1;
}
else
第9页共18页
武汉产业学院数据库使用零碎计划
{
}
sql+=
"intersect"
+sqlStr;
check4.Checked=
false;
}
SqlCommandcommand=
newSqlCommand(sql,connection);
try
{
connection.Open();
SqlDataReaderdata=command.ExecuteReader();
if(data.Read())
{
BindData(sql);
}
else
{
if(this.mainForm.operatorRight==2)
{
sql=
人为'fromSalary"
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份
',Salaryas'
);
}
{
elseif(this.mainForm.operatorRight==1)
sql=
'月份',Salaryas'
String.Format("selectSalary.EmpIDas'年份',Monthas
职工号',Yearas'
人为'fromSalary,Employee_Info,Dept_InfowhereSalary.EmpID=Employee_Info.EmpID
andEmployee_Info.DeptID=Dept_Info.DeptIDandDept_Info.DeptIDin(selectDeptIDfromEmployee_Info
whereEmpID='{0}')",this.mainForm.person.userName);
}
else
{
sql=
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份
',Salaryas'
人为'fromSalarywhereEmpID='{0}'"
,this.mainForm.person.userName);
}
BindData(sql);
MessageBox.Show(
"查问掉败,不契合请求的人为信息","查寻掉败",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
}
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message,
"数据库操纵掉败1",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
finally
第10页共18页
武汉产业学院数据库使用零碎计划
{
}
connection.Close();
}
{
privatevoidLoadOrCancel()
mainForm=(MainForm)
this.ParentForm;
YearComBox.SelectedIndex=0;
MonthComBox.SelectedIndex=0;
YearComBox.Enabled=
false;
false;
false;
MonthComBox.Enabled=
DeptcomBox.Enabled=
btnYes.Enabled=
false;
BindDeptComBox();
if(this.mainForm.operatorRight==2)
{
sql=
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份',Salary
as'人为'fromSalary"
);
}
elseif(this.mainForm.operatorRight==1)
{
DeptcomBox.Visible=
check1.Visible=
false;
false;
sql=
String.Format("selectSalary.EmpIDas'
职工号',Yearas'
年份',Monthas'
月份',
Salaryas'人为'fromSalary,Employee_Info,Dept_InfowhereSalary.EmpID=Employee_Info.EmpIDand
Employee_Info.DeptID=Dept_Info.DeptIDandDept_Info.DeptIDin(selectDeptIDfromEmployee_Infowhere
EmpID='{0}')",this.mainForm.person.userName);
}
else
{
check1.Visible=
false;
false;
check4.Visible=
DeptcomBox.Visible=
false;
sql=
String.Format("selectEmpIDas'
职工号',Yearas'
年份',Monthas'
月份',Salary
as'人为'fromSalarywhereEmpID='{0}'"
,this.mainForm.person.userName);
}
BindData(sql);
count=0;
}
privatevoidgroupBox2_Enter(objectsender,EventArgse)
{
}
第11页共18页
武汉产业学院数据库使用零碎计划
2.对表的增编削局部:
ataGrid数据绑定
private
voidBindData()
{
sql=
人为'fromSalary"
String.Format("selectEmpIDas'
);
职工号',Yearas'
年份',Monthas'
月份',Salaryas'
SqlConnectionconnection=
SqlDataAdapterdataAdapter=
newSqlConnection(connString);
newSqlDataAdapter(sql,connection);
DataSetdataSet=
newDataSet();
dataAdapter.Fill(dataSet);
dataGridView1.DataSource=dataSet.Tables[0];
dataGridView1.Columns[0].DataPropertyName=
dataGridView1.Columns[1].DataPropertyName=
dataGridView1.Columns[2].DataPropertyName=
dataGridView1.Columns[3].DataPropertyName=
"职工号";
"年份";
"月份";
"人为";
}
{
删除
privatevoidbtn3_Click(objectsender,EventArgse)
cleartext();
textreadwrite();
btnOkOrCancel();
combMonth.Enabled=
combYear.Enabled=
txt4.ReadOnly=
true;
true;
true;
"delete";
opterate=
}
{
修正或更新职工人为信息
private
voidbtnOk_Click(objectsender,EventArgse)
btnOkOrCancel();
btnOk.Enabled=
false;
EmpID=txt1.Text;
Year=
Convert.ToString(combYear.SelectedItem.ToString());
Convert.ToInt32(combMonth.SelectedItem.ToString());
Month=
Stringsalary=txt4.Text;
if(salary==
"")
{
}
salary=
"0";
第12页共18页
武汉产业学院数据库使用零碎计划
Salary=(
float)Convert.ToDouble(salary.Trim());
intnum=0;
try
{
if(EmpID!="")
{
sql=
String.Format("selectcount(*)from[Employee_Info]whereEmpID='{0}'"
,
EmpID);
SqlCommandcommand=
connection.Open();
newSqlCommand(sql,connection);
intc=(int)command.ExecuteScalar();
connection.Close();
if(c>0)
{
connection=
connection.Open();
sql=
newSqlConnection(connString);
String.Format("selectcount(*)from[Salary]whereEmpID='{0}'and
,EmpID,Year,Month);
Year='{1}'andMonth='{2}'"
SqlCommandmycmd=
newSqlCommand(sql,connection);
num=(
int)mycmd.ExecuteScalar();
connection.Close();
职工的人为信息存在
if(num>0)
{
if(opterate==
"insert")
{
MessageBox.Show(
"录入不胜利,你要录入的员工的人为信息已存在!
","录入
掉败",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
textreadonly();
}
elseif(opterate==
"update")
{
sql=
andYear='{2}'andMonth='{3}'"
String.Format("update[Salary]setSalary='{0}'whereEmpID='{1}'
,Salary,EmpID,Year,Month);
connection.Open();
command=
newSqlCommand(sql,connection);
command.ExecuteNonQuery();
connection.Close();
BindData();
textreadonly();
MessageBox.Show(
"更新胜利!","更新胜利",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
else
第13页共18页
武汉产业学院数据库使用零碎计划
{
connection.Open();
sql=
String.Format("deletefrom[Salary]whereEmpID='{0}'and
Year='{1}'andMonth='{2}'"
command=
,EmpID,Year,Month);
newSqlCommand(sql,connection);
command.ExecuteNonQuery();
connection.Close();
BindData();
MessageBox.Show(
"删除胜利!","删除胜利",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
textreadonly();
}
}
{
else
if(opterate==
"insert")
{
sql=
String.Format("insertinto
[Salary](EmpID,Year,Month,Salary)values('{0}','{1}','{2}','{3}')"
,EmpID,Year,Month,Salary);
command=
newSqlCommand(sql,connection);
connection.Open();
command.ExecuteNonQuery();
connection.Close();
BindData();
MessageBox.Show(
"录入胜利!","录入胜利",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
textreadonly();
}
{
elseif(opterate==
"update")
MessageBox.Show(
"修正掉败,不存在要修正的人为信息!
","修T改掉败",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
textreadonly();
}
else
{
MessageBox.Show(
"删除掉败,不存在要删除的人为信息!
","删除掉败",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
textreadonly();
}
}
}
else
{
第14页共18页
武汉产业学院数据库使用零碎计划
MessageBox.Show(
"不存在要治理的员工人为信息!","操纵掉败",
MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
textreadonly();
}
}
else
{
MessageBox.Show(
"操纵掉败,请填入员工号!","操纵掉败",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
textreadonly();
}
btnModi();
btnCancel.Enabled=
true;
}
catch(Exceptionex)
{
MessageBox.Show(ex.Message,
"数据库操纵掉败1",MessageBoxButtons.OK,
MessageBoxIcon.Exclamation);
}
finally
{
connection.Close();
}
}
3.对于界面
录入跟修正键跟封闭键能用,断定跟撤消键不克不及用
privatevoidbtnModi()
{
btn1.Enabled=
btn2.Enabled=
btn3.Enabled=
true;
true;
true;
btnOk.Enabled=
false;
btnCancel.Enabled=
false;
}
{
录入跟修正键不克不及用,断定跟撤消键跟封闭键能用
privatevoidbtnOkOrCancel()
btn1.Enabled=
btn2.Enabled=
btn3.Enabled=
btnCancel.Enabled=
btnOk.Enabled=
false;
false;
false;
true;
true;
第15页共18页
武汉产业学院数据库使用零碎计划
}
{
}
{
将文本框清空
privatevoidcleartext()
txt1.Text=
txt4.Text=
"";
"";
撤消按钮
privatevoidbtnCancel_Click(objectsender,EventArgse)
combYear.SelectedIndex=0;
combMonth.SelectedIndex=0;
combMonth.Enabled=
combYear.Enabled=
textreadonly();
false;
false;
btnModi();
BindData();
}
{
录入按钮
privatevoidbtn1_Click(objectsender,EventArgse)
cleartext();
textreadwrite();
btnOkOrCancel();
combMonth.Enabled=
combYear.Enabled=
true;
true;
opterate=
"insert";
}
{
修正按钮
privatevoidbtn2_Click(objectsender,EventArgse)
cleartext();
textreadwrite();
btnOkOrCancel();
opterate=
"update";
combMonth.Enabled=
combYear.Enabled=
true;
true;
}
第16页共18页
武汉产业学院数据库使用零碎计划
四员工人为界面:
第17页共18页
武汉产业学院数据库使用零碎计划
五课程计划总结:
本次课程计划,跟别的两个同窗一同,实现了人事人为治理零碎的计划,经过本次课
程计划,晋升了咱们的团队合作才干,增强了咱们入手、考虑跟处置咨询题的才干,
测验了我所
进修的常识,在计划进程中,与同窗分工计划,跟同窗们互相讨论,互相进修,互相监视。经过实现零碎
的计划,使本人对C#编写C/S零碎有了进一步的看法,同时也进步了
C#编程才干。
本次计划顶用到了数据库、软件计划等,使得本人对所学的内容愈加明晰明白。并使本人在种种
东西的集成开辟有了全新领会。
本次课程计划最年夜的播种是了解到了团队合作以及义务计划的主要性,对于现在的本人来说想要
独破实现一个软件的计划是不理想的,分工合作能够非常好地处置那个咨询题,但合作中也会呈现非常多咨询题,
因为每团体独破计划一个模块,独自运转时不咨询题,但最初零碎功用综合运转时,因为每团体各个局部
的计划思绪不尽一样,会出非常多过错,需要跟同组人员进展相同,而后各自对本人的模块进展须要的修正,
才干综合构成一个完好的可用的零碎,由此可见在软件计划的进程中,合作是非常主要的,同时每个成员间
必需有非常好的相同,才干防止计划中呈现的不兼容的过错,才干使工程做得完满。
在试验中,清楚了C#的反应机制:一个代办东西包含了访咨询一个特定东西的特定办法所需的信息
.
只需把它当成一个聪慧的办法
已存在的办法进展范例平安的挪用
次试验对我的协助特别之年夜。
指针就行了。代办东西能够被挪动到另一个地点,而后能够经过访咨询它来对
.一个反应办法是代办的特例。对C#的强范例特色有了更深的了解。本
第18页共18页
展开阅读全文