-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAttendence.java
More file actions
331 lines (289 loc) · 14.2 KB
/
Attendence.java
File metadata and controls
331 lines (289 loc) · 14.2 KB
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
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Reception;
import Reception.Reception_Welcome;
import Secure.DBConnect;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
/**
*
* @author User
*/
public class Attendence extends javax.swing.JFrame {
int count=0;
String exists="no";
/**
* Creates new form Attendence
*/
public Attendence() {
initComponents();
setLocationRelativeTo(null);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel2 = new javax.swing.JLabel();
jEmpId = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jLabel3 = new javax.swing.JLabel();
cmbMonth = new javax.swing.JComboBox();
jGetDetails = new javax.swing.JButton();
jbtnIncrement = new javax.swing.JButton();
jLabel4 = new javax.swing.JLabel();
txtDays = new javax.swing.JTextField();
jbtnDecrement = new javax.swing.JButton();
jbtnUpdate = new javax.swing.JButton();
jbtnReset = new javax.swing.JButton();
jbtnBack = new javax.swing.JButton();
jLabel5 = new javax.swing.JLabel();
jLabel1.setText("jLabel1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Attendence");
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());
jLabel2.setText("Employee Id :");
jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 50, -1, -1));
jPanel1.add(jEmpId, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 50, 160, -1));
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null},
{null, null},
{null, null},
{null, null}
},
new String [] {
"Employee Name", "Type"
}
));
jScrollPane1.setViewportView(jTable1);
jPanel1.add(jScrollPane1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 290, 430, 240));
jLabel3.setText("Month :");
jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 130, -1, -1));
cmbMonth.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Select", "Jan", "Feb", "Mar", "Apr", "May", "June", "July", "Aug", "Sep", "Oct", "Nov", "Dec" }));
cmbMonth.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cmbMonthActionPerformed(evt);
}
});
jPanel1.add(cmbMonth, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 130, 160, -1));
jGetDetails.setText("Get Details");
jGetDetails.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jGetDetailsActionPerformed(evt);
}
});
jPanel1.add(jGetDetails, new org.netbeans.lib.awtextra.AbsoluteConstraints(490, 60, -1, -1));
jbtnIncrement.setText("Increment");
jbtnIncrement.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnIncrementActionPerformed(evt);
}
});
jPanel1.add(jbtnIncrement, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 420, 120, -1));
jLabel4.setText("No of Days : ");
jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 210, -1, -1));
jPanel1.add(txtDays, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 210, 160, -1));
jbtnDecrement.setText("Decrement");
jbtnDecrement.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnDecrementActionPerformed(evt);
}
});
jPanel1.add(jbtnDecrement, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 460, 120, -1));
jbtnUpdate.setText("Update");
jbtnUpdate.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnUpdateActionPerformed(evt);
}
});
jPanel1.add(jbtnUpdate, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 500, 120, -1));
jbtnReset.setText("Reset");
jbtnReset.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnResetActionPerformed(evt);
}
});
jPanel1.add(jbtnReset, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 540, 120, -1));
jbtnBack.setText("Back");
jbtnBack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jbtnBackActionPerformed(evt);
}
});
jPanel1.add(jbtnBack, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 590, 120, -1));
jLabel5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/all.jpg"))); // NOI18N
jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1000, 670));
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 1000, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 666, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 0, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jGetDetailsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jGetDetailsActionPerformed
try {
Statement stat= DBConnect.getStatemennt();
ResultSet rs1 = stat.executeQuery("SELECT Fname,Lname,Type FROM employees WHERE employees.Employee_ID='" + jEmpId.getText() + "'" );
boolean type=false;
DefaultTableModel DataModel = (DefaultTableModel)jTable1.getModel();
DataModel.setRowCount(0);
while(rs1.next()) {
String Name=rs1.getString("Fname")+ " " +rs1.getString("Lname");
//String Type=rs1.getString(3);
DataModel.addRow(new Object[]{Name,rs1.getString(3)});
type=true;
}
if(type==false)
{
JOptionPane.showMessageDialog(this,"Warning!Invalid Employee No","Unsuccess!",JOptionPane.INFORMATION_MESSAGE);
}
}
catch (SQLException ex) {
Logger.getLogger(Attendence.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_jGetDetailsActionPerformed
private void jbtnIncrementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnIncrementActionPerformed
if(cmbMonth.getSelectedItem()=="Select"){
JOptionPane.showMessageDialog(this,"Select a valid Month","Unsuccess!",JOptionPane.INFORMATION_MESSAGE);
}
else{
++count;
txtDays.setText(Integer.toString(count));
}//GEN-LAST:event_jbtnIncrementActionPerformed
}
private void cmbMonthActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbMonthActionPerformed
try {
Statement stat= DBConnect.getStatemennt();
ResultSet rs = stat.executeQuery( "SELECT "+cmbMonth.getSelectedItem().toString()+" FROM attendence WHERE Emp_Id='"
+ jEmpId.getText()+"'") ;
if (rs.next()){
count = Integer.parseInt(rs.getString(1));
exists="yes";
}
txtDays.setText(Integer.toString(count));
} catch(SQLException ex){
JOptionPane.showMessageDialog(null, ex);
}
}//GEN-LAST:event_cmbMonthActionPerformed
private void jbtnDecrementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnDecrementActionPerformed
if(cmbMonth.getSelectedItem()=="Select"){
JOptionPane.showMessageDialog(this,"Select a valid Month","Unsuccess!",JOptionPane.INFORMATION_MESSAGE);
}
else if (count==0){
JOptionPane.showMessageDialog( this, "Cannot Decrement Further","Error", JOptionPane.ERROR_MESSAGE);
return;
}
else{
--count;
txtDays.setText(Integer.toString(count));
}
}//GEN-LAST:event_jbtnDecrementActionPerformed
private void jbtnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnUpdateActionPerformed
if(cmbMonth.getSelectedItem()=="Select"){
JOptionPane.showMessageDialog(this,"Select a valid Month","Unsuccess!",JOptionPane.INFORMATION_MESSAGE);
}
try {
Statement stat= DBConnect.getStatemennt();
if (exists.equals("yes")){
stat.executeUpdate("UPDATE attendence SET "+cmbMonth.getSelectedItem().toString()+"='"+Integer.toString(count)+"' WHERE attendence.Emp_Id='"
+ jEmpId.getText()+"'") ;;
}//GEN-LAST:event_jbtnUpdateActionPerformed
else{
stat.executeUpdate("INSERT INTO attendence(Emp_Id,"+cmbMonth.getSelectedItem().toString()+") "
+ "VALUES ('"+ jEmpId.getText()+"','"+ txtDays.getText()+"')");
}
JOptionPane.showMessageDialog(this,"Successfully Updated","Sucess",JOptionPane.INFORMATION_MESSAGE);
}
catch (SQLException ex) {
Logger.getLogger(Attendence.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void jbtnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnResetActionPerformed
jEmpId.setText(null);
//cmbMonth.setSelectedItem.equals();
txtDays.setText("");
//jTable1.setModel(null);
// jTable1.setRowCount(0);
}//GEN-LAST:event_jbtnResetActionPerformed
private void jbtnBackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnBackActionPerformed
Reception_Welcome rec_welcome = new Reception_Welcome();
rec_welcome.setVisible(true);
this.setVisible(false);
}//GEN-LAST:event_jbtnBackActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Attendence.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Attendence.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Attendence.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Attendence.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Attendence().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JComboBox cmbMonth;
private javax.swing.JTextField jEmpId;
private javax.swing.JButton jGetDetails;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JButton jbtnBack;
private javax.swing.JButton jbtnDecrement;
private javax.swing.JButton jbtnIncrement;
private javax.swing.JButton jbtnReset;
private javax.swing.JButton jbtnUpdate;
private javax.swing.JTextField txtDays;
// End of variables declaration//GEN-END:variables
}