⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insertpanel.java~130~

📁 会员管理系统的一个子模块
💻 JAVA~130~
📖 第 1 页 / 共 2 页
字号:
    JTextField careerField = new JTextField();
    JTextField certcodeField = new JTextField();
    JTextField mobiliField = new JTextField();
    JTextField emailField = new JTextField();
    JLabel memNumLabel = new JLabel();
    JTextField memNumField = new JTextField();
    JCheckBox validCheckBox = new JCheckBox();
    JLabel passwordLabel = new JLabel();
    JPasswordField passwordField = new JPasswordField();
    JComboBox gradeComboBox = new JComboBox();
    JComboBox enterDateComboBox = new JComboBox();
    JComboBox endDateComboBox = new JComboBox();
    JLabel gradeLabel = new JLabel();
    JLabel enterDateLabel = new JLabel();
    JLabel endDateLabel = new JLabel();
    JLabel beginMoneyLabel = new JLabel();
    JLabel beginPointsLabel = new JLabel();
    JTextField beginMoneyField = new JTextField();
    JTextField beginPointsField = new JTextField();
    JLabel curMoneyLabel = new JLabel();
    JLabel curPointsLabel = new JLabel();
    JTextField curMoneyField = new JTextField();
    JTextField curPointsField = new JTextField();
    JLabel consumLabel = new JLabel();
    JLabel sumPointsLabel = new JLabel();
    JTextField consumField = new JTextField();
    JTextField sumPointsField = new JTextField();
    JLabel remarkLabel = new JLabel();
    JTextArea remarkArea = new JTextArea();
    Border border1 = BorderFactory.createEtchedBorder(EtchedBorder.RAISED,
        Color.white, new Color(178, 178, 178));
    JTable table = null;
    //简单的日期格式
    private static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    //DateChooser,用于日期的选择
    private static final DateChooser DATE_CHOOSER = new DateChooser((JFrame)null,"日期选择");
    Date birthday = new Date();//日期
    Date enterdate = new Date();
    Date enddate = new Date();

    public void cancelButton_actionPerformed(ActionEvent e) {
        //通过当前panel得到其所依附的JFrame,需要四次getParent()
        //从底层向上分别为:InsertPanel->JPanel->JLayeredPane->JRootPane->JFrame
        JFrame frame = (JFrame)this.getParent().getParent().getParent().getParent();
        frame.setVisible(false);
        frame.dispose();
    }

    public void saveButton_actionPerformed(ActionEvent e) {
        //获得新添加会员的各个属性
        String Mname = nameField.getText();
        String Msex = (String)(sexComboBox.getSelectedItem());
        String Mminzu = nationField.getText();
        String Mvipkind = (String)(memKindComboBox.getSelectedItem());
        String Mbirthday = "";//此处的日期值不起作用,仅作为声明
        String Munit = unitField.getText();
        String Maddress = addressField.getText();
        String Mpostcode = postcodeField.getText();
        String Mphone = phoneField.getText();
        String Moccu = careerField.getText();
        String Mmovephone = mobiliField.getText();
        String Mcertid = certcodeField.getText();
        String Memail = emailField.getText();
        String Mvipid = memNumField.getText();
        int Mvalid = validCheckBox.isSelected() ? 1 : 0;
        char[] pass = passwordField.getPassword();
        String Mpass = new String(pass);
        String Mgrade = (String)(gradeComboBox.getSelectedItem());
        String Menterdate = "";//此处的日期值不起作用,仅作为声明
        String Menddate = "";//此处的日期值不起作用,仅作为声明
        String Mbeginmoney = beginMoneyField.getText().length() == 0 ? "0" : beginMoneyField.getText();//如果未填写,则默认为"0"
        String Mcurmoney = curMoneyField.getText().length() == 0 ? "0" : curMoneyField.getText();
        String Msumcost = consumField.getText().length() == 0 ? "0" : consumField.getText();
        String Mbeginpoints = beginPointsField.getText().length() == 0 ? "0" : beginPointsField.getText();
        String Mcurpoints = curPointsField.getText().length() == 0 ? "0" : curPointsField.getText();
        String Msumpoints = sumPointsField.getText().length() == 0 ? "0" : sumPointsField.getText();
        String Mremark = remarkArea.getText().length() == 0 ? " " : remarkArea.getText();

        //连接数据库
        Connection conn = null;
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }
        catch (ClassNotFoundException ex) {
        }
        String dburl = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=db.mdb";
        try {
            conn = DriverManager.getConnection(dburl);
        } catch (SQLException ex1) {
        }

        Statement stmtUpdate = null;
        Statement stmtQuery = null;
        ResultSet  rs = null;
        try {
            stmtUpdate = conn.createStatement();
            stmtQuery = conn.createStatement();

            //更新数据库
            stmtUpdate.executeUpdate("insert into VIP (Name,Sex,MinZu,VIPID,VIPKind,Birthday,"
                              + "Unit,Address,postcode,Phone,Occu,MovePhone,CertID,Email,Valid,"
                              + "Pass,Grade,EnterDate,EndDate,BeginMoney,SumCost,"
                              + "BeginPoints,CurPoints,SumPoints,Mem) values "
                              + "('"+Mname+"','"+Msex+"','"+Mminzu+"','"+Mvipid+"','"+Mvipkind+"','"+DATE_FORMAT.format(birthday)+"',"
                              + "'"+Munit+"','"+Maddress+"','"+Mpostcode+"','"+Mphone+"','"+Moccu+"','"+Mmovephone+"','"+Mcertid+"','"+Memail+"','"+Mvalid+"',"
                              + "'"+Mpass+"','"+Mgrade+"','"+DATE_FORMAT.format(enterdate)+"','"+DATE_FORMAT.format(enddate)+"','"+Mbeginmoney+"','"+Msumcost+"',"
                              + "'"+Mbeginpoints+"','"+Mcurpoints+"','"+Msumpoints+"','"+Mremark+"')");

            //更新表
            Vector row = new Vector();//行

            rs = stmtQuery.executeQuery("select ID from VIP order by ID DESC");//获取当前最大ID值,即新加入对象的ID

            rs.next();
            String MID = rs.getString("ID");
            row.add(MID);

            row.add(Mname);
            row.add(Mvipid);
            row.add(Msex);
            row.add(Mgrade);
            row.add(Mphone);
            row.add(Mmovephone);
            row.add(DATE_FORMAT.format(birthday));
            row.add(Mvalid);
            row.add(Mpass);
            row.add(DATE_FORMAT.format(enterdate));
            row.add(DATE_FORMAT.format(enddate));
            row.add(Mbeginmoney);
            row.add(Mcurmoney);
            row.add(Msumcost);
            row.add(Mbeginpoints);
            row.add(Mcurpoints);
            row.add(Msumpoints);
            row.add(Mminzu);
            row.add(Munit);
            row.add(Maddress);
            row.add(Mpostcode);
            row.add(Moccu);
            row.add(Mcertid);
            row.add(Memail);

            DefaultTableModel tm = (DefaultTableModel)table.getModel();
            tm.addRow(row);
            table.repaint();

            conn.close();
        }catch (SQLException ex) {
            System.out.println(ex.getStackTrace());
        }
        //退出
        cancelButton_actionPerformed(e);
    }

    public void birthdayComboBox_actionPerformed(ActionEvent e) {
        DATE_CHOOSER.setLocation(birthdayComboBox.getX() + DATE_CHOOSER.getWidth() / 2,
                                 birthdayComboBox.getY() + DATE_CHOOSER.getHeight() / 2 + birthdayComboBox.getHeight());
        Date day = DATE_CHOOSER.select(birthday);
        if(day != null){
            birthdayComboBox.removeItemAt(0);
            birthdayComboBox.addItem(DATE_FORMAT.format(day));
            birthday = day;
        }
    }

    public void enterDateComboBox_actionPerformed(ActionEvent e) {
        DATE_CHOOSER.setLocation(enterDateComboBox.getX() + DATE_CHOOSER.getWidth() / 2,
                                 enterDateComboBox.getY() + DATE_CHOOSER.getHeight() / 2 + enterDateComboBox.getHeight());
        Date day = DATE_CHOOSER.select(enterdate);
        if(day != null){
            enterDateComboBox.removeItemAt(0);
            enterDateComboBox.addItem(DATE_FORMAT.format(day));
            enterdate = day;
        }
    }

    public void endDateComboBox_actionPerformed(ActionEvent e) {
        DATE_CHOOSER.setLocation(endDateComboBox.getX() + DATE_CHOOSER.getWidth() / 2,
                                 endDateComboBox.getY() + DATE_CHOOSER.getHeight() / 2 + endDateComboBox.getHeight());
        Date day = DATE_CHOOSER.select(enddate);
        if(day != null){
            endDateComboBox.removeItemAt(0);
            endDateComboBox.addItem(DATE_FORMAT.format(day));
            enddate = day;
        }
    }
}

class InsertPanel_endDateComboBox_actionAdapter
    implements ActionListener {
    private InsertPanel adaptee;
    InsertPanel_endDateComboBox_actionAdapter(InsertPanel adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.endDateComboBox_actionPerformed(e);
    }
}

class InsertPanel_enterDateComboBox_actionAdapter
    implements ActionListener {
    private InsertPanel adaptee;
    InsertPanel_enterDateComboBox_actionAdapter(InsertPanel adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.enterDateComboBox_actionPerformed(e);
    }
}

class InsertPanel_birthdayComboBox_actionAdapter
    implements ActionListener {
    private InsertPanel adaptee;
    InsertPanel_birthdayComboBox_actionAdapter(InsertPanel adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.birthdayComboBox_actionPerformed(e);
    }
}

class InsertPanel_saveButton_actionAdapter
    implements ActionListener {
    private InsertPanel adaptee;
    InsertPanel_saveButton_actionAdapter(InsertPanel adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.saveButton_actionPerformed(e);
    }
}

class InsertPanel_cancelButton_actionAdapter
    implements ActionListener {
    private InsertPanel adaptee;
    InsertPanel_cancelButton_actionAdapter(InsertPanel adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.cancelButton_actionPerformed(e);
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -