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

📄 选课状态.java

📁 经过调查分析
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    }// </editor-fold>//GEN-END:initComponents

    private void jComboBox2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jComboBox2MouseClicked
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2MouseClicked

    private void jComboBox2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox2ItemStateChanged
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2ItemStateChanged

    private void jComboBox2ComponentAdded(java.awt.event.ContainerEvent evt) {//GEN-FIRST:event_jComboBox2ComponentAdded
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2ComponentAdded

    private void jComboBox2AncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jComboBox2AncestorAdded
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2AncestorAdded

    private void jComboBox2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox2ActionPerformed
// TODO add your handling code here:
    }//GEN-LAST:event_jComboBox2ActionPerformed

    private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton1ActionPerformed
     
     Statement statement;
     try{
                Connect con=new Connect();
                statement=con.con.createStatement();
                
                String sql="update 课程 set 选课状态='开通' where 选课属性='选修'";
                
                int reg=statement.executeUpdate(sql);
                
               }

     catch(SQLException sqlException){
        JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
        System.exit(1);}
     catch(ClassNotFoundException classNotFound){
       JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
        System.exit(1); }// TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton1ActionPerformed

    private void jRadioButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButton2ActionPerformed
     
     Statement statement;
     try{
                Connect con=new Connect();
                statement=con.con.createStatement();
                
                String sql="update 课程 set 选课状态='关闭' where 选课属性='选修'";
                
                int reg=statement.executeUpdate(sql);
                
               }

     catch(SQLException sqlException){
        JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
        System.exit(1);}
     catch(ClassNotFoundException classNotFound){
       JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
        System.exit(1); }// TODO add your handling code here:
    }//GEN-LAST:event_jRadioButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    
   Statement statement;
    
     try{
            int n=0;
            Connect con = new Connect();
            statement= con.con.createStatement();
             ResultSet resultSet0=statement.executeQuery("SELECT 课程名 FROM 课程 WHERE 选课属性='选修' AND 开课学年='"+jComboBox2.getSelectedItem().toString()+"'");
            ResultSetMetaData metaData0=resultSet0.getMetaData();
            int numberOfColumns0=metaData0.getColumnCount();
                
                while(resultSet0.next()){
                    for(int j=1;j<=numberOfColumns0;j++)
                       jTable1.setValueAt(resultSet0.getObject(j).toString(),n,0);
                      n++;
                    }
           }
     
     catch(SQLException sqlException){
        JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
        System.exit(1);}
     catch(ClassNotFoundException classNotFound){
       JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
        System.exit(1); }
    // TODO add your handling code here:
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    

    
    Statement statement;
    
     try{
            Connect con = new Connect();
            statement= con.con.createStatement();
            int number=0;
            
            for(int i=0;i<jTable1.getRowCount();i++)
                if(jTable1.getValueAt(i,0)!=null)
                     number++;
           
           
            
          for(int i=0;i<number;i++)
            {   int flag=0;
                String courseNumber=null,roomNumber=null;
                ResultSet resultSet=statement.executeQuery("SELECT 课程号 FROM 课程 WHERE 课程名='"+jTable1.getValueAt(i,0)+"'");
                ResultSetMetaData metaData=resultSet.getMetaData();
                int numberOfColumns=metaData.getColumnCount();
                while(resultSet.next()){
                    for(int j=1;j<=numberOfColumns;j++)
                       courseNumber=resultSet.getObject(j).toString();
                       
                    }
              
               ResultSet resultSet1=statement.executeQuery("SELECT 教室编号 FROM 教室 WHERE 状态='未占用'");
                ResultSetMetaData metaData1=resultSet1.getMetaData();
                int numberOfColumns1=metaData1.getColumnCount();
                
                while(resultSet1.next()){
                    for(int j=1;j<=numberOfColumns1;j++)
                    {  roomNumber=resultSet1.getObject(j).toString();
                        if(roomNumber.equals(jTable1.getValueAt(i,2).toString()))
                           flag=1;
                        }
                }
                if(flag==0)   
                    JOptionPane.showMessageDialog(null,jTable1.getValueAt(i,2)+"教室编号错误或已占用!");
                 
                
                if(flag==1)
                {   int reg=0,reg0=0;
                    String sql1="INSERT INTO 课表 VALUES('"+courseNumber+"','任意','"+jTable1.getValueAt(i,1).toString()+"','"+jTable1.getValueAt(i,2).toString()+"','"+jTable1.getValueAt(i,3).toString()+"')";
                    reg=statement.executeUpdate(sql1);
                    
                    reg0=statement.executeUpdate("UPDATE 教室 SET 状态='占用' WHERE 教室编号='"+jTable1.getValueAt(i,2).toString()+"'");
                   
         
                  
              }       
         }
            JOptionPane.showMessageDialog(null,"排课成功!");
            for(int t1=0;t1<jTable1.getRowCount();t1++)
                    for(int t2=0;t2<jTable1.getColumnCount();t2++)
                        jTable1.setValueAt(null,t1,t2);
     
     }
    catch(SQLException sqlException){
        JOptionPane.showMessageDialog(null,sqlException.getMessage(),"Database Error",JOptionPane.ERROR_MESSAGE);
        System.exit(1);}
   catch(ClassNotFoundException classNotFound){
       JOptionPane.showMessageDialog(null,classNotFound.getMessage(),"Driver Not Found",JOptionPane.ERROR_MESSAGE);
        System.exit(1); }// TODO add your handling code here:
    }//GEN-LAST:event_jButton2ActionPerformed
   
   
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
    
}

⌨️ 快捷键说明

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