-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDelivery_Executive.java
More file actions
222 lines (200 loc) · 7.97 KB
/
Delivery_Executive.java
File metadata and controls
222 lines (200 loc) · 7.97 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
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;
public class Delivery_Executive {
Scanner sc=new Scanner(System.in);
int deliver_executive_id=15;
public int delivery_executive_login(Connection con) {
try {
Statement stmt=con.createStatement();
try {
System.out.println("************");
System.out.println("Welcome Delivery Executive");
System.out.println("Enter delivery executive ID: ");
String loginid=sc.next();
System.out.println("Enter your unique photo ID number:");
String password=sc.next();
System.out.println("************");
ResultSet rs=stmt.executeQuery("select * from delivery_executive where delivery_executive_id='"+loginid+"'"+ "and photo_id_number='"+password+"'");
boolean isnotEmpty = rs.first();
if(isnotEmpty) {
deliver_executive_id=rs.getInt(1);
System.out.println("your id "+deliver_executive_id);
stmt.close();
return deliver_executive_id;//logged in successfully
}
else return 0;// not able to login
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
return 0;
}
public void show_details(Connection con,int delivery){
try {
Statement stmt=con.createStatement();
System.out.println("Your details");
ResultSet rs=stmt.executeQuery("Select delivery_executive_name, delivery_executive_phone,"
+ " photo_id_type, photo_id_number, rating, delivery_executive_id, photo_id_number "
+ "from delivery_executive where delivery_executive_id = " +Integer.toString(delivery));
while(rs.next()) {
System.out.println("*************");
System.out.print(" Name: " + rs.getString("delivery_executive_name") );
System.out.println(" Contact: "+rs.getString("delivery_executive_phone"));
System.out.println(" Photo ID type: " + rs.getString("photo_id_type"));
System.out.println(" Photo ID number: " + rs.getString("photo_id_number"));
System.out.println(" Login ID: " + rs.getString("delivery_executive_id"));
System.out.println(" Password: " + rs.getString("photo_id_number"));
System.out.println(" Rating: " + rs.getString("rating") );
System.out.println();
}
}
catch (Exception e) {
System.out.println(e);
}
}
public int deliveryexec_register(Connection con){
System.out.print("Enter your login id");String loginid=sc.next();System.out.println();
System.out.print("Enter your password");String password=sc.next();System.out.println();
System.out.print("Enter your name");String name=sc.next();System.out.println();
System.out.print("Enter your ID type");String idType=sc.next();System.out.println();
System.out.print("Enter your ID number");String idNumber=sc.next();System.out.println();
System.out.print("Enter your contact number");String contact=sc.next();System.out.println();
// String rating=null;
try {
Statement stmt=con.createStatement();
try {
String query1="INSERT into delivery_executive (`delivery_executive_login_id`,`delivery_executive_password`,`deliver_executive_name`,`deliver_executive_phone`,`photo_id_type`,`photo_id_number`)";
String query2="VALUES ('"+loginid+"','"+password+"','"+name+"','"+contact+"','"+idType+"','"+idNumber+"')";
String final_query=query1+query2;
stmt.executeUpdate(final_query);
stmt.close();
return 1;
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
return 0;
}
public int delivery_executive_showresult(Connection con, String delivery, int flag) {
try {
Statement stmt=con.createStatement();
try {
if(flag==1) //View current pending orders assigned to you
{
ResultSet rs=stmt.executeQuery("Select A.order_id, B.first_name, A.status, A.order_ship_address_line1, A.order_ship_address_line2 from orders as A, customer as B where A.status='"+"Shipping"+"'"+"and A.customer_id = B.customer_id and A.order_delivery_partner ='" +delivery+"'");
boolean check=rs.first();
if(check) {
do {
System.out.println("************");
System.out.println("Order ID: "+rs.getString("A.order_id"));
System.out.println("Customer Name: " + rs.getString("B.first_name"));
System.out.println("Order Status: " + rs.getString("A.status"));
System.out.println("Address: " + rs.getString("A.order_ship_address_line1") + rs.getString("A.order_ship_address_line2"));
System.out.println("--------------");
}while(rs.next());
}
else {
System.out.println("No order is pending for you!");
}
return 1;
}
else if(flag==2) //View details of a particular order
{
try{
System.out.println("Please enter an orderID :) ");
int order=sc.nextInt();
ResultSet rs = stmt.executeQuery("Select A.order_id, C.first_name, C.contact, "
+ "A.order_ship_address_line1, A.order_ship_address_line2, A.order_ship_city_pincode, "
+ "A.order_ship_country, B.product_id, B.quantity, B.sum_total, D.payment_mode, D.paid "
+ "from orders as A, order_items as B, customer as C, invoice as D "
+ "where B.order_id = A.order_id and A.customer_id = C.customer_id and "
+ "D.order_id = A.order_id and A.order_id='" + order +"'"+
"and A.order_delivery_partner='" + delivery+"'");
//System.out.println(rs.first());
if(rs.first()) {
while(rs.next()) {
System.out.println("************");
System.out.println("Order ID: "+rs.getString("A.order_id"));
System.out.println("Customer Name: " + rs.getString("C.first_name"));
System.out.println("Customer contact: " + rs.getString("C.contact"));
System.out.println("Address: " + rs.getString("A.order_ship_address_line1") +
rs.getString("A.order_ship_address_line2") + rs.getString("A.order_ship_city_pincode") + rs.getString("A.order_ship_country"));
System.out.println("Product ID: "+rs.getString("B.product_id"));
System.out.println("Quantity: "+rs.getString("B.quantity"));
System.out.println("Sum total: "+rs.getString("B.sum_total"));
System.out.println("Payment Mode: "+rs.getString("D.payment_mode"));
System.out.println("Paid ( 1 for yes, 0 for no:)-> "+rs.getString("D.paid"));
System.out.println("--------------");
}
}
return 1;
}
catch (Exception e){
System.out.println("No such orders");
System.out.println(e);
return 0;
}
}
else if(flag==3) //Update your information
{
System.out.println("Your current details");
System.out.println("************");
show_details(con, Integer.parseInt(delivery));
System.out.println("--------------");
System.out.println("Press 1 to change your name");
System.out.println("Press 2 to change your contact");
System.out.println("Press 5 to change your login ID");
int choice=sc.nextInt();
if(choice==1)
{ System.out.println("--------------");
System.out.println("Enter new name: ");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set delivery_executive_name='" + update +"'"+"where delivery_executive_id='"+delivery+"'");
}
else if(choice==2)
{ System.out.println("--------------");
System.out.println("Enter new contact: ");
String update=sc.next();
stmt.executeUpdate("Update delivery_executive set delivery_executive_phone='" + update +"'"+ "where delivery_executive_id='"+delivery+"'");
}
else if(choice==5)
{
ResultSet rs=stmt.executeQuery("Select MAX(delivery_executive_id) from delivery_executive");
System.out.println("--------------");
System.out.println("Set value greater than "+rs.getString(1));
System.out.println("Enter new loginID: ");
String update=sc.next();
try {
stmt.executeUpdate("Update delivery_executive set delivery_executive_id='" + update +"'"+ "where delivery_executive_id='"+delivery+"'"); //login_password='"+password+"'");
}
catch(Exception E) {
System.out.println("Already taken username entered!");
}
}
return 1;
}
else if(flag==4)
{
return 1;
}
}
catch(Exception e) {
System.out.println(e);
}
}
catch(Exception e) {
System.out.println(e);
}
return 0;
}
}