dangsn
2024-12-26 4e9ff2ce6a830bb2340d7c8612c72eea0c5a553e
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
package com.vci.client.framework.rightConfig.operate;
 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
 
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFileChooser;
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 javax.swing.tree.TreePath;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.TransmitTreeObject;
import com.vci.client.framework.delegate.OperateClientDelegate;
import com.vci.client.framework.rightConfig.object.OperateObject;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.image.BundleImage;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.KTextField;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.tree.VCIBaseTreeNode;
 
/**
 * 操作类型的管理是初始化系统中每个功能模块所具有的操作的集合。
 * 
 * @author
 */
public class OperateMangePanel extends JPanel {
 
    private static final long serialVersionUID = -3826623955360533220L;
    private final OperateClientDelegate modelDelegate = new OperateClientDelegate(LogonApplication.getUserEntityObject());
    private JLabel operateLab = new JLabel();
    private JLabel nameLab = new JLabel();
    private KTextField nameText = new KTextField();
    private JLabel identifyLab = new JLabel();
    private KTextField identifyText = new KTextField();
    private JLabel aliasLab = new JLabel();
    private KTextField aliasText = new KTextField();
    private JLabel seqLab = new JLabel("顺序");
    private KTextField seqText = new KTextField();
    private JLabel describeLab = new JLabel();
    private JTextArea describeTxtArea = new JTextArea();
    private JButton addButton = new JButton();
    private JButton updateButton = new JButton();
    private JButton delButton = new JButton();
    private JButton exportSqlButton = new JButton("导出sql");
    private JTextField top = new JTextField();// 横线
    private JTextField bottom = new JTextField();// 横线
    private TransmitTreeObject transmitTreeObject = new TransmitTreeObject();// 传递树的信息
    
    // 控件的坐标位置变量
    private int x = 10;
    private int y = 20;
    private int width = 50;
    private int height = 25;
    /**
     * 两控件间水平间隔
     */
    private int hspan = 5;
 
    private OperateClientDelegate operateClient = new OperateClientDelegate(LogonApplication.getUserEntityObject());
 
    public OperateMangePanel(Object obj,TransmitTreeObject transmitTreeObject) {
        super();
        this.transmitTreeObject = transmitTreeObject;
        init();
        if (obj instanceof OperateObject) {
            initData((OperateObject)obj);
        }
        this.setOpaque(false);
    }
 
    public void init(){
        JPanel palMain = new JPanel();
        JPanel contentPanel = new JPanel();
        JPanel buttonPanel = new JPanel();
        palMain.setLayout(new BorderLayout());
        
        operateLab.setIcon(new BundleImage().createImageIcon("codevalue.gif"));
        operateLab.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.operateTypeLab.file","RMIPFramework", getLocale()));
        operateLab.setBounds(new Rectangle(0, 0, 30, 25));
        
        contentItem(contentPanel);
        jButtonPanl(buttonPanel);
        
        palMain.add(operateLab,BorderLayout.NORTH);
        palMain.add(contentPanel, BorderLayout.CENTER);
        palMain.add(buttonPanel, BorderLayout.SOUTH);
        this.setLayout(new BorderLayout());
        this.add(palMain, BorderLayout.CENTER);
    }
 
