?? scoreuniversquerydialog.java
字號(hào):
ncountClass = 1;
// 清空Vector變量vecSQL vecListView清空List控件中查詢條件 this.vecSQLClass.clear();
this.vecListViewClass.clear();
this.ClassQueryList.setListData(vecListViewClass);
// 清除按鈕不可用 this.clearButton.setEnabled(false);
}
/**
* 根據(jù)用戶選擇匹配相應(yīng)比較符 *
* @param evt
*/
private void queryConditionComboBoxActionPerformed(ActionEvent evt) {
// 根據(jù)用戶選擇匹配比較字段 // 定義int型變量, nuserSelect,存儲(chǔ)用戶選擇的字段的索引 int nuserSelect = 0;
// 獲得用戶所選字段的 nuserSelect = this.queryConditionComboBox.getSelectedIndex();
// 用戶選擇的字段的索引加一 nuserSelect++;
// 利用switch語(yǔ)句匹配比較符 switch (nuserSelect) {
case 1:
case 3:
// 如果用戶選擇的是學(xué)號(hào)和年齡 this.compareComboBox.removeAllItems();
this.compareComboBox.addItem(">");
this.compareComboBox.addItem("<");
this.compareComboBox.addItem("=");
break;
case 2:
case 4:
// 如果用戶選擇的是姓名和班級(jí) this.compareComboBox.removeAllItems();
this.compareComboBox.addItem("匹配");
this.compareComboBox.addItem("=");
break;
default:
}
}
/**
* 學(xué)生查詢,顯示學(xué)生信息 *
* @param evt
*/
private void studentQueryButton1ActionPerformed(ActionEvent evt) {
// 查詢 // 建立一個(gè)JDBC對(duì)象 JdbcConnct jdbcConnection = new JdbcConnct();
// 定義Vector變量,存儲(chǔ)從數(shù)據(jù)庫(kù)查詢來(lái)的信息 Vector vecData = new Vector();
// 定義SQL語(yǔ)句組合項(xiàng) String strSQL = "select studentid,stuname,age,teachername from zlb.stu_teacher_view ";
String strSQL1 = " where ";
String strTemp = " order by studentid ASC";
// 組合SQL語(yǔ)句 if (this.vecSQL.isEmpty()) {
strSQL += strTemp;
} else {
for (int i = 0; i < this.vecSQL.size(); i++) {
strSQL1 += this.vecSQL.get(i).toString();
}
strSQL += strSQL1 + strTemp;
}
// 刷新table中數(shù)據(jù) DefaultTableModel StuQueryTableModel = new DefaultTableModel(row,
combListStu);
this.ClassQueryTable.setModel(StuQueryTableModel);
// 獲得數(shù)據(jù) try {
vecData = jdbcConnection.getData(strSQL);
} catch (SQLException e) {
e.printStackTrace();
}
// 依次為各行插入數(shù)據(jù) if (vecData.size() > 0) {
for (int i = 0; i < vecData.size(); i++) {
StuQueryTableModel.addRow((String[]) vecData.get(i));
}
// 顯示查詢數(shù)據(jù) this.ScorQueryTabbedPane
.setSelectedComponent(this.queryResultPanel);
//用戶點(diǎn)擊表格次數(shù)置為1
nclickNum = 1;
} else {
JOptionPane.showMessageDialog(this, "您查詢的記錄在數(shù)據(jù)庫(kù)中不存在!請(qǐng)換一個(gè)查詢條件.");
}
}
/**
* 根據(jù)用戶輸入返回SQL語(yǔ)句 *
* @return
*/
private String getUserSelect() {
// 添加組合查詢信息 // 定義boolean型變量 isRight 用戶輸入是否正確,初始化false
boolean bisRight = false;
// 定義String類型,查詢字段,比較符,用戶輸入 String strQueryField = "";
String strLogicalSymbol = "";
String strUserInput = "";
// 用戶在組合框中選擇的Item索引 int nUserSelect;
// 定義SQL語(yǔ)句 String strSQL = "";
// 定義SQL顯示語(yǔ)句 String strSQLView = "";
// 獲得查詢字段,比較符,用戶輸入 strQueryField = this.queryConditionComboBox.getSelectedItem()
.toString();
strLogicalSymbol = this.compareComboBox.getSelectedItem().toString();
strUserInput = this.userInputTextField1.getText();
// 用戶選擇的查詢字段的索引 nUserSelect = this.queryConditionComboBox.getSelectedIndex();
// 用戶選擇的查詢字段的索引加一 nUserSelect++;
// 打印用戶選擇的查詢字段的索引 System.out.println("\t" + nUserSelect);
// 利用switch語(yǔ)句進(jìn)行查詢判斷 switch (nUserSelect) {
case 1:
// 如果用戶選擇學(xué)號(hào) // 校驗(yàn)用戶數(shù)據(jù) if (strUserInput.matches(REG_DIGIT)) {
bisRight = true;
strSQL = "StudentId" + " " + strLogicalSymbol + strUserInput;
// SQL顯示 strSQLView = strQueryField + " " + strLogicalSymbol
+ strUserInput;
} else {
bisRight = false;
JOptionPane.showMessageDialog(this,
"請(qǐng)不要在學(xué)號(hào)中輸入字母,班級(jí)號(hào)為7位數(shù)字,請(qǐng)重新輸入學(xué)號(hào)!");
}
break;
case 2:
// 判斷是否為數(shù)字型字段 // 如果查詢字段為姓名 if (strLogicalSymbol.equals("匹配")) {
bisRight = true;
strSQL = "StuName" + " Like '" + strUserInput + "%'";
// SQL顯示 strSQLView = strQueryField + "的前幾個(gè)字符為:" + strUserInput;
} else {
bisRight = true;
strSQL = "StuName" + " " + strLogicalSymbol + "'"
+ strUserInput + "'";
// SQL顯示 strSQLView = strQueryField + " " + strLogicalSymbol + " "
+ strUserInput;
}
break;
case 3:
// 如果用戶選擇"年齡"
// 校驗(yàn)用戶數(shù)據(jù) if (strUserInput.matches(REG_DIGITAGE)) {
bisRight = true;
strSQL = "AGE" + " " + strLogicalSymbol + strUserInput;
// SQL顯示 strSQLView = strQueryField + " " + strLogicalSymbol
+ strUserInput;
} else {
bisRight = false;
JOptionPane.showMessageDialog(this,
"請(qǐng)不要在年齡中輸入字母,年齡為2位數(shù)字,請(qǐng)重新輸入!");
}
break;
case 4:
// 如果用戶選擇"班主任名"
// 校驗(yàn)用戶數(shù)據(jù) if (strLogicalSymbol.equals("匹配")) {
bisRight = true;
strSQL = "TeacherName" + " Like '" + strUserInput + "%'";
// SQL顯示 strSQLView = strQueryField + "的前幾個(gè)字符為:" + strUserInput;
} else {
bisRight = true;
strSQL = "TeacherName" + " " + strLogicalSymbol + "'"
+ strUserInput + "'";
// SQL顯示 strSQLView = strQueryField + " " + strLogicalSymbol + " "
+ strUserInput;
}
break;
default:
JOptionPane.showMessageDialog(this, "您選擇的查詢字段不存在,請(qǐng)重新選擇!");
}
// 如果用戶輸入錯(cuò)誤,查詢學(xué)生條件減一 if (!bisRight) {
ncount--;
}
// 對(duì)用戶選擇進(jìn)行操作 none and or
if (this.nullRadioButton1.isSelected()) {
} else if (this.andRadioButton1.isSelected()) {
// 添加按鈕置為可用 this.addStuQueryButton.setEnabled(true);
strSQLView = "并且 " + strSQLView;
strSQL = "and " + strSQL;
} else {
// 添加按鈕置為可用 this.addStuQueryButton.setEnabled(true);
strSQLView = "或者 " + strSQLView;
strSQL = "or " + strSQL;
}
// 顯示SQL查詢信息 this.vecListView.add(strSQLView);
// 向List控件中寫(xiě)入數(shù)據(jù) this.studentQueryList1.setListData(vecListView);
return strSQL;
}
/**
* 根據(jù)用戶選擇返回SQL語(yǔ)句 *
* @return String strSQL
*/
private String getUserSelectClass() {
// 添加組合查詢信息 // 定義boolean型變量 isRight 用戶輸入是否正確,初始化false
boolean bisRight = false;
// 定義String類型,查詢字段,比較符,用戶輸入 String strQueryField = "";
String strLogicalSymbol = "";
String strUserInput = "";
// 用戶在組合框中選擇的Item索引 int nUserSelect;
// 定義SQL語(yǔ)句 String strSQL = "";
// 定義SQL顯示語(yǔ)句 String strSQLView = "";
// 獲得查詢字段,比較符,用戶輸入 strQueryField = this.ClassQueryComboBox.getSelectedItem().toString();
strLogicalSymbol = this.classQueryConditionComboBox.getSelectedItem().toString();
strUserInput = this.commentTextField.getText();
// 用戶選擇的查詢字段的索引 nUserSelect = this.ClassQueryComboBox.getSelectedIndex();
// 用戶選擇的查詢字段的索引加一 nUserSelect++;
// 打印用戶選擇的查詢字段的索引 System.out.println("\t" + nUserSelect);
// 利用switch語(yǔ)句進(jìn)行查詢判斷 switch (nUserSelect) {
case 1:
// 如果用戶選擇班級(jí)號(hào) // 校驗(yàn)用戶數(shù)據(jù) if (strUserInput.matches(REG_DIGITCLASS)) {
bisRight = true;
strSQL = "ClassId" + " " + strLogicalSymbol + strUserInput;
// SQL顯示 strSQLView = strQueryField + " " + strLogicalSymbol
+ strUserInput;
} else {
bisRight = false;
JOptionPane.showMessageDialog(this,
"請(qǐng)不要在班級(jí)號(hào)中輸入字母,班級(jí)號(hào)為7位數(shù)字,請(qǐng)重新輸入班級(jí)號(hào)!");
}
break;
case 2:
// 判斷是否為數(shù)字型字段 // 如果查詢字段為班級(jí)名 if (strLogicalSymbol.equals("匹配")) {
bisRight = true;
strSQL = "ClassName" + " Like '" + strUserInput + "%'";
// SQL顯示 strSQLView = strQueryField + "的前幾個(gè)字符為:" + strUserInput;
} else {
bisRight = true;
strSQL = "ClassName" + " " + strLogicalSymbol + "'"
+ strUserInput + "'";
// SQL顯示 strSQLView = strQueryField + " " + strLogicalSymbol + " "
+ strUserInput;
}
break;
case 3:
// 如果用戶選擇"屆別"
// 校驗(yàn)用戶數(shù)據(jù) if (strUserInput.matches(REG_DIGITFLAGYEAR)) {
bisRight = true;
strSQL = "flagYear" + " " + strLogicalSymbol + "'"
+ strUserInput + "' ";
// SQL顯示 strSQLView = strQueryField + " " + strLogicalSymbol
+ strUserInput;
} else {
bisRight = false;
JOptionPane.showMessageDialog(this,
"請(qǐng)不要在屆別中輸入字母,屆別為4位數(shù)字,請(qǐng)重新輸入!");
}
break;
default:
JOptionPane.showMessageDialog(this, "您選擇的查詢字段不存在,請(qǐng)重新選擇!");
}
// 如果用戶輸入不正確,班級(jí)查詢條件數(shù)減一 if (!bisRight) {
ncountClass--;
}
// 對(duì)用戶選擇進(jìn)行操作 none and or
if (this.nullRadioButton.isSelected()) {
} else if (this.addRadioButton.isSelected()) {
// 并且按鈕置為可用 this.addButton.setEnabled(true);
strSQLView = "并且 " + strSQLView;
strSQL = "and " + strSQL;
} else {
// 或者按鈕置為可用 this.orRadioButton.setEnabled(true);
strSQLView = "或者 " + strSQLView;
strSQL = "or " + strSQL;
}
// 顯示SQL查詢信息 this.vecListViewClass.add(strSQLView);
// 向List控件中寫(xiě)入數(shù)據(jù) this.ClassQueryList.setListData(vecListViewClass);
return strSQL;
}
/**
* 退出 * @param evt
*/
private void exitButtonActionPerformed(ActionEvent evt) {
//退出 this.dispose();
}
/**
* 鼠標(biāo)滾輪事件,滾動(dòng)鼠標(biāo)改變年份 * @param evt
*/
private void yearSelectSpinnerMouseWheelMoved(MouseWheelEvent evt) {
//添加鼠標(biāo)滾輪事件,滾動(dòng)鼠標(biāo)改變年份 if (evt.getWheelRotation() < 0
&& Integer.parseInt((String) yearSelectSpinner.getValue()) < this.nowYear + 9) {
yearSelectSpinner.setValue(yearSelectSpinner.getNextValue());
} else if (evt.getWheelRotation() > 0
&& Integer.parseInt((String) yearSelectSpinner.getValue()) > this.nowYear - 10) {
yearSelectSpinner
.setValue(yearSelectSpinner.getPreviousValue());
}
}
/**
* 點(diǎn)擊鼠標(biāo),選擇學(xué)生成績(jī)查詢或班級(jí)成績(jī)查詢 * @param evt
*/
private void ClassQueryTableMouseClicked(MouseEvent evt) {
// 定義變量bisStudent,判斷是否選擇學(xué)生表,初始化為false
boolean bisStudent = false;
//班級(jí)號(hào)、班級(jí)名 String strclassId = "";
String strclassName = "";
//鼠標(biāo)點(diǎn)擊行 int nrow = 0;
//獲得用戶選擇類型 bisStudent= this.getUserSelectType();
//獲取鼠標(biāo)點(diǎn)擊行 nrow = this.ClassQueryTable.getSelectedRow();
//獲取前兩個(gè)數(shù)據(jù) strclassId = String.valueOf(this.ClassQueryTable.getValueAt(nrow, 0));
strclassName = String.valueOf(this.ClassQueryTable.getValueAt(nrow, 1));
//如果首次點(diǎn)擊班級(jí)信息查詢表 if(bisStudent
&&nclickNum == 1){
//用戶點(diǎn)擊次數(shù)加一 nclickNum++;
//顯示學(xué)生成績(jī)查詢組件,隱藏班級(jí)成績(jī)查詢組件 this.SetQueryModel(bisStudent);
}else if(!bisStudent
&&nclickNum == 1){
//如果首次點(diǎn)擊班級(jí)信息查詢表 //用戶點(diǎn)擊次數(shù)加一 nclickNum++;
//顯示班級(jí)成績(jī)查詢組件,隱藏學(xué)生成績(jī)查詢組件 this.SetQueryModel(bisStudent);
}
if(bisStudent
&&nclickNum >1){
//對(duì)學(xué)生表點(diǎn)擊進(jìn)行操作
}else if(!bisStudent
&&nclickNum >1){
//對(duì)班級(jí)表點(diǎn)擊進(jìn)行操作,顯示班級(jí)號(hào)、班級(jí)名 this.classIdViewLabel.setText(strclassId);
this.classNameViewLabel.setText(strclassName);
}
}
private void SetQueryModel(boolean bisStudent){
if(bisStudent){
//顯示學(xué)生成績(jī)查詢組件 this.fullQueryRadioButton.setVisible(true);
this.commonRadioButton.setVisible(true);
this.yearSelectSpinner.setVisible(true);
this.conditionComboBox.setVisible(true);
this.studentQueryButton.setVisible(true);
//顯示學(xué)生成績(jī)查詢標(biāo)簽 this.stuQueryViewLabel.setText("學(xué)生成績(jī)查詢");
//隱藏班級(jí)成績(jī)查詢組件 this.classIdLabel.setVisible(false);
this.classIdViewLabel.setVisible(false);
this.classNameLabel.setVisible(false);
this.classNameViewLabel.setVisible(false);
this.fullSubjectQueryRadioButton.setVisible(false);
this.subjectQueryRadioButton.setVisible(false);
this.subjectConditionComboBox.setVisible(false);
this.classScoreQueryButton.setVisible(false);
}else{
//顯示班級(jí)成績(jī)查詢組件 this.classIdLabel.setVisible(true);
this.classIdViewLabel.setVisible(true);
this.classNameLabel.setVisible(true);
this.classNameViewLabel.setVisible(true);
this.fullSubjectQueryRadioButton.setVisible(true);
this.subjectQueryRadioButton.setVisible(true);
this.subjectConditionComboBox.setVisible(true);
this.classScoreQueryButton.setVisible(true);
//顯示班級(jí)成績(jī)查詢標(biāo)簽 this.stuQueryViewLabel.setText("班級(jí)成績(jī)查詢");
//隱藏學(xué)生成績(jī)查詢組件 this.fullQueryRadioButton.setVisible(false);
this.commonRadioButton.setVisible(false);
this.yearSelectSpinner.setVisible(false);
this.conditionComboBox.setVisible(false);
this.studentQueryButton.setVisible(false);
}
}
/**
* 返回用戶選擇的對(duì)象 *
* @return bisStudent,true為學(xué)生、false為教師 */
private boolean getUserSelectType() {
// 定義變量bisStudent,判斷是否選擇學(xué)生,初始化為false
boolean bisStudent = false;
if (this.ClassQueryTable.getColumnCount() == 4) {
bisStudent = true;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -