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

📄 studentpanelaction.java

📁 培训时做的学生管理系统.基于J2SE平台开发
💻 JAVA
字号:
package cn.com.action.studentmanageraction;

import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.print.PrinterException;
import java.util.Vector;

import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import cn.com.dao.studentmanagerdao.StudentDao;
import cn.com.dialog.studentmanagerdialog.StudentAdd;
import cn.com.dialog.studentmanagerdialog.StudentHighSelectDialog;
import cn.com.dialog.studentmanagerdialog.StudentUpdateDialog;
import cn.com.panel.studentmanagerpanel.StudentPanel;
import cn.com.studentsystem.excel.StudentExcelFrame;
import cn.com.studentsystem.excel.StudentPutOutExcel;
import cn.com.util.LogWriter;
import cn.com.vo.studentmanagervo.StudentVo;

public class StudentPanelAction implements ActionListener {

	private StudentVo studentVo;

	private StudentPanel studentPanel;

	private String[] column = { "学号", "组号", "姓名", "性别", "年级", "学校", "专业",
			"联系号码", "QQ", "电子邮件" };

	private LogWriter logWriter;

	public StudentPanelAction(StudentPanel studentPanel, LogWriter logWriter) {
		super();
		this.studentPanel = studentPanel;
		this.logWriter = logWriter;
	}

