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

📄 classupdate.java~6~

📁 java语言做的教务管理系统
💻 JAVA~6~
📖 第 1 页 / 共 2 页
字号:
            this.cbobeginstimemonth.getSelectedItem().toString() + "-" +
            this.cbobeginstimedate.getSelectedItem().toString() + " ";

    //毕业时间
    String endtimename =
            this.cboendtimeyear.getSelectedItem().toString() + "-" +
            this.cboendtimemonth.getSelectedItem().toString() + "-" +
            this.cboendtimedate.getSelectedItem().toString() + " ";

    public void btnclassselect_actionPerformed(ActionEvent e) {
        try {
            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection nod = DriverManager.getConnection("jdbc:odbc:studer");
            String daima = "select classno,classmastername,classcategory,classSemester,beginstime,endtime,classRemarks from class where 1=1";
            if (!this.txtclassno.getText().equals("")) {
                daima += " and classno = '" + this.txtclassno.getText() + "'";
            }
            if (!this.txtclassmastername.getText().equals("")) {
                daima += " and classmastername ='" +
                        this.txtclassmastername.getText() + "'";
            }
            if (!categoryname.equals("")) {
                daima += " and classcategory ='" + categoryname + "'";
            }
            if (!Semestername.equals("")) {
                daima += " and classSemester='" + Semestername + "'";
            }
            if (!beginstimenameyear.equals("")) {
                daima += " and beginstime like '%" + beginstimenameyear + "%'";
            }
            if (!beginstimenamemonth.equals("")) {
                daima += " and beginstime like '%" + beginstimenamemonth + "%'";
            }
            if (!beginstimenamedate.equals("")) {
                daima += " and beginstime like '%" + beginstimenamedate + "%'";
            }
            if (!endtimenameyear.equals("")) {
                daima += " and endtime like '%" + endtimenameyear + "%'";
            }
            if (!endtimenamemonth.equals("")) {
                daima += " and endtime like '%" + endtimenamemonth + "%'";
            }
            if (!endtimenamedate.equals("")) {
                daima += " and endtime like '%" + endtimenamedate + "%'";
            }
            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)};
                mod.addRow(j);
            }
            tbclass.updateUI();
            i.close();
            sql.close();
            nod.close();
        } catch (Exception ex) {

        }
    }

    public void tbclass_mouseClicked(MouseEvent e) {
        int row = this.tbclass.getSelectedRow();
        if (row > -1) {
            this.txtclassno.setText(this.tbclass.getValueAt(row, 0).toString());
            this.txtclassmastername.setText(this.tbclass.getValueAt(row, 1).
                                            toString());
            this.cboclasscategory.setSelectedItem(this.tbclass.getValueAt(row,
                    2).
                                                  toString());
            this.cboclassSemester.setSelectedItem(this.tbclass.getValueAt(row,
                    3).toString());
            String beginstime = this.tbclass.getValueAt(row, 4).toString();
            this.cbobeginstimeyear.setSelectedItem(beginstime.substring(0, 4));
            this.cbobeginstimemonth.setSelectedItem(beginstime.substring(5, 7));
            this.cbobeginstimedate.setSelectedItem(beginstime.substring(8, 10));
            String endtime = this.tbclass.getValueAt(row, 5).toString();
            this.cboendtimeyear.setSelectedItem(endtime.substring(0, 4));
            this.cboendtimemonth.setSelectedItem(endtime.substring(5, 7));
            this.cboendtimedate.setSelectedItem(endtime.substring(8, 10));
            this.txaclassRemarks.setText(this.tbclass.getValueAt(row, 6).
                                         toString());
        }
    }

    public void btnclassupdate_actionPerformed(ActionEvent e) {
        try {
            if (this.txtclassno.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入班级编号");
                return;
            }
            if (this.txtclassmastername.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入班级主任姓名");
                return;
            }
            if (this.cboclasscategory.getSelectedItem().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入班级类别");
                return;
            }
            if (this.cboclassSemester.getSelectedItem().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入班级学期");
                return;
            }
            if (cbobeginstimeyear.equals("")) {
                JOptionPane.showMessageDialog(this, "请输入开学日期");
                return;
            }
            /*if(endtimename.equals("")){
                JOptionPane.showMessageDialog(this,"请输入毕业日期");
                 }
             */
            //班级类别classcategory
            String categoryname = this.cboclasscategory.getSelectedItem().
                                  toString();
            //学期classSemester
            String Semestername = this.cboclassSemester.getSelectedItem().
                                  toString();
            //开学时间(年,月,日)
            String beginstimenameyear = this.cbobeginstimeyear.getSelectedItem().
                                        toString();
            String beginstimenamemonth = this.cbobeginstimemonth.
                                         getSelectedItem().
                                         toString();
            String beginstimenamedate = this.cbobeginstimedate.getSelectedItem().
                                        toString();
            //毕业时间(年,月,日)
            String endtimenameyear = this.cboendtimeyear.getSelectedItem().
                                     toString();
            String endtimenamemonth = this.cboendtimemonth.getSelectedItem().
                                      toString();
            String endtimenamedate = this.cboendtimedate.getSelectedItem().
                                     toString();
            //开学时间
            String beginstimename =
                    this.cbobeginstimeyear.getSelectedItem().toString() + "-" +
                    this.cbobeginstimemonth.getSelectedItem().toString() + "-" +
                    this.cbobeginstimedate.getSelectedItem().toString() + " ";
            //毕业时间
            String endtimename =
                    this.cboendtimeyear.getSelectedItem().toString() + "-" +
                    this.cboendtimemonth.getSelectedItem().toString() + "-" +
                    this.cboendtimedate.getSelectedItem().toString() + " ";

            Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
            Connection nod = DriverManager.getConnection("jdbc:odbc:studer");
            PreparedStatement sql = nod.prepareStatement(
                    "update class set classno=?,classmastername=?,classcategory=?,classSemester=?,beginstime=?,endtime=?,classRemarks=? where classno ='" +
                    this.txtclassno.getText() + "'");
            sql.setString(1, this.txtclassno.getText());
            sql.setString(2, this.txtclassmastername.getText());
            sql.setString(3, categoryname);
            sql.setString(4, Semestername);
            sql.setString(5, beginstimename);
            sql.setString(6, endtimename);
            sql.setString(7, this.txaclassRemarks.getText());
            int i = sql.executeUpdate();
            int row = tbclass.getSelectedRow();
            if (i > 0) {
                tbclass.setValueAt(this.txtclassmastername.getText(), row, 1);
                tbclass.setValueAt(categoryname, row, 2);
                tbclass.setValueAt(Semestername, row, 3);
                tbclass.setValueAt(beginstimename, row, 4);
                tbclass.setValueAt(endtimename, row, 5);
                tbclass.setValueAt(this.txaclassRemarks.getText(), row, 6);
                JOptionPane.showMessageDialog(this, "修改成功");
            } else {
                JOptionPane.showMessageDialog(this, "修改失败");
            }
            sql.close();
            nod.close();
        } catch (Exception ex) {
        }
    }
}


class classupdate_tbclass_mouseAdapter extends MouseAdapter {
    private classupdate adaptee;
    classupdate_tbclass_mouseAdapter(classupdate adaptee) {
        this.adaptee = adaptee;
    }

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


class classupdate_btnclassupdate_actionAdapter implements ActionListener {
    private classupdate adaptee;
    classupdate_btnclassupdate_actionAdapter(classupdate adaptee) {
        this.adaptee = adaptee;
    }

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


class classupdate_btnclassselect_actionAdapter implements ActionListener {
    private classupdate adaptee;
    classupdate_btnclassselect_actionAdapter(classupdate adaptee) {
        this.adaptee = adaptee;
    }

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

⌨️ 快捷键说明

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