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

📄 workbench.java

📁 大型数据库课程设计源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package com.vbank.admin;

import com.vbank.db.*;
import com.vbank.admin.component.CheckBoxCellEditor;
import com.vbank.admin.component.CheckBoxCellRenderer;
import com.vbank.admin.component.EmpDialog;
import com.vbank.admin.component.EmpPanel;
import com.vbank.admin.component.MyTable;
import com.vbank.admin.component.MyTableModel;
import com.vbank.admin.component.UserMouseAdapter;

import com.vbank.beans.*;

import javax.swing.SwingUtilities;
import java.awt.BorderLayout;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JPasswordField;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Dimension;
import javax.swing.JMenu;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.ListIterator;
import java.util.Vector;

/**
 * @author Administrator
 * 
 */
public class WorkBench extends JFrame {

	private static final long serialVersionUID = 1L;

	int f = 0;

	public static int newrow = 0;

	public static Vector rowid = new Vector();

	public static Vector updaterow = new Vector();

	public static Vector delrowid = new Vector();

	long clicktime = 0;

	String account;

	String pwd;

	ResultSet rs;

	Employee emp;

	ArrayList<Employee> empArray;

	private JPanel jContentPane = null;

	private JMenuBar MenuBar = null;

	private MyTable tab;

	MyTableModel mod;

	JMenu menu = null;

	JMenu save = null;

	JMenuItem view = null;

	JMenuItem create = null;

	JMenuItem privmenu = null;
	
	JMenuItem pwdmenu = null;
	
	JMenuItem chmenu = null;


	JMenuItem exit = null;

	JPopupMenu jpm = null;

	EmpDialog empdialog = null;

	EmpPanel emppane;
	
	JPanel pwdpanel=null;
	JLabel numl=null;
	JTextField numf=null;
	JLabel pwdl=null;
	JPasswordField pwdf=null;
	JButton pwdbtn=null;
	JButton defbtn=null;
	
	CardLayout card = null;

	JScrollPane s, js2;

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自动生成方法存根
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				WorkBench thisClass = new WorkBench();
				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				thisClass.setVisible(true);
			}
		});
	}

	/**
	 * This is the default constructor
	 */
	public WorkBench() {
		super();

		initialize();
	}

	public WorkBench(String na, String pw) {
		super();
		account = na;
		pwd = pw;

		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {

		this.setBounds(50, 20, 750, 450);
		JPopupMenu.setDefaultLightWeightPopupEnabled(false);

		this.setBackground(Color.blue);
		MenuBar = new JMenuBar();
		menu = new JMenu("管理");
		view = new JMenuItem("查看员工信息");
		create = new JMenuItem("录入员工信息");
		privmenu = new JMenuItem("权限管理");
		pwdmenu=new JMenuItem("密码管理");
		chmenu=new JMenuItem("切换到服务模块");
		exit = new JMenuItem("退出");
		save = new JMenu("保存设置");
		menu.add(view);
		menu.add(create);
		menu.add(privmenu);
		menu.add(pwdmenu);
		menu.add(chmenu);
		menu.add(exit);
		MenuBar.add(menu);
		MenuBar.add(save);
		this.setJMenuBar(MenuBar);
		this.add(getJContentPane(), BorderLayout.CENTER);
		this.setTitle("Admin Console Management");
		view.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if (e.getSource().equals(view))
					card.show(jContentPane, "table");
				f = 0;
			}
		});
		create.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				create();
			}
		});
		privmenu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				privMng();
				f = 1;
			}
		});
		pwdmenu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				pwdMng();
			}
		});
		chmenu.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				chgwksp();
			}
		});
		exit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exitBench();
			}
		});
		save.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				saveUpdate(rowid);

			}

		});

	}

	/**
	 * 
	 */
	private void saveUpdate(Vector rowid) {
		int r, i;
		ListIterator it = rowid.listIterator();
		DBManager.getConnection();
		Employee cu;
		Priv p;
		Vector<Employee> v = new Vector<Employee>();
		Vector<Priv> c = new Vector<Priv>();
		if (f == 0) {
			while (it.hasNext()) {
				r = (Integer) it.next();
				cu = new Employee();
				for (i = 0; i < 9; i++) {
					Object ob = tab.getValueAt(r, i);
					if (ob == null) {
						JOptionPane.showMessageDialog(this, "资料没有填写完整",
								"alert", JOptionPane.ERROR_MESSAGE);
						return;
					}
				}
				cu.setId(tab.getValueAt(r, 0).toString());
				cu.setName(tab.getValueAt(r, 1).toString());
				cu.setSex(tab.getValueAt(r, 2).toString());
				cu.setAge(new Integer(tab.getValueAt(r, 3).toString())
						.intValue());
				cu.setIDCard(tab.getValueAt(r, 4).toString());
				cu.setEmployeedDate(tab.getValueAt(r, 5).toString());
				cu.setAddress(tab.getValueAt(r, 6).toString());
				cu.setPhone(tab.getValueAt(r, 7).toString());
				cu.setSalary(new Float(tab.getValueAt(r, 8).toString()));

				v.add(cu);
			}
			DBManager.saveNewEmp(v);
		} else {
			while (it.hasNext()) {
				r = (Integer) it.next();
				p = new Priv();
				for (i = 0; i < 13; i++) {
					Object ob = jTable.getValueAt(r, i);
					if (ob == null) {
						JOptionPane.showMessageDialog(this, "资料没有填写完整",
								"alert", JOptionPane.ERROR_MESSAGE);
						return;
					}
				}
				System.out.println(jTable.getValueAt(r, 0).toString());
				p.setOperateNum(jTable.getValueAt(r, 0).toString());
				p.setOpenAccount(jTable.getValueAt(r, 1).toString());
				p.setLostAccount(jTable.getValueAt(r, 2).toString());
				p.setStoreMoney(jTable.getValueAt(r, 3).toString());
				p.setCash(jTable.getValueAt(r, 4).toString());
				p.setOpenAccountCard(jTable.getValueAt(r, 5).toString());
				p.setOpenNetBank(jTable.getValueAt(r, 6).toString());
				p.setDisableAccount(jTable.getValueAt(r, 7).toString());
				p.setSearchEmpInfo(jTable.getValueAt(r, 8).toString());
				p.setAddEmp(jTable.getValueAt(r, 9).toString());
				p.setModifyEmpInfo(jTable.getValueAt(r, 10).toString());
				p.setEmmPwdManage(jTable.getValueAt(r, 11).toString());
				p.setIceCreditCard(jTable.getValueAt(r, 12).toString());
				c.add(p);
			}
			DBManager.updatePriv(c);
		}
		rowid.removeAllElements();
	}

	public void paint(Graphics g) {
		if (f == 0)
			card.show(jContentPane, "table");
		else if (f == 1)
			card.show(jContentPane, "priv");
		super.paint(g);
		// view();
	}

	private void create() {
		empdialog = new EmpDialog(this);

		empdialog.setVisible(true);
	}

	private void privMng() {
		card.show(jContentPane, "priv");
	}
	private void pwdMng() {
		card.show(jContentPane, "pwdmng");
	}
	private void chgwksp() {
		this.setVisible(false);
		new com.vbank.operate.ServiceFrame(account,"y").setVisible(true);
	}
	private void exitBench() {
		this.dispose();
		System.exit(0);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			card = new CardLayout();
			jContentPane.setLayout(card);
			jContentPane.setBounds(new Rectangle(3, 68, this.getWidth(), this
					.getHeight()));
			s = new JScrollPane(getMyTable());
			jContentPane.add("table", s);
			
			js2 = new JScrollPane(getJTable());
			jContentPane.add("priv", js2);
			
			jContentPane.add("pwdmng", getPwdpanel());
		}
		return jContentPane;
	}
