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

📄 select_attendance.java

📁 用来管理在校学生的出勤.作息等的管理系统
💻 JAVA
字号:
/*
 * @author 黎龙飞 , 创建日期 2008-5-20
 *
 * Blog : http://lilongfei1030.blog.163.com
 */
package stu.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
import javax.swing.table.TableModel;

import stu.util.ConnectDatabase;
import stu.util.getResults;

public class Select_Attendance extends JFrame {

	private JTextField textField;

	private JComboBox comboBox_2;

	private JTable table;

	private JComboBox comboBox_1;

	private static String sql = "";

	private JComboBox comboBox;

	JLabel ghfLabel;

	JScrollPane scrollPane;

	private static final long serialVersionUID = -941183581920734500L;

	public Select_Attendance() {
		super();
		setTitle("查看到课情况");
		setFont(new Font("", Font.PLAIN, 14));
		getContentPane().setLayout(null);
		setBounds(100, 100, 778, 503);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setResizable(false);
		
		final Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		final Dimension my = this.getSize();
		setLocationByPlatform(true);
		setLocation((screen.width - my.width) / 2,
				(screen.height - my.height) / 2);
		setVisible(true);

		ghfLabel = new JLabel();
		ghfLabel.setFont(new Font("", Font.PLAIN, 14));
		ghfLabel.setBounds(335, 443, 128, 30);
		getContentPane().add(ghfLabel);

		final JLabel label = new JLabel();
		label.setFont(new Font("", Font.PLAIN, 14));
		label.setBounds(53, 12, 63, 30);
		getContentPane().add(label);
		label.setText("选择班级:");

		final JLabel label_1 = new JLabel();
		label_1.setFont(new Font("", Font.PLAIN, 14));
		label_1.setBounds(218, 12, 63, 30);
		getContentPane().add(label_1);
		label_1.setText("选择课程:");

		String sql = "select * from 班级表";
		String[] columnName = null;
		Connection con = new ConnectDatabase().getResultString();
		try {
			Statement stm = con.createStatement();
			ResultSet rs = stm.executeQuery(sql);
			
			int num = 0;
			while (rs.next())
				num++;
			columnName = new String[num];
			int k = 0;
			rs = stm.executeQuery(sql);
			while (rs.next()) {
				columnName[k++] = (String) rs.getObject(2);
			}
			/*for (int i = 0; i < k; i++)
				System.out.println(columnName[i] + " ");
*/
		} catch (SQLException e1) {
			//e1.printStackTrace();
		}

		comboBox = new JComboBox(columnName);
		comboBox.setFont(new Font("宋体", Font.PLAIN, 14));
		comboBox.setBounds(122, 12, 90, 30);
		getContentPane().add(comboBox);

		sql = "select * from 课程表";
		String[] columnName1 = null;
		con = new ConnectDatabase().getResultString();
		try {
			Statement stm = con.createStatement();
			ResultSet rs = stm.executeQuery(sql);

			int num = 0;
			while (rs.next())
				num++;
			columnName1 = new String[num];
			int k = 0;
			rs = stm.executeQuery(sql);
			while (rs.next()) {
				columnName1[k++] = (String) rs.getObject(2);
			}
			/*for (int i = 0; i < k; i++)
				System.out.println(columnName1[i] + " ");
*/
		} catch (SQLException e1) {
			//e1.printStackTrace();
		}
		comboBox_1 = new JComboBox(columnName1);
		comboBox_1.setFont(new Font("宋体", Font.PLAIN, 14));
		comboBox_1.setBounds(287, 12, 113, 30);
		getContentPane().add(comboBox_1);

		scrollPane = new JScrollPane();
		final JButton button = new JButton();
		button.setFont(new Font("", Font.PLAIN, 14));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				
				Select();
			}
		});
		button.setBounds(612, 12, 74, 30);
		getContentPane().add(button);
		button.setText("查询 ");

		final JButton button_1 = new JButton();
		button_1.setFont(new Font("", Font.PLAIN, 14));
		button_1.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				dispose();
			}
		});
		button_1.setBounds(692, 13, 70, 30);
		getContentPane().add(button_1);
		button_1.setText(" 退出");

		final TitledBorder titledBorder = new TitledBorder(null, "查询结果",
				TitledBorder.DEFAULT_JUSTIFICATION,
				TitledBorder.DEFAULT_POSITION, null, null);
		titledBorder.setTitleFont(new Font("", Font.PLAIN, 15));
		scrollPane.setBorder(titledBorder);
		scrollPane.setBounds(0, 48, 770, 347);
		getContentPane().add(scrollPane);

		table = new JTable();
		scrollPane.setViewportView(table);

		final JLabel label_2 = new JLabel();
		label_2.setFont(new Font("", Font.PLAIN, 14));
		label_2.setText("日期:");
		label_2.setBounds(406, 18, 32, 18);
		getContentPane().add(label_2);

		sql = "select   DISTINCT  点名日期 from 考勤表";
		String[] columnName2 = null;
		con = new ConnectDatabase().getResultString();
		try {
			Statement stm = con.createStatement();
			ResultSet rs = stm.executeQuery(sql);
			int num = 0;
			while (rs.next())
				num++;
			columnName2 = new String[num];
			int k = 0;
			rs = stm.executeQuery(sql);
			while (rs.next()) {
				columnName2[k++] = (String) rs.getObject(1).toString();
			}
			/*for (int i = 0; i < k; i++)
				System.out.println(columnName2[i] + " ");
*/
		} catch (SQLException e1) {
			//e1.printStackTrace();
		}

		comboBox_2 = new JComboBox(columnName2);
		comboBox_2.setFont(new Font("宋体", Font.PLAIN, 14));
		comboBox_2.addItem("所有");
		comboBox_2.setBounds(444, 15, 143, 27);
		getContentPane().add(comboBox_2);

		final JLabel label_4 = new JLabel();
		label_4.setFont(new Font("", Font.PLAIN, 14));
		label_4.setText("按学号查询:");
		label_4.setBounds(42, 416, 74, 18);
		getContentPane().add(label_4);

		textField = new JTextField();
		textField.setBounds(122, 415, 139, 22);
		getContentPane().add(textField);

		final JButton button_2 = new JButton();
		button_2.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {
				// textField.getText().trim();
				String sql = "select * from 考勤表 where 学号='"
						+ textField.getText().trim() + "' and 课程名='"
						+ comboBox_1.getSelectedItem() + "'";
				//System.out.println(sql);
				TableModel tableModel;
				try {
					tableModel = new getResults().Results(sql);
					table = new JTable(tableModel);
					scrollPane.setViewportView(table);
					table.setSelectionForeground(Color.RED);
				} catch (Exception e3) {
					//e3.printStackTrace();
				}
				/*System.out.println("行数: " + table.getRowCount() + " 列数: "
						+ table.getColumnCount());
				System.out.println("表中共有: " + table.getRowCount() + " 条记录");*/
				ghfLabel.setText("  共有[" + table.getRowCount() + "]条数据");
			}
		});
		button_2.setText("确定");
		button_2.setBounds(280, 412, 63, 28);
		getContentPane().add(button_2);

		final JButton button_3 = new JButton();

		button_3.addActionListener(new ActionListener() {

			public void actionPerformed(final ActionEvent e) {

				int result = JOptionPane.showOptionDialog(null, "是否存盘学生的考勤信息?",
						"系统提示", JOptionPane.YES_NO_OPTION,
						JOptionPane.QUESTION_MESSAGE, null, new String[] { "是",
								"否" }, "否");
				if (result == JOptionPane.OK_OPTION) {
					//System.out.println("Yes");
				} else {
				}
				
			
				int currow = table.getSelectedRow();
				//System.out.println(currow);
				if (currow > 0) {
					//System.out.println(table.getValueAt(currow, 3).toString());
					Select_Attendance.sql = "update 考勤表 set 到课情况='"
							+ table.getValueAt(currow, 3) + "' where 学号='"
							+ table.getValueAt(currow, 0) + "'";
					//System.out.println(Select_Attendance.sql);
				}
						
			
				Connection con = new ConnectDatabase().getResultString();
				try {
					Statement stm = con.createStatement();
					stm.executeUpdate(Select_Attendance.sql);
					JOptionPane.showMessageDialog(null, "数据存盘成功!!!", "系统提示",
							JOptionPane.INFORMATION_MESSAGE);
				} catch (Exception e3) {
					//e3.printStackTrace();
				}
				
				Select();
			}
		});
		button_3.setText("存盘");
		button_3.setBounds(369, 412, 63, 28);
		getContentPane().add(button_3);
	}
	
	public void Select(){
		
		String sql;
		
		if (comboBox_2.getSelectedItem().equals("所有"))
			sql = "select * from 考勤表 where 班级名='"
					+ comboBox.getSelectedItem() + "' and 课程名='"
					+ comboBox_1.getSelectedItem() + "'";
		else
			sql = "select * from 考勤表 where 班级名='"
					+ comboBox.getSelectedItem() + "' and 课程名='"
					+ comboBox_1.getSelectedItem() + "' and 点名日期='"
					+ comboBox_2.getSelectedItem() + "'";
		//System.out.println(sql);
		TableModel tableModel;
		try {
			tableModel = new getResults().Results(sql);
			table = new JTable(tableModel);
			scrollPane.setViewportView(table);
			table.setSelectionForeground(Color.RED);
		} catch (Exception e3) {
			//e3.printStackTrace();
		}
		/*System.out.println("行数: " + table.getRowCount() + " 列数: "
				+ table.getColumnCount());
		System.out.println("表中共有: " + table.getRowCount() + " 条记录");*/
		ghfLabel.setText("  共有[" + table.getRowCount() + "]条数据");
		if(table.getRowCount()==0)
			JOptionPane.showMessageDialog(null, "没有点名记录","系统提示",JOptionPane.INFORMATION_MESSAGE);
		
	}
}

⌨️ 快捷键说明

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