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
package com.vci.client.workflow.task;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.objects.UserObject;
import com.vci.client.framework.rightConfig.object.FunctionObject;
import com.vci.client.ui.swing.VCIOptionPane;
import com.vci.client.ui.swing.VCISwingUtil;
import com.vci.client.ui.swing.components.VCIJButton;
import com.vci.client.ui.swing.components.VCIJCalendarPanel;
import com.vci.client.workflow.delegate.ProcessCustomClientDelegate;
import com.vci.client.workflow.template.object.TasksAssignedObject;
import com.vci.common.utility.ObjectUtility;
import com.vci.corba.common.VCIError;
 
public class TasksAssignedPanel extends JPanel {
    /**
     * 指定代理任务人模块
     */
 
    private static final long serialVersionUID = 844086978269740691L;
    private VCIJButton btnClear = VCISwingUtil.createVCIJButton("", "清除", "清除", "clear.gif");
    private JButton addButton;
    private JLabel fromLabel = new JLabel("从  :");
    private JLabel JLbelName = new JLabel("委托给  :");
    private JLabel RadioJLbelName = new JLabel("是否生效:");
    private JTextField fromUser = new JTextField();
    private JTextField JTextName = new JTextField();
    private JButton fromChoice = new JButton("选择");
    private JButton choice = new JButton("选择");
    private JLabel JLbelstartTime = new JLabel("有效时间:从");
    private JLabel JLbelendTime = new JLabel("到");
    private VCIJCalendarPanel txtStartTime = new VCIJCalendarPanel("yyyy-MM-dd",false,false,false);
    private VCIJCalendarPanel txtEndTime = new VCIJCalendarPanel("yyyy-MM-dd",false,false,false);
    private JRadioButton jRadioButTrue = new JRadioButton();
    private JRadioButton jRadioButFalse = new JRadioButton();
    private JLabel hisTodoTaskDepute = new JLabel("待办任务委托:");
    private JRadioButton hisTodoTaskYes = new JRadioButton("是");
    private JRadioButton hisTodoTaskNo = new JRadioButton("否");
    private ButtonGroup bg = new ButtonGroup();
    private ButtonGroup hisTodoTaskBg = new ButtonGroup();
    
    private UserObject[] userObject;
    private boolean isTrue;//是否生效
    
    public boolean getIsTrue() {
        return isTrue;
    }
 
    public void setIsTrue(boolean isTrue) {
        this.isTrue = isTrue;
    }
    
    private static TasksAssignedPanel tasksAssignedPanel;
    static String querySQL = "";
    static String taskType ="";
    static FunctionObject object = new FunctionObject();
    public static TasksAssignedPanel getInstance(String taskType) {
//        if (trackTaskPanel == null) {
        tasksAssignedPanel = new TasksAssignedPanel(object,taskType);
//        }
        return tasksAssignedPanel;
    }
 
