ludc
2025-01-16 986aa62ed00bee39363bab41b4eeb8259d446efd
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
package com.vci.client.framework.systemConfig.stafforgmanage;
 
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
 
import javax.swing.JOptionPane;
 
import com.vci.client.LogonApplication;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.framework.systemConfig.object.CombinationObject;
import com.vci.client.framework.systemConfig.object.CombinationValueObject;
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.components.VCIJComboBox;
 
public class CombinationValueActionListener implements ActionListener {
    private CombinationValueTablePanel combValPanel;
    private String optType;
    private CombinationObject combObject;
    
    public CombinationValueActionListener(CombinationValueTablePanel combValPanel,String optType){
        this.combValPanel = combValPanel;
        this.optType = optType;
    }
 
    
    @Override
    public void actionPerformed(ActionEvent e) {
        if (optType.equals("add")) {
            createButton_actionEvent();
        } else if (optType.equals("modify")) {
            editButton_actionEvent();
        } else if (optType.equals("delete")) {
            deleteButton_actionEvent();
        }  
    }
    /**
     * 添加
     * <p>Description: </p>
     * 
     * @author wangxl
     * @time 2013-1-3
     */
    private void createButton_actionEvent(){
        VCIJComboBox combox = combValPanel.getClassComBox();
           if(combox.getSelectedIndex() < 0){
               VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择组合方式");
               return;
        }
           String value = combValPanel.getValueText();
           boolean checkValue = checkValue(value);
           if (!checkValue) {
               return;
           }
        int length = value.length();
        ArrayList<CombinationValueObject> list = new ArrayList<CombinationValueObject>();
        for (int i = 0; i < length; i++) {
            String values = String.valueOf(value.charAt(i)).trim();
            if ("".equals(values)) {
                continue;
            }
            CombinationValueObject combValObject = new CombinationValueObject();
            combValObject.setValue(values);
            list.add(combValObject);
        }
        
        try {
            boolean rs = isCharacterHaveExist(list);
            if (rs) {
                return;
            }
            int size = list.size();
            CombinationValueObject[] addCombValObject = new CombinationValueObject[size];
            combObject = combValPanel.getCombinationObject();
            for (int i = 0; i < size; i++) {
               addCombValObject[i] = list.get(i);
               addCombValObject[i].setParentId(combObject.getId());
            }
            new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).saveCombinationValue(addCombValObject);
            combValPanel.initTableProperty(combObject.getId());
         } catch (VCIException e) {
             VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
         } 
    }
    /**
     * 修改
     * <p>Description: </p>
     * 
     * @author wangxl
     * @time 2013-1-3
     */
    private void editButton_actionEvent(){
         VCIJComboBox combox =     combValPanel.getClassComBox();
         if(combox.getSelectedIndex() < 0){
             VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择组合方式");
             return;
         }
         String value = combValPanel.getValueText();
         boolean checkValue = checkValue(value);
         if (!checkValue) {
             return;
         }
         CombinationValueObject combValObject = combValPanel.getCombinationValueObject();
         String oldValue = combValObject.getValue();//选到的值
         try {
            combValObject.setValue(value);
            if(!oldValue.equals(value)){               //add by liujw
                new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).updateCombinationValue(combValObject);
            }
            VCIOptionPane.showMessageDialog(combValPanel, "修改成功!");
        } catch (VCIException e) {
            combValObject.setValue(oldValue);
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
        }
         combObject = combValPanel.getCombinationObject();
         combValPanel.initTableProperty(combObject.getId());
         combValPanel.setValueText("");
    }
    /**
     * 删除
     * <p>Description: </p>
     * 
     * @author wangxl
     * @time 2013-1-3
     */
    private void deleteButton_actionEvent(){
        VCIJComboBox combox = combValPanel.getClassComBox();
        if(combox.getSelectedIndex() < 0){
          VCIOptionPane.showMessageDialog(LogonApplication.frame, "请选择组合方式");
          return;
        }
        CombinationValueObject combValObject = combValPanel.getCombinationValueObject();
        if(combValObject == null){
            JOptionPane.showMessageDialog(combValPanel,"请选择要删除的取值范围");
            return;
         }
        
        ArrayList<String> arrayListPuids = new ArrayList<String>(); //要删除的分割符id
        arrayListPuids.add(combValObject.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, "您确定要删除选中的组合方式取值范围吗?","提醒",VCIOptionPane.YES_NO_OPTION);
          if (i == 0){
              try {
                  new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).deletCombinationValues(puids);
            } catch (VCIException e) {
                VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework",e);
            } 
              combObject = combValPanel.getCombinationObject();
              combValPanel.initTableProperty(combObject.getId());
              combValPanel.setValueText("");
        } 
    }
    private boolean checkValue(String value) {
        if ("".equals(value)) {
            VCIOptionPane.showMessageDialog(combValPanel,"值不能为空,请填写!");
            return false;
        }
           if (optType.equals("modify")) {
            if (value.length() != 1) {
                VCIOptionPane.showMessageDialog(combValPanel, "一次只能修改一个对象,请重新选择!");
                return false;
            }
            
            CombinationValueObject obj = combValPanel.getCombinationValueObject();
             if (obj == null) {
                 VCIOptionPane.showMessageDialog(combValPanel, "请选择要修改的取值范围");
                 return false;
             }
           }
        return true;
    }
    
    /***
     * 
     * @param list    要添加的字符
     * @return  如果要添加的字符有的已经存在,则返回true,否则返回false
     */
    private boolean isCharacterHaveExist( ArrayList<CombinationValueObject> list) {
        int size = list.size();
        StringBuffer stringbuffer = new StringBuffer();
        for (int i = 0; i < size; i++) {
            String addValue = list.get(i).getValue();
            stringbuffer.append(addValue);
        }
        int stringbufferLength = stringbuffer.length();//要添加的数组间存不存在重复
        for (int i = 0; i < stringbufferLength - 1; i++) {
            String character = stringbuffer.substring(i, i+1);
            if (stringbuffer.toString().indexOf(character) !=  stringbuffer.toString().lastIndexOf(character)) {
                VCIOptionPane.showMessageDialog(LogonApplication.frame, "添加的 '" + character + "' 字符不能添加多个,请修改");
                 return true;
            }
        }
        return false;
    }
}