wangting
2024-09-27 a3e87f78ee262ca9bb7d9b0c997639d5f3295890
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
package com.vci.client.portal.NewNewUI.actionmng;
 
import java.awt.Frame;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
 
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
 
import com.vci.client.portal.utility.UITools;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.portal.data.PLActionCls;
import com.vci.mw.ClientContextVariable;
 
public class PLActionClsEditDialog extends JDialog {
 
    /**
     * serialVersionUID
     */
    private static final long serialVersionUID = 1L;
 
    /**
     * 父窗口
     */
    private Frame owner;
    /**
     * 名称标签
     */
    private JLabel nameLabel;
    /**
     * 名称文本框
     */
    private JTextField nameField;
    /**
     * 序号标签
     */
    private JLabel serialNoLabel;
    /**
     * 序号输入框
     */
    private JTextField serialNoField;
    /**
     * 所属父分类标签
     */
    private JLabel pNameLabel;
    /**
     * 所属父分类输入框
     */
    private JTextField pNameField;
    /**
     * 创建者标签
     */
    private JLabel creatorLabel;
    /**
     * 创建者文本框
     */
    private JTextField creatorField;
    /**
     * 最后修改时间标签
     */
    private JLabel createTimeLabel;
    /**
     * 最后修改时间文本框
     */
    private JTextField createTimeField;
    /**
     * 备注标签
     */
    private JLabel descLabel;
    /**
     * 备注文本域
     */
    private JTextArea descArea;
    /**
     * 确定按钮
     */
    private JButton okBtn;
    /**
     * 取消按钮
     */
    private JButton cancelBtn;
    /**
     * 标记 0创建、1修改
     */
    private int flag;
 
    /**
     * 是否保存
     */
    private boolean ok = false;
 
    /**
     * 所属父分类
     */
    private PLActionCls parent;
    /**
     * 当前分类
     */
    private PLActionCls currentCls;
 
    /**
     * 创建,修改Action分类窗口
     * 
     * @param owner  所属父
     * @param title  标题
     * @param flag   标记 0创建、1修改
     * @param parent 所属父分类
     */
    public PLActionClsEditDialog(Frame owner, String title, int flag, PLActionCls parent, PLActionCls cls) {
        super(owner, title, true);
        this.owner = owner;
        this.flag = flag;
        this.parent = parent;
        this.currentCls = cls;
        this.init();
        this.setLocationRelativeTo(owner);
        this.setVisible(true);
    }
 