    private TasksAssignedPanel(FunctionObject object,String taskType) {
//        super(object);
        this.object = object;
        this.taskType = taskType;
        initUI();
    }
    private void initUI() {
        setLayout(new BorderLayout());
        JPanel palNorthBtn = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
        addButton = new JButton("保存");
        addButton.setIcon(VCISwingUtil.createImageIcon("add.png"));
        palNorthBtn.add(addButton);
        palNorthBtn.add(btnClear);
        JPanel CenterPanel = new JPanel();
        CenterPanel.setLayout(null);
        bg.add(jRadioButTrue);
        bg.add(jRadioButFalse);
        hisTodoTaskBg.add(hisTodoTaskYes);
        hisTodoTaskBg.add(hisTodoTaskNo);
        
//        fromLabel.setBounds(130, 50, 120, 30);
//        fromUser.setBounds(210, 50, 120, 30);
//        fromUser.setEditable(false);
//        fromChoice.setBounds(330, 50, 70, 30);
        
        JLbelName.setBounds(130, 50, 170, 30);
        JTextName.setBounds(210, 50, 170, 30);
        JTextName.setEditable(false);
        choice.setBounds(380, 50, 70, 30);
        
//        JLbelName.setBounds(420, 50, 120, 30);
//        JTextName.setBounds(530, 50, 120, 30);
//        JTextName.setEditable(false);
//        choice.setBounds(650, 50, 70, 30);
        
        JLbelstartTime.setBounds(130,100,150,30);
        txtStartTime.setBounds(210,100,180,30);
        JLbelendTime.setBounds(190,150,20,30);
        txtEndTime.setBounds(210,150,180,30);
        
        hisTodoTaskDepute.setBounds(130, 200, 180, 30);
        hisTodoTaskYes.setBounds(210, 200, 45, 25);
        hisTodoTaskNo.setBounds(270, 200, 45, 25);
        hisTodoTaskYes.setSelected(true);
        
        RadioJLbelName.setBounds(130, 200, 150, 30);
        jRadioButTrue.setBounds(210, 200, 45, 25);
        jRadioButFalse.setBounds(270, 200, 45, 25);
//        CenterPanel.add(fromLabel);
//        CenterPanel.add(fromUser);
//        CenterPanel.add(fromChoice);
        
        CenterPanel.add(JLbelName);
        CenterPanel.add(JTextName);
        CenterPanel.add(choice);
        
        CenterPanel.add(JLbelstartTime);
        CenterPanel.add(txtStartTime);
        CenterPanel.add(JLbelendTime);
        CenterPanel.add(txtEndTime);
        CenterPanel.add(RadioJLbelName);
        CenterPanel.add(jRadioButTrue);
        
//        CenterPanel.add(hisTodoTaskDepute);
//        CenterPanel.add(hisTodoTaskYes);
//        CenterPanel.add(hisTodoTaskNo);
        
        jRadioButTrue.setText("是");
        jRadioButFalse.setText("否");
        jRadioButFalse.setSelected(true);
        CenterPanel.add(jRadioButFalse);
        add(CenterPanel, BorderLayout.CENTER);
        
        JPanel southPanel = new JPanel(new BorderLayout());
        southPanel.add(palNorthBtn,BorderLayout.NORTH);
        add(southPanel, BorderLayout.SOUTH);
        addListener();
        init();
    }
 
    private void addListener() {
        addButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                add_ActionPerformed();
                //如果是生效,并且委托待办任务
                if(jRadioButTrue.isSelected()){
                    if(hisTodoTaskYes.isSelected()){
//                        new .assignTask(userName);
                        ProcessCustomClientDelegate processCustomClientDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
                        processCustomClientDelegate.assignTask(LogonApplication.getUserEntityObject().getUserName(), JTextName.getText());
                    }
                    
                }
            }
        });
