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

📄 coursemagdialog.java

📁 学生管理系统。使用java编程
💻 JAVA
📖 第 1 页 / 共 4 页
字号:

		// 获得查询字段,比较符,用户输入		strQueryField = this.CourseQueryComboBox1.getSelectedItem().toString();
		strLogicalSymbol = this.CompareComboBox.getSelectedItem().toString();
		strUserInput = this.QueryTextField.getText();

		// 用户选择的Item索引		nUserSelect = this.CourseQueryComboBox1.getSelectedIndex();
		// 获得最大值,最小值		strMin = this.FirstTextField.getText();
		strMax = this.EndTextField1.getText();

		// 用户选择的查询字段索引加一		nUserSelect++;
		// 打印用户选择的查询字段的索引		System.out.println("\t" + nUserSelect);

		if (this.SelectRageCheckBox.isSelected()) {
			// 如果用户选择按范围查询			isSelectRage = true;
			// 利用switch语句进行判断			switch (nUserSelect) {
			case 1:
				// 如果用户选择科目号				// 校验用户数据				if (strMin.matches(REG_DIGCOUID)
						&& strMax.matches(REG_DIGCOUID)) {
					bisRight = true;
				} else {
					bisRight = false;
					JOptionPane.showMessageDialog(this,
							"请不要在学科号中输入字母,学科为数值型,请重新输入科目号!");
				}
				break;

			case 2:

				// 如果用户选择科目名				if (strQueryField.equals("科目名")) {
					bisRight = false;
					JOptionPane.showMessageDialog(this,
							"选择按范围查询时,请选择数值型的查询数据!请重新选择查询选项。");
				}				
				break;
			case 3:
				// 如果用户选择学时				// 校验用户数据				if (strMin.matches(REG_DIGPREIOD)
						&& strMax.matches(REG_DIGPREIOD)) {
					bisRight = true;
				} else {
					bisRight = false;
					JOptionPane.showMessageDialog(this,
							"请不要在学时中输入字母,学时在(0,200)内,请重新输入学时!");
				}
				break;
			case 4:
				// 如果用户选择学分				// 校验用户数据				if (strMin.matches(REG_FLOATHOUR)
						&& strMax.matches(REG_FLOATHOUR)) {
					bisRight = true;
				} else {
					bisRight = false;
					JOptionPane.showMessageDialog(this,
							"请不要在学分中输入字母,学分在(0,5)内,请重新输入学分!");
				}
				break;
			default:
				JOptionPane.showMessageDialog(this, "您选择的查询字段不存在,请重新选择!");
			}

		} else {
			// 如果用户选择按范围查询			isSelectRage = false;
			// 组合SQL子句 where后			switch (nUserSelect) {
			case 1:
				// 如果用户选择科目号				// 校验用户数据				if (strUserInput.matches(REG_DIGCOUID)) {
					bisRight = true;
					strSQL = "courseId" + " " + strLogicalSymbol + strUserInput;
					// SQL显示					strSQLView = strQueryField + " " + strLogicalSymbol
							+ strUserInput;
				} else {
					bisRight = false;
					JOptionPane.showMessageDialog(this,
							"请不要在学科号中输入字母,学科为数值型,请重新输入学科号!");
				}
				break;
			case 2:
				// 如果用户选择"科目名"
				//判断科目名是否超长				if(strUserInput.length() > 100){
					bisRight = false;
					JOptionPane.showMessageDialog(this,
							"学科名最多50个汉字,请重新输入学科名!");			
				}else{
					bisRight = true;					
				}
				if (strLogicalSymbol.equals("匹配")
						&&bisRight) {
					bisRight = true;
					strSQL = "courseName" + " Like '" + strUserInput + "%'";
					// SQL显示					strSQLView = strQueryField + "的前几个字符为:" + strUserInput;
				} else if(bisRight){
					bisRight = true;
					strSQL = "courseName" + " " + strLogicalSymbol + "'"
							+ strUserInput + "'";
					// SQL显示					strSQLView = strQueryField + " " + strLogicalSymbol + " "
							+ strUserInput;
				}
				break;
			case 3:
				// 如果用户选择学时				// 校验用户数据				if (strUserInput.matches(REG_DIGPREIOD)) {
					try {
						nUserInput = Integer.parseInt(strUserInput);
					} catch (NumberFormatException e) {
						e.printStackTrace();
					}
					if (nUserInput > 200) {
						bisRight = false;
						JOptionPane.showMessageDialog(this,
								"您输入的学时超出范围。\n学时在(0,200]内,请重新输入!");
					} else {
						// 组合SQL语句						bisRight = true;
						strSQL = "period" + " " + strLogicalSymbol
								+ strUserInput;
						// SQL显示						strSQLView = strQueryField + " " + strLogicalSymbol
								+ strUserInput;
					}

				} else {
					bisRight = false;
					JOptionPane.showMessageDialog(this,
							"请不要在学时中输入字母,学时在(0,200)内,请重新输入学时!");
				}

				break;
			case 4:
				// 用户选择为数值型变量 学分				if (strUserInput.matches(REG_FLOATHOUR)) {
					try {
						dUserInput = Double.parseDouble(strUserInput);
					} catch (NumberFormatException e) {
						e.printStackTrace();
					}
					if (dUserInput > 5) {
						bisRight = false;
						JOptionPane.showMessageDialog(this,
								"您输入的学分超出范围。\n学分在(0,5]内,请重新输入!");
					} else {
						strSQL = "creditHour" + " " + strLogicalSymbol
								+ strUserInput;
						// SQL显示						strSQLView = strQueryField + " " + strLogicalSymbol
								+ strUserInput;
						bisRight = true;
					}
				} else {
					bisRight = false;
					JOptionPane.showMessageDialog(this,
							"请不要在学分中输入字母,学分在(0,5)内,请重新输入学分!");
				}
				break;
			default:
				JOptionPane.showMessageDialog(this, "您选择的查询字段不存在,请重新选择!");
			}
		}

		// 如果用户选择”范围查询“、没有选择科目名且初始校验成功,        //进行第二轮校验,返回科目号,学时、学分的查询语句		if (!strQueryField.equals("科目名") && isSelectRage && bisRight) {
			// 数值转换			try {
				dMin = Double.parseDouble(strMin);
				dMax = Double.parseDouble(strMax);
			} catch (NumberFormatException e) {
				e.printStackTrace();
				JOptionPane.showMessageDialog(this, "数值转换错误!请确认输入值");
			}
			// 校验用户输入的信息 输入范围是否前小后大			if (dMin > dMax) {
				bisRight = false;
				JOptionPane.showMessageDialog(this, "选择按范围查询时,前一个值需小于后一个值");
			} else
				bisRight = true;

			// 根据用户查询字段校验输入范围			// 利用switch语句进行判断			if (bisRight) {
				switch (nUserSelect) {
				case 1:
					// 如果用户选择科目号					strSQL = "courseId" + " between " + dMin + " and " + dMax;
					strSQLView = strQueryField + " 大于 " + dMin + " 小于 " + dMax;
					break;
				case 3:
					// 如果用户选择学时					if (dMin == 0 || dMax > 200) {
						bisRight = false;
						JOptionPane.showMessageDialog(this,
								"您输入的学时超出范围。\n学时在(0,200]内,请重新输入!");
					} else {
						// 组合SQL语句						strSQL = "period" + " between " + dMin + " and " + dMax;
						strSQLView = strQueryField + " 大于 " + dMin + " 小于 "
								+ dMax;
						bisRight = true;
					}
					break;
				case 4:
					// 如果用户选择学分					if (dMin == 0 || dMax > 5) {
						bisRight = false;
						JOptionPane.showMessageDialog(this,
								"您输入的学分超出范围。\n学分在(0,5]内,请重新输入!");
					} else {
						// 组合SQL语句						strSQL = "creditHour" + " between " + dMin + " and "
								+ dMax;
						// SQL显示						strSQLView = strQueryField + " 大于 " + dMin + " 小于 "
								+ dMax;

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

				}
			}
		}else if(!bisRight){
			//若用户操作失败,则用户查询条件数量减一			ncount--;
		}

		// 对用户选择进行操作 none and or
		if (this.PrecisionRadioButton.isSelected()) {

		} else if (this.FaintnessRadioButton.isSelected()) {
			// 添加按钮置为可用			this.AddButton.setEnabled(true);
			strSQLView = "并且 " + strSQLView;
			strSQL = "and " + strSQL;
		} else {
			// 添加按钮置为可用			this.AddButton.setEnabled(true);
			strSQLView = "或者 " + strSQLView;
			strSQL = "or " + strSQL;
		}
		//如果校验成功则显示SQL查询信息		if(bisRight){
			this.vecListView.add(strSQLView);
			// 向List控件中写入数据			this.SQLComjList.setListData(vecListView);
		}
		return strSQL;
	}

	private void PrecisionRadioButtonActionPerformed(ActionEvent evt) {
		System.out
				.println("PrecisionRadioButton.actionPerformed, event=" + evt);
		// TODO add your code for PrecisionRadioButton.actionPerformed
		// 添加按钮置为不可用		this.AddButton.setEnabled(true);

	}

	private void FaintnessRadioButtonActionPerformed(ActionEvent evt) {
		System.out
				.println("FaintnessRadioButton.actionPerformed, event=" + evt);
		// TODO add your code for FaintnessRadioButton.actionPerformed
		// 添加按钮置为可用		this.AddButton.setEnabled(true);

	}

	private void OrRadioButtonActionPerformed(ActionEvent evt) {
		System.out.println("OrRadioButton.actionPerformed, event=" + evt);
		// TODO add your code for OrRadioButton.actionPerformed
		// 添加按钮置为可用		this.AddButton.setEnabled(true);
	}

	private boolean isReferenceOtherForm(String strSQL) {
		// 建立一个JDBC对象		JdbcConnct jdbcConnection = new JdbcConnct();
		// 定义Vector变量,存储从数据库查询来的信息		Vector vecData = new Vector();

		return false;
	}

	class Course {
		// 定义Course属性 学科号、学科名、学时、学分		private int ncourseId;

		private String strCourseName;

		private int nPreiod;

		private float fCreditHour;

		/**
		 * 初始化方法		 * 
		 * @param courseId
		 * @param courseName
		 * @param preiod
		 * @param creditHour
		 */
		public Course(int courseId, String courseName, int preiod,
				float creditHour) {
			this.ncourseId = courseId;
			this.strCourseName = courseName;
			this.nPreiod = preiod;
			this.fCreditHour = creditHour;
		}

		/**
		 * 无参初始化方法		 * 
		 */
		public Course() {
			this.ncourseId = 0;
			this.strCourseName = "";
			this.nPreiod = 0;
			this.fCreditHour = 0.0f;
		}

		/**
		 * 定义属性器setValue() 设置变量值		 * 
		 * @param courseId
		 * @param courseName
		 * @param preiod
		 * @param creditHour
		 */
		public void setValue(int courseId, String courseName, int preiod,
				float creditHour) {
			this.ncourseId = courseId;
			this.strCourseName = courseName;
			this.nPreiod = preiod;
			this.fCreditHour = creditHour;
		}

		/**
		 * 定义属性器getCouId() 返回课程号		 * 
		 * @return
		 */
		public int getCouId() {
			return this.ncourseId;
		}

		/**
		 * 定义属性器getCourseName() 返回课程名		 * 
		 * @return
		 */
		public String getCourseName() {
			return this.strCourseName;
		}

		/**
		 * 定义属性器getPreiod() 学时		 * 
		 * @return Preiod
		 */
		public int getPreiod() {
			return this.nPreiod;
		}

		/**
		 * 定义属性器getCreditHour() 返回学分		 * 
		 * @return
		 */
		public float getCreditHour() {
			return this.fCreditHour;
		}

	}
}

⌨️ 快捷键说明

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