    /**
     * 绘制界面
     */
    private void init() {
        this.setSize(480, 320);
        this.setLayout(null);
 
        nameLabel = new JLabel("分类名称");
        nameLabel.setBounds(15, 15, 60, 25);
        nameField = new JTextField();
        if (this.flag != 0) {
            nameField.setText(this.currentCls.name);
        }
        nameField.setBounds(70, 15, 150, 25);
        serialNoLabel = new JLabel("分类序号");
        serialNoLabel.setBounds(230, 15, 70, 25);
        serialNoField = new JTextField();
        if (this.flag != 0) {
            serialNoField.setText(this.currentCls.serialno + "");
        }
        serialNoField.setBounds(300, 15, 150, 25);
        creatorLabel = new JLabel("创建者");
        creatorLabel.setBounds(15, 50, 60, 25);
        creatorField = new JTextField(ClientContextVariable.getInvocationInfo().userName);
        if (this.flag != 0) {
            creatorField.setText(this.currentCls.creator);
        }
        creatorField.setEditable(false);
        creatorField.setBounds(70, 50, 150, 25);
        createTimeLabel = new JLabel("创建时间");
        if (this.flag != 0) {
            createTimeLabel.setText("修改时间");
        }
        createTimeLabel.setBounds(230, 50, 70, 25);
        createTimeField = new JTextField(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        createTimeField.setEditable(false);
        createTimeField.setBounds(300, 50, 150, 25);
        pNameLabel = new JLabel("父分类");
        pNameLabel.setBounds(15, 85, 60, 25);
        pNameField = new JTextField(parent == null ? "Action分类" : parent.name);
        pNameField.setEditable(false);
        pNameField.setBounds(70, 85, 380, 25);
        descLabel = new JLabel("备注");
        descLabel.setBounds(15, 120, 60, 25);
        descArea = new JTextArea();
        descArea.setLineWrap(true);
        if (this.flag != 0) {
            descArea.setText(this.currentCls.description);
        }
        JScrollPane descScrollPane = new JScrollPane(descArea);
        descScrollPane.setBounds(70, 120, 380, 110);
 
        JPanel btnPanel = new JPanel();
        btnPanel.setLayout(null);
        btnPanel.setBounds(0, 240, 485, 40);
        okBtn = new JButton("确定");
        okBtn.setBounds(new Rectangle(300, 5, 50, 25));
        okBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                okAction();
            }
        });
        cancelBtn = new JButton("取消");
        cancelBtn.setBounds(new Rectangle(360, 5, 50, 25));
        cancelBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                cancelAction();
            }
        });
        btnPanel.add(okBtn);
        btnPanel.add(cancelBtn);
 
        this.add(nameLabel);
        this.add(nameField);
        this.add(serialNoLabel);
        this.add(serialNoField);
        this.add(creatorLabel);
        this.add(creatorField);
        this.add(createTimeLabel);
        this.add(createTimeField);
        this.add(pNameLabel);
        this.add(pNameField);
        this.add(descLabel);
        this.add(descScrollPane);
        this.add(btnPanel);
        this.validate();
        this.setResizable(false);
    }
 
    /**
     * 创建按钮事件
     */
    private void okAction() {
        String name = getNotNullString(this.nameField.getText());
        String pid = this.parent == null ? "" : this.parent.id;
        String creator = getNotNullString(this.creatorField.getText());
        String createTime = "";// this.createTimeField.getText();
        String serialNo = getNotNullString(this.serialNoField.getText());
        String desc = getNotNullString(this.descArea.getText());
        if (name == null || name.trim().equals("")) {
            JOptionPane.showMessageDialog(this, "分类名称不能为空!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        if (name.equals("未分类")) {
            JOptionPane.showMessageDialog(this, "未分类节点已经存在!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        }
        short serialNumber = 0;
        if (serialNo == null || serialNo.trim().equals("")) {
            JOptionPane.showMessageDialog(this, "分类序号不能为空!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
            return;
        } else {
            try {
                serialNumber = Short.valueOf(serialNo);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(this, "分类序号必须为整数!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
        }
        if (this.flag == 0) {
            PLActionCls pac = new PLActionCls();
            pac.id = ObjectUtility.getNewObjectID36();
            pac.name = name;
            pac.pid = pid;
            pac.description = desc == null ? "" : desc;
            pac.creator = creator;
            pac.createTime = System.currentTimeMillis();
            pac.serialno = serialNumber;
            // 保存分类信息
            String message = UITools.getService().creaetePLActionCls(pac);
            if (message.startsWith("0")) {
                if (message.equals("01")) {
                    message = "分类" + pac.name + "已经存在!";
                } else if (message.equals("02")) {
                    message = "同一分类下序号不能重复!";
                } else {
                    message = "保存分类时发生异常!" + message.substring(1);
                }
                JOptionPane.showMessageDialog(this, message, "系统提示", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            JOptionPane.showMessageDialog(this, "分类创建成功!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
        } else {
            PLActionCls pac = this.currentCls;
            pac.name = name;
            pac.description = desc == null ? "" : desc;
            pac.serialno = serialNumber;
            // 保存分类信息
            String message = UITools.getService().editPLActionCls(pac);
            if (message.startsWith("0")) {
                if (message.equals("01")) {
                    message = "分类" + pac.name + "已经存在!";
                } else if (message.equals("02")) {
                    message = "同一分类下序号不能重复!";
                } else {
                    message = "保存分类时发生异常!" + message.substring(1);
                }
                JOptionPane.showMessageDialog(this, message, "系统提示", JOptionPane.INFORMATION_MESSAGE);
                return;
            }
            JOptionPane.showMessageDialog(this, "分类修改成功!", "系统提示", JOptionPane.INFORMATION_MESSAGE);
        }
        this.dispose();
        this.ok = true;
    }
 
    /**
     * 取消按钮事件
     */
    private void cancelAction() {
        this.dispose();
    }
 
    public boolean isOk() {
        return ok;
    }
 
    private String getNotNullString(String str) {
        if (str == null) {
            return "";
        }
        return str.trim();
    }
}