📄 editempinfo1.java
字号:
package employee;import java.awt.*;import java.sql.*;import java.awt.event.*;import javax.swing.*;import java.io.File;import java.io.FileInputStream;import java.io.InputStream;import java.util.*;import javax.swing.table.*;import javax.swing.border.*;import javax.swing.filechooser.*;/** * 职工信息管理模块 * 修改职工信息信息的类 */public class EditEmpInfo1 extends EmpInfo1 { ImageIcon icon; Statement stmt; ResultSet rs; String eEid_str = ""; String fname=null; String a=""; public EditEmpInfo1() { JFrame.setDefaultLookAndFeelDecorated(true); Font font=new Font("JFrame",Font.PLAIN,14); Enumeration keys=UIManager.getLookAndFeelDefaults().keys(); while(keys.hasMoreElements()){ Object key=keys.nextElement(); if(UIManager.get(key)instanceof Font)UIManager.put(key,font); } if(!ConnectServer.conn("jdbc:odbc:employee_manage","sa","")){ JOptionPane.showMessageDialog(null,"数据库连接不成功!"); System.exit(0); } this.setTitle("修改职工基本信息"); this.setResizable(false); eEid1.setEditable(false); eEid1.setText("请查询职工编号"); ePassword.setEditable(false); eName.setEditable(false); eSex.setEditable(false); eNation.setEditable(false); eRegion.setEditable(false); eEducation.setEditable(false); eSpecialty.setEditable(false); eBirthday.setEditable(false); eGstatus.setEditable(false); eMarriage.setEditable(false); eIdcard.setEditable(false); eHlocation.setEditable(false); eCityhk.setEditable(false); eCaddress.setEditable(false); ePostcode.setEditable(false); eMobilephone.setEditable(false); eHomephone.setEditable(false); eEmail.setEditable(false); eCategory.setEditable(false); eJobdate.setEditable(false); eContractdate.setEditable(false); eZzdate.setEditable(false); eXqdate.setEditable(false); eFilelocation.setEditable(false); //设置运行时窗口的位置 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((screenSize.width - 500) / 2, (screenSize.height - 680) / 2); } public void downInit(){ /*searchInfo.setText("职工编号查询"); searchInfo.setFont(new Font("Dialog",0,12)); downPanel.add(searchInfo); modifyInfo.setText("修改"); modifyInfo.setFont(new Font("Dialog",0,12)); downPanel.add(modifyInfo); clearInfo1.setText("清空"); clearInfo1.setFont(new Font("Dialog",0,12)); downPanel.add(clearInfo1);*/ eixtInfo.setText("退出"); eixtInfo.setFont(new Font("Dialog",0,12)); downPanel.add(eixtInfo); /*searchInfo.setEnabled(true); modifyInfo.setEnabled(false); clearInfo1.setEnabled(true);*/ eixtInfo.setEnabled(true); //添加事件侦听 /*searchInfo.addActionListener(this); modifyInfo.addActionListener(this); clearInfo1.addActionListener(this);*/ eixtInfo.addActionListener(this); this.contentPane.add(downPanel,BorderLayout.SOUTH); } /** * 事件处理 */ public void actionPerformed(ActionEvent e) { Object obj = e.getSource(); String[] s = new String[24]; byte[]b=new byte[1]; if (obj == eixtInfo) { //退出 this.dispose(); } else if (obj == modifyInfo1) { //修改 EmpBean modifyEmp = new EmpBean(); modifyEmp.empModify(eEid1.getText(),ePassword.getText(),eName.getText(),eSex.getText(), eNation.getText(), eRegion.getText(),eEducation.getText(), eSpecialty.getText(), eBirthday.getText(),eGstatus.getText(), eMarriage.getText(), eIdcard.getText(), eHlocation.getText(),eCityhk.getText(), eCaddress.getText(), ePostcode.getText(), eMobilephone.getText(), eHomephone.getText(), eEmail.getText(),eCategory.getText(),eJobdate.getText(),eContractdate.getText(),eZzdate.getText(),eXqdate.getText(),eFilelocation.getText()); modifyEmp.empSearch(eEid1.getText()); s = modifyEmp.empSearch(eEid_str); ePassword.setText(s[0]); eName.setText(s[1]); eSex.setText(s[2]); eNation.setText(s[3]); eRegion.setText(s[4]); eEducation.setText(s[5]); eSpecialty.setText(s[6]); eBirthday.setText(s[7]); eGstatus.setText(s[8]); eMarriage.setText(s[9]); eIdcard.setText(s[10]); eHlocation.setText(s[11]); eCityhk.setText(s[12]); eCaddress.setText(s[13]); ePostcode.setText(s[14]); eMobilephone.setText(s[15]); eHomephone.setText(s[16]); eEmail.setText(s[17]); eCategory.setText(s[18]); eJobdate.setText(s[19]); eContractdate.setText(s[20]); eZzdate.setText(s[21]); eXqdate.setText(s[22]); eFilelocation.setText(s[23]); if(!fname.equals("")){ try{ a=eEid1.getText(); String sql="update picture set photo=? where eid=?"; PreparedStatement pstmt=ConnectServer.con.prepareStatement(sql); File file=new File(fname); FileInputStream fis=new FileInputStream(file);//建立文件输入流 pstmt.setBinaryStream(1,fis,(int)file.length());//设置数据流 pstmt.setString(2,a); pstmt.executeUpdate(); pstmt.close(); }catch(Exception ee){ee.printStackTrace();} } } else if (obj == clearInfo1) { //清空 setNull1(); eEid1.setText(eEid_str); } else if (obj == selectPic){//选择照片 fc=new JFileChooser(".");//建立文件选择器 fc.addChoosableFileFilter(new MyFileFilter("gif"));//设置选择器 fc.addChoosableFileFilter(new MyFileFilter("jpg"));//设置选择器 int result=fc.showOpenDialog(this);//打开文件选择器,选择图片文件 if(result==JFileChooser.APPROVE_OPTION){//若打开 File file=fc.getSelectedFile(); fname=file.getAbsoluteFile().toString(); pic.setIcon(new ImageIcon(fname)); } else if (result==fc.CANCEL_OPTION){//若选择撤销 ;//没有选择任何文件,什么也不做 } } else if (obj == searchInfo1) { //职工编号查询 EmpInfoInputEeid eise = new EmpInfoInputEeid(this); eise.pack(); eise.setVisible(true); try{ eEid_str = eise.getEeid(); }catch(Exception ex){ JOptionPane.showMessageDialog(null, "没有查找到该职工编号!"); } EmpBean searchEmp = new EmpBean(); s = searchEmp.empSearch(eEid_str); b = searchEmp.empPic(eEid_str); if(s == null){ JOptionPane.showMessageDialog(null, "记录不存在!"); eEid1.setText("请查询职工编号"); ePassword.setText(""); eName.setText(""); eSex.setText(""); eNation.setText(""); eRegion.setText(""); eEducation.setText(""); eSpecialty.setText(""); eBirthday.setText(""); eGstatus.setText(""); eMarriage.setText(""); eIdcard.setText(""); eHlocation.setText(""); eCityhk.setText(""); eCaddress.setText(""); ePostcode.setText(""); eMobilephone.setText(""); eHomephone.setText(""); eEmail.setText(""); eCategory.setText(""); eJobdate.setText(""); eContractdate.setText(""); eZzdate.setText(""); eXqdate.setText(""); eFilelocation.setText(""); ePassword.setEditable(false); eName.setEditable(false); eSex.setEditable(false); eNation.setEditable(false); eRegion.setEditable(false); eEducation.setEditable(false); eSpecialty.setEditable(false); eBirthday.setEditable(false); eGstatus.setEditable(false); eMarriage.setEditable(false); eIdcard.setEditable(false); eHlocation.setEditable(false); eCityhk.setEditable(false); eCaddress.setEditable(false); ePostcode.setEditable(false); eMobilephone.setEditable(false); eHomephone.setEditable(false); eEmail.setEditable(false); eCategory.setEditable(false); eJobdate.setEditable(false); eContractdate.setEditable(false); eZzdate.setEditable(false); eXqdate.setEditable(false); eFilelocation.setEditable(false); return; } else{ eEid1.setText(eEid_str); ePassword.setText(s[0]); eName.setText(s[1]); eSex.setText(s[2]); eNation.setText(s[3]); eRegion.setText(s[4]); eEducation.setText(s[5]); eSpecialty.setText(s[6]); eBirthday.setText(s[7]); eGstatus.setText(s[8]); eMarriage.setText(s[9]); eIdcard.setText(s[10]); eHlocation.setText(s[11]); eCityhk.setText(s[12]); eCaddress.setText(s[13]); ePostcode.setText(s[14]); eMobilephone.setText(s[15]); eHomephone.setText(s[16]); eEmail.setText(s[17]); eCategory.setText(s[18]); eJobdate.setText(s[19]); eContractdate.setText(s[20]); eZzdate.setText(s[21]); eXqdate.setText(s[22]); eFilelocation.setText(s[23]); icon=new ImageIcon(b); pic.setIcon(icon); ePassword.setEditable(true); eName.setEditable(true); eSex.setEditable(true); eNation.setEditable(true); eRegion.setEditable(true); eEducation.setEditable(true); eSpecialty.setEditable(true); eBirthday.setEditable(true); eGstatus.setEditable(true); eMarriage.setEditable(true); eIdcard.setEditable(true); eHlocation.setEditable(true); eCityhk.setEditable(true); eCaddress.setEditable(true); ePostcode.setEditable(true); eMobilephone.setEditable(true); eHomephone.setEditable(true); eEmail.setEditable(true); eCategory.setEditable(true); eJobdate.setEditable(true); eContractdate.setEditable(true); eZzdate.setEditable(true); eXqdate.setEditable(true); eFilelocation.setEditable(true); modifyInfo1.setEnabled(true); selectPic.setEnabled(true); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -