searchpanel3.java~43~

来自「银行信用评估系统」· JAVA~43~ 代码 · 共 327 行

JAVA~43~
327
字号
package management;

import java.awt.*;
import javax.swing.*;
import com.borland.dx.sql.dataset.*;
import com.borland.dbswing.*;
import java.awt.event.*;
import java.sql.*;
import com.borland.dx.dataset.*;
import com.borland.jbcl.layout.*;
import com.borland.dx.sql.dataset.*;

/**
 * <p>Title: </p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: </p>
 * @author not attributable
 * @version 1.0
 */

public class searchPanel3 extends JPanel {
  JTextField jTextField1 = new JTextField();
  String strx;
  JLabel jLabel1 = new JLabel();
  JLabel jLabel2 = new JLabel();
  JLabel jLabel3 = new JLabel();
  JComboBox jComboBox1 = new JComboBox();
  JComboBox jComboBox2 = new JComboBox();
  JButton jButton1 = new JButton();
  JButton jButton2 = new JButton();
  Database database1 = new Database();
  QueryDataSet queryDataSet1 = new QueryDataSet();
  QueryResolver queryResolver1 = new QueryResolver();
  TableScrollPane tableScrollPane1 = new TableScrollPane();
  JdbTable jdbTable1 = new JdbTable();

  PreparedStatement pstmt;
  Connection con;
  String query;
  ResultSet rs;
  String str;
  String str1;
  String str2;
   String str3;
   String str4;
    String a[]={"STUDENTNO","STUDENTNAME","STUDENTAGE","STUDENTSEX","STUENTRACE","STUDENTSPECIATION","COURSENAME"
    ,"COURSETYPE","COURSETEACHER","COURSETIME","COURSEADDRESS","COURSEWEEK","SCORE","SCORECREDIT","SCORESORT",
    "SCORETPYE","SCOREREMARK","SCORETIME"};
    String b[]={"学号","姓名","年龄","性别","民族","专业","课程名称","课程类型","任课老师","上课时间","上课地点","上课周次",
    "成绩","学分","类别","考别","备注","时间"};
    String c[]={"student","course","score"};
    String d[]={"学生个人信息表","学生课程表","学生成绩表"};
  JLabel jLabel5 = new JLabel();
   String ip;
  JLabel jLabel8 = new JLabel();
  GridBagLayout gridBagLayout1 = new GridBagLayout();
  JLabel jLabel6 = new JLabel();

  public searchPanel3() {
    try {
      jbInit();
    }
    catch(Exception ex) {
      ex.printStackTrace();
    }
  }
  public searchPanel3(String str) {
  strx=str;
    try {
     jbInit();
   }
   catch(Exception ex) {
     ex.printStackTrace();
   }
 }
 public searchPanel3(String str,String str1) {
  strx=str;
  ip=str1;
    try {
     jbInit();
   }
   catch(Exception ex) {
     ex.printStackTrace();
   }
 }


