Jay
2024-11-08 02722a3f9eca857ce7fffea352e9f7ee692a1b71
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
package com.iailab.netsdk.demo.frame;
 
import com.iailab.netsdk.common.FunctionList;
import com.iailab.netsdk.common.Res;
import com.iailab.netsdk.lib.NetSDKLib;
import com.iailab.netsdk.lib.NetSDKLib.LLong;
import com.iailab.netsdk.lib.ToolKits;
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
 
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.UnsupportedEncodingException;
 
import static com.iailab.netsdk.lib.NetSDKLib.NET_MAX_NAME_LEN;
import static com.iailab.netsdk.lib.NetSDKLib.NET_MAX_PLATE_NUMBER_LEN;
import static java.util.Locale.ENGLISH;
 
class JNATrafficListFrame extends Frame{
    
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    static NetSDKLib NetSdk        = NetSDKLib.NETSDK_INSTANCE;
    static NetSDKLib ConfigSdk     = NetSDKLib.CONFIG_INSTANCE;
    
    //登陆参数
    private String m_strIp         = "172.13.138.22";
    private Integer m_nPort        = new Integer("37777");
    private String m_strUser       = "admin";
    private String m_strPassword   = "hzci202239";
    private int nNo = 0;
    private String[] name = {Res.string().getSerialNumber(), Res.string().getLicensePlateNumber(), Res.string().getCarOwner(),
            Res.string().getStartTime(), Res.string().getEndTime(),Res.string().getOpenModel()};
 
