wangting
2024-12-26 fa261e8c1220b31af54e8167e4de9c3320b1af27
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
package com.vci.client.framework.systemConfig.specialCharacter;
 
 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.Locale;
 
import javax.swing.JOptionPane;
 
import com.vci.client.LogonApplication;
import com.vci.client.framework.delegate.SystemCfgClientDelegate;
import com.vci.client.framework.systemConfig.object.SpecialCharClsfObject;
import com.vci.client.framework.systemConfig.object.SpecialCharObject;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.components.VCIJComboBox;
 
 
/***
 * 特殊字符
 * @author Administrator
 *
 */
public class SpecialCharacterActionListener  implements ActionListener{
    
    /****************************国际化信息**********************************/
    //要修改的值只能是一个字符!
    private String MODIFYALERT2 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.modifyCharAlert2", "RMIPFramework",Locale.getDefault());
    //请选中要修改的字符进行修改操作!
    private String MODIFYALERT3 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.modifyCharAlert3", "RMIPFramework",Locale.getDefault());
    //值不能为空!
    private String VALUEALERT = LocaleDisplay.getI18nString("rmip.framework.sysconfig.valueAlert", "RMIPFramework",Locale.getDefault());
    //添加的 '
    private String ADDALERT1 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.addCharAlert1", "RMIPFramework",Locale.getDefault());
    //' 字符不能添加多个,请修改!
    private String ADDALERT2 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.addCharAlert2", "RMIPFramework",Locale.getDefault());
    //修改成功!
    private String MODIFYSUCCESS = LocaleDisplay.getI18nString("rmip.framework.sysconfig.modifySuccess", "RMIPFramework",Locale.getDefault());
    //请选择要删除的字符!
    private String DELETEALERT1 = LocaleDisplay.getI18nString("rmip.framework.sysconfig.deleteCharAlert1", "RMIPFramework",Locale.getDefault());
    //您确定要删除选中的字符吗?
    private String DELETECONFIRM = LocaleDisplay.getI18nString("rmip.framework.sysconfig.deleteConfirm", "RMIPFramework",Locale.getDefault());
    //温馨提示
    private String WARMTIP = LocaleDisplay.getI18nString("rmip.framework.sysconfig.warmTip", "RMIPFramework",Locale.getDefault());
    
    private SpecialCharacterPanel characterPanel = null;
    private String type = "";  //相应类型  添加:add  修改:modify   删除delete
    private SpecialCharClsfObject obj;
 
    public SpecialCharacterActionListener(SpecialCharacterPanel characterPanel , String type ) {
        this.characterPanel = characterPanel;
        this.type = type;
    }
 
    public void actionPerformed(ActionEvent e) {
        if (type.equals("add")) {
            createCharacterButton_actionEvent();
        } else if (type.equals("modify")) {
            editCharacterButton_actionEvent();
        }  else if (type.equals("delete")) {
            deleteCharacterButton_actionEvent();
        }  
        
    }
    
    private boolean checkValue() {
        String value = characterPanel.getValueText();
        if ("".equals(value)) {
            VCIOptionPane.showMessageDialog(characterPanel,VALUEALERT);
            return false;
        }
           if (type.equals("modify")) {
            if (value.length() != 1) {
                VCIOptionPane.showMessageDialog(characterPanel, MODIFYALERT2);
                return false;
            }
            SpecialCharObject specialCharObject = characterPanel.getSpecialCharObject();
            if (specialCharObject == null) {
                 VCIOptionPane.showMessageDialog(characterPanel, MODIFYALERT3);
                 return false;
            }
           }
        return true;
    }
    
