1、 《数据库原理与应用》课程设计 题 目: 影碟出租数据库系统设计与实现 系 别: 数学与信息工程学院 专业(含班级): 09计算机科学与技术(嵌入式) 学 号: 20090861108 姓 名: 游海斌
2、 指导教师: 林克明 职称 副教授 填表日期: 2011 年 12 月 26 日 前 言 一、选题的依据及意义 1. 依据 熟悉C#、SQL程序设计的基本语法知识及常用技巧。 2. 意义 本课程的课程设计实际是学生学习完《数据库系统概论》课程后,进行的一次全面的综合训练,其目的在于加深对编程技术基本知识的理解,掌握运用开发应用程序的基本方法及基本技巧。 二、本课程设计内容 1. 出租、归还碟片信息的统计:会员账号,影碟编号,出租时间,
3、归还时间,租金等 2. 影片信息的查询的统计:影碟编号,名称,类型,国家,主演,单价,购入时间,库存量。 3.营业员和会员资料的查询的统计:营业员账号,会员账号, 密码,姓名,办理时间,剩余可租碟数,工作时间。 4.营业员、会员及碟片的添加或删除。 三、研究目标 1. 碟片出租系统是一个面向碟片出租者的管理信息系统。有会员(租借者),营业员,店长三方组成。该系统的工作目标就是要碟片的出租能有计划地进行,以利于出租者管理。 2. 本系统开发将综合采用结构化系统开发方法和面向对象开发方法,充分发挥两种开发方法的优势。 实 现 方 案 一、开发平台选择 1. SQL
4、 Server 2000 2. C# 二、需求分析 在对世面上的影碟出租公司进行了初步的了解后,发现其业务主要是集中在影碟的管理和录像的出租归还上。对影碟的管理工作量较大,采用手工的方式还容易出错,并且不能满足顾客对影碟的详细信息的查询功能。在现有的影碟出租中对会员的管理也很重要,传统的登记方式不仅费时而且不能对其出租日志进行系统的管理,造成了不必要的经济损失。综上说述,在影碟出租数据库设计中应考虑和克服了上诉的诸多问题,增强了实用性。 2.1数据需求 影片信息数据:录像ID、片名、导演、主演、类型、介绍、上映时间。 录像信息数据:录像ID、格式、语言、进货时间、状态、库存数量。
5、 租借记录数据:记录ID、租借时间。 租借项记录数据:记录项ID、租借数量、归还时间、租金。 租金信息数据:租借类型、租借天数、每日金额。 会员信息数据:会员ID、会员姓名、会员性别、身份证ID、电话、地址。 2.2功能需求 会员信息管理部分:可以查询会员资料、可以对会员进行增删。 影片信息管理部分:可以查询影片本身的信息、可以对影片信息实行增删。 租借信息管理部分:可以查询影片的租借状态。 租金信息管理部分:可以查询各类影片的租金情况、会员应付的租金情况。 数据流图: 2.业务流程图:
6、 图1:影碟出租管理系统业务流程图 三、概要结构设计 图2:影碟出租管理系统E-R图 四、逻辑结构设计: 1.选课系统关系模式: (1)店长(店长账号,密码,姓名); (2)营业员(营业员账号,密码,姓名,性别,工作时间,店长账号); (3)会员(会员帐号,密码,姓名,办理时间,剩余可租碟数,营业员账号); (4)影碟查询(影碟编号,名称,类型,国家,主演,单价,购入时间,库存量) (5)影碟出租、归还(影碟编号,出租时间,营业员账号,会员账号) 2. 数据库关系图: 图3:影碟出租管理系统关系图 五、功能模块设计 影碟出租管理系统
7、 营 业 员 租 借 查 询 登 陆 添 加 店 长 修 改 密 码 退 出 出 租 影 碟 返 还 影 碟 影 碟 查 询 会 员 查 询 退 碟 查 询 新 营 业 员 新 入 会 员 影 碟 类 别 会 员 级 别 营 业 员 图4:影碟出租管理系统功能模块图 六、主界面设计 1.登录界面: 图4:影碟出租管理系统登陆页面 2. 主界面: 图4:影
8、碟出租管理系统主页面 图5:会员管理主页面 八、主要功能的源代码 1.连接数据库 string connstr = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=影碟出租管理系统;Data Source=PC-20100331FOMN"; string selectcmd = "select * from 影碟信息 where 影碟编号='" + 影碟编号.Text + "'"; //建立选择查询 strin
9、g insertcmd = "insert into 影碟信息 values('" + 影碟编号.Text + "','" + 名称.Text + "','" + 类型.Text + "','" + 国家.Text + "','" + 主演.Text + "','"+单价.Text+"','"+购入时间.Text+"','"+库存量.Text+"')";//建立插入查询 SqlConnection conn = new SqlConnection(connstr); //建立数据库连接 conn.Op
10、en(); SqlCommand cmd1 = new SqlCommand(selectcmd, conn); //建立数据库命令 SqlDataReader reader = cmd1.ExecuteReader(); 2.查询 3.增加 private void 添加_Click(object sender, EventArgs e) { 账号.Focus(); if (账号.Text != "" && 密码.Text != ""
11、 姓名.Text != "" && 剩余可租碟数.Text != "" && 营业员账号.Text != "") //*项上不能为空 { string connstr = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=影碟出租管理系统;Data Source=PC-20100331FOMN"; string selectcmd = "select * from 会员 where 会员账号='" + 账号
12、Text + "'"; //建立选择查询 string insertcmd = "insert into 会员 values('" + 账号.Text + "','" + 密码.Text + "','" + 姓名.Text + "','" + 办理时间.Text + "','" + 剩余可租碟数.Text + "','" + 营业员账号.Text + "')";//建立插入查询 SqlConnection conn = new SqlConnection(connstr); //建立数据库连接
13、 conn.Open(); SqlCommand cmd1 = new SqlCommand(selectcmd, conn); //建立数据库命令 SqlDataReader reader = cmd1.ExecuteReader(); if (!reader.Read()) //读取数据 { reader.Close();
14、 SqlCommand cmd = new SqlCommand(insertcmd, conn); //建立新的数据库命令 try { cmd.ExecuteNonQuery(); //执行操作命令 MessageBox.Show("添加成功!"); 账号.Text = "";
15、 密码.Text = ""; 姓名.Text = ""; 办理时间.Text = ""; 剩余可租碟数.Text = ""; 营业员账号.Text = ""; } catch (Exception ex) { Message
16、Box.Show("添加出错!错误原因为:\n" + ex.Message + "\n"); } } else //账号已存在 { reader.Close(); MessageBox.Show("对不起,此账号已经被使用,请更改账号!", "会员账号检验!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
17、 //用户名已 账号.Text = ""; } conn.Close(); } else MessageBox.Show("带*项不能为空!", "会员账号核查", MessageBoxButtons.OK, MessageBoxIcon.Warning); } string updatecmd, updatecmd1, updatecmd2, updatec
18、md3, updatecmd4; private void 修改_Click(object sender, EventArgs e) { 账号.Focus(); if (账号.Text != "") //*项上不能为空 { string connstr = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=影碟出租管理系统;Data Source=PC-
19、20100331FOMN"; string selectcmd = "select * from 会员 where 会员账号='" + 账号.Text + "'"; //建立选择查询 if (密码.Text != "") { updatecmd = "update 会员 set 密码='" + 密码.Text + "' where 会员账号='" + 账号.Text + "'"; } if (姓名.Text != "")
20、 { updatecmd1 = "update 会员 set 姓名='" + 姓名.Text + "' where 会员账号='" + 账号.Text + "'"; } if (办理时间.Text != "") { updatecmd2 = "update 会员 set 办理时间='" + 办理时间.Text + "' where 会员账号='" + 账号.Text + "'"; } if (剩余可租碟数.Text != "") { updatec
21、md3 = "update 会员 set 剩余可租碟数='" + 剩余可租碟数.Text + "' where 会员账号='" + 账号.Text + "'"; } if (营业员账号.Text != "") { updatecmd4 = "update 会员 set 营业员账号='" + 营业员账号.Text + "' where 会员账号='" + 账号.Text + "'"; } //建立更新查询 SqlConnection conn = n
22、ew SqlConnection(connstr); //建立数据库连接 conn.Open(); SqlCommand cmd = new SqlCommand(selectcmd, conn); //建立数据库命令 SqlDataReader reader = cmd.ExecuteReader(); if (reader.Read()) //读取数据 {
23、 reader.Close(); try { if (密码.Text != "") { SqlCommand cmd1 = new SqlCommand(updatecmd, conn); //建立新的数据库命令 cmd1.ExecuteNonQuery();
24、 } if (姓名.Text != "") { SqlCommand cmd2 = new SqlCommand(updatecmd1, conn); //建立新的数据库命令 cmd2.ExecuteNonQuery(); } if
25、办理时间.Text != "") { SqlCommand cmd3 = new SqlCommand(updatecmd2, conn); //建立新的数据库命令 cmd3.ExecuteNonQuery(); } if (剩余可租碟数.Text != "") {
26、 SqlCommand cmd4 = new SqlCommand(updatecmd3, conn); //建立新的数据库命令 cmd4.ExecuteNonQuery(); } if (营业员账号.Text != "") { SqlCommand cmd5 = new Sql
27、Command(updatecmd4, conn); //建立新的数据库命令 cmd5.ExecuteNonQuery(); } MessageBox.Show("修改成功!"); 账号.Text = ""; 密码.Text = ""; 姓名.Text = "";
28、 办理时间.Text = ""; 剩余可租碟数.Text = ""; 营业员账号.Text = ""; } catch (Exception ex) { MessageBox.Show("修改出错!错误原因为:\n" + ex.Message + "\n");
29、 账号.Text = ""; 密码.Text = ""; 姓名.Text = ""; 办理时间.Text = ""; 剩余可租碟数.Text = ""; 营业员账号.Text = ""; } } else //
30、影碟编号已存在 { reader.Close(); MessageBox.Show("对不起,无此会员,请更改会员编号!", "会员账号检验!", MessageBoxButtons.OK, MessageBoxIcon.Warning); //用户名已 账号.Text = ""; } conn.Close(); } }
31、 private void 删除_Click(object sender, EventArgs e) { string connstr = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=影碟出租管理系统;Data Source=PC-20100331FOMN"; SqlConnection conn = new SqlConnection(connstr); conn.Open();
32、 string select = "select * from 出租关系 where 会员账号='" + 账号.Text + "'"; SqlCommand cmd1 = new SqlCommand(select, conn); SqlDataReader reader1 = cmd1.ExecuteReader(); if (!reader1.Read()) { string selectcmd = "select * from 会员
33、 where 会员账号='" + 账号.Text + "'"; SqlCommand cmd = new SqlCommand(selectcmd, conn); SqlDataReader reader = cmd.ExecuteReader(); if (!reader.Read()) MessageBox.Show("不存在此会员!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
34、 else { reader.Close(); DialogResult result = MessageBox.Show("确实要删除此会员吗?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) {
35、 string delstr = "delete from 会员 where 会员账号='" + 账号.Text + "'"; cmd = new SqlCommand(delstr, conn); cmd.ExecuteNonQuery(); MessageBox.Show("已成功删除了此会员!"); 账号.Text = ""; }
36、 } } else { MessageBox.Show("此会员有影碟未归还,不能删除!", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } private void 查询_Click(object sender, EventArgs e) { string source = "Integr
37、ated Security=SSPI;Persist Security Info=False;Initial Catalog=影碟出租管理系统;Data Source=PC-20100331FOMN"; string select = "select * from 会员 where 会员账号='" + 账号.Text + "'"; string select1 = "select * from 会员 where 姓名='" + 姓名.Text + "'"; string select2 = "select * fro
38、m 会员 where 营业员账号='" + 营业员账号.Text + "'"; SqlConnection conn = new SqlConnection(source); conn.Open(); SqlDataAdapter adapter = new SqlDataAdapter(select, conn); SqlDataAdapter adapter1 = new SqlDataAdapter(select1, conn); SqlDataAdapter
39、 adapter2 = new SqlDataAdapter(select2, conn); DataSet ds = new DataSet(); if (账号.Text != "") { if (会员信息.Columns.Count > 0) { 会员信息.Columns.Clear(); } adapter.Fill(ds, "会员")
40、 DataTableReader dtr = ds.CreateDataReader(); if (dtr.Read()) { 会员信息.DataSource = ds.Tables["会员"]; 账号.Text = ""; 密码.Text = ""; 姓名.Text = ""; 办理
41、时间.Text = ""; 剩余可租碟数.Text = ""; 营业员账号.Text = ""; } else { dtr.Close(); MessageBox.Show("不存在此会员,请重新输入会员账号!"); 账号.Text = "";
42、密码.Text = ""; 姓名.Text = ""; 办理时间.Text = ""; 剩余可租碟数.Text = ""; 营业员账号.Text = ""; } } else if (姓名.Text != "") { if (会员信息.Columns.Count > 0)
43、 { 会员信息.Columns.Clear(); } adapter1.Fill(ds, "会员"); DataTableReader dtr = ds.CreateDataReader(); if (dtr.Read()) { 会员信息.DataSource = ds.Tables["会员"];
44、 账号.Text = ""; 密码.Text = ""; 姓名.Text = ""; 办理时间.Text = ""; 剩余可租碟数.Text = ""; 营业员账号.Text = ""; } else { MessageBox.S
45、how("不存在此会员,请重新输入会员账号!"); 账号.Text = ""; 密码.Text = ""; 姓名.Text = ""; 办理时间.Text = ""; 剩余可租碟数.Text = ""; 营业员账号.Text = ""; } } else if
46、营业员账号.Text!="") { if (会员信息.Columns.Count > 0) { 会员信息.Columns.Clear(); } adapter2.Fill(ds, "会员"); DataTableReader dtr = ds.CreateDataReader(); if (dtr.Read())
47、 { 会员信息.DataSource = ds.Tables["会员"]; 账号.Text = ""; 密码.Text = ""; 姓名.Text = ""; 办理时间.Text = ""; 剩余可租碟数.Text = ""; 营业员账号.Text = "";
48、 } else { MessageBox.Show("不存在此会员,请重新输入会员账号!"); 账号.Text = ""; 密码.Text = ""; 姓名.Text = ""; 办理时间.Text = ""; 剩余可租碟数.Text = "";
49、 营业员账号.Text = ""; } } else { MessageBox.Show("请输入会员账号!"); 账号.Text = ""; } conn.Close(); } private void 浏览_Click(object sender, EventArgs e) {
50、 if (会员信息.Columns.Count > 0) { 会员信息.Columns.Clear(); } string source = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=影碟出租管理系统;Data Source=PC-20100331FOMN"; string select = "select 会员账号,姓名,办理时间,剩余可租碟数






