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