package Frame;
|
import java.awt.BorderLayout;
|
import java.awt.Color;
|
import java.awt.Component;
|
import java.awt.Container;
|
import java.awt.Dimension;
|
import java.awt.FlowLayout;
|
import java.awt.Font;
|
import java.awt.GridLayout;
|
import java.awt.Toolkit;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyListener;
|
import java.sql.ResultSet;
|
import java.util.Iterator;
|
import java.util.List;
|
import java.util.Vector;
|
import javax.swing.Box;
|
import javax.swing.ButtonGroup;
|
import javax.swing.ComboBoxModel;
|
import javax.swing.DefaultComboBoxModel;
|
import javax.swing.ImageIcon;
|
import javax.swing.JComboBox;
|
import javax.swing.JDialog;
|
import javax.swing.JInternalFrame;
|
import javax.swing.JLabel;
|
import javax.swing.JPanel;
|
import javax.swing.JRadioButton;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTable;
|
import javax.swing.JTextField;
|
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.TableCellRenderer;
|
import javax.swing.table.TableColumn;
|
|
import ColorAndFont.English;
|
import ColorAndFont.NothJPanel;
|
import ColorAndFont.UIColor;
|
import ColorAndFont.buttonTitle;
|
import Company.Dell_tbCompany;
|
import DataBase.DatabaseManagement;
|
import Method.GetNowTime;
|
import PbuliClass.BuMens;
|
import PbuliClass.DownloadFile;
|
import PbuliClass.ImExport;
|
import PbuliClass.JButtonModel;
|
import PbuliClass.JlableModel;
|
import PbuliClass.OutButton;
|
import PbuliClass.ShowMessage;
|
import PbuliClass.Systems;
|
import PbuliClass.WarningMessage;
|
import PbuliClass.greateTables;
|
import PbuliClass.jinternalFrame;
|
import person.Person;
|
import person.person_Dell;
|
|
/**´ËÀàÓÃÓÚÈËÔ±¹ÜÀí*/
|
@SuppressWarnings("rawtypes")
|
public class PersonManage extends jinternalFrame {
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
jinternalFrame jinerFrame=null;
|
JInternalFrame jinFrame=null;
|
JPanel innerPanel=null;//ÄÚ²¿´°ÌåÃæ°å
|
NothJPanel northPanel=null;//Äϲ¿Ãæ°å
|
JPanel centerPanel=null;//Öв¿Ãæ°å
|
JButtonModel jbut=null;//°´Å¥Ä£ÐÍ
|
JTextField searchFileld=null;//ËÑË÷Îı¾¿ò
|
JButtonModel search=null;//ËÑË÷°´Å¥
|
JButtonModel shuaxin=null;//ˢа´Å¥
|
JButtonModel add=null;//ÐÂÔö°´Å¥
|
JButtonModel alter=null;//Ð޸İ´Å¥
|
JButtonModel delete=null;//ɾ³ý°´Å¥
|
JButtonModel deleteAll=null;//È«²¿É¾³ý°´Å¥
|
JButtonModel enterPort=null;//µ¼ÈëÈËÔ±°´Å¥
|
OutButton outbt=new OutButton();
|
JButtonModel download=null;//Ä£°åÏÂÔØ°´Å¥
|
JScrollPane gd=null;//¹ö¶¯Ãæ°å
|
JTable table=null;//ÉêÃ÷±í¸ñ
|
Vector rowData=new Vector();;
|
DefaultTableModel tableModel=null;//ÉùÃ÷±í¸ñÄ£ÐÍ
|
List list=null;
|
int selectedRow;//±»Ñ¡ÖеÄÐÐ
|
String departMent;//±êÇ©ËùÊôµÄ²¿ÃÅ
|
Container rq;
|
JComboBox<String> bumenComboBox2=null;//²¿ÃÅÑ¡ÔñÏÂÀÁбí¿ò
|
public PersonManage() {//¹¹Ôì·½·¨
|
String title="ÈËÔ±¹ÜÀí";
|
if(Systems.sys().getLanguage().equals("English")) {
|
title="Personnel management";
|
}
|
this.setTitle(title);
|
rq=getContentPane();//»ñÈ¡ÈÝÆ÷
|
rq.setLayout(new BorderLayout());
|
rq.setBackground(Color.white);
|
rq.add(getGd(),BorderLayout.CENTER);
|
rq.add(getNorthPanel(),BorderLayout.NORTH);
|
this.setFrameIcon(new ImageIcon("image/icon/renyuanicon.png"));//ÉèÖô°Ìåͼ±ê
|
|
}
|
|
|
|
/**»ñÈ¡Äϲ¿Ãæ°åµÄ·½·¨*/
|
public NothJPanel getNorthPanel() {
|
if(northPanel==null) {
|
northPanel=new NothJPanel();
|
Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
|
topicBox.add(getBumenComboBox2());
|
topicBox.add(Box.createHorizontalStrut(10));
|
topicBox.add(getSearchFileld());//Ìí¼ÓËÑË÷Îı¾¿ò
|
topicBox.add(Box.createHorizontalStrut(3));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getSearch());//Ìí¼ÓËÑË÷°´Å¥
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getShuaxin());//Ìí¼Óˢа´Å¥
|
// topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
// topicBox.add(getAdd());//Ìí¼ÓÐÂÔö°´Å¥
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getAlter());//Ìí¼ÓÐ޸İ´Å¥
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getDelete());//Ìí¼Óɾ³ý°´Å¥
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getDeleteAll());//Ìí¼Óɾ³ýÈ«²¿°´Å¥
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getEnterPort());//Ìí¼Óµ¼ÈëÈËÔ±°´Å¥
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getOutport());//Ìí¼Óµ¼³ö±í¸ñ°´Å¥
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getDownload());//Ìí¼ÓÏÂÔØÄ£°å°´Å¥
|
northPanel.add(topicBox );
|
}
|
return northPanel;
|
}
|
/**»ñÈ¡Öв¿Ãæ°åµÄ·½·¨*/
|
public JPanel getCenterPanel() {
|
if(centerPanel==null) {
|
centerPanel=new JPanel();
|
centerPanel.add(getGd());//Ìí¼Ó¹ö¶¯Ãæ°å
|
centerPanel.setBackground(Color.WHITE);
|
|
}
|
return centerPanel;
|
}
|
/**»ñÈ¡ËÑË÷Îı¾¿òµÄ·½·¨*/
|
public JTextField getSearchFileld() {
|
if(searchFileld==null){
|
searchFileld=new JTextField(10);
|
searchFileld.addKeyListener(new KeyListener() { //¼üÅÌʼþ¼àÌý
|
public void keyTyped(KeyEvent e) {
|
|
}
|
public void keyReleased(KeyEvent e) {
|
int keyCode=e.getKeyCode();
|
if(keyCode==KeyEvent.VK_ENTER) {
|
getSearch().doClick();//ËÑË÷°´Å¥±»µã»÷
|
}
|
}
|
public void keyPressed(KeyEvent e) {
|
|
}
|
});
|
|
}
|
return searchFileld;
|
}
|
|
|
|
/**»ñȡѡÔñ²¿ÃÅÏÂÀ¿ò*/
|
public JComboBox<String> getBumenComboBox2() {
|
if(bumenComboBox2==null) {
|
bumenComboBox2=new JComboBox<>();//´´½¨ÏÂÀ¿ò¶ÔÏó
|
bumenComboBox2.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 14));//ÉèÖÃ×ÖÌå
|
ComboBoxModel<String > coModel=new DefaultComboBoxModel<>(BuMens.getBumenNames2());//ÏÂÀÁбíÄ£ÐÍ
|
bumenComboBox2.setModel(coModel);
|
bumenComboBox2.updateUI();//¸üÐÂUI
|
bumenComboBox2.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
String text=(String) bumenComboBox2.getSelectedItem();
|
if(text.equals("Ñ¡Ôñ²¿ÃÅ")) {
|
updateTable();
|
}else {
|
updateSerch(text);
|
}
|
|
}
|
});
|
}
|
|
return bumenComboBox2;
|
}
|
|
/**»ñÈ¡ËÑË÷°´Å¥µÄ·½·¨*/
|
public JButtonModel getSearch() {
|
if(search==null){
|
search=new JButtonModel(buttonTitle.getSerch());
|
search.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(getSearchFileld().getText().length()>=1) {
|
String go=getSearchFileld().getText().trim();
|
updateSerch(go);
|
}else {
|
ShowMessage.zidingyi("ÊäÈëµÄËÑË÷ÄÚÈݲ»ÄÜΪ¿Õ");
|
}
|
}
|
});
|
|
}
|
return search;
|
}
|
|
/**ËÑË÷·½·¨*/
|
public void updateSerch(String serch) {
|
if(person_Dell.serch(serch).size()==0) {
|
ShowMessage.zidingyi("ÄãËÑË÷µÄ"+serch+"²»´æÔÚ£¡");
|
return;
|
}
|
int tagnum=getTable().getRowCount();//±í¸ñ×ÜÐÐÊý
|
if(tagnum !=0 ) {
|
for (int i = 0; i < tagnum; i++) {//ɾ³ýËùÓÐÐÐ
|
tableModel.removeRow(0);
|
}
|
}
|
getRowData(person_Dell.serch(serch));
|
}
|
|
/**»ñȡˢа´Å¥µÄ·½·¨*/
|
public JButtonModel getShuaxin() {
|
if(shuaxin==null){
|
shuaxin=new JButtonModel(buttonTitle.getRefresh());
|
shuaxin.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
updateTable() ;
|
}
|
});
|
|
}
|
return shuaxin;
|
}
|
|
/**»ñÈ¡ÐÂÔö°´Å¥µÄ·½·¨*/
|
public JButtonModel getAdd() {
|
if(add==null){
|
add=new JButtonModel(buttonTitle.getAddOne());
|
add.setEnabled(false);
|
add.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
new AddTagDialog("ÐÂÔöÈËÔ±¶Ô»°¿ò");
|
|
}
|
});
|
|
}
|
return add;
|
}
|
/**»ñÈ¡±í¸ñ±»Ñ¡ÖеÄÐз½·¨*/
|
public int getSelectedRow() {
|
selectedRow=getTable().getSelectedRow();
|
return selectedRow;
|
|
}
|
|
/**»ñÈ¡Ð޸İ´Å¥µÄ·½·¨*/
|
public JButtonModel getAlter() {
|
|
|
/**ÐÞ¸ÄÈËÔ±¶Ô»°¿ò*/
|
class alertDiolog extends AddTagDialog{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
public alertDiolog(String title) {
|
super(title);
|
}
|
|
|
public JTextField getSnameFile() {//ÖØÐ´ÁË»ñÈ¡ÐÕÃûµÄÎı¾¿ò
|
if(snameFile==null) {
|
snameFile=new JTextField(8);
|
Object name=getTable().getValueAt(getSelectedRow(), 1);
|
snameFile.setText((String) name);
|
|
}
|
return snameFile;
|
}
|
//ÖØÐ´µç»°Îı¾¿ò
|
public JTextField getPhoneNumFile() {
|
if(phoneNumFile==null) {
|
phoneNumFile=new JTextField(12);
|
Object phone=getTable().getValueAt(getSelectedRow(), 5);
|
phoneNumFile.setText((String) phone);
|
}
|
return phoneNumFile;
|
}
|
/**»ñÈ¡±¸×¢Îı¾¿ò*/
|
public JTextField getBeizhuFile() {
|
if(beizhuFile==null) {
|
beizhuFile=new JTextField(12);
|
Object beizhu=getTable().getValueAt(getSelectedRow(), 6);
|
beizhuFile.setText((String) beizhu);
|
}
|
return beizhuFile;
|
}
|
|
|
/**»ñȡѡÔñ±êÇ©ÏÂÀ¿ò*/
|
|
public JTextField get_tag_field() {
|
|
if(tag_field==null) {
|
tag_field=new JTextField(8);
|
String tagID=(String) getTable().getValueAt(getSelectedRow(), 2);//±»Ñ¡ÖеÄIDºÅ
|
tag_field.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 12));//ÉèÖÃ×ÖÌå
|
tag_field.setText(tagID);
|
tag_field.setEnabled(false);
|
}
|
|
return tag_field;
|
}
|
|
/**ÐÞ¸Ä±í·½·¨*/
|
public void setUpadateSql(){
|
// Ö´ÐÐSQL²éѯÓï¾ä»ñµÃµÄ½á¹û¼¯Èç¹û±êÇ©ÒѾ´æÔÚÔò²»ÔÙÖ´ÐÐÏÂÃæµÄÓï¾ä
|
String tagid=(String) getTable().getValueAt(getSelectedRow(), 2);
|
String name=getName();
|
String sex=getSelectedSex();
|
String bumen=getDePartMent();
|
String phone=getPhoneNumText();
|
String time=GetNowTime.now();
|
String[] ziduan= {"p_name","p_department","p_sex","p_phone","p_addtiem","p_tagid"};
|
String[] zhi= {name,bumen,sex,phone,time,tagid};
|
if(DatabaseManagement.fast_alert_dbase("tb_person", ziduan, zhi)) {
|
person_Dell.alert_person(tagid, bumen, name, sex, phone);
|
getShuaxin();
|
ShowMessage.zidingyi(tagid+","+name+"Ð޸ijɹ¦£¡");
|
}else {
|
ShowMessage.zidingyi(tagid+"ÐÞ¸Äʧ°Ü£¡");
|
}
|
|
}
|
}
|
|
if(alter==null){
|
alter=new JButtonModel(buttonTitle.getAlert());
|
alter.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(getSelectedRow() !=-1) {//Èç¹ûÑ¡ÖеÄÐв»Îª¿Õ
|
new alertDiolog("ÐÞ¸ÄÈËÔ±¶Ô»°¿ò");
|
}
|
else {
|
ShowMessage.chooseRow(buttonTitle.getAlert());
|
return;
|
}
|
|
}
|
});
|
|
}
|
return alter;
|
}
|
/**»ñȡɾ³ý°´Å¥µÄ·½·¨*/
|
public JButtonModel getDelete() {
|
if(delete==null){
|
delete=new JButtonModel(buttonTitle.getDelete());
|
delete.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
int[] selectedRows=table.getSelectedRows();//±»Ñ¡ÖÐÐеÄË÷Òý¼¯ºÏ
|
if(selectedRows.length !=0) {
|
for(int i=0;i<selectedRows.length;i++){
|
String tagid=(String) table.getValueAt(selectedRows[i], 2);
|
//½«±êÇ©Êý¾Ý±íÖеÄ״̬ÐÞ¸ÄΪ·ñ
|
String deleteSql="DELETE FROM tb_person WHERE p_tagid='"+tagid+"'";
|
if (DatabaseManagement.update(deleteSql)!=0) {
|
String update="UPDATE tb_tag SET state='δ°ó¶¨' where tag_id='"+tagid+"'";
|
DatabaseManagement.update(update);
|
person_Dell.remove_person(tagid);
|
|
}// Ð޸ıêÇ©ÐÅÏ¢
|
}
|
//ɾ³ý³É¹¦ÌáʾÐÅÏ¢
|
ShowMessage.delteSuccess(selectedRows.length);
|
updateTable();//ˢбí¸ñ
|
|
}
|
else {
|
ShowMessage.chooseRow(buttonTitle.getDelete());
|
}
|
|
}
|
});
|
|
}
|
return delete;
|
}
|
/**»ñȡȫ²¿É¾³ý°´Å¥µÄ·½·¨*/
|
public JButtonModel getDeleteAll() {
|
if(deleteAll==null){
|
deleteAll=new JButtonModel(buttonTitle.getDeleteall());
|
deleteAll.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
//Ñ¡Ôñ¶Ô»°¿òÈçyes·µ»Ø0£¬NO·µ»Ø1£¬È¡Ïû·µ»Ø2
|
WarningMessage warning=new WarningMessage();
|
warning.setMessage("Ñ¡Ôñɾ³ýÈ«²¿½«»á°Ñ±í¸ñÊý¾ÝÈ«²¿É¾³ýÈ·¶¨Âð£¿");
|
int warn=warning.getwarMss(getCenterPanel());
|
int tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý
|
if(tagnum!=0 && warn==0) {
|
String deleteSql="TRUNCATE TABLE tb_person";
|
DatabaseManagement.update(deleteSql);// ɾ³ýËùÓмǼ
|
String update="UPDATE tb_tag SET state='δ°ó¶¨' ";
|
ShowMessage.deleteAll(DatabaseManagement.update(update));
|
person_Dell.removall_person();
|
rq.repaint();
|
}
|
}
|
});
|
|
}
|
return deleteAll;
|
}
|
/**»ñÈ¡µ¼ÈëÈËÔ±°´Å¥µÄ·½·¨*/
|
public JButtonModel getEnterPort() {
|
if(enterPort==null){
|
enterPort=new JButtonModel(buttonTitle.getImport());
|
enterPort.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
WarningMessage warning=new WarningMessage();
|
warning.setMessage("µ¼ÈëÊý¾Ý±ØÐëÏÈÏÂÔØÄ£°å£¬Ïȵã»÷ÏÂÔØÄ£°å°´¼üÏÂÔØ±í¸ñÄ£°å\nÄãÊÇ·ñÒѾÏÂÔØÄ£°å²¢ÇÒ°´ÕÕÄ£°å¸ñʽÌîдÊý¾ÝÁË£¿");
|
int warn=warning.getwarMss(getCenterPanel());
|
if( warn==0) {
|
new ImExport().excelPersonToMysql(getNorthPanel());
|
updateTable();//ˢбí¸ñ
|
}
|
}
|
});
|
|
}
|
return enterPort;
|
}
|
/**»ñÈ¡µ¼³ö±í¸ñ°´Å¥µÄ·½·¨*/
|
public JButtonModel getOutport() {
|
OutButton.setAddtime("addtime");
|
OutButton.setDataName("tb_person");
|
return new OutButton().get_ouotport_button();
|
|
}
|
/**»ñÈ¡ÏÂÔØÄ£°å°´Å¥µÄ·½·¨*/
|
public JButtonModel getDownload() {
|
if(download==null){
|
download=new JButtonModel(buttonTitle.getTemplate());
|
download.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {;
|
DownloadFile dw=new DownloadFile();
|
dw.dowPersonFile(getNorthPanel());
|
|
}
|
});
|
|
}
|
return download;
|
}
|
/**»ñÈ¡¹ö¶¯Ãæ°åµÄ·½·¨*/
|
public JScrollPane getGd() {
|
if(gd==null){
|
gd=new JScrollPane(getTable());
|
gd.getViewport().setBackground(UIColor.getNorth_color());
|
|
}
|
return gd;
|
}
|
|
|
/**»ñÈ¡ÈËÔ±±í¸ñµÄ·½·¨*/
|
@SuppressWarnings({ "serial"})
|
public JTable getTable() {
|
if(table==null) {
|
String[] name1= {"ÐòºÅ","ÐÕÃû","±êÇ©ID","ÐÔ±ð","²¿ÃÅ","µç»°","µçÁ¿(%)","ͼ±ê","״̬","ÐÄÂÊ","Ìí¼Óʱ¼ä"};//±í¸ñÁÐÃû
|
String[] name2= {"Serial Number", "Name", "Tag ID", "Sex",
|
"Department", "Phone", "Battery (%)", "Icon","HEART", "AddTime"};//±í¸ñÁÐÃû
|
String[] columnNames=English.columnNames(name1, name2);
|
//Ìí¼Ó±í¸ñÁÐÏòÁ¿
|
Vector<String> columnName=new Vector<>();
|
for(int i=0;i<columnNames.length;i++){
|
columnName.add(columnNames[i]);
|
}
|
|
//Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý
|
greateTables tables=new greateTables();
|
tableModel=new DefaultTableModel(rowData, columnName){
|
// ʵÏÖÈÃÕû¸ö±í¸ñ²»²»ÔÊÐí±»±à¼
|
public boolean isCellEditable(int row,int column){
|
return false;
|
}
|
};
|
|
table=tables.getTable(tableModel);
|
getRowData(person_Dell.getPerson_vector());
|
table.setRowHeight(40);//ÉèÖñí¸ñÐиß
|
|
//´úÂëΪÈñí¸ñÏÔʾͼƬ
|
TableColumn column = table.getColumnModel().getColumn(7);// »ñÈ¡±í¸ñµÚ8ÁжÔÏó
|
column.setCellRenderer(new TableCellRenderer() {// ÉèÖõÚ3ÁеÄäÖȾÆ÷
|
public Component getTableCellRendererComponent(
|
JTable table, Object value, boolean isSelected,
|
boolean hasFocus, int row, int column) {
|
ImageIcon icon = (ImageIcon) value;
|
JLabel label = new JLabel(icon);// ´´½¨Í¼±ê
|
// °ÑÑ¡ÔñµÄ±êÇ©ÉèÖÃΪ͸Ã÷
|
label.setOpaque(true);
|
|
if (row % 2 == 0) {
|
label.setBackground(UIColor.getTable_1());
|
} else {
|
label.setBackground(UIColor.getTable_2());
|
}
|
|
if(isSelected) {
|
label.setBackground(UIColor.getTable_sekected());
|
}
|
return label;// °Ñͼ±ê×÷ΪΪäÖȾ¿Ø¼þ
|
}
|
});
|
|
}
|
return table;
|
|
}
|
|
/**Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý·½·¨*/
|
@SuppressWarnings("unchecked")
|
public void getRowData(Vector<Person> person_vector ) {
|
Iterator iterator =person_vector.iterator();//´´½¨µü´úÆ÷
|
int i=0;
|
while (iterator.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ
|
i++;
|
Person info = (Person) iterator.next();//½«µü´úÆ÷ÀïÃæµÄÔªËØ¸øµ½info¼¯ºÏ
|
Vector row = new Vector();
|
row.add(String.valueOf(i));//ÐòºÅ
|
row.add(info.getP_name());//ÐÕÃû
|
row.add(info.getP_tagid());//±êÇ©id
|
row.add(info.getP_sex());//ÐÔ±ð
|
row.add(info.getP_department());//²¿ÃÅ
|
row.add(info.getP_phone());//µç»°
|
row.add(info.getP_power());//µçÁ¿
|
row.add(info.getP_image());//ͼ±ê
|
String zaixian="ÔÚÏß";
|
if(info.getP_online().equals("0")) {
|
zaixian="ÀëÏß";
|
}
|
row.add(zaixian);//ÊÇ·ñÔÚÏß
|
String baoliu16=info.getBaoliu16();
|
if(baoliu16.equals("-1")) {
|
baoliu16="δ֪";
|
}
|
row.add(baoliu16);//ÐÄÂÊ
|
row.add(String.valueOf(info.getP_addtiem()));//Ìí¼Óʱ¼ä
|
tableModel.addRow(row);// Ïò±í¸ñ¶ÔÏóÌí¼ÓÐÐÊý¾Ý
|
}
|
|
}
|
|
/**ˢбí¸ñ·½·¨*/
|
/**ˢбí¸ñ·½·¨*/
|
public void updateTable() {
|
if(tableModel !=null) {
|
tableModel.getDataVector().clear();
|
getRowData(person_Dell.getPerson_vector());
|
gd.validate();
|
}
|
}
|
|
|
|
/**¸ù¾ÝID»òÕßÐÕÃû»ñÈ¡ËùÔÚ²¿Ãŵķ½·¨*/
|
public String getDepartMent(String tagid) {
|
String serch="select * from tb_person where tag_id='"+tagid+"'or name='"+
|
tagid+"'";
|
list = DatabaseManagement.serch(serch);//½«ÁбíÖÐËùÓнá¹û¼¯¸øµ½list¼¯ºÏ
|
Iterator iterator = list.iterator();//´´½¨µü´úÆ÷
|
while (iterator.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ
|
List info = (List) iterator.next();//½«µü´úÆ÷ÀïÃæµÄÔªËØ¸øµ½list¼¯ºÏ
|
departMent=(String) info.get(3);
|
}
|
return departMent;
|
}
|
|
/**ÐÂÔöÈËÔ±¶Ô»°¿ò*/
|
class AddTagDialog extends JDialog{
|
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
JlableModel tagId=null;//±êÇ©id
|
JlableModel sname=null;//ÐÕÃû
|
JlableModel bumen=null;//²¿ÃÅ
|
JlableModel company=null;//²¿ÃÅ
|
JlableModel sex=null;//ÐÔ±ð
|
JlableModel phoneNum=null;//µç»°
|
JlableModel beizhu=null;//±¸×¢
|
JButtonModel serchTag=null;//²éÕÒ±êÇ©
|
JButtonModel sure=null;//È·¶¨°´Å¥
|
JButtonModel quxiao=null;//È¡Ïû°´Å¥
|
JRadioButton boy=null;//µ¥Ñ¡°´Å¥ÄÐ
|
JRadioButton girl=null;//µ¥Ñ¡°´Å¥Å®
|
ButtonGroup btgroup=null;//ÉêÃ÷°´Å¥×é
|
JTextField tagIdFile=null;//±êÇ©idÎı¾¿ò
|
JTextField snameFile=null;//ÐÕÃûÎı¾¿ò
|
JTextField phoneNumFile=null;//µç»°ºÅÂëÎı¾¿ò
|
JTextField beizhuFile=null;//±¸×¢Îı¾¿ò
|
JTextField tag_field=null;//»ñÈ¡±êÇ©µÄÎı¾¿ò
|
JTextField Company=null;//»ñÈ¡±êÇ©µÄÎı¾¿ò
|
JPanel mb=null;//ÉêÃ÷Ò»¸öÃæ°å
|
JComboBox<String> bumenComboBox=null;
|
JComboBox<String> companyComboBox=null;
|
|
/**¹Ø±Õ¶Ô»°¿ò·½·¨*/
|
public void closeTagDialog() {
|
this.dispose();
|
|
}
|
/**»ñÈ¡¶Ô»°¿ò·½·¨*/
|
public AddTagDialog(String title) {
|
super();
|
this.setAlwaysOnTop(true);//×ÜÊÇÖö¥
|
this.setTitle(title);
|
Toolkit toolkit = getToolkit();// »ñµÃ´°Ì幤¾ß°ü
|
Dimension screenSize = toolkit.getScreenSize();// »ñÈ¡ÆÁÄ»´óС
|
int width = (int) (screenSize.width* 0.5);// ¼ÆËã´°Ìåпí¶È
|
int height = (int) (screenSize.height * 0.5);// ¼ÆËã´°Ìåпí¶È
|
int x0=width-160;//´°Ìåx0×ø±ê
|
int y0=height-160;//´°Ìåy0×ø±ê
|
Container rq=getContentPane();
|
rq.add(getMb());
|
this.setBounds(x0, y0, 320, 360);
|
this.setVisible(true);
|
}
|
|
|
public JPanel getMb() {
|
btgroup=new ButtonGroup();
|
btgroup.add(getBoy());
|
btgroup.add(getGirl());
|
if(mb==null){
|
mb=new JPanel();
|
mb.setLayout(new GridLayout(8, 1,10,10));
|
JPanel mb1=new JPanel();
|
mb1.setLayout(new FlowLayout(FlowLayout.LEFT));
|
JPanel mb2=new JPanel();
|
mb2.setLayout(new FlowLayout(FlowLayout.LEFT));
|
JPanel mb3=new JPanel();
|
mb3.setLayout(new FlowLayout(FlowLayout.LEFT));
|
JPanel mb4=new JPanel();
|
mb4.setLayout(new FlowLayout(FlowLayout.LEFT));
|
JPanel mb5=new JPanel();
|
mb5.setLayout(new FlowLayout(FlowLayout.LEFT));
|
JPanel mb6=new JPanel();
|
mb6.setLayout(new FlowLayout(FlowLayout.LEFT));
|
JPanel mb8=new JPanel();
|
mb8.setLayout(new FlowLayout(FlowLayout.LEFT));
|
JPanel mb7=new JPanel();
|
mb8.add(getCompany());
|
mb8.add(getCompanyComboBox());
|
mb1.add(getTagId());
|
mb1.add(get_tag_field());
|
mb2.add(getSname());
|
mb3.add(getBumen());
|
mb2.add(getSnameFile());
|
mb3.add(getBumenComboBox());
|
mb4.add(getSex());
|
mb4.add(getBoy());
|
mb4.add(getGirl());
|
mb5.add(getPhoneNum());
|
mb5.add(getPhoneNumFile());
|
mb6.add(getBeizhu());
|
mb6.add(getBeizhuFile());
|
mb7.add(getSure());
|
mb7.add(getQuxiao());
|
mb.add(mb1);
|
mb.add(mb2);
|
mb.add(mb3);
|
mb.add(mb4);
|
mb.add(mb5);
|
mb.add(mb6);
|
mb.add(mb8);
|
mb.add(mb7);
|
}
|
|
return mb;
|
}
|
|
public JlableModel getTagId() {
|
if(tagId==null) {
|
tagId=new JlableModel();
|
tagId.setText(" ±êÇ©ID: ");
|
|
}
|
return tagId;
|
}
|
|
public JlableModel getSname() {
|
if(sname==null) {
|
sname=new JlableModel();
|
sname.setText(" ÐÕ Ãû: ");
|
|
}
|
return sname;
|
}
|
|
public JlableModel getBumen() {
|
if(bumen==null) {
|
bumen=new JlableModel();
|
bumen.setText(" ²¿ ÃÅ: ");
|
}
|
return bumen;
|
}
|
/**»ñÈ¡ÐÔ±ðÄе¥Ñ¡°´Å¥*/
|
public JRadioButton getBoy() {
|
if(boy==null) {
|
boy=new JRadioButton("ÄÐ");
|
boy.setSelected(true);//ĬÈÏÄб»Ñ¡ÖÐ
|
}
|
return boy;
|
}
|
/**»ñÈ¡ÐÔ±ðÅ®µ¥Ñ¡°´Å¥*/
|
public JRadioButton getGirl() {
|
if(girl==null) {
|
girl=new JRadioButton("Å®");
|
}
|
return girl;
|
}
|
|
|
public JlableModel getCompany() {
|
if(company==null) {
|
company=new JlableModel();
|
company.setText(" ¹« ˾: ");
|
}
|
return company;
|
}
|
|
/**»ñȡѡÔñ¹«Ë¾ÏÂÀ¿ò*/
|
public JComboBox<String> getBumenComboBox() {
|
if(bumenComboBox==null) {
|
bumenComboBox=new JComboBox<>();//´´½¨ÏÂÀ¿ò¶ÔÏó
|
bumenComboBox.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 12));//ÉèÖÃ×ÖÌå
|
ComboBoxModel<String > coModel=new DefaultComboBoxModel<>(BuMens.getBumenNames());//ÏÂÀÁбíÄ£ÐÍ
|
bumenComboBox.setModel(coModel);
|
bumenComboBox.setEditable(true);
|
}
|
|
return bumenComboBox;
|
}
|
|
/**»ñȡѡÔñ¹«Ë¾ÏÂÀ¿ò*/
|
public JComboBox<String> getCompanyComboBox() {
|
if(companyComboBox==null) {
|
companyComboBox=new JComboBox<>();//´´½¨ÏÂÀ¿ò¶ÔÏó
|
companyComboBox.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 12));//ÉèÖÃ×ÖÌå
|
ComboBoxModel<String > coModel=new DefaultComboBoxModel<>(Dell_tbCompany.getcompanyNames());//ÏÂÀÁбíÄ£ÐÍ
|
companyComboBox.setModel(coModel);
|
companyComboBox.setEditable(true);
|
}
|
return companyComboBox;
|
}
|
|
public JlableModel getSex() {
|
if(sex==null) {
|
sex=new JlableModel();
|
sex.setText(" ÐÔ ±ð: ");
|
}
|
return sex;
|
}
|
|
public JlableModel getPhoneNum() {
|
if(phoneNum==null) {
|
phoneNum=new JlableModel();
|
phoneNum.setText(" µç »°: ");
|
}
|
return phoneNum;
|
}
|
|
public JlableModel getBeizhu() {
|
if(beizhu==null) {
|
beizhu=new JlableModel();
|
beizhu.setText(" ±¸ ×¢: ");
|
}
|
return beizhu;
|
}
|
|
/**»ñÈ¡±êÇ©Îı¾¿òIDµÄ·½·¨*/
|
public String getTagID() {
|
String tagId=get_tag_field().getText();//»ñÈ¡±êÇ©id
|
return tagId;
|
|
}
|
|
/**»ñÈ¡±êÇ©Îı¾¿òÐÕÃûµÄ·½·¨*/
|
public String getName(){
|
String name=getSnameFile().getText().trim();//»ñÈ¡ÐÕÃû
|
return name;
|
}
|
|
/**»ñÈ¡²¿ÃÅÎı¾¿ò²¿Ãŵķ½·¨*/
|
public String getDePartMent() {
|
String dePartMent=(String) getBumenComboBox().getSelectedItem();//»ñÈ¡²¿ÃÅ
|
return dePartMent;
|
}
|
|
/**»ñÈ¡µç»°ºÅÂëÎı¾¿òºÅÂëµÄ·½·¨*/
|
public String getPhoneNumText() {
|
String phoneNum=getPhoneNumFile().getText().trim();//»ñÈ¡µç»°
|
return phoneNum;
|
}
|
|
/**»ñÈ¡ÐÔ±ðµÄ·½·¨*/
|
public String getSelectedSex() {
|
String sex="ÄÐ";
|
if(getGirl().isSelected()) {
|
sex="Å®";
|
}
|
return sex;
|
}
|
|
/**»ñÈ¡±¸×¢Îı¾¿òÄÚÈݵķ½·¨*/
|
public String getBeizhuText() {
|
String beizhu=getBeizhuFile().getText().trim();//»ñÈ¡±¸×¢ÐÅÏ¢
|
return beizhu;
|
}
|
|
/**»ñȡȷ¶¨°´Å¥*/
|
public JButtonModel getSure() {
|
if(sure==null) {
|
sure=new JButtonModel("È·¶¨");
|
sure.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if(getTagID() .equals("")) {
|
ShowMessage.zidingyi("±êÇ©ID²»ÄÜΪ¿Õ");
|
return;
|
}
|
|
if(getName().equals("")||getName().length()>4) {
|
ShowMessage.zidingyi("¼ì²éÐÕÃûÊÇ·ñΪ¿Õ»òÕß³¤¶È´óÓÚ4£¡");
|
return;
|
}
|
|
if(getPhoneNumText().length()>11) {
|
ShowMessage.zidingyi("µç»°ºÅÂë¹ý³¤Çë¼ì²é£¡");
|
return;
|
}
|
|
if(getBeizhuText().length()>15) {
|
ShowMessage.zidingyi("±¸×¢ÐÅÏ¢¹ý³¤ÇëÐ޸ģ¡");
|
return;
|
}
|
|
setUpadateSql();
|
String update="UPDATE tb_tag SET state='"+getName()+"' where tag_id='"+getTagID()+"'";
|
DatabaseManagement.update(update);// Ð޸ıêÇ©ÐÅÏ¢
|
updateTable() ;
|
|
}
|
});
|
}
|
|
return sure;
|
}
|
|
/**ÐÞ¸Ä±í·½·¨*/
|
public void setUpadateSql(){
|
// Ö´ÐÐSQL²éѯÓï¾ä»ñµÃµÄ½á¹û¼¯Èç¹û±êÇ©ÒѾ´æÔÚÔò²»ÔÙÖ´ÐÐÏÂÃæµÄÓï¾ä
|
ResultSet haveTag = DatabaseManagement.query("select * from tb_person where tag_id='"+getTagID()+"'");
|
try {
|
if (haveTag.next()) {// ½á¹û¼¯ÖбêÇ©IDÓг¬¹ýÒ»ÌõµÄ¼Ç¼
|
ShowMessage.zidingyi("±êÇ©Ìí¼Óʧ°Ü"+getTagID()+"±êÇ©ÒѾ´æÔÚ£¡");
|
return;
|
}
|
} catch (Exception er) {
|
er.printStackTrace();
|
}
|
String updateSQL="INSERT tb_person (id,tag_id,name,departmentName,sex,phonenum,addtime,remark) VALUES (default,'"+
|
getTagID()+"','"+getName()+"','"+getDePartMent()+"','"+getSelectedSex()+"','"+
|
getPhoneNumText()+"','"+GetNowTime.now2()+"','"+getBeizhuText()+"')";
|
DatabaseManagement.update(updateSQL);// Ìí¼Ó±êÇ©ÐÅÏ¢
|
|
//Ìí¼Ó³É¹¦ÌáʾÐÅÏ¢
|
ShowMessage.zidingyi("Ìí¼Ó³É¹¦£¡");
|
//±êÇ©Ìí¼Ó³É¹¦ºóÐèÒªÐ޸ıêÇ©µÄʹÓÃ״̬ΪÊÇ
|
|
}
|
|
|
/**»ñȡȡÏû°´Å¥*/
|
public JButtonModel getQuxiao() {
|
if(quxiao==null) {
|
quxiao=new JButtonModel("È¡Ïû");
|
quxiao.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
closeTagDialog();
|
}
|
});
|
}
|
return quxiao;
|
}
|
|
public JTextField getSnameFile() {
|
if(snameFile==null) {
|
snameFile=new JTextField(8);
|
}
|
return snameFile;
|
}
|
|
public JTextField getPhoneNumFile() {
|
if(phoneNumFile==null) {
|
phoneNumFile=new JTextField(12);
|
phoneNumFile.setText("1234*******");
|
}
|
return phoneNumFile;
|
}
|
/**»ñÈ¡±¸×¢Îı¾¿ò*/
|
public JTextField getBeizhuFile() {
|
if(beizhuFile==null) {
|
beizhuFile=new JTextField(12);
|
}
|
return beizhuFile;
|
}
|
|
/**»ñȡѡÔñ±êÇ©ÏÂÀ¿ò*/
|
public JTextField get_tag_field() {
|
|
if(tag_field==null) {
|
tag_field=new JTextField(10);//´´½¨ÏÂÀ¿ò¶ÔÏó
|
tag_field.setFont(new Font("΢ÈíÑźÚ", Font.PLAIN, 12));//ÉèÖÃ×ÖÌå
|
}
|
|
return tag_field;
|
}
|
|
}
|
|
}
|