  void jbInit() throws Exception {

    jTextField1.setEnabled(true);
    jTextField1.setFont(new java.awt.Font("Dialog", 1, 15));
    this.setLayout(gridBagLayout1);
    jLabel1.setFont(new java.awt.Font("Dialog", 1, 22));    jLabel1.setForeground(SystemColor.activeCaption);
    jLabel1.setText("选择查询的表:");
    jLabel2.setFont(new java.awt.Font("Dialog", 1, 22));    jLabel2.setForeground(SystemColor.activeCaption);
    jLabel2.setText("选择查询的项:");
    jLabel3.setFont(new java.awt.Font("Dialog", 1, 22));    jLabel3.setForeground(SystemColor.activeCaption);
    jLabel3.setText("输入查询的内容:");
    jComboBox1.setFont(new java.awt.Font("Dialog", 1, 15));
    jComboBox1.addItemListener(new searchPanel3_jComboBox1_itemAdapter(this));
    jComboBox2.setFont(new java.awt.Font("Dialog", 1, 15));
    jComboBox2.addItemListener(new searchPanel3_jComboBox2_itemAdapter(this));
    jButton1.setBackground(new Color(151, 164, 203));    jButton1.setFont(new java.awt.Font("Dialog", 1, 15));
    jButton1.setText("确定");
    jButton1.addActionListener(new searchPanel3_jButton1_actionAdapter(this));
    jButton2.setBackground(new Color(151, 164, 203));    jButton2.setFont(new java.awt.Font("Dialog", 1, 15));
    jButton2.setText("清除");
    jButton2.addActionListener(new searchPanel3_jButton2_actionAdapter(this));
    jdbTable1.setBackground(new Color(217, 230, 236));    jdbTable1.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    jdbTable1.setDataSet(queryDataSet1);    jdbTable1.setEditableFocusedCellForeground(SystemColor.activeCaptionText);    jdbTable1.setEditableFocusedCellBackground(UIManager.getColor("EditorPane.selectionBackground"));
    database1.setConnection(new com.borland.dx.sql.dataset.ConnectionDescriptor("jdbc:microsoft:sqlserver://"+ip+":1433;DatabaseName=student", "sa", "lomf8244", false, "com.borland.datastore.jdbc.DataStoreDriver"));
    database1.setTransactionIsolation(java.sql.Connection.TRANSACTION_READ_COMMITTED);
    queryDataSet1.setResolver(queryResolver1);
    queryResolver1.setDatabase(database1);
    queryResolver1.setUpdateMode(com.borland.dx.dataset.UpdateMode.KEY_COLUMNS);
    jLabel5.setFont(new java.awt.Font("Dialog", 1, 22));    jLabel5.setForeground(SystemColor.activeCaption);
    jLabel5.setText("你好:学号为");
    jLabel8.setFont(new java.awt.Font("Dialog", 1, 22));    jLabel8.setForeground(SystemColor.activeCaption);
    jLabel6.setFont(new java.awt.Font("Dialog", 1, 44));    jLabel6.setForeground(SystemColor.activeCaption);    jLabel6.setText("       学 生 查 询 管 理");
    this.setBackground(new Color(217, 230, 236));    tableScrollPane1.getViewport().setBackground(new Color(217, 230, 236));    this.add(tableScrollPane1,   new GridBagConstraints(0, 7, 3, 1, 1.0, 1.0
            ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(13, 0, 0, 0), 56, -201));
    tableScrollPane1.getViewport().add(jdbTable1, null);
    this.add(jButton1,   new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(19, 124, 0, 0), 11, 2));
    this.add(jButton2,   new GridBagConstraints(2, 6, 1, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(20, 72, 0, 107), 11, 2));
    this.add(jLabel1,   new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(14, 9, 0, 24), 7, -7));
    this.add(jLabel2,   new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(22, 10, 0, 29), 1, -9));
    this.add(jComboBox1,   new GridBagConstraints(1, 3, 2, 1, 1.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(16, 0, 0, 33), 258, -5));
    this.add(jLabel3,   new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(19, 10, 0, 0), 3, -9));
    this.add(jComboBox2,   new GridBagConstraints(1, 4, 2, 1, 1.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(23, 0, 0, 33), 258, -6));
    this.add(jTextField1,   new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(20, 0, 0, 33), 287, -6));
    this.add(jLabel8,   new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(8, 20, 0, 11), 156, -6));
    this.add(jLabel5,   new GridBagConstraints(0, 2, 2, 1, 0.0, 0.0
            ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(7, 130, 0, 0), 2, -2));
    this.add(jLabel6,    new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0
            ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 222, 0));

    jComboBox1.addItem("学生个人信息表");
    jComboBox1.addItem("学生课程表");
    jComboBox1.addItem("学生成绩表");

    Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
    String url = "jdbc:microsoft:sqlserver://"+ip+":1433;DatabaseName=student";
    String username= "sa";
    String password= "lomf8244";
    con = DriverManager.getConnection(url,username,password);
    str2="STUDENTNO"; //初始化
    jLabel8.setText(strx+"的同学");
  }

  void jButton1_actionPerformed(ActionEvent e) {
    try{
      String str9=(String)jComboBox1.getSelectedItem();
      if(str9.equals("学生个人信息表")){
        str2="STUDENTNO"; //初始化
        jTextField1.setText("");
        query="select * from student";
       pstmt = con.prepareStatement(query);
       rs=pstmt.executeQuery();
      }
      else{
        query = "select * from " + str1 + " where " + str2 + "=?";
        pstmt = con.prepareStatement(query);
        str3 = jTextField1.getText();
        pstmt.setString(1, str3);
        rs = pstmt.executeQuery();
      }
     if(rs.next()){
      queryDataSet1.close();
      str=rs.getString(str2);
      if(str1.equals("student"))
      {
      str4= "select STUDENTNO as"+ "\'"+"学号" +"\'"+",STUDENTNAME as"+ "\'"+"姓名" +"\'"+",STUDENTAGE as"+ "\'"+"年龄" +"\'"+",STUDENTSEX as"+ "\'"+"性别" +"\'"+",STUENTRACE as"+ "\'"+"民族" +"\'"+",STUDENTSPECIATION as"+ "\'"+"专业" +"\'"+"from "+str1+" where  STUDENTNO="+"\'"+strx+"\'";
      }
      else if(str1.equals("course"))
      {
       str4= "select STUDENTNO as"+ "\'"+"学号" +"\'"+",COURSENAME as"+ "\'"+"课程名称" +"\'"+",COURSETYPE as"+ "\'"+"课程类型" +"\'"+",COURSETEACHER as"+ "\'"+"任课老师" +"\'"+",COURSETIME as"+ "\'"+"上课时间" +"\'"+",COURSEADDRESS as"+ "\'"+"上课地点" +"\'"+",COURSEWEEK as"+ "\'"+"上课周次" +"\'"+"from "+str1+" where "+str2+"="+"\'"+str+"\'"+"and STUDENTNO="+"\'"+strx+"\'";
      }
      else{
      str4= "select STUDENTNO as"+ "\'"+"学号" +"\'"+",COURSENAME as"+ "\'"+"课程名称" +"\'"+",SCORE as"+ "\'"+"成绩" +"\'"+",SCORECREDIT as"+ "\'"+"学分" +"\'"+",SCORESORT as"+ "\'"+"类别" +"\'"+",SCORETPYE as"+ "\'"+"考别" +"\'"+",SCOREREMARK as"+ "\'"+"备注" +"\'"+",SCORETIME as"+ "\'"+"时间" +"\'"+"from "+str1+" where "+str2+"="+"\'"+str+"\'"+"and STUDENTNO="+"\'"+strx+"\'";
      }
      queryDataSet1.setQuery(new com.borland.dx.sql.dataset.QueryDescriptor(database1, str4, null, true, Load.ALL));
      queryDataSet1.refresh();
      jdbTable1.setDataSet(queryDataSet1);
      jdbTable1.repaint();
     }
     else{

       jTextField1.setText("学号不存在!");
       queryDataSet1.close();
       queryDataSet1.refresh();
       jdbTable1.setDataSet(null);
       jdbTable1.repaint();

     }
   }
   catch(Exception ef)
   { System.out.print("系统错误,请重新运行。");
   }
  }

  void jButton2_actionPerformed(ActionEvent e) {
    jTextField1.setText("");
    queryDataSet1.close();
    queryDataSet1.refresh();
    jdbTable1.setDataSet(null);
    jdbTable1.repaint();

  }

  void jComboBox1_itemStateChanged(ItemEvent e) {
    if(jComboBox1.getSelectedIndex()==0)
  {    jComboBox2.removeAllItems();
   //  jTextField1.enable(false);

   }
   else if(jComboBox1.getSelectedIndex()==1)
  {   jComboBox2.removeAllItems();
    //jComboBox2.addItem("学号");
    jComboBox2.addItem("课程名称");
    jComboBox2.addItem("课程类型");
    jComboBox2.addItem("任课老师");
    jComboBox2.addItem("上课时间");
    jComboBox2.addItem("上课地点");
    jComboBox2.addItem("上课周次");
  }
  else if(jComboBox1.getSelectedIndex()==2)
  {   jComboBox2.removeAllItems();
     // jComboBox2.addItem("学号");
      jComboBox2.addItem("课程名称");
      jComboBox2.addItem("成绩");
      jComboBox2.addItem("学分");
      jComboBox2.addItem("类别");
      jComboBox2.addItem("考别");
      jComboBox2.addItem("备注");
      jComboBox2.addItem("时间");
  }
   str1=(String)jComboBox1.getSelectedItem();
   for(int i=0;i<d.length;i++)
         if(str1.equals(d[i]))
           str1=c[i];

  }

  void jComboBox2_itemStateChanged(ItemEvent e) {
    for(int i=0;i<7;i++)
      if(jComboBox2.getSelectedIndex()==i)
        str2=(String)jComboBox2.getSelectedItem();
     for(int i=0;i<b.length;i++)
                if(str2.equals(b[i]))
                  str2=a[i];

  }




}

