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

📄 insert_kaoshichengji.java

📁 用来管理在校学生的出勤.作息等的管理系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*
 * @author 黎龙飞 , 创建日期 2008-5-21
 *
 * 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.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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 Insert_KaoshiChengji extends JFrame {

	private JTextField textField_2;

	private JTextField textField_1;

	private JTable table;

	private JTextField textField;

	private JComboBox comboBox_1;

	private JComboBox comboBox;

	JScrollPane scrollPane;

	final JLabel label_5;

	private static final long serialVersionUID = -4372979707716476614L;

	public Insert_KaoshiChengji() {
		super();
		getContentPane().setLayout(null);
		setTitle("录入学生考试成绩");
		setBounds(100, 100, 655, 458);
		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);

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

		String sql = "select  DISTINCT 班级名 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(1);
			}
			/*
			 * 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(153, 20, 106, 27);
		getContentPane().add(comboBox);

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

		sql = "select  DISTINCT 课程名 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(1);
			}
			/*
			 * 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(334, 20, 106, 27);
		getContentPane().add(comboBox_1);

		textField = new JTextField();
		textField.setFont(new Font("", Font.PLAIN, 14));
		textField.setBounds(209, 320, 180, 28);
		getContentPane().add(textField);

		final JButton button = new JButton();
		button.setFont(new Font("", Font.PLAIN, 14));
		button.addActionListener(new ActionListener() {
			public void actionPerformed(final ActionEvent e) {

				textField.setText(SelectFile.Test());
			}
		});
		button.setText("批量导入");
		button.setBounds(113, 321, 90, 28);
		getContentPane().add(button);

		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) {

				String sql2 = " select 学号 from 学生表,授课关系表 where 学生表.学号='"
						+ textField_1.getText().trim() + "' and 学生表.班级名='"
						+ comboBox.getSelectedItem() + "' and 课程名='"
						+ comboBox_1.getSelectedItem()
						+ "' and 学生表.班级名=授课关系表.班级名";

				boolean flag = false;
				try {
					Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
					Connection con = DriverManager
							.getConnection("jdbc:odbc:DB_Student");
					Statement stm = con.createStatement();
					
					if (stm.executeQuery(sql2).next()) {
						flag = true;
					}
					else JOptionPane.showMessageDialog(null, "无法添加该数据,请检查信息是否正确!",
							"系统提示!", JOptionPane.INFORMATION_MESSAGE);
				} catch (Exception e2) {
					 //e2.printStackTrace();
				}
				 //System.out.println(flag);
				if (flag) {
					String sql = "insert  into  成绩表(学号,课程名,考试成绩)  values('"
							+ textField_1.getText().trim() + "','"
							+ comboBox_1.getSelectedItem() + "','"
							+ textField_2.getText().trim() + "')";

					// System.out.println(sql);
			
						int result = JOptionPane.showOptionDialog(null,
								"是否添加该条数据?", "系统提示", JOptionPane.YES_NO_OPTION,
								JOptionPane.QUESTION_MESSAGE, null,
								new String[] { "是", "否" }, "否");
						if (result == JOptionPane.OK_OPTION) {
							
							try{
								Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
								Connection con = DriverManager
										.getConnection("jdbc:odbc:DB_Student");
								Statement stm = con.createStatement();
								
								if (stm.executeUpdate(sql) != 0)
									JOptionPane.showMessageDialog(null, "学生成绩添加成功!",
											"系统提示!", JOptionPane.INFORMATION_MESSAGE);
								Select();
								
								stm.close();
								con.close();
								
								}catch(Exception e1){
									//e1.printStackTrace();
									
									JOptionPane.showMessageDialog(null, "无法添加该数据,请核对添加信息是否正确!\n@该条记录是否已经存在?\n@该班级是否开设本课程?\n",
											"系统提示!", JOptionPane.INFORMATION_MESSAGE);
								}
						} else {
						}
					
				}
			}
		});
		button_1.setText("添加");
		button_1.setBounds(209, 371, 63, 27);
		getContentPane().add(button_1);

		scrollPane = new JScrollPane();
		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(10, 50, 627, 188);
		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(113, 271, 32, 24);
		getContentPane().add(label_2);

		textField_1 = new JTextField();
		textField_1.setBounds(153, 273, 137, 22);
		getContentPane().add(textField_1);

		final JLabel label_3 = new JLabel();
		label_3.setFont(new Font("", Font.PLAIN, 14));
		label_3.setText("成绩:");
		label_3.setBounds(296, 274, 32, 18);
		getContentPane().add(label_3);

⌨️ 快捷键说明

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