数据库课程设计电力公司收费系统.docx

上传人:牧羊曲112 文档编号:5306450 上传时间:2023-06-24 格式:DOCX 页数:29 大小:188.97KB
返回 下载 相关 举报
数据库课程设计电力公司收费系统.docx_第1页
第1页 / 共29页
数据库课程设计电力公司收费系统.docx_第2页
第2页 / 共29页
数据库课程设计电力公司收费系统.docx_第3页
第3页 / 共29页
数据库课程设计电力公司收费系统.docx_第4页
第4页 / 共29页
数据库课程设计电力公司收费系统.docx_第5页
第5页 / 共29页
亲,该文档总共29页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述

《数据库课程设计电力公司收费系统.docx》由会员分享,可在线阅读,更多相关《数据库课程设计电力公司收费系统.docx(29页珍藏版)》请在三一办公上搜索。

1、数据库课程设计电力公司收费系统数据库课程设计题目某电力公司收费管理信息系统专业班级姓名学号完成日期-12-18一、课程实验目的1. 经过课程设计,使学生进一步巩固所学的知识,考查学生对数据库理论及知识的理解能力和综合运用能力;2. 培养学生自主学习、独立思考的能力,学会查找资料并善于分 析资料的能力;3. 培养学生独立设计、独立调试程序的能力;4. 培养学生初步的软件设计能力,形成良好的编程风格-课程实验要求-、(28)某电力公司收费管理信息系统1. 实现客户信息、用电类型(类别号、类别名、电价)及业务 员管理;2. 实现客户用电信息管理(客户号、月份、用电类别号、用电 度数);3. 实现客户

2、费用管理(客户号、月份、费用、收费标志),收费标志的默认值为未收;4. 实现收费登记(客户、月份、应收费用、实收费用、业务员),并自动修改收费标志(用触发器实现);5. 创立触发器,实现收费时自动更加应收费用和实收费用,计算本次结余,然后修改客户信息表中的结余金额;6. 创立存储过程统计指定月份应收费用和实收费用;7. 创立存储过程查询指定月份未交费的用户信息,以便崔费;8. 创立规则使得月份符合格式“XXXX年XX月”,并邦定 到表中相应字段;9. 建立表间关系。三、课程设计要求1. 在对数据库理论及知识理解的基础上;重点是针对具体的实际 问题选择并设计合适的数据库表加以应用,并在此基础上完

3、成 相关的算法与程序;2. 给出系统的概要设计、详细设计;3. 完成数据流程图,E-R关系图,数据库表、程序流程图、功能 模块图的设计、对功能编程加以实现;4. 设计必要的视图、触发器、存储过程;5. 使用相关的编程工具(C#.NET)和ORACLE编写代码实现设计 的数据库系统;6. 完成规范化的课程设计报告的编写;7. 每个同学完成一个题目,题目由老师安排。四、实验环境VS,SQLsever五、课程设计过程1. 根据题目写出关系模型如下: 客户(客户号、客户名、地址、联系方式) 用电类型(类别号、编号、类别名、电价) 员工(员工号、姓名、性别、联系方式) 用电信息(客户号、月份、类别号、用

4、电度数) 费用管理(客户号、月份、费用、收费标志) 收费登记(客户号、月份、应收费用、实收费用、员工号) 结余登记(客户号、月份、应收费用、实收费用、结余费用)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(

5、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,家庭,1.00);Insert into 用电类型 values(ABD,

6、政府,2.00);Insert into 用电类型 values(ABE,工厂,1.50);Insert into 用电类型 values(ABF,学校,2.50);Insert into 用电类型 values(ABG,医院,0.50);3. 员工表Create table 员工(员工号 char (5) PRIMARY KEY,姓名 char(20),性别 char(10),联系方式char(20);插入数据:Insert into 员工 values(12345,李丽,女,1230000);Insert into 员工 values(12346,王华,男,1230002);Insert

7、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, -12-01,100);Insert into 用电信息 values(00001,ABE, -12-01,220);Ins

8、ert into 用电信息 values(00002,ABC, -12-01,110);Insert into 用电信息 values(00003,ABE, -11-01,125);Insert into 用电信息 values(00003,ABE, -12-01,105);Insert into 用电信息 values(00004,ABC, -12-01,200);Insert into 用电信息 values(00005,ABC, -12-01,102);Insert into 用电信息 values(00006,ABC, -12-01,100);5. 费用管理Create table费用

