数库课程设计
题 目 某电力公司收费理信息系统
专业班级
姓 名
学 号
完成日期 2013
课程实验目
1 通课程设计学生进步巩固学知识考查学生数库理知识理解力综合运力
2 培养学生学独立思考力学会查找资料善分析资料力
3 培养学生独立设计独立调试程序力
4 培养学生初步软件设计力形成良编程风格
二 课程实验求
(28)某电力公司收费理信息系统
1 实现客户信息电类型(类号类名电价)业务员理
2 实现客户电信息理(客户号月份电类号电度数)
3 实现客户费理(客户号月份费收费标志)收费标志默认值未收’
4 实现收费登记(客户月份应收费实收费业务员)动修改收费标志(触发器实现)
5 创建触发器实现收费时动更加应收费实收费计算次结余然修改客户信息表中结余金额
6 创建存储程统计指定月份应收费实收费
7 创建存储程查询指定月份未交费户信息便崔费
8 创建规月份符合格式××××年××月邦定表中相应字段
9 建立表间关系
三 课程设计求
1 数库理知识理解基础重点针具体实际问题选择设计合适数库表加应基础完成相关算法程序
2 出系统概设计详细设计
3 完成数流程图ER关系图数库表程序流程图功模块图设计功编程加实现
4 设计必视图触发器存储程
5 相关编程工具(C#NET)ORACLE编写代码实现设计数库系统
6 完成规范化课程设计报告编写
7 学完成题目题目老师安排
四 实验环境
VS2010SQLsever2008
五课程设计程
1 根题目写出关系模型:
① 客户(客户号客户名址联系方式)
② 电类型(类号编号类名电价)
③ 员工(员工号姓名性联系方式)
④ 电信息(客户号月份类号电度数)
⑤ 费理(客户号月份费收费标志)
⑥ 收费登记(客户号月份应收费实收费员工号)
⑦ 结余登记(客户号月份应收费实收费结余费)
2根关系模型绘制出ER模型:
3 创建表
1客户表
Create table 客户
(
客户号 char(5) PRIMARY KEY
客户名 char(4)
址 varchar(50)
联系方式 char(10)
)
插入数:
Insert into 客户 values('00001''张三''市南区''0000000')
Insert into 客户 values('00002''李四''黄岛区''0000002')
Insert into 客户 values('00003''王五''崂山区''0000003')
Insert into 客户 values('00004''赵兰''城阳区''0000004')
Insert into 客户 values('00005''李青''黄岛区''0000005')
Insert into 客户 values('00006''张倩''市南区''0000001')
2电类型表
Create table 电类型
(
类号 char(10) PRIMARY KEY
类名 varchar(50)
电价 money
)
插入数:
Insert into 电类型 values('ABC''家庭''100')
Insert into 电类型 values('ABD''政府''200')
Insert into 电类型 values('ABE''工厂''150')
Insert into 电类型 values('ABF''学校''250')
Insert into 电类型 values('ABG''医院''050')
3员工表
Create table 员工
(
员工号 char(5) PRIMARY KEY
姓名 char(20)
性 char(10)
联系方式 char(20)
)
插入数:
Insert into 员工 values('12345''李丽''女''1230000')
Insert into 员工 values('12346''王华''男''1230002')
Insert into 员工 values('12347''张悦''女''1230003')
4电信息表
Create table 电信息
(
客户号 char(5)
类号 char(10)
月份 date
电度数 char(8)
primary key (客户号类号月份)
foreign key (客户号) references 客户(客户号)
foreign key (类号) references 电类型(类号)
)
Insert into 电信息 values('00001''ABC''20131201''100')
Insert into 电信息 values('00001''ABE''20131201''220')
Insert into 电信息 values('00002''ABC''20131201''110')
Insert into 电信息 values('00003''ABE''20131101''125')
Insert into 电信息 values('00003''ABE''20131201''105')
Insert into 电信息 values('00004''ABC''20131201''200')
Insert into 电信息 values('00005''ABC''20131201''102')
Insert into 电信息 values('00006''ABC''20131201''100')
5费理
Create table 费理
(
客户号 char(5)
月份 date
费 money
收费标志 varchar(50)
PRIMARY KEY (客户号月份)
foreign key (客户号) references 客户(客户号)
)
6收费登记
Create table 收费登记
(
客户号 char(5)
月份 date
应收费 money
实收费 money
员工号 char(5)
PRIMARY KEY (客户号月份)
foreign key (员工号) references 员工(员工号)
)
7结余登记
Create table 结余登记
(
客户号 char(5)
月份 date
应收费 money
实收费 money
结余费 money
PRIMARY KEY (客户号月份)
)
4创建触发器
触发器1:计算费
create trigger change_trigger1
on 电信息
for insert
as
insert
into 费理 (客户号月份费)
SELECT inserted客户号inserted月份inserted电度数*(select 电价 from 电类型inserted where 电类型类号inserted类号)
FROM inserted
触发器2未收标志
create trigger change_trigger on 费理
for insert
as
update 费理 set 收费标志'未收'
触发器3:已收标志
create trigger change_trigger3
on 收费登记
for update
as
update 费理 set 收费标志'已收'
from 费理inserted
where 费理客户号inserted客户号 and 费理月份inserted月份
触发器4结余登记
create trigger change_trigger4
on 收费登记
for update
as
insert into 结余登记
select inserted客户号 inserted月份inserted应收费inserted实收费inserted实收费inserted应收费
from inserted
5建立存储
存储程1:应收费实收费
create procedure ch_procedure01
@month date
as
begin
select 月份应收费实收费
from 收费登记
where 收费登记月份@month
end
go
存储程2:未收费
create procedure ch_procedure02
@month date
as
begin
select 客户号月份结余费
from 结余登记
where 结余登记月份@month
order by 结余费
end
go
6表间关系
六代码实现程
1显示窗体容表容
private void Form5_Load(object sender EventArgs e)
{
string consqlserver Data SourceGXWPCInitial Catalogliqiuyue0Integrated SecurityTrue
string consqlserver Data SourceCHENPCInitial CatalogrlIntegrated SecurityTrue
定义连接数源
string sql select * from 电信息
SqlConnection sqlcon new SqlConnection(consqlserver)
sqlconOpen()
SqlDataAdapter da new SqlDataAdapter(sql sqlcon)
DataSet ds new DataSet()shengming
try
{
daFill(ds)
if (dsTables[0]RowsCount > 1) 判断否符合条件数记录
{
获数源赋予数库控件
dataGridView1DataSource dsTables[0]
}
}
catch (Exception ex)
{
throw new Exception(exToString())
}
finally
{
sqlconClose()
sqlconDispose()
daDispose()
}
}
结果图示:
2插入行信息代码
private void label3_Click(object sender EventArgs e)
{
}
private void button1_Click(object sender EventArgs e)
{
string consqlserver Data SourceGXWPCInitial Catalogliqiuyue0Integrated SecurityTrue
string sql select * from 客户
SqlConnection sqlcon new SqlConnection(consqlserver)
sqlconOpen()
try
{
首先判断输入信息否完全
if (textBox1Text )
{
MessageBoxShow(请输入完整数信息 信息提示 SystemWindowsFormsMessageBoxButtonsOK SystemWindowsFormsMessageBoxIconWarning)
}
else
{
DataSet ds new DataSet()
判断保存重复记录问题
string strSqls
strSqls stringFormat(SELECT * FROM 电信息 where 客户号' + textBox1TextTrim() + 'and 类号' + textBox2TextTrim() + 'and 月份' + textBox3TextTrim() + ')
定义SQL Server连接象
SqlDataAdapter da new SqlDataAdapter(strSqls sqlcon)
daFill(ds)
if (dsTables[0]RowsCount > 1)
{
MessageBoxShow(已存 信息提示 SystemWindowsFormsMessageBoxButtonsOK SystemWindowsFormsMessageBoxIconError)
}
else
{
strSqls insert into 电信息 values (' + textBox1TextTrim() + '' + textBox2TextTrim() + '' + textBox3TextTrim() + '' + textBox4TextTrim() + ')
定义SQL Server连接象
SqlConnection sqlcon1 new SqlConnection(consqlserver)
SqlCommand cmd new SqlCommand(strSqls sqlcon1)
try
{
sqlcon1Open()
cmdExecuteNonQuery()
}
catch { }
finally
{
sqlcon1Close()
sqlcon1Dispose()
cmdDispose()
}
MessageBoxShow(保存成功 信息提示 SystemWindowsFormsMessageBoxButtonsOK SystemWindowsFormsMessageBoxIconInformation)
刷新数
string sqls select * from 电信息
SqlDataAdapter da1 new SqlDataAdapter(sqls sqlcon)
da1Fill(ds)
if (dsTables[0]RowsCount > 1)
{
dataGridView1DataSource dsTables[0]
}
}
}
}
catch { }
}
结果图示:
3修改行信息容
private void button2_Click(object sender EventArgs e)
{
string consqlserver Data SourceGXWPCInitial Catalogliqiuyue0Integrated SecurityTrue
string sql select * from 客户
SqlConnection sqlcon new SqlConnection(consqlserver)
sqlconOpen()
try
{
if (textBox1Text )
{
MessageBoxShow(请输入客户号类号月份 信息提示 SystemWindowsFormsMessageBoxButtonsOK SystemWindowsFormsMessageBoxIconWarning)
}
else
{
DataSet ds new DataSet()
string strSqls stringFormat(SELECT * FROM 电信息 where 客户号' + textBox1TextTrim() + 'and 类号' + textBox2TextTrim() + 'and 月份' + textBox3TextTrim() + ')
string strSqls stringFormat(SELECT * FROM 客户 where 客户号' + textBox1TextTrim() + ')
string strSqls stringFormat(update teacher set tname' + textBox2TextTrim() + 'where tno' + textBox1TextTrim() + ')
SqlConnection con new SqlConnection(consqlserver)
SqlDataAdapter da new SqlDataAdapter(strSqls con)
定义SQL Server连接象
daFill(ds)
int tnum dataGridView1CurrentRowIndex先选中某行
string oldDate dataGridView1Rows[tnum]Cells[月份]ValueToString()
string oldLeibie dataGridView1Rows[tnum]Cells[类号]ValueToString()
strSqls stringFormat(update 客户 set 客户名' + textBox2TextTrim() + 'where 客户号' + textBox1TextTrim() + 'update 客户 set 址' + textBox3TextTrim() + 'where 客户号' + textBox1TextTrim() + 'update 客户 set 联系方式' + textBox4TextTrim() + 'where 客户号' + textBox1TextTrim() + )
strSqls stringFormat(update 电信息 set 类号' + textBox2TextTrim() + '月份' + textBox3TextTrim() + '电度数' + textBox4TextTrim() + 'where 客户号' + textBox1TextTrim() + 'and 类号' + oldLeibie + 'and 月份' + oldDate + ')
SqlConnection cons new SqlConnection(consqlserver)
SqlCommand cmd new SqlCommand(strSqls cons)
try
{
consOpen()
cmdExecuteNonQuery()
}
catch { }
finally
{
consClose()
consDispose()
cmdDispose()
}
MessageBoxShow(修改成功 信息提示 SystemWindowsFormsMessageBoxButtonsOK SystemWindowsFormsMessageBoxIconInformation)
刷新数
string sqls select * from 电信息
SqlDataAdapter da1 new SqlDataAdapter(sqls con)
DataSet dss new DataSet()
da1Fill(dss)
if (dssTables[0]RowsCount > 1)
{
dataGridView1DataSource dssTables[0]
}
}
}
catch { }
}
运行结果图示:(注应该先选中修改目改码)
5 删行信息容
private void button3_Click(object sender EventArgs e)
{
string consqlserver Data SourceGXWPCInitial Catalogliqiuyue0Integrated SecurityTrue
SqlConnection sqlcon new SqlConnection(consqlserver)
sqlconOpen()
try
{
if (textBox1Text )
{
MessageBoxShow(请选择输入删信息 信息提示 SystemWindowsFormsMessageBoxButtonsOK SystemWindowsFormsMessageBoxIconWarning)
}
else
{
DataSet ds new DataSet()
判断删数信息否存
string strSqls
strSqls stringFormat(SELECT * FROM 电信息 where 客户号' + textBox1TextTrim() + 'and 类号' + textBox2TextTrim() + 'and 月份' + textBox3TextTrim() + ')
strSqls stringFormat(SELECT * FROM 客户 where 客户号' + textBox1TextTrim() + ')
定义SQL Server连接象
SqlConnection con new SqlConnection(consqlserver)
SqlDataAdapter da new SqlDataAdapter(strSqls con)
daFill(ds)
if (dsTables[0]RowsCount > 0)
{
if (MessageBoxShow(确认删? 信息提示 SystemWindowsFormsMessageBoxButtonsYesNo SystemWindowsFormsMessageBoxIconQuestion) SystemWindowsFormsDialogResultYes)
{
定义删数信息SQL语句
strSqls stringFormat(delete from 电信息 where 客户号' + textBox1TextTrim() + 'and 类号' + textBox2TextTrim() + 'and 月份' + textBox3TextTrim() + ')
定义SQL Server连接象
SqlConnection cons new SqlConnection(consqlserver)
SqlCommand cmd new SqlCommand(strSqls cons)
try
{
consOpen()
cmdExecuteNonQuery()
}
catch { }
finally
{
consClose()
consDispose()
cmdDispose()
}
MessageBoxShow(信息删成功 信息提示 SystemWindowsFormsMessageBoxButtonsOK SystemWindowsFormsMessageBoxIconInformation)
刷新数
string sqls select * from 电信息
SqlDataAdapter da1 new SqlDataAdapter(sqls con)
DataSet dss new DataSet()
da1Fill(dss)
if (dssTables[0]RowsCount > 0)
{
dataGridView1DataSource dssTables[0]
}
}
}
}
}
catch { }
}
}
}
七运行结果展示:
触发器实现动修改计算:
添加新值收费标志动改成未收
存储程实现实现存储指定日期应收费实收费
八总结心体会
通月课程设计简单完成某电力公司收费理信息系统题目相关求设计时创建表table存储程procedure触发器trigger规rule实现相关功写SQL语句(createselect等语句)创建查询表中相关信息次课程设计熟悉VS2010SQLsever2008时sql语句强加练遍学会创建规存储程触发器熟悉C#遇许问题:1C#熟悉刚开始插手难慢慢熟悉掌握编程技巧2修改码时查询根码实现通查资料值提取出保存字符串里样轻易解决代码: inttnumdataGridView1CurrentRowIndex先选中某行
string oldDate dataGridView1Rows[tnum]Cells[月份]ValueToString()
string oldLeibie dataGridView1Rows[tnum]Cells[类号]ValueToString()样修改码3创建触发器实现相关功时身知识够写完整导致级联反复修改实现4存储程实现时会调知道样传参做长时间请教实现存储程代码:
commParametersAdd(@month SqlDbTypeDate) commParameters[@month]Value textBox2Text
说次课程设计收获少仅学期学知识容综合考验回顾知识牢记知识复知识次时机时中足次作业觉应该认真虚心学
文档香网(httpswwwxiangdangnet)户传
《香当网》用户分享的内容,不代表《香当网》观点或立场,请自行判断内容的真实性和可靠性!
该内容是文档的文本内容,更好的格式请下载文档