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

📄 search.java

📁 用java实现的学生管理系统
💻 JAVA
字号:
package xscjgl;

import java.awt.BorderLayout;

import javax.swing.JFrame;
import java.awt.Dimension;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.*;
import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
import com.borland.dbswing.TableScrollPane;
import com.borland.dbswing.JdbTable;
import com.borland.dbswing.JdbNavToolBar;
import com.borland.dx.sql.dataset.QueryDescriptor;
import com.borland.dx.sql.dataset.Load;
import javax.swing.JOptionPane;
import java.util.concurrent.locks.Condition;
import java.awt.Font;
import com.sun.org.apache.xerces.internal.impl.dv.xs.StringDV;

/**
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author not attributable
 * @version 1.0
 */
public class search extends JFrame {
    XYLayout xYLayout1 = new XYLayout();
    JPanel jPanel1 = new JPanel();
    JPanel jPanel2 = new JPanel();
    JLabel jLabel1 = new JLabel();
    XYLayout xYLayout2 = new XYLayout();
    JLabel jLabel2 = new JLabel();
    JRadioButton jRadioButton1 = new JRadioButton();
    JRadioButton jRadioButton2 = new JRadioButton();
    JComboBox jComboBox1 = new JComboBox();
    JComboBox jComboBox2 = new JComboBox();
    JTextField jTextField1 = new JTextField();
    JButton jButton1 = new JButton();
    TableScrollPane tableScrollPane1 = new TableScrollPane();
    XYLayout xYLayout3 = new XYLayout();
    JdbTable jdbTable1 = new JdbTable();
    DataModule1 dataModule11 = new DataModule1();
    public search() {
        try {
            jbInit();
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        dataModule11 = DataModule1.getDataModule();
        getContentPane().setLayout(xYLayout1);
        xYLayout1.setWidth(456);
        xYLayout1.setHeight(346);
        jPanel1.setLayout(xYLayout2);
        jLabel1.setFont(new java.awt.Font("宋体", Font.BOLD, 15));
        jLabel1.setToolTipText("");
        jLabel1.setText("查询学生,课程信息");
        jLabel2.setText("请选择查询方式:");
        jRadioButton1.setText("精确查询");
        jRadioButton2.setSelected(true);
        jRadioButton2.setText("模糊查询");
        ButtonGroup group = new ButtonGroup();
        jTextField1.setText("请输入关键字");
        jTextField1.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                jTextField1_mousePressed(e);
            }
        });

        jButton1.setText("查询");
        jButton1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                jButton1_actionPerformed(e);
            }
        });
        jComboBox1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                jComboBox1_actionPerformed(e);
            }
        });
        jPanel2.setLayout(xYLayout3);
        jdbTable1.setDataSet(dataModule11.getStudent());

        group.add(jRadioButton1);
        group.add(jRadioButton2);
        jPanel2.setBackground(new Color(236, 234, 255));
        jPanel1.setBackground(new Color(241, 249, 249));
        this.getContentPane().add(jPanel1, new XYConstraints(0, 10, 456, 113));
        jPanel1.add(jRadioButton2, new XYConstraints(219, 34, -1, -1));
        jPanel1.add(jLabel2, new XYConstraints(11, 38, -1, -1));
        jPanel1.add(jRadioButton1, new XYConstraints(120, 34, -1, -1));
        jPanel1.add(jComboBox1, new XYConstraints(11, 77, 119, -1));
        jPanel1.add(jButton1, new XYConstraints(379, 75, -1, -1));
        jPanel1.add(jTextField1, new XYConstraints(265, 78, 101, -1));
        this.getContentPane().add(jPanel2, new XYConstraints( -1, 130, 458, 182));
        jPanel2.add(tableScrollPane1, new XYConstraints(5, 0, 437, 162));
        tableScrollPane1.getViewport().add(jdbTable1);
        jPanel1.add(jComboBox2, new XYConstraints(134, 77, 124, -1));
        jPanel1.add(jLabel1, new XYConstraints(116, 10, 165, 15));
        jComboBox1.addItem("请选择查询类别");
        jComboBox1.addItem("课程信息查询");
        jComboBox1.addItem("学生信息查询");
        jComboBox2.addItem("请选择查询条件");


    }

    public static void main(String[] args) {
        search search = new search();
        search.setVisible(true);
        search.setLocationRelativeTo(null);
        search.setSize(new Dimension(455,355));

    }

    public void jComboBox1_actionPerformed(ActionEvent e) {
        //jComboBox1_change事件
       int Select = jComboBox1.getSelectedIndex();
       switch (Select)
       {

       case 1:
           jComboBox2.removeAllItems();
           jComboBox2.addItem("请选择查询条件");
           jComboBox2.addItem("课程名");
           jComboBox2.addItem("课程号");
           jComboBox2.addItem("任课教师");
           jComboBox2.addItem("上课时间");
           jComboBox2.addItem("上课地点");
           dataModule11.Query.close();
           dataModule11.Query.setQuery(new QueryDescriptor(dataModule11.database1, "select * from Course", null, true,
                                                     Load.ALL));
           System.out.println("after change queryDataSet1, SQL is:" +
                             dataModule11.Query.getQuery());

          dataModule11.Query.open();
          dataModule11.Query.refresh();


           break;

       case 2:
           jComboBox2.removeAllItems();
           jComboBox2.addItem("请选择查询条件");
           jComboBox2.addItem("学生姓名");
           jComboBox2.addItem("学生籍贯");
           jComboBox2.addItem("出生年月");
           dataModule11.Query.close();
           dataModule11.Query.setQuery(new QueryDescriptor(dataModule11.database1, "select * from Student", null, true,
                                                     Load.ALL));
          System.out.println("after change queryDataSet1, SQL is:" +
                             dataModule11.Query.getQuery());

          dataModule11.Query.open();
          dataModule11.Query.refresh();

           break;
       }

    }


    public void jTextField1_mousePressed(MouseEvent e) {
        this.jTextField1.setText("");
    }

    public void jButton1_actionPerformed(ActionEvent e) {

        //得到当前选中的类别
      int Selected = jComboBox1.getSelectedIndex();

      //得到当前选中的条件
      int Condition = jComboBox2.getSelectedIndex();
      int t=0;
      String ClassID="";
      String ConditionID="";
      String selectCondition="";//SQL语句
      String Keyvalue=jTextField1.getText().trim();
      //如果没有选择
//*********************************************************************************
      if(Selected==0)
      {
      JOptionPane.showMessageDialog(null,"请选择查询类别!");
       t=1;
      }else{
     //*************************************************************************
          if (Condition == 0) {
       JOptionPane.showMessageDialog(null,"请选择查询条件!");
       t=1;
          }else{
              //***************************************************************************

               if(Keyvalue.equals("")||Keyvalue.equals("请输入关键字"))
               {
               JOptionPane.showMessageDialog(null,"请输入关键字!");
               t=1;
               jTextField1.setText("");
               }else{
                   //判断选择的类别,为查询语句提供表名。
                  switch(Selected){
                  case 1://课程信息查询
                      ClassID="Course";
                    try{
                        switch (Condition) {
                        case 1:
                            ConditionID = "Cname";
                            break;
                        case 2:
                           ConditionID = "Cno";
                            break;
                        case 3:
                            ConditionID = "Cteacher";
                        case 4:
                            ConditionID = "Ctime";
                            break;
                        case 5:
                            ConditionID = "Caddress";
                            break;
                        }
                      }catch(Exception ex)
                      {
                          System.out.print("the first exception:" +
                                           ex.getMessage());
                      }

                      break;

                  case 2:
                      ClassID="Student";
                     try{
                          switch (Condition) {
                          case 1:
                              ConditionID = "Sname";
                              break;
                          case 2:
                              ConditionID = "Sjg";
                              break;
                        case 3:
                             ConditionID = "Sbirth";
                              break;
                         }
                      }catch(Exception ex)
                      {
                        System.out.print("the third exception:"+ex.getMessage());
                      }
                      break;

                  }

                  //*********************************************************************************

                  //根据选择条件得到最终的SQL语句
                  if(jRadioButton1.isSelected())
                  {
                      selectCondition = "select * from " + ClassID + " where " +
                                        ConditionID + "='" + Keyvalue + "'";
                     // JOptionPane.showMessageDialog(null,"查询条件为:" + selectCondition);
                      System.out.println("查询条件为:" + selectCondition);
                  }else{
                      selectCondition = "select * from " + ClassID + " where " +
                                        ConditionID + " like'%" + Keyvalue +
                                        "%'";
                      //JOptionPane.showMessageDialog(null,"查询条件为:" + selectCondition);
                      System.out.println("查询条件为:" + selectCondition);

                  }//end third if else
                  //*********************************************************************************
              }
             //*****************************************************************
          }//end second if else
     //*************************************************************************
      }//end first if else



      //************************************************************************
       //hava not change queryDataSet1
       if (t == 0) {
           try {
               System.out.println("hava not change queryDataSet1, SQL is:" +
                                  dataModule11.Query.getQuery());
               //changge queryDataSet1
               dataModule11.Query.close();
               dataModule11.Query.setQuery(new QueryDescriptor(dataModule11.
                       database1, selectCondition, null, true,
                       Load.ALL));
               System.out.println("after change queryDataSet1, SQL is:" +
                                  dataModule11.Query.getQuery());
               //jdbTable1
               dataModule11.Query.open();
               dataModule11.Query.refresh();


               if (dataModule11.Query.getRowCount() == 0) {
                   JOptionPane.showMessageDialog(null, "抱歉,没有找到您要的信息!");
               } else {
                   JOptionPane.showMessageDialog(null, "找到以下记录");
               }
           } catch (Exception ex) {
               System.out.println("exception is:" + ex.getMessage());
               JOptionPane.showMessageDialog(null, "没有找到您要的信息!");
           }

       }



      //************************************************************************



//*********************************************************************************

    }



}

⌨️ 快捷键说明

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