-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNadraDBModel.java
More file actions
88 lines (76 loc) · 2.51 KB
/
Copy pathNadraDBModel.java
File metadata and controls
88 lines (76 loc) · 2.51 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
package model;
import java.io.*;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
public class NadraDBModel {
private String CNIC;
private String issued_date;
private String expiry_date;
private static String filename;
public NadraDBModel(){}
// Constructors
public NadraDBModel(String CNIC1, String iss_date, String exp_date) {
this.CNIC = CNIC1;
this.issued_date = iss_date;
this.expiry_date = exp_date;
}
public static void setFilename(String filename) {
NadraDBModel.filename = filename;
}
public static List<NadraDBModel> loadNadraData() {
List<NadraDBModel> nadraList = new ArrayList<>();
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line;
while ((line = reader.readLine()) != null) {
String[] parts = line.split(",");
if (parts.length == 3) {
String CNIC = parts[0].trim();
String issued_date = parts[1].trim();
String expiry_date = parts[2].trim();
nadraList.add(new NadraDBModel(CNIC, issued_date, expiry_date));
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return nadraList;
}
public static void saveNadraData(List<NadraDBModel> nadraList) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
for (NadraDBModel ndb : nadraList) {
writer.write(ndb.CNIC + "," + ndb.issued_date + "," + ndb.expiry_date);
writer.newLine();
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
// Getters and Setters
public String getCNIC() {
return CNIC;
}
public String getIssuedDate() {
return issued_date;
}
public String getExpiryDate() {
return expiry_date;
}
public void setExpiryDate(String expiry_date) {
this.expiry_date = expiry_date;
}
public static void updateExpiryDate(List<NadraDBModel> nadraList, String CNIC, String newExpiryDate) {
for (NadraDBModel ndb : nadraList) {
if (ndb.getCNIC().equals(CNIC)) {
ndb.setExpiryDate(newExpiryDate);
break;
}
}
saveNadraData(nadraList);
}
}