zsh_root
2024-01-02 7b595546af704983dbafcd0d385c8768ddacefc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
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);
        }
    }
 
}