Subversion Repository Public Repository

FingerPrint_5.2

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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
package test;

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.border.BevelBorder;
import java.awt.Font;
import java.awt.Image;

import javax.swing.border.LineBorder;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.Vector;
import java.awt.event.ActionEvent;
import javax.swing.JComboBox;
import javax.swing.JFormattedTextField;
import java.awt.event.ItemListener;
import java.awt.event.ItemEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.UIManager;
import java.awt.SystemColor;

public class ModalPurposeOfVisit extends JDialog {

	private final JPanel contentPanel = new JPanel();
	JLabel lblPurposeOfVisit;
	JLabel lblWhomeToMeet;
	JComboBox cmbPurposeOfVisit;
	JFormattedTextField txtStudentId;
	JFormattedTextField txtStudentName;
	JButton btnStudentIdSearch;
	String purposeOfVisit = "";

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		try {
			ModalPurposeOfVisit dialog = new ModalPurposeOfVisit();
			dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
			dialog.setVisible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * Create the dialog.
	 */
	public ModalPurposeOfVisit() {
		setTitle("Purpose of visit");
		//setModalityType(ModalityType.APPLICATION_MODAL);
		setBounds(100, 100, 459, 234);
		getContentPane().setLayout(new BorderLayout());
		contentPanel.setBackground(SystemColor.control);
		contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		getContentPane().add(contentPanel, BorderLayout.CENTER);
		contentPanel.setLayout(null);
		lblPurposeOfVisit = new JLabel("Purpose of visit");
		lblPurposeOfVisit.setFont(new Font("Arial Unicode MS", Font.PLAIN, 12));
		lblPurposeOfVisit.setBounds(10, 11, 131, 20);
		contentPanel.add(lblPurposeOfVisit);
		{
			cmbPurposeOfVisit = new JComboBox();
			cmbPurposeOfVisit.addItemListener(new ItemListener() {
				public void itemStateChanged(ItemEvent e) {
					cmbPurposeOfVisitItemStateChanged(e);
				}
			});
			cmbPurposeOfVisit.setFont(new Font("Arial Unicode MS", Font.PLAIN, 14));
			cmbPurposeOfVisit.setBounds(10, 29, 420, 32);
			contentPanel.add(cmbPurposeOfVisit);
		}
		
		lblWhomeToMeet = new JLabel("Whom to meet");
		lblWhomeToMeet.setFont(new Font("Arial Unicode MS", Font.PLAIN, 12));
		lblWhomeToMeet.setBounds(10, 72, 131, 20);
		contentPanel.add(lblWhomeToMeet);
		
		txtStudentId = new JFormattedTextField();
		txtStudentId.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				txtStudentIdKeyPressed(e);
			}
			@Override
			public void keyTyped(KeyEvent e) {
				txtStudentIdKeyTyped(e);
			}
		});
		txtStudentId.setText("");
		txtStudentId.setName("txtStudentId");
		txtStudentId.setFont(new Font("Arial Unicode MS", Font.PLAIN, 16));
		txtStudentId.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		txtStudentId.setBounds(10, 92, 118, 30);
		contentPanel.add(txtStudentId);
		
		btnStudentIdSearch = new JButton("");
		btnStudentIdSearch.setIcon(getResizedIcon("search.png", 15));
		btnStudentIdSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				btnStudentIdSearchActionPerformed(e);
			}
		});
		btnStudentIdSearch.setBounds(133, 92, 32, 31);
		contentPanel.add(btnStudentIdSearch);
		
		txtStudentName = new JFormattedTextField();
		txtStudentName.setFont(new Font("Arial Unicode MS", Font.PLAIN, 16));
		txtStudentName.setEditable(false);
		txtStudentName.setBorder(new BevelBorder(BevelBorder.LOWERED, null, null, null, null));
		txtStudentName.setBounds(167, 92, 263, 30);
		contentPanel.add(txtStudentName);
		{
			JPanel buttonPane = new JPanel();
			buttonPane.setBackground(SystemColor.activeCaptionBorder);
			buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
			getContentPane().add(buttonPane, BorderLayout.SOUTH);
			{
				JButton okButton = new JButton("OK");
				okButton.setFont(new Font("Arial Unicode MS", Font.PLAIN, 14));
				okButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						okButtonActionPerformed(e);
					}
				});
				okButton.setActionCommand("OK");
				buttonPane.add(okButton);
				getRootPane().setDefaultButton(okButton);
			}
			{
				JButton cancelButton = new JButton("Cancel");
				cancelButton.setFont(new Font("Arial Unicode MS", Font.PLAIN, 14));
				cancelButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent e) {
						cancelButtonActionPerformed(e);
					}
				});
				cancelButton.setActionCommand("Cancel");
				buttonPane.add(cancelButton);
			}
		}
		loadPurposeOfVisit();
	}

	protected void cmbPurposeOfVisitItemStateChanged(ItemEvent e) {
		String selected_purpose_of_visit = cmbPurposeOfVisit.getSelectedItem().toString();
		selected_purpose_of_visit = selected_purpose_of_visit.toUpperCase().toLowerCase().trim();
		if(selected_purpose_of_visit.contains("office check-in") || selected_purpose_of_visit.contains("office check-out")){
			lblWhomeToMeet.setVisible(false);
			txtStudentId.setText("0");
			txtStudentId.setVisible(false);
			btnStudentIdSearch.setVisible(false);
			txtStudentName.setText("NA");;
			txtStudentName.setVisible(false);
		}else{
			lblWhomeToMeet.setVisible(true);
			txtStudentId.setText("");
			txtStudentId.setVisible(true);
			btnStudentIdSearch.setVisible(true);
			txtStudentName.setText("");;
			txtStudentName.setVisible(true);
		}		
	}
	
	protected void txtStudentIdKeyTyped(KeyEvent e) {
		// TODO Auto-generated method stub
		
	}

	protected void txtStudentIdKeyPressed(KeyEvent evt) {
		if (evt.getKeyCode() == KeyEvent.VK_F1){
			showStudentModal();
		}
		evt.consume();
	}

	protected void btnStudentIdSearchActionPerformed(ActionEvent e) {
		showStudentModal();
	}
	
	public void showStudentModal(){
		String selected_purpose_of_visit = cmbPurposeOfVisit.getSelectedItem().toString();
		selected_purpose_of_visit = selected_purpose_of_visit.toUpperCase().toLowerCase().trim();
		if(selected_purpose_of_visit.trim().length() > 0){
			if(selected_purpose_of_visit.contains("hostel") || selected_purpose_of_visit.contains("meet the student")){
				ModalStudentList s = new ModalStudentList(txtStudentId, txtStudentName, true);
				s.setModal(true);
				s.setLocationRelativeTo(txtStudentId);
				s.show();
			}else if(selected_purpose_of_visit.contains("office check-in") || selected_purpose_of_visit.contains("office check-out")){
				ModalStudentList s = new ModalStudentList(txtStudentId, txtStudentName, true);
				s.setModal(true);
				s.setLocationRelativeTo(txtStudentId);
				s.show();
			}else{
				ModalEmployeeList s = new ModalEmployeeList(txtStudentId, txtStudentName, true);
				s.setModal(true);
				s.setLocationRelativeTo(txtStudentId);
				s.show();
			}			
		}else{
			JOptionPane.showMessageDialog(null, "Please select Purpose of visit first.");
		}
	}

	public void loadPurposeOfVisit(){
		Utilities util = new Utilities();
		Connection con = util.getConnection();
		String query = "select id,reason_for_visit from t_reason_for_visit_master ";
		Vector values = util.selectQuery(query, 2, con);
		
		cmbPurposeOfVisit.removeAllItems();
		for (int i = 0; i < values.size(); i++) {
			Vector temp = (Vector)values.elementAt(i);
			cmbPurposeOfVisit.addItem(temp.elementAt(1).toString().trim());
		}
		
		String selected_purpose_of_visit = cmbPurposeOfVisit.getSelectedItem().toString();
		selected_purpose_of_visit = selected_purpose_of_visit.toUpperCase().toLowerCase().trim();
		if(selected_purpose_of_visit.contains("office check-in") || selected_purpose_of_visit.contains("office check-out")){
			lblWhomeToMeet.setVisible(false);
			txtStudentId.setText("0");
			txtStudentId.setVisible(false);
			btnStudentIdSearch.setVisible(false);
			txtStudentName.setText("NA");;
			txtStudentName.setVisible(false);
		}else{
			lblWhomeToMeet.setVisible(true);
			txtStudentId.setText("");
			txtStudentId.setVisible(true);
			btnStudentIdSearch.setVisible(true);
			txtStudentName.setText("");;
			txtStudentName.setVisible(true);
		}		
	}
	
	protected void cancelButtonActionPerformed(ActionEvent e) {
		String pov = "";
		SFESampleView.POV = pov;
		setVisible(false);
		dispose();
	}

	protected void okButtonActionPerformed(ActionEvent e) {
		String pov = cmbPurposeOfVisit.getSelectedItem().toString().trim();
		pov = pov.toUpperCase().toLowerCase().trim();
		String pov_id = getReasonForVisitId(pov);
		String whom_to_meet_id = txtStudentId.getText().trim();
		String whom_to_meet_name = txtStudentName.getText().trim();
		
		whom_to_meet_id = (whom_to_meet_id == null || whom_to_meet_id.trim().length() <= 0)?"0":whom_to_meet_id;
		whom_to_meet_name = (whom_to_meet_name == null || whom_to_meet_name.trim().length() <= 0)?"NA":whom_to_meet_name;
		//System.out.println("111@@@purpose of visit: "+pov+"    whom_to_meet_id: "+whom_to_meet_id+"    whom_to_meet_name: "+whom_to_meet_name);
		
		if(pov.trim().length() >= 0){
			SFESampleView.POV = pov;
			SFESampleView.POV_ID = pov_id;
			SFESampleView.WHOM_TO_MEET_ID = whom_to_meet_id;
			SFESampleView.WHOM_TO_MEET_NAME = whom_to_meet_name;
			System.out.println("##");
		}
		if(pov.trim().contains("hostel") || pov.trim().contains("meet the student")){
			SFESampleView.WHOM_TO_MEET_TYPE = "student";
		}else if(pov.trim().contains("employee")){
			SFESampleView.WHOM_TO_MEET_TYPE = "employee";
		}else{
			SFESampleView.WHOM_TO_MEET_TYPE = "administrative";
		}
			
		//setVisible(true);
		dispose();
	}
	
	public String getReasonForVisitId(String reason_for_visit_name){
		String reason_for_visit_id = "";
		String query = " select id from t_reason_for_visit_master where reason_for_visit like '"+reason_for_visit_name+"' order by id limit 1 ";
		Utilities util = new Utilities();
		Connection con = util.getConnection();
		reason_for_visit_id = util.getField(query, con);
		return reason_for_visit_id;
	}
	
	public ImageIcon getResizedIcon(String imagename, int size){
		ImageIcon userImg = null;
		if(imagename.trim().length()>0){
			userImg = new ImageIcon("images/"+imagename);
			Image image = userImg.getImage();
			Image newimg = image.getScaledInstance(size, size,  java.awt.Image.SCALE_SMOOTH); // scale it the smooth way  
			userImg = new ImageIcon(newimg);			
		}
		return userImg;
	}
}

Commits for FingerPrint_5.2/src/test/ModalPurposeOfVisit.java

Diff revisions: vs.
Revision Author Commited Message
1 lingaraj picture lingaraj Sat 24 Nov, 2018 09:32:39 +0000