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

📄 teacherinfopanel.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;

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

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

        } catch (Exception ex) {
        }
        jLabel1.setText("姓名");
        jTextField_tname.setText("jTextField1");
        jLabel2.setText("职工号");
        jTextField_teacher_no.setText("jTextField2");
        jLabel3.setText("性别");
        jLabel4.setText("联系电话");
        jTextField_phone.setText("jTextField3");
        jLabel5.setText("职称");
        jLabel6.setText("学院");
        this.add(jLabel1, new XYConstraints(56, 45, 82, 38));
        this.add(jTextField_tname, new XYConstraints(128, 53, 95, 29));
        this.add(jLabel2, new XYConstraints(297, 51, 80, 31));
        this.add(jTextField_teacher_no, new XYConstraints(427, 52, 96, 30));
        this.add(jLabel3, new XYConstraints(56, 113, 60, 31));
        this.add(jComboBox_sex, new XYConstraints(128, 115, 96, 31));
        this.add(jLabel5, new XYConstraints(297, 113, 65, 34));
        this.add(jLabel6, new XYConstraints(57, 176, 71, 37));
        this.add(jComboBox_coname, new XYConstraints(128, 181, 163, 32));
        this.add(jLabel4, new XYConstraints(56, 241, 67, 33));
        this.add(jTextField_phone, new XYConstraints(128, 243, 180, 32));
        this.add(jComboBox_post, new XYConstraints(427, 116, 145, 32));
    }

    public void setSwingEnable(boolean e) {
        jTextField_tname.setEnabled(e);
        jTextField_teacher_no.setEnabled(e);
        jComboBox_sex.setEnabled(e);
        jTextField_phone.setEnabled(e);
        jComboBox_post.setEnabled(e);
        jComboBox_coname.setEnabled(e);
    }

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

    public boolean update() {
         try{
           String college_no;
            if(jComboBox_coname.getSelectedItem()==null){
                JOptionPane.showMessageDialog(null,"学院不能为空","系统提示",JOptionPane.ERROR_MESSAGE);
                return false;
            }else{
                String coname=(String)(jComboBox_coname.getSelectedItem());
                ResultSet rs=SQLRunner.getResult("select * from college where coname='"+coname+"'");
                if(!rs.next())return false;//System.out.println("can't find clname");
                college_no=rs.getString("college_no").trim();//不该不抱错
            }
            String tname= jTextField_tname.getText().trim();
            String teacher_no=jTextField_teacher_no.getText().trim();
            String phone=jTextField_phone.getText().trim();
            String sex;
            if(jComboBox_sex.getSelectedItem()==null){
                JOptionPane.showMessageDialog(null,"性别不能为空","系统提示",JOptionPane.ERROR_MESSAGE);
                return false;
            }else{
                sex=((String)jComboBox_sex.getSelectedItem()).trim();
            }String post;
            if(jComboBox_post.getSelectedItem()==null){
                post="";
            }else{
                post=((String)jComboBox_post.getSelectedItem()).trim();
            }String updatesql="update teacher set college_no='"+college_no+"',post='"+post+"',sex='"+sex+"',phone='"+phone+"',tname='"+tname+"' where teacher_no='"+teacher_no+"'";
            return SQLRunner.executSql(updatesql);
        }catch(Exception e){
            JOptionPane.showMessageDialog(null,e.toString(),"系统提示",JOptionPane.ERROR_MESSAGE);
            return false;
        }
    }

    public boolean insert() {
        try{
           String college_no;
            if(jComboBox_coname.getSelectedItem()==null){
                JOptionPane.showMessageDialog(null,"学院不能为空","系统提示",JOptionPane.ERROR_MESSAGE);
                return false;
            }else{
                String coname=(String)(jComboBox_coname.getSelectedItem());
                ResultSet rs=SQLRunner.getResult("select * from college where coname='"+coname+"'");
                if(!rs.next())return false;//System.out.println("can't find clname");
                college_no=rs.getString("college_no").trim();//不该不抱错
            }
            String tname= jTextField_tname.getText().trim();
            String teacher_no=jTextField_teacher_no.getText().trim();
            String phone=jTextField_phone.getText().trim();
            String sex;
            if(jComboBox_sex.getSelectedItem()==null){
                JOptionPane.showMessageDialog(null,"性别不能为空","系统提示",JOptionPane.ERROR_MESSAGE);
                return false;
            }else{
                sex=((String)jComboBox_sex.getSelectedItem()).trim();
            }String post;
            if(jComboBox_post.getSelectedItem()==null){
                post="";
            }else{
                post=((String)jComboBox_post.getSelectedItem()).trim();
            }String insertsql="insert into teacher(teacher_no,tname,sex,phone,post,college_no) values('"+teacher_no+"','"+tname+"','"+sex+"','"+phone+"','"+post+"','"+college_no+"')";
            return SQLRunner.executSql(insertsql);
        }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);

        try {
            //rs.next();
            ResultSet rs=SQLRunner.getResult("select * from teacher,college where teacher.college_no=college.college_no and teacher_no='"+keyValue+"'");
            if(!rs.next())return;
            addItemFromDic(jComboBox_sex,"sex");//从字典加
            jComboBox_sex.setSelectedItem(rs.getString("sex"));
            addItemFromDic(jComboBox_post,"post");
            jComboBox_post.setSelectedItem(rs.getString("post"));
            addItem(jComboBox_coname,"select * from college","coname");//addItem示例,从制定表
            jComboBox_coname.setSelectedItem(rs.getString("coname"));//
            jTextField_phone.setText(rs.getString("phone"));
            jTextField_teacher_no.setText(rs.getString("teacher_no"));
            jTextField_tname.setText(rs.getString("tname"));
        } catch (SQLException ex) {
            System.out.print(ex.toString());
        }
    }


    public void setAllNew() {
        jButton_remove.setVisible(false);
        addItem(jComboBox_coname,"select * from college","coname");
        addItemFromDic(jComboBox_post,"post");
        addItemFromDic(jComboBox_sex,"sex");
        jComboBox_coname.setSelectedItem(null);
        jComboBox_post.setSelectedItem(null);
        jComboBox_sex.setSelectedItem(null);
        jTextField_tname.setText("");
        jTextField_teacher_no.setText("");
        jTextField_phone.setText("");
    }

    JLabel jLabel1 = new JLabel();
    JTextField jTextField_tname = new JTextField();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField_teacher_no = new JTextField();
    JLabel jLabel3 = new JLabel();
    JComboBox jComboBox_sex = new JComboBox();
    JLabel jLabel4 = new JLabel();
    JTextField jTextField_phone = new JTextField();
    JLabel jLabel5 = new JLabel();
    JComboBox jComboBox_post = new JComboBox();
    JLabel jLabel6 = new JLabel();
    JComboBox jComboBox_coname = new JComboBox();

}

⌨️ 快捷键说明

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