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

本文介绍了一个简单的Java实现的员工信息管理系统,包括数据连接层(UserDao.java)和表现层的实现。该系统允许用户添加员工信息,并对输入进行有效性检查。

广告,嘿嘿。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

效果图

转载于:https://www.cnblogs.com/liuquande/p/3162412.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值