Jay
2024-11-01 03e8aca3ad6201c0d74e00d4c8d7367cdaaa54f9
提交 | 用户 | 时间
ce910c 1 package com.netsdk.demo.frame.Attendance;
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.KeyEvent;
8 import java.awt.event.KeyListener;
9
10 import javax.swing.JButton;
11 import javax.swing.JDialog;
12 import javax.swing.JLabel;
13 import javax.swing.JOptionPane;
14 import javax.swing.JPanel;
15 import javax.swing.JScrollPane;
16 import javax.swing.JTextArea;
17 import javax.swing.JTextField;
18
19 import com.netsdk.common.Base64;
20 import com.netsdk.common.BorderEx;
21 import com.netsdk.common.Res;
22 import com.netsdk.demo.module.AttendanceModule;
23 import com.netsdk.demo.module.AttendanceModule.OPERATE_TYPE;
24 import com.netsdk.demo.module.AttendanceModule.UserData;
25
26 /**
27  * 通过信息ID操作信息对话框
28  */
29 public class OperateByFingerPrintIdDialog extends JDialog{
30     /**
31      * 
32      */
33     private static final long serialVersionUID = 1L;
34     
35     public OperateByFingerPrintIdDialog() {
36         setTitle(Res.string().getOperateByFingerPrintId());
37         setLayout(new BorderLayout());
38         setModal(true);
39         pack();
40         setSize(600, 500);
41         setResizable(false);
42         setLocationRelativeTo(null);
43         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
44         
45         ////////// 查询条件 /////////////////
46         JLabel fingerPrintIdLabel = new JLabel(Res.string().getFingerPrintId(), JLabel.CENTER);
47         fingerPrintIdTextField = new JTextField();
48         fingerPrintIdLabel.setPreferredSize(new Dimension(85, 20));
49         fingerPrintIdTextField.setPreferredSize(new Dimension(100, 20));
50         
51         ////////// 信息功能 /////////////////
52         searchFingerPrintBtn = new JButton(Res.string().getSearchFingerPrint());
53         deleteFingerPrintBtn = new JButton(Res.string().getDeleteFingerPrint());
54         
55         searchFingerPrintBtn.setPreferredSize(new Dimension(140, 20));
56         deleteFingerPrintBtn.setPreferredSize(new Dimension(140, 20));
57
58         JPanel functionPanel = new JPanel();
59         BorderEx.set(functionPanel, Res.string().getOperateByFingerPrintId(), 1);
60         functionPanel.add(fingerPrintIdLabel);
61         functionPanel.add(fingerPrintIdTextField);
62         functionPanel.add(searchFingerPrintBtn);
63         functionPanel.add(deleteFingerPrintBtn);
64         
65         //////////信息信息 /////////////////
66         JPanel fingerPrintPanel = new JPanel();
67         BorderEx.set(fingerPrintPanel, Res.string().getFingerPrintInfo(), 1);
68         fingerPrintPanel.setLayout(null);
69         JLabel userIdLabel = new JLabel(Res.string().getUserId());
70         userId = new JLabel();
71         JLabel fingerPrintDataLabel = new JLabel(Res.string().getFingerPrintData());
72         fingerPrintData = new JTextArea();
73         fingerPrintData.setBackground(null);
74         fingerPrintData.setEditable(false);
75         fingerPrintData.setLineWrap(true);
76         JScrollPane scrollPane = new JScrollPane(fingerPrintData);
77         userIdLabel.setBounds(30, 30, 90, 20);
78         userId.setBounds(150, 30, 300, 20);
79         fingerPrintDataLabel.setBounds(30, 60, 150, 20);
80         fingerPrintData.setBounds(30, 80, 600, 20);
81         scrollPane.setBounds(30, 80, 550, 300);
82         scrollPane.setBorder(null);
83         
84         fingerPrintPanel.add(userIdLabel);
85         fingerPrintPanel.add(userId);
86         fingerPrintPanel.add(fingerPrintDataLabel);
87         fingerPrintPanel.add(scrollPane);
88         
89         add(functionPanel, BorderLayout.NORTH);
90         add(fingerPrintPanel, BorderLayout.CENTER);
91         
92         fingerPrintIdTextField.addKeyListener(new KeyListener() {
93             
94             public void keyTyped(KeyEvent e) {
95                   int key = e.getKeyChar();
96                   if (key < 48 || key > 57) {
97                       e.consume();
98                   }
99             }
100
101             public void keyPressed(KeyEvent e) {}
102             
103             public void keyReleased(KeyEvent e) {}
104         });
105         
106         listener = new FingerPrintIdOperateActionListener();
107         searchFingerPrintBtn.addActionListener(listener);
108         deleteFingerPrintBtn.addActionListener(listener);
109     }
110     
111     public String getFingerPrintId() {
112         
113         if (fingerPrintIdTextField.getText().isEmpty()) {
114             JOptionPane.showMessageDialog(null, Res.string().getInput()+Res.string().getFingerPrintId(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
115             return null;
116         }
117         
118         try {
119             Integer.parseInt(fingerPrintIdTextField.getText());
120         }catch (NumberFormatException e){
121             JOptionPane.showMessageDialog(null, Res.string().getFingerPrintIdIllegal(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
122             return null;
123         }
124         return fingerPrintIdTextField.getText();
125     }
126     
127     public void searchFingerPrint() {
128         clearFingerPrintInfo();
129         
130         String fingerPrintId = getFingerPrintId();
131         if (fingerPrintId == null) {
132             return;
133         }
134         UserData userData = AttendanceModule.getFingerRecord(Integer.parseInt(fingerPrintId));
135         if (userData == null) {
136             JOptionPane.showMessageDialog(null, Res.string().getFailed(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
137             return;
138         }
139         
140         if (userData.szFingerPrintInfo[0].length == 0) {
141             JOptionPane.showMessageDialog(null, Res.string().getFingerPrintIdNotExist(), Res.string().getErrorMessage(), JOptionPane.ERROR_MESSAGE);
142             return;
143         }
144         
145         dealFingerPrintInfo(userData);
146     }
147     
148     public void dealFingerPrintInfo(UserData userData) {
149         userId.setText(userData.userId);
150         fingerPrintData.setText(formatFingerPrintData(userData.szFingerPrintInfo[0]));
151     }
152     
153     private String formatFingerPrintData(byte[] fingerPrintData) {
154         String formatData = Base64.getEncoder().encodeToString(fingerPrintData);
155         return formatData;
156     }
157     
158     public void clearFingerPrintInfo() {
159         userId.setText("");
160         fingerPrintData.setText("");
161     }
162     
163     /**
164      * 按键监听实现类
165      */
166     private class FingerPrintIdOperateActionListener implements ActionListener {    
167
168         @Override
169         public void actionPerformed(ActionEvent arg0) {
170
171             OPERATE_TYPE emType = getOperateType(arg0.getSource());
172             switch(emType) {
173                 case SEARCH_FINGERPRINT_BY_ID:
174                     searchFingerPrint();
175                     break;
176                 case DELETE_FINGERPRINT_BY_ID:
177                     String fingerPrintId = getFingerPrintId();
178                     if (fingerPrintId == null) {
179                         return;
180                     }
181                     new AttendanceOperateShareDialog(emType, fingerPrintId).setVisible(true);
182                     break;
183                 default:
184                     break;
185             }
186         }
187         
188         private OPERATE_TYPE getOperateType(Object btn) {
189             OPERATE_TYPE type = OPERATE_TYPE.UNKNOWN;
190             if (btn == searchFingerPrintBtn) { // 查找信息
191                 type = OPERATE_TYPE.SEARCH_FINGERPRINT_BY_ID;
192             }else if (btn == deleteFingerPrintBtn) {    // 删除信息
193                 type = OPERATE_TYPE.DELETE_FINGERPRINT_BY_ID;
194             }else {
195                 System.err.println("Unknown Event: " + btn);
196             }
197             
198             return type;
199             
200         }
201     }
202     
203     private JTextField fingerPrintIdTextField;
204     public JButton searchFingerPrintBtn;
205     private JButton deleteFingerPrintBtn;
206     private JLabel userId;
207     private JTextArea fingerPrintData;
208     private FingerPrintIdOperateActionListener listener;
209 }