package 固定资产管理系统;
import java.awt.*;
import javax.swing.JInternalFrame;
import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.table.JTableHeader;
import com.borland.jbcl.layout.XYLayout;
import com.borland.jbcl.layout.XYConstraints;
import com.borland.jbcl.layout.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseAdapter;
public class Frmemp extends JInternalFrame {
ConnectDataBase cdb=new ConnectDataBase();
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
JPanel jPanel2 = new JPanel();
JLabel lblwmpno = new JLabel();
JTextField txtempno = new JTextField();
JLabel lblempname = new JLabel();
JButton btnadd = new JButton();
JButton btndel = new JButton();
JButton btnrenew = new JButton();
JTextField txtempname = new JTextField();
JLabel lblposition = new JLabel();
JTextField txtposition = new JTextField();
JLabel lblremarks = new JLabel();
JTextField txtremarks = new JTextField();
XYLayout xYLayout1 = new XYLayout();
JPanel jPanel3 = new JPanel();
JScrollPane jScrollPane1 = new JScrollPane();
BorderLayout borderLayout2 = new BorderLayout();
JTable jTable1 = new JTable(cdb.getempinfo());
JTableHeader jTableHeader1 = jTable1.getTableHeader();
TitledBorder titledBorder1 = new TitledBorder("职员信息");
TitledBorder titledBorder2 = new TitledBorder("职员表");
public Frmemp() {
try {
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}
private void jbInit() throws Exception {
getContentPane().setLayout(borderLayout1);
lblwmpno.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
lblwmpno.setText("职员编号");
txtempno.setText("");
lblempname.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
lblempname.setText("职员名称");
jPanel1.setLayout(xYLayout1);
btnadd.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
btnadd.setText("入职");
btnadd.addActionListener(new Frmemp_btnadd_actionAdapter(this));
btndel.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
btndel.setText("离职");
btndel.addActionListener(new Frmemp_btndel_actionAdapter(this));
btnrenew.setFont(new java.awt.Font("宋体", Font.BOLD, 13));
btnrenew.setText("更新");
btnrenew.addActionListener(new Frmemp_btnrenew_actionAdapter(this));
txtempname.setText("");
lblposition.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
lblposition.setText(" 职位");
txtposition.setText("");
lblremarks.setFont(new java.awt.Font("宋体", Font.BOLD, 12));
lblremarks.setText("备注(可空)");
txtremarks.setText("");
jPanel3.setLayout(borderLayout2);
jPanel1.setBorder(titledBorder1);
jPanel3.setBorder(titledBorder2);
this.setTitle("职员管理");
jTable1.setFont(new java.awt.Font("宋体", Font.PLAIN, 12));
jTable1.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS);
jTable1.addMouseListener(new Frmemp_jTable1_mouseAdapter(this));
jTable1.addKeyListener(new Frmemp_jTable1_keyAdapter(this));
this.getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
jPanel2.add(btnadd);
jPanel2.add(btndel);
jPanel2.add(btnrenew);
this.getContentPane().add(jPanel1, java.awt.BorderLayout.WEST);
jPanel1.add(txtremarks, new XYConstraints(75, 180, 90, 20));
jPanel1.add(lblremarks, new XYConstraints(8, 180, 80, 20));
jPanel1.add(txtposition, new XYConstraints(75, 130, 90, 20));
jPanel1.add(lblposition, new XYConstraints(8, 130, 80, 20));
jPanel1.add(txtempname, new XYConstraints(75, 80, 90, 20));
jPanel1.add(lblempname, new XYConstraints(8, 80, 80, 20));
jPanel1.add(txtempno, new XYConstraints(75, 30, 90, 20));
jPanel1.add(lblwmpno, new XYConstraints(8, 30, 80, 20));
this.getContentPane().add(jPanel3, java.awt.BorderLayout.CENTER);
jPanel3.add(jTableHeader1, java.awt.BorderLayout.NORTH);
jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTable1);
jTableHeader1.setReorderingAllowed(false);
}
public void btnadd_actionPerformed(ActionEvent e) {
if(txtempno.getText().equals("") || txtempname.getText().equals("") ||
txtposition.getText().equals("") ){
JOptionPane.showMessageDialog(this,"输入的职员信息不完整","错误",
JOptionPane.ERROR_MESSAGE);
}
else{
int flag=JOptionPane.showConfirmDialog(this,"确定真的要把当前的职员信息添加吗?",
"入职信息",0);
if(flag==0){
cdb.empaddinfo(txtempno.getText(), txtempname.getText(),
txtposition.getText(),txtremarks.getText());
jTable1.setModel(cdb.getempinfo());
}
}
}
public void btndel_actionPerformed(ActionEvent e) {
int r;
r=jTable1.getSelectedRow();
if(r>=0){
int flag=JOptionPane.showConfirmDialog(this,"确定真的要把当前的职员信息删除吗?",
"离职信息",0);
if(flag==0){
String no = jTable1.getValueAt(r, 0).toString();
cdb.empdelinfo(no);
jTable1.setModel(cdb.getempinfo());
}
}
else
JOptionPane.showMessageDialog(this,"没有选中职员表中的任何一项","错误",
JOptionPane.ERROR_MESSAGE);
}
public void btnrenew_actionPerformed(ActionEvent e) {
if(txtempno.getText().equals("") || txtempname.getText().equals("") ||
txtposition.getText().equals("") ){
JOptionPane.showMessageDialog(this,"输入的职员信息不完整","错误",
JOptionPane.ERROR_MESSAGE);
}
else{
int flag=JOptionPane.showConfirmDialog(this,"确定真的要把当前的职员信息更新吗?",
"更新信息",0);
if(flag==0){
cdb.emprenew(txtempno.getText(), txtempname.getText(),
txtposition.getText(),txtremarks.getText());
jTable1.setModel(cdb.getempinfo());
}
}
}
public void jTable1_keyPressed(KeyEvent e) {
if(e.getKeyCode()==e.VK_DOWN){
int r = jTable1.getSelectedRow();
if(r>=jTable1.getRowCount()-1){
r=jTable1.getRowCount()-2;
}
txtempno.setText(jTable1.getValueAt(r+1,0).toString());
txtempname.setText(jTable1.getValueAt(r+1,1).toString());
txtposition.setText(jTable1.getValueAt(r+1,2).toString());
txtremarks.setText(String.valueOf(jTable1.getValueAt(r+1,3)));
}
else if(e.getKeyCode()==e.VK_UP){
int r = jTable1.getSelectedRow();
if(r==0){
r=1;
}
txtempno.setText(jTable1.getValueAt(r-1,0).toString());
txtempname.setText(jTable1.getValueAt(r-1,1).toString());
txtposition.setText(jTable1.getValueAt(r-1,2).toString());
txtremarks.setText(String.valueOf(jTable1.getValueAt(r-1,3)));
}
else if(e.getKeyCode()==e.VK_PAGE_DOWN){
int r = jTable1.getRowCount() - 1;
txtempno.setText(jTable1.getValueAt(r, 0).toString());
txtempname.setText(jTable1.getValueAt(r, 1).toString());
txtposition.setText(jTable1.getValueAt(r, 2).toString());
txtremarks.setText(String.valueOf(jTable1.getValueAt(r,3)));
}
else if(e.getKeyCode()==e.VK_PAGE_UP){
txtempno.setText(jTable1.getValueAt(0, 0).toString());
txtempname.setText(jTable1.getValueAt(0, 1).toString());
txtposition.setText(jTable1.getValueAt(0, 2).toString());
txtremarks.setText(String.valueOf(jTable1.getValueAt(0,3)));
}
else if(e.getKeyCode()==e.VK_BACK_SPACE){
int r=jTable1.getSelectedRow();
int c=jTable1.getSelectedColumn();
jTable1.setValueAt("ou",r,c);
}
}
public void jTable1_mousePressed(MouseEvent e) {
int r = jTable1.getSelectedRow();
txtempno.setText(jTable1.getValueAt(r,0).toString());
txtempname.setText(jTable1.getValueAt(r,1).toString());
txtposition.setText(jTable1.getValueAt(r,2).toString());
txtremarks.setText(String.valueOf(jTable1.getValueAt(r,3)));
}
}
class Frmemp_jTable1_keyAdapter extends KeyAdapter {
private Frmemp adaptee;
Frmemp_jTable1_keyAdapter(Frmemp adaptee) {
this.adaptee = adaptee;
}
public void keyPressed(KeyEvent e) {
adaptee.jTable1_keyPressed(e);
}
}
class Frmemp_jTable1_mouseAdapter extends MouseAdapter {
private Frmemp adaptee;
Frmemp_jTable1_mouseAdapter(Frmemp adaptee) {
this.adaptee = adaptee;
}
public void mousePressed(MouseEvent e) {
adaptee.jTable1_mousePressed(e);
}
}
class Frmemp_btnrenew_actionAdapter implements ActionListener {
private Frmemp adaptee;
Frmemp_btnrenew_actionAdapter(Frmemp adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnrenew_actionPerformed(e);
}
}
class Frmemp_btndel_actionAdapter implements ActionListener {
private Frmemp adaptee;
Frmemp_btndel_actionAdapter(Frmemp adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btndel_actionPerformed(e);
}
}
class Frmemp_btnadd_actionAdapter implements ActionListener {
private Frmemp adaptee;
Frmemp_btnadd_actionAdapter(Frmemp adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.btnadd_actionPerformed(e);
}
}