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

📄 stuupdate.java~13~

📁 java语言做的教务管理系统
💻 JAVA~13~
📖 第 1 页 / 共 2 页
字号:

    //性别
    String stusexname = this.cbostusex.getSelectedItem().toString();

    //出生日期
    String stubirthdaytime =
            this.cbostubirthdayyear.getSelectedItem().toString() + "-" +
            this.cbostubirthdaymonth.getSelectedItem().toString() + "-" +
            this.cbostubirthdaydate.getSelectedItem().toString() + " ";

    JTableHeader jTableHeader1 = tbstu.getTableHeader();
    JComboBox cboclassno = new JComboBox();
    public void btnstuselect_actionPerformed(ActionEvent e) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection nod = DriverManager.getConnection("jdbc:odbc:studer");
            String daima =
                    "select stuno,stuname,stusex,stuclassno,stuidcard,stubirthday,stuaddress,stuphoto,stuschool,stubackground,stuappearance,sturemarks from stu where 1=1";
            if (!this.txtstuno.getText().equals("")) {
                daima += " and stuno = '" + this.txtstuno.getText() + "'";
            }
            if (!this.txtstuname.getText().equals("")) {
                daima += " and stuname ='" +
                        this.txtstuname.getText() + "'";
            }
            if (!stusexname.equals("")) {
                daima += " and stusex ='" + stusexname + "'";
            }
            if (!this.txtstuidcard.getText().equals("")) {
                daima += " and stuidcard ='" + this.txtstuidcard.getText() +
                        "'";
            }
            if (!this.cboclassno.getSelectedItem().toString().equals("")) {
                daima += " and stuclassno = '" +
                        this.cboclassno.getSelectedItem().toString() + "'";
            }
            if (!this.cbostubirthdayyear.getSelectedItem().toString().equals("")) {
                daima += " and stubirthday like '%" +
                        this.cbostubirthdayyear.getSelectedItem().toString() +
                        "%'";
            }
            if (!this.cbostubirthdaymonth.getSelectedItem().toString().equals(
                    "")) {
                daima += " and stubirthday like '%" +
                        this.cbostubirthdaymonth.getSelectedItem().toString() +
                        "%'";
            }
            if (!this.cbostubirthdaydate.getSelectedItem().toString().equals("")) {
                daima += " and stubirthday like '%" +
                        this.cbostubirthdaydate.getSelectedItem().toString() +
                        "%'";
            }
            if (!this.txtstuaddress.getText().equals("")) {
                daima += " and stuaddress like '%" + this.txtstuaddress.getText() +
                        "%'";
            }
            if (!this.txtstuphoto.getText().equals("")) {
                daima += " and stuphoto like '%" + this.txtstuphoto.getText() +
                        "%'";
            }
            if (!this.txtstuschool.getText().equals("")) {
                daima += " and stuschool like '%" + this.txtstuschool.getText() +
                        "%'";
            }
            if (!this.cbostubackground.getSelectedItem().toString().equals("")) {
                daima += " and stubackground ='" +
                        this.cbostubackground.getSelectedItem().toString() +
                        "'";
            }
            if (!this.cbostuappearance.getSelectedItem().toString().equals("")) {
                daima += " and stuappearance = '" +
                        this.cbostuappearance.getSelectedItem().toString() +
                        "'";
            }
            if (!this.txasturemarks.getText().toString().equals("")) {
                daima += " and sturemarks like '%" +
                        this.txasturemarks.getText().toString() + "%'";
            }

            PreparedStatement sql = nod.prepareStatement(daima);
            ResultSet i = sql.executeQuery();
            mod.setNumRows(0);
            while (i.next()) {
                Object j[] = {i.getString(1), i.getString(2), i.getString(3),
                             i.getString(4), i.getString(5), i.getString(6),
                             i.getString(7), i.getString(8), i.getString(9),
                             i.getString(10), i.getString(11), i.getString(12)};
                mod.addRow(j);
            }
            tbstu.updateUI();
            i.close();
            sql.close();
            nod.close();
        } catch (Exception ex) {

        }
    }

    public void tbstu_mouseClicked(MouseEvent e) {
        int row = this.tbstu.getSelectedRow();
        if (row > -1) {
            this.txtstuno.setText(this.tbstu.getValueAt(row, 0).toString());
            this.txtstuname.setText(this.tbstu.getValueAt(row, 1).toString());
            this.cbostusex.setSelectedItem(this.tbstu.getValueAt(row, 2).
                                           toString());
            this.cboclassno.setSelectedItem(this.tbstu.getValueAt(row, 3).
                                            toString());
            this.txtstuidcard.setText(this.tbstu.getValueAt(row, 4).toString());
            String stubirthday = this.tbstu.getValueAt(row, 5).toString();
            this.cbostubirthdayyear.setSelectedItem(stubirthday.substring(0, 4));
            this.cbostubirthdaymonth.setSelectedItem(stubirthday.substring(5, 7));
            this.cbostubirthdaydate.setSelectedItem(stubirthday.substring(8, 10));
            this.txtstuaddress.setText(this.tbstu.getValueAt(row, 6).toString());
            this.txtstuphoto.setText(this.tbstu.getValueAt(row, 7).toString());
            this.txtstuschool.setText(this.tbstu.getValueAt(row, 8).toString());
            this.cbostubackground.setSelectedItem(this.tbstu.getValueAt(row, 9).
                                                  toString());
            this.cbostuappearance.setSelectedItem(this.tbstu.getValueAt(row, 10).
                                                  toString());
            this.txasturemarks.setText(this.tbstu.getValueAt(row, 11).toString());
        }
    }

    public void btnstuupdate_actionPerformed(ActionEvent e) {
        try {
            //性别stusex
            String sexname = this.cbostusex.getSelectedItem().
                             toString();
            //状态
            String stuappearancename = this.cbostuappearance.getSelectedItem().
                                       toString();
            //出生日期
            String stubirthdaytime =
                    this.cbostubirthdayyear.getSelectedItem().toString() + "-" +
                    this.cbostubirthdaymonth.getSelectedItem().toString() + "-" +
                    this.cbostubirthdaydate.getSelectedItem().toString() + " ";
            if (this.txtstuno.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入学号");
                return;
            }
            if (this.txtstuname.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入姓名");
                return;
            }
            if (sexname.equals("")) {
                JOptionPane.showMessageDialog(this, "请输入性别");
                return;
            }
            if (this.cboclassno.getSelectedItem().toString().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入班级编号");
                return;
            }
            if (stuappearancename.equals("")) {
                JOptionPane.showMessageDialog(this, "请输入状态");
                return;
            }
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection nod = DriverManager.getConnection("jdbc:odbc:studer");
            PreparedStatement sql = nod.prepareStatement(
                    "update stu set stuno=?,stuname=?,stusex=?,stuclassno=?,stuidcard=?,stubirthday=?,stuaddress=?,stuphoto=?,stuschool=?, stubackground=?,stuappearance=?,sturemarks=? where stuno ='" +
                    this.txtstuno.getText() + "'");
            sql.setString(1, this.txtstuno.getText());
            sql.setString(2, this.txtstuname.getText());
            sql.setString(3, sexname);
            sql.setString(4, this.cboclassno.getSelectedItem().toString());
            sql.setString(5, this.txtstuidcard.getText());
            sql.setString(6, stubirthdaytime);
            sql.setString(7, this.txtstuaddress.getText());
            sql.setString(8, this.txtstuphoto.getText());
            sql.setString(9, this.txtstuschool.getText());
            sql.setString(10, this.cbostubackground.getSelectedItem().toString());
            sql.setString(11, stuappearancename);
            sql.setString(12, this.txasturemarks.getText());
            int i = sql.executeUpdate();
            int row = tbstu.getSelectedRow();
            if (i > 0) {
                tbstu.setValueAt(this.txtstuname.getText(), row, 1);
                tbstu.setValueAt(sexname, row, 2);
                tbstu.setValueAt(this.cboclassno.getSelectedItem().toString(),
                                 row, 3);
                tbstu.setValueAt(this.txtstuidcard.getText(), row, 4);
                tbstu.setValueAt(stubirthdaytime, row, 5);
                tbstu.setValueAt(this.txtstuaddress.getText(), row, 6);
                tbstu.setValueAt(this.txtstuphoto.getText(), row, 7);
                tbstu.setValueAt(this.txtstuschool.getText(), row, 8);
                tbstu.setValueAt(this.cbostubackground.getSelectedItem().
                                 toString(), row, 9);
                tbstu.setValueAt(stuappearancename, row, 10);
                tbstu.setValueAt(this.txasturemarks.getText(), row, 11);
                JOptionPane.showMessageDialog(this, "修改成功");
            } else {
                JOptionPane.showMessageDialog(this, "修改失败");
            }
            sql.close();
            nod.close();
        } catch (Exception ex) {
        }
    }
}


class stuupdate_tbstu_mouseAdapter extends MouseAdapter {
    private stuupdate adaptee;
    stuupdate_tbstu_mouseAdapter(stuupdate adaptee) {
        this.adaptee = adaptee;
    }

    public void mouseClicked(MouseEvent e) {
        adaptee.tbstu_mouseClicked(e);
    }
}


class stuupdate_btnstuupdate_actionAdapter implements ActionListener {
    private stuupdate adaptee;
    stuupdate_btnstuupdate_actionAdapter(stuupdate adaptee) {
        this.adaptee = adaptee;
    }

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


class stuupdate_btnstuselect_actionAdapter implements ActionListener {
    private stuupdate adaptee;
    stuupdate_btnstuselect_actionAdapter(stuupdate adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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