9、管理(客户号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,实收费用 mon

10、ey,结余费用 money,PRIMARY KEY (客户号,月份));4. 创立触发器触发器1:计算费用create trigger change_trigger1on用电信息for insertasinsertinto费用管理(客户号,月份,费用)SELECT inserted.客户号,inserted.月份,inserted.用电度数*(select 电 价from用电类型,inserted where用电类型.类别号=inserted.类别 号)FROM inserted;触发器2:未收标志create trigger change_trigger on 费用管理for insert

11、asupdate费用管理set收费标志=未收;触发器3:已收标志 create trigger change_trigger3on收费登记for updateasupdate费用管理set收费标志=已收from 费用管理,insertedwhere费用管理.客户号=inserted.客户号and费用管理.月份=inserted.月份;触发器4:结余登记create trigger change_trigger4on收费登记for updateasinsert into 结余登记select inserted.客户号,inserted.月份,inserted.应收费用,inserted.实 收费

12、用,inserted.实收费用-inserted.应收费用from inserted;5. 建立存储存储过程1:应收费用,实收费用create procedure ch_procedure01month dateasbeginselect月份,应收费用,实收费用from收费登记where收费登记.月份=monthendgo存储过程2:未收费create procedure ch_procedure02month dateasbeginselect客户号,月份,结余费用from结余登记where结余登记.月份=monthorder by结余费用endgo6. 表间关系关系田“关孚图.位置呈电力食

13、可收我管理系脱中、-Cloo.l)-六、代码实现过程1. 显示窗体内的内容及表的内容private void Form5_Load(object sender, EventArgs e)stringconsqlserver=DataSource=GXW-PC;InitialCatalog=liqiuyue0;Integrated Security=True;/stringconsqlserver=DataSource=CHEN-PC;InitialCatalog=rl;Integrated Security=True;定义连接数据源string sql = select * from 用电信息

14、;SqlConnection sqlcon = new SqlConnection(consqlserver);sqlcon.Open();SqlDataAdapter da = new SqlDataAdapter(sql, sqlcon);DataSet ds = new DataSet();/shengmingtryda.Fill(ds);if (ds.Tables0.Rows.Count 1)/判断是否有符合条件的数据记录将获得数据源赋予数据库控件dataGridView1.DataSource = ds.Tables0;catch (Exception ex)throw new Ex

