s1(java)项目实战(固定资产管理)(set_ ManagerADD )

package set;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import tools.*;
import javax.swing.*;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2007</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class ManagerADD extends JDialog {
    private JLabel jLabel1 = new JLabel();
    private JLabel jLabel2 = new JLabel();
    private JTextField txtUserName = new JTextField();
    private JPasswordField ptxt_Pass = new JPasswordField();
    private DBConnection dcon = null;
    private JButton btn_ok = new JButton();
    private JButton btn_cancle = new JButton();
    private JLabel jLabel3 = new JLabel();
    private JTextField txt_userid;
    private JLabel jLabel4 = new JLabel();
    private JPasswordField ptxt_confrimPass = new JPasswordField();
    public ManagerADD(Frame owner, String title, boolean modal) {
        super(owner, title, modal);
        try {
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            jbInit();
            pack();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    public ManagerADD() {
        this(new Frame(), "add", false);
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(null);
        jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        jLabel1.setToolTipText("");
        jLabel1.setText("密   码");
        jLabel1.setBounds(new Rectangle(11, 116, 65, 21));
        jLabel2.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        jLabel2.setToolTipText("");
        jLabel2.setText("用户名称");
        jLabel2.setBounds(new Rectangle(11, 32, 57, 32));
        txtUserName.setBounds(new Rectangle(82, 72, 104, 25));
        txt_userid = new JTextField(getManagerID());
        txt_userid.setEditable(false);
        ptxt_Pass.setBounds(new Rectangle(82, 112, 105, 25));
        btn_ok.setBounds(new Rectangle(19, 187, 75, 30));
        btn_ok.setText("确定");
        btn_cancle.setBounds(new Rectangle(128, 187, 74, 32));
        btn_cancle.setText("取消");
        jLabel3.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        jLabel3.setToolTipText("");
        jLabel3.setText("用户名称");
        jLabel3.setBounds(new Rectangle(11, 71, 57, 32));
        txt_userid.setBounds(new Rectangle(82, 35, 104, 27));
        jLabel4.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
        jLabel4.setToolTipText("");
        jLabel4.setText("确    认");
        jLabel4.setBounds(new Rectangle(11, 149, 65, 21));
        this.setResizable(false);
        ptxt_confrimPass.setBounds(new Rectangle(82, 146, 105, 25));
        this.getContentPane().add(jLabel3);
        this.getContentPane().add(jLabel2);
        this.getContentPane().add(txtUserName);
        this.getContentPane().add(txt_userid);
        this.getContentPane().add(btn_ok);
        this.getContentPane().add(btn_cancle);
        this.getContentPane().add(ptxt_Pass);
        this.getContentPane().add(jLabel1);
        this.getContentPane().add(ptxt_confrimPass);
        this.getContentPane().add(jLabel4);
        this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
        btn_cancle.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                cancleDialog();
            }
        });
        btn_ok.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                ManagerADD();
            }
        });
    }

    private void ManagerADD() {
        String pass = new String(ptxt_Pass.getPassword());
        String confrimpass = new String(ptxt_confrimPass.getPassword());

        if (txtUserName.getText().trim().length() == 0) {
            JOptionPane.showMessageDialog(this, "用户名不能为空");
        } else if (pass.trim().length() == 0) {
            JOptionPane.showMessageDialog(this, "不能为空密码");
        } else if (!pass.trim().equals(confrimpass.trim())) {
            JOptionPane.showMessageDialog(this, "确认密码不一样");
            ptxt_confrimPass.setText("");
        } else {
            dcon = new DBConnection();
            String sql = "Select * from Manager where manager_username = '" +
                         txtUserName.getText().trim() + "'";
            if (dcon.isNull(sql)) {
                JOptionPane.showMessageDialog(this, "该用户名已经存在");
            } else {
                sql =
                        "insert into Manager(manager_id,manager_username,manager_password) values ('";
                sql += txt_userid.getText().trim() + "','";
                sql += txtUserName.getText().trim() + "','";
                sql += pass.trim() + "')";
                JOptionPane.showMessageDialog(this, dcon.update(3, sql));
                ptxt_Pass.setText("");
                txt_userid.setText(getManagerID());
                ptxt_confrimPass.setText("");
                txtUserName.setText("");
            }
        }
    }

//关闭对话框
    private void cancleDialog() {
        this.dispose();
    }

    //获取管理员ID
    private String getManagerID() {
        dcon = new DBConnection();
        Vector v = dcon.select(
                "select manager_id from Manager order by manager_id asc");
        if (v.size() == 1) {
            return "2";
        }
        int autoID = 2;
        for (int i = 1; i < v.size(); i++) {
            String s = ((Vector) v.get(i)).get(0).toString();

            int getID = Integer.parseInt(s);
            if (autoID != getID) {
                return String.valueOf(autoID);
            }
            autoID++;
        }
        return String.valueOf(v.size() + 1);
    }

}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值