    //设备信息
    private NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); // 对应CLIENT_LoginEx2
    private LLong m_hLoginHandle = new LLong(0);   //登陆句柄
    private NetSDKLib.NET_TRAFFIC_LIST_RECORD pstRecordAdd = new NetSDKLib.NET_TRAFFIC_LIST_RECORD(); // 开闸权限
    
    //////////////////SDK相关信息///////////////////////////
    //NetSDK 库初始化
    public class SDKEnvironment {
        
        private boolean bInit    = false;
        private boolean bLogopen = false;   
        
        private DisConnect disConnect       = new DisConnect();    //设备断线通知回调
        private HaveReConnect haveReConnect = new HaveReConnect(); //网络连接恢复
            
        //设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数
        public class DisConnect implements NetSDKLib.fDisConnect {
            public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
                System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort);
            }
        }        
        //网络连接恢复,设备重连成功回调
        // 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数
        public class HaveReConnect implements NetSDKLib.fHaveReConnect {
            public void invoke(LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
                System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort);
            }
        }
        
        //初始化
        public boolean init() {    
            bInit = NetSdk.CLIENT_Init(disConnect, null);
            if(!bInit) {
                System.out.println("Initialize SDK failed");
                return false;
            }
            
            //打开日志,可选
            NetSDKLib.LOG_SET_PRINT_INFO setLog = new NetSDKLib.LOG_SET_PRINT_INFO();
            File path = new File(".");        
            String logPath = path.getAbsoluteFile().getParent() + "\\sdk_log\\TrafficList" + System.currentTimeMillis() + ".log";            
            
            setLog.bSetFilePath = 1; 
            System.arraycopy(logPath.getBytes(), 0, setLog.szLogFilePath, 0, logPath.getBytes().length);
            
            setLog.bSetPrintStrategy = 1;
            setLog.nPrintStrategy    = 0;
            bLogopen = NetSdk.CLIENT_LogOpen(setLog);
            if(!bLogopen ) {
                System.err.println("Failed to open NetSDK log");
            }
            
            // 设置断线重连回调接口,设置过断线重连成功回调函数后,当设备出现断线情况,SDK内部会自动进行重连操作
            // 此操作为可选操作,但建议用户进行设置
            NetSdk.CLIENT_SetAutoReconnect(haveReConnect, null);
            
            //设置登录超时时间和尝试次数,可选
            int waitTime = 5000; //登录请求响应超时时间设置为5S
            int tryTimes = 3;    //登录时尝试建立链接3次
            NetSdk.CLIENT_SetConnectTime(waitTime, tryTimes);
            
            // 设置更多网络参数,NET_PARAM的nWaittime,nConnectTryNum成员与CLIENT_SetConnectTime 
            // 接口设置的登录设备超时时间和尝试次数意义相同,可选
            NetSDKLib.NET_PARAM netParam = new NetSDKLib.NET_PARAM();
            netParam.nConnectTime = 10000; //登录时尝试建立链接的超时时间
            NetSdk.CLIENT_SetNetworkParam(netParam);    
            return true;
        }
        
        //清除环境
        public void cleanup() {
            if(bLogopen) {
                NetSdk.CLIENT_LogClose();
            }
            
            if(bInit) {
                NetSdk.CLIENT_Cleanup();
            }
        }
    }
        
    private SDKEnvironment sdkEnv;
 
    public JNATrafficListFrame() {    
        sdkEnv = new SDKEnvironment();
        sdkEnv.init();
        setTitle(Res.string().getTrafficAllowList());
        setSize(900, 650);
        setLayout(new BorderLayout());
        setLocationRelativeTo(null);
        setVisible(true);
                
        loginPanel = new LoginPanel();
        TrafficPanel trafficPanel = new TrafficPanel();
        QueryViewPanel queryViewPanel = new QueryViewPanel();
         
        add(loginPanel, BorderLayout.NORTH);
        add(trafficPanel, BorderLayout.WEST);
        add(queryViewPanel, BorderLayout.CENTER);
        
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.out.println("Window Closing");
                //登出
                logoutButtonPerformed(null);            
                dispose();
 
                // 返回主菜单
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        FunctionList demo = new FunctionList();
                        demo.setVisible(true);
                    }
                });
            }
        });
 
    }
    
    /////////////////面板///////////////////
    //////////////////////////////////////
    //设置边框
    private void setBorderEx(JComponent object, String title, int width) {
        Border innerBorder = BorderFactory.createTitledBorder(title);
        Border outerBorder = BorderFactory.createEmptyBorder(width, width, width, width);
        object.setBorder(BorderFactory.createCompoundBorder(outerBorder, innerBorder));     
    }
    
    //登录面板
    public class LoginPanel extends JPanel {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
 
        public LoginPanel() {
            loginBtn = new JButton(Res.string().getLogin());
            logoutBtn = new JButton(Res.string().getLogout());
            nameLabel = new JLabel(Res.string().getUserName());
            passwordLabel = new JLabel(Res.string().getPassword());
            nameTextArea = new JTextField(m_strUser, 8);
            passwordTextArea = new JPasswordField(m_strPassword, 8);
            ipLabel = new JLabel(Res.string().getIp());
            portLabel = new JLabel(Res.string().getPort());
            ipTextArea = new JTextField(m_strIp, 16);
            portTextArea = new JTextField(m_nPort.toString(), 8);
 
            setLayout(new FlowLayout());
            setBorderEx(this, Res.string().getLogin(), 2);
            
            add(ipLabel);
            add(ipTextArea);
            add(portLabel);
            add(portTextArea);
            add(nameLabel);
            add(nameTextArea);
            add(passwordLabel);
            add(passwordTextArea);
            add(loginBtn);
            add(logoutBtn);
            
            logoutBtn.setEnabled(false);
            
            //登录按钮,监听事件
            loginBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new SDKEnvironment().init();
                    loginButtonPerformed(e);
                }
            });
            
            //登出按钮,监听事件
            logoutBtn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e) {
                    logoutButtonPerformed(e);
                }
            });
        }
    }
        
    //允许名单操作面板
    public class TrafficPanel extends JPanel {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
 
        public TrafficPanel() {
            setBorderEx(this,Res.string().getAllowlistOperation(), 4);
            Dimension dim = this.getPreferredSize();
            dim.width = 300;
            this.setPreferredSize(dim);    
            
            SinglePanel singlePanel = new SinglePanel();
            BatchPanel batchPanel = new BatchPanel();
            setLayout(new BorderLayout());
            add(singlePanel, BorderLayout.NORTH);
            add(batchPanel, BorderLayout.SOUTH);
        }
    }
    
    // 单个上传面板
    public class SinglePanel extends JPanel {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
 
        public SinglePanel(){
            setBorderEx(this, Res.string().getSingleUpload(), 4);
            Dimension dim = this.getPreferredSize();
            dim.height = 200;
            this.setPreferredSize(dim);
            setLayout(new GridLayout(4, 2, 30, 20));
 
            numLabel = new JLabel( Res.string().getLicensePlateRun());
            numTextArea = new JTextField("");
        //    queryBtn = new JButton("查询");
            queryExBtn = new JButton(Res.string().getFuzzyQuery());
            addBtn = new JButton(Res.string().getAdd());
            deleteBtn = new JButton(Res.string().getDelete());
            modifyBtn = new JButton(Res.string().getModify());
            alldeleteBtn = new JButton(Res.string().getDeleteAll());
            
        //    queryBtn.setEnabled(false);
            queryExBtn.setEnabled(false);
            addBtn.setEnabled(false);
            deleteBtn.setEnabled(false);
            modifyBtn.setEnabled(false);
            alldeleteBtn.setEnabled(false);
            
            add(numLabel);
            add(numTextArea);
        //    add(queryBtn);
            add(queryExBtn);
            add(addBtn);
            add(deleteBtn);
            add(modifyBtn);
            add(alldeleteBtn);
            
        /*    queryBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {            
                    DefaultTableModel model = (DefaultTableModel)table.getModel();
                    model.setRowCount(0);  // 在模糊查询前,清空表格
                    data = new Object[200][6];  // 再重设表格,
                    query();
                }
            });*/
            queryExBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    DefaultTableModel model = (DefaultTableModel)table.getModel();
                    model.setRowCount(0);  // 在模糊查询前,清空表格
                    data = new Object[200][6];  // 再重设表格,
                    queryEx();
                }
            });
            addBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    new AddFrame();
                }                    
            });
            deleteBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int rowCount = table.getSelectedRowCount();
                    if(rowCount > 0) {
                        deleteOperate();
                        int row = table.getSelectedRow();
                        DefaultTableModel model = (DefaultTableModel)table.getModel();
                        model.removeRow(row);   // 删除选中的行
                        data = new Object[200][6];  // 再重设表格,
                    }    else {
 
                        JOptionPane.showMessageDialog(null, Res.string().getSelectData());
                    }
                }
            });
            modifyBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    int rowCount = table.getSelectedRowCount();
                    if(rowCount > 0) {
                        new ModifyFrame();
                        int row = table.getSelectedRow(); //获得所选的单行
                        nullTextArea31.setText(String.valueOf(model.getValueAt(row, 1)));
                        nullTextArea41.setText(String.valueOf(model.getValueAt(row, 2)));
                        startTextArea1.setText(String.valueOf(model.getValueAt(row, 3)));
                        endTextArea1.setText(String.valueOf(model.getValueAt(row, 4)));
                        if((model.getValueAt(row, 5)).equals(Res.string().getAuthorization())) {
                            jr1.setSelected(true);
                        } else {
                            jr1.setSelected(false);
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, Res.string().getSelectData());
                    }
                }
            });
            alldeleteBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {        
                    alldeleteOperate();
                }
            });
        }
    }
    
    // 批量上传面板
    public class BatchPanel extends JPanel {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
 
        public BatchPanel() {
            setBorderEx(this, Res.string().getBatchUpload(), 4);
            Dimension dim = this.getPreferredSize();
            dim.height = 150;
            this.setPreferredSize(dim);
            setLayout(new GridLayout(3, 2, 30, 20));
            
            browseTextArea = new JTextField();
            browseBtn = new JButton(Res.string().getBrowse());
            nullLabel1 = new JLabel("");
            upLoadBtn = new JButton(Res.string().getUpload());
            nullLabel2 = new JLabel("");
 
            browseTextArea.setEditable(false);
            browseBtn.setEnabled(false);
            upLoadBtn.setEnabled(false);
 
            add(browseTextArea);
            add(browseBtn);
            add(nullLabel1);
            add(upLoadBtn);
            add(nullLabel2);
 
            final File[] file = new File[1];
            browseBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    jfc = new JFileChooser();
                    jfc.setMultiSelectionEnabled(true); //可以拖选多个文件
                    jfc.setAcceptAllFileFilterUsed(false); //关掉显示所有
                    //添加过滤器
                    jfc.addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {
                        public boolean accept(File f) {
                            if(f.getName().endsWith(".CSV")||f.isDirectory()) {
                                file[0] =f;
                                return true;
                            }
                            return false;
                        }
                        public String getDescription() {
                            return ".CSV";
                        }
                    });
                    if(jfc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
                        System.out.println(jfc.getSelectedFile().getAbsolutePath());
                        browseTextArea.setText(jfc.getSelectedFile().getAbsolutePath());
                    } 
                }
            });
 
            upLoadBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
 
                    if(browseTextArea.getText().isEmpty()){
                        
                    }else {
 
 
                        String uploading = Res.string().getUploading();
                        upLoadBtn.setLabel(uploading);
                        JOptionPane jOptionPane=new JOptionPane();
                                if(uploading.equals("uploading")){
                                    jOptionPane.setDefaultLocale(ENGLISH);
                                }
 
                    if(    jOptionPane.showConfirmDialog(null, Res.string().getSureUpload())==JOptionPane.OK_OPTION){
                        upLoad();
                    }
 
                        upLoadBtn.setLabel(Res.string().getUpload());
                    }
                }
            });
        }
    }
    
    // 查询显示 面板
    public class QueryViewPanel extends JPanel {
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
 
        public QueryViewPanel() {
            setBorderEx(this, Res.string().getQueryInformation() , 4);
            setLayout(new BorderLayout());
            
            // 在JTable列表里添加一个模版,信息存在模版里
            data = new Object[200][6];
            model = new DefaultTableModel(data, name);
            table = new JTable(model);
            
            // 设置某列的宽度
            table.getColumnModel().getColumn(0).setPreferredWidth(40);
            table.getColumnModel().getColumn(3).setPreferredWidth(120);
            table.getColumnModel().getColumn(4).setPreferredWidth(120);
            table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);  // 只能选中一行        
 
            // 建立滑动面板,并插入列表
            JScrollPane scrollPane = new JScrollPane(table);
            add(scrollPane, BorderLayout.CENTER);
        }
    }
 
    //添加按钮窗口    
    public class AddFrame extends Frame{
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        public AddFrame(){
            setTitle(Res.string().getDialog());
            setSize(450, 450);
            setLocationRelativeTo(null);
            setVisible(true);
            setLayout(new BorderLayout());
            DialogPanel dialogPanel = new DialogPanel();
            add(dialogPanel, BorderLayout.CENTER);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e){
                    dispose();
                }
            });
        }
        public class DialogPanel extends JPanel{
            /**
             * 
             */
            private static final long serialVersionUID = 1L;
 
            public DialogPanel() {
                setBorderEx(this, Res.string().getAdd(), 4);
                Dimension dim = this.getPreferredSize();
                dim.height = 400;
                dim.width = 400;
                this.setPreferredSize(dim);
                setLayout(new GridLayout(3, 1));
                JPanel jp11 = new JPanel();
                JPanel jp1 = new JPanel();
                JPanel jp2 = new JPanel();
                JPanel jp3 = new JPanel();
                
                numberLabel = new JLabel(Res.string().getLicensePlateNumber());
                String[] str;
                if(Res.string().getLicensePlateNumber().equals("license plate number")){
                    str= new String[]{"jing", "jin", "ji"};
                }else {
                    //下拉菜单设置选项
                    str = new String[]{"京", "津", "冀", "晋", "内蒙古", "辽", "吉", "黑", "沪", "鲁", "苏", "浙", "皖", "闽", "赣", "豫", "鄂", "湘",
                            "粤", "桂", "琼", "渝", "川", "贵", "云", "藏", "陕", "甘", "青", "宁", "新", "港", "澳", "台"};
                }
 
                /*ComboBoxModel jComboBoxModel = new DefaultComboBoxModel(str);
                jComboBox.setModel(jComboBoxModel);*/
                jComboBox = new JComboBox(str);    
                jComboBox.setPreferredSize(new Dimension(100, 25));  // 设置宽度
                
                nullTextArea3 = new JTextField(8);
                userLabel = new JLabel(Res.string().getCarOwner());
                nullTextArea4 = new JTextField(8);
                startTime = new JLabel(Res.string().getStartTime());
                startTextArea = new JTextField("2021/11/1 6:07:07");
                stopTime = new JLabel(Res.string().getEndTime());
                endTextArea = new JTextField("2021/11/1 8:08:07");
                
                jr = new JRadioButton(Res.string().getAuthorization());
                jr.setSelected(true);
                okBtn = new JButton(Res.string().getConfirm());
                cancleBtn = new JButton(Res.string().getCancel());
                
                jp11.setLayout(new FlowLayout(FlowLayout.CENTER));
                jp11.add(jComboBox);
                jp11.add(nullTextArea3);
                
                jp1.setLayout(new GridLayout(4, 2, 1, 8));
                jp1.add(numberLabel);
                jp1.add(jp11);
                jp1.add(userLabel);
                jp1.add(nullTextArea4);
                jp1.add(startTime);
                jp1.add(startTextArea);
                
                jp1.add(stopTime);
                jp1.add(endTextArea);
                
                jp2.setLayout(new FlowLayout(FlowLayout.CENTER));
                jp2.add(jr);
                
                jp3.setLayout(new FlowLayout(FlowLayout.CENTER));
                jp3.add(okBtn);
                jp3.add(cancleBtn);
                                
                add(jp1);
                add(jp2);
                add(jp3);
                
                okBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        if(jr.isSelected()) {
                            pstRecordAdd.stAuthrityTypes[0].emAuthorityType = NetSDKLib.EM_NET_AUTHORITY_TYPE.NET_AUTHORITY_OPEN_GATE;
                            pstRecordAdd.stAuthrityTypes[0].bAuthorityEnable = 1;    
                        } else {
                            pstRecordAdd.stAuthrityTypes[0].emAuthorityType = NetSDKLib.EM_NET_AUTHORITY_TYPE.NET_AUTHORITY_OPEN_GATE;
                            pstRecordAdd.stAuthrityTypes[0].bAuthorityEnable = 0;    
                        }
                        addOperate();
                        dispose();
                    }
                });
                
                cancleBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dispose();
                    }
                });                        
            }         
        }         
    }
    // 修改按钮窗口    
    public class ModifyFrame extends Frame{
        /**
         * 
         */
        private static final long serialVersionUID = 1L;
        public ModifyFrame(){
            setTitle(Res.string().getModifyPanel());
            setSize(450, 350);
            setLocationRelativeTo(null);
            setVisible(true);
            setLayout(new BorderLayout());
            ModifyPanel modifyPanel = new ModifyPanel();
            add(modifyPanel, BorderLayout.CENTER);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e){
                    dispose();
                }
            });
        }
        public class ModifyPanel extends JPanel{
            /**
             * 
             */
            private static final long serialVersionUID = 1L;
 
            public ModifyPanel() {
                setBorderEx(this, Res.string().getModify(), 3);
                Dimension dim = this.getPreferredSize();
                dim.height = 450;
                dim.width = 350;
 
                this.setPreferredSize(dim);
                setLayout(new GridLayout(3, 1,2,2));
                JPanel jp111 = new JPanel();
                JPanel jp11 = new JPanel();
                JPanel jp21 = new JPanel();
                JPanel jp31 = new JPanel();
                
                numberLabel1 = new JLabel(Res.string().getLicensePlateNumber());
                nullTextArea31 = new JTextField(33);
                nullTextArea31.setEditable(true);
                userLabel1 = new JLabel(Res.string().getCarOwner());
                nullTextArea41 = new JTextField(8);
                startTime1 = new JLabel(Res.string().getStartTime());
                startTextArea1 = new JTextField("2021/11/1 6:07:07");
                stopTime1 = new JLabel(Res.string().getEndTime());
                endTextArea1 = new JTextField("2021/11/1 8:08:07");
                
                jr1 = new JRadioButton(Res.string().getAuthorization());
                okBtn1 = new JButton(Res.string().getConfirm());
                cancleBtn1 = new JButton(Res.string().getCancel());
                
                jp111.setLayout(new FlowLayout(FlowLayout.CENTER));
                jp111.add(nullTextArea31);
                
                jp11.setLayout(new GridLayout(4, 2, 1, 1));
 
                jp11.add(numberLabel1);
                jp11.add(jp111);
                jp11.add(userLabel1);
                jp11.add(nullTextArea41);
                jp11.add(startTime1);
                jp11.add(startTextArea1);
                
                jp11.add(stopTime1);
                jp11.add(endTextArea1);
                
                jp21.setLayout(new FlowLayout(FlowLayout.CENTER));
                jp21.add(jr1);
 
 
                jp31.setLayout(new FlowLayout(FlowLayout.CENTER));
                jp31.add(okBtn1);
                jp31.add(cancleBtn1);
                                
                add(jp11);
                add(jp21);
                add(jp31);
                
                okBtn1.addActionListener(new ActionListener() {
 
 
                    public void actionPerformed(ActionEvent e) {
 
 
 
                        if(jr1.isSelected()) {
                            pstRecordAdd.stAuthrityTypes[0].emAuthorityType = NetSDKLib.EM_NET_AUTHORITY_TYPE.NET_AUTHORITY_OPEN_GATE;
                            pstRecordAdd.stAuthrityTypes[0].bAuthorityEnable = 1;    
                        } else {
                            pstRecordAdd.stAuthrityTypes[0].emAuthorityType = NetSDKLib.EM_NET_AUTHORITY_TYPE.NET_AUTHORITY_OPEN_GATE;
                            pstRecordAdd.stAuthrityTypes[0].bAuthorityEnable = 0;    
                        }
                        modifyOperate();
                        dispose();
                    }
                });
                
                cancleBtn1.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        dispose();
                    }
                });                        
            }         
        }         
    }
    
    ////////////////////事件执行//////////////////////
    ///////////////////////////////////////////////
    //登录按钮事件
    private void loginButtonPerformed(ActionEvent e) {
        m_strIp = ipTextArea.getText();
        m_nPort = Integer.parseInt(portTextArea.getText());    
        m_strUser = nameTextArea.getText();
        m_strPassword = new String(passwordTextArea.getPassword());
        
        System.out.println("设备地址:" + m_strIp + "\n端口号:" + m_nPort 
                + "\n用户名:" + m_strUser + "\n密码:" + m_strPassword);
        
        int nSpecCap = NetSDKLib.EM_LOGIN_SPAC_CAP_TYPE.EM_LOGIN_SPEC_CAP_TCP; //=0
        IntByReference nError = new IntByReference(0);
        m_hLoginHandle = NetSdk.CLIENT_LoginEx2(m_strIp, m_nPort.intValue(), m_strUser, m_strPassword, nSpecCap, null, m_stDeviceInfo, nError);
        if(m_hLoginHandle.longValue() == 0) {
            int error = 0;
            error = NetSdk.CLIENT_GetLastError();
            System.err.printf("Login Device[%s] Port[%d]Failed. Last Error[0x%x]\n", m_strIp, m_nPort, error);
            JOptionPane.showMessageDialog(this, Res.string().getLoginFailed()+":" + String.format("[0x%x]", error));
        } else {
            System.out.println("Login Success [ " + m_strIp + " ]");
            JOptionPane.showMessageDialog(this, Res.string().getLoginSuccess());
            logoutBtn.setEnabled(true);
            loginBtn.setEnabled(false);    
        //    queryBtn.setEnabled(true);
            queryExBtn.setEnabled(true);
            addBtn.setEnabled(true);
            deleteBtn.setEnabled(true);
            modifyBtn.setEnabled(true);
            browseBtn.setEnabled(true);
            upLoadBtn.setEnabled(true);
            alldeleteBtn.setEnabled(true);
        }    
    }
    
    //登出按钮事件
    private void logoutButtonPerformed(ActionEvent e) {
        if(m_hLoginHandle.longValue() != 0) {
            System.out.println("Logout Button Action");
        
            if(NetSdk.CLIENT_Logout(m_hLoginHandle)) {
                System.out.println("Logout Success [ " + m_strIp + " ]");
                m_hLoginHandle.setValue(0);
                logoutBtn.setEnabled(false);
                loginBtn.setEnabled(true);    
        //        queryBtn.setEnabled(false);
                queryExBtn.setEnabled(false);
                addBtn.setEnabled(false);
                deleteBtn.setEnabled(false);
                modifyBtn.setEnabled(false);
                browseBtn.setEnabled(false);
                upLoadBtn.setEnabled(false);
                
            }
        }
    }
    
    // 查询按钮事件
    private void query() {
        // 开始查询记录
        NetSDKLib.NET_IN_FIND_RECORD_PARAM stuFindInParam = new NetSDKLib.NET_IN_FIND_RECORD_PARAM();
        stuFindInParam.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_TRAFFICREDLIST;
        
        NetSDKLib.FIND_RECORD_TRAFFICREDLIST_CONDITION stuRedListCondition = new NetSDKLib.FIND_RECORD_TRAFFICREDLIST_CONDITION();
        stuFindInParam.pQueryCondition = stuRedListCondition.getPointer();
        byte[] numText;
        try {
 
            numText    = numTextArea.getText().trim().getBytes("GBK");
            System.arraycopy(numText, 0, stuRedListCondition.szPlateNumber, 0, numText.length);
        } catch (UnsupportedEncodingException e) {
            System.err.println("字符串转码异常");
        }
 
        
        NetSDKLib.NET_OUT_FIND_RECORD_PARAM stuFindOutParam = new NetSDKLib.NET_OUT_FIND_RECORD_PARAM();
 
        if((numTextArea.getText()).equals("")) {
            JOptionPane.showMessageDialog(this, Res.string().getEnterQueryData());
        }else {
            stuRedListCondition.write();
            boolean bRet = NetSdk.CLIENT_FindRecord(m_hLoginHandle, stuFindInParam, stuFindOutParam, 5000);
            stuRedListCondition.read();
            System.out.println("FindRecord Succeed" + "\n" + "FindHandle :" + stuFindOutParam.lFindeHandle);
            if(bRet) {
                int nRecordCount = 10;
                NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM stuFindNextInParam = new NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM();
                stuFindNextInParam.lFindeHandle = stuFindOutParam.lFindeHandle;
                stuFindNextInParam.nFileCount = nRecordCount;  //想查询的记录条数
                
                NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM stuFindNextOutParam = new NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM();
                stuFindNextOutParam.nMaxRecordNum = nRecordCount;
                NetSDKLib.NET_TRAFFIC_LIST_RECORD pstRecord = new NetSDKLib.NET_TRAFFIC_LIST_RECORD();
                stuFindNextOutParam.pRecordList = pstRecord.getPointer();
 
                pstRecord.write();
                boolean zRet = NetSdk.CLIENT_FindNextRecord(stuFindNextInParam, stuFindNextOutParam, 5000);
                pstRecord.read();
                
                if(zRet) {        
                    System.out.println("record are found!");
                    
                    for(int i=0; i < stuFindNextOutParam.nRetRecordNum; i++) {
                        data[i][0] = String.valueOf(i);
                        try {
                            data[i][1] = new String(pstRecord.szPlateNumber,"GBK").trim();
                            data[i][2] = new String(pstRecord.szMasterOfCar,"GBK").trim();
                            data[i][3] = pstRecord.stBeginTime.toStringTime();
                            data[i][4] = pstRecord.stCancelTime.toStringTime();
                        } catch (UnsupportedEncodingException e) {
                            System.err.println("字符串转码异常");
                        }
 
                        if(pstRecord.stAuthrityTypes[0].bAuthorityEnable == 1) {
                            data[i][5] = "授权";
                        } else {
                            data[i][5] = "不授权";
                        }
                        model.setDataVector(data, name);
                    }                
                } 
                
                NetSdk.CLIENT_FindRecordClose(stuFindOutParam.lFindeHandle);      
            }else {
                System.err.println("Can Not Find This Record" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));                    
            }
        }            
    }
    public static void ByteArrZero(byte[] dst) {
        // 清零
        for (int i = 0; i < dst.length; ++i) {
            dst[i] = 0;
        }
    }
    // 模糊查询按钮事件
        private   void queryEx() {
 
        NetSDKLib.NET_IN_FIND_RECORD_PARAM stuFindInParam = new NetSDKLib.NET_IN_FIND_RECORD_PARAM();
        stuFindInParam.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_TRAFFICREDLIST;
        
        NetSDKLib.FIND_RECORD_TRAFFICREDLIST_CONDITION stuRedListConditionEx = new NetSDKLib.FIND_RECORD_TRAFFICREDLIST_CONDITION();
        stuFindInParam.pQueryCondition = stuRedListConditionEx.getPointer();
        JNATrafficListFrame.ByteArrZero(stuRedListConditionEx.szPlateNumberVague);
 
        try {
            byte[] numText = numTextArea.getText().trim().getBytes("GBK");
 
            System.arraycopy(numText, 0, stuRedListConditionEx.szPlateNumberVague, 0, numText.length);
        } catch (UnsupportedEncodingException e) {
            System.err.println("字符串转码异常");
        }
 
        
        NetSDKLib.NET_OUT_FIND_RECORD_PARAM stuFindOutParam = new NetSDKLib.NET_OUT_FIND_RECORD_PARAM();
        
        stuRedListConditionEx.write(); 
        boolean bRet = NetSdk.CLIENT_FindRecord(m_hLoginHandle, stuFindInParam, stuFindOutParam, 10000);
        stuRedListConditionEx.read();
            int total=0;
        if(bRet) {
            int doNextCount = 0;
            while(true) {
                int nRecordCount = 10;
                NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM stuFindNextInParam = new NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM();
                stuFindNextInParam.lFindeHandle = stuFindOutParam.lFindeHandle;
                stuFindNextInParam.nFileCount = nRecordCount;
                
                NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM stuFindNextOutParam = new NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM();
                stuFindNextOutParam.nMaxRecordNum = nRecordCount;
                NetSDKLib.NET_TRAFFIC_LIST_RECORD pstRecordEx = new NetSDKLib.NET_TRAFFIC_LIST_RECORD();
                stuFindNextOutParam.pRecordList = new Memory(pstRecordEx.dwSize * nRecordCount);   //分配(stRecordEx.dwSize * nRecordCount)个内存
 
 
                // 把内存里的dwSize赋值
                for (int i=0; i<stuFindNextOutParam.nMaxRecordNum; ++i)
                {
                    ToolKits.SetStructDataToPointer(pstRecordEx, stuFindNextOutParam.pRecordList, i*pstRecordEx.dwSize);
                }
                
                pstRecordEx.write();
                boolean zRet = NetSdk.CLIENT_FindNextRecord(stuFindNextInParam, stuFindNextOutParam, 10000);
                pstRecordEx.read();
 
                int jnumber=stuFindNextOutParam.nRetRecordNum;
 
                if(zRet) {
 
                    for(int i=0; i < jnumber; i++) {
                        int item = i + doNextCount * nRecordCount;
                        total=item+1;
                        if(item>data.length-1){
 
                            continue;
                        }
                        data[item][0] = String.valueOf(item);
                        ToolKits.GetPointerDataToStruct(stuFindNextOutParam.pRecordList, i*pstRecordEx.dwSize, pstRecordEx);
                        try {
                            data[item][1] = new String(pstRecordEx.szPlateNumber,"GBK").trim();
                            data[item][2] = new String(pstRecordEx.szMasterOfCar,"GBK").trim();
                            data[item][3] = pstRecordEx.stBeginTime.toStringTime();
                            data[item][4] = pstRecordEx.stCancelTime.toStringTime();
                        } catch (UnsupportedEncodingException e) {
                            System.err.println("字符串转码异常");
                        }
 
                        if(pstRecordEx.stAuthrityTypes[0].bAuthorityEnable == 1) {
                            data[item][5] = Res.string().getAuthorization();
                        } else {
                            data[item][5] =Res.string().getUnauthorization();
                        }
 
                        model.setDataVector(data, name);
 
                    }
                    
                    if (stuFindNextOutParam.nRetRecordNum < nRecordCount)
                    {
                        break;
                    } else {
                        doNextCount ++;
                    }
                } else {
                    break;
                }
            }
            NetSdk.CLIENT_FindRecordClose(stuFindOutParam.lFindeHandle);
 
            JOptionPane.showMessageDialog(this, total+" "+Res.string().getDataNumber());
 
        }else {
            System.err.println("Can Not Find This Record" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));
        }
    }
    
    // 添加按钮事件
    private void addOperate() {
        NetSDKLib.NET_INSERT_RECORD_INFO stInsertInfo = new NetSDKLib.NET_INSERT_RECORD_INFO();  // 添加
        
        NetSDKLib.NET_TRAFFIC_LIST_RECORD.ByReference stRec = new NetSDKLib.NET_TRAFFIC_LIST_RECORD.ByReference();
 
 
        try {
 
            String plate = nullTextArea3.getText();
 
            boolean matches = plate.matches("^[\\da-zA-Z]*$");
 
            if(!matches){
                JOptionPane.showMessageDialog(this, Res.string().getFillingRules());
                return;
            }
 
            byte[] PlateNumber
                    = (jComboBox.getSelectedItem().toString() + plate).getBytes("GBK");
 
            if(PlateNumber.length>NET_MAX_PLATE_NUMBER_LEN){
                JOptionPane.showMessageDialog(this, Res.string().getLicensePlateLengthTooLong());
 
                return;
            }
 
            byte[] MasterOfCar = nullTextArea4.getText().getBytes("GBK");
 
            if(MasterOfCar.length>NET_MAX_NAME_LEN){
                JOptionPane.showMessageDialog(this, Res.string().getNameTooLong());
                return;
            }
 
            stRec.szPlateNumber =PlateNumber;
            stRec.szMasterOfCar = MasterOfCar;
        } catch (UnsupportedEncodingException e) {
            System.err.println("字符串转码异常");
        }
 
        String[] start = startTextArea.getText().split(" ");
        String st1 = start[0];
        String st2 = start[1];
        String[] start1 = st1.split("/"); //年月日
        String[] start2 = st2.split(":"); // 时分
        String[] end = endTextArea.getText().split(" ");
        String ed1 = end[0];
        String ed2 = end[1];
        String[] end1 = ed1.split("/"); //年月日
        String[] end2 = ed2.split(":"); // 时分
        stRec.stBeginTime.dwYear = Integer.parseInt(start1[0]);
        stRec.stBeginTime.dwMonth = Integer.parseInt(start1[1]);
        stRec.stBeginTime.dwDay = Integer.parseInt(start1[2]);
        stRec.stBeginTime.dwHour = Integer.parseInt(start2[0]);
        stRec.stBeginTime.dwMinute = Integer.parseInt(start2[1]);
        stRec.stBeginTime.dwSecond = Integer.parseInt(start2[2]);
        stRec.stCancelTime.dwYear = Integer.parseInt(end1[0]);
        stRec.stCancelTime.dwMonth = Integer.parseInt(end1[1]);
        stRec.stCancelTime.dwDay = Integer.parseInt(end1[2]);
        stRec.stCancelTime.dwHour = Integer.parseInt(end2[0]);
        stRec.stCancelTime.dwMinute = Integer.parseInt(end2[1]);
        stRec.stCancelTime.dwSecond = Integer.parseInt(end2[2]);
        stRec.nAuthrityNum = 1;
        stRec.stAuthrityTypes[0].emAuthorityType = pstRecordAdd.stAuthrityTypes[0].emAuthorityType;
        stRec.stAuthrityTypes[0].bAuthorityEnable = pstRecordAdd.stAuthrityTypes[0].bAuthorityEnable;
        
        stInsertInfo.pRecordInfo = stRec;
 
        NetSDKLib.NET_IN_OPERATE_TRAFFIC_LIST_RECORD stInParam = new NetSDKLib.NET_IN_OPERATE_TRAFFIC_LIST_RECORD();
        stInParam.emOperateType = NetSDKLib.EM_RECORD_OPERATE_TYPE.NET_TRAFFIC_LIST_INSERT;
        stInParam.emRecordType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_TRAFFICREDLIST;
        stInParam.pstOpreateInfo = stInsertInfo.getPointer();
    
        NetSDKLib.NET_OUT_OPERATE_TRAFFIC_LIST_RECORD stOutParam = new NetSDKLib.NET_OUT_OPERATE_TRAFFIC_LIST_RECORD();
        stRec.write();
        stInsertInfo.write();
        stInParam.write();
 
        boolean zRet = NetSdk.CLIENT_OperateTrafficList(m_hLoginHandle, stInParam, stOutParam, 5000);
        if(zRet) {
            stInParam.read();
            System.out.println("succeed!");
            JOptionPane.showMessageDialog(this, Res.string().getAddSuccess());
        } else {
            System.err.println("failed!" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));
            JOptionPane.showMessageDialog(this, Res.string().getAddFail());
        }
    }
 
    // 查询之前的记录号
    private void findRecordCount() {
        // 开始查询记录
        NetSDKLib.NET_IN_FIND_RECORD_PARAM stuFindInParam = new NetSDKLib.NET_IN_FIND_RECORD_PARAM();
        stuFindInParam.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_TRAFFICREDLIST;
        NetSDKLib.FIND_RECORD_TRAFFICREDLIST_CONDITION stuRedListCondition = new NetSDKLib.FIND_RECORD_TRAFFICREDLIST_CONDITION();
        stuFindInParam.pQueryCondition = stuRedListCondition.getPointer();
        // 获取选中行的车牌号,并赋值
        int row = table.getSelectedRow();
        try {
            System.arraycopy(String.valueOf(model.getValueAt(row, 1)).getBytes("GBK"), 0, stuRedListCondition.szPlateNumber,
                    0, String.valueOf(model.getValueAt(row, 1)).getBytes("GBK").length);
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
 
        NetSDKLib.NET_OUT_FIND_RECORD_PARAM stuFindOutParam = new NetSDKLib.NET_OUT_FIND_RECORD_PARAM();
 
        stuFindInParam.write();
        stuRedListCondition.write();
        boolean bRet = NetSdk.CLIENT_FindRecord(m_hLoginHandle, stuFindInParam, stuFindOutParam, 5000);
        stuRedListCondition.read();
        stuFindInParam.read();
 
        if(bRet){
            int nRecordCount = 1;
 
            NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM stuFindNextInParam = new NetSDKLib.NET_IN_FIND_NEXT_RECORD_PARAM();
            stuFindNextInParam.lFindeHandle = stuFindOutParam.lFindeHandle;
            stuFindNextInParam.nFileCount = nRecordCount;  //想查询的记录条数
 
            NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM stuFindNextOutParam = new NetSDKLib.NET_OUT_FIND_NEXT_RECORD_PARAM();
            stuFindNextOutParam.nMaxRecordNum = nRecordCount;
            NetSDKLib.NET_TRAFFIC_LIST_RECORD pstRecord = new NetSDKLib.NET_TRAFFIC_LIST_RECORD();
            stuFindNextOutParam.pRecordList = pstRecord.getPointer();
 
            stuFindNextInParam.write();
            stuFindNextOutParam.write();
            pstRecord.write();
            boolean zRet = NetSdk.CLIENT_FindNextRecord(stuFindNextInParam, stuFindNextOutParam, 5000);
            pstRecord.read();
            stuFindNextInParam.read();
            stuFindNextOutParam.read();
 
            if(zRet) {
                // 获取当前记录号
                nNo = pstRecord.nRecordNo;
            }
            // 停止查询
            NetSdk.CLIENT_FindRecordClose(stuFindOutParam.lFindeHandle);
        } else {
            System.err.println("error occured!" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));
        }
    }
    
    // 删除按钮事件
    private void deleteOperate() {
 
        findRecordCount();
            
        // 获得之前查询到的记录号后,开始删除数据
        NetSDKLib.NET_REMOVE_RECORD_INFO stRemoveInfo = new NetSDKLib.NET_REMOVE_RECORD_INFO();
 
        stRemoveInfo.nRecordNo = nNo;
        System.out.println("nNo:"+nNo);
        NetSDKLib.NET_IN_OPERATE_TRAFFIC_LIST_RECORD stInParam = new NetSDKLib.NET_IN_OPERATE_TRAFFIC_LIST_RECORD();
        stInParam.emOperateType = NetSDKLib.EM_RECORD_OPERATE_TYPE.NET_TRAFFIC_LIST_REMOVE;
        stInParam.emRecordType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_TRAFFICREDLIST;;
        stInParam.pstOpreateInfo = stRemoveInfo.getPointer();
        NetSDKLib.NET_OUT_OPERATE_TRAFFIC_LIST_RECORD stOutParam = new NetSDKLib.NET_OUT_OPERATE_TRAFFIC_LIST_RECORD();
        
        stInParam.write();
        stRemoveInfo.write();
        boolean zRet = NetSdk.CLIENT_OperateTrafficList(m_hLoginHandle, stInParam, stOutParam, 5000);
 
        if(zRet) {
            System.out.println("delete  succeed!");
            JOptionPane.showMessageDialog(this, Res.string().getDeleteSuccess());
        } else {
            JOptionPane.showMessageDialog(this, Res.string().getDeleteFail());
            System.err.println("failed!" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));
        }    
    }
 
    // 修改按钮事件
    private void modifyOperate() {
 
 
        findRecordCount();
 
        NetSDKLib.NET_TRAFFIC_LIST_RECORD.ByReference stRec = new NetSDKLib.NET_TRAFFIC_LIST_RECORD.ByReference();
        try {
 
            stRec.szPlateNumber =  nullTextArea31.getText().getBytes("GBK");
            stRec.szMasterOfCar = nullTextArea41.getText().getBytes("GBK");
 
            if(    stRec.szPlateNumber.length>NET_MAX_PLATE_NUMBER_LEN-1){
                JOptionPane.showMessageDialog(this, Res.string().getLicensePlateLengthTooLong());
                return;
            }
 
 
            if(stRec.szMasterOfCar.length>NET_MAX_NAME_LEN){
                JOptionPane.showMessageDialog(this, Res.string().getNameTooLong());
                return;
            }
        } catch (UnsupportedEncodingException e) {
            System.err.println("字符串转码异常");
        }
 
 
 
        String[] start = startTextArea1.getText().split(" ");
        String st1 = start[0];
        String st2 = start[1];
        String[] start1 = st1.split("/"); //年月日
        String[] start2 = st2.split(":"); // 时分
        String[] end = endTextArea1.getText().split(" ");
        String ed1 = end[0];
        String ed2 = end[1];
        String[] end1 = ed1.split("/"); //年月日
        String[] end2 = ed2.split(":"); // 时分
        stRec.stBeginTime.dwYear = Integer.parseInt(start1[0]);
        stRec.stBeginTime.dwMonth = Integer.parseInt(start1[1]);
        stRec.stBeginTime.dwDay = Integer.parseInt(start1[2]);
        stRec.stBeginTime.dwHour = Integer.parseInt(start2[0]);
        stRec.stBeginTime.dwMinute = Integer.parseInt(start2[1]);
        stRec.stBeginTime.dwSecond = Integer.parseInt(start2[2]);
        stRec.stCancelTime.dwYear = Integer.parseInt(end1[0]);
        stRec.stCancelTime.dwMonth = Integer.parseInt(end1[1]);
        stRec.stCancelTime.dwDay = Integer.parseInt(end1[2]);
        stRec.stCancelTime.dwHour = Integer.parseInt(end2[0]);
        stRec.stCancelTime.dwMinute = Integer.parseInt(end2[1]);    
        stRec.stCancelTime.dwSecond = Integer.parseInt(end2[2]);
        stRec.nAuthrityNum = 1;
        stRec.stAuthrityTypes[0].emAuthorityType = pstRecordAdd.stAuthrityTypes[0].emAuthorityType;
        stRec.stAuthrityTypes[0].bAuthorityEnable = pstRecordAdd.stAuthrityTypes[0].bAuthorityEnable;
                
        stRec.nRecordNo = nNo;
 
        NetSDKLib.NET_UPDATE_RECORD_INFO stUpdateInfo = new NetSDKLib.NET_UPDATE_RECORD_INFO();
        stUpdateInfo.pRecordInfo = stRec;
        
        NetSDKLib.NET_IN_OPERATE_TRAFFIC_LIST_RECORD stInParam = new NetSDKLib.NET_IN_OPERATE_TRAFFIC_LIST_RECORD();
        stInParam.emOperateType = NetSDKLib.EM_RECORD_OPERATE_TYPE.NET_TRAFFIC_LIST_UPDATE;
        stInParam.emRecordType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_TRAFFICREDLIST;
        stInParam.pstOpreateInfo = stUpdateInfo.getPointer();
        NetSDKLib.NET_OUT_OPERATE_TRAFFIC_LIST_RECORD stOutParam = new NetSDKLib.NET_OUT_OPERATE_TRAFFIC_LIST_RECORD();
 
        stRec.write();
        stUpdateInfo.write();
        stInParam.write();
        boolean zRet = NetSdk.CLIENT_OperateTrafficList(m_hLoginHandle, stInParam, stOutParam, 5000);
        if(zRet) {
            System.out.println("succeed!");
            System.out.println("stOutParam:"+stOutParam.nRecordNo);
            JOptionPane.showMessageDialog(this, Res.string().getModifySuccess());
        } else {
            JOptionPane.showMessageDialog(this, Res.string().getModifyFail());
 
            System.err.println("failed!" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));
        }
    }
    
    // 全部删除
    private void alldeleteOperate() {
        int type = NetSDKLib.CtrlType.CTRLTYPE_CTRL_RECORDSET_CLEAR;
        NetSDKLib.NET_CTRL_RECORDSET_PARAM param = new NetSDKLib.NET_CTRL_RECORDSET_PARAM();
        param.emType = NetSDKLib.EM_NET_RECORD_TYPE.NET_RECORD_TRAFFICREDLIST;
        param.write();
        boolean zRet = NetSdk.CLIENT_ControlDevice(m_hLoginHandle, type, param.getPointer(), 5000);
        if(zRet) {
            System.out.println("全部删除成功");
            JOptionPane.showMessageDialog(this, Res.string().getDeleteSuccess());
        } else {
            System.err.println("全部删除失败");
            JOptionPane.showMessageDialog(this, Res.string().getDeleteFail());
        }
    }
    
    // 上传按钮事件      注:上传*.CSV的文件,文件的数据会覆盖原数据库的数据,所以可以从数据库导出文件,并在文件里添加数据后,再上传
    private void upLoad() {
 
 
        JOptionPane jOptionPane=new JOptionPane();
 
        NetSDKLib.NETDEV_BLACKWHITE_LIST_INFO stIn = new NetSDKLib.NETDEV_BLACKWHITE_LIST_INFO();
        Pointer szInBuf = stIn.getPointer();
        int nInBufLen = stIn.size();
        try {
            stIn.szFile = jfc.getSelectedFile().getAbsolutePath().getBytes("GBK");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        stIn.nFileSize = 1024*1024*3;  // 升级文件大小
        stIn.byFileType = 1; //当前文件类型,0-禁止名单,1-允许名单
        stIn.byAction = 0; //动作,0-覆盖,1-追加
        stIn.write();
        LLong zRet = NetSdk.CLIENT_FileTransmit(m_hLoginHandle, NetSDKLib.NET_DEV_BLACKWHITETRANS_START, szInBuf, nInBufLen, TransFileCall.getInstance(), null, 5000);
 
 
        stIn.read();
        if(zRet.longValue() == 0) {
            System.err.println("Start failed!" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));
 
            String    type=Res.string().getUploadFail();
            jOptionPane.showMessageDialog( this, type);
 
            return;
        }
 
        stIn.write();
        LongByReference handleReference = new LongByReference(zRet.longValue());   //LLong转为Pointer*
        LLong zRet1 = NetSdk.CLIENT_FileTransmit(m_hLoginHandle, NetSDKLib.NET_DEV_BLACKWHITETRANS_SEND, handleReference.getPointer(), nInBufLen, TransFileCall.getInstance(), null, 20000);
        stIn.read();
        if(zRet1.longValue() == 0) {
            System.err.println("Send failed!" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));
 
            String    type=Res.string().getUploadFail();
            jOptionPane.showMessageDialog( this, type);
        }else {
 
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            stIn.write();
            LLong zRet2 = NetSdk.CLIENT_FileTransmit(m_hLoginHandle, NetSDKLib.NET_DEV_BLACKWHITETRANS_STOP,  handleReference.getPointer(), nInBufLen, TransFileCall.getInstance(), null, 5000);
            stIn.read();
            if(zRet2.longValue() == 0) {
 
                System.err.println("Stop failed!" + String.format("0x%x", NetSdk.CLIENT_GetLastError()));
                String    type=Res.string().getUploadFail();
                jOptionPane.showMessageDialog( this, type);
            } else {
 
                String    type=Res.string().getUploadSuccess();
                jOptionPane.showMessageDialog( this, type);
            }
 
        }
 
 
    }
 
    private static class TransFileCall implements NetSDKLib.fTransFileCallBack{
        private static TransFileCall instance;
        public static TransFileCall getInstance() {
            if (instance == null) {
                        instance = new TransFileCall();
            }
            return instance;
        }
 
 
        @Override
        public void invoke(LLong lHandle, int nTransType, int nState, int nSendSize, int nTotalSize, Pointer dwUser) {
            /*    System.out.println("nTransType:"+nTransType);
                System.out.println("nState:"+nState);*/
        }
    }
 
    /////////////////////组件//////////////////////////
    //////////////////////////////////////////////////
 
    //登录组件
    private LoginPanel loginPanel;
    private JButton loginBtn;
    private JButton logoutBtn;
    
    private JLabel numLabel;
    private JTextField numTextArea;
    //private JButton queryBtn;
    private JButton queryExBtn;
    private JButton addBtn;
    private JButton deleteBtn;
    private JButton modifyBtn;
 
    private JTextField browseTextArea;
    private JButton browseBtn;
    private JLabel nullLabel1;
    private JButton upLoadBtn;
    private JLabel nullLabel2;
 
    private JComboBox jComboBox;
    private JLabel numberLabel;
    private JTextField nullTextArea3;
    private JLabel userLabel;
    private JTextField nullTextArea4;
    private JLabel startTime;
    private JTextField startTextArea;
    private JLabel stopTime;
    private JTextField endTextArea;
    private JRadioButton jr;
    private JButton okBtn;
    private JButton cancleBtn;
    private JButton alldeleteBtn;
    
    private JLabel numberLabel1;
    private JTextField nullTextArea31;
    private JLabel userLabel1;
    private JTextField nullTextArea41;
    private JLabel startTime1;
    private JTextField startTextArea1;
    private JLabel stopTime1;
    private JTextField endTextArea1;
    private JRadioButton jr1;
    private JButton okBtn1;
    private JButton cancleBtn1;
 
    private JFileChooser jfc;
    private JLabel ipLabel;
    private JTextField ipTextArea;
    private JLabel nameLabel;
    private JLabel passwordLabel;
    private JLabel portLabel;
    
    private JTextField portTextArea;
    private JTextField nameTextArea;
    private JPasswordField passwordTextArea;    
    
    private DefaultTableModel model;
    private JTable table;
    private Object[][] data;
}
 
 
public class TrafficAllowList {  
    public static void main(String[] args) {    
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JNATrafficListFrame demo = new JNATrafficListFrame();
                demo.setVisible(true);
            }
        });        
    }
}