2數(shù)據(jù)庫(kù)結(jié)構(gòu)2.1用戶(hù)表
2.2商品表 | | | | |
| | | | |
| | | | |
| | | | 商品庫(kù)存數(shù)量,庫(kù)存量<=0不能上架 |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
2.3訂單表 | | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | |
| | | | 已支付該項(xiàng)為“true”,未支付為“false” |
| | | | |
2.4購(gòu)物車(chē)表
3 實(shí)體類(lèi)定義3.1User.javapublic class User {
String userName;
String password;
double account;
boolean identity;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
} public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public double getAccount() {
return account;
}
public void setAccount(double d) {
this.account = d;
}
public boolean getIdentity() {
return identity;
}
public void setIdentity(boolean b) {
this.identity = b;
}
}
3.1Goods.javapackage shop;
public class Goods {
String goodsID;
String goodsName;
int store;
double price;
String color;
String size;
String image;
String detail;
public String getGoodsID() {
return goodsID;
}
public void setGoodsID(String goodsID) {
this.goodsID = goodsID;
}
public String getGoodsName() {
return goodsName;
}
public void setGoodsName(String goodsName) {
this.goodsName = goodsName;
}
public int getStore() {
return store;
}
public void setStore(int store) {
this.store = store;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getSize() {
return size;
}
public void setSize(String size) {
this.size = size;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public String getDetail() {
return detail;
}
public void setDetail(String detail) {
this.detail = detail;
}
3.3Shop.javapackage shop;
public class Shop {
private User user = new User();
private Goods goods = new Goods();
private int number;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
3.4Order.java
package shop;
public class Order {
private User user=new User();
private Goods goods=new Goods();
private String orderID;
private String orderTime;
private int number;
private int pay;
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public Goods getGoods() {
return goods;
}
public void setGoods(Goods goods) {
this.goods = goods;
}
public String getOrderID() {
return orderID;
}
public void setOrderID(String orderID) {
this.orderID = orderID;
}
public String getOrderTime() {
return orderTime;
}
public void setOrderTime(String orderTime) {
this.orderTime = orderTime;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
4 功能類(lèi)定義——圖形界面實(shí)現(xiàn)4.1登錄界面(1)布局框架采用網(wǎng)格布局3行1列,每一行放一個(gè)面板,面板采用流水布局,前兩行(用戶(hù)名、密碼)采用左對(duì)齊,最后一行(按鈕行)采用居中對(duì)齊。
1.001.jpg (5.44 KB, 下載次數(shù): 54)
下載附件
2017-3-16 19:44 上傳
圖4-1-1登錄界面布局圖
(2)源代碼public class Load extends JFrame implements ActionListener{
public Load() {
this.init();
this.setVisible(true);
this.setSize(400, 400);
this.setTitle("");
//this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
}
public void init(){
this.setLayout(new GridLayout(3,1));
JPanel jp1=new JPanel();
load.addActionListener(this);
cancel.addActionListener(this);
zc.addActionListener(this);
}
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource()==load){
String userName = userField.getText();
System.out.println(userName);
String psw = pswField.getText();
String sql="select * from userinfo where UserName='"+userName+"'";
System.out.println(sql);
//加數(shù)據(jù)庫(kù)操作代碼
try{
ResultSet rs=ConnectionDB.selectData(sql);
if(!rs.next()){
JOptionPane.showMessageDialog(this,"用戶(hù)名錯(cuò)誤,此用戶(hù)名不存在!", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);
} else{
user.setUserName(rs.getString("" + "userName"));
//System.out.println(rs.getString("userName"));
user.setAccount(rs.getDouble("account"));
user.setPassword(rs.getString("password"));
user.setIdentity(rs.getBoolean("identity"));
//System.out.println(user.getIdentity());
if(user.getPassword().equals(psw)) {
if(user.isIdentity()) {
GoodsMaintain goodsMaintain=new GoodsMaintain();
}
else {
Main main=new Main(user);
}
this.dispose();
}
else {
JOptionPane.showMessageDialog(this, "密碼錯(cuò)誤", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);
}
}
ConnectionDB.close();
} catch (SQLException e) {
e.printStackTrace();}
}else if(arg0.getSource()==cancel){
userField.setText("");
pswField.setText("");
}else if(arg0.getSource()==zc){
zhuce zcl=new zhuce(user);
}}
public static void main(String[] args) {
Load l=new Load();
}
}
1.002.jpg (6.27 KB, 下載次數(shù): 69)
下載附件
2017-3-16 19:44 上傳
(3)完成效果截圖
圖4-1-2登錄界面效果圖
4.2 商品信息維護(hù)界面(1)布局先采用邊界布局分為中間C和南邊S,南邊S采用流水布局中間對(duì)齊,順次擺放4個(gè)按鈕,中間C再次采用邊界布局分為中間CC和南邊CS,CC采用網(wǎng)格布局分成4行1列網(wǎng)格,每個(gè)網(wǎng)格上流水布局左對(duì)齊,按順次擺放控件;南邊CS采用流水布局左對(duì)齊,將標(biāo)簽“商品描述”和文本域控件放上。
1.003.jpg (8.18 KB, 下載次數(shù): 69)
下載附件
2017-3-16 19:44 上傳
圖4-2-1商品信息維護(hù)界面布局圖
(2)源代碼public class GoodsMaintain extends JFrame implements ActionListener{
public GoodsMaintain() {
// TODO Auto-generated constructor stub
this.init();
this.setVisible(true);
this.setSize(500, 500);
this.setTitle("");
this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
id=IDField.getText();
//查找商品
if(e.getSource()==jbsearch){
if(id.equals("")){
JOptionPane.showMessageDialog(this,"商品ID不能為空","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
}else{
sql="select * from goodsinfo where goodsID='"+id+"'";
rs=(ResultSet) ConnectionDB.selectData(sql);
try {
if(rs.next()){
nameField.setText(rs.getString("goodsName"));
priceField.setText(String.valueOf(rs.getDouble("price")));
imageField.setText(rs.getString("image"));
storeField.setText(String.valueOf(rs.getInt("store")));
colorBox.setEditable(true);
colorBox.setSelectedItem(rs.getString("color"));
sizeBox.setEditable(true);
sizeBox.setSelectedItem(rs.getString("size"));
detailArea.setText(rs.getString("detail"));
}else{
JOptionPane.showMessageDialog(this,"商品不存在","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
}
ConnectionDB.close();
} catch (HeadlessException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}else if(e.getSource()==jbupdate){
if(id.equals("")){
JOptionPane.showMessageDialog(this,"商品ID不能為空","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
}else{
goodsName=nameField.getText();
price=Double.parseDouble(priceField.getText());
image=imageField.getText();
store=Integer.parseInt(storeField.getText());
detail=detailArea.getText();
sql="update goodsinfo set goodsName='"+goodsName+"',store='"+store+"',price='"+price+"',color='"+color+"',size='"+size+"',image='"+image+"',detail='"+detail+"'where goodsID='"+id+"'";
ConnectionDB.updateData(sql);
System.out .println(sql);
JOptionPane.showMessageDialog(this, "商品修改成功", "系統(tǒng)信息", JOptionPane.INFORMATION_MESSAGE);;
ConnectionDB.close();
}
}else if(e.getSource()==jbdelete){
if(id.equals("")){
JOptionPane.showMessageDialog(this,"商品ID不能為空","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
}else{
sql="delete from goodsinfo where goodsID='"+id+"'";
ConnectionDB.updateData(sql);
JOptionPane.showMessageDialog(this, "商品刪除成功", "系統(tǒng)信息", JOptionPane.INFORMATION_MESSAGE);;
ConnectionDB.close();
IDField.setText("");
nameField.setText("");
priceField.setText("");
imageField.setText("");
storeField.setText("");
colorBox.setEditable(true);
colorBox.setSelectedItem("");
sizeBox.setEditable(true);
sizeBox.setSelectedItem("");
detailArea.setText("");
}else if(e.getSource()==jbadd){
id=IDField.getText();
if(id.equals("")){
JOptionPane.showMessageDialog(this,"商品ID不能為空","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
}else{
sql="select * from goodsinfo where goodsID='"+id+"'";
rs=(ResultSet) ConnectionDB.selectData(sql);
try {
if(rs.next()){
JOptionPane.showMessageDialog(this,"商品信息已存在","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
ConnectionDB.close();
}else{
ConnectionDB.close();
goodsName=nameField.getText();
price=Double.parseDouble(priceField.getText());
image=imageField.getText();
store=Integer.parseInt(storeField.getText());
detail=detailArea.getText();
sql="insert into goodsinfo(goodsID,goodsName,store,price,color,size,image,detail) values('"+id+"','"+goodsName+"','"+store+"','"+price+"','"+color+"','"+size+"','"+image+"','"+detail+"')";
ConnectionDB.updateData(sql);
JOptionPane.showMessageDialog(this,"商品信息添加成功","系統(tǒng)信息",JOptionPane.INFORMATION_MESSAGE);
ConnectionDB.close();}
} catch (HeadlessException e1) {
e1.printStackTrace();
} catch (SQLException e1) {
e1.printStackTrace();
}
}
(3)完成效果截圖
1.004.jpg (11.6 KB, 下載次數(shù): 76)
下載附件
2017-3-16 19:44 上傳
圖4-2-2商品信息維護(hù)界面效果圖
4.3主頁(yè)面(1)布局先采用邊界布局分為北邊N、中間C、西邊W和南邊S。北邊N采用邊界布局分為中間NC和南邊NS,NC流水布局中間對(duì)齊,放jlLogo,NS采用1行兩列網(wǎng)格布局,左側(cè)網(wǎng)格流水布局左對(duì)齊,放標(biāo)簽jl,右側(cè)網(wǎng)格流水布局右對(duì)齊,放標(biāo)簽、文本框nameField、按鈕jbsearch。中間C采用2行3列網(wǎng)格布局,用循環(huán)放mp。西邊W采用3行1列網(wǎng)格布局,每個(gè)網(wǎng)格流水布局中間對(duì)齊,放按鈕jbadd、jbshop和jborder。南邊S流水布局中間對(duì)齊放標(biāo)簽。
1.005.jpg (6.56 KB, 下載次數(shù): 65)
下載附件
2017-3-16 19:44 上傳
圖4-3-1主頁(yè)面布局圖
(2)源代碼 public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jbadd){
Rechange rechange=new Rechange(user);
}else if(e.getSource()==jbshop){
ShopSearch shopSearch=new ShopSearch(user);
}
else if(e.getSource()==jbsearch){
if(nameField.getText().trim().equals("")){
JOptionPane.showMessageDialog(this,"商品名稱(chēng)不為空","系統(tǒng)消息",JOptionPane.INFORMATION_MESSAGE);
}else{
sql="select * from goodsinfo where goodsName='"+nameField.getText().trim()+"'";
System.out.println(sql);
//st=conn.createStatement();
//rs=st.executeQuery(sql);
rs=ConnectionDB.selectData(sql);//通過(guò)ConnectionDB連接
try {
if(rs.next()){//進(jìn)行判斷集合中是否有數(shù)據(jù)存在 rs.next()
goods.setGoodsID(rs.getString("goodsID"));
goods.setGoodsName(rs.getString("goodsName"));
goods.setStore(rs.getInt("store"));
goods.setPrice(rs.getDouble("price"));
goods.setColor(rs.getString("color"));
goods.setSize(rs.getString("size"));
goods.setImage(rs.getString("image"));
goods.setSize(rs.getString("size"));
goods.setDetail(rs.getString("detail"));
GoodsBuy GoodsBuy=new GoodsBuy(goods,user);
}else{
JOptionPane.showMessageDialog(this,"商品不存在","系統(tǒng)消息",JOptionPane.INFORMATION_MESSAGE);}
ConnectionDB.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else if(e.getSource()==(jborder)){
OrderAllSearch orderAllSearch=new OrderAllSearch(user);
}}
1.006.jpg (25.44 KB, 下載次數(shù): 54)
下載附件
2017-3-16 19:44 上傳
(3)完成效果截圖
圖4-3-2主頁(yè)面完成效果圖
4.4 商品購(gòu)買(mǎi)頁(yè)面(1)布局先采用邊界布局分為中間C和南邊S。中間C采用1行2列網(wǎng)格布局,左側(cè)網(wǎng)格流水布局中間對(duì)齊,放標(biāo)簽jliamge,右側(cè)網(wǎng)格采用7行1列網(wǎng)格布局,每一行再采用流水布局左對(duì)齊,將對(duì)應(yīng)組件放上去。南邊S流水布局中間對(duì)齊,將組件放上。
1.007.jpg (4.69 KB, 下載次數(shù): 66)
下載附件
2017-3-16 19:44 上傳
圖4-4-1購(gòu)買(mǎi)界面布局圖
(2)源代碼public class GoodsBuy extends JFrame implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jbadd){
sql="insert into shopinfo values('"+goods.getGoodsID()+"','"+goods.getGoodsName()+"','"+user.getUserName()+"','"+Integer.parseInt(nubmerField.getText())+"','"+goods.getColor()+"','"+goods.getSize()+"','"+goods.getPrice()+"')";
ConnectionDB.updateData(sql);
JOptionPane.showMessageDialog(this,"添加成功","系統(tǒng)消息",JOptionPane.INFORMATION_MESSAGE);
ConnectionDB.close();
}else if(e.getSource()==jborder){
//OrderSearch or = new OrderSearch(order,user,goods);
String orderid=null;
sql="select max(orderID) as id from orderinfo";
rs=ConnectionDB.selectData(sql);
try {
if(rs.next()){
System.out.println(orderid);
orderid=String.valueOf(Integer.parseInt(rs.getString("id"))+1);
}else{
orderid="10001";
System.out.println(orderid);
}
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
ConnectionDB.close();
Date date=new Date();
String orderTime=String.valueOf(date.getYear()+1900);
orderTime=orderTime+"-"+String.valueOf(date.getMonth()+1);
orderTime=orderTime+"-"+String.valueOf(date.getDate());
sql="insert into orderinfo values('"+orderid+"','"+goods.getGoodsID()+"','"+goods.getGoodsName()+"','"+orderTime+"','"+user.getUserName()+"','"+Integer.parseInt(nubmerField.getText())+"','"+goods.getColor()+"','"+goods.getSize()+"','0','"+goods.getPrice()+"')";
System.out.println(sql);
ConnectionDB.updateData(sql);
ConnectionDB.close();
order.setOrderID(orderid);
System.out.println(orderid);
order.setGoods(goods);
order.setUser(user);
order.setNumber(Integer.parseInt(nubmerField.getText()));
order.setPay(0);
order.setOrderTime(orderTime);
OrderlSearch orderSearch=new OrderlSearch(order,user);
}
}
}
1.008.jpg (20.52 KB, 下載次數(shù): 80)
下載附件
2017-3-16 19:44 上傳
(3)完成效果截圖
1.010.jpg (6.2 KB, 下載次數(shù): 69)
下載附件
2017-3-16 19:44 上傳
圖4-4-2購(gòu)買(mǎi)界面完成效果圖
4.5 單筆訂單支付界面(1)布局先采用邊界布局分為北邊N、中間C和南邊S。北邊N流水布局左對(duì)齊,放標(biāo)簽jluser。中間C采用4行2列網(wǎng)格布局,每一網(wǎng)格再采用流水布局左對(duì)齊,放置組件。南邊S流水布局右對(duì)齊,將按鈕jbdelete和jbpay放上。
1.009.jpg (2.93 KB, 下載次數(shù): 89)
下載附件
2017-3-16 19:44 上傳
圖4-5-1單筆訂單完成布局圖
(2)源代碼public class OrderlSearch extends JFrame implements ActionListener{
public void actionPerformed(ActionEvent e) {
if(e.getSource()==jbdelete){
sql="delete from orderinfo where orderID='"+order.getOrderID()+"'";
ConnectionDB.updateData(sql);
JOptionPane.showMessageDialog(this, "刪除成功", "系統(tǒng)消息", JOptionPane.INFORMATION_MESSAGE);
ConnectionDB.close();
}else if(e.getSource()==jbpay){
double account=user.getAccount();
double all=goods.getPrice()*order.getNumber();