-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathreqtable.java
More file actions
378 lines (318 loc) · 9.36 KB
/
Copy pathreqtable.java
File metadata and controls
378 lines (318 loc) · 9.36 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
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/** author @ Shreyash Arya (2015097)h
Tushita Rathore (2015108)
*/
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import javax.swing.*;
public class reqtable extends JFrame{
JTable table;
JButton approve,disapprove, cancel;
JTextField submitTF;
JLabel username = new JLabel("Enter Username:");
int mainCount=0;
Object[][] data = new Object[100][4];
static ArrayList<forRequests> list = new ArrayList<forRequests>();
int size=0;
{
for(int i=0;i<100;i++)
{
list.add(new forRequests());
}
}
data obj;
public reqtable()
{
//mainCount = count;
try {
obj = new data();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
size = reading(list);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String[] columnNames = {"Name", "Username", "Post", "Department"};
table = new JTable(data,columnNames){
private static final long serialVersionUID = 1L;
public boolean isCellEditable(int row, int column) {
return false;};};
table.setPreferredScrollableViewportSize(new Dimension(500,100));
table.setFillsViewportHeight(true);
//table.setBounds(100, 200, 500, 200);
//data[0][0]= "hi";
writeTable(list);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
scrollPane.setBounds(50, 50, 500, 200);
approve = new JButton("Approve");
approve.setBounds(100, 280, 100, 20);
disapprove = new JButton("Disapprove");
disapprove.setBounds(230, 280, 120, 20);
submitTF = new JTextField(250);
submitTF.setBounds(400, 310, 120, 20);
cancel = new JButton("Cancel");
cancel.setBounds(160, 320, 120, 20);
username.setBounds(400, 280, 120, 20);
//memreqdata mm = new memreqdata(this);
//add(table);
this.add(approve);
this.add(disapprove);
this.add(submitTF);
this.add(cancel);
this.add(username);
this.setLayout(null);
this.setSize(630,400);
this.setVisible(true);
this.setTitle("Member Registration Requests");
//this.setDefaultCloseOperation(EXIT_ON_CLOSE);
approveEvent app = new approveEvent();
approve.addActionListener(app);
dipproveEvent dap = new dipproveEvent();
disapprove.addActionListener(dap);
cancelEvent ce = new cancelEvent();
cancel.addActionListener(ce);
}
public static int reading(ArrayList<forRequests> list) throws IOException
{
FileReader inp = new FileReader("db1register.csv");
BufferedReader bfile = new BufferedReader(inp);
String line= bfile.readLine();
int a=0;
while(line!= null)
{
List<String> items = Arrays.asList(line.split("\\s*,\\s*"));
list.get(a).setName(items.get(0));
list.get(a).setPost(items.get(1));
list.get(a).setUsername(items.get(2));
list.get(a).setPassword(items.get(3));
list.get(a).setDep(items.get(4));
list.get(a).setDOB(items.get(5));
list.get(a).setAdr(items.get(6));
line= bfile.readLine();
a++;
}
return a;
}
int index =0;
int i1=0,i2=0,i3=0;
public class approveEvent implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String submit = submitTF.getText();
//System.out.println(size+"-------");
for(int i=0;i<size;i++)
{
i1 = obj.numSuperv();
i2 = obj.numStaff();
if(submit.equals(list.get(i).getUsername()))
{
index = i;
System.out.println(index + "****");
if(list.get(index).getPost().equals("supervisor"))
{
for(int j=0;j<i1;j++)
{
if(list.get(index).getDep().equals(obj.supervisors.get(j).getDepartment()))
{
//i1++;
//System.out.println(i1+"-------");
obj.supervisors.get(j).setName(list.get(index).getName());
obj.supervisors.get(j).setPost(list.get(index).getPost());
obj.supervisors.get(j).setUsername(list.get(index).getUsername());
obj.supervisors.get(j).setPassword(list.get(index).getPassword());
obj.supervisors.get(j).setId(obj.supervisors.get(j).getId());
obj.supervisors.get(j).setDepartment(list.get(index).getDep());
obj.supervisors.get(j).setDob(list.get(index).getDOB());
obj.supervisors.get(j).setAdr(list.get(index).getAdr());
}
}
}
else if(list.get(index).getPost().equals("staff"))
{
//i2++;
System.out.println(i2+"-------");
obj.staffs.get(i2).setName(list.get(index).getName());
obj.staffs.get(i2).setPost(list.get(index).getPost());
obj.staffs.get(i2).setUsername(list.get(index).getUsername());
obj.staffs.get(i2).setPassword(list.get(index).getPassword());
obj.staffs.get(i2).setId(generateID());
obj.staffs.get(i2).setDepartment(list.get(index).getDep());
obj.staffs.get(i2).setDob(list.get(index).getDOB());
obj.staffs.get(i2).setAdr(list.get(index).getAdr());
i2++;
}
list.remove(index);
size--;
try {
updatefile1(list,size);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
updatefile2(i1,i2);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
//System.out.println(i1+"-------");
//System.out.println(i2+"-------");
break;
}
}
dispose();
}
}
public class dipproveEvent implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String submit = submitTF.getText();
for(int i=0;i<size;i++)
{
if(submit.equals(list.get(i).getUsername()))
{
index = i;
list.remove(index);
size--;
try {
updatefile1(list,size);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
dispose();
}
}
public void writeTable(ArrayList<forRequests> list)
{
for(int i=0;i<size;i++)
{
data[i][0] = list.get(i).getName();
data[i][1] = list.get(i).getUsername();
data[i][2] = list.get(i).getPost();
data[i][3] = list.get(i).getDep();
}
}
public static void updatefile1(ArrayList<forRequests> list ,int s) throws IOException
{
FileWriter file = new FileWriter("db1register.csv",false);
BufferedWriter bw = new BufferedWriter(file);
PrintWriter pw = new PrintWriter(bw);
for(int i=0;i<s;i++)
{
pw.print( list.get(i).getName() +",");
pw.print( list.get(i).getPost() +",");
pw.print( list.get(i).getUsername() +",");
pw.print( list.get(i).getPassword() +",");
pw.print( list.get(i).getDep() +",");
pw.print( list.get(i).getDOB() +",");
pw.print( list.get(i).getAdr());
if(i!= s)
{
pw.print("\n");
}
}
s++;
pw.close();
}
public void updatefile2(int s1,int s2) throws IOException
{
FileWriter file = new FileWriter("db1basics.csv",false);
BufferedWriter bw = new BufferedWriter(file);
PrintWriter pw = new PrintWriter(bw);
pw.print( obj.admin.get(0).getName() +",");
pw.print( obj.admin.get(0).getPost() +",");
pw.print( obj.admin.get(0).getUsername() +",");
pw.print( obj.admin.get(0).getPassword() +",");
pw.print(obj.admin.get(0).getId()+",");
pw.print( "-,");
pw.print( obj.admin.get(0).getDob() +",");
pw.print( obj.admin.get(0).getAdr() + "\n");
//pw.println("\n");
for(int i=0;i< s1;i++)
{
pw.print( obj.supervisors.get(i).getName() +",");
pw.print( obj.supervisors.get(i).getPost() +",");
pw.print( obj.supervisors.get(i).getUsername() +",");
pw.print( obj.supervisors.get(i).getPassword() +",");
pw.print( obj.supervisors.get(i).getId() +",");
pw.print( obj.supervisors.get(i).getDepartment() +",");
pw.print( obj.supervisors.get(i).getDob() +",");
pw.print( obj.supervisors.get(i).getAdr());
if(i!= s1)
{
pw.print("\n");
}
}
for(int i=0;i< s2;i++)
{
pw.print( obj.staffs.get(i).getName() +",");
pw.print( obj.staffs.get(i).getPost() +",");
pw.print( obj.staffs.get(i).getUsername() +",");
pw.print( obj.staffs.get(i).getPassword() +",");
pw.print( obj.staffs.get(i).getId()+",");
pw.print( obj.staffs.get(i).getDepartment() +",");
pw.print( obj.staffs.get(i).getDob() +",");
pw.print( obj.staffs.get(i).getAdr());
if(i!= s2)
{
pw.print("\n");
}
}
//s1++;
s2++;
pw.close();
}
public String generateID()
{
int idd=0;
//Random rand = new Random();
String dpt = list.get(index).getDep();
if(dpt.equals("Electricity"))
{
idd = 1100 + (1 + (int)(Math.random() * 99));
}
else if(dpt.equals("Security"))
{
idd = 1200 + (1 + (int)(Math.random() * 99));
}
else if(dpt.equals("HVAC"))
{
idd = 1300 + (1 + (int)(Math.random() * 99));
}
else if(dpt.equals("Audio/Video"))
{
idd = 1400 + (1 + (int)(Math.random() * 99));
}
else if(dpt.equals("Housekeeping"))
{
idd = 1500 + (1 + (int)(Math.random() * 99));
}
return String.valueOf(idd);
}
public class cancelEvent implements ActionListener{
public void actionPerformed(ActionEvent e)
{
dispose();
}
}
}