    /***
     * 添加特殊字符
     *
     */
     private void createCharacterButton_actionEvent() {
         VCIJComboBox combox =     characterPanel.getClassComBox();
         if(combox.getSelectedIndex() < 0){
             VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择分类");
             return;
         }
         String value = characterPanel.getValueText();
         boolean checkValue = checkValue();
         if (!checkValue) {
             return;
         }
         int length = value.length();
         ArrayList<SpecialCharObject> list = new ArrayList<SpecialCharObject>();
         for (int i = 0; i < length; i++) {
             String values = String.valueOf(value.charAt(i)).trim();
             if ("".equals(values)) {
                 continue;
             }
             SpecialCharObject specialCharObject = new SpecialCharObject();
             specialCharObject.setValue(values);
             list.add(specialCharObject);
         }
         
         try {
             SpecialCharClsfObject clsfObj = (SpecialCharClsfObject) combox.getSelectedItem();
             String plsfoId = clsfObj.getId();
             boolean rs = isCharacterHaveExist(list, plsfoId);
             if (rs) {
                 return;
             }
             int size = list.size();
             SpecialCharObject[] addSpecialCharObject = new SpecialCharObject[size];
             obj = characterPanel.getSpecialCharClsfObject();
             for (int i = 0; i < size; i++) {
                 addSpecialCharObject[i] = list.get(i);
                 addSpecialCharObject[i].setParentId(obj.getId());
             }
             new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).saveSpecialChar(addSpecialCharObject);
             characterPanel.initTableProperty(obj.getId());
         } catch (VCIException e) {
             VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
         } 
          
     }    
     
     /***
      * 
      * @param list    要添加的字符
      * @return  如果要添加的字符有的已经存在,则返回true,否则返回false
      */
     private boolean isCharacterHaveExist(ArrayList<SpecialCharObject> list,String plsfoId) {
         int size = list.size();
         int count=0;
         
         SpecialCharObject[] specialCharObjects = new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).getBychar(plsfoId);
          ArrayList<String> importValues = new ArrayList<String>();
         for (int i = 0; i < list.size(); i++) {
             //判断输入字符中是否包含重复值
             if(importValues.contains(list.get(i).getValue())){
                 return true;
             }
             importValues.add(list.get(i).getValue());
            if(specialCharObjects.length>0){
                    for (int t = 0; t < specialCharObjects.length; t++) {
                        if(list.get(i).getValue().equals(specialCharObjects[t].getValue())){
                            
                            count+=1;
                        }
                        
                    }
                    
                }
        }
        if(count>0){
            
            return true;
        }else{
            return false;
        }
         
         
     }
    
     /***
      * 修改监听事件
      *
      */
     private void editCharacterButton_actionEvent() {
         VCIJComboBox combox =     characterPanel.getClassComBox();
         if(combox.getSelectedIndex() < 0){
             VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择分类");
             return;
         }
         String value = characterPanel.getValueText();
         boolean checkValue = checkValue();
         if (!checkValue) {
             return;
         }
        
         SpecialCharObject specialCharObject = characterPanel.getSpecialCharObject();
         String oldValue = specialCharObject.getValue();
         try {
            specialCharObject.setValue(value);
            
             //add by liujw
            if(!oldValue.equals(value)){              
                new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).updateSpecialChar(specialCharObject);
            }
            VCIOptionPane.showMessageDialog(LogonApplication.frame, MODIFYSUCCESS);
        } catch (VCIException e) {
            specialCharObject.setValue(oldValue);
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
        }
        obj = characterPanel.getSpecialCharClsfObject();
        characterPanel.initTableProperty(obj.getId());
        characterPanel.setValueText("");
     }
        
     /***
      * 删除监听事件
      *
      */
     private void deleteCharacterButton_actionEvent(){
         VCIJComboBox combox =     characterPanel.getClassComBox();
         if(combox.getSelectedIndex() < 0){
             VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择分类");
             return;
         }
        SpecialCharObject specialCharObject = characterPanel.getSpecialCharObject();
        if(specialCharObject == null){
            JOptionPane.showMessageDialog(LogonApplication.frame,DELETEALERT1);
            return;
         }
        
        ArrayList<String> arrayListPuids = new ArrayList<String>(); //要删除的分割符id
        arrayListPuids.add(specialCharObject.getId());
        String[] puids=new String[arrayListPuids.size()];
        for(int i=0;i<puids.length;i++){
            puids[i]=arrayListPuids.get(i);
        }
        int i = VCIOptionPane.showConfirmDialog(null, DELETECONFIRM,WARMTIP,VCIOptionPane.YES_NO_OPTION);
           if (i == 0){
               try {
                   new SystemCfgClientDelegate(LogonApplication.getUserEntityObject()).deletSpecialChar(puids);
            } catch (VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
            } 
               obj = characterPanel.getSpecialCharClsfObject();
               characterPanel.initTableProperty(obj.getId());
            characterPanel.setValueText("");
         } 
     }
    
 
}