数据库课程设计某电力公司收费系统方案.doc

上传人:李司机 文档编号:1087386 上传时间:2022-06-20 格式:DOC 页数:17 大小:274KB
返回 下载 相关 举报
数据库课程设计某电力公司收费系统方案.doc_第1页
第1页 / 共17页
数据库课程设计某电力公司收费系统方案.doc_第2页
第2页 / 共17页
数据库课程设计某电力公司收费系统方案.doc_第3页
第3页 / 共17页
数据库课程设计某电力公司收费系统方案.doc_第4页
第4页 / 共17页
数据库课程设计某电力公司收费系统方案.doc_第5页
第5页 / 共17页
点击查看更多>>
资源描述

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

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

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

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

4、、费用、收费标志) 收费登记(客户号、月份、应收费用、实收费用、员工号) 结余登记(客户号、月份、应收费用、实收费用、结余费用)2、根据关系模型绘制出E-R模型为: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,王五,崂山区,

5、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,政府,2.00);Insert

6、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 into 员工 values(12347

7、,悦,女,1230003);4.用电信息表Create table 用电信息(客户号 char(5) ,类别号 char(10) ,月份 date ,用电度数 char(8),primary key (客户号,类别号,月份),foreign key (客户号) references 客户(客户号),foreign key (类别号) references 用电类型(类别号);Insert into 用电信息 values(00001,ABC,2013-12-01,100);Insert into 用电信息 values(00001,ABE,2013-12-01,220);Insert into

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

9、e 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

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

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

12、inserted.月份,inserted.应收费用,inserted.实收费用,inserted.实收费用-inserted.应收费用from inserted;5.建立存储存储过程1:应收费用,实收费用create procedure ch_procedure01month date asbeginselect 月份,应收费用,实收费用 from 收费登记where 收费登记.月份=monthendgo存储过程2:未收费create procedure ch_procedure02month date asbeginselect 客户号,月份,结余费用 from 结余登记where 结余登记

13、.月份=monthorder by 结余费用endgo6.表间关系六、代码实现过程1.显示窗体的容与表的容private void Form5_Load(object sender, EventArgs e) string consqlserver = Data Source=GXW-PC;Initial Catalog=liqiuyue0;Integrated Security=True; /string consqlserver = Data Source=CHEN-PC;Initial Catalog=rl;Integrated Security=True; /定义连接数据源 strin

14、g sql = select * from 用电信息 ; SqlConnection sqlcon = new SqlConnection(consqlserver); sqlcon.Open(); SqlDataAdapter da = new SqlDataAdapter(sql, sqlcon); DataSet ds = new DataSet();/shengming try da.Fill(ds); if (ds.Tables0.Rows.Count 1) /判断是否有符合条件的数据记录 /将获得数据源赋予数据库控件 dataGridView1.DataSource = ds.Ta

15、bles0; catch (Exception ex) throw new Exception(ex.ToString(); finally sqlcon.Close(); sqlcon.Dispose(); da.Dispose(); 结果如下图:2.插入一行信息的代码 private void label3_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e) string consqlserver = Data Source=GXW-PC;Initial Catal

16、og=liqiuyue0;Integrated Security=True; / string sql = select * from 客户 ; SqlConnection sqlcon = new SqlConnection(consqlserver); sqlcon.Open(); try / 首先判断输入信息是否完全 if (textBox1.Text = ) MessageBox.Show(请输入完整的数据信息, 信息提示, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Wa

17、rning); else DataSet ds = new DataSet(); / 在此判断保存重复记录问题 string strSqls; strSqls = string.Format(SELECT * FROM 用电信息 where 客户号= + textBox1.Text.Trim() + and 类别号= + textBox2.Text.Trim() + and 月份= + textBox3.Text.Trim() + ;); /定义SQL Server连接对象 SqlDataAdapter da = new SqlDataAdapter(strSqls, sqlcon); da.

18、Fill(ds); if (ds.Tables0.Rows.Count 1) MessageBox.Show(已经存在, 信息提示, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); else strSqls = insert into 用电信息 values ( + textBox1.Text.Trim() + , + textBox2.Text.Trim() + , + textBox3.Text.Trim() + , + textBox4.Text.Trim() +

19、 ); /定义SQL Server连接对象 / SqlConnection sqlcon1 = new SqlConnection(consqlserver); SqlCommand cmd = new SqlCommand(strSqls, sqlcon1); try sqlcon1.Open(); cmd.ExecuteNonQuery(); catch finally sqlcon1.Close(); sqlcon1.Dispose(); cmd.Dispose(); MessageBox.Show(保存成功, 信息提示, System.Windows.Forms.MessageBoxB

20、uttons.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) dataGridView1.DataSource = ds.Tables0; catch 结果如下图:3.修改一行信息的容 private void button2_Click(object send

21、er, EventArgs e) string consqlserver = Data Source=GXW-PC;Initial Catalog=liqiuyue0;Integrated Security=True; / string sql = select * from 客户 ; SqlConnection sqlcon = new SqlConnection(consqlserver); sqlcon.Open(); try if (textBox1.Text = ) MessageBox.Show(请输入客户号,类别号,月份, 信息提示, System.Windows.Forms.M

22、essageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning); else DataSet 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 * F

23、ROM 客户 where 客户号= + textBox1.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.Fil

24、l(ds); int tnum = dataGridView1.CurrentRow.Index;/先选中某一行 string oldDate = dataGridView1.Rowstnum.Cells月份.Value.ToString(); string oldLeibie = dataGridView1.Rowstnum.Cells类别号.Value.ToString(); / strSqls = string.Format(update 客户 set 客户名= + textBox2.Text.Trim() + where 客户号= + textBox1.Text.Trim() + up

25、date 客户 set 地址= + textBox3.Text.Trim() + 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 客

26、户号= + textBox1.Text.Trim() + and 类别号= + oldLeibie + and 月份= + oldDate + ;); SqlConnection cons = new SqlConnection(consqlserver); SqlCommand cmd = new SqlCommand(strSqls, cons); try cons.Open(); cmd.ExecuteNonQuery(); catch finally cons.Close(); cons.Dispose(); cmd.Dispose(); MessageBox.Show(修改成功, 信

27、息提示, System.Windows.Forms.MessageBoxButtons.OK, System.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.Table

28、s0; catch 运行结果如下图:(注应该先选中,在修改,目的改主码)5. 删除一行信息的容 private void button3_Click(object sender, EventArgs e) string consqlserver = Data Source=GXW-PC;Initial Catalog=liqiuyue0;Integrated Security=True; SqlConnection sqlcon = new SqlConnection(consqlserver); sqlcon.Open(); try if (textBox1.Text = ) Message

29、Box.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.Trim() + and

30、 月份= + textBox3.Text.Trim() + ;); / strSqls = string.Format(SELECT * FROM 客户 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.Sh

31、ow(确认要删除吗?, 信息提示, System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) = System.Windows.Forms.DialogResult.Yes) /定义删除数据信息的SQL语句 strSqls = string.Format(delete from 用电信息 where 客户号= + textBox1.Text.Trim() + and 类别号= + textBox2.Text.Trim() + and 月份= + textBox3.Tex

32、t.Trim() + ;); /定义SQL Server连接对象 SqlConnection cons = new SqlConnection(consqlserver); SqlCommand cmd = new SqlCommand(strSqls, cons); try cons.Open(); cmd.ExecuteNonQuery(); catch finally cons.Close(); cons.Dispose(); cmd.Dispose(); MessageBox.Show(信息删除成功, 信息提示, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information); /刷新数据 string sqls = select * from 用电信息 ; SqlDataAdapter da1 = new SqlDataAdapter(sqls, con); DataSet dss = new DataSet();

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

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


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号