jinlin
2025-03-21 77d58298d00c11ade8862ca8acb0fdef5a45322e
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
package com.example.client.service;
 
import com.example.client.dto.ColumnDto;
import com.example.client.dto.JComboBoxItem;
import com.example.client.utils.BoxIteUtils;
import com.example.client.utils.CommonTable;
import com.example.client.utils.GBC;
import com.example.server.boatFleet.service.BoatFleetService;
import com.example.server.teamGroup.model.SysTeamGroupClass;
import com.example.server.teamGroup.service.SysTeamGroupClassService;
import com.example.server.user.model.SysUser;
import com.example.server.user.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.List;
 
@Service
public class TeamGroupAddOrUpdate {
 
    @Autowired
    private TeamGroupManageService teamGroupManageService;
    @Autowired
    private SysTeamGroupClassService sysTeamGroupClassService;
 
 
    public void openDialog(SysTeamGroupClass data, JFrame jFrame, List<ColumnDto> columnDto, JTable table) {
        JFrame frame1 = new JFrame("专业操作");
        frame1.setSize(800, 600);
        frame1.setResizable(false);
        frame1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        frame1.setLocationRelativeTo(null);
        frame1.setVisible(true);
        frame1.addWindowListener(new WindowAdapter() {
            //添加第二个界面的关闭事件:
            public void windowClosing(WindowEvent e) {
                //添加事件:
                jFrame.setEnabled(true);//将主界面再设置为可操作的
            }
        });
        GridBagLayout layout = new GridBagLayout();
        frame1.setLayout(layout);
 
        JComboBoxItem[] deptList = sysTeamGroupClassService.getDeptList();
        String[] typeList = new String[]{
                "部门", "专业"
        };
 
        JLabel JLabel0 = new JLabel("类型");
        JComboBox<String> comboBox1 = new JComboBox<>(typeList);
        comboBox1.setPreferredSize(new Dimension(185,28));
        if (StringUtils.isNotBlank(data.getType())) {
            comboBox1.setSelectedItem(data.getType());
        }
 
        JLabel JLabel1 = new JLabel("部门/专业名称");
        JTextField name = new JTextField(16);
        if (StringUtils.isNotBlank(data.getName())) {
            name.setText(data.getName());
        }
 
        JLabel JLabel4 = new JLabel("所属部门");
        JComboBox<JComboBoxItem> comboBox2 = new JComboBox<>(deptList);
        comboBox2.setPreferredSize(new Dimension(185,28));
        if (data.getPid() != null) {
            if (data.getPid()!=0){
                comboBox2.setSelectedItem(BoxIteUtils.GetSelectItemById(deptList, data.getPid()));
            }else {
                comboBox2.setEditable(false);
            }
        }
 
        comboBox1.addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    String type = comboBox1.getSelectedItem().toString();
                    if (type.equals("部门")) {
                        comboBox2.setEditable(false);
                        comboBox2.setSelectedIndex(-1);
                        data.setPid(0L);
                    }
                }
            }
        });
 
 
        JButton saveButton = new JButton("确定");
 
        frame1.add(JLabel0, new GBC(0, 0, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox1, new GBC(1, 0, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel1, new GBC(0, 1, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(name, new GBC(1, 1, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(JLabel4, new GBC(0, 2, 1, 1).setAnchor(GBC.SOUTHEAST).setInsets(5));
        frame1.add(comboBox2, new GBC(1, 2, 1, 1).setAnchor(GBC.SOUTHWEST).setInsets(5));
 
        frame1.add(saveButton, new GBC(0, 3, 2, 1).setWeight(0, 0));
 
        saveButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String type = comboBox1.getSelectedItem().toString();
                JComboBoxItem dept = (JComboBoxItem) comboBox2.getSelectedItem();
                Integer sortMax = 0;
                if (type.equals("部门")) {
                    data.setPid(0L);
                    sortMax = sysTeamGroupClassService.getSortMax(0L);
                    data.setSort(sortMax + 100);
                } else {
                    data.setPid(dept.getId());
                    sortMax = sysTeamGroupClassService.getSortMax(dept.getId());
                    data.setSort(sortMax + 1);
                }
 
                data.setArea("hld");
                data.setName(name.getText());
                //data.setBoatfleet(String.valueOf(boat.getId()));
 
                sysTeamGroupClassService.save(data);
 
                List<SysTeamGroupClass> list = sysTeamGroupClassService.getListByTree();;
                CommonTable.refreshTable(list, columnDto, table);
                teamGroupManageService.tableModelListener(table, jFrame, list);
                frame1.dispose();
                jFrame.setEnabled(true);//将主界面再设置为可操作的
            }
        });
 
    }
}