	public void actionPerformed(ActionEvent e) {

		String str = e.getActionCommand();
		StudentDao studentdao = null;
		if (str.equals("查询")) {
			String str1 = studentPanel.getSelect();
			if (str1.equals("查询全部学生信息")) {
				logWriter.Log("查询了全部学生的成绩");
				studentdao = new StudentDao();
				Object[][] s2 = studentdao.selectAll();
				studentPanel.creatJTable().setModel(
						new DefaultTableModel(s2, column));
			} else if (str1.equals("根据学号查询学生信息")) {
				if (studentPanel.getInput().equals("")) {
					javax.swing.JOptionPane
							.showMessageDialog(null, "查询条件不能为空!");
				} else {
					try {
						studentVo = new StudentVo();
						studentVo.setS_id(Integer.parseInt(studentPanel
								.getInput()));
						studentdao = new StudentDao(studentVo);
						Object[][] s2 = studentdao.selectBySid();
						studentPanel.creatJTable().setModel(
								new DefaultTableModel(s2, column));
						if (s2.length == 0) {
							javax.swing.JOptionPane.showMessageDialog(null,
									"没有搜索到结果!");
						}
					} catch (NumberFormatException ex) {
						javax.swing.JOptionPane.showMessageDialog(null,
								"请输入正确的字符格式!");
					}
				}
			} else if (str1.equals("根据组号查询学生信息")) {
				if (studentPanel.getInput().equals("")) {
					javax.swing.JOptionPane
							.showMessageDialog(null, "查询条件不能为空!");
				} else {
					try {
						studentVo = new StudentVo();
						studentVo.setG_id(Integer.parseInt(studentPanel
								.getInput()));
						studentdao = new StudentDao(studentVo);
						Object[][] s2 = studentdao.selectByGid();
						studentPanel.creatJTable().setModel(
								new DefaultTableModel(s2, column));
						if (s2.length == 0) {
							javax.swing.JOptionPane.showMessageDialog(null,
									"没有搜索到结果!");
						}
					} catch (NumberFormatException ex) {
						javax.swing.JOptionPane.showMessageDialog(null,
								"请输入正确的字符格式!");
					}
				}
			} else if (str1.equals("根据姓名查询学生信息")) {
				if (studentPanel.getInput().equals("")) {
					javax.swing.JOptionPane
							.showMessageDialog(null, "查询条件不能为空!");
				} else {
					studentVo = new StudentVo();
					studentVo.setS_name(studentPanel.getInput());
					studentdao = new StudentDao(studentVo);
					Object[][] s2 = studentdao.selectByName();
					studentPanel.creatJTable().setModel(
							new DefaultTableModel(s2, column));
					if (s2.length == 0) {
						javax.swing.JOptionPane.showMessageDialog(null,
								"没有搜索到结果!");
					}
				}
			}
		} else if (str.equals("高级查询")) {
			StudentHighSelectDialog dialog = new StudentHighSelectDialog(
					studentPanel);
			dialog.CreatHighSelectDialog().setVisible(true);
		} else if (str.equals("刷新")) {
			studentdao = new StudentDao(studentVo);
			Object[][] s2 = studentdao.selectAll();
			studentPanel.creatJTable().setModel(
					new DefaultTableModel(s2, column));
		} else if (str.equals("增加信息")) {
			StudentAdd dialog = new StudentAdd();
			JDialog dialog1 = dialog.addstudent();
			dialog1.setModal(true);
		} else if (str.equals("删除信息")) {
			if (studentPanel.creatJTable().getSelectedRow() >= 0) {
				studentVo = new StudentVo();
				int i = studentPanel.getChevementJtable().getSelectedRow();
				int stuid = Integer.parseInt(studentPanel.getChevementJtable()
						.getValueAt(i, 0).toString());
				studentVo.setS_id(stuid);
				int choice = javax.swing.JOptionPane.showConfirmDialog(null,
						"确定删除?", "删除确认", JOptionPane.YES_NO_OPTION);
				if (choice == JOptionPane.YES_OPTION) {
					studentdao = new StudentDao(studentVo);
					studentdao.deletestudentinfo();
					javax.swing.JOptionPane.showMessageDialog(null, "删除成功!");
					Object[][] s2 = studentdao.selectAll();
					studentPanel.creatJTable().setModel(
							new DefaultTableModel(s2, column));
				} else {
					javax.swing.JOptionPane.showMessageDialog(null, "删除取消!");
				}
			} else {
				javax.swing.JOptionPane.showMessageDialog(null, "请先选择");
			}
		} else if (str.equals("修改信息")) {
			if (studentPanel.creatJTable().getSelectedRow() >= 0) {
				try {
				int i = studentPanel.creatJTable().getSelectedRow();
				studentVo = new StudentVo();
				studentVo.setS_id(Integer.parseInt(studentPanel.creatJTable().getValueAt(i, 0).toString()));
				studentVo.setG_id(Integer.parseInt(studentPanel.creatJTable().getValueAt(i, 1).toString()));
				studentVo.setS_name(studentPanel.creatJTable().getValueAt(i, 2).toString());
				studentVo.setS_sex(studentPanel.creatJTable().getValueAt(i, 3).toString());
				studentVo.setS_grade(studentPanel.creatJTable().getValueAt(i, 4).toString());
				studentVo.setS_school(studentPanel.creatJTable().getValueAt(i, 5).toString());
				studentVo.setS_professional(studentPanel.creatJTable().getValueAt(i, 6).toString());
				studentVo.setS_tel(Long.parseLong(studentPanel.creatJTable().getValueAt(i, 7).toString()));
				studentVo.setS_qq(Long.parseLong(studentPanel.creatJTable().getValueAt(i, 8).toString()));
				studentVo.setS_emali(studentPanel.creatJTable().getValueAt(i, 9).toString());
				StudentUpdateDialog dialog = new StudentUpdateDialog(studentVo);
				JDialog dialog1 = dialog.updatestudent();
				dialog1.setModal(true);
				} catch (NumberFormatException ex) {
					javax.swing.JOptionPane.showMessageDialog(null,
							"请输入正确的字符格式!");
				}
			} else {
				javax.swing.JOptionPane.showMessageDialog(null, "请先选择");
			}
		}
		// else if (str.equals("修改选中学生成绩")) {
		// if (studentPanel.creatJTable().getSelectedRow() >= 0) {
		// studentVo = new StudentVo();
		// int i = studentPanel.getChevementJtable().getSelectedRow();
		//
		// int stuid = Integer.parseInt(studentPanel.getChevementJtable()
		// .getValueAt(i, 0).toString());
		//
		// String stuname = studentPanel.getChevementJtable().getValueAt(
		// i, 2).toString();
		//
		// int ordinary = Integer.parseInt(studentPanel
		// .getChevementJtable().getValueAt(i, 3).toString());
		//
		// studentVo.setS_id(stuid);
		// studentVo.setS_name(stuname);
		// studentVo.setClassExamChivement(ordinary);
		// StudentUpdateStuDialog dialog = new StudentUpdateStuDialog(
		// studentVo);
		// dialog.creatUpdateStuDialog().setVisible(true);
		// } else {
		// javax.swing.JOptionPane.showMessageDialog(null, "请先选择");
		// }
		//
		// }
		// else if (str.equals("修改平时成绩")) {
		// studentVo = new StudentVo();
		// studentdao = new StudentDao(studentVo);
		// studentdao.SelectClassStuName();
		// int[] sNum = studentVo.getSid();
		// String[] sName = studentVo.getSname();
		// int[] classExam = studentVo.getClassExam();
		// StudentUpdateClassChivementDialog dialog1 = new
		// StudentUpdateClassChivementDialog(
		// sNum, sName, classExam);
		// dialog1.creatUpdateClass1Dialog().setVisible(true);
		//
		// }
		else if (str.equals("打印")) {
			if (studentPanel.getChevementJtable() != null) {
				try {
					studentPanel.creatJTable().print(null, null, null, true,
							null, false);
				} catch (HeadlessException e1) {
					e1.printStackTrace();
				} catch (PrinterException e1) {
					e1.printStackTrace();
				}
			} else {
				javax.swing.JOptionPane.showMessageDialog(null, "请先得到表格");
			}
		}
		else if(str.equals("导出")){
			StudentExcelFrame sef = new StudentExcelFrame();
//			String filename = "f:\\student.xls";
//			int row_count = StudentPanel.stuinfoJtable.getRowCount();
//			Vector vector = new Vector();
//			for(int i=0;i<row_count;i++){
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 0));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 1));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 2));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 3));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 4));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 5));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 6));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 7));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 8));
//				vector.add(StudentPanel.stuinfoJtable.getValueAt(i, 9));
//			}
//			
//			WritableWorkbook workbook = StudentPutOutExcel.buildWorkBook(filename);
//			WritableSheet sheet = StudentPutOutExcel.setExcel(workbook, row_count,vector);
//			JOptionPane.showMessageDialog(null, "表已导出,存放在"+filename);
		}
	}

}

⌨️ 快捷键说明

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