crm开发定制Java实现超市管理系统(含数据库)

序言: 学Javacrm开发定制已经有几个月了,crm开发定制上一次总结是针对GUIcrm开发定制界面写的简易计算器,crm开发定制实现加减乘除功能以及crm开发定制计算器标准型和科学型crm开发定制之间的转换,有兴趣可以看看 . 这次写的,实现的功能有账户的注册、登录,超市商品类别的添加、修改和删除以及商品的添加、修改和删除的功能。用户注册之后把注册信息导入数据库;用户登录时候查询用户表,方可登录进去;商品类别和商品的增加也如注册信息一样,把信息导入商品类别表和商品表。由于快期末考试了,超市管理系统的一些功能还没有完善,后续还会更新顾客登录超市系统后,只能拥有查询商品的权限,并且还可以实现购买商品的功能,哈~哈 ~…

1、首先是建立数据库表:


2、实现主页面:

3、实现用户注册:


核心代码:

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);    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70

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

4、实现用户登录:

核心代码:

 //重置    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();            }        }    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40

接下来是商品类别和商品的实现,主要是在JFrame窗口中加入Inter窗口
5、主菜单之关于:

核心代码:
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("");    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
//表格行点击事件    private void jTable1MousePressed(java.awt.event.MouseEvent evt) {        int row=jTable1.getSelectedRow();//获取行数        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("");    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112

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("");    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
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 {        }    }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73

8、退出:

网站建设定制开发 软件系统开发定制 定制软件开发 软件开发定制 定制app开发 app开发定制 app开发定制公司 电商商城定制开发 定制小程序开发 定制开发小程序 客户管理系统开发定制 定制网站 定制开发 crm开发定制 开发公司 小程序开发定制 定制软件 收款定制开发 企业网站定制开发 定制化开发 android系统定制开发 定制小程序开发费用 定制设计 专注app软件定制开发 软件开发定制定制 知名网站建设定制 软件定制开发供应商 应用系统定制开发 软件系统定制开发 企业管理系统定制开发 系统定制开发