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

📄 scoreuniversquerydialog.java

📁 学生管理系统。使用java编程
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
		ncountClass = 1;
		// 清空Vector变量vecSQL vecListView清空List控件中查询条件		this.vecSQLClass.clear();
		this.vecListViewClass.clear();
		this.ClassQueryList.setListData(vecListViewClass);
		// 清除按钮不可用		this.clearButton.setEnabled(false);
	}

	/**
	 * 根据用户选择匹配相应比较符	 * 
	 * @param evt
	 */
	private void queryConditionComboBoxActionPerformed(ActionEvent evt) {
		// 根据用户选择匹配比较字段		// 定义int型变量, nuserSelect,存储用户选择的字段的索引		int nuserSelect = 0;

		// 获得用户所选字段的		nuserSelect = this.queryConditionComboBox.getSelectedIndex();

		// 用户选择的字段的索引加一		nuserSelect++;
		// 利用switch语句匹配比较符		switch (nuserSelect) {
		case 1:

		case 3:
			// 如果用户选择的是学号和年龄			this.compareComboBox.removeAllItems();
			this.compareComboBox.addItem(">");
			this.compareComboBox.addItem("<");
			this.compareComboBox.addItem("=");
			break;
		case 2:
		case 4:
			// 如果用户选择的是姓名和班级			this.compareComboBox.removeAllItems();
			this.compareComboBox.addItem("匹配");
			this.compareComboBox.addItem("=");
			break;
		default:

		}

	}

	/**
	 * 学生查询,显示学生信息	 * 
	 * @param evt
	 */
	private void studentQueryButton1ActionPerformed(ActionEvent evt) {
		// 查询		// 建立一个JDBC对象		JdbcConnct jdbcConnection = new JdbcConnct();
		// 定义Vector变量,存储从数据库查询来的信息		Vector vecData = new Vector();
		// 定义SQL语句组合项		String strSQL = "select studentid,stuname,age,teachername from zlb.stu_teacher_view ";
		String strSQL1 = " where ";
		String strTemp = " order by studentid ASC";

		// 组合SQL语句		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中数据		DefaultTableModel StuQueryTableModel = new DefaultTableModel(row,
				combListStu);
		this.ClassQueryTable.setModel(StuQueryTableModel);
		// 获得数据		try {
			vecData = jdbcConnection.getData(strSQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		// 依次为各行插入数据		if (vecData.size() > 0) {
			for (int i = 0; i < vecData.size(); i++) {
				StuQueryTableModel.addRow((String[]) vecData.get(i));
			}
			// 显示查询数据			this.ScorQueryTabbedPane
					.setSelectedComponent(this.queryResultPanel);
			//用户点击表格次数置为1
			nclickNum = 1;
		} else {
			JOptionPane.showMessageDialog(this, "您查询的记录在数据库中不存在!请换一个查询条件.");
		}
	}

	/**
	 * 根据用户输入返回SQL语句	 * 
	 * @return
	 */
	private String getUserSelect() {
		// 添加组合查询信息		// 定义boolean型变量 isRight 用户输入是否正确,初始化false
		boolean bisRight = false;
		// 定义String类型,查询字段,比较符,用户输入		String strQueryField = "";
		String strLogicalSymbol = "";
		String strUserInput = "";

		// 用户在组合框中选择的Item索引		int nUserSelect;

		// 定义SQL语句		String strSQL = "";
		// 定义SQL显示语句		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语句进行查询判断		switch (nUserSelect) {
		case 1:
			// 如果用户选择学号			// 校验用户数据			if (strUserInput.matches(REG_DIGIT)) {
				bisRight = true;
				strSQL = "StudentId" + " " + strLogicalSymbol + strUserInput;
				// SQL显示				strSQLView = strQueryField + " " + strLogicalSymbol
						+ strUserInput;
			} else {
				bisRight = false;
				JOptionPane.showMessageDialog(this,
						"请不要在学号中输入字母,班级号为7位数字,请重新输入学号!");
			}
			break;
		case 2:
			// 判断是否为数字型字段			// 如果查询字段为姓名			if (strLogicalSymbol.equals("匹配")) {
				bisRight = true;
				strSQL = "StuName" + " Like '" + strUserInput + "%'";
				// SQL显示				strSQLView = strQueryField + "的前几个字符为:" + strUserInput;
			} else {
				bisRight = true;
				strSQL = "StuName" + " " + strLogicalSymbol + "'"
						+ strUserInput + "'";
				// SQL显示				strSQLView = strQueryField + " " + strLogicalSymbol + " "
						+ strUserInput;
			}
			break;
		case 3:
			// 如果用户选择"年龄"
			// 校验用户数据			if (strUserInput.matches(REG_DIGITAGE)) {
				bisRight = true;
				strSQL = "AGE" + " " + strLogicalSymbol + strUserInput;
				// SQL显示				strSQLView = strQueryField + " " + strLogicalSymbol
						+ strUserInput;

			} else {
				bisRight = false;
				JOptionPane.showMessageDialog(this,
						"请不要在年龄中输入字母,年龄为2位数字,请重新输入!");
			}
			break;
		case 4:
			// 如果用户选择"班主任名"
			// 校验用户数据			if (strLogicalSymbol.equals("匹配")) {
				bisRight = true;
				strSQL = "TeacherName" + " Like '" + strUserInput + "%'";
				// SQL显示				strSQLView = strQueryField + "的前几个字符为:" + strUserInput;
			} else {
				bisRight = true;
				strSQL = "TeacherName" + " " + strLogicalSymbol + "'"
						+ strUserInput + "'";
				// SQL显示				strSQLView = strQueryField + " " + strLogicalSymbol + " "
						+ strUserInput;
			}
			break;
		default:
			JOptionPane.showMessageDialog(this, "您选择的查询字段不存在,请重新选择!");
		}

		// 如果用户输入错误,查询学生条件减一		if (!bisRight) {
			ncount--;
		}

		// 对用户选择进行操作 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控件中写入数据		this.studentQueryList1.setListData(vecListView);
		return strSQL;
	}

	/**
	 * 根据用户选择返回SQL语句	 * 
	 * @return String strSQL
	 */
	private String getUserSelectClass() {
		// 添加组合查询信息		// 定义boolean型变量 isRight 用户输入是否正确,初始化false
		boolean bisRight = false;
		// 定义String类型,查询字段,比较符,用户输入		String strQueryField = "";
		String strLogicalSymbol = "";
		String strUserInput = "";

		// 用户在组合框中选择的Item索引		int nUserSelect;

		// 定义SQL语句		String strSQL = "";
		// 定义SQL显示语句		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语句进行查询判断		switch (nUserSelect) {
		case 1:
			// 如果用户选择班级号			// 校验用户数据			if (strUserInput.matches(REG_DIGITCLASS)) {
				bisRight = true;
				strSQL = "ClassId" + " " + strLogicalSymbol + strUserInput;
				// SQL显示				strSQLView = strQueryField + " " + strLogicalSymbol
						+ strUserInput;
			} else {
				bisRight = false;
				JOptionPane.showMessageDialog(this,
						"请不要在班级号中输入字母,班级号为7位数字,请重新输入班级号!");
			}
			break;
		case 2:
			// 判断是否为数字型字段			// 如果查询字段为班级名			if (strLogicalSymbol.equals("匹配")) {
				bisRight = true;
				strSQL = "ClassName" + " Like '" + strUserInput + "%'";
				// SQL显示				strSQLView = strQueryField + "的前几个字符为:" + strUserInput;
			} else {
				bisRight = true;
				strSQL = "ClassName" + " " + strLogicalSymbol + "'"
						+ strUserInput + "'";
				// SQL显示				strSQLView = strQueryField + " " + strLogicalSymbol + " "
						+ strUserInput;
			}
			break;
		case 3:
			// 如果用户选择"届别"
			// 校验用户数据			if (strUserInput.matches(REG_DIGITFLAGYEAR)) {
				bisRight = true;
				strSQL = "flagYear" + " " + strLogicalSymbol + "'"
						+ strUserInput + "' ";
				// SQL显示				strSQLView = strQueryField + " " + strLogicalSymbol
						+ strUserInput;

			} else {
				bisRight = false;
				JOptionPane.showMessageDialog(this,
						"请不要在届别中输入字母,届别为4位数字,请重新输入!");
			}
			break;

		default:
			JOptionPane.showMessageDialog(this, "您选择的查询字段不存在,请重新选择!");
		}

		// 如果用户输入不正确,班级查询条件数减一		if (!bisRight) {
			ncountClass--;

		}
		// 对用户选择进行操作 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控件中写入数据		this.ClassQueryList.setListData(vecListViewClass);
		return strSQL;
	}
	
	/**
	 * 退出	 * @param evt
	 */
	private void exitButtonActionPerformed(ActionEvent evt) {
		//退出		this.dispose();
	}
	
	/**
	 * 鼠标滚轮事件,滚动鼠标改变年份	 * @param evt
	 */
	private void yearSelectSpinnerMouseWheelMoved(MouseWheelEvent evt) {
		//添加鼠标滚轮事件,滚动鼠标改变年份		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());
		}		
	}
	/**
	 * 点击鼠标,选择学生成绩查询或班级成绩查询	 * @param evt
	 */
	private void ClassQueryTableMouseClicked(MouseEvent evt) {
		// 定义变量bisStudent,判断是否选择学生表,初始化为false
		boolean bisStudent = false;
		//班级号、班级名		String strclassId   =  "";
		String strclassName =  "";
		//鼠标点击行		int nrow = 0;
		
		//获得用户选择类型		bisStudent= this.getUserSelectType();
		//获取鼠标点击行		nrow  = this.ClassQueryTable.getSelectedRow();
		
		//获取前两个数据		strclassId = String.valueOf(this.ClassQueryTable.getValueAt(nrow, 0));
		strclassName = String.valueOf(this.ClassQueryTable.getValueAt(nrow, 1));
		
		//如果首次点击班级信息查询表		if(bisStudent
				&&nclickNum == 1){
			//用户点击次数加一			nclickNum++;
			//显示学生成绩查询组件,隐藏班级成绩查询组件			this.SetQueryModel(bisStudent);
			
		}else if(!bisStudent
				&&nclickNum == 1){
			//如果首次点击班级信息查询表			//用户点击次数加一			nclickNum++;
			//显示班级成绩查询组件,隐藏学生成绩查询组件			this.SetQueryModel(bisStudent);
		}
		
		if(bisStudent
				&&nclickNum >1){
			//对学生表点击进行操作			
		}else if(!bisStudent
				&&nclickNum >1){
			//对班级表点击进行操作,显示班级号、班级名			this.classIdViewLabel.setText(strclassId);
			this.classNameViewLabel.setText(strclassName);			
		}
		
	}
	
	private void SetQueryModel(boolean bisStudent){
		
		if(bisStudent){
			//显示学生成绩查询组件			this.fullQueryRadioButton.setVisible(true);
			this.commonRadioButton.setVisible(true);
			this.yearSelectSpinner.setVisible(true);
			this.conditionComboBox.setVisible(true);
			this.studentQueryButton.setVisible(true);
			//显示学生成绩查询标签			this.stuQueryViewLabel.setText("学生成绩查询");
			//隐藏班级成绩查询组件			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{
			//显示班级成绩查询组件			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);
			//显示班级成绩查询标签			this.stuQueryViewLabel.setText("班级成绩查询");			
			//隐藏学生成绩查询组件			this.fullQueryRadioButton.setVisible(false);
			this.commonRadioButton.setVisible(false);
			this.yearSelectSpinner.setVisible(false);
			this.conditionComboBox.setVisible(false);
			this.studentQueryButton.setVisible(false);			
		}
	}
	
	/**
	 * 返回用户选择的对象	 * 
	 * @return bisStudent,true为学生、false为教师	 */
	private boolean getUserSelectType() {
		// 定义变量bisStudent,判断是否选择学生,初始化为false
		boolean bisStudent = false;
		if (this.ClassQueryTable.getColumnCount() == 4) {
			bisStudent = true;

⌨️ 快捷键说明

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