团队课程设计--购物车

1 团队名称、团队成员介绍(需要有照片)

  • 团队成员:郭雅芳

2 项目git地址

3 项目git提交记录截图(要体现出每个人的提交记录、提交说明),老师将点击进去重点考核。

4 项目功能架构图与主要功能流程图

  • 架构图
  • 流程图

5 项目运行截图




6 项目关键代码(不能太多)

private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {                                          
    try{
         conn=DriverManager.getConnection(url,userName,password);
         st = conn.createStatement();
		//通过sql语句,将文本框内的商品信息加入购物车,并且加入mlist。
         String sql="insert into goods(name,price,num,color,size)"
                 + " values('"+Text1.getText()+"',"+Double.parseDouble(Text2.getText())+","+Integer.parseInt(Text3.getText())+",'"+Text4.getText()+"','"+Text5.getText()+"')";
         st.executeUpdate(sql);
        }catch (SQLException e){
         e.printStackTrace();
         }
        mlist.add(new Clothes(Text1.getText(),Double.parseDouble(Text2.getText()),
    Integer.parseInt(Text3.getText()),Text4.getText(),Text5.getText()));
		//统计加入了多少条商品信息,显示到TextArea
        goodsNum++;
        addGoods();
}
  撤销添加:
private void cancleButtonActionPerformed(java.awt.event.ActionEvent evt) {   
        if(goodsNum>0){
           goodsNum--;
           try{
            conn=DriverManager.getConnection(url,userName,password);
             st = conn.createStatement();
             String delName=mlist.get(goodsNum).getName();
             String sql = "delete from goods where name = '"+delName+"' ";  
             System.out.println(sql);
             st.executeUpdate(sql); 
            }catch (SQLException e){
             e.printStackTrace();
             }
                 addGoods();
        }
}  

用户界面:
   组合框获取数据库中商品信息
private static void addComboxItem(){
    	try{ 
		conn=DriverManager.getConnection(url,userName,password);
         st = conn.createStatement();
         String sql="select * from goods";
         rs=st.executeQuery(sql);
         while(rs.next()){
             list.add(new Clothes(rs.getString("name"),rs.getDouble("price"),rs.getInt("num"),rs.getString("color"),rs.getString("size")));
         }
        }catch (SQLException e){
         e.printStackTrace();
         }
        System.out.println();
        for(int i=0;i<list.size();i++){ 
        	String a=list.get(i).getName();
			//addItem方法加入组合框列表中
        	clothesComboBox.addItem(a); 
        }
显示商品:
private void clothesComboBoxActionPerformed(java.awt.event.ActionEvent evt) 
{		//获得你选中的下拉框的位置
        int i=clothesComboBox.getSelectedIndex();
		//如何i大于零,则将信息显示购物车界面
         if(i>=0) {
            jLabel6.setText(list.get(i).getName());
            jLabel7.setText(Double.toString(list.get(i).getPrice()));
            jLabel8.setText(Integer.toString(list.get(i).getNum()));
            jLabel9.setText(list.get(i).getColor());
            jLabel10.setText(list.get(i).getSize());
         }
 }    
     加入购物车:      
private  void addButtonActionPerformed(java.awt.event.ActionEvent evt) 
{		//建立一个GoodDao table;
        GoodsDao goodDao = new Jtable(jTable1);
        try{
            count=Integer.parseInt(jTextField1.getText());
        }catch(NumberFormatException e){
            System.out.println(e);
        }
         int i=clothesComboBox.getSelectedIndex();
         if(i>=0) {
            String name=list.get(i).getName();
            double price=list.get(i).getPrice();
            Goods good = new Goods(name,price,count);
            boolean flag = goodDao.save(good);
            if(flag){
                JOptionPane.showMessageDialog(null, "添加成功");
            }else{
                JOptionPane.showMessageDialog(null, "添加失败!");
            }
            sum+=list.get(i).getPrice()*count;
         }
    }     

7 尚待改进或者新的想法

  • 改进:图形界面太过简单、管理界面不能显示已存在数据库的信息。通过管理界面返回用户界面,组合框没有导入商品信息。删除商品时,结算需要相应扣钱。

8 团队成员任务分配,团队成员课程设计博客链接(以表格形式呈现),标明组长

郭雅芳:管理员界面、用户界面

posted @ 2017-06-22 15:33  _Another  阅读(343)  评论(0编辑  收藏  举报