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

📄 departmentinfopanel.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 DepartmentInfoPanel extends InfoPanel {
    public DepartmentInfoPanel(boolean e){
        try {
            initialize(e);//初始化父类
        } catch (Exception ex) {
        }
    }

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

        } catch (Exception ex) {
        }
        jLabel1.setText("系名");
        jTextField_dpname.setText("jTextField1");
        jLabel2.setText("系编号");
        jTextField_depart_no.setText("jTextField2");
        jLabel4.setText("联系电话");
        jTextField_phone.setText("jTextField3");
        jLabel6.setToolTipText("");
        jLabel6.setText("系主任");
        jLabel3.setText("简介");
        jTextArea_introduction.setText("jTextArea1");
        jLabel5.setText("学院");
        this.add(jLabel1, new XYConstraints(56, 45, 82, 38));
        this.add(jTextField_dpname, new XYConstraints(128, 53, 95, 29));
        this.add(jTextField_depart_no, new XYConstraints(427, 52, 96, 30));
        this.add(jLabel6, new XYConstraints(56, 112, 71, 37));
        this.add(jComboBox_tname, new XYConstraints(128, 113, 163, 32));
        this.add(jLabel4, new XYConstraints(54, 169, 67, 33));
        this.add(jTextField_phone, new XYConstraints(128, 167, 180, 32));
        this.add(jLabel3, new XYConstraints(54, 213, 58, 31));
        this.add(jTextArea_introduction, new XYConstraints(126, 221, 396, 108));
        this.add(jLabel2, new XYConstraints(318, 52, 80, 31));
        this.add(jLabel5, new XYConstraints(316, 112, 56, 31));
        this.add(jComboBox_coname, new XYConstraints(364, 112, 208, 35));
    }

    public void setSwingEnable(boolean e) {
        jTextField_dpname.setEnabled(e);
        jTextField_depart_no.setEnabled(e);
        jTextField_phone.setEnabled(e);
        jComboBox_tname.setEnabled(e);
        jTextArea_introduction.setEnabled(e);
        jComboBox_coname.setEnabled(e);
    }

    public boolean delete() {
        return SQLRunner.executSql("delete from department where depart_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 teacher_no;
             if(jComboBox_tname.getSelectedItem()==null){
                 teacher_no="";
                 //return false;
             }else{
                 String tname=(String)(jComboBox_tname.getSelectedItem());
                 ResultSet rs=SQLRunner.getResult("select * 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 coname= jTextField_dpname.getText().trim();
             String depart_no= jTextField_depart_no.getText().trim();
             String phone=jTextField_phone.getText().trim();
             String introduction=jTextArea_introduction.getText().trim();
             String updatesql="update department set DEPART_HEADER='"+teacher_no+"',dphone='"+phone+"',dpname='"+coname+"',INRTODUCTION='"+introduction+"' where depart_no='"+depart_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);

         try {
             //rs.next();
             ResultSet rs=SQLRunner.getResult("select * from department,college where department.college_no=college.college_no and depart_no='"+keyValue+"'");
             if(!rs.next())return;
             addItem(jComboBox_coname,"select * from college","coname");//addItem示例,从制定表
             jComboBox_coname.setSelectedItem(rs.getString("coname"));//
             addItem(jComboBox_tname,"select distinct tname from teacher,department where department.college_no=teacher.college_no and depart_no='"+keyValue+"'","tname");
             jTextField_phone.setText(rs.getString("dphone"));
             jTextField_depart_no.setText(rs.getString("depart_no"));
             jTextField_dpname.setText(rs.getString("dpname").trim());
             jTextArea_introduction.setText(rs.getString("INRTODUCTION"));
             ResultSet rss=SQLRunner.getResult("select * from college where college_no='"+rs.getString("depart_no")+"'");
             ResultSet rpt=SQLRunner.getResult("select distinct * from teacher,department where teacher.teacher_no=department.DEPART_HEADER and department.depart_no='"+keyValue+"'");
             if(rpt.next()){
                 jComboBox_tname.setSelectedItem(rpt.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);

        jTextField_dpname.setText("");
        jTextField_depart_no.setText("");
        jTextField_phone.setText("");
        jComboBox_tname.setSelectedItem(null);
        jTextArea_introduction.setText("");
        addItem(jComboBox_coname,"select * from college","coname");
        jComboBox_coname.setSelectedItem(null);
    }

    JLabel jLabel1 = new JLabel();
    JTextField jTextField_dpname = new JTextField();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField_depart_no = new JTextField();
    JLabel jLabel4 = new JLabel();
    JTextField jTextField_phone = new JTextField();
    JLabel jLabel6 = new JLabel();
    JComboBox jComboBox_tname = new JComboBox();
    JLabel jLabel3 = new JLabel();
    JTextArea jTextArea_introduction = new JTextArea();
    JLabel jLabel5 = new JLabel();
    JComboBox jComboBox_coname = new JComboBox();
    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 teacher_no;
             if(jComboBox_tname.getSelectedItem()==null){
                 teacher_no="";
                 //return false;
             }else{
                 String tname=(String)(jComboBox_tname.getSelectedItem());
                 ResultSet rs=SQLRunner.getResult("select * 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 depart_no= jTextField_depart_no.getText().trim();
             String dpname= jTextField_dpname.getText().trim();
             //String college_no= jTextField_depart_no.getText().trim();
             //ResultSet ras=SQLRunner.getResult("select * from ")
             String phone=jTextField_phone.getText().trim();
             String introduction=jTextArea_introduction.getText().trim();
             String insertsql="insert into department(college_no,dpname,DEPART_HEADER,dphone,INRTODUCTION,depart_no) values('"+college_no+"','"+dpname+"','"+teacher_no+"','"+phone+"','"+introduction+"','"+depart_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 + -