<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Java實現(xiàn)超市管理系統(tǒng)(含數(shù)據(jù)庫)

          共 16181字,需瀏覽 33分鐘

           ·

          2021-01-14 19:13

          來源:https://blog.csdn.net/qq_44859533



          序言:?這次寫的超市管理系統(tǒng),實現(xiàn)的功能有賬戶的注冊、登錄,超市商品類別的添加、修改和刪除以及商品的添加、修改和刪除的功能。用戶注冊之后把注冊信息導(dǎo)入數(shù)據(jù)庫;用戶登錄時候查詢用戶表,方可登錄進去;商品類別和商品的增加也如注冊信息一樣,把信息導(dǎo)入商品類別表和商品表。超市管理系統(tǒng)的一些功能還沒有完善,后續(xù)還會更新顧客登錄超市系統(tǒng)后,只能擁有查詢商品的權(quán)限,并且還可以實現(xiàn)購買商品的功能。

          1、首先是建立數(shù)據(jù)庫表:


          2、實現(xiàn)主頁面:

          3、實現(xiàn)用戶注冊:


          核心代碼:

          public static void main(String args[]) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                new Register().setVisible(true);            }        });    }    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {        String name=this.jTextField1.getText();        String age=this.jTextField3.getText();        String QQ=this.jTextField4.getText();        String userName=this.jTextField5.getText();        String password1=this.jPasswordField1.getText();        String password2=this.jPasswordField2.getText();        if(StringUtil.isEmpty(name)){            JOptionPane.showMessageDialog(null,"姓名不能為空");            return;        }        if(StringUtil.isEmpty(age)){            JOptionPane.showMessageDialog(null,"年齡不能為空");            return;        }        if(StringUtil.isEmpty(QQ)){            JOptionPane.showMessageDialog(null,"QQ不能為空");            return;        }        if(StringUtil.isEmpty(userName)){            JOptionPane.showMessageDialog(null,"注冊賬號不能為空");            return;        }        if(StringUtil.isEmpty(password1)){            JOptionPane.showMessageDialog(null,"注冊密碼不能為空");            return;        }        if(StringUtil.isEmpty(password2)){            JOptionPane.showMessageDialog(null,"確認密碼不能為空");            return;        }        if(!password1.equals(password2)){            JOptionPane.showMessageDialog(null,"兩個密碼填寫不一致");            return;        }        User user=new User(userName,password1);        Connection con=null;        try{            con=dbUtil.getCon();            int n=userDao.add(con,user);            if(n==1){                JOptionPane.showMessageDialog(null,"用戶注冊成功!");
          }else{ JOptionPane.showMessageDialog(null,"注冊失?。。?); } }catch (Exception e){ e.printStackTrace(); JOptionPane.showMessageDialog(null,"注冊失?。。?); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); }
          } } //上一步 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { dispose(); new HomePage().setVisible(true);????}

          注冊成功之后可以返回上一步,重新登錄

          4、實現(xiàn)用戶登錄:

          核心代碼:

           //重置    private void resetValueActionPerformed(ActionEvent evt) {        this.userNameTxt.setText("");        this.passwordTxt.setText("");    }    //登錄事件處理    private void loginActionPerformed(ActionEvent evt) {        String userName=this.userNameTxt.getText();        String password=new String(this.passwordTxt.getPassword());        if(StringUtil.isEmpty(userName)){            JOptionPane.showMessageDialog(null,"用戶名不能為空!");            return;        }        if(StringUtil.isEmpty(password)){            JOptionPane.showMessageDialog(null,"密碼不能為空");            return;        }        User usr=new User(userName,password);        Connection con=null;        try{            con=dbUtil.getCon();            User currentUser=userDao.login(con,usr);            if(currentUser!=null){                dispose();                new MainFrm().setVisible(true);
          }else{ JOptionPane.showMessageDialog(null,"登錄失敗,用戶名密碼錯誤!"); } }catch (Exception e){ e.printStackTrace(); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); } }
          ????}

          接下來是商品類別和商品的實現(xiàn),主要是在JFrame窗口中加入Inter窗口
          5、主菜單之關(guān)于:

          核心代碼:

          6、主菜單之商品類別管理:
          核心代碼:

           private void jButton1ActionPerformed(ActionEvent evt) {        String goodsTypeName=this.goodsTypeNameTxt.getText();        String goodsTypeDesc=this.goodsTypeDescTxt.getText();        if(StringUtil.isEmpty(goodsTypeName)){            JOptionPane.showMessageDialog(null,"商品類別不能為空");            return;        }        GoodsType goodsType=new GoodsType(goodsTypeName,goodsTypeDesc);        Connection con=null;        try{            con=dbUtil.getCon();            int n=goodsTypeDao.add(con,goodsType);            if(n==1){                JOptionPane.showMessageDialog(null,"商品類別添加成功!");                jButton2ActionPerformed(evt);            }else{                JOptionPane.showMessageDialog(null,"添加失?。。?);            }        }catch (Exception e){            e.printStackTrace();            JOptionPane.showMessageDialog(null,"添加失?。。?);        }finally {            try{                dbUtil.closeCon(con);            }catch (Exception e){                e.printStackTrace();            }
          } } //重置
          private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { this.goodsTypeNameTxt.setText(""); this.goodsTypeDescTxt.setText("");????}


          //表格行點擊事件    private void jTable1MousePressed(java.awt.event.MouseEvent evt) {        int row=jTable1.getSelectedRow();//獲取行數(shù)        idTxt.setText((String)jTable1.getValueAt(row,0));        goodsTypeNameTxt.setText((String)jTable1.getValueAt(row,1));        goodsTypeDescTxt.setText((String)jTable1.getValueAt(row,2));
          } //鼠標單擊后,刪除 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { String id=idTxt.getText(); if(StringUtil.isEmpty(id)){ JOptionPane.showMessageDialog(null,"請選擇要刪除的記錄"); return; } int n=JOptionPane.showConfirmDialog(null,"Are you 確定delete this記錄?"); if(n==0){ Connection con=null; try{ con=dbUtil.getCon(); int deleteNum=goodsTypeDao.delect(con,id); //System.out.println(deleteNum); if(deleteNum==1){ JOptionPane.showMessageDialog(null,"刪除成功"); this.resetValue(); this.fillTable(new GoodsType()); }else{ JOptionPane.showMessageDialog(null,"刪除失敗"); }
          }catch (Exception e){ e.printStackTrace(); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); } } } } //鼠標單擊后,修改 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { String id=idTxt.getText(); String goodsTypeName=goodsTypeNameTxt.getText(); String goodsTypeDesc=goodsTypeDescTxt.getText(); if(StringUtil.isEmpty(id)){ JOptionPane.showMessageDialog(null,"請選擇要修改的記錄"); return; } GoodsType goodsType=new GoodsType(Integer.parseInt(id),goodsTypeName,goodsTypeDesc); Connection con=null; try{ con=dbUtil.getCon(); int modifyNum=goodsTypeDao.update(con,goodsType); if(modifyNum==1){ JOptionPane.showMessageDialog(null,"修改成功"); this.resetValue(); this.fillTable(new GoodsType()); }else{ JOptionPane.showMessageDialog(null,"修改失敗"); } }catch (Exception e){ e.printStackTrace(); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); } }

          } //查詢商品類型 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String t_goodsTypeName=this.jTextField2.getText(); GoodsType goodsType=new GoodsType(); goodsType.setGoodsTypeName(t_goodsTypeName); this.fillTable(goodsType); } //插入商品類型 private void fillTable(GoodsType goodsType){ DefaultTableModel dtm=(DefaultTableModel)jTable1.getModel(); dtm.setRowCount(0); Connection con=null; try{ con=dbUtil.getCon(); ResultSet rs=goodsTypeDao.list(con,goodsType); while(rs.next()){ Vector v=new Vector(); v.add(rs.getString("id")); v.add(rs.getString("goodsTypeName")); v.add(rs.getString("goodsTypeDesc")); dtm.addRow(v); } }catch (Exception e){ e.printStackTrace(); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); } } } //修改后重置 private void resetValue(){ this.idTxt.setText(""); this.goodsTypeNameTxt.setText(""); this.goodsTypeDescTxt.setText("");????}

          7、主菜單之商品管理:
          核心代碼:

          //查詢    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {        String t_goodsName=this.s_goodsNameTxt.getText();        Goods goods=new Goods();        goods.setGoodsName(t_goodsName);        this.fillTable(goods);    }    //下拉框    private void fillGoodsType(String type){        Connection con=null;        GoodsType goodsType=null;        try{            con=dbUtil.getCon();            ResultSet rs=goodsTypeDao.list(con,new GoodsType());            if("search".equals(type)){                goodsType=new GoodsType();                goodsType.setGoodsTypeName("請選擇");                goodsType.setId(-1);                this.s_goodsJcb.addItem(goodsType);            }            while(rs.next()){                goodsType=new GoodsType();                goodsType.setGoodsTypeName(rs.getString("goodsTypeName"));                goodsType.setId(rs.getInt("id"));                if("search".equals(type)){                    this.s_goodsJcb.addItem(goodsType);                }else if("modify".equals(type)){
          } } }catch (Exception e){ e.printStackTrace(); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); }
          } } //表 private void fillTable(Goods goods){ DefaultTableModel dtm=(DefaultTableModel) jTable1.getModel(); dtm.setRowCount(0); Connection con=null; try{ con=dbUtil.getCon(); ResultSet rs=goodsDao.list(con,goods); while(rs.next()){ Vector v=new Vector(); v.add(rs.getInt("id")); v.add(rs.getString("goodsName")); v.add(rs.getFloat("price")); v.add(rs.getString("goodsDesc")); dtm.addRow(v); }
          }catch (Exception e){ e.printStackTrace(); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); } } } //鼠標點擊表格事件 private void jTable1MousePressed(java.awt.event.MouseEvent evt) { int row=jTable1.getSelectedRow(); this.idTxt.setText((Integer)jTable1.getValueAt(row,0)+""); this.goodsNameTxt.setText((String)jTable1.getValueAt(row,1)); this.priceTxt.setText((Float)jTable1.getValueAt(row,2)+""); this.goodsDescTxt.setText((String)jTable1.getValueAt(row,3));
          } //鼠標單擊后,修改 private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { String id=this.idTxt.getText(); if(StringUtil.isEmpty(id)){ JOptionPane.showMessageDialog(null,"請選擇要修改的記錄"); return; } String goodsName=this.goodsNameTxt.getText(); String price=this.priceTxt.getText(); String goodsDesc=this.goodsDescTxt.getText(); if(StringUtil.isEmpty(goodsName)){ JOptionPane.showMessageDialog(null,"商品名稱不能為空"); return; } if(StringUtil.isEmpty(price)){ JOptionPane.showMessageDialog(null,"商品價錢不能為空"); return; } if(StringUtil.isEmpty(goodsDesc)){ JOptionPane.showMessageDialog(null,"商品描述不能為空"); return; } Goods goods=new Goods(Integer.parseInt(id),goodsName, Float.parseFloat(price),goodsDesc); Connection con=null; try{ con=dbUtil.getCon(); int modifyNum=goodsDao.update(con,goods); if(modifyNum==1){ JOptionPane.showMessageDialog(null,"修改成功"); this.resetValue(); this.fillTable(new Goods()); }else{ JOptionPane.showMessageDialog(null,"修改失敗"); } }catch (Exception e){ e.printStackTrace(); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); } }
          } //鼠標單擊后刪除 private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) { String id=idTxt.getText(); if(StringUtil.isEmpty(id)){ JOptionPane.showMessageDialog(null,"請選擇要刪除的記錄"); return; } int n=JOptionPane.showConfirmDialog(null,"Are you 確定delete this記錄?"); if(n==0){ Connection con=null; try{ con=dbUtil.getCon(); int deleteNum=goodsDao.delete(con,id); if(deleteNum==1){ JOptionPane.showMessageDialog(null,"刪除成功"); this.resetValue(); this.fillTable(new Goods()); }else{ JOptionPane.showMessageDialog(null,"刪除失敗"); }
          }catch (Exception e){ e.printStackTrace(); }finally { try{ dbUtil.closeCon(con); }catch (Exception e){ e.printStackTrace(); } } } } //修改后重置 private void resetValue(){ this.idTxt.setText(""); this.goodsNameTxt.setText(""); this.goodsDescTxt.setText("");????}


          private void jButton2ActionPerformed(ActionEvent evt) {        this.resetValue();    }    //商品添加    private void jButton1ActionPerformed(ActionEvent evt){        String goodsName=this.goodsNameTxt.getText();        String price=this.priceTxt.getText();        String goodsDesc=this.goodsDecTxt.getText();        if(StringUtil.isEmpty(goodsName)){            JOptionPane.showMessageDialog(null,"商品類別名稱不能為空");            return;        }        if(StringUtil.isEmpty(price)){            JOptionPane.showMessageDialog(null,"商品價格不能為空");            return;        }        GoodsType goodsType=(GoodsType)goodsTypeJcb.getSelectedItem();        int goodsTypeId=goodsType.getId();        Goods goods=new Goods(goodsName,Float.parseFloat(price),goodsDesc);        Connection con=null;        try{            con=dbUtil.getCon();            int addNum=goodsDao.add(con,goods);            if(addNum==1){                JOptionPane.showMessageDialog(null,"商品添加成功");                resetValue();            }else{                JOptionPane.showMessageDialog(null,"商品添加失敗");            }        }catch (Exception e){            e.printStackTrace();            JOptionPane.showMessageDialog(null,"商品添加失敗");        }finally {            try{                dbUtil.closeCon(con);            }catch (Exception e){                e.printStackTrace();            }        }
          }
          /** * 重置表單 */ private void resetValue(){ this.goodsNameTxt.setText(""); this.priceTxt.setText(""); this.goodsDecTxt.setText(""); if(this.goodsTypeJcb.getItemCount()>0){ this.goodsTypeJcb.setSelectedIndex(0);
          } } //初始化商品類別下拉框 private void fillGoodsType(){ Connection con=null; GoodsType goodsType=null; try{ con=dbUtil.getCon(); ResultSet rs=goodsTypeDao.list(con,new GoodsType()); while(rs.next()){ goodsType=new GoodsType(); goodsType.setId(rs.getInt("id")); goodsType.setGoodsTypeName(rs.getString("goodsTypeName")); this.goodsTypeJcb.addItem(goodsType); } }catch (Exception e){ e.printStackTrace(); }finally {
          }????}

          8、退出:


          PS:如果覺得我的分享不錯,歡迎大家隨手點贊、在看。
          END
          瀏覽 54
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  99re4| 高清无码在线不卡 | 日逼视频| 久久久久草 | 一级a一级a爰片免费免 |