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

📄 tesaction.java

📁 包含了学生管理系统的一些基本操作以及相关窗口页面实现。
💻 JAVA
字号:
package com.hb.studentmanager.action;

import java.util.Iterator;
import java.util.List;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTable;
import com.hb.studentmanager.date.SubDTO;
import com.hb.studentmanager.date.TesDAO;
import com.hb.studentmanager.date.TesDTO;

public class TesAction {
	TesDAO dao = new TesDAO();// 创建一个功能对象

	TesDTO dto = new TesDTO();// 创建一个数据对象
	// 返回y 年 m 月的天数

	public int mdays(int y, int m) {
		int d = 31;
		if (m == 4 || m == 6 || m == 9 || m == 11)
			d = 30;
		else if (m == 2)
			d = (y % 4 == 0 && y % 100 != 0 || y % 400 == 0) ? 29 : 28;
		return d;
	}

	// 从考试表中查询tes_date
	public List selecttesdate(int flag) {
		return dao.selecttes_date(flag);
	}

	// 从科目表中查询sub_id
	public List selectsubid() {
		return dao.selectsub_id();
	}

	// 条件查询
	public void tesSelect(JTable table, int page, String tesid, String subid,
			String time1, String time2, String address, String tea) {
		List list = dao.tesSelect(tesid, subid, time1, time2, address, tea);
		if (list.isEmpty()) {
			JOptionPane.showMessageDialog(new JFrame(), "找不到和您的查询条件相符的记录 !");
		} else {
			Iterator it = list.iterator();
			for (int i = 0; i < (page - 1) * 5; i++) {
				it.next();// 只显示第page页数据
			}
			for (int i = 1; i < table.getRowCount(); i++) {
				if (it.hasNext()) {
					dto = (TesDTO) it.next();
					table.setValueAt(dto.getTes_id(), i, 0);
					table.setValueAt(dto.getSub_id(), i, 1);
					table.setValueAt(dto.getTes_date(), i, 2);
					table.setValueAt(dto.getTes_add(), i, 3);
					table.setValueAt(dto.getTes_tea(), i, 4);
				} else {
					table.setValueAt("", i, 0);
					table.setValueAt("", i, 1);
					table.setValueAt("", i, 2);
					table.setValueAt("", i, 3);
					table.setValueAt("", i, 4);
				}
			}
		}
	}

	// 返回查询结果总页码
	public int pageCountSelect(String tesid, String subid, String time1,
			String time2, String address, String tea) {
		int page, rowCount = 0;
		List list = dao.tesSelect(tesid, subid, time1, time2, address, tea);
		Iterator it = list.iterator();
		while (it.hasNext()) {
			it.next();
			rowCount++;
		}
		if (rowCount % 5 == 0)
			page = rowCount / 5;
		else
			page = rowCount / 5 + 1;
		return page;
	}

	// 添加
	public boolean add(String tes_id, String sub_id, String tes_date,
			String tes_add, String tes_tea) {
		List list = dao.judge(tes_id);
		if (list.isEmpty() == false) {
			JOptionPane.showMessageDialog(new JFrame(), "考试编号已存在!");
			return false;
		} else {
			dto.setTes_id(tes_id);
			dto.setSub_id(sub_id);
			dto.setTes_date(tes_date);
			dto.setTes_add(tes_add);
			dto.setTes_tea(tes_tea);
			dao.tesInsert(dto);
			return true;
		}
	}

	// 修改
	public void update(String tesid, String subid, String tesdate,
			String tesadd, String testea) {

		dao.tesUpdate(tesid, subid, tesdate, tesadd, testea);
	}

	// 删除
	public void delete(String tesid) {
		dao.tesDelete(tesid);
	}

	// 返回当前总页码
	public int pageCount() {
		int page, rowCount = 0;
		List list = dao.init();
		Iterator it = list.iterator();
		while (it.hasNext()) {
			it.next();
			rowCount++;
		}
		if (rowCount % 5 == 0)
			page = rowCount / 5;
		else
			page = rowCount / 5 + 1;
		return page;
	}

	// 显示结果
	public void init(JTable table, int page, int pageSize) {
		List list = dao.init();
		Iterator it = list.iterator();
		for (int i = 0; i < (page - 1) * 5; i++) {
			it.next();// 只显示第page页数据
		}
		for (int i = 1; i < table.getRowCount(); i++) {
			if (it.hasNext()) {
				dto = (TesDTO) it.next();
				table.setValueAt(dto.getTes_id(), i, 0);
				table.setValueAt(dto.getSub_id(), i, 1);
				if (dto.getTes_date() == null)
					table.setValueAt(dto.getTes_date(), i, 2);
				else
					table.setValueAt(dto.getTes_date().substring(0, 16), i, 2);
				table.setValueAt(dto.getTes_add(), i, 3);
				table.setValueAt(dto.getTes_tea(), i, 4);
			} else {
				table.setValueAt("", i, 0);
				table.setValueAt("", i, 1);
				table.setValueAt("", i, 2);
				table.setValueAt("", i, 3);
				table.setValueAt("", i, 4);
			}
		}
	}

	// /////******//////
	public void tesdate(JComboBox tesDateComboBox, int flag) {
		Iterator it = selecttesdate(flag).iterator();
		while (it.hasNext()) {
			TesDTO dto = (TesDTO) it.next();
			if (dto.getTes_date() == null)
				tesDateComboBox.addItem(dto.getTes_date());
			else
				tesDateComboBox.addItem(dto.getTes_date().substring(0, 16));
		}
	}

	public void subid(JComboBox subComboBox, String subid) {
		subComboBox.addItem(subid);
		if (!subid.equals(""))
			subComboBox.addItem("");
		Iterator it = selectsubid().iterator();
		while (it.hasNext()) {
			SubDTO dto = (SubDTO) it.next();
			if (dto.getSub_id().equals(subid))
				continue;
			subComboBox.addItem(dto.getSub_id());
		}
	}

}

⌨️ 快捷键说明

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