houzhongjian
5 天以前 d66edbeffee5e308504e48372a5bb4d04aa4e843
提交 | 用户 | 时间
149dd0 1 package com.iailab.netsdk.demo.frame.Gate;
H 2
3 import java.awt.BorderLayout;
4 import java.awt.Dimension;
5 import java.awt.event.ActionEvent;
6 import java.awt.event.ActionListener;
7 import java.awt.event.WindowAdapter;
8 import java.awt.event.WindowEvent;
9 import java.io.IOException;
10 import java.util.Vector;
11
12 import javax.swing.JButton;
13 import javax.swing.JCheckBox;
14 import javax.swing.JComboBox;
15 import javax.swing.JDialog;
16 import javax.swing.JLabel;
17 import javax.swing.JOptionPane;
18 import javax.swing.JPanel;
19 import javax.swing.JPasswordField;
20 import javax.swing.JTextField;
21
22 import com.sun.jna.Memory;
23
24 import com.iailab.netsdk.common.BorderEx;
25 import com.iailab.netsdk.common.DateChooserJButton;
26 import com.iailab.netsdk.common.PaintPanel;
27 import com.iailab.netsdk.common.Res;
28 import com.iailab.netsdk.demo.module.GateModule;
29 import com.iailab.netsdk.lib.ToolKits;
30
31 public class ModifyCardDialog extends JDialog{
32
33     private static final long serialVersionUID = 1L;
34
35     private Memory memory = null;
36     
37     private Vector<String> vector = null;
38     
39     private String picPath = "";
40     
41     public ModifyCardDialog(Vector<String> v){
42         setTitle(Res.string().getModify() + Res.string().getCardInfo());
43         setLayout(new BorderLayout());
44         setModal(true);    
45         pack();
46         setSize(520, 390);
47         setResizable(false);
48         setLocationRelativeTo(null);
49         setDefaultCloseOperation(DISPOSE_ON_CLOSE);   // 释放窗体
50         
51         CardInfoPanel cardInfoPanel = new CardInfoPanel();
52         ImagePanel imagePanel = new ImagePanel();
53         
54         add(cardInfoPanel, BorderLayout.CENTER);
55         add(imagePanel, BorderLayout.EAST);
56         
57         this.vector = v;
58         showCardInfo();
59         
60         addWindowListener(new WindowAdapter() {
61             public void windowClosing(WindowEvent e){
62                 clear();
63                 dispose();
64             }
65         });
66     }
67     
68     /**
69      * 卡信息
70      */
71     private class CardInfoPanel extends JPanel {
72
73         private static final long serialVersionUID = 1L;
74         
75         public CardInfoPanel() {
76             BorderEx.set(this, Res.string().getCardInfo(), 4);
77             
78             JLabel cardNoLabel = new JLabel(Res.string().getCardNo() + ":", JLabel.CENTER);
79             JLabel userIdLabel = new JLabel(Res.string().getUserId() + ":", JLabel.CENTER);
80             JLabel cardNameLabel = new JLabel(Res.string().getCardName() + ":", JLabel.CENTER);
81             JLabel cardPasswdLabel = new JLabel(Res.string().getCardPassword() + ":", JLabel.CENTER);
82             JLabel cardStatusLabel = new JLabel(Res.string().getCardStatus() + ":", JLabel.CENTER);
83             JLabel cardTypeLabel = new JLabel(Res.string().getCardType() + ":", JLabel.CENTER);
84             JLabel useTimesLabel = new JLabel(Res.string().getUseTimes() + ":", JLabel.CENTER);
85             JLabel validPeriodLabel = new JLabel(Res.string().getValidPeriod() + ":", JLabel.CENTER);
86             
87             Dimension dimension = new Dimension();
88             dimension.width = 85;
89             dimension.height = 20;
90             cardNoLabel.setPreferredSize(dimension);
91             userIdLabel.setPreferredSize(dimension);
92             cardNameLabel.setPreferredSize(dimension);
93             cardPasswdLabel.setPreferredSize(dimension);
94             cardStatusLabel.setPreferredSize(dimension);
95             cardTypeLabel.setPreferredSize(dimension);
96             useTimesLabel.setPreferredSize(dimension);
97             validPeriodLabel.setPreferredSize(dimension);
98             
99             cardNoTextField = new JTextField();
100             userIdTextField = new JTextField();
101             cardNameTextField = new JTextField();
102             cardPasswdField = new JPasswordField();        
103             cardStatusComboBox = new JComboBox(Res.string().getCardStatusList());
104             cardTypeComboBox = new JComboBox(Res.string().getCardTypeList());    
105             useTimesTextField = new JTextField();
106             firstEnterCheckBox = new JCheckBox(Res.string().getIsFirstEnter());
107             enableCheckBox = new JCheckBox(Res.string().getEnable());
108             enableCheckBox.setSelected(true);
109             enableCheckBox.setVisible(false);
110             startTimeBtn = new DateChooserJButton();
111             endTimeBtn = new DateChooserJButton();
112             
113             cardNoTextField.setPreferredSize(new Dimension(145, 20));
114             userIdTextField.setPreferredSize(new Dimension(145, 20));
115             cardNameTextField.setPreferredSize(new Dimension(145, 20));
116             cardPasswdField.setPreferredSize(new Dimension(145, 20));
117             useTimesTextField.setPreferredSize(new Dimension(145, 20));
118             cardStatusComboBox.setPreferredSize(new Dimension(145, 20));
119             cardTypeComboBox.setPreferredSize(new Dimension(145, 20));
120             startTimeBtn.setPreferredSize(new Dimension(145, 20));
121             endTimeBtn.setPreferredSize(new Dimension(145, 20));
122             firstEnterCheckBox.setPreferredSize(new Dimension(170, 20));
123             enableCheckBox.setPreferredSize(new Dimension(70, 20));
124             
125             JLabel nullLabel1 = new JLabel();
126             JLabel nullLabel2 = new JLabel();
127             JLabel nullLabel3 = new JLabel();
128             nullLabel1.setPreferredSize(new Dimension(5, 20));
129             nullLabel2.setPreferredSize(new Dimension(30, 20));
130             nullLabel3.setPreferredSize(new Dimension(85, 20));
131             
132             cardNoTextField.setEditable(false);
133             userIdTextField.setEditable(false);
134             
135             modifyBtn = new JButton(Res.string().getModify());
136             cancelBtn = new JButton(Res.string().getCancel());
137             JLabel nullLabel4 = new JLabel();
138             nullLabel4.setPreferredSize(new Dimension(250, 20));
139             modifyBtn.setPreferredSize(new Dimension(110, 20));
140             cancelBtn.setPreferredSize(new Dimension(110, 20));
141             
142             add(cardNoLabel);
143             add(cardNoTextField);
144             add(userIdLabel);
145             add(userIdTextField);
146             
147             add(cardNameLabel);
148             add(cardNameTextField);
149             add(cardPasswdLabel);
150             add(cardPasswdField);
151             
152             add(cardStatusLabel);
153             add(cardStatusComboBox);
154             add(cardTypeLabel);
155             add(cardTypeComboBox);
156             
157             add(useTimesLabel);
158             add(useTimesTextField);
159             add(nullLabel1);
160             add(firstEnterCheckBox);
161             add(nullLabel2);
162             add(enableCheckBox);
163             
164             add(validPeriodLabel);
165             add(startTimeBtn);
166             add(nullLabel3);
167             add(endTimeBtn);
168             
169             add(nullLabel4);
170             add(modifyBtn);
171             add(cancelBtn);
172             
173             // 修改
174             modifyBtn.addActionListener(new ActionListener() {        
175                 @Override
176                 public void actionPerformed(ActionEvent arg0) {    
177                     try {
178                         if (cardNameTextField.getText().getBytes("UTF-8").length > 63) {
179                             JOptionPane.showMessageDialog(null, Res.string().getCardNameExceedLength() + "(63)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
180                             return;
181                         }
182                         
183                         if (new String(cardPasswdField.getPassword()).getBytes("UTF-8").length > 63) {
184                             JOptionPane.showMessageDialog(null, Res.string().getCardPasswdExceedLength() + "(63)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
185                             return;
186                         }
187                     } catch (Exception e1) {
188                         e1.printStackTrace();
189                     }     
190                     
191                     int useTimes = 0;
192                     if(useTimesTextField.getText().isEmpty()) {
193                         useTimes = 0;
194                     } else {
195                         useTimes = Integer.parseInt(useTimesTextField.getText());
196                     }
197                     
198                     if(GateModule.modifyCard(Integer.parseInt(vector.get(3).toString()), cardNoTextField.getText(), 
199                                             userIdTextField.getText(), cardNameTextField.getText(), 
200                                             new String(cardPasswdField.getPassword()), 
201                                             Res.string().getCardStatusInt(cardStatusComboBox.getSelectedIndex()), 
202                                             Res.string().getCardTypeInt(cardTypeComboBox.getSelectedIndex()), 
203                                             useTimes, firstEnterCheckBox.isSelected() ? 1:0, 
204                                             enableCheckBox.isSelected() ? 1:0, startTimeBtn.getText(), endTimeBtn.getText())) {
205                         if(memory == null) {
206                             JOptionPane.showMessageDialog(null, Res.string().getSucceedModifyCard(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE);
207                             dispose();
208                         } else {
209                             if(GateModule.modifyFaceInfo(userIdTextField.getText(), memory)) {
210                                 JOptionPane.showMessageDialog(null, Res.string().getSucceedModifyCardAndPerson(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE);
211                                 dispose();
212                             } else {
213                                 JOptionPane.showMessageDialog(null, Res.string().getSucceedModifyCardButFailedModifyPerson() + " : " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
214                             }
215                         }
216                     } else {
217                         JOptionPane.showMessageDialog(null, Res.string().getFailedModifyCard() + " : " + ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
218                     }    
219                 }
220             });
221             
222             // 取消
223             cancelBtn.addActionListener(new ActionListener() {        
224                 @Override
225                 public void actionPerformed(ActionEvent arg0) {
226                     clear();
227                     dispose();                
228                 }
229             });
230         }
231     }
232     
233     /**
234      * 选择图片
235      */
236     private class ImagePanel extends JPanel {
237
238         private static final long serialVersionUID = 1L;
239         
240         public ImagePanel() {
241             BorderEx.set(this, Res.string().getPersonPicture(), 4);
242             Dimension dimension = new Dimension();
243             dimension.width = 250;
244             setPreferredSize(dimension);
245             setLayout(new BorderLayout());
246             
247             addImagePanel = new PaintPanel();   // 添加的人员信息图片显示
248             selectImageBtn = new JButton(Res.string().getSelectPicture());
249             add(addImagePanel, BorderLayout.CENTER);
250             add(selectImageBtn, BorderLayout.SOUTH);
251             
252             // 选择图片,获取图片的信息
253             selectImageBtn.addActionListener(new ActionListener() {                
254                 @Override
255                 public void actionPerformed(ActionEvent arg0) {
256                     // 选择图片,获取图片路径,并在界面显示
257                     picPath = ToolKits.openPictureFile(addImagePanel);
258                             
259                     if(!picPath.isEmpty()) {
260                         try {
261                             memory = ToolKits.readPictureFile(picPath);
262                         } catch (IOException e) {
263                             // TODO Auto-generated catch block
264                             e.printStackTrace();
265                         }
266                     }        
267                 }
268             });
269         }
270     }
271     
272     /**
273      * 界面显示要修改的卡信息
274      */
275     private void showCardInfo() {
276         // 卡号
277         cardNoTextField.setText(vector.get(1).toString());
278         
279         // 卡名
280         cardNameTextField.setText(vector.get(2).toString());
281         
282         // 用户ID
283         userIdTextField.setText(vector.get(4).toString());
284         
285         // 卡密码
286         cardPasswdField.setText(vector.get(5).toString());
287         
288         // 卡状态
289         cardStatusComboBox.setSelectedIndex(Res.string().getCardStatusChomBoxIndex(vector.get(6).toString()));
290         
291         // 卡类型
292         cardTypeComboBox.setSelectedIndex(Res.string().getCardTypeChomBoxIndex(vector.get(7).toString()));
293         
294         // 使用次数
295         useTimesTextField.setText(vector.get(8).toString());
296         
297         // 是否首卡
298         if(vector.get(9).toString().equals(Res.string().getFirstEnter())) {
299             firstEnterCheckBox.setSelected(true);
300         } else {
301             firstEnterCheckBox.setSelected(false);
302         }
303         
304         // 是否有效
305         if(vector.get(10).toString().equals(Res.string().getValid())) {
306             enableCheckBox.setSelected(true);
307         } else {
308             enableCheckBox.setSelected(false);
309         }
310         
311         // 有效开始时间
312         startTimeBtn.setText(vector.get(11).toString());
313         
314         // 有效结束时间
315         endTimeBtn.setText(vector.get(12).toString());
316     }
317     
318     private void clear() {
319         memory = null;
320         vector = null;
321         picPath = "";
322     }
323     
324     private PaintPanel addImagePanel;
325     private JButton selectImageBtn;
326     
327     private JTextField cardNoTextField;
328     private JTextField userIdTextField;
329     private JTextField cardNameTextField;
330     private JPasswordField cardPasswdField;        
331     private JComboBox cardStatusComboBox;
332     private JComboBox cardTypeComboBox;    
333     private JTextField useTimesTextField;
334     private JCheckBox firstEnterCheckBox;
335     private JCheckBox enableCheckBox;
336     private DateChooserJButton startTimeBtn;
337     private DateChooserJButton endTimeBtn;
338     
339     private JButton modifyBtn;
340     private JButton cancelBtn;
341 }