-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPersistentStorage.java
More file actions
executable file
·186 lines (150 loc) · 6.42 KB
/
PersistentStorage.java
File metadata and controls
executable file
·186 lines (150 loc) · 6.42 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
package ProcessSale;
import java.util.ArrayList;
/*persistant storage class*/
public class PersistentStorage{
private static PersistentStorage ps = null;
private DataBaseConnection db = null;
private PersistentStorage(){
db = DataBaseConnection.getInstance();
}
public static PersistentStorage getInstance(){
if(ps == null){
ps = new PersistentStorage();
}
else{
return ps;
}
return ps;
}
public boolean closeConnection(){
return db.close();
}
public boolean isUser(String user){
return db.isInDataBase(user, "Users");
}
public boolean isInventory(String barcode){
return db.isInDataBase(barcode, "Inventory");
}
public boolean isTransaction(String id) {
return db.isInDataBase(id, "Transaction");
}
public boolean checkPassword(String userID, String password){
return db.verifyMatch(userID, password, "Users", "employee_id", "passwords");
}
public boolean checkRolePermission(String password, String role) {
return db.verifyMatch(password, role, "Users", "passwords", "role");
}
public String getRole(String employeeID) {
String query = "select role from users where employee_id = '"+ employeeID+"'";
ArrayList<ArrayList<String>> outer = new ArrayList<ArrayList<String>>();
ArrayList<String> inner = new ArrayList<String>();
outer = db.newQuery(query, 1);
inner = outer.get(0);
String combined = "";
for(int i=0; i<inner.size(); i++){
combined += inner.get(i) + "";
}
return combined;
}
/*
public int getRentalDueDate(String){
String query = "select DUE_DATE from transaction where barcode = '"+barcode+"'" ;
ArrayList<ArrayList<String>> outer = new ArrayList<ArrayList<String>>();
ArrayList<String> inner = new ArrayList<String>();
outer = db.newQuery(query, 1);
inner = outer.get(0);
return Integer.parseInt(inner.get(0));
}*/
public String getProductDesc(String barcode) {
String query = "select name_of_product, quantity, color, size_of_shirt, unit_price from inventory where barcode = '"+barcode+"'";
ArrayList<ArrayList<String>> outer = new ArrayList<ArrayList<String>>();
ArrayList<String> inner = new ArrayList<String>();
outer = db.newQuery(query, 5);
inner = outer.get(0);
String combined = "";
for(int i=0; i<inner.size(); i++){
combined += inner.get(i) + "";
}
return combined;
}
public String getProductInfo(String barcode){
String query = "select name_of_product, color, size_of_shirt from inventory where barcode = '"+barcode+"'";
ArrayList<ArrayList<String>> outer = new ArrayList<ArrayList<String>>();
ArrayList<String> inner = new ArrayList<String>();
outer = db.newQuery(query, 3);
inner = outer.get(0);
String combined = "";
for(int i=0; i<inner.size(); i++){
combined += inner.get(i);
}
return combined;
}
public int getSaleProductPrice(String barcode) {
String query = "select unit_price from inventory where barcode = '"+barcode+"'";
ArrayList<ArrayList<String>> outer = new ArrayList<ArrayList<String>>();
ArrayList<String> inner = new ArrayList<String>();
outer = db.newQuery(query, 1);
inner = outer.get(0);
return Integer.parseInt(inner.get(0));
}
public int getRentProductPrice(String barcode){
String query = "select RENTAL_PRICE from inventory where barcode = '"+barcode+"'";
ArrayList<ArrayList<String>> outer = new ArrayList<ArrayList<String>>();
ArrayList<String> inner = new ArrayList<String>();
outer = db.newQuery(query, 1);
inner = outer.get(0);
return Integer.parseInt(inner.get(0));
}
//returns the rental information as in its tansaction_Id, Total_Price, and DUe_Date
public String getDueDate(String transactionID){
String query = "select DUE_DATE from TRANSACTION where TRANSACTION_ID ='"+transactionID+"'";
ArrayList<ArrayList<String>> outer = new ArrayList<ArrayList<String>>();
ArrayList<String> inner = new ArrayList<String>();
outer = db.newQuery(query, 3);
inner = outer.get(0);
outer = db.newQuery(query, 1);
inner = outer.get(0);
return inner.get(0);
}
//returns transaction type
public String getTransactionType (String transactionId){
String query = "select TRANSACTION_TYPE from TRANSACTION where TRANSACTION_ID ='"+transactionId+"'";
ArrayList<ArrayList<String>> outer = new ArrayList<ArrayList<String>>();
ArrayList<String> inner = new ArrayList<String>();
outer = db.newQuery(query, 1);
inner = outer.get(0);
return inner.get(0);
}
public boolean makePayment(String id, String type, double price, int quantity, String paymentType, String date, String due, String creditCardNum) {
String query = "insert into transaction values('"+id+"','"+type+"',"+price+","+quantity+",'"+paymentType+"','"+date+"','"+due+"','"+creditCardNum+"')";
return db.newUpdateQuery(query);
}
public boolean updateInventory(String barcode, int qty, int id){
String query1 = "update inventory set quantity = quantity - "+qty+" where barcode = '"+barcode+"'";
String query2 = "insert into cart values ('" + id + "','" + barcode + "'," + qty + ")";
db.newUpdateQuery(query1);
return db.newUpdateQuery(query2);
}
public boolean updateDueDate(String transactionID){
String query1 = "update transaction set DUE_DATE = '0' where transaction_ID = '"+transactionID+"'";
return db.newUpdateQuery(query1);
}
public boolean returnRentedItem(String barcode, int qty) {
String query2 = "update inventory set quantity = quantity + "+qty+" where barcode = '"+barcode+"'";
return db.newUpdateQuery(query2);
}
public boolean returnSoldItem(String transactionID, String barcode, int qty) {
String query2 = "insert into returnedinventory values(" + barcode + "," + qty + "," + transactionID + ")";
return db.newUpdateQuery(query2);
}
//used to show rental is done
public boolean zeroDueDate(String id){
String query2 = "update tansaction set DUE_DATE = '0' where TRANSACTION_ID = '"+id+"'";
return db.newUpdateQuery(query2);
}
public boolean removeFromCart(String barcode, int qty, int id) {
returnRentedItem(barcode, qty);
String query2 = "delete from cart where TRANSACTION_ID = " + id;
return db.newUpdateQuery(query2);
}
}