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

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

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

        } catch (Exception ex) {
        }
        jLabel.setText("楼号");
        jLabel2.setText("房间号");
        jLabel3.setText("性别");
        jLabel4.setText("容量");
        jTextField_capacity.setText("jTextField3");
        jLabel5.setText("现有人数");
        jTextField_livein.setText("jTextField4");
        jLabel6.setText("电话号码");
        jTextField_phone.setText("jTextField5");
        this.add(jTextField_capacity, new XYConstraints(391, 134, 109, 37));
        this.add(jLabel4, new XYConstraints(317, 133, 76, 40));
        this.add(jTextField_biuld_no, new XYConstraints(89, 42, 54, 35));
        this.add(jLabel2, new XYConstraints(181, 40, 65, 39));
        this.add(jTextField_apartment_no, new XYConstraints(242, 41, 76, 39));
        this.add(jLabel3, new XYConstraints(379, 37, 77, 41));
        this.add(jComboBox_sex, new XYConstraints(440, 41, 92, 37));
        this.add(jLabel5, new XYConstraints(50, 129, 74, 47));
        this.add(jTextField_livein, new XYConstraints(124, 134, 114, 39));
        this.add(jLabel6, new XYConstraints(50, 227, 108, 40));
        this.add(jTextField_phone, new XYConstraints(129, 227, 180, 39));
        this.add(jLabel, new XYConstraints(52, 40, 39, 38));
    }



    JLabel jLabel = new JLabel();
    JTextField jTextField_biuld_no = new JTextField();
    JLabel jLabel2 = new JLabel();
    JTextField jTextField_apartment_no = new JTextField();
    JLabel jLabel3 = new JLabel();
    JComboBox jComboBox_sex = new JComboBox();
    JLabel jLabel4 = new JLabel();
    JTextField jTextField_capacity = new JTextField();
    JLabel jLabel5 = new JLabel();
    JTextField jTextField_livein = new JTextField();
    JLabel jLabel6 = new JLabel();
    JTextField jTextField_phone = new JTextField();
    public void setSwingEnable(boolean e) {
        jTextField_biuld_no.setEnabled(e);
        jTextField_apartment_no.setEnabled(e);
        jComboBox_sex.setEnabled(e);
        jTextField_capacity.setEnabled(e);
        jTextField_livein.setEnabled(false);
        jTextField_phone.setEnabled(e);
    }

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

    public boolean update() {
        try{
            String sex=((String)jComboBox_sex.getSelectedItem()).trim();
            ResultSet rs=SQLRunner.getResult("select * from student where dorm_no='"+keyValue+"'");
            if(rs.next()){
                String ssex=rs.getString("sex");
                if(!sex.equals(ssex)){
                    JOptionPane.showMessageDialog(null,"与居住学生性别不符","系统提示",JOptionPane.ERROR_MESSAGE);
                    return false;
                }
            }
            //String sex=((String)jComboBox_sex.getSelectedItem()).trim();
            String capacity= jTextField_capacity.getText().trim();
            String livein= jTextField_livein.getText().trim();
            String phone=jTextField_phone.getText().trim();
            if(Integer.parseInt(livein)>Integer.parseInt(capacity)){
                JOptionPane.showMessageDialog(null,"人数不符","系统提示",JOptionPane.ERROR_MESSAGE);
                return false;
            }
            String updatesql="update dormitory set sex='"+sex+"',phone='"+phone+"',capacity="+capacity+" where dorm_no='"+keyValue+"'";
            return SQLRunner.executSql(updatesql);
         }catch(Exception e){
             JOptionPane.showMessageDialog(null,e.toString(),"系统提示",JOptionPane.ERROR_MESSAGE);
             return false;
         }

    }

    public boolean insert() {
        try{
            String build_no=jTextField_biuld_no.getText().trim();
            String apartment_no=jTextField_apartment_no.getText().trim();
            String sex=((String)jComboBox_sex.getSelectedItem()).trim();
            String capacity= jTextField_capacity.getText().trim();
            //String livein= jTextField_livein.getText().trim();
            String phone=jTextField_phone.getText().trim();
            String insertsql="insert into dormitory(build_no,apartment_no,dorm_no,phone,sex,capacity,livein) values('"+build_no+"','"+apartment_no+"','"+build_no+apartment_no+"','"+phone+"','"+sex+"',"+capacity+","+String.valueOf(0)+")";
            //String updatesql="insert  set sex='"+sex+"',phone='"+phone+"',capacity="+capacity+",livein="+livein+" where dorm_no='"+keyValue+"'";
            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 {
            ResultSet rs=SQLRunner.getResult("select * from dormitory where dorm_no='"+keyValue+"'");
            if (!rs.next()) {
                return;
            }jTextField_biuld_no.setText(rs.getString("build_no"));
            jTextField_apartment_no.setText(rs.getString("apartment_no"));
            jTextField_capacity.setText(rs.getString("capacity"));
            jTextField_livein.setText(rs.getString("livein"));
            jTextField_phone.setText(rs.getString("phone"));
            addItemFromDic(jComboBox_sex,"sex");
            jComboBox_sex.setSelectedItem(rs.getString("sex"));

        } catch (SQLException ex) {
        }
    }

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

        jTextField_biuld_no.setText("");
        jTextField_apartment_no.setText("");
        jTextField_capacity.setText("");
        jTextField_livein.setText("");
        jTextField_phone.setText("");
        addItemFromDic(jComboBox_sex,"sex");
        jComboBox_sex.setSelectedItem(null);
    }
}

⌨️ 快捷键说明

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