数据库课程设计快餐网售系统.docx
《数据库课程设计快餐网售系统.docx》由会员分享,可在线阅读,更多相关《数据库课程设计快餐网售系统.docx(18页珍藏版)》请在冰豆网上搜索。
![数据库课程设计快餐网售系统.docx](https://file1.bdocx.com/fileroot1/2022-12/15/f874e3d4-daa8-4d52-8a59-94c28849dc08/f874e3d4-daa8-4d52-8a59-94c28849dc081.gif)
数据库课程设计快餐网售系统
课
程
设
计
班级:
2009级
姓名:
孙超
学号:
2009010423
系别:
经济管理系
日期:
2011/12/19
快餐网售课程设计
一、设计需求:
本设计为快餐网售,可以在网上选购自己喜欢的快餐,通过这个系统可以随时订餐,送餐上门。
快餐网购的功能要求:
●用户登录、注销、用户注册
●查询所需的快餐。
●订购所需快餐
●结算订购快餐的款项
●选择方便的方式进行快餐的价钱的支付
●到相应的网站进行支付
二、设计的目的:
为在校学生提供方便的送货上门的快餐服务,以便学生拥有更健康的身体及更有效地学习。
三、快餐网售的模块:
通过登陆界面登录.aspx验证正确的用户名和密码后进入主界面快餐主页.aspx。
若没有用户名和密码,则先跳到注册界面注册.aspx进行注册(注册内容包括:
客户名、密码、编号)。
在主页面上包含:
1.快餐买卖快餐主页.aspx
2.快速下订单输入快餐.aspx
3.支付支付页面.aspx
4.请结算结算.aspx
以上模块共同构成整个系统。
四、网站的内容:
首先是硬盘的功能流程图:
快餐网购系统运行
系统功能流程图
五、数据库的设计:
1.需求分析
通过对大学生日常生活进行的可行性分析和详细调查,确定开发快餐网购管理系统。
开发小组的成员经过调查研究、信息流程分析和数据收集,明确了该系统的主要功能;用户登录、注销、用户注册、查询所需的快餐、订购所需快餐、结算订购快餐的款项、选择方便的方式进行快餐的价钱的支付、到相应的网站进行支付,并提供简单的查询功能。
2.概念结构设计
由于系统不太复杂,设计E-R图可以直接从系统的数据流下手。
参照需求分析中对业务数据流程的描述,对每个试题及属性进行如下定义:
订单表(订单编号、客户编号、商品编号、订单时间)
客户表(客户编号、姓名、密码、已购数量)
商品表(商品编号、商品名称、数量、保质期、下架时间、价钱)
系统的E-R图如图所示:
图2E-R图
3.逻辑结构设计
根据概念结构设计的结果,设计出“快餐网售管理系统”数据库的逻辑关系模型。
将图2的E-R图转换为关系模型,关系的主码用下划线划出:
订单表(订单编号、客户编号、商品编号、订单时间)
客户(客户编号、姓名、密码、已购数量)
商品表(商品编号、商品名称、数量、保质期、下架时间、价钱)
4.物理设计结构设计
将逻辑结构设计的关系模型转换为物理数据库,及具体的RDBMS中支持的关系数据模型-表。
在SQLServer2005数据库管理系统中创建订单表、客户、商品表、订单1和订单2。
表的结构如表1-表5所示。
1.名称:
订单表,如表-1所示
订单表包括订单编号、客户编号、商品编号和订单时间。
表-1
字段名称
类型
主键
非空
订单编号
自动生成
Yes
Yes
客户编号
文本
No
Yes
商品编号
文本
No
Yes
订单时间
文本
No
Yes
2.名称:
商品表,如表1-2所示
商品表包括商品编号、商品名称、数量、保质期、下架时间和价钱。
表-2
字段名称
类型
主键
非空
商品编号
自动编号
Yes
Yes
商品名称
文本
No
Yes
数量
文本
No
Yes
保质期
文本
No
Yes
下架时间
文本
No
Yes
价钱
文本
No
Yes
3.名称:
客户表,如表1-3所示
客户表包括:
姓名、密码、客户编号、已购数量e。
表-3
字段名称
类型
主键
非空
客户编号
自动编号
Yes
Yes
姓名
文本
No
Yes
密码
文本
No
Yes
已购数量
文本
No
Yes
5.数据库实施、数据库运行及维护
在SQLServer2005中创建表成功后,向表中添加数据,将各种表的记录添加到各个表中。
六、系统设计
前台设计:
1.创建项目
首先启动MicrosoftVisualStudio2005,进入.NET的IDE界面,创建一个新的项目,选择菜单“文件”→“新建”→“网站”。
在打开的“新建网站”对话框中,选择建立ASP.NET网站,设置网站文件所在文件系统的位置,并指定开发语言为VisualC#。
网站建立成功后,在网站项目下可以看到Default.aspx页面,该页面为网站的第一个网页,登录页面生成。
2.设计登录页面
publicpartialclass_Default:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidLinkButton1_Click(objectsender,EventArgse)
{
this.Response.Redirect(“注册”.aspx");
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
SqlConnectionmyConnection=newSqlConnection("DataSource=;IntegratedSecurity=SSPI;InitialCatalog=用户信息");
stringmySQL="select*from客¨户where姓名='"+TextBox1.Text+"'and密码='"+TextBox2.Text+"'";
try
{
myConnection.Open();
SqlCommandmyComm=newSqlCommand(mySQL,myConnection);
SqlDataReaderdr=myComm.ExecuteReader();
if(dr.Read())
{
this.Response.Redirect("快餐主页.aspx");
}
else
{
this.Response.Write("alert('登录失败')");
}
}
catch(Exception)
{
this.Response.Write("alert('异常)");
}
finally
{
myConnection.Close();
}
Application["ww"]=this.TextBox1.Text;
}
protectedvoidLinkButton2_Click(objectsender,EventArgse)
{
this.Response.Redirect("快餐主页.aspx");
}
}
2.2注册页面
publicpartialclassDefault2:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
}
protectedvoidButton1_Click(objectsender,EventArgse)
{SqlConnectionmyConnection=newSqlConnection("DataSource=;IntegratedSecurity=SSPI;InitialCatalog=用户信息");
stringmySQL="insertinto客户(姓名,密码,客户编号)values('"+this.TextBox1.Text+"','"+this.TextBox2.Text+"','"+this.TextBox3.Text+"')";
try
{myConnection.Open();
SqlCommandcmd=newSqlCommand(mySQL,myConnection);
cmd.ExecuteNonQuery();
this.Response.Write("alert('注册成功|!
')");
}
catch(Exception)
{this.Response.Write("alert('注册失败!
')");
}
Finally
{myConnection.Close();
}
}
protectedvoidButton2_Click(objectsender,EventArgse)
{this.Response.Redirect("登录.aspx");}
protectedvoidTextBox1_TextChanged(objectsender,EventArgse){
}
}
protectedvoidButton3_Click(objectsender,EventArgse)
{
SqlConnectionmyConnection=newSqlConnection("DataSource=;IntegratedSecurity=SSPI;InitialCatalog=用户信息");
stringmySQL="execute级联删除'"+TextBox3.Text+"'";
myConnection.Open();
SqlCommandmyComm=newSqlCommand(mySQL,myConnection);
SqlDataReaderdr=myComm.ExecuteReader();
this.Response.Write("alert('删除成功')");
myConnection.Close();
}
}
3.设计快餐网售的主页面
publicpartialclassDefault7:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
this.Label10.Text=Convert.ToString(Application["ww"]);
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
stringmyConnStr="DataSource=;IntegratedSecurity=SSPI;InitialCatalog=用户信息";
SqlConnectionmyConn=newSqlConnection(myConnStr);
stringsql="select*from商品表where商品编号like'%"+this.TextBox1.Text+"%'and"+"商品名称like'%"+this.TextBox2.Text+"%'";
SqlCommandmyComm=newSqlCommand(sql,myConn);
myConn.Open();
SqlDataReadermyReader=myComm.ExecuteReader();
DataTabledt=newDataTable();
dt.Columns.Add(newDataColumn("商品编号",typeof(string)));
dt.Columns.Add(newDataColumn("商品名称",typeof(string)));
dt.Columns.Add(newDataColumn("数量",typeof(string)));
dt.Columns.Add(newDataColumn("保质期",typeof(string)));
dt.Columns.Add(newDataColumn("下架时间",typeof(string)));
dt.Columns.Add(newDataColumn("价钱",typeof(string)));
while(myReader.Read())
{
DataRowdr=dt.NewRow();
dr[0]=myReader.GetValue(0).ToString();
dr[1]=myReader.GetValue(0).ToString();
dr[2]=myReader.GetValue(0).ToString();
dr[3]=myReader.GetValue(0).ToString();
dr[4]=myReader.GetValue(0).ToString();
dr[5]=myReader.GetValue(0).ToString();
dt.Rows.Add(dr);
}
myConn.Close();
this.GridView1.DataSource=newDataView(dt);
this.GridView1.DataBind();
}
protectedvoidLinkButton1_Click(objectsender,EventArgse)
{
this.Response.Redirect("订单输入.aspx");
}
}
4.设计下订单的页面
publicpartialclassDefault6:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
stringmyConnStr="DataSource=;IntegratedSecurity=SSPI;InitialCatalog=用户信息";
SqlConnectionmyConn=newSqlConnection(myConnStr);
stringsql="selectmax(订单编号)from订单表";
SqlCommandmyComm=newSqlCommand(sql,myConn);
myConn.Open();
//intmaxNum=Convert.ToInt32(myComm.ExecuteScalar())+1;
//this.TextBox1.Text=maxNum.ToString();
sql="select商品编号from商品表";
myComm=newSqlCommand(sql,myConn);
SqlDataReadermyReader=myComm.ExecuteReader();
while(myReader.Read())
this.DropDownList1.Items.Add(myReader.GetValue(0).ToString());
myReader.Close();
sql="select客户编号from客户";
myComm=newSqlCommand(sql,myConn);
myReader=myComm.ExecuteReader();
while(myReader.Read())
this.DropDownList2.Items.Add(myReader.GetValue(0).ToString());
myConn.Close();
}
protectedvoidButton1_Click(objectsender,EventArgse)
{
stringmyConnStr="DataSource=;IntegratedSecurity=SSPI;InitialCatalog=用户信息";
SqlConnectionmyConn=newSqlConnection(myConnStr);
stringsql="insertinto订单表(订单编号,商品编号,客户编号,订单时间)values('"+this.TextBox1.Text+"','"+this.DropDownList1.Text+"','"+this.DropDownList2.Text+"','"+this.TextBox4.Text+"');";
SqlCommandmyComm=newSqlCommand(sql,myConn);
myConn.Open();
myComm.ExecuteNonQuery();
myConn.Close();
this.Response.Write("alert('订单成功!
')");
Application["ww"]=this.DropDownList1.Text;
Application["aa"]=this.TextBox5.Text;
}
protectedvoidLinkButton1_Click(objectsender,EventArgse)
{
this.Response.Redirect("商品查询.aspx");
}
protectedvoidLinkButton2_Click(objectsender,EventArgse)
{
this.Response.Redirect("支付页面.aspx");
}
}
5.设计支付的页面
publicpartialclass_Default:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
this.TextBox3.Text=Convert.ToString(Application["ww"]);
this.TextBox2.Text=Convert.ToString(Application["aa"]);
}
protectedvoidLinkButton1_Click(objectsender,EventArgse)
{
this.Response.Redirect("结算.aspx");
}
protectedvoidButton1_Click1(objectsender,EventArgse)
{
SqlConnectionmyConnection=newSqlConnection("DataSource=;IntegratedSecurity=SSPI;InitialCatalog=用户信息");
stringmySql="select价钱from商品表where商品编号='"+this.TextBox3.Text+"'";
try
{
myConnection.Open();//调用对象的Open()方法,打开数据库连接
SqlCommandmycomm=newSqlCommand(mySql,myConnection);
stringcount=Convert.ToString(mycomm.ExecuteScalar());
//DataSetds=newDataSet();
//myDataAdapter.Fill(ds,"价钱");
this.Label9.Text=count;
}
catch(Exception)
{
this.Response.Write("存在异常");//处理异常
}
finally
{
myConnection.Close();
this.Response.Write("关闭数据库连接成功");
}
Application["ee"]=this.Label9.Text;
}
}
6设计结算的页面
publicpartialclass_Default:
System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
TextBox1.Text=Convert.ToString(Application["ee"]);
//inti=int.Parse(TextBox1.Text)+int.Parse(TextBox2.Text);
//Label4.Text=i.ToString();
Label4.Text=Convert.ToString(TextBox1.Text)+Convert.ToString(TextBox2.Text);
}
protectedvoidLinkButton1_Click(objectsender,EventArgse)
{
this.Response.Redirect("
}
}
2.后台设计
namespaceWindowsFormsApplication1
{
publicpartialclassForm2:
Form
{
SqlConnectionmyConnection=newSqlConnection("DataSource=;IntegratedSecurity=SSPI;InitialCatalog=用户信息");
publicForm2()
{
InitializeComponent();
}
privatevoidlabel1_Click(objectsender,EventArgse)
{
}
privatevoidbutton1_Click(objectsender,EventArgse)
{
stringmySQL="select*from订单表";
try
{
myConnection.Ope