class searchPanel3_jButton1_actionAdapter implements java.awt.event.ActionListener {
  searchPanel3 adaptee;

  searchPanel3_jButton1_actionAdapter(searchPanel3 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton1_actionPerformed(e);
  }
}

class searchPanel3_jButton2_actionAdapter implements java.awt.event.ActionListener {
  searchPanel3 adaptee;

  searchPanel3_jButton2_actionAdapter(searchPanel3 adaptee) {
    this.adaptee = adaptee;
  }
  public void actionPerformed(ActionEvent e) {
    adaptee.jButton2_actionPerformed(e);
  }
}

class searchPanel3_jComboBox1_itemAdapter implements java.awt.event.ItemListener {
  searchPanel3 adaptee;

  searchPanel3_jComboBox1_itemAdapter(searchPanel3 adaptee) {
    this.adaptee = adaptee;
  }
  public void itemStateChanged(ItemEvent e) {
    adaptee.jComboBox1_itemStateChanged(e);
  }
}

class searchPanel3_jComboBox2_itemAdapter implements java.awt.event.ItemListener {
  searchPanel3 adaptee;

  searchPanel3_jComboBox2_itemAdapter(searchPanel3 adaptee) {
    this.adaptee = adaptee;
  }
  public void itemStateChanged(ItemEvent e) {
    adaptee.jComboBox2_itemStateChanged(e);
  }
}

⌨️ 快捷键说明

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