15、ception(ex.ToString();finallysqlcon.Close();sqlcon.Dispose();da.Dispose();结果如图所示:0.用电信息客户号类别号月份用电度数客户导000100001000020002OOOC3Q000300003类别号kBCkBCATE顷ACKBCAIEMEIP月份013/9/12013/12/12013/3/32013/10/12013/12/12013/S/102Q13/11/12013/12/1用目LOOLOO400150190120L25105增加修改4T刑除1 2. 插入一行信息的代码private void label3_C

16、lick(object sender, EventArgs e)private void button1_Click(object sender, EventArgs e)string consqlserver = Data Source=GXW-PC;InitialCatalog=liqiuyue0;Integrated Security=True;/ string sql = select * from 客户;SqlConnection sqlcon = new SqlConnection(consqlserver); sqlcon.Open();try/首先判断输入信息是否完全if (t

17、extBox1.Text =)MessageBox.Show(请输入完整的数据信息”,”信息提示”,System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); else DataSet ds = new DataSet();/在此判断保存重复记录问题string strSqls;strSqls = string.Format(SELECT * FROM 用电信息 where 客户号=+ textBox1.Text.Trim() + and 类别号=+ textBox2.Text

18、.Trim() + and 月份=+ textBox3.Text.Trim() + ;);定义SQL Server连接对象SqlDataAdapter da = new SqlDataAdapter(strSqls, sqlcon);da.Fill(ds);if (ds.Tables0.Rows.Count 1)MessageBox.Show(已经存在,信息提示, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);elsestrSqls = insert into 用电信息

19、 values ( + textBox1.Text.Trim() + , + textBox2.Text.Trim() + , + textBox3.Text.Trim() + , + textBox4.Text.Trim() + );定义SQL Server连接对象/SqlConnectionsqlcon1=newSqlConnection(consqlserver);SqlCommand cmd = new SqlCommand(strSqls, sqlcon1);trysqlcon1.Open();cmd.ExecuteNonQuery();catch ( finallysqlcon1.

20、Close();sqlcon1.Dispose();cmd.Dispose();MessageBox.Show(保存成功,信息提示,System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Information);刷新数据string sqls = select * from 用电信息;SqlDataAdapter da1 = new SqlDataAdapter(sqls, sqlcon);da1.Fill(ds);if (ds.Tables0.Rows.Count 1)dataGridVie

21、w1.DataSource = ds.Tables0;catch ( 结果如图所示:噌用电信息客户号00001 类别号睥 月份 013/7/1用电度数330容户号类别号月份用庄增加JOOQ12013/9/11Q000001ABC013/12/1IQCi00001013/7/1330JOOQ1顾2013/3/34Q0_il信改ooooe顾013/10/115000002顾2013/12/1190000032013/8/1012000003ABE|i013/11/1125卜4删除3. 修改一行信息的内容private void button2_Click(object sender, EventA

22、rgs e)string consqlserver = Data Source=GXW-PC;Initial Catalog=liqiuyue0;Integrated Security=True;/ string sql = select * from 客户;SqlConnection sqlcon = new SqlConnection(consqlserver);sqlcon.Open();tryif (textBoxl.Text =)MessageBox.Show(请输入客户号,类别号,月份”,”信 息提示, System.Windows.Forms.MessageBoxButtons.

23、OK, System.Windows.Forms.MessageBoxIcon.Warning);elseDataSet ds = new DataSet();string strSqls = string.Format(SELECT * FROM 用电信息 where 客户号=+ textBox1.Text.Trim() + and 类别号=+ textBox2.Text.Trim() + and 月份=+ textBox3.Text.Trim() + ;);/ string strSqls = string.Format(SELECT * FROM 客户 where 客户号=+ textB

24、ox1.Text.Trim() + );/ string strSqls = string.Format(update teacher set tname= + textBox2.Text.Trim() + where tno= + textBox1.Text.Trim() + );SqlConnection con = new SqlConnection(consqlserver);SqlDataAdapter da = new SqlDataAdapter(strSqls, con);定义SQL Server连接对象da.Fill(ds);int tnum = dataGridViewl.

25、CurrentRow.Index;/ 先选中某 一行string oldDate = dataGridView1Rowstnum,Cells月份 .ValueToString();string oldLeibie = dataGridView1Rowstnum,Cells类另 U 号.Value.ToString();/ strSqls = string.Format(update 客户 set 客户名=+ textBox2.Text.Trim() + where 客户号=+ textBox1.Text.Trim() + update 客户 set 地址=+ textBox3.Text.Tri

26、m() + where 客户号= + textBox1.Text.Trim() + update 客户 set 联系方式=+ textBox4.Text.Trim() + where 客户号=+ textBox1.Text.Trim() + );strSqls = string.Format(update 用电信息 set 类别号=+ textBox2.Text.Trim() + ,月份=+ textBox3.Text.Trim() + ,用 电度数 =+ textBox4.Text.Trim() + where 客户号=+ textBox1.Text.Trim() + and 类别号=+ o

27、ldLeibie + and 月份=+ oldDate + ;);SqlConnection cons = new SqlConnection(consqlserver);SqlCommand cmd = new SqlCommand(strSqls, cons);trycons.Open();cmd.ExecuteNonQuery();catch ( finallycons.Close();cons.Dispose();cmd.Dispose();MessageBox.Show(修改成功,信息提示,System.Windows.Forms.MessageBoxButtons.OK,Syste

28、m.Windows.Forms.MessageBoxIcon.Information);刷新数据string sqls = select * from 用电信息;SqlDataAdapter da1 = new SqlDataAdapter(sqls, con);DataSet dss = new DataSet();da1.Fill(dss);if (dss.Tables0.Rows.Count 1)dataGridView1.DataSource = dss.Tables0;catch ( 运行结果如图所示:(注应该先选中,在修改,目的改主码)5.删除一行信息的内容private void

29、 button3_Click(object sender, EventArgs e)string consqlserver = Data Source=GXW-PC;InitialCatalog=liqiuyue0;Integrated Security=True;SqlConnection sqlcon = new SqlConnection(consqlserver);sqlcon.Open();try if (textBoxl.Text =)MessageBox.Show(请选择或输入要删除的信息,信息 提 示 , System.Windows.Forms.MessageBoxButto

30、ns.OK, System.Windows.Forms.MessageBoxIcon.Warning);elseDataSet ds = new DataSet();判断要删除的数据信息是否存在string strSqls;strSqls = string.Format(SELECT * FROM 用电信息 where 客户号=+ textBox1.Text.Trim() + and 类别号=+ textBox2.Text.Trim() + and 月份=+ textBox3.Text.Trim() + ;);/ strSqls = string.Format(SELECT * FROM 客户

31、 where 客 户号=+ textBox1.Text.Trim() + );定义SQL Server连接对象SqlConnection con = new SqlConnection(consqlserver);SqlDataAdapter da = new SqlDataAdapter(strSqls, con); da.Fill(ds);if (ds.Tables0.Rows.Count 0)if (MessageBox.Show(确认要删除吗?,信息提示, System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Form

32、s.MessageBoxIcon.Question)=System.Windows.Forms.DialogResult.Yes)定义删除数据信息的SQL语句strSqls = string.Format(delete from 用电信息 where 客户号=+ textBox1.Text.Trim() + and 类别号=+ textBox2.Text.Trim() + and 月份=+ textBox3.Text.Trim() + ;);定义SQL Server连接对象SqlConnectioncons=newSqlConnection(consqlserver);SqlCommand c

33、md = new SqlCommand(strSqls, cons);trycons.Open();cmd.ExecuteNonQuery();catch finallycons.Close();cons.Dispose();cmd.Dispose();MessageBox.Show(信息删除成功,信息提示,System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Information);刷新数据string sqls = select * from 用电信息;SqlDataAdapter da

34、1 = new SqlDataAdapter(sqls, con);DataSet dss = new DataSet();da1.Fill(dss);if (dss.Tables0.Rows.Count 0)dataGridView1.DataSource = dss.Tables0;catch 七、运行结果展示: 触发器实现自动修改和计算:呼赛用管理I 口 II回IMI月份矗用2013/12/1100. 0000未收2013/8/15.0000未收2013/8/1060.0000未吸2013/7/1100. 0000未吸2013/8/1400. 0000未吸2013/11/110.0000

35、未吸2013/11/12300. 0QQ0未版米JJk1r每当添加一个新值,收费标志自动改成未收存储过程的实现,实现存储指定日期的应收费用和实收费用叱1电力瞧统基本信息用电信息黑用管理费登记始余登记八、总结与心得体会经过几月的课程设计,还是简单地完成了“某电力公司收费管理 信息系统”题目的相关要求。在设计时创立了表table、存储过程 procedure触发器trigger、规则rule来实现相关的功能和写了、1语 句(create,select等语句)来创立、查询表中的相关信息,这次课 程设计也让我熟悉了使用VS和SQLsever,同时把sql语句强加练习 了一遍,还学会了创立规则和存储过程

36、还有触发器,而且熟悉的 使用了 C#,但也遇到了许多问题,比如:1.由于对C#不熟悉,刚 开始插手很难,后来慢慢熟悉了才掌握了一些编程技巧。2.在修 改主码时,由于查询是根据主码的,因此不好实现,经过查资 料,能够把就的值提取出来并保存在一个字符串里,这样就轻易 解决了,代码如:inttnum=dataGridView1.CurrentRow.Index;先 选中某一行string oldDa=edataGridView1.Rowstnum.Cells月份.Value.ToString();string oldLei=i曲taGridView1.Rowstnum.Cells类别号.Value.

37、ToString()这样就能够修改主码了。3.创立触发器来实现相 关功能时由于自身知识的不够,写的不完整,导致不能级联,经 过重复修改才能实现。4.存储过程实现时由于不会调用,不知道 怎样传参,做了好长时间,最后经过向别人请教才实现了存储过 程。代码如下:comm.Parameters.Add(month, SqlDbType.Date); comm.Parametersmonth.Value = textBox2.Text;但不论怎么说这次课程设计还是收获不少的,这不但是对我们一 个学期以来所学知识内容的综合考验,也是我们回顾知识、牢记 知识、复习知识的一次大好时机,同时也是我们从中看到自己的 不足的一次作业;我觉得我们应该认真对待、虚心学习!

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号