//        fromChoice.addActionListener(new ActionListener() {
//            @Override
//            public void actionPerformed(ActionEvent e) {
//                fromChoice_ActionPerformed();
//                }
//            });
        choice.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                choice_ActionPerformed();
            }
        });
        btnClear.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                clear_ActionPerformed();
            }
        });
    }
 
    public void init(){
        TasksAssignedObject obj;
        ProcessCustomClientDelegate processCustomClientDelegate = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
        try {
            obj = processCustomClientDelegate.getTasksAssignedByUserName("");
            if(obj.getId() != ""&& obj.getId() != null){
                String user = obj.getTasksName();
                user.split(",");
//                userObject = new UserObject();
//                userObject.setUserName(obj.getUserName());
//                userObject.setTrueName(obj.getTasksTrueName());
//                userObject.setId(obj.getTasksId());
//                fromUser.setText(obj.getFromUser());
//                JTextName.setText(userObject.getTrueName());
                JTextName.setText(obj.getTasksName());
                txtStartTime.setDate(obj.getStartTime());
                txtEndTime.setDate(obj.getEndTime());
                if(obj.getIsTrue()){
                    jRadioButTrue.setSelected(true);
                }else{
                    jRadioButFalse.setSelected(true);
                }
                if(obj.getTasksName().contains(",")){
                    String[] userName = obj.getTasksName().split(",");
                    userObject = new UserObject[userName.length];
                    for(int i = 0;i<userName.length;i++){
                        userObject[i] = new UserObject();
                        userObject[i].setUserName(userName[i]);
                    }
                }else{
                    userObject = new UserObject[1];
                    userObject[0] = new UserObject();
                    userObject[0].setUserName(obj.getTasksName());
                }
            }
            
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
//    private void fromChoice_ActionPerformed() {
//        TaskAssignedDialog dialog = new TaskAssignedDialog(LogonApplication.frame);
//        userObject = dialog.getProcessDefinitionObject();
//        if(userObject == null) {
//            fromUser.setText("");
//        }else
//            fromUser.setText(getTasksName(userObject));
//        
//    }
    private void choice_ActionPerformed() {
        TaskAssignedDialog dialog = new TaskAssignedDialog(LogonApplication.frame);
        userObject = dialog.getProcessDefinitionObject();
        if(userObject == null) {
            JTextName.setText("");
        }else
            JTextName.setText(getTasksName(userObject));
        
    }
    private void add_ActionPerformed() {
        if(!jRadioButTrue.isSelected()&&!jRadioButFalse.isSelected()) {
            JOptionPane.showMessageDialog(LogonApplication.frame, "请选择是否生效");
            return;
        }
//        if("".equals(fromUser.getText())){
//            JOptionPane.showMessageDialog(LogonApplication.frame, "请选择被委托任务人");
//            return;
//        }
        if("".equals(JTextName.getText())){
            JOptionPane.showMessageDialog(LogonApplication.frame, "请选择代办人");
            return;
        }
        if(txtStartTime.getDateString() == null ||txtEndTime.getDateString() ==null
                || "".equals(txtStartTime.getDateString()) || "".equals(txtEndTime.getDateString())){
            JOptionPane.showMessageDialog(LogonApplication.frame, "请选择开始日期或结束日期!");
            return;
        }
//        String name = JTextName.getText();
        if(jRadioButTrue.isSelected()){
            setIsTrue(true);//生效
        }else setIsTrue(false);//不生效
        TasksAssignedObject tasksObject = new TasksAssignedObject();
        if(userObject != null){
            String ploid = ObjectUtility.getNewObjectID36();
            tasksObject.setId(ploid);
            tasksObject.setIsTrue(isTrue);
            tasksObject.setUserName(LogonApplication.getUserEntityObject().getUserName());
//            tasksObject.setTasksId(userObject[0].getId());
            tasksObject.setTasksName(getTasksName(userObject));
//            tasksObject.setTasksTrueName(name);
            tasksObject.setStartTime(txtStartTime.getDate());
            tasksObject.setEndTime(txtEndTime.getDate());
            tasksObject.setFromUser(LogonApplication.getUserEntityObject().getUserName());
        }
        ProcessCustomClientDelegate processDel = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
        try {
            boolean res = processDel.saveOrUpdateTasksAssigned(tasksObject);
            if(res) {
                JOptionPane.showMessageDialog(this, "保存成功");
            }
        } catch (VCIError e) {
            e.printStackTrace();
        }
    }
    private void clear_ActionPerformed(){
        if(VCIOptionPane.showQuestion(this, "你确定要删除设置的代办人吗?") != 0) return;
        ProcessCustomClientDelegate processDel = new ProcessCustomClientDelegate(LogonApplication.getUserEntityObject());
        try{
            String[] s = new String[1];
            s[0] = LogonApplication.getUserEntityObject().getUserName();
            boolean res = processDel.deleteTasksAssignedByUserName(s);
            if(res) {
                JOptionPane.showMessageDialog(this, "清除成功");
                JTextName.setText("");
                txtStartTime.setDateString();
                txtEndTime.setDateString();
                jRadioButTrue.setSelected(false);
                jRadioButFalse.setSelected(true);
                hisTodoTaskYes.setSelected(true);
            }
        } catch(VCIError e){
            e.printStackTrace();
        }
    }
//    public List<UserObject> getSelectedUsers() {
//        List<UserObject> list = new ArrayList<UserObject>();
//        UserObject[] object = new UserObject[]{};
//        RightManagementClientDelegate del = new RightManagementClientDelegate();
//        try {
//            object = del.fetchUserInfo();
//        } catch (VCIException e) {
//            e.printStackTrace();
//        }
//        for(UserObject obj : object){
//            list.add(obj);
//        }
//        return list;
//    }
    private String getTasksName(UserObject[] object){
        String userName = "";
        for(int i = 0 ;i<object.length;i++){
            if(i+1 == object.length){
                userName += object[i].getUserName();
                break;
            }
            userName += object[i].getUserName()+",";
        }
        return userName;
    }
}