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
package com.vci.client.framework.specialrole;
 
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
 
import com.vci.client.LogonApplication;
import com.vci.client.common.objects.DeptObject;
import com.vci.client.common.objects.UserObject;
import com.vci.client.framework.delegate.RightManagementClientDelegate;
import com.vci.client.logon.base.BaseJDialog;
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.VCIOptionPane;
 
/**
 * <p>Title: DeptingDialog</p>
 * <p>Description:为人员分配部门 </p>
 * <p>Copyright: Copyright (c) 2012</p>
 * <p>Company: VCI</p>
 * @author wangxl
 * @time 2012-5-13
 * @version 1.0
 */
public class DeptingDialog extends BaseJDialog{
 
    private static final long serialVersionUID = 1L;
    private JLabel deptLabel = new JLabel();
    private JComboBox departmentComBox = new JComboBox(); 
    private JButton conformBut = new JButton(LocaleDisplay.getI18nString("rmip.stafforg.operate.conform", "RMIPFramework", getLocale()));
    private JButton cancelBut = new JButton(LocaleDisplay.getI18nString("rmip.stafforg.operate.cancel", "RMIPFramework", getLocale()));
    private UserTablePanel userPanel;
    private UserObject userObj;
    
    public DeptingDialog(UserTablePanel userPanel ,UserObject userObj){
        super(LogonApplication.frame);
        this.userObj = userObj;
        this.userPanel = userPanel;
        this.setModal(true);
        init();
    }
     
    
    /**
     * 初始化界面
     */
    private void init() {
         JLabel titleLabel = new JLabel();
         titleLabel.setText("分配部门");
         titleLabel.setIcon(new BundleImage().createImageIcon ("book.png"));
         JPanel bottomPanel = new JPanel();
         bottomPanel.add(conformBut);
         bottomPanel.add(cancelBut);
         
         JPanel contentPanel = initCenterContentPanel();
//         initRole(); //初始化角色信息
         JPanel midPanel = new JPanel();
         midPanel.setLayout(new BorderLayout());
 
         midPanel.add(contentPanel, BorderLayout.CENTER);
         
         this.setLayout(new BorderLayout());
         this.add(titleLabel, BorderLayout.NORTH);
         this.add(midPanel, BorderLayout.CENTER);
         this.add(bottomPanel, BorderLayout.SOUTH); 
         initDialogSize(610, 550);
         this.setVisible(true);
    }
    
    private JPanel initCenterContentPanel() {
        JPanel contentPanel = new JPanel();
        contentPanel.setLayout(null);
        
        deptLabel.setText("所属部门:");
        deptLabel.setBounds(60, 30, 60, 25);
        
        departmentComBox.setBounds(130, 30, 150, 25);
        initDepartment();
        
        conformBut.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(ActionEvent e) {
                addButton_actionPerformed();
            }
        });
        
        cancelBut.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                cancelCreate();
            }
        });
        contentPanel.add(deptLabel);
        contentPanel.add(departmentComBox);
        return contentPanel;
        
    }
    
    private void addButton_actionPerformed() {
       String deptId = "";
       if (departmentComBox.getSelectedItem() instanceof DeptObject){
           deptId = ((DeptObject)departmentComBox.getSelectedItem()).getId() == null ? "" : ((DeptObject)departmentComBox.getSelectedItem()).getId() ;
       }
       try{
           new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
                   .saveUserDept(new String[]{userObj.getId()},deptId);
           
       }catch(VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame,"RMIPFramework",e);
            return ;
        }
       userPanel.tablePanel.refreshTableData();
       this.dispose();
    }
    
    public void cancelCreate(){
        this.dispose();
    }
    
    /**
     * 初始化部门
     *
     */
    private void initDepartment() {
        try {
            departmentComBox.addItem(new DeptObject());
            DeptObject[] departmentInfo = new RightManagementClientDelegate(LogonApplication.getUserEntityObject()).fetchDepartmentInfo();
            int size = departmentInfo.length;
            for (int i = 0; i < size; i++) {
                departmentComBox.addItem(departmentInfo[i]);
            }
            DeptObject userDeptObj = new RightManagementClientDelegate(LogonApplication.getUserEntityObject())
                                           .fetchDeptByUserId(userObj.getId());
            if (userDeptObj != null){
                int count = departmentComBox.getItemCount();  
                for (int i = 0 ; i < count ; i++){
                    DeptObject deptObj  =  (DeptObject)departmentComBox.getItemAt(i);
                    if (userDeptObj.getId().equals(deptObj.getId())){
                        departmentComBox.setSelectedIndex(i);
                        break;
                    }
                }
            }
        } catch (VCIException e) {
            VCIOptionPane.showError(LogonApplication.frame, "RMIPFramework", e);
            return ;
        }
                      
    }
    
}