private JPanel getPwdpanel() {
	if(pwdpanel==null) {
		pwdpanel=new JPanel();
		pwdpanel.setLayout(null);
		pwdpanel.setBounds(new Rectangle(this.getLocation().x,this.getLocation().y,this.getWidth(),this.getHeight()));
		numl=new JLabel("操作员编号:");
		numl.setBounds(80, 60, 100, 30);
		pwdpanel.add(numl);
		numf=new JTextField();
		numf.setBounds(200, 60, 150, 30);
		pwdpanel.add(numf);
		pwdl=new JLabel("设置新密码:");
		pwdl.setBounds(80, 100, 100, 30);
		pwdpanel.add(pwdl);
		pwdf=new JPasswordField();
		pwdf.setBounds(200, 100, 150, 30);
		pwdpanel.add(pwdf);
		pwdbtn=new JButton("应用");
		pwdbtn.setBounds(260,350, 100, 30);
		pwdbtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				savepwd();
			}
		});
		pwdpanel.add(pwdbtn);
		defbtn=new JButton("恢复默认密码");
		defbtn.setBounds(400, 350, 120, 30);
		pwdpanel.add(defbtn);
		defbtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				setdefaultpwd();
			}
		});
	}
	return pwdpanel;
}
private void savepwd() {
	String opnum=numf.getText().trim();
	String pwd=com.vbank.tool.CharToString.charToString(pwdf.getPassword());
	if(pwd==null) {
		JOptionPane.showMessageDialog(this,
				"请输入新密码", "alert",
				JOptionPane.ERROR_MESSAGE);
		return;
	}
	String sql="update operator set operatePwd='"+pwd+"' where operateNum='"+opnum+"'";
	DBManager.getConnection();
	int i=DBManager.execUpdate(sql);
	DBManager.releaseCon();
	numf.setText("");
	pwdf.setText("");
}
private void setdefaultpwd() {
	String opnum=numf.getText().trim();
	String sql="update operator set operatePwd='666666' where operateNum='"+opnum+"'";
	DBManager.getConnection();
	int i=DBManager.execUpdate(sql);
	DBManager.releaseCon();

⌨️ 快捷键说明

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