package Frame;
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.awt.Container;
|
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.List;
|
import java.util.Vector;
|
import javax.swing.Box;
|
import javax.swing.ImageIcon;
|
import javax.swing.JLabel;
|
import javax.swing.JPanel;
|
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 DataBase.DatabaseManagement;
|
import Method.InsertData;
|
import Method.Serch;
|
import PbuliClass.JButtonModel;
|
import PbuliClass.OutButton;
|
import PbuliClass.ShowMessage;
|
import PbuliClass.Systems;
|
import PbuliClass.WarningMessage;
|
import PbuliClass.greateTables;
|
import PbuliClass.jinternalFrame;
|
import engbs.Tongji;
|
import person.Person;
|
import person.person_Dell;
|
import tbDataModel_Dell.Tb_Warnig_Dell;
|
@SuppressWarnings("rawtypes")
|
public class WarningManage extends jinternalFrame {
|
/**
|
*
|
*/
|
private static final long serialVersionUID = 1L;
|
|
JPanel inJpanel=null;//ÄÚ²¿Ãæ°å
|
NothJPanel northJpanel=null;//±±²¿Ãæ°å
|
JPanel centerJpanel=null;//Öв¿Ãæ°å
|
JButtonModel jbut;//°´Å¥Ä£ÐÍ
|
JTextField searchFileld=null;//ËÑË÷Îı¾¿ò
|
JButtonModel search=null;//ËÑË÷°´Å¥
|
JButtonModel shuaxin=null;//ˢа´Å¥
|
JButtonModel delete=null;//ɾ³ý°´Å¥
|
JButtonModel deleteAll=null;//È«²¿É¾³ý°´Å¥
|
JButtonModel handle=null;//µ¥Ìõ´¦Àí
|
JButtonModel handleAll=null;//È«²¿´¦Àí
|
JTable table=null;//ÉêÃ÷±í¸ñ
|
Vector rowData=null;
|
DefaultTableModel tableModel;//±í¸ñÄ£ÐÍ
|
List list;
|
int tagnum;//±í¸ñ×ÜÐÐÊý
|
Container rq;
|
|
|
public WarningManage() {
|
rowData=new Vector();
|
String title="¸æ¾¯ÐÅÏ¢";
|
if(Systems.sys().getLanguage().equals("English")) {
|
title="Warning Mangage";
|
}
|
this.setTitle(title);
|
this.setFrameIcon(new ImageIcon("image/icon/sosicon.png"));//ÉèÖô°Ìåͼ±ê
|
rq=getContentPane();//»ñÈ¡ÈÝÆ÷
|
rq.setLayout(new BorderLayout());
|
rq.add(getNorthJpanel(),BorderLayout.NORTH);
|
rq.add(getGd());
|
|
}
|
|
/**»ñÈ¡±±²¿Ãæ°å*/
|
public NothJPanel getNorthJpanel() {
|
if(northJpanel==null) {
|
northJpanel=new NothJPanel();
|
Box topicBox = Box.createHorizontalBox();// ´´½¨Ò»¸öˮƽÏäÈÝÆ÷
|
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(getHandle());//Ìí¼Ó´¦Àí°´Å¥
|
topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getHandleAll());//Ìí¼Ó´¦ÀíÈ«²¿°´Å¥
|
topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getDelete());//Ìí¼Óɾ³ý°´Å¥
|
topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getDeleteAll());//Ìí¼Óɾ³ýÈ«²¿°´Å¥
|
topicBox.add(Box.createHorizontalStrut(5));// Ìí¼ÓÒ»¸ö5ÏñËØ¿íµÄˮƽ֧Öù
|
topicBox.add(getOutport());//Ìí¼Óµ¼³ö°´Å¥
|
northJpanel.add(topicBox );
|
}
|
|
return northJpanel;
|
}
|
|
|
/**»ñÈ¡ËÑË÷Îı¾¿òµÄ·½·¨*/
|
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²éѯÓï¾ä»ñµÃµÄ½á¹û¼¯
|
String so=getSearchFileld().getText();
|
try {
|
if(so.length()>1) {
|
String go=getSearchFileld().getText().trim();
|
updateSerch(Serch.so("tb_warning", go, "objectid", "status", "type"));
|
}else {
|
ShowMessage.zidingyi("ÄãÊäÈëµÄËÑË÷ÄÚÈݲ»ÕýÈ·");
|
return;
|
}
|
} catch (Exception er) {
|
er.printStackTrace();
|
}
|
}
|
});
|
}
|
return search;
|
}
|
|
|
/**»ñȡˢа´Å¥µÄ·½·¨*/
|
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 getHandle() {
|
if(handle==null){
|
handle=new JButtonModel(buttonTitle.getTreat());
|
handle.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 id=(String) table.getValueAt(selectedRows[i], 0);
|
String type=(String) table.getValueAt(selectedRows[i], 1);
|
String tagid=(String) table.getValueAt(selectedRows[i], 2);
|
String status=(String) table.getValueAt(selectedRows[i], 3);
|
String updateSQL="UPDATE tb_warning SET status='ÒÑ´¦Àí' where objectid='"+tagid+"'";
|
if(status.equals("ÒÑ´¦Àí")) {
|
ShowMessage.zidingyi("ÐòºÅ"+id+"ÒѾ´¦Àí²»ÒªÖØ¸´´¦Àí£¡");
|
return;
|
}
|
|
int ok=DatabaseManagement.update(updateSQL);// ´¦Àí¸æ¾¯ÐÅÏ¢ÐÅÏ¢
|
Person prs=person_Dell.get_Person(tagid);
|
if(ok !=0) {
|
if(type.equals("SOS")&&status.equals("δ´¦Àí")) {
|
Tb_Warnig_Dell.alert_sos_status(tagid);
|
updateTable();
|
ShowMessage.zidingyi(tagid+"´¦Àí³É¹¦£¡");
|
person_Dell.alert_sos(tagid, "0");
|
person_Dell.alert_sos_state(tagid, "0");//±êÇ©sos´¦Àí״̬ΪÒÑ´¦Àí
|
}else if(type.equals("¸æ¾¯ÇøÓò")&&status.equals("δ´¦Àí")) {
|
person_Dell.alert_isin_fence(tagid, "0","");
|
}else if(type.equals("µÍµçÁ¿")&&status.equals("δ´¦Àí")) {
|
person_Dell.alert_person_power_lowpowerstate(tagid);
|
}else if(type.equals("³öÇøÓò¸æ¾¯")&&status.equals("δ´¦Àí")) {
|
prs.setOutwarning(false);
|
}else if(type.equals("±»²ð³ý")&&status.equals("δ´¦Àí")) {
|
prs.setTagoff("1");
|
}
|
|
}else {
|
ShowMessage.zidingyi("ûÓд¦Àí³É¹¦Ð´ÈëÊý¾Ý¿â³ö´í£¡");
|
}
|
}
|
updateTable();//ˢбí¸ñ
|
}
|
|
}
|
});
|
}
|
return handle;
|
}
|
|
/**»ñȡȫ²¿´¦Àí°´Å¥µÄ·½·¨*/
|
public JButtonModel getHandleAll() {
|
if(handleAll==null){
|
handleAll=new JButtonModel(buttonTitle.getTreatAll());
|
handleAll.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
//Ñ¡Ôñ¶Ô»°¿òÈçyes·µ»Ø0£¬NO·µ»Ø1£¬È¡Ïû·µ»Ø2
|
WarningMessage warning=new WarningMessage();
|
warning.setMessage("Ñ¡Ôñ´¦ÀíÈ«²¿½«»á°Ñ±í¸ñÊý¾ÝÈ«²¿´¦ÀíÈ·¶¨Âð£¿");
|
int warn=warning.getwarMss(northJpanel );
|
int tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý
|
if(tagnum!=0 && warn==0) {
|
InsertData.alertSosTbWaring();
|
Tb_Warnig_Dell.alert_all_status();
|
String sos="0";
|
person_Dell.alert_all_sos_and_infence(sos);
|
String update="UPDATE tb_person SET p_sos='"+sos+"'";
|
DatabaseManagement.update(update);// ¸üÐÂÊý¾Ý¿â
|
person_Dell.alert_person_power_lowpowerstate("ËùÓбêÇ©");
|
ShowMessage.zidingyi("È«²¿´¦ÀíÍê±Ï");
|
Tongji.gengxin();
|
}
|
|
updateTable();//ˢбí¸ñ
|
}
|
});
|
}
|
return handleAll;
|
}
|
|
/**»ñȡɾ³ý°´Å¥µÄ·½·¨*/
|
public JButtonModel getDelete() {
|
if(delete==null){
|
delete=new JButtonModel(buttonTitle.getDelete());
|
delete.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
int[] selectedRows=table.getSelectedRows();//±»Ñ¡ÖÐÐеÄË÷Òý¼¯ºÏ
|
int size=selectedRows.length;
|
if( size!=0) {
|
//ɾ³ýËùÓб»Ñ¡ÖеÄÐÐ
|
for(int i=selectedRows.length-1;i>=0;i--){//ÕâÊǹؼü´úÂë
|
String sosstate=(String)table.getValueAt(selectedRows[i], 1);
|
String tagid=(String)table.getValueAt(selectedRows[i], 2);
|
String time=(String)table.getValueAt(selectedRows[i],5);
|
if(sosstate.equals("SOS¸æ¾¯")) {
|
person_Dell.alert_sos(tagid, "0");
|
}else if(sosstate.equals("¸æ¾¯ÇøÓò")) {
|
person_Dell.alert_isin_fence(tagid, "0","");
|
}
|
InsertData.deletetData("tb_warning", (String)table.getValueAt(selectedRows[i], 0));
|
|
Tb_Warnig_Dell.delete_tbwarning(tagid, time);
|
|
tableModel.removeRow(selectedRows[i]);//ɾ³ýÈÎÒⱻѡÖÐÐÐ
|
}
|
table.setModel(tableModel);//¸üбí¸ñÄ£ÐÍ
|
ShowMessage.delteSuccess(selectedRows.length);
|
}
|
else {
|
ShowMessage.zidingyi("ÇëÑ¡ÖÐÐèҪɾ³ýµÄÐУ¡");
|
}
|
updateTable();
|
}
|
});
|
}
|
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(northJpanel );
|
int tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý
|
String deleteSql="TRUNCATE TABLE tb_warning ";
|
if(tagnum!=0 && warn==0) {
|
ShowMessage.deleteAll(DatabaseManagement.update(deleteSql));
|
person_Dell.alert_all_sos_and_infence("0");
|
Tb_Warnig_Dell.delete_all_tbwarning();
|
}
|
rq.repaint();
|
}
|
});
|
|
}
|
return deleteAll;
|
}
|
|
/**»ñÈ¡µ¼³ö±í¸ñ°´Å¥µÄ·½·¨*/
|
public JButtonModel getOutport() {
|
OutButton.setAddtime("time");
|
OutButton.setDataName("tb_warning");
|
return new OutButton().get_ouotport_button();
|
|
}
|
|
/**»ñÈ¡¹ö¶¯Ãæ°åµÄ·½·¨*/
|
public JScrollPane getGd() {
|
JScrollPane gd=new JScrollPane(getTable());
|
gd.getViewport().setBackground(UIColor.getNorth_color());
|
return gd;
|
}
|
|
|
/**Ìí¼Ó±í¸ñÐÐÏòÁ¿Êý¾Ý·½·¨*/
|
@SuppressWarnings("unchecked")
|
public void getRowData(List list ) {
|
Iterator iterator = list.iterator();//´´½¨µü´úÆ÷
|
while (iterator.hasNext()) {//µü´úÆ÷´æÔÚÔªËØ
|
List info = (List) iterator.next();//½«µü´úÆ÷ÀïÃæµÄÔªËØ¸øµ½list¼¯ºÏ
|
Vector row = new Vector();
|
String name=(String)info.get(3);
|
if(name.equals("ÒÑ´¦Àí")) {
|
name="okdell";
|
}else {
|
name="nodell";
|
}
|
ImageIcon icon=new ImageIcon("image/icon/"+name+".png");
|
row.add((String)info.get(0));// ÐòºÅ
|
row.add((String)info.get(1));//
|
row.add((String)info.get(2));//
|
row.add((String)info.get(3));//
|
row.add(icon);// ͼ±êµØÖ·
|
row.add((String)info.get(4));
|
String a1=(String)info.get(5);
|
if(a1==null) {
|
a1="";
|
}
|
row.add(a1);
|
rowData.add(row);// Ïò±í¸ñ¶ÔÏóÌí¼ÓÐÐÊý¾Ý£¨Í¼±êÐÅÏ¢£©
|
}
|
|
}
|
|
|
/**»ñÈ¡±êÇ©¸æ¾¯±í¸ñµÄ·½·¨*/
|
@SuppressWarnings("serial")
|
public JTable getTable() {
|
if(table==null) {
|
String[] name1= {"ÐòºÅ","¸æ¾¯ÀàÐÍ","É豸ID","´¦ÀíÇé¿ö","´¦Àí״̬","¸üÐÂʱ¼ä","±¸×¢"};//±í¸ñÁÐÃû
|
String[] name2= {"Serial Number", "Alarm Type", "Device ID",
|
"Processing Status", "Processing Status", "Update Time"};//±í¸ñÁÐÃû
|
String[] columnNames=English.columnNames(name1, name2);
|
//Ìí¼Ó±í¸ñÁÐÏòÁ¿
|
Vector<String> columnName=new Vector<>();
|
for(int i=0;i<columnNames.length;i++){
|
columnName.add(columnNames[i]);
|
}
|
list = DatabaseManagement.table_AandD("tb_warning", "DESC");//½«ÁбíÖÐËùÓнá¹û¼¯¸øµ½list¼¯ºÏ
|
getRowData(list );
|
greateTables tables=new greateTables();
|
tableModel=new DefaultTableModel(rowData, columnName){
|
// ʵÏÖÈÃÕû¸ö±í¸ñ²»²»ÔÊÐí±»±à¼
|
public boolean isCellEditable(int row,int column){
|
return false;
|
}
|
};
|
table=tables.getTable(tableModel);
|
table.getColumnModel().getColumn(0).setPreferredWidth(75);
|
table.getColumnModel().getColumn(1).setPreferredWidth(100);
|
table.getColumnModel().getColumn(2).setPreferredWidth(90);
|
table.getColumnModel().getColumn(3).setPreferredWidth(90);// ÉèÖõÚ3Áпí
|
table.getColumnModel().getColumn(4).setPreferredWidth(90);
|
table.getColumnModel().getColumn(5).setPreferredWidth(150);// ÉèÖõÚ4Áпí
|
TableColumn column = table.getColumnModel().getColumn(4);// »ñÈ¡±í¸ñµÚ2ÁжÔÏó
|
column.setCellRenderer(new TableCellRenderer() {// ÉèÖõÚ2ÁеÄäÖȾÆ÷
|
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;
|
}
|
|
|
/**ˢбí¸ñ·½·¨*/
|
public void updateTable() {
|
tagnum=table.getRowCount();//±í¸ñ×ÜÐÐÊý
|
if(tagnum !=0 ) {
|
for (int i = 0; i < tagnum; i++) {//ɾ³ýËùÓÐÐÐ
|
tableModel.removeRow(0);//ɾ³ýËùÓÐÐÐ
|
}
|
list = DatabaseManagement.table_AandD("tb_warning", "DESC");
|
getRowData(list);
|
}
|
}
|
|
|
/**ËÑË÷·½·¨*/
|
public void updateSerch(String serch) {
|
tagnum=getTable().getRowCount();//±í¸ñ×ÜÐÐÊý
|
if(tagnum !=0 ) {
|
for (int i = 0; i < tagnum; i++) {//ɾ³ýËùÓÐÐÐ
|
tableModel.removeRow(0);
|
}
|
list = DatabaseManagement.serch(serch);//½«ÁбíÖÐËùÓнá¹û¼¯¸øµ½list¼¯ºÏ
|
getRowData(list);
|
}
|
}
|
|
}
|