826220679@qq.com
2025-08-07 4d6cd980c5c69e4d9d150669c89734642297e0cd
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
package dell_suanfa;
import targets.GroupManagement;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.table.*;
import dell_system.Dell_company;
import java.awt.*;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.List;
 
public class GroupManagementPanel extends JPanel {
    private static final long serialVersionUID = 1L;  // ÐòÁл¯°æ±¾ºÅ
    private JTable groupTable;  // Ð¡×é±í¸ñ
    private DefaultTableModel tableModel;  // ±í¸ñÄ£ÐÍ
    private List<GroupManagement> allGroups;  // ËùÓÐС×éÁбí
    private ResourceBundle messages;  // ¹ú¼Ê»¯×ÊÔ´Êø
    private JTextField searchField;  // ËÑË÷Îı¾¿ò
 
    @SuppressWarnings("serial")
    public GroupManagementPanel(ResourceBundle messages) {
        this.messages = messages;  // ³õʼ»¯×ÊÔ´Êø
        setLayout(new BorderLayout());  // ÉèÖñ߽粼¾Ö
        setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));  // ÉèÖÿձ߿ò
        
        // ´´½¨¶¥²¿Ãæ°å
        JPanel topPanel = new JPanel(new BorderLayout(5, 5));  // ´´½¨¶¥²¿Ãæ°å
        topPanel.setBorder(BorderFactory.createTitledBorder(getMessage("GROUP_SETTINGS")));  // ÉèÖôø±êÌâµÄ±ß¿ò
 
        // ´´½¨ËÑË÷ÊäÈëÃæ°å
        JPanel searchInputPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 5, 0));  // ´´½¨ËÑË÷Ãæ°å
        JLabel searchLabel = new JLabel(getMessage("SEARCH") + ":");  // ËÑË÷±êÇ©
        searchField = new JTextField(20);  // ËÑË÷Îı¾¿ò
        JButton searchButton = new JButton(getMessage("SEARCH"));  // ËÑË÷°´Å¥
        JButton resetButton = new JButton(getMessage("RESET"));  // ÖØÖð´Å¥
 
        searchInputPanel.add(searchLabel);  // Ìí¼ÓËÑË÷±êÇ©
        searchInputPanel.add(searchField);  // Ìí¼ÓËÑË÷¿ò
        searchInputPanel.add(searchButton);  // Ìí¼ÓËÑË÷°´Å¥
        searchInputPanel.add(resetButton);  // Ìí¼ÓÖØÖð´Å¥
 
        // ´´½¨²Ù×÷°´Å¥Ãæ°å
        JPanel actionPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 0));  // ´´½¨²Ù×÷Ãæ°å
        JButton addButton = new JButton(getMessage("ADD"));  // Ìí¼Ó°´Å¥
        JButton editButton = new JButton(getMessage("EDIT"));  // ±à¼­°´Å¥
        JButton deleteButton = new JButton(getMessage("DELETE"));  // É¾³ý°´Å¥
        JButton refreshButton = new JButton(getMessage("REFRESH"));  // Ë¢Ð°´Å¥
 
        actionPanel.add(addButton);  // Ìí¼ÓÌí¼Ó°´Å¥
        actionPanel.add(editButton);  // Ìí¼Ó±à¼­°´Å¥
        actionPanel.add(deleteButton);  // Ìí¼Óɾ³ý°´Å¥
        actionPanel.add(refreshButton);  // Ìí¼Óˢа´Å¥
 
        // ½«ËÑË÷ºÍ²Ù×÷Ãæ°åÌí¼Óµ½¶¥²¿Ãæ°å
        topPanel.add(searchInputPanel, BorderLayout.CENTER);  // ËÑË÷Ãæ°å·ÅÔÚÖмä
        topPanel.add(actionPanel, BorderLayout.EAST);  // ²Ù×÷Ãæ°å·ÅÔÚÓÒ±ß
 
        // ´´½¨±í¸ñÁÐÃû
        String[] columnNames = {
            getMessage("INDEX"),  // ÐòºÅ
            getMessage("GROUP_NUMBER"),  // ×é±àºÅ
            getMessage("BELONG_LAYER"),  // ËùÊô²ã
            getMessage("ALGORITHM"),  // Ëã·¨
            getMessage("OUTDOOR_GROUP"),  // ÊÒÍâ×é
            getMessage("MUST_PASS_GROUP"),  // ±Ø¾­×é
            getMessage("CROSS_MULTILAYER"),  // ×é¿ç¶à²ã
            getMessage("GROUP_WIDTH"),  // ×é¿í¶È
            getMessage("VALID_AREA"),  // ÓÐÐ§ÇøÓò
            getMessage("COMPANY"),  // ¹«Ë¾
            getMessage("ADD_TIME"),  // ÐÞ¸ÄΪÖÐÎÄ"Ìí¼Óʱ¼ä"
        };
        
        // ´´½¨±í¸ñÄ£ÐÍ
        tableModel = new DefaultTableModel(columnNames, 0) {  // ³õʼ»¯±í¸ñÄ£ÐÍ
            private static final long serialVersionUID = 1L;  // ÐòÁл¯°æ±¾ºÅ
 
            @Override
            public boolean isCellEditable(int row, int column) {
                return false;  // ËùÓе¥Ôª¸ñ²»¿É±à¼­
            }
        };
        
        // ´´½¨±í¸ñ
        groupTable = new JTable(tableModel);  // ´´½¨±í¸ñ
        groupTable.setAutoCreateRowSorter(true);  // ÆôÓÃÐÐÅÅÐò
        groupTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);  // ÉèÖõ¥Ñ¡Ä£Ê½
        
        // ÉèÖÃÁпí
        TableColumnModel columnModel = groupTable.getColumnModel();  // »ñÈ¡ÁÐÄ£ÐÍ
        columnModel.getColumn(0).setPreferredWidth(50);   // ÐòºÅ
        columnModel.getColumn(1).setPreferredWidth(100);  // ×é±àºÅ
        columnModel.getColumn(2).setPreferredWidth(100);  // ËùÊô²ã
        columnModel.getColumn(3).setPreferredWidth(80);   // Ëã·¨
        columnModel.getColumn(4).setPreferredWidth(80);   // ÊÒÍâ×é
        columnModel.getColumn(5).setPreferredWidth(80);   // ±Ø¾­×é
        columnModel.getColumn(6).setPreferredWidth(100);  // ×é¿ç¶à²ã
        columnModel.getColumn(7).setPreferredWidth(80);   // ×é¿í¶È
        columnModel.getColumn(8).setPreferredWidth(100);  // ÓÐÐ§ÇøÓò
        columnModel.getColumn(9).setPreferredWidth(150);  // ËùÊô¹«Ë¾
        columnModel.getColumn(10).setPreferredWidth(150); // Ìí¼Óʱ¼ä
        
        // ÉèÖñíÍ·Ñùʽ
        JTableHeader header = groupTable.getTableHeader();  // »ñÈ¡±íÍ·
        header.setBackground(Color.GRAY);  // ±³¾°É«
        header.setForeground(Color.WHITE);  // Ç°¾°É«
        header.setFont(header.getFont().deriveFont(Font.BOLD));  // ´ÖÌå
        
        // ´´½¨±íÍ·äÖȾÆ÷
        DefaultTableCellRenderer headerRenderer = new DefaultTableCellRenderer() {
            {
                setHorizontalAlignment(SwingConstants.LEFT);  // ×ó¶ÔÆë
                setBackground(Color.GRAY);  // ±³¾°É«
                setForeground(Color.WHITE);  // Ç°¾°É«
                setFont(getFont().deriveFont(Font.BOLD));  // ´ÖÌå
            }
        };
        
        // Ó¦ÓñíÍ·äÖȾÆ÷
        for (int i = 0; i < groupTable.getColumnCount(); i++) {
            groupTable.getColumnModel().getColumn(i).setHeaderRenderer(headerRenderer);  // ÉèÖÃÿÁеÄäÖȾÆ÷
        }
        
        JScrollPane scrollPane = new JScrollPane(groupTable);  // ´´½¨¹ö¶¯Ãæ°å
        scrollPane.setPreferredSize(new Dimension(1100, 400));  // ÉèÖÃÊ×Ñ¡´óС
        
        // Ìí¼Ó×é¼þµ½Ö÷Ãæ°å
        add(topPanel, BorderLayout.NORTH);  // ¶¥²¿Ãæ°å
        add(scrollPane, BorderLayout.CENTER);  // ±í¸ñÔÚÖмä
        
        // ¼ÓÔØÊý¾Ý
        loadGroupData();  // ¼ÓÔØÐ¡×éÊý¾Ý
        
        // Ìí¼Óʼþ¼àÌýÆ÷
        addButton.addActionListener(e -> addNewGroup());  // Ìí¼Ó°´Å¥Ê¼þ
        editButton.addActionListener(e -> editSelectedGroup());  // ±à¼­°´Å¥Ê¼þ
        deleteButton.addActionListener(e -> deleteSelectedGroups());  // É¾³ý°´Å¥Ê¼þ
        refreshButton.addActionListener(e -> loadGroupData());  // Ë¢Ð°´Å¥Ê¼þ
        searchButton.addActionListener(e -> searchGroups());  // ËÑË÷°´Å¥Ê¼þ
        resetButton.addActionListener(e -> resetSearch());  // ÖØÖð´Å¥Ê¼þ
    }
    
    // ¼ÓÔØÐ¡×éÊý¾Ý
    private void loadGroupData() {
        try {
            allGroups = Dell_GroupManagement.getAllGroups();  // »ñÈ¡ËùÓÐС×é
            updateTable(allGroups);  // ¸üбí¸ñ
        } catch (SQLException ex) {
            showErrorDialog("DATA_LOAD_ERROR", ex.getMessage());  // ÏÔʾ´íÎó
        }
    }
    
    // ¸üбí¸ñÊý¾Ý
    private void updateTable(List<GroupManagement> groups) {
        tableModel.setRowCount(0);  // Çå¿Õ±í¸ñ
        
        int index = 1;  // ÐòºÅ´Ó1¿ªÊ¼
        for (GroupManagement group : groups) {
            tableModel.addRow(new Object[]{  // Ìí¼ÓÐÐÊý¾Ý
                index++,  // ÐòºÅ
                group.getGroupNumber(),  // ×é±àºÅ
                group.getBelongLayer(),  // ËùÊô²ã
                algorithmCodeToText(group.getAlgorithm()),  // Ëã·¨ÃèÊö
                booleanToText(group.getOutdoorGroup()),  // ÊÒÍâ×é
                booleanToText(group.getMustPassGroup()),  // ±Ø¾­×é
                booleanToText(group.getCrossMultilayer()),  // ×é¿ç¶à²ã
                group.getGroupWidth(),  // ×é¿í¶È
                group.getValidArea(),  // ÓÐÐ§ÇøÓò
                group.getCompany(),  // ¹«Ë¾
                group.getAddTime()  // Ìí¼Óʱ¼ä
            });
        }
    }
    
    // Ëã·¨´úÂëתÎı¾
    private String algorithmCodeToText(String code) {
        if (code == null) return "";  // ¿ÕÖµ´¦Àí
        switch (code) {
            case "0": return getMessage("ALGORITHM_0");  // Áã½×
            case "1": return getMessage("ALGORITHM_1");  // Ò»½×
            case "2": return getMessage("ALGORITHM_2");  // ¶þ½×
            case "3": return getMessage("ALGORITHM_3");  // Èý½×
            default: return code;  // Ä¬ÈÏ·µ»ØÔ­Öµ
        }
    }
    
    // ²¼¶ûֵתÎı¾
    private String booleanToText(String value) {
        if (value == null) return "";  // ¿ÕÖµ´¦Àí
        return "1".equals(value) ? getMessage("YES") : getMessage("NO");  // 1תÊÇ£¬0ת·ñ
    }
    
    // ËÑË÷С×é
    private void searchGroups() {
        String keyword = searchField.getText().trim();  // »ñÈ¡¹Ø¼ü´Ê
        if (keyword.isEmpty()) {
            updateTable(allGroups);  // ¿Õ¹Ø¼ü´ÊÏÔʾȫ²¿
            return;
        }
        
        List<GroupManagement> filtered = new ArrayList<>();  // ¹ýÂ˽á¹ûÁбí
        for (GroupManagement group : allGroups) {
            if (group.getGroupNumber().toLowerCase().contains(keyword.toLowerCase())) {  // Æ¥Åä×é±àºÅ
                filtered.add(group);  // Ìí¼Óµ½½á¹û
            }
        }
        
        if (filtered.isEmpty()) {
            JOptionPane.showMessageDialog(this, getMessage("SEARCH_NO_RESULTS"),  // ÏÔʾÎÞ½á¹û
                    getMessage("INFO"), JOptionPane.INFORMATION_MESSAGE);
        }
        
        updateTable(filtered);  // ¸üбí¸ñ
    }
    
    // ÖØÖÃËÑË÷
    private void resetSearch() {
        searchField.setText("");  // Çå¿ÕËÑË÷¿ò
        updateTable(allGroups);  // ÏÔʾËùÓÐÊý¾Ý
    }
    
    // Ìí¼ÓÐÂС×é
    private void addNewGroup() {
        GroupEditDialog dialog = new GroupEditDialog(  // ´´½¨Ìí¼Ó¶Ô»°¿ò
            (Frame) SwingUtilities.getWindowAncestor(this), 
            messages, 
            true, 
            null
        );
        dialog.setVisible(true);  // ÏÔʾ¶Ô»°¿ò
        
        if (dialog.isConfirmed()) {  // È·ÈϲÙ×÷
            GroupManagement newGroup = dialog.getGroup();  // »ñȡС×é¶ÔÏó
            
            // ÑéÖ¤ÊäÈë
            if (validateInput(newGroup)) {
                // ¼ì²é×é±àºÅÊÇ·ñΨһ
                if (isGroupNumberExists(newGroup.getGroupNumber())) {
                    showErrorDialog("GROUP_NUMBER_EXISTS", null);  // ÏÔʾ´íÎó
                    return;
                }
                
                // ±£´æµ½Êý¾Ý¿â
                if (saveGroupToDatabase(newGroup)) {
                    // ¸üÐÂÄÚ´æÊý¾Ý
                    allGroups.add(newGroup);  // Ìí¼Óµ½Áбí
                    updateTable(allGroups);  // ¸üбí¸ñ
                }
            }
        }
    }
    
    // ±à¼­Ñ¡ÖÐС×é
    private void editSelectedGroup() {
        int selectedRow = groupTable.getSelectedRow();  // »ñȡѡÖÐÐÐ
        if (selectedRow == -1) {
            showWarningDialog("SELECT_GROUP_TO_EDIT");  // ÌáʾѡÔñС×é
            return;
        }
        
        // »ñȡѡÖеÄС×é
        int modelRow = groupTable.convertRowIndexToModel(selectedRow);  // ×ª»»ÎªÄ£ÐÍË÷Òý
        String groupNumber = (String) tableModel.getValueAt(modelRow, 1);  // »ñÈ¡×é±àºÅ
        GroupManagement group = findGroupByNumber(groupNumber);  // ²éÕÒС×é
        
        if (group == null) {
            showErrorDialog("GROUP_NOT_FOUND", null);  // Ð¡×é²»´æÔÚ
            return;
        }
        
        GroupEditDialog dialog = new GroupEditDialog(  // ´´½¨±à¼­¶Ô»°¿ò
            (Frame) SwingUtilities.getWindowAncestor(this), 
            messages, 
            false, 
            group
        );
        dialog.setVisible(true);  // ÏÔʾ¶Ô»°¿ò
        
        if (dialog.isConfirmed()) {  // È·ÈϲÙ×÷
            GroupManagement updatedGroup = dialog.getGroup();  // »ñÈ¡¸üкóµÄС×é
            
            // ÑéÖ¤ÊäÈë
            if (validateInput(updatedGroup)) {
                // ¸üÐÂС×éÐÅÏ¢
                group.setBelongLayer(updatedGroup.getBelongLayer());  // ËùÊô²ã
                group.setAlgorithm(updatedGroup.getAlgorithm());  // Ëã·¨
                group.setOutdoorGroup(updatedGroup.getOutdoorGroup());  // ÊÒÍâ×é
                group.setMustPassGroup(updatedGroup.getMustPassGroup());  // ±Ø¾­×é
                group.setCrossMultilayer(updatedGroup.getCrossMultilayer());  // ×é¿ç¶à²ã
                group.setGroupWidth(updatedGroup.getGroupWidth());  // ×é¿í¶È
                group.setValidArea(updatedGroup.getValidArea());  // ÓÐÐ§ÇøÓò
                group.setCompany(updatedGroup.getCompany());  // ¹«Ë¾
                
                // ¸üÐÂÊý¾Ý¿â
                if (updateGroupInDatabase(group)) {
                    updateTable(allGroups);  // ¸üбí¸ñ
                }
            }
        }
    }
    
    // É¾³ýÑ¡ÖÐС×é
    private void deleteSelectedGroups() {
        int[] selectedRows = groupTable.getSelectedRows();  // »ñȡѡÖÐÐÐ
        if (selectedRows.length == 0) {
            showWarningDialog("SELECT_GROUP_TO_DELETE");  // ÌáʾѡÔñС×é
            return;
        }
        
        int confirm = JOptionPane.showConfirmDialog(this, 
            getMessage("CONFIRM_DELETE_GROUPS").replace("{0}", String.valueOf(selectedRows.length)),  // È·ÈÏÏûÏ¢
            getMessage("CONFIRM"), JOptionPane.YES_NO_OPTION);  // È·È϶Ի°¿ò
        
        if (confirm == JOptionPane.YES_OPTION) {  // Óû§È·ÈÏ
            Arrays.sort(selectedRows);  // ÅÅÐòÐÐË÷Òý
            for (int i = selectedRows.length - 1; i >= 0; i--) {  // µ¹Ðòɾ³ý
                int viewRow = selectedRows[i];  // ÊÓͼÐÐË÷Òý
                int modelRow = groupTable.convertRowIndexToModel(viewRow);  // ×ª»»ÎªÄ£ÐÍË÷Òý
                
                String groupNumber = (String) tableModel.getValueAt(modelRow, 1);  // »ñÈ¡×é±àºÅ
                GroupManagement group = findGroupByNumber(groupNumber);  // ²éÕÒС×é
                
                if (group != null) {
                    if (deleteGroupFromDatabase(group)) {  // ´ÓÊý¾Ý¿âɾ³ý
                        allGroups.remove(group);  // ´ÓÄÚ´æÉ¾³ý
                    }
                }
            }
            
            updateTable(allGroups);  // ¸üбí¸ñ
        }
    }
    
    // ÑéÖ¤ÊäÈë
    private boolean validateInput(GroupManagement group) {
        // ×é±àºÅ²»ÄÜΪ¿Õ
        if (group.getGroupNumber() == null || group.getGroupNumber().trim().isEmpty()) {
            showErrorDialog("GROUP_NUMBER_REQUIRED", null);  // ÏÔʾ´íÎó
            return false;
        }
        
        // ×é¿í¶È±ØÐëÊÇÊý×Ö
        if (group.getGroupWidth() != null && !group.getGroupWidth().isEmpty()) {
            try {
                Integer.parseInt(group.getGroupWidth());  // ³¢ÊÔת»»
            } catch (NumberFormatException e) {
                showErrorDialog("GROUP_WIDTH_NUMBER", null);  // ÏÔʾ´íÎó
                return false;
            }
        }
        
        return true;  // Ñé֤ͨ¹ý
    }
    
    // ¼ì²é×é±àºÅÊÇ·ñ´æÔÚ
    private boolean isGroupNumberExists(String groupNumber) {
        for (GroupManagement group : allGroups) {
            if (group.getGroupNumber().equals(groupNumber)) {  // Æ¥Åä×é±àºÅ
                return true;  // ´æÔÚ
            }
        }
        return false;  // ²»´æÔÚ
    }
    
    // Í¨¹ý±àºÅ²éÕÒС×é
    private GroupManagement findGroupByNumber(String groupNumber) {
        for (GroupManagement group : allGroups) {
            if (group.getGroupNumber().equals(groupNumber)) {  // Æ¥Åä×é±àºÅ
                return group;  // ·µ»ØÐ¡×é
            }
        }
        return null;  // Î´ÕÒµ½
    }
    
    // ±£´æÐ¡×éµ½Êý¾Ý¿â
    private boolean saveGroupToDatabase(GroupManagement group) {
        try {
            Dell_GroupManagement.insertGroup(group);  // ²åÈëС×é
            showSuccessDialog("SAVE_SUCCESS");  // ÏÔʾ³É¹¦
            return true;
        } catch (SQLException ex) {
            showErrorDialog("SAVE_FAILED", ex.getMessage());  // ÏÔʾ´íÎó
            return false;
        }
    }
    
    // ¸üÐÂÊý¾Ý¿âÖеÄС×é
    private boolean updateGroupInDatabase(GroupManagement group) {
        try {
            Dell_GroupManagement.updateGroup(group);  // ¸üÐÂС×é
            showSuccessDialog("UPDATE_SUCCESS");  // ÏÔʾ³É¹¦
            return true;
        } catch (SQLException ex) {
            showErrorDialog("UPDATE_FAILED", ex.getMessage());  // ÏÔʾ´íÎó
            return false;
        }
    }
    
    // ´ÓÊý¾Ý¿âɾ³ýС×é
    private boolean deleteGroupFromDatabase(GroupManagement group) {
        String idStr = group.getId();  // »ñÈ¡ID×Ö·û´®
        if (idStr == null || idStr.trim().isEmpty()) {
            showErrorDialog("INVALID_GROUP_ID", null);  // ÎÞЧID
            return false;
        }
        
        try {
            int id = Integer.parseInt(idStr);  // ×ª»»ÎªÕûÊý
            Dell_GroupManagement.deleteGroup(id);  // É¾³ýС×é
            showSuccessDialog("DELETE_SUCCESS");  // ÏÔʾ³É¹¦
            return true;
        } catch (NumberFormatException e) {
            showErrorDialog("INVALID_GROUP_ID", idStr);  // ÎÞЧID
            return false;
        } catch (SQLException ex) {
            showErrorDialog("DELETE_FAILED", ex.getMessage());  // É¾³ýʧ°Ü
            return false;
        }
    }
    
    // ÏÔʾ´íÎó¶Ô»°¿ò
    private void showErrorDialog(String key, String detail) {
        String message = getMessage(key);  // »ñÈ¡ÏûÏ¢
        if (detail != null) {
            message += ": " + detail;  // Ìí¼ÓÏêÇé
        }
        JOptionPane.showMessageDialog(this, message, 
                                     getMessage("ERROR"), JOptionPane.ERROR_MESSAGE);  // ÏÔʾ¶Ô»°¿ò
    }
    
    // ÏÔʾ¾¯¸æ¶Ô»°¿ò
    private void showWarningDialog(String key) {
        JOptionPane.showMessageDialog(this, getMessage(key),
                                     getMessage("WARNING"), JOptionPane.WARNING_MESSAGE);  // ÏÔʾ¾¯¸æ
    }
    
    // ÏÔʾ³É¹¦¶Ô»°¿ò
    private void showSuccessDialog(String key) {
        JOptionPane.showMessageDialog(this, getMessage(key),
                                     getMessage("SUCCESS"), JOptionPane.INFORMATION_MESSAGE);  // ÏÔʾ³É¹¦
    }
    
    // »ñÈ¡±¾µØ»¯ÏûÏ¢
    private String getMessage(String key) {
        try {
            return messages.getString(key);  // ´Ó×ÊÔ´Êø»ñÈ¡
        } catch (Exception e) {
            return "[" + key + "]";  // »ØÍËÏÔʾ
        }
    }
    
    // Ð¡×é±à¼­¶Ô»°¿ò
    class GroupEditDialog extends JDialog {
        private static final long serialVersionUID = 1L;  // ÐòÁл¯°æ±¾ºÅ
        private JTextField numberField;  // ×é±àºÅÊäÈë¿ò
        private JComboBox<String> layerComboBox;  // ËùÊô²ãÏÂÀ­¿ò
        private JComboBox<String> algorithmComboBox;  // Ëã·¨ÏÂÀ­¿ò
        
        // ÊÒÍâ×鵥ѡ°´Å¥×é
        private ButtonGroup outdoorGroup;  
        private JRadioButton outdoorYes;  // ÊÒÍâ×é-ÊÇ
        private JRadioButton outdoorNo;   // ÊÒÍâ×é-·ñ
        
        // ±Ø¾­×鵥ѡ°´Å¥×é
        private ButtonGroup mustPassGroup;  
        private JRadioButton mustPassYes;  // ±Ø¾­×é-ÊÇ
        private JRadioButton mustPassNo;   // ±Ø¾­×é-·ñ
        
        // ×é¿ç¶à²ãµ¥Ñ¡°´Å¥×é
        private ButtonGroup crossMultilayerGroup;  
        private JRadioButton crossMultilayerYes;  // ×é¿ç¶à²ã-ÊÇ
        private JRadioButton crossMultilayerNo;   // ×é¿ç¶à²ã-·ñ
        
        private JTextField widthField;  // ×é¿í¶ÈÊäÈë¿ò
        private JTextField areaField;  // ÓÐÐ§ÇøÓòÊäÈë¿ò
        private JComboBox<String> companyComboBox;  // ¹«Ë¾ÏÂÀ­¿ò
        private boolean confirmed = false;  // È·ÈÏ״̬
        
        public GroupEditDialog(Frame parent, ResourceBundle messages, boolean isAddDialog, GroupManagement existingGroup) {
            super(parent, isAddDialog ? getMessage("ADD") : getMessage("EDIT"), true);  // ´´½¨¶Ô»°¿ò
            setLayout(new BorderLayout());  // ÉèÖñ߽粼¾Ö
            setSize(500, 400);  // ÉèÖôóС
            setLocationRelativeTo(parent);  // ¾ÓÖÐÏÔʾ
 
            JPanel formPanel = new JPanel(new GridLayout(9, 2, 5, 5));  // ´´½¨±íµ¥Ãæ°å
            formPanel.setBorder(new EmptyBorder(10, 10, 10, 10));  // ÉèÖñ߿ò
 
            // ×é±àºÅ
            JLabel numberLabel = new JLabel(getMessage("GROUP_NUMBER") + ": *");  // ±êÇ©
            numberField = new JTextField();  // Îı¾¿ò
            if (!isAddDialog && existingGroup != null) {
                numberField.setEditable(false);  // ±à¼­Ä£Ê½Ï²»¿É±à¼­
            }
            formPanel.add(numberLabel);  // Ìí¼Ó±êÇ©
            formPanel.add(numberField);  // Ìí¼ÓÎı¾¿ò
 
            // ËùÊô²ã
            JLabel layerLabel = new JLabel(getMessage("BELONG_LAYER") + ": *");  // ±êÇ©
            layerComboBox = new JComboBox<>();  // ÏÂÀ­¿ò
            // »ñÈ¡ËùÓвã±àºÅ
            String[] layerNumbers = Dell_LayerManagement.getAllLayerNumbers();  // »ñÈ¡²ã±àºÅ
            for (String number : layerNumbers) {
                layerComboBox.addItem(number);  // Ìí¼ÓÑ¡Ïî
            }
            formPanel.add(layerLabel);  // Ìí¼Ó±êÇ©
            formPanel.add(layerComboBox);  // Ìí¼ÓÏÂÀ­¿ò
 
            // Ëã·¨
            JLabel algorithmLabel = new JLabel(getMessage("ALGORITHM") + ":");  // ±êÇ©
            algorithmComboBox = new JComboBox<>();  // ÏÂÀ­¿ò
            algorithmComboBox.addItem(getMessage("ALGORITHM_0"));  // Áã½×
            algorithmComboBox.addItem(getMessage("ALGORITHM_1"));  // Ò»½×
            algorithmComboBox.addItem(getMessage("ALGORITHM_2"));  // ¶þ½×
            algorithmComboBox.addItem(getMessage("ALGORITHM_3"));  // Èý½×
            formPanel.add(algorithmLabel);  // Ìí¼Ó±êÇ©
            formPanel.add(algorithmComboBox);  // Ìí¼ÓÏÂÀ­¿ò
 
            // ÊÒÍâ×é - ¸ÄΪµ¥Ñ¡°´Å¥
            JLabel outdoorLabel = new JLabel(getMessage("OUTDOOR_GROUP") + ":");  // ±êÇ©
            JPanel outdoorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));  // µ¥Ñ¡°´Å¥Ãæ°å
            outdoorGroup = new ButtonGroup();  // °´Å¥×é
            outdoorYes = new JRadioButton(getMessage("YES"));  // ÊÇ
            outdoorNo = new JRadioButton(getMessage("NO"));   // ·ñ
            outdoorGroup.add(outdoorYes);  // Ìí¼Óµ½×é
            outdoorGroup.add(outdoorNo);   // Ìí¼Óµ½×é
            outdoorPanel.add(outdoorYes);  // Ìí¼Óµ½Ãæ°å
            outdoorPanel.add(outdoorNo);   // Ìí¼Óµ½Ãæ°å
            formPanel.add(outdoorLabel);   // Ìí¼Ó±êÇ©
            formPanel.add(outdoorPanel);   // Ìí¼Óµ¥Ñ¡°´Å¥Ãæ°å
 
            // ±Ø¾­×é - ¸ÄΪµ¥Ñ¡°´Å¥
            JLabel mustPassLabel = new JLabel(getMessage("MUST_PASS_GROUP") + ":");  // ±êÇ©
            JPanel mustPassPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));  // µ¥Ñ¡°´Å¥Ãæ°å
            mustPassGroup = new ButtonGroup();  // °´Å¥×é
            mustPassYes = new JRadioButton(getMessage("YES"));  // ÊÇ
            mustPassNo = new JRadioButton(getMessage("NO"));   // ·ñ
            mustPassGroup.add(mustPassYes);  // Ìí¼Óµ½×é
            mustPassGroup.add(mustPassNo);   // Ìí¼Óµ½×é
            mustPassPanel.add(mustPassYes);  // Ìí¼Óµ½Ãæ°å
            mustPassPanel.add(mustPassNo);   // Ìí¼Óµ½Ãæ°å
            formPanel.add(mustPassLabel);    // Ìí¼Ó±êÇ©
            formPanel.add(mustPassPanel);    // Ìí¼Óµ¥Ñ¡°´Å¥Ãæ°å
 
            // ×é¿ç¶à²ã - ¸ÄΪµ¥Ñ¡°´Å¥
            JLabel crossLabel = new JLabel(getMessage("CROSS_MULTILAYER") + ":");  // ±êÇ©
            JPanel crossPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));  // µ¥Ñ¡°´Å¥Ãæ°å
            crossMultilayerGroup = new ButtonGroup();  // °´Å¥×é
            crossMultilayerYes = new JRadioButton(getMessage("YES"));  // ÊÇ
            crossMultilayerNo = new JRadioButton(getMessage("NO"));   // ·ñ
            crossMultilayerGroup.add(crossMultilayerYes);  // Ìí¼Óµ½×é
            crossMultilayerGroup.add(crossMultilayerNo);   // Ìí¼Óµ½×é
            crossPanel.add(crossMultilayerYes);  // Ìí¼Óµ½Ãæ°å
            crossPanel.add(crossMultilayerNo);   // Ìí¼Óµ½Ãæ°å
            formPanel.add(crossLabel);  // Ìí¼Ó±êÇ©
            formPanel.add(crossPanel);  // Ìí¼Óµ¥Ñ¡°´Å¥Ãæ°å
 
            // ×é¿í¶È
            JLabel widthLabel = new JLabel(getMessage("GROUP_WIDTH") + " (cm):");  // ±êÇ©
            widthField = new JTextField();  // Îı¾¿ò
            formPanel.add(widthLabel);  // Ìí¼Ó±êÇ©
            formPanel.add(widthField);  // Ìí¼ÓÎı¾¿ò
 
            // ÓÐÐ§ÇøÓò
            JLabel areaLabel = new JLabel(getMessage("VALID_AREA") + ":");  // ±êÇ©
            areaField = new JTextField();  // Îı¾¿ò
            formPanel.add(areaLabel);  // Ìí¼Ó±êÇ©
            formPanel.add(areaField);  // Ìí¼ÓÎı¾¿ò
 
            // ËùÊô¹«Ë¾
            JLabel companyLabel = new JLabel(getMessage("COMPANY") + ": *");  // ±êÇ©
            companyComboBox = new JComboBox<>();  // ÏÂÀ­¿ò
            // »ñÈ¡ËùÓй«Ë¾Ãû³Æ
            String[] companyNames = Dell_company.getAllCompanyNames();  // »ñÈ¡¹«Ë¾Ãû
            for (String name : companyNames) {
                companyComboBox.addItem(name);  // Ìí¼ÓÑ¡Ïî
            }
            formPanel.add(companyLabel);  // Ìí¼Ó±êÇ©
            formPanel.add(companyComboBox);  // Ìí¼ÓÏÂÀ­¿ò
 
            // Èç¹ûÊDZ༭ģʽ£¬Ìî³äÏÖÓÐÊý¾Ý
            if (!isAddDialog && existingGroup != null) {
                numberField.setText(existingGroup.getGroupNumber());  // ÉèÖÃ×é±àºÅ
                layerComboBox.setSelectedItem(existingGroup.getBelongLayer());  // ÉèÖÃËùÊô²ã
                
                // ÉèÖÃË㷨ѡÔñ
                String algorithm = existingGroup.getAlgorithm();  // »ñÈ¡Ëã·¨Öµ
                if (algorithm != null) {
                    switch (algorithm) {
                        case "0": algorithmComboBox.setSelectedIndex(0); break;  // Áã½×
                        case "1": algorithmComboBox.setSelectedIndex(1); break;  // Ò»½×
                        case "2": algorithmComboBox.setSelectedIndex(2); break;  // ¶þ½×
                        case "3": algorithmComboBox.setSelectedIndex(3); break;  // Èý½×
                        default: algorithmComboBox.setSelectedIndex(0);  // Ä¬ÈÏ
                    }
                }
                
                // ÉèÖõ¥Ñ¡°´Å¥×´Ì¬
                if ("1".equals(existingGroup.getOutdoorGroup())) {
                    outdoorYes.setSelected(true);  // ÊÒÍâ×é-ÊÇ
                } else {
                    outdoorNo.setSelected(true);   // ÊÒÍâ×é-·ñ
                }
                
                if ("1".equals(existingGroup.getMustPassGroup())) {
                    mustPassYes.setSelected(true);  // ±Ø¾­×é-ÊÇ
                } else {
                    mustPassNo.setSelected(true);   // ±Ø¾­×é-·ñ
                }
                
                if ("1".equals(existingGroup.getCrossMultilayer())) {
                    crossMultilayerYes.setSelected(true);  // ×é¿ç¶à²ã-ÊÇ
                } else {
                    crossMultilayerNo.setSelected(true);   // ×é¿ç¶à²ã-·ñ
                }
                
                widthField.setText(existingGroup.getGroupWidth());  // ×é¿í¶È
                areaField.setText(existingGroup.getValidArea());    // ÓÐÐ§ÇøÓò
                companyComboBox.setSelectedItem(existingGroup.getCompany());  // ¹«Ë¾
            }
 
            add(formPanel, BorderLayout.CENTER);  // Ìí¼Ó±íµ¥µ½ÖÐÐÄ
 
            // °´Å¥Ãæ°å
            JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));  // °´Å¥Ãæ°å
            JButton okButton = new JButton(getMessage("OK"));  // È·¶¨°´Å¥
            JButton cancelButton = new JButton(getMessage("CANCEL"));  // È¡Ïû°´Å¥
 
            okButton.addActionListener(e -> {
                confirmed = true;  // ÉèÖÃÈ·ÈÏ״̬
                dispose();  // ¹Ø±Õ¶Ô»°¿ò
            });
 
            cancelButton.addActionListener(e -> dispose());  // ¹Ø±Õ¶Ô»°¿ò
 
            buttonPanel.add(okButton);  // Ìí¼ÓÈ·¶¨°´Å¥
            buttonPanel.add(cancelButton);  // Ìí¼ÓÈ¡Ïû°´Å¥
            add(buttonPanel, BorderLayout.SOUTH);  // Ìí¼Ó°´Å¥Ãæ°åµ½µ×²¿
        }
 
        // »ñȡС×é¶ÔÏó
        public GroupManagement getGroup() {
            if (!confirmed) {
                return null;  // Î´È·ÈÏ·µ»Ø¿Õ
            }
            
            GroupManagement group = new GroupManagement();  // ´´½¨Ð¡×é¶ÔÏó
            group.setGroupNumber(numberField.getText());  // ÉèÖÃ×é±àºÅ
            group.setBelongLayer((String) layerComboBox.getSelectedItem());  // ÉèÖÃËùÊô²ã
            
            // Ë㷨ת»»
            String algorithmText = (String) algorithmComboBox.getSelectedItem();  // »ñÈ¡Ëã·¨Îı¾
            if (getMessage("ALGORITHM_0").equals(algorithmText)) group.setAlgorithm("0");  // Áã½×
            else if (getMessage("ALGORITHM_1").equals(algorithmText)) group.setAlgorithm("1");  // Ò»½×
            else if (getMessage("ALGORITHM_2").equals(algorithmText)) group.setAlgorithm("2");  // ¶þ½×
            else if (getMessage("ALGORITHM_3").equals(algorithmText)) group.setAlgorithm("3");  // Èý½×
            else group.setAlgorithm("0");  // Ä¬ÈÏÁã½×
            
            // ÉèÖõ¥Ñ¡°´Å¥Öµ
            group.setOutdoorGroup(outdoorYes.isSelected() ? "1" : "0");  // ÊÒÍâ×é
            group.setMustPassGroup(mustPassYes.isSelected() ? "1" : "0");  // ±Ø¾­×é
            group.setCrossMultilayer(crossMultilayerYes.isSelected() ? "1" : "0");  // ×é¿ç¶à²ã
            
            group.setGroupWidth(widthField.getText());  // ×é¿í¶È
            group.setValidArea(areaField.getText());    // ÓÐÐ§ÇøÓò
            group.setCompany((String) companyComboBox.getSelectedItem());  // ¹«Ë¾
            
            // ÉèÖÃÌí¼Óʱ¼ä
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  // Ê±¼ä¸ñʽ
            group.setAddTime(sdf.format(new Date()));  // µ±Ç°Ê±¼ä
            
            return group;  // ·µ»ØÐ¡×é¶ÔÏó
        }
 
        // ÊÇ·ñÈ·ÈÏ
        public boolean isConfirmed() {
            return confirmed;  // ·µ»ØÈ·ÈÏ״̬
        }
    }
}