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

📄 classinfopanel.java

📁 使用JBuilder基于Oracle数据库的课程作业
💻 JAVA
字号:
package StudentManageSystem.factionpanels.infopanel;

import com.borland.jbcl.layout.XYConstraints;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import StudentManageSystem.link.SQLRunner;
import java.sql.ResultSet;
import javax.swing.JOptionPane;
import java.sql.SQLException;
import javax.swing.JTextArea;

public class ClassInfoPanel extends InfoPanel {
    public ClassInfoPanel(boolean e){
        try {
            initialize(e);//初始化父类
        } catch (Exception ex) {
        }
    }

    protected void initialize(boolean e){
        try {
            super.initialize(e);

        } catch (Exception ex) {
        }
        jLabel1.setText("班级名");
        jTextField_clname.setText("jTextField1");
        jLabel2.setText("班级编号");
        jTextField_class_no.setText("jTextField2");
        jLabel4.setText("班长");
        jLabel6.setToolTipText("");
        jLabel6.setText("班主任");
        jLabel5.setText("系");
        this.add(jLabel1, new XYConstraints(56, 45, 82, 38));
        this.add(jTextField_clname, new XYConstraints(128, 53, 95, 29));
        this.add(jTextField_class_no, new XYConstraints(427, 52, 96, 30));
        this.add(jLabel2, new XYConstraints(318, 52, 80, 31));
        this.add(jLabel5, new XYConstraints(55, 111, 56, 31));
        this.add(jComboBox_dpname, new XYConstraints(128, 109, 208, 35));
        this.add(jLabel6, new XYConstraints(56, 173, 71, 37));
        this.add(jComboBox_tname, new XYConstraints(128, 175, 163, 32));
        this.add(jLabel4, new XYConstraints(56, 246, 67, 33));
        this.add(jComboBox_sname, new XYConstraints(128, 249, 211, 37));
    }

    public void setSwingEnable(boolean e) {
        jTextField_clname.setEnabled(e);
        jTextField_class_no.setEnabled(e);
        jComboBox_tname.setEnabled(e);
        jComboBox_sname.setEnabled(e);
        jComboBox_dpname.setEnabled(e);
    }

    public boolean delete() {
        return SQLRunner.executSql("delete from class where class_no='"+keyValue+"'");
    }

    public boolean update() {
        try{
            String depart_no;
            if(jComboBox_dpname.getSelectedItem()==null){
                JOptionPane.showMessageDialog(null,"系不能为空","系统提示",JOptionPane.ERROR_MESSAGE);
                return false;
            }else{
                String dpname=(String)(jComboBox_dpname.getSelectedItem());
                ResultSet rs=SQLRunner.getResult("select distinct * from department where dpname='"+dpname+"'");
                if(!rs.next())return false;//System.out.println("can't find clname");
                depart_no=rs.getString("depart_no").trim();//不该不抱错
            }
            String teacher_no;
             if(jComboBox_tname.getSelectedItem()==null){
                 teacher_no="";
                 //return false;
             }else{
                 String tname=(String)(jComboBox_tname.getSelectedItem());
                 ResultSet rs=SQLRunner.getResult("select distinct * from teacher where tname='"+tname+"'");
                 if(!rs.next())return false;//System.out.println("can't find clname");
                 teacher_no=rs.getString("teacher_no").trim();//不该不抱错
             }
             String stu_no;
             if(jComboBox_sname.getSelectedItem()==null){
                 stu_no="";
                 //return false;
             }else{
                 String sname=(String)(jComboBox_sname.getSelectedItem());
                 ResultSet rs=SQLRunner.getResult("select distinct * from student where sname='"+sname+"'");
                 if(!rs.next())return false;//System.out.println("can't find clname");
                 stu_no=rs.getString("stu_no").trim();//不该不抱错
             }
             String clname= jTextField_clname.getText().trim();
             String class_no= jTextField_class_no.getText().trim();
             //String phone=jTextField_sname.getText().trim();
             //String introduction= .trim();
             String updatesql="update class set clname='"+clname+"',monitor='"+stu_no+"',depart_no='"+depart_no+"',manager='"+teacher_no+"' where class_no='"+class_no+"'";
             return SQLRunner.executSql(updatesql);
         }catch(Exception e){
             JOptionPane.showMessageDialog(null,e.toString(),"系统提示",JOptionPane.ERROR_MESSAGE);
             return false;
         }


    }

