Java Swing 影楼管理系统之员工添加

广告,嘿嘿。Java1234.com。

多话不说,直接代码。

数据连接层  UserDao.java

    public int YG_Add(Connection conn ,YG_XinXi yuangong){
        
        int i=0;
        String sql="insert tb_ygxx value(null,?,?,?,?,?)";
        try{
            PreparedStatement pstm=conn.prepareStatement(sql);
            pstm.setString(1, yuangong.getYG_name());
            pstm.setString(2,String.valueOf(yuangong.getYG_Sex()) );
            pstm.setInt(3, yuangong.getYG_Ages());
            pstm.setString(4, yuangong.getYG_Address());
            pstm.setString(5, yuangong.getYG_phone());
            i=pstm.executeUpdate();
        }
        catch(Exception e){
            e.printStackTrace();
        }
        
        return i;
    }
View Code

表现层 

private void Jb_AddActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        //String name,sex,age,address,phone;
        String name = this.Jb_UserNameTxt.getText();
        String sex = (String) this.Jb_ComsexTxt.getSelectedItem();
        String age = this.Jb_AgeTxt.getText();
        String address = this.Jb_AddressTxt.getText();
        String phone = this.Jb_phoneTxt.getText().toString();

        int i = 0;
        UserDao us = new UserDao();
        if (stringutil.IfEmpty(name)) {
            JOptionPane.showMessageDialog(null, "员工名不能为空!");
        } else if ("请选择。。".equals(sex)) {
            JOptionPane.showMessageDialog(null, "性别不能为空!");
            return;
        } else if (stringutil.IfEmpty(age)) {
            JOptionPane.showMessageDialog(null, "年龄不能为空!");
        } else if (!stringutil.ShuziStr(age)) {
            JOptionPane.showMessageDialog(null, "年龄的格式不对!");
        } else if (stringutil.IfEmpty(address)) {
            JOptionPane.showMessageDialog(null, "地址不能为空");
        } else if (stringutil.IfEmpty(phone)) {
            JOptionPane.showMessageDialog(null, "联系电话不能为空");
        } else if (!stringutil.ShuziStr(phone)) {
            JOptionPane.showMessageDialog(null, "电话好格式不对");
        }
        YG_XinXi xinxi = new YG_XinXi(name, sex, Integer.parseInt(age),
                address, phone);
        Connection conn = null;
        try {
            conn = dbutil.getcon();
            i = us.YG_Add(conn, xinxi);
            if (i != 0) {
                JOptionPane.showMessageDialog(null, "新增成功!");
                //this.FillData();
                Reset();

            } else {
                JOptionPane.showMessageDialog(null, "新增失败");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                dbutil.closeCon(conn);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }
View Code

效果图

posted @ 2013-06-29 16:20  清风yi竹  阅读(310)  评论(0编辑  收藏  举报