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

📄 notnormalworktype.java

📁 JAVA实现的酒店管理系统
💻 JAVA
字号:
package file1;

/*
 * 功能描述:所有对非正常出勤类型的操作的入口
 * Author:黄顺武
 * Time:---
 * Last Modified:2007-12-15
 * Modify Reason:数据库连接类DBConnection 的内部结构设计得到优化
 */
import java.awt.*;
import sun.jdbc.rowset.*;
import javax.swing.*;
import java.sql.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

public class NotNormalWorkType extends JPanel implements ActionListener {

	private JLabel type = new JLabel("非正常出勤类型:");
	private JTextField typeTF = new JTextField(10);
	private JTable recTable = null;
	private JScrollPane recScrollPane = null;
	private JButton add = new JButton("增加记录");
	private JButton delete = new JButton("删除记录");
	private JPanel p1 = new JPanel();
	private JPanel p2 = new JPanel();
	private String[] head = { "ID", "非正常出勤类型" };
	private int headNum = 0;
	private String[][] data = null;
	private String[] typeIDs = null;

	public NotNormalWorkType() {
		headNum = head.length;
		String valueGet = getRecord();
		if (valueGet == null) {
			return;
		}
		p1.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 0));
		p1.add(type);
		p1.add(typeTF);
		add.setBackground(Color.LIGHT_GRAY);
		add.setBorder(null);
		delete.setBackground(Color.LIGHT_GRAY);
		delete.setBorder(null);
		p2.setLayout(new FlowLayout(FlowLayout.CENTER, 20, 0));
		p2.add(add);
		p2.add(delete);
		add.addActionListener(this);
		delete.addActionListener(this);
	}

	private String getRecord() {
		try {
			DBConnection con = new DBConnection();
			String query = "select* from NNormalWork";
			CachedRowSet crs = con.getResultSet(query);
			int count = 0;
			while (crs.next()) {
				count++;
			}
			if (count == 0) {
				delete.setEnabled(false);
			} else {
				delete.setEnabled(true);
			}
			data = new String[count][headNum];
			typeIDs = new String[count];
			crs.beforeFirst();
			int arrayIndex = 0;
			while (crs.next()) {
				String id = String.valueOf(crs.getInt(1));
				typeIDs[arrayIndex] = id;
				data[arrayIndex][0] = id;
				data[arrayIndex][1] = crs.getString(2).trim();
				arrayIndex++;
			}
			recTable = new JTable(data, head);
			recScrollPane = new JScrollPane(recTable);
			this.setLayout(new BorderLayout(0, 15));
			this.add(p1, BorderLayout.NORTH);
			this.add(recScrollPane, BorderLayout.CENTER);
			this.add(p2, BorderLayout.SOUTH);
			this.validate();
		} catch (ClassNotFoundException cnfe) {
			cnfe.printStackTrace();
			return null;
		} catch (SQLException sqle) {
			sqle.printStackTrace();
			return null;
		}
		return "success";
	}

	public void actionPerformed(ActionEvent ae) {
		if (ae.getSource() == add) {
			String type = typeTF.getText().trim();
			if (type.equals("")) {
				JOptionPane.showMessageDialog(null, "类型不能为空!", "",
						JOptionPane.INFORMATION_MESSAGE);
				return;
			}
			String query = "select* from NNormalWork where tName='" + type
					+ "'";
			CachedRowSet crs = null;
			try {
				DBConnection con = new DBConnection();
				crs = con.getResultSet(query);
				if (crs.next()) {
					JOptionPane.showMessageDialog(null, "该类型已存在!", "",
							JOptionPane.INFORMATION_MESSAGE);
					return;
				}

				StringBuffer insertSB = new StringBuffer(
						"insert into NNormalWork values('");
				insertSB.append(type).append("')");
				con.addSql(insertSB.toString());
				con.doDML();
				getRecord();
			} catch (SQLException sqle) {
				sqle.printStackTrace();
			} catch (ClassNotFoundException cnfe) {
				cnfe.printStackTrace();
			}
		}
		if (ae.getSource() == delete) {
			String typeStr = (String) JOptionPane.showInputDialog(null,
					"请选择要删除的非正常出勤类型ID!", "", JOptionPane.INFORMATION_MESSAGE,
					null, typeIDs, typeIDs[0]);
			if (typeStr == null) {
				return;
			}
			int confirm = JOptionPane.showConfirmDialog(null, "您真的确认删除该记录吗?",
					"", JOptionPane.YES_NO_OPTION);
			if (confirm == JOptionPane.YES_OPTION) {
				try {
					DBConnection con = new DBConnection();
					StringBuffer deleteSB = new StringBuffer(
							"delete from NNormalWork where ID=");
					deleteSB.append(typeStr);
					con.addSql(deleteSB.toString());
					con.doDML();
				} catch (ClassNotFoundException cnfe) {
					cnfe.printStackTrace();
				} catch (SQLException sqle) {
					sqle.printStackTrace();
				}
				getRecord();
			}
		}
	}
}

⌨️ 快捷键说明

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