数据库课程设计小型电子商务数据管理系统Word文档格式.docx
《数据库课程设计小型电子商务数据管理系统Word文档格式.docx》由会员分享,可在线阅读,更多相关《数据库课程设计小型电子商务数据管理系统Word文档格式.docx(22页珍藏版)》请在冰豆网上搜索。
客户(客户代码、姓名、密码、地址、电子邮件、邮编、联系电话)
发货(订单号、发货方式、发货日期)外键:
订单号
订购(订单号、图书编号、数量、总价)外键:
订单号,图书编号
(3)数据库表结构设计
根据上述关系模式集和实际情况,设计数据库物理结构如下所述
表2.1类别表(Type)
字段名
类型
长度
说明
Tno
Char
2
类别号,主键,索引
Tname
varchar
20
类别名,非空,索引
表2.2出版商表(pblisher)
pbsno
8
出版商代号,主键,索引
pbsname
40
出版商名称,非空
pbsadd
地址,非空
pbsphone
电话,非空
pbspostcode
10
邮编,非空
pbscontact
联系人,非空
表2.3图书表(pblisher)
bno
4
图书编号,主键,索引
bname
100
图书名称,非空,索引
类别号,外键,非空
page
int
页数,非空,大于0
price
Money
单价,非空,大于等于0
quantity
数量,非空,大于等于0
char
出版商代号,外键,非空
edition
版次,非空
first_author
第一作者,非空
date_of_publish
date
出版日期,非空
description
1000
内容简介,非空
表2.4客户表(client)
Cno
客户代码,主键,索引
Cname
姓名,非空
Cpass
16
密码,非空
Cadd
Cmail
电子邮件,非空
Cpostcode
Cphone
联系电话,非空
表2.5订单表(border)
Ono
订单号,主键,索引
客户代码,外键,非空
图书编号,外键,非空
int
数量,非空
money
总价,非空
paytype
varchar
10
付款方式,非空,('
货到付款'
'
网上支付'
)
Cstatus
付款标志,非空,('
未付款'
已付款'
表2.6发货表(bsend)
订单号,主键,外键,索引
Stype
varhar
发货方式,非空,('
中通'
圆通'
Sdate
datetime
发货日期
第2章方案实现过程之客户端
(1)系统客户登陆窗口的设计过程
用户登录窗体主要功能有三:
用户注册、用户登录、以及管理员入口。
在设计时,利用VS的C#开发环境,增加多个label和button、textbox控件。
效果图如下
源代码
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Data.SqlClient;
namespace数据库
{
publicpartialclass用户登录:
Form
{
public用户登录()
InitializeComponent();
}
privatevoidbutton3_Click(objectsender,EventArgse)
登陆lvFrm=new登陆();
lvFrm.Show();
Hide();
SqlConnectionconn;
publicstaticstringuserID;
publicstaticstringuserpsd;
privatevoidbtnLogin_Click(objectsender,EventArgse)
conn=newSqlConnection("
DataSource=(local);
InitialCatalog=bookstore;
IntegratedSecurity=True"
);
conn.Open();
//打开数据库
SqlCommandcmd=newSqlCommand();
stringstrsql="
select*fromCustomerwhereCno="
+txtUserName.Text
+"
andCpass="
+txtUserPwd.Text;
cmd=newSqlCommand(strsql,conn);
SqlDataReaderrd=cmd.ExecuteReader();
if(rd.HasRows)
/*BuylvFrm=newBuy();
*/
用户购买frm2=new用户购买();
inta;
int.TryParse(txtUserName.Text,outa);
frm2.STR=a.ToString();
frm2.ShowDialog();
else
label4.Text="
请正确输入用户名与密码"
;
txtUserPwd.Text=null;
conn.Close();
privatevoidbutton2_Click(objectsender,EventArgse)
注册lvFrm=new注册();
privatevoid用户登录_Load(objectsender,EventArgse)
}
(2)用户登录系统后的购买界面的设计:
考虑到我和管理员的管理系统要合并为同一个完整系统,我在编写用户购买界面时减少了窗体的数量,但是主体功能都在。
此处用到了窗体传值技术、DataGridView控件展示数据库的图书表,订单表。
下图展示了用户登录后的图书查询、图书购买、订单形成、订单查询的操作过程
用户登录后的界面
用户查询所有图书的界面
以上三图展示用户提交订单并成功过程
用户查询订单界面
源代码:
publicpartialclass用户购买:
public用户购买()
privatestringstr;
//定义的私有变量
publicstringSTR//为窗体Form2定义的属性
get//读
returnstr;
set//写
str=value;
privatevoidlabel5_Click(objectsender,EventArgse)
privatevoidlabel1_Click(objectsender,EventArgse)
privatevoidbtnselect_Click(objectsender,EventArgse)
SqlCommandcmd=newSqlCommand("
select*frombooks"
conn);
SqlDataAdaptersda=newSqlDataAdapter();
sda.SelectCommand=cmd;
DataSetds=newDataSet();
sda.Fill(ds,"
books"
dataGridView1.DataSource=ds.Tables[0];
dataGridView1.Columns["
bno"
].HeaderText="
编号"
bname"
名称"
tno"
类别号"
page"
页数"
price"
单价"
quantity"
数量"
pbsno"
出版社代号"
edition"
版次"
first_author"
第一作者"
date_of_publish"
出版年月"
description"
内容简介"
}
privatevoiddataGridView1_CellClick(objectsender,DataGridViewCellEventArgse)
txtID.Text=dataGridView1.SelectedCells[0].Value.ToString();
txtPrice.Text=dataGridView1.SelectedCells[4].Value.ToString();
privatevoidCalc_Click(objectsender,EventArgse)
floata,b,sum;
if(float.TryParse(txtPrice.Text,outa)&
&
float.TryParse(txtBquanity.Text,outb))//关于TryParse的使用方法,见补充知识。
sum=a*b;
txtjin.Text=sum.ToString();
txtjin.Show();
MessageBox.Show("
计算出错!
"
privatevoidbutton1_Click(objectsender,EventArgse)
Randomrad=newRandom();
//实例化随机数产生器rad;
intvalue=rad.Next(1000,10000);
//用rad生成大于等于1000,小于等于9999的随机数;
txtRandom.Text=value.ToString();
//用label控件label1显示产生的四位随机数;
SqlConnectionconn1;
SqlCommandcmd;
privatevoidbtnSubmit_Click(objectsender,EventArgse)
conn1=newSqlConnection("
conn1.Open();
cmd.Connection=conn1;
cmd.CommandText="
insertintoborder(Ono,Cno,bno,quantity,price,paytype,cstatus)values("
+txtRandom.Text.Trim()+"
"
+txtCID.Text.Trim()+"
+
txtID.Text+"
+txtBquanity.Text.Trim()+"
txtjin.Text.Trim()+"
'
txtFang.Text.Trim()+"
this.la.Text.Trim().ToString()+"
cmd.CommandType=CommandType.Text;
cmd.ExecuteNonQuery();
提交成功!
updatebookssetquantity=quantity-"
wherebno="
+txtID.Text.Trim();
insertintobsend(Ono,Stype,Sdate)values("
+txtRandom.Text+"
btnselect.PerformClick();
privatevoidbtncheck_Click(objectsender,EventArgse)
select*fromborderwhereCno="
+this.txtCID.Text,conn);
broder"
dataGridView2.DataSource=ds.Tables[0];
dataGridView2.Columns["
Ono"
订单编号"
Cno"
客户编号"
图书编号"
金额"
paytype"
付款方式"
Cstatus"
订单状态"
privatevoiddataGridView1_CellContentClick(objectsender,DataGridViewCellEventArgse)
privatevoidlabel3_Click(objectsender,EventArgse)
privatevoidtxtBquanity_TextChanged(objectsender,EventArgse)
privatevoidlabel4_Click(objectsender,EventArgse)
privatevoidlabel9_Click(objectsender,EventArgse)
用户登录lvFrm=new用户登录();
privatevoidcomboBox1_SelectedIndexChanged(objectsender,EventArgse)
privatevoidBuy_Load(objectsender,EventArgse)
txtFang.DropDownStyle=ComboBoxStyle.DropDownList;
txtFang.Items.Add("
货到付款"
网上支付"
txtCID.Text=str;
privatevoidtxtPrice_TextChanged(objectsender,EventArgse)
privatevoidtxtjin_TextChanged(objectsender,EventArgse)
(3)用户注册
用户注册后,数据自动插入数据库中的Customer表中,并在界面处设计了返回登陆窗的button
下图展示用户注册的过程
源代码;
publicpartialclass注册:
public注册()
privatevoidFormCZ_Load(obj