提交 | 用户 | 时间
|
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.FlowLayout; |
|
6 |
import java.awt.Panel; |
|
7 |
import java.awt.event.ActionEvent; |
|
8 |
import java.awt.event.ActionListener; |
|
9 |
import java.awt.event.WindowAdapter; |
|
10 |
import java.awt.event.WindowEvent; |
|
11 |
import java.io.UnsupportedEncodingException; |
|
12 |
import java.util.Vector; |
|
13 |
|
|
14 |
import javax.swing.JButton; |
|
15 |
import javax.swing.JDialog; |
|
16 |
import javax.swing.JLabel; |
|
17 |
import javax.swing.JOptionPane; |
|
18 |
import javax.swing.JPanel; |
|
19 |
import javax.swing.JScrollPane; |
|
20 |
import javax.swing.JTable; |
|
21 |
import javax.swing.JTextField; |
|
22 |
import javax.swing.SwingUtilities; |
|
23 |
import javax.swing.SwingWorker; |
|
24 |
import javax.swing.table.DefaultTableCellRenderer; |
|
25 |
import javax.swing.table.DefaultTableModel; |
|
26 |
|
|
27 |
import com.iailab.netsdk.common.BorderEx; |
|
28 |
import com.iailab.netsdk.common.Res; |
|
29 |
import com.iailab.netsdk.demo.module.GateModule; |
|
30 |
import com.iailab.netsdk.lib.ToolKits; |
|
31 |
import com.iailab.netsdk.lib.NetSDKLib.*; |
|
32 |
|
|
33 |
public class CardManegerDialog extends JDialog{ |
|
34 |
private static final long serialVersionUID = 1L; |
|
35 |
|
|
36 |
private int count = 0; // 查询了几次 |
|
37 |
private int index = 0; // 查询的卡信息索引 |
|
38 |
private int nFindCount = 10; // 每次查询的次数 |
|
39 |
|
|
40 |
public CardManegerDialog(){ |
|
41 |
setTitle(Res.string().getCardManager()); |
|
42 |
setLayout(new BorderLayout()); |
|
43 |
setModal(true); |
|
44 |
pack(); |
|
45 |
setSize(700, 390); |
|
46 |
setResizable(false); |
|
47 |
setLocationRelativeTo(null); |
|
48 |
setDefaultCloseOperation(DISPOSE_ON_CLOSE); // 释放窗体 |
|
49 |
|
|
50 |
CardListPanel cardListPanel = new CardListPanel(); |
|
51 |
CardOperatePanel cardOperatePanel = new CardOperatePanel(); |
|
52 |
|
|
53 |
add(cardListPanel, BorderLayout.CENTER); |
|
54 |
add(cardOperatePanel, BorderLayout.EAST); |
|
55 |
|
|
56 |
addWindowListener(new WindowAdapter() { |
|
57 |
public void windowClosing(WindowEvent e){ |
|
58 |
dispose(); |
|
59 |
} |
|
60 |
}); |
|
61 |
|
|
62 |
setOnClickListener(); |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* 卡信息列表 |
|
67 |
*/ |
|
68 |
private class CardListPanel extends JPanel { |
|
69 |
private static final long serialVersionUID = 1L; |
|
70 |
|
|
71 |
public CardListPanel() { |
|
72 |
BorderEx.set(this, Res.string().getCardInfo(), 2); |
|
73 |
setLayout(new BorderLayout()); |
|
74 |
|
|
75 |
defaultModel = new DefaultTableModel(null, Res.string().getCardTable()); |
|
76 |
table = new JTable(defaultModel) { // 列表不可编辑 |
|
77 |
private static final long serialVersionUID = 1L; |
|
78 |
@Override |
|
79 |
public boolean isCellEditable(int row, int column) { |
|
80 |
return false; |
|
81 |
} |
|
82 |
}; |
|
83 |
defaultModel.setRowCount(18); |
|
84 |
|
|
85 |
table.getColumnModel().getColumn(0).setPreferredWidth(80); |
|
86 |
table.getColumnModel().getColumn(1).setPreferredWidth(120); |
|
87 |
table.getColumnModel().getColumn(2).setPreferredWidth(100); |
|
88 |
table.getColumnModel().getColumn(3).setPreferredWidth(100); |
|
89 |
table.getColumnModel().getColumn(4).setPreferredWidth(100); |
|
90 |
table.getColumnModel().getColumn(5).setPreferredWidth(100); |
|
91 |
table.getColumnModel().getColumn(6).setPreferredWidth(100); |
|
92 |
table.getColumnModel().getColumn(7).setPreferredWidth(100); |
|
93 |
table.getColumnModel().getColumn(8).setPreferredWidth(100); |
|
94 |
table.getColumnModel().getColumn(9).setPreferredWidth(100); |
|
95 |
table.getColumnModel().getColumn(10).setPreferredWidth(100); |
|
96 |
table.getColumnModel().getColumn(11).setPreferredWidth(150); |
|
97 |
table.getColumnModel().getColumn(12).setPreferredWidth(150); |
|
98 |
|
|
99 |
// 列表显示居中 |
|
100 |
DefaultTableCellRenderer dCellRenderer = new DefaultTableCellRenderer(); |
|
101 |
dCellRenderer.setHorizontalAlignment(JLabel.CENTER); |
|
102 |
table.setDefaultRenderer(Object.class, dCellRenderer); |
|
103 |
((DefaultTableCellRenderer)table.getTableHeader().getDefaultRenderer()).setHorizontalAlignment(JLabel.CENTER); |
|
104 |
|
|
105 |
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); |
|
106 |
JScrollPane scrollPane = new JScrollPane(table); |
|
107 |
add(scrollPane, BorderLayout.CENTER); |
|
108 |
} |
|
109 |
|
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* 卡操作 |
|
114 |
*/ |
|
115 |
private class CardOperatePanel extends JPanel { |
|
116 |
private static final long serialVersionUID = 1L; |
|
117 |
|
|
118 |
public CardOperatePanel() { |
|
119 |
BorderEx.set(this, Res.string().getCardOperate(), 2); |
|
120 |
setLayout(new BorderLayout()); |
|
121 |
Dimension dimension = new Dimension(); |
|
122 |
dimension.width = 210; |
|
123 |
setPreferredSize(dimension); |
|
124 |
|
|
125 |
Panel panel1 = new Panel(); |
|
126 |
Panel panel2 = new Panel(); |
|
127 |
|
|
128 |
add(panel1, BorderLayout.NORTH); |
|
129 |
add(panel2, BorderLayout.CENTER); |
|
130 |
|
|
131 |
// |
|
132 |
JLabel cardNoLabel = new JLabel(Res.string().getCardNo() + ":", JLabel.CENTER); |
|
133 |
cardNoTextField = new JTextField(""); |
|
134 |
|
|
135 |
cardNoLabel.setPreferredSize(new Dimension(50, 20)); |
|
136 |
cardNoTextField.setPreferredSize(new Dimension(120, 20)); |
|
137 |
cardNoTextField.setHorizontalAlignment(JTextField.CENTER); |
|
138 |
|
|
139 |
panel1.setLayout(new FlowLayout()); |
|
140 |
panel1.add(cardNoLabel); |
|
141 |
panel1.add(cardNoTextField); |
|
142 |
|
|
143 |
// |
|
144 |
searchBtn = new JButton(Res.string().getSearch()); |
|
145 |
addBtn = new JButton(Res.string().getAdd()); |
|
146 |
modifyBtn = new JButton(Res.string().getModify()); |
|
147 |
deleteBtn = new JButton(Res.string().getDelete()); |
|
148 |
clearBtn = new JButton(Res.string().getClear()); |
|
149 |
|
|
150 |
searchBtn.setPreferredSize(new Dimension(180, 21)); |
|
151 |
addBtn.setPreferredSize(new Dimension(180, 21)); |
|
152 |
modifyBtn.setPreferredSize(new Dimension(180, 21)); |
|
153 |
deleteBtn.setPreferredSize(new Dimension(180, 21)); |
|
154 |
clearBtn.setPreferredSize(new Dimension(180, 21)); |
|
155 |
|
|
156 |
JLabel nullLabel = new JLabel(); |
|
157 |
nullLabel.setPreferredSize(new Dimension(180, 30)); |
|
158 |
|
|
159 |
panel2.setLayout(new FlowLayout()); |
|
160 |
panel2.add(nullLabel); |
|
161 |
panel2.add(searchBtn); |
|
162 |
panel2.add(addBtn); |
|
163 |
panel2.add(modifyBtn); |
|
164 |
panel2.add(deleteBtn); |
|
165 |
panel2.add(clearBtn); |
|
166 |
} |
|
167 |
} |
|
168 |
|
|
169 |
private void setOnClickListener() { |
|
170 |
searchBtn.addActionListener(new ActionListener() { |
|
171 |
@Override |
|
172 |
public void actionPerformed(ActionEvent arg0) { |
|
173 |
SwingUtilities.invokeLater(new Runnable() { |
|
174 |
public void run() { |
|
175 |
try { |
|
176 |
if (cardNoTextField.getText().getBytes("UTF-8").length > 31) { |
|
177 |
JOptionPane.showMessageDialog(null, Res.string().getCardNoExceedLength() + "(31)", Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
178 |
return; |
|
179 |
} |
|
180 |
} catch (Exception e1) { |
|
181 |
e1.printStackTrace(); |
|
182 |
} |
|
183 |
|
|
184 |
searchBtn.setEnabled(false); |
|
185 |
defaultModel.setRowCount(0); |
|
186 |
defaultModel.setRowCount(18); |
|
187 |
} |
|
188 |
}); |
|
189 |
|
|
190 |
findCardInfo(); |
|
191 |
} |
|
192 |
}); |
|
193 |
|
|
194 |
addBtn.addActionListener(new ActionListener() { |
|
195 |
@Override |
|
196 |
public void actionPerformed(ActionEvent arg0) { |
|
197 |
AddCardDialog dialog = new AddCardDialog(); |
|
198 |
dialog.setVisible(true); |
|
199 |
} |
|
200 |
}); |
|
201 |
|
|
202 |
modifyBtn.addActionListener(new ActionListener() { |
|
203 |
@Override |
|
204 |
public void actionPerformed(ActionEvent arg0) { |
|
205 |
int row = -1; |
|
206 |
row = table.getSelectedRow(); //获得所选的单行 |
|
207 |
|
|
208 |
if(row < 0) { |
|
209 |
JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
210 |
return; |
|
211 |
} |
|
212 |
|
|
213 |
if(defaultModel.getValueAt(row, 3) == null || String.valueOf(defaultModel.getValueAt(row, 3)).trim().isEmpty()) { |
|
214 |
JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
215 |
return; |
|
216 |
} |
|
217 |
|
|
218 |
@SuppressWarnings("unchecked") |
|
219 |
Vector<String> vector = (Vector<String>) defaultModel.getDataVector().get(row); |
|
220 |
|
|
221 |
ModifyCardDialog dialog = new ModifyCardDialog(vector); |
|
222 |
dialog.setVisible(true); |
|
223 |
} |
|
224 |
}); |
|
225 |
|
|
226 |
deleteBtn.addActionListener(new ActionListener() { |
|
227 |
@Override |
|
228 |
public void actionPerformed(ActionEvent arg0) { |
|
229 |
int row = -1; |
|
230 |
row = table.getSelectedRow(); //获得所选的单行 |
|
231 |
|
|
232 |
if(row < 0) { |
|
233 |
JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
234 |
return; |
|
235 |
} |
|
236 |
|
|
237 |
if(defaultModel.getValueAt(row, 3) == null || String.valueOf(defaultModel.getValueAt(row, 3)).trim().isEmpty()) { |
|
238 |
JOptionPane.showMessageDialog(null, Res.string().getSelectCard(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
239 |
return; |
|
240 |
} |
|
241 |
|
|
242 |
Vector<String> v = (Vector<String>)defaultModel.getDataVector().get(row); |
|
243 |
|
|
244 |
String recordNo = v.get(3).toString(); // 记录集编号 |
|
245 |
String userId = v.get(4).toString(); // 用户ID |
|
246 |
|
|
247 |
// 删除人脸和卡信息 |
|
248 |
if(!GateModule.deleteFaceInfo(userId) || |
|
249 |
!GateModule.deleteCard(Integer.parseInt(recordNo))) { |
|
250 |
JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
251 |
} else { |
|
252 |
JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); |
|
253 |
defaultModel.removeRow(row); |
|
254 |
table.updateUI(); |
|
255 |
} |
|
256 |
} |
|
257 |
}); |
|
258 |
|
|
259 |
clearBtn.addActionListener(new ActionListener() { |
|
260 |
@Override |
|
261 |
public void actionPerformed(ActionEvent arg0) { |
|
262 |
int result = JOptionPane.showConfirmDialog(null, Res.string().getWantClearAllInfo(), Res.string().getPromptMessage(), JOptionPane.YES_NO_OPTION); |
|
263 |
if(result == 0) { // 0-是, 1-否 |
|
264 |
// 清空人脸和卡信息 |
|
265 |
if(!GateModule.clearFaceInfo() || |
|
266 |
!GateModule.clearCard()) { |
|
267 |
JOptionPane.showMessageDialog(null, ToolKits.getErrorCodeShow(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE); |
|
268 |
} else { |
|
269 |
JOptionPane.showMessageDialog(null, Res.string().getSucceed(), Res.string().getPromptMessage(), JOptionPane.INFORMATION_MESSAGE); |
|
270 |
defaultModel.setRowCount(0); |
|
271 |
defaultModel.setRowCount(18); |
|
272 |
} |
|
273 |
} |
|
274 |
} |
|
275 |
}); |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* 查询卡的信息 |
|
280 |
*/ |
|
281 |
public void findCardInfo() { |
|
282 |
new SwingWorker<Boolean, CardData>() { |
|
283 |
@Override |
|
284 |
protected Boolean doInBackground() { |
|
285 |
count = 0; |
|
286 |
index = 0; |
|
287 |
nFindCount = 10; |
|
288 |
|
|
289 |
// 卡号: 为空,查询所有的卡信息 |
|
290 |
// 获取查询句柄 |
|
291 |
if(!GateModule.findCard(cardNoTextField.getText())) { |
|
292 |
return false; |
|
293 |
} |
|
294 |
|
|
295 |
// 查询具体信息 |
|
296 |
while(true) { |
|
297 |
NET_RECORDSET_ACCESS_CTL_CARD[] pstRecord = GateModule.findNextCard(nFindCount); |
|
298 |
if(pstRecord == null) { |
|
299 |
break; |
|
300 |
} |
|
301 |
|
|
302 |
for(int i = 0; i < pstRecord.length; i++) { |
|
303 |
index = i + count * nFindCount; |
|
304 |
|
|
305 |
try { |
|
306 |
Vector<String> vector = new Vector<String>(); |
|
307 |
vector.add(String.valueOf(index + 1)); // 序号 |
|
308 |
vector.add(new String(pstRecord[i].szCardNo).trim()); // 卡号 |
|
309 |
vector.add(new String(pstRecord[i].szCardName, "GBK").trim()); // 卡名 |
|
310 |
vector.add(String.valueOf(pstRecord[i].nRecNo)); // 记录集编号 |
|
311 |
vector.add(new String(pstRecord[i].szUserID).trim()); // 用户ID |
|
312 |
vector.add(new String(pstRecord[i].szPsw).trim()); // 卡密码 |
|
313 |
vector.add(Res.string().getCardStatus(pstRecord[i].emStatus)); // 卡状态 |
|
314 |
vector.add(Res.string().getCardType(pstRecord[i].emType)); // 卡类型 |
|
315 |
vector.add(String.valueOf(pstRecord[i].nUserTime)); // 使用次数 |
|
316 |
vector.add(pstRecord[i].bFirstEnter == 1 ? Res.string().getFirstEnter() : Res.string().getNoFirstEnter()); // 是否首卡 |
|
317 |
vector.add(pstRecord[i].bIsValid == 1? Res.string().getValid() : Res.string().getInValid()); // 是否有效 |
|
318 |
vector.add(pstRecord[i].stuValidStartTime.toStringTimeEx()); // 有效开始时间 |
|
319 |
vector.add(pstRecord[i].stuValidEndTime.toStringTimeEx()); // 有效结束时间 |
|
320 |
|
|
321 |
CardData data = new CardData(); |
|
322 |
data.setIndex(index); |
|
323 |
data.setVector(vector); |
|
324 |
|
|
325 |
publish(data); |
|
326 |
|
|
327 |
} catch (UnsupportedEncodingException e) { |
|
328 |
e.printStackTrace(); |
|
329 |
} |
|
330 |
} |
|
331 |
|
|
332 |
if (pstRecord.length < nFindCount) { |
|
333 |
break; |
|
334 |
} else { |
|
335 |
count ++; |
|
336 |
} |
|
337 |
|
|
338 |
} |
|
339 |
|
|
340 |
// 关闭查询接口 |
|
341 |
GateModule.findCardClose(); |
|
342 |
|
|
343 |
return true; |
|
344 |
} |
|
345 |
|
|
346 |
@Override |
|
347 |
protected void process(java.util.List<CardData> chunks) { |
|
348 |
for(CardData data : chunks) { |
|
349 |
defaultModel.insertRow(data.getIndex(), data.getVector()); |
|
350 |
if(data.getIndex() < 18) { |
|
351 |
defaultModel.setRowCount(18); |
|
352 |
} else { |
|
353 |
defaultModel.setRowCount(data.getIndex() + 1); |
|
354 |
} |
|
355 |
|
|
356 |
table.updateUI(); |
|
357 |
} |
|
358 |
|
|
359 |
super.process(chunks); |
|
360 |
} |
|
361 |
|
|
362 |
@Override |
|
363 |
protected void done() { |
|
364 |
searchBtn.setEnabled(true); |
|
365 |
} |
|
366 |
}.execute(); |
|
367 |
} |
|
368 |
|
|
369 |
class CardData { |
|
370 |
private int nIndex = 0; |
|
371 |
private Vector<String> vector = null; |
|
372 |
|
|
373 |
public int getIndex() { |
|
374 |
return nIndex; |
|
375 |
} |
|
376 |
public void setIndex(int index) { |
|
377 |
this.nIndex = index; |
|
378 |
} |
|
379 |
public Vector<String> getVector() { |
|
380 |
return vector; |
|
381 |
} |
|
382 |
public void setVector(Vector<String> vector) { |
|
383 |
this.vector = vector; |
|
384 |
} |
|
385 |
} |
|
386 |
|
|
387 |
|
|
388 |
/// |
|
389 |
private DefaultTableModel defaultModel; |
|
390 |
private JTable table; |
|
391 |
|
|
392 |
private JTextField cardNoTextField; |
|
393 |
|
|
394 |
private JButton searchBtn; |
|
395 |
private JButton addBtn; |
|
396 |
private JButton modifyBtn; |
|
397 |
private JButton deleteBtn; |
|
398 |
private JButton clearBtn; |
|
399 |
} |