    public void setAllInfo(String keyValue) {
        updateModel=true;//
         this.keyValue=keyValue;//
         jButton_remove.setVisible(enable);
         //jTextField_class_no.setEditable(false);
         try {
             //rs.next();
             ResultSet rs=SQLRunner.getResult("select distinct * from department,class,college where department.college_no=college.college_no and class.depart_no=department.depart_no and class_no='"+keyValue+"'");
             if(!rs.next())return;
             addItem(jComboBox_dpname,"select distinct dpname from department,college where department.college_no='"+rs.getString("college_no")+"' group by dpname","dpname");//addItem示例,从制定表
            jComboBox_dpname.setSelectedItem(rs.getString("dpname"));//
             addItem(jComboBox_tname,"select distinct tname from teacher,department,class where class.depart_no=department.depart_no and department.college_no=teacher.college_no and class_no='"+keyValue+"'","tname");
            addItem(jComboBox_sname,"select distinct sname from student where class_no='"+keyValue+"'","sname");
             jTextField_class_no.setText(rs.getString("class_no"));
            jTextField_clname.setText(rs.getString("clname").trim());

             ResultSet rst=SQLRunner.getResult("select sname from student where stu_no='"+rs.getString("monitor")+"'");
             if(rst.next()){
                 jComboBox_sname.setSelectedItem(rst.getString("sname"));
             }else{
                 jComboBox_sname.setSelectedItem(null);
             }
             ResultSet rsp=SQLRunner.getResult("select tname from teacher where teacher_no='"+rs.getString("manager")+"'");
             if(rsp.next()){
                 jComboBox_tname.setSelectedItem(rsp.getString("tname"));
             }else{
                 jComboBox_tname.setSelectedItem(null);
             }



             //if(!rss.next())return;
             //jLabel_coname.setText(rss.getString("coname"));
         } catch (SQLException ex) {
             System.out.print(ex.toString());
         }

    }


    public void setAllNew() {
        jButton_remove.setVisible(false);

        try {
            jTextField_clname.setText("");
        jTextField_class_no.setText("");
        jComboBox_tname.setSelectedItem(null);
        ResultSet rs=SQLRunner.getResult("select distinct * from class,department,college where class.depart_no=department.depart_no and department.college_no=college.college_no");
            if (!rs.next()) {
                return;
            }
            addItem(jComboBox_dpname,"select distinct * from department where college_no='"+rs.getString("college_no")+"'","dpname");
        jComboBox_dpname.setSelectedItem(null);
        jComboBox_sname.removeAllItems();
        } catch (SQLException ex) {
        }

    }

    JLabel jLabel1 = new JLabel();
    JTextField jTextField_clname = new JTextField();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField_class_no = new JTextField();
    JLabel jLabel4 = new JLabel();
    JLabel jLabel6 = new JLabel();
    JComboBox jComboBox_tname = new JComboBox();
    JLabel jLabel5 = new JLabel();
    JComboBox jComboBox_dpname = new JComboBox();
    JComboBox jComboBox_sname = new JComboBox();
    public boolean insert() {
        try{
            String depart_no;
            if(jComboBox_dpname.getSelectedItem()==null){
                JOptionPane.showMessageDialog(null,"系不能为空","系统提示",JOptionPane.ERROR_MESSAGE);
                return false;
            }else{
                String dpname=(String)(jComboBox_dpname.getSelectedItem());
                ResultSet rs=SQLRunner.getResult("select distinct * from department where dpname='"+dpname+"'");
                if(!rs.next())return false;//System.out.println("can't find clname");
                depart_no=rs.getString("depart_no").trim();//不该不抱错
            }
            String teacher_no;
             if(jComboBox_tname.getSelectedItem()==null){
                 teacher_no="";
                 //return false;
             }else{
                 String tname=(String)(jComboBox_tname.getSelectedItem());
                 ResultSet rs=SQLRunner.getResult("select distinct * from teacher where tname='"+tname+"'");
                 if(!rs.next())return false;//System.out.println("can't find clname");
                 teacher_no=rs.getString("teacher_no").trim();//不该不抱错
             }
             String stu_no;
             if(jComboBox_sname.getSelectedItem()==null){
                 stu_no="";
                 //return false;
             }else{
                 String sname=(String)(jComboBox_sname.getSelectedItem());
                 ResultSet rs=SQLRunner.getResult("select distinct * from student where sname='"+sname+"'");
                 if(!rs.next())return false;//System.out.println("can't find clname");
                 stu_no=rs.getString("stu_no").trim();//不该不抱错
             }
             String clname= jTextField_clname.getText().trim();
             String class_no= jTextField_class_no.getText().trim();
             String insertsql="insert into class(depart_no,clname,manager,monitor,class_no) values('"+depart_no+"','"+clname+"','"+teacher_no+"','"+stu_no+"','"+class_no+"')";

             return SQLRunner.executSql(insertsql);
         }catch(Exception e){
             JOptionPane.showMessageDialog(null,e.toString(),"系统提示",JOptionPane.ERROR_MESSAGE);
             return false;
         }


    }

}

⌨️ 快捷键说明

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