    private void initData(OperateObject obj){
        nameText.setText(obj.getName());
        identifyText.setText(obj.getIdentify());
        aliasText.setText(obj.getAlias());
        seqText.setText(String.valueOf(obj.getSequence()));
        describeTxtArea.setText(obj.getDesc());
        addButton.setEnabled(false); // 按钮失效
        updateButton.setEnabled(true); // 显示按钮
        delButton.setEnabled(true); // 显示按钮
    }
    
 
    /**
     * 按钮
     * 
     * @return
     */
    public void jButtonPanl(JPanel p) {
 
        addButton.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.addButton.file", "RMIPFramework",getLocale()));
        addButton.setIcon(new BundleImage().createImageIcon("create.gif"));
        addButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                if (!"operateNode".equals(transmitTreeObject.getCurrentTreeNode().getObj())) {
                    message("请选择操作类型节点","RMIPFramework");
                    return;
                }
                if (checkItem()) {
                    return;
                }
                try {
                    OperateObject ot = getValue();
                    String s = operateClient.saveOperate(ot);
                    /**返回1表示名称有重复,返回2表示标识有重复,返回3表示顺序有重复**/
                    if(s.equals("1")){
                        message("rmip.framework.operateType.nameIsExist.message","RMIPFramework");
                        return;
                    }else if(s.equals("2")){
                        message("rmip.framework.operateType.identifyingIsExist.message","RMIPFramework");
                        return;
                    }else if (s.equals("3")){
                        VCIOptionPane.showMessage(LogonApplication.frame, "操作的顺序值已经存在,保存失败");
                        return;
                    }
                    ot.setId(s);
                    if (!s.equals("") && s != null) {
                        updateTreeData("add", ot);
                    } else {
                        message("rmip.framework.operateType.savefail.message","RMIPFramework");
                    }
                } catch (VCIException e1) {
                    e1.printStackTrace();
                    VCIOptionPane.showError(LogonApplication.frame,LocaleDisplay.getI18nString(e1, "RMIPFramework", getLocale()));
                    return;
                }
            }
 
        });
        updateButton.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.updateButton.file","RMIPFramework", getLocale()));
        updateButton.setIcon(new BundleImage().createImageIcon("modify.gif"));
        updateButton.addActionListener(new ActionListener() {
 
            public void actionPerformed(ActionEvent e) {
                if (checkItem()) {
                    return;
                }
                OperateObject ot = getValue();
                Object obj = transmitTreeObject.getCurrentTreeNode().getObj();
                if(obj instanceof OperateObject){
                    ot.setId(((OperateObject) obj).getId());
                }
                try {
                    String res = operateClient.updateOperate(ot);
                    /**返回1表示名称有重复,返回2表示标识有重复,返回3表示顺序有重复**/
                    if(res.equals("1")){
                        message("rmip.framework.operateType.nameIsExist.message","RMIPFramework");
                        return;
                    }else if(res.equals("2")){
                        message("rmip.framework.operateType.identifyingIsExist.message","RMIPFramework");
                        return;
                    }else if (res.equals("3")){
                        VCIOptionPane.showMessage(LogonApplication.frame, "操作的顺序值已经存在,保存失败");
                        return;
                    }
                    message("rmip.framework.operateType.updatesusses.message","RMIPFramework");
                    updateTreeData("modify", ot);
                } catch (VCIException e1) {
                    e1.printStackTrace();
                    VCIOptionPane.showError(LogonApplication.frame,LocaleDisplay.getI18nString(e1, "RMIPFramework", getLocale()));
                    return;
                }
            }
        });
        delButton.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.delButton.file", "RMIPFramework",getLocale()));
        delButton.setIcon(new BundleImage().createImageIcon("delete.gif"));
        delButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                OperateObject curObj = (OperateObject)transmitTreeObject.getCurrentTreeNode().getObj();
                try {
                    /**检查当前操作是否被引用,0表示无引用,1表示被模块引用,2表示已有权限信息**/
                    int res = operateClient.checkOperateIsReferenced(curObj.getId());
                    int ok = -1;
                    if(res == 1){
                        ok = VCIOptionPane.showQuestion(LogonApplication.frame, "当前操作已被模块引用,删除该操作的同时会将其从模块下移除,确认执行删除吗?");
                    }else if(res == 2){
                        ok = VCIOptionPane.showQuestion(LogonApplication.frame, "当前操作已经在权限模块被分配过权限,删除该操作的同时会将其从用户的权限中移除,确认执行删除吗?");
                    }else{
                        ok = VCIOptionPane.showQuestion(LogonApplication.frame, "确认执行删除吗?");
                    }
                    if(ok != 0){
                        return;
                    }
                    boolean success = operateClient.deleteOperate(curObj.getId());
                    if(success){
                        VCIBaseTreeNode parentNode = (VCIBaseTreeNode)transmitTreeObject.getCurrentTreeNode().getParent();
                        transmitTreeObject.getTreeModel().removeNodeFromParent(transmitTreeObject.getCurrentTreeNode());
                        transmitTreeObject.getTree().setSelectionPath(new TreePath(parentNode.getPath()));
                    }
                } catch (VCIException e1) {
                    e1.printStackTrace();
                    VCIOptionPane.showError(LogonApplication.frame,LocaleDisplay.getI18nString(e1, "RMIPFramework", getLocale()));
                }
            }
        });
        updateButton.setEnabled(false); // 按钮失效
        delButton.setEnabled(false); // 按钮失效
        exportSqlButton.addActionListener(new ActionListener() {
            
            @Override
            public void actionPerformed(ActionEvent arg0) {
                // TODO Auto-generated method stub
                exportTxt();
            }
        }); 
        p.add(addButton);
        p.add(updateButton);
        p.add(delButton);
        p.add(exportSqlButton);
    }
    //add by caill Start 2015.12.11 为操作类型添加导出sql功能
        public void exportTxt(){
            int size = 0;        
                try {
                    size = modelDelegate.getAllOperitionsNum();
                } catch (VCIException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                System.out.println("size = "+size);
                String[][] plDatas = new String[size][6];
                try {
                    plDatas = modelDelegate.getAllOperitions(size);
                } catch (VCIException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                //modelDelegate.checkLevel();
        
            JFileChooser fileChooser = new JFileChooser();
            fileChooser.setDialogTitle("导出sql");
            fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            fileChooser.setApproveButtonText("导出");
            int result = fileChooser.showOpenDialog(this);
            if(result == JFileChooser.APPROVE_OPTION){
                String dir = fileChooser.getSelectedFile().getAbsolutePath();
                if(expData(dir,plDatas)==true){
                    JOptionPane.showMessageDialog(this, "导出成功", "导出成功", JOptionPane.INFORMATION_MESSAGE);
                }else{
                    JOptionPane.showMessageDialog(this, "导出失败", "导出失败", JOptionPane.INFORMATION_MESSAGE);
                }
                
            }
        }
        public boolean expData(String dir, String[][] plDatas){
            new File(dir).mkdir();
            File file = new File(dir + "/ploperation.sql");
            try {
                FileWriter w = new FileWriter(file);
                BufferedWriter bw = new BufferedWriter(w);
                for(int i=0;i<plDatas.length;i++){
                        bw.write("insert into ploperation values('"+plDatas[i][0]+"','"+plDatas[i][1]+"',"+"'"+plDatas[i][2]+"',"+"'"+plDatas[i][3]+"',"+"'"+plDatas[i][4]+"',"
                                +"'"+plDatas[i][5]+"');");
                        bw.write("\r\n");        
                }
                bw.flush();
                bw.close();
                return true;
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return false;
        }
        
        //add by caill end
    /**
     * 获取页面的值
     * 
     * @return
     */
    private OperateObject getValue() {
        OperateObject ot = new OperateObject();
        ot.setName(nameText.getText());
        ot.setIdentify(identifyText.getText());
        ot.setAlias(aliasText.getText());
        ot.setDesc(describeTxtArea.getText());
        ot.setSequence(Integer.valueOf(seqText.getText()));
        return ot;
    }
 
    /**
     * 内容项
     * 
     * @return
     */
    public void contentItem(JPanel p) {
        JPanel panel = new JPanel();
        
        top.setPreferredSize(new Dimension(63,2));
        bottom.setPreferredSize(new Dimension(63,2));
        
        x = 30;y = 30;width = 80;height = 25;
        nameLab.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.designationLab.file","RMIPFramework", getLocale()));
        nameLab.setBounds(new Rectangle(x, y, width, height));
 
        x += nameLab.getWidth() + hspan;y = 30;width = 200;height = 25;
        nameText.setBounds(new Rectangle(x, y, width, height));
 
        x = 30;y = 70;width = 80;height = 25;
        identifyLab.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.identifyingLab.file","RMIPFramework", getLocale()));
        identifyLab.setBounds(new Rectangle(x, y, width, height));;
        
        x += identifyLab.getWidth() + hspan;y = 70;width = 200;height = 25;
        identifyText.setBounds(new Rectangle(x, y, width, height));
 
        x = 30;y = 110;width = 80;height = 25;
        aliasLab.setText("别名");
        aliasLab.setBounds(new Rectangle(x, y, width, height));
        
        x += aliasLab.getWidth() + hspan;y = 110;width = 200;height = 25;
        aliasText.setBounds(new Rectangle(x, y, width, height));
        
        x = 30;y = 150;width = 80;height = 25;
        seqLab.setBounds(new Rectangle(x, y, width, height));
        x += seqLab.getWidth() + hspan;y = 150;width = 200;height = 25;
        seqText.setBounds(new Rectangle(x, y, width, height));
        
        x = 30;y = 190;width = 80;height = 25;
        describeLab.setText(LocaleDisplay.getI18nString("rmip.framework.operateType.describeLab.file", "RMIPFramework",getLocale()));
        describeLab.setBounds(new Rectangle(x, y, width, height));
 
        x += describeLab.getWidth() + hspan;y = 190;width = 200;height = 100;
        JScrollPane scroll = new JScrollPane(describeTxtArea);
        scroll.setBounds(new Rectangle(x, y, width, height));
        describeTxtArea.setLineWrap(true);
        
        panel.setLayout(null);
        panel.add(nameLab);
        panel.add(nameText);
        panel.add(identifyLab);
        panel.add(identifyText);
        panel.add(aliasLab);
        panel.add(aliasText);
        panel.add(seqLab);
        panel.add(seqText);
        panel.add(describeLab);
        panel.add(scroll);
        
        p.setLayout(new BorderLayout());
        p.add(top,BorderLayout.NORTH);
        p.add(panel,BorderLayout.CENTER);
        p.add(bottom,BorderLayout.SOUTH);
    }
 
    /**
     * 校验
     * 
     * @return
     */
    public boolean checkItem() {
        if (nameText.getText() == null|| "".equals(nameText.getText())) {
            message("rmip.framework.operateType.designationTextNotNull.message","RMIPFramework");
            nameText.requestFocus();
            return true;
        }
        if (identifyText.getText() == null|| "".equals(identifyText.getText())) {
            message("rmip.framework.operateType.identifyingIsChoice.message","RMIPFramework");
            identifyText.requestFocus();
            return true;
 
        }
        if (aliasText.getText() == null|| "".equals(aliasText.getText())) {
            message("rmip.framework.operateType.aliasTextNotNull.message","RMIPFramework");
            identifyText.requestFocus();
            return true;
            
        }
        if (seqText.getText().equals("")){
            VCIOptionPane.showMessage(this, "请输入操作的顺序值!");
            seqText.requestFocus();
            return true;
        }
        String seq = seqText.getText();
        Pattern pattern = Pattern.compile("[0-9]*"); 
        Matcher isNum = pattern.matcher(seq);
        if( !isNum.matches() ){
            VCIOptionPane.showMessageDialog(LogonApplication.frame ,"操作的顺序值只能是[0-9]之间的数字,并且必须是正整数.\n长度不允许输入小数或者负数!");
            return true; 
        }
        if (nameText.getText().length() > 128) {
            message("rmip.framework.operateType.designationTextLength.message","RMIPFramework");
            return true;
        }
        if (describeTxtArea.getText().length() > 255) {
            message("rmip.framework.operateType.describeTextAreaLength.message","RMIPFramework");
            return true;
        }
        if (aliasText.getText().length() > 128) {
            message("rmip.framework.operateType.aliasTextLength.message","RMIPFramework");
            return true;
        }
        return false;
    }
    
    private void message(String key,String file){
        String msg = LocaleDisplay.getI18nString(key,file,getLocale());
        VCIOptionPane.showMessage(LogonApplication.frame, msg);
    }
 
    // 更新树
    private void updateTreeData(String identifer, OperateObject ot) {
        if (identifer.equals("add")) {// 添加
            VCIBaseTreeNode addTreeNode = new VCIBaseTreeNode(ot.getName(), ot);
            addTreeNode.setLeaf(true);
            transmitTreeObject.getCurrentTreeNode().setLeaf(false);
            if(transmitTreeObject.getCurrentTreeNode().isExpand()){
                transmitTreeObject.getTreeModel().insertNodeInto(addTreeNode,transmitTreeObject.getCurrentTreeNode(),transmitTreeObject.getCurrentTreeNode().getChildCount());
                transmitTreeObject.getTree().setSelectionPath(new TreePath(addTreeNode.getPath()));// 设置路径
            }else{
                transmitTreeObject.getTree().expandPath(new TreePath(transmitTreeObject.getCurrentTreeNode().getPath()));
                transmitTreeObject.getTree().setSelectionPath(new TreePath(transmitTreeObject.getCurrentTreeNode().getPath()));
            }
        }
        if (identifer.equals("modify")) {// 修改
            transmitTreeObject.getCurrentTreeNode().setObj(ot);
            transmitTreeObject.getCurrentTreeNode().setUserObject(ot.getName());
            transmitTreeObject.getTreeModel().nodeChanged(transmitTreeObject.getCurrentTreeNode());
        }
    }
 
}