📄 presentquerydialog.java
字号:
* 选择班级查询条件
*/
private void ClassQueryComboBoxActionPerformed(ActionEvent evt) {
String strUserSelectclass = "";
// 获取用户选择字段
strUserSelectclass = this.ClassQueryComboBox.getSelectedItem()
.toString();
if (strUserSelectclass.equals("班级名")) {
this.conditionComboBox.removeAllItems();
this.conditionComboBox.addItem("匹配");
this.conditionComboBox.addItem("=");
}
if (strUserSelectclass.equals("班级号") || strUserSelectclass.equals("届别")) {
this.conditionComboBox.removeAllItems();
this.conditionComboBox.addItem(">");
this.conditionComboBox.addItem("<");
this.conditionComboBox.addItem("=");
}
}
/**
* 学生查询
* @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 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.querButton.setVisible(true);
// 显示查询数据
this.presentTabbedPane
.setSelectedComponent(this.queryResultPanel1);
} else {
JOptionPane.showMessageDialog(this, "您查询的记录在数据库中不存在!请换一个查询条件.");
}
}
}
/**
* 清空按钮事件
*/
private void ClearButtonActionPerformed(ActionEvent evt) {
ncount = 1;
// 清空Vector变量vecSQL vecListView清空List控件中查询条件
this.vecSQL.clear();
this.vecListView.clear();
this.studentQueryList1.setListData(vecListView);
// 清除按钮不可用
this.ClearButton.setEnabled(false);
}
//选择年份
private void yearSelectjSpinner1MouseWheelMoved(MouseWheelEvent evt) {
// 鼠标滚轮事件,选择年份
if (evt.getWheelRotation() < 0
&& Integer.parseInt((String) yearSelectjSpinner1.getValue()) < this.nowYear + 9) {
yearSelectjSpinner1.setValue(yearSelectjSpinner1.getNextValue());
} else if (evt.getWheelRotation() > 0
&& Integer.parseInt((String) yearSelectjSpinner1.getValue()) > this.nowYear - 10) {
yearSelectjSpinner1
.setValue(yearSelectjSpinner1.getPreviousValue());
}
}
//出勤查询条件选择
private void preSelectConditionComboBoxActionPerformed(ActionEvent evt) {
// 出勤查询条件匹配
// 用户在组合框中选择的Item索引
int nUserSelect;
// 用户选择的查询字段的索引
nUserSelect = this.preSelectConditionComboBox.getSelectedIndex();
// 用户选择的查询字段的索引加一
nUserSelect++;
System.out.println(nUserSelect);
// 根据用户选择匹配查询条件
switch (nUserSelect) {
case 1:
this.selectConditionComboBox.removeAllItems();
for (int i = 1; i <= 18; i++) {
this.selectConditionComboBox.addItem("上学期第" + i + "周");
}
for (int i = 1; i <= 18; i++) {
this.selectConditionComboBox.addItem("下学期第" + i + "周");
}
break;
case 2:
this.selectConditionComboBox.removeAllItems();
for (int i = 1; i <= 12; i++) {
if (i != 2 && i != 8) {
this.selectConditionComboBox.addItem(" " + i + "月");
}
}
break;
case 3:
this.selectConditionComboBox.removeAllItems();
for (int i = 1; i <= 4; i++) {
this.selectConditionComboBox.addItem("第" + i + "季度");
}
break;
case 4:
this.selectConditionComboBox.removeAllItems();
this.selectConditionComboBox.addItem("上学期");
this.selectConditionComboBox.addItem("下学期");
break;
default:
JOptionPane.showMessageDialog(this, "您选择的查询字段不存在,请重新选择!");
}
}
/**
* 班级查询,显示班级信息
* @param evt 鼠标响应事件
*/
private void queryButtoncActionPerformed(ActionEvent evt) {
// 查询班级
// 建立一个JDBC对象
JdbcConnct jdbcConnection = new JdbcConnct();
// 定义Vector变量,存储从数据库查询来的信息
Vector vecData = new Vector();
// 定义SQL语句组合项
String strSQL = "select classid,classname,flagyear from classes ";
String strSQL1 = " where ";
String strTemp = " order by classid ASC";
// 组合SQL语句
if (this.vecSQLClass.isEmpty()) {
strSQL += strTemp;
} else {
for (int i = 0; i < this.vecSQLClass.size(); i++) {
strSQL1 += this.vecSQLClass.get(i).toString();
}
strSQL += strSQL1 + strTemp;
// 刷新table中数据
DefaultTableModel StuQueryTableModel = new DefaultTableModel(row,
combListClass);
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.querButton.setVisible(true);
// 显示查询数据
this.presentTabbedPane
.setSelectedComponent(this.queryResultPanel1);
} else {
JOptionPane.showMessageDialog(this, "您查询的记录在数据库中不存在!请换一个查询条件.");
}
}
}
private void clearButtonActionPerformed(ActionEvent evt) {
ncountClass = 1;
// 清空Vector变量vecSQL vecListView清空List控件中查询条件
this.vecSQLClass.clear();
this.vecListViewClass.clear();
this.ClassQueryList.setListData(vecListViewClass);
// 清除按钮不可用
this.clearButton.setEnabled(false);
}
private void ClassQueryScrollPane1MouseClicked(MouseEvent evt) {
// 鼠标点击,获取点击行数据,显示在界面上
// 定义变量 "班级号", "班级名", "届别", "出勤率"
String strclassId = "";
int nclassid = 0;
String strclassName = "";
String flagyear = "";
int nflagyear = 0;
// 定义鼠标点击行
int nrow = 0;
// 获取鼠标点击行
nrow = this.ClassQueryTable.getSelectedRow();
// 定义鼠标点击行
// 获取行内数据
strclassId = String.valueOf(this.ClassQueryTable.getValueAt(nrow, 0));
strclassName = String.valueOf(this.ClassQueryTable.getValueAt(nrow, 1));
flagyear = String.valueOf(this.ClassQueryTable.getValueAt(nrow, 2));
// 类型转换
try {
nclassid = Integer.parseInt(strclassId);
nflagyear = Integer.parseInt(flagyear);
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
/**
* 根据用户选择返回SQL子句
*
* @return SQL子句
*/
private String getUserSelectPresent() {
// 根据用户选择返回SQL语句
// 定义变量bisStudent,判断是否选择学生,初始化为false
boolean bisStudent = false;
// 定义变量 "班级号","班级名"、"届别" "学号","姓名"
String strclassId = "";
String strclassName = "";
String strflagYear = "";
String strStudentId = "";
String strStudentName = "";
int nclassid = 0;
int nclassId = 0;
// 定义鼠标点击行
int nrow = 0;
// 定义SQL语句组合项
String strSQL = "select presentStatus from present ";
String strSQL1 = " where ";
String strTemp = " order by presentStatus ASC ";
String strSQLQueryClass ="select p.presentstatus from present p " +
"where p.studentid in "+
"(select s.studentid from student s where s.classid = " ;
//定义查询显示queryView,用于向用户显示查询信息
String strQueryView = "";
// 获取鼠标点击行
nrow = this.ClassQueryTable.getSelectedRow();
bisStudent = this.getUserSelectType();
if (bisStudent) {
// 如果选择的是学生,获得学号
strStudentId = String.valueOf(this.ClassQueryTable.getValueAt(nrow,
0));
strSQL1 += "StudentId = " + strStudentId +" and ";
// 获取SQL子句
strSQL += strSQL1 + this.getUserSelectPresentRange() + strTemp;
//获得查询条件后打印出查询条件
strpreQueryView +=" 学生出勤查询";
this.presentQueryViewLabel.setText(strpreQueryView);
// 打印出SQL语句
System.out.println("\t" + strSQL);
} else {
// 如果选择的是班级,获得班级号,班级名、届别
strclassId = String.valueOf(this.ClassQueryTable
.getValueAt(nrow, 0));
strclassName = String.valueOf(this.ClassQueryTable.getValueAt(nrow,
1));
strflagYear = String.valueOf(this.ClassQueryTable.getValueAt(nrow,
2));
//组合SQL语句
strSQLQueryClass += strclassId+" ) and "+ this.getUserSelectPresentRange() + strTemp;
//赋值给SQL语句
strSQL = strSQLQueryClass;
//获得查询条件后打印出查询条件
strpreQueryView +=" 班级出勤查询";
this.presentQueryViewLabel.setText(strpreQueryView);
// 打印出SQL语句
System.out.println("\t" + strSQL);
}
return strSQL;
}
/**
* 返回用户选择的对象
*
* @return bisStudent,true为学生、false为教师
*/
private boolean getUserSelectType() {
// 定义变量bisStudent,判断是否选择学生,初始化为false
boolean bisStudent = false;
if (this.ClassQueryTable.getColumnCount() == 4) {
bisStudent = true;
} else {
bisStudent = false;
}
//打印是否选择学生
System.out.println("\n 是否选择学生表:"+bisStudent);
return bisStudent;
}
/**
* 根据用户选择返回出勤查询得日期范围
* @return String strSQL 出勤查询SQL子句
*/
private String getUserSelectPresentRange() {
// 定义年\月\日
String year = "";
int nyear = 0;
// 定义用户所选的周、月、季度、学期
int nquarter = 0;
int nmonth = 0;
int nweek = 0;
// 用户在组合框中选择的Item索引
int nUserSelect;
// 用户选择的条件索引
int nUserSelectConditionNum;
// 定义SQL语句
String strSQL = "";
//定义查询显示queryView,用于向用户显示查询信息
String strpresentQueryView = "";
// 新建开始时间对象
Date startDate = new Date();
// 新建开始时间对象
Date endDate = new Date();
// 定义String类型开始和结束时间
String strStartDate = "";
String strEndDate = "";
// 新建日期格式化对象
SimpleDateFormat simpleFormat = new SimpleDateFormat("yyyy-MM-dd");
// 获得用户选择的年份
year = String.valueOf(this.yearSelectjSpinner1.getValue());
//向用户显示查询年份
strpresentQueryView = year +" 年 ";
// 数值转换
try {
nyear = Integer.parseInt(year);
} catch (NumberFormatException e) {
e.printStackTrace();
}
System.out.println("\t" + year);
// 新建一个Calendar对象
Calendar calendar = Calendar.getInstance();
//初始化设置为所选年的3月1号,Calendar月份从0开始
calendar.set(nyear, 2, 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -