package Frame;
|
import java.awt.BorderLayout;
|
import java.awt.Color;
|
import java.awt.Component;
|
import java.awt.Container;
|
import java.awt.Font;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.KeyEvent;
|
import java.awt.event.KeyListener;
|
import java.util.Iterator;
|
import java.util.Timer;
|
import java.util.TimerTask;
|
import java.util.Vector;
|
import javax.swing.Box;
|
import javax.swing.ImageIcon;
|
import javax.swing.JInternalFrame;
|
import javax.swing.JProgressBar;
|
import javax.swing.JScrollPane;
|
import javax.swing.JTable;
|
import javax.swing.JTextField;
|
import javax.swing.UIManager;
|
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 DataBase.DatabaseManagement;
|
import PbuliClass.JButtonModel;
|
import PbuliClass.Leds;
|
import PbuliClass.OutButton;
|
import PbuliClass.ShowMessage;
|
import PbuliClass.Systems;
|
import PbuliClass.WarningMessage;
|
import PbuliClass.greateTables;
|
import PbuliClass.jinternalFrame;
|
import fence.kaoqing.Dell_KaoQing;
|
import fence.kaoqing.TbRealKaoQing;
|
/**ʵʱ¿¼ÇڼǼ±í*/
|
@SuppressWarnings("rawtypes")
|
public class RealKaoQingTable extends jinternalFrame {
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
jinternalFrame jinerFrame=null;
|
JInternalFrame jinFrame=null;
|
NothJPanel northPanel=null;//±±²¿Ãæ°å
|
JTextField searchFileld=null;//ËÑË÷Îı¾¿ò
|
JTextField kaoqing_num=null;//ʵʱ¿¼ÇÚÈËÊý
|
JButtonModel search=null;//ËÑË÷°´Å¥
|
JButtonModel shuaxin=null;//ˢа´Å¥
|
JButtonModel add=null;//ÐÂÔö°´Å¥
|
JButtonModel alter=null;//Ð޸İ´Å¥
|
JButtonModel delete=null;//ɾ³ý°´Å¥
|
JButtonModel deleteAll=null;//È«²¿É¾³ý°´Å¥
|
JButtonModel enterPort=null;//µ¼ÈëÈËÔ±°´Å¥
|
JButtonModel download=null;//Ä£°åÏÂÔØ°´Å¥
|
JScrollPane gd=null;//¹ö¶¯Ãæ°å
|
JTable table=null;//ÉêÃ÷±í¸ñ
|
Vector<Vector<String>> rowData=null;
|
DefaultTableModel tableModel=null;//ÉùÃ÷±í¸ñÄ£ÐÍ
|
Container rq;
|
Box topicBox;
|
Font font=new Font("ºÚÌå", Font.BOLD, 14);
|
|
|
int selectedRow;//±»Ñ¡ÖеÄÐÐ
|
public RealKaoQingTable() {//¹¹Ôì·½·¨
|
topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
|
rowData=new Vector<>();
|
rq=getContentPane();//»ñÈ¡ÈÝÆ÷
|
rq.setLayout(new BorderLayout());
|
rq.setBackground(Color.white);
|
String title="ʵʱ¿¼ÇÚÐÅÏ¢±í";
|
if(Systems.sys().getLanguage().equals("English")) {
|
title="Real-time Attendance Information Sheet";
|
}
|
this.setTitle(title);
|
this.setFrameIcon(new ImageIcon("image/icon/kaoqingicon.png"));//ÉèÖô°Ìåͼ±ê
|
rq.add(getNorthPanel(),BorderLayout.NORTH);
|
rq.add(getGd(),BorderLayout.CENTER);
|
ding_shi_qi();
|
|
}
|
|
|
/**»ñÈ¡±±²¿Ãæ°åµÄ·½·¨*/
|
public NothJPanel getNorthPanel() {
|
if(northPanel==null) {
|
northPanel=new NothJPanel();
|
topicBox.add(getKaoqing_num());
|
topicBox.add(Box.createHorizontalStrut(10));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getSearchFileld());//Ìí¼ÓËÑË÷Îı¾¿ò
|
topicBox.add(Box.createHorizontalStrut(3));// Ìí¼ÓÒ»¸ö3ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getSearch());//Ìí¼ÓËÑË÷°´Å¥
|
topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getShuaxin());//Ìí¼Óˢа´Å¥
|
topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getDelete());//Ìí¼Óɾ³ý°´Å¥
|
topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getDeleteAll());//Ìí¼Óɾ³ýÈ«²¿°´Å¥
|
northPanel.add(topicBox );
|
|
|
}
|
return northPanel;
|
}
|
|
/**»ñÈ¡ËÑË÷Îı¾¿òµÄ·½·¨*/
|
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 JButtonModel getSearch() {
|
if(search==null){
|
search=new JButtonModel(buttonTitle.getSerch());
|
search.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
// Ö´ÐÐSQL²éѯÓï¾ä»ñµÃµÄ½á¹û¼¯
|
try {
|
if(getSearchFileld().getText().length()>1) {
|
String go=getSearchFileld().getText();
|
updateSerch(go);
|
}
|
|
} catch (Exception er) {
|
er.printStackTrace();
|
}
|
}
|
});
|
|
}
|
return search;
|
}
|
|
/**»ñÈ¡µ¼³ö±í¸ñ°´Å¥µÄ·½·¨*/
|
public JButtonModel getDao_chu_table() {
|
OutButton.setAddtime("intime");
|
OutButton.setDataName("tb_realkaoqing");
|
return new OutButton().get_ouotport_button();
|
}
|
|
/**»ñȡˢа´Å¥µÄ·½·¨*/
|
public JButtonModel getShuaxin() {
|
if(shuaxin==null){
|
shuaxin=new JButtonModel(buttonTitle.getRefresh());
|
shuaxin.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
updateTable() ;
|
}
|
});
|
|
}
|
return shuaxin;
|
}
|
|
|
/**»ñÈ¡±í¸ñ±»Ñ¡ÖеÄÐз½·¨*/
|
public int getSelectedRow() {
|
selectedRow=getTable().getSelectedRow();
|
return selectedRow;
|
|
}
|
|
/**»ñȡɾ³ý°´Å¥µÄ·½·¨*/
|
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], 3);
|
String araname=(String) table.getValueAt(selectedRows[i], 0);
|
String deleteSql="DELETE FROM tb_realkaoqing WHERE tagid='"+tagid+"'";
|
TbRealKaoQing tbkq=Dell_KaoQing.get_tbkq(araname, tagid);
|
Dell_KaoQing.delete_TbRealKaoQing(tbkq, tagid);
|
DatabaseManagement.update(deleteSql);// ɾ³ý
|
|
}
|
//ɾ³ý³É¹¦ÌáʾÐÅÏ¢
|
ShowMessage.delteSuccess(selectedRows.length);
|
updateTable();//ˢбí¸ñ
|
|
}
|
else {
|
ShowMessage.zidingyi("ÇëÑ¡ÖÐÐèҪɾ³ýµÄÐУ¡");
|
}
|
|
}
|
});
|
|
}
|
return delete;
|
}
|
/**»ñȡȫ²¿É¾³ý°´Å¥µÄ·½·¨*/
|
public JButtonModel getDeleteAll() {
|
if(deleteAll==null){
|
deleteAll=new JButtonModel("Çå¿Õ¿¼ÇÚ");
|
deleteAll.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
//Ñ¡Ôñ¶Ô»°¿òÈçyes·µ»Ø0£¬NO·µ»Ø1£¬È¡Ïû·µ»Ø2
|
WarningMessage warning=new WarningMessage();
|
warning.setMessage("Ñ¡Ôñɾ³ýÈ«²¿½«»á°Ñ±í¸ñÊý¾ÝÈ«²¿É¾³ýÈ·¶¨Âð£¿");
|
int warn=warning.getwarMss(getNorthPanel());
|
int tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý
|
if(tagnum!=0 && warn==0) {
|
Dell_KaoQing.cleartallkaoqing();
|
ShowMessage.zidingyi("ɾ³ý³É¹¦");
|
rq.repaint();
|
}
|
}
|
});
|
|
}
|
return deleteAll;
|
}
|
|
/**»ñÈ¡¹ö¶¯Ãæ°åµÄ·½·¨*/
|
public JScrollPane getGd() {
|
if(gd==null){
|
gd=new JScrollPane(getTable());
|
gd.getViewport().setBackground(UIColor.getNorth_color());
|
|
}
|
return gd;
|
}
|
|
|
/**Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý·½·¨*/
|
@SuppressWarnings("unchecked")
|
public void getRowData(Vector<TbRealKaoQing> list ) {
|
Iterator<TbRealKaoQing> it = list.iterator();//´´½¨µü´úÆ÷
|
Vector row;
|
while (it.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ
|
TbRealKaoQing tb=it.next();
|
row = new Vector();
|
row.add(tb.getArea());
|
row.add(tb.getName());
|
row.add(tb.getBumen());
|
row.add(tb.getTagid());
|
row.add(Integer.parseInt(tb.getPower()));
|
row.add(tb.getIntime());
|
row.add("");
|
tableModel.addRow(row);
|
}
|
|
}
|
|
|
|
/**»ñÈ¡¿¼ÇÚ±í¸ñµÄ·½·¨*/
|
public JTable getTable() {
|
if(table==null) {
|
String[] name1= {"¿¼ÇÚÇøÓò","ÐÕ Ãû","²¿ ÃÅ","±êÇ©ID","±êÇ©µçÁ¿","½øÈëʱ¼ä","±¸ ×¢"};//±í¸ñÁÐÃû
|
String[] name2= {"Attendance Area", "Name", "Department",
|
"Tag ID", "Tag Power", "Entry Time", "Remarks"};//±í¸ñÁÐÃû
|
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){
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
// ʵÏÖÈÃÕû¸ö±í¸ñ²»²»ÔÊÐí±»±à¼
|
public boolean isCellEditable(int row,int column){
|
return false;
|
}
|
};
|
|
table=tables.getTable(tableModel);
|
getRowData(Dell_KaoQing.getrealkaoqings());
|
table.getColumnModel().getColumn(5).setPreferredWidth(174);// ÉèÖÃÁпí
|
table.getColumnModel().getColumn(6).setPreferredWidth(174);// ÉèÖÃÁпí
|
TableColumn column = table.getColumnModel().getColumn(4);// »ñÈ¡±í¸ñµÚ4ÁжÔÏó
|
column.setCellRenderer(new TableCellRenderer() {// ÉèÖõÚ4ÁеÄäÖȾÆ÷
|
public Component getTableCellRendererComponent(
|
JTable table, Object value, boolean isSelected,
|
boolean hasFocus, int row, int column) {
|
if (value instanceof Integer) {
|
JProgressBar bar=new JProgressBar();//´´½¨½ø¶ÈÌõ
|
Integer percent=(Integer)value;//°Ñµ±Ç°Öµ×ªÎªÕûÊý
|
bar.setValue(percent);//ÉèÖýø¶ÈÌõµÄÖµ
|
bar.setStringPainted(true);//ÏÔʾ½ø¶ÈÌõÎı¾
|
//δ¸²¸ÇǰµÄ½ø¶ÈÌõÑÕÉ«
|
UIManager.put("ProgressBar.selectionBackground",Color.black);
|
//¸²¸ÇºóµÄ½ø¶ÈÌõÑÕÉ«
|
UIManager.put("ProgressBar.selectionForeground",Color.blue);
|
if(percent<15) {
|
bar.setForeground(Color.red);//ÏÔʾ½ø¶ÈÌõµÄÑÕÉ«
|
}
|
else {
|
bar.setForeground(Color.green);//ÏÔʾ½ø¶ÈÌõµÄÑÕÉ«
|
}
|
bar.setBackground(UIColor.getNorth_color());
|
|
bar.setBorderPainted(false);//ÊÇ·ñÏÔʾ½ø¶ÈÌõ±ß¿ò
|
if (row % 2 == 0) {
|
bar.setBackground(UIColor.getTable_1());
|
} else {
|
bar.setBackground(UIColor.getTable_2());
|
}
|
|
if(isSelected) {
|
bar.setBackground(UIColor.getTable_sekected());
|
}
|
|
|
|
return bar;// °Ñͼ±ê×÷ΪΪäÖȾ¿Ø¼þ
|
}
|
else {
|
return null;
|
}
|
}
|
});
|
|
}
|
return table;
|
|
}
|
|
//ʵʱ¿¼ÇÚÎı¾¿ò
|
public JTextField getKaoqing_num() {
|
if(kaoqing_num==null) {
|
kaoqing_num=new JTextField(50);
|
kaoqing_num.setBorder(null);
|
kaoqing_num.setBackground(null);
|
kaoqing_num.setEnabled(true);
|
kaoqing_num.setFont(font);
|
kaoqing_num.setForeground(UIColor.getGrenn());
|
}
|
return kaoqing_num;
|
}
|
|
/**ˢбí¸ñ·½·¨*/
|
public void updateTable() {
|
|
if(tableModel !=null) {
|
tableModel.getDataVector().clear();
|
getRowData(Dell_KaoQing.getrealkaoqings());
|
gd.validate();
|
}
|
}
|
|
/**´´½¨Ò»¸ö¶¨Ê±Æ÷ÓÃÓÚˢбí¸ñ*/
|
public void ding_shi_qi() {
|
if (Leds.get_tb_led()==null){
|
return;
|
}
|
int time=Integer.parseInt(Leds.get_tb_led().getGengxintime());
|
Integer cacheTime = 1000 *time;//´¥·¢Æ÷ʱ¼ä
|
Timer timer = new Timer();
|
// (TimerTask task, long delay, long period)ÈÎÎñ£¬ÑÓ³Ùʱ¼ä£¬¶à¾ÃÖ´ÐÐ
|
timer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
try {
|
updateTable() ;//Ë¢ÐÂʵʱ¿¼ÇÚ±í¸ñ
|
kaoqing_num.setText(Dell_KaoQing.all_kaoqing_num());
|
} catch (Exception e) {
|
// TODO ×Ô¶¯Éú³ÉµÄ catch ¿é
|
e.printStackTrace();
|
}
|
}
|
}, 1000, cacheTime);
|
|
}
|
|
|
|
/**ËÑË÷·½·¨*/
|
public void updateSerch(String serch) {
|
int tagnum=getTable().getRowCount();//±í¸ñ×ÜÐÐÊý
|
if(tagnum !=0 ) {
|
for (int i = 0; i < tagnum; i++) {//ɾ³ýËùÓÐÐÐ
|
tableModel.removeRow(0);
|
}
|
getRowData(Dell_KaoQing.serch(serch));
|
}
|
}
|
|
|
}
|