-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgram.cs
389 lines (345 loc) · 15.1 KB
/
Program.cs
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
379
380
381
382
383
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data.OleDb;
namespace TermProject
{
class Program
{
private Worker myWorker = new Worker();
private User myUser = new User();
private Vehicle myVehicle = new Vehicle();
private VehicleCollection vehicles = new VehicleCollection();
private RentalCollection rentals = new RentalCollection();
private bool keepRunning = true;
public Program()
{
while (keepRunning == true) { RunProgram(); }
}
public static void Main(string[] args)
{
Program myProg = new Program();
}
private void RunProgram()
{
ParseMainInput(MainMenuPrompt());
}
//Prompts the Main menu of options, returns the users input #
private int MainMenuPrompt()
{
Console.WriteLine("\nTo view worker information: Press 1 ");
Console.WriteLine("To add a new worker: Press 2");
Console.WriteLine("To update a worker: Press 3");
Console.WriteLine("To delete a worker: Press 4");
Console.WriteLine("\nTo view vehicle information: Press 5 ");
Console.WriteLine("To add a new vehicle: Press 6");
Console.WriteLine("To update a vehicle: Press 7");
Console.WriteLine("To delete a vehicle: Press 8");
Console.WriteLine("\nTo view user information: Press 9 ");
Console.WriteLine("To add a new user: Press 10");
Console.WriteLine("To update a user: Press 11");
Console.WriteLine("To delete a user: Press 12");
Console.WriteLine("To view a list of good and available bikes: Press 13");
Console.WriteLine("To view a list of all active rentals: Press 14");
int response = Convert.ToInt32(Console.ReadLine());
return response;
}
private void ParseMainInput(int inputInt)
{
switch (inputInt)
{
case 1:
ShowWorkerTransaction();
break;
case 2:
CreateNewWorkerTrans();
break;
case 3:
ModifyWorkerTrans();
break;
case 4:
ModifyWorkerTrans();
break;
case 5:
GetAndShowVehicle();
break;
case 6:
CreateNewVehicleTrans();
break;
case 7:
ModifyVehicleTrans();
break;
case 8:
DeleteVehicleTrans();
break;
case 9:
GetAndShowUser();
break;
case 10:
CreateNewUserTrans();
break;
case 11:
ModifyUserTrans();
break;
case 12:
DeleteUserTrans();
break;
case 13:
vehicles.PopulateWithGoodAndAvailableBikes();
vehicles.PrintAll();
break;
case 14:
rentals.PopulateWithRentedOutBikes();
rentals.PrintAll();
break;
}
}
//Prompts for an id and displays the worker with that ID #
private void ShowWorkerTransaction()
{
Console.WriteLine("\n----------------");
Console.WriteLine("Get Worker Information");
Console.WriteLine("----------------");
GetAndShowWorker();
Console.WriteLine("\n\n\n\n");
}
private void GetAndShowWorker()
{
int workerId;
Console.Write("Please enter the worker id: ");
workerId = Convert.ToInt32(Console.ReadLine());
//view specified worker from worker table
try
{
myWorker.Populate(workerId);
if (myWorker.ID == 0)
Console.WriteLine("Not a valid worker number.");
else
Console.WriteLine(myWorker.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
//Prompts for new worker's information then insersts the new user into the database
private void CreateNewWorkerTrans()
{
Console.WriteLine("\n----------------");
Console.WriteLine("Create New Worker");
Console.WriteLine("----------------");
ReadAssignWorkerInput();
myWorker.Insert();
Console.WriteLine("\n\n\n\n");
}
//Prompts for and reads input for a worker's variables (used in creation and modification)
//This would end up being a lot cleaner in a GUI situation
private void ReadAssignWorkerInput()
{
Console.Write("Please enter the banner Id: ");
myWorker.BannerID = Console.ReadLine();
Console.Write("Please enter the first name: ");
myWorker.FirstName = Console.ReadLine();
Console.Write("Please enter the last name: ");
myWorker.LastName = Console.ReadLine();
Console.Write("Please enter the phone number: ");
myWorker.PhoneNumber = Console.ReadLine();
Console.Write("Please enter the email address: ");
myWorker.Email = Console.ReadLine();
Console.Write("Please enter the credential: ");
myWorker.Credential = Console.ReadLine();
Console.Write("Please enter the worker password: ");
myWorker.WorkerPassword = Console.ReadLine();
Console.Write("Please enter some notes: ");
myWorker.Notes = Console.ReadLine();
Console.Write("Please enter the status: ");
myWorker.Status = Console.ReadLine();
myWorker.DateStatusUpdated = (DateTime.Now.ToString("yyyy-MM-dd"));
}
//Modify an existing worker, Prompts for a worker's ID then provides his information and a prompt to modify the worker
private void ModifyWorkerTrans()
{
Console.WriteLine("\n----------------");
Console.WriteLine("Modify an existing Worker Information");
Console.WriteLine("----------------");
GetAndShowWorker();
Console.WriteLine("Is this the worker to modify? Enter 'y' to confirm modify, any other input will cancel modify");
string responce = Console.ReadLine();
if (responce == "y") { ReadAssignWorkerInput(); myWorker.Update(); }
else { Console.WriteLine("Worker not modified"); }
Console.WriteLine("\n\n\n\n");
}
//Delete a worker, Prompts for the workers ID, displays the worker than prompts to confirm that this is the correct decision. Will delete after prompt
private void DeleteWorkerTrans()
{
Console.WriteLine("Delete a worker,");
GetAndShowWorker();
Console.WriteLine("Is this the worker to delete? Enter 'y' to confirm delete, any other input will cancel deletion");
string responce = Console.ReadLine();
if (responce == "y") { myWorker.Delete(); }
else { Console.WriteLine("Worker not deleted"); }
Console.WriteLine("\n\n\n\n");
}
//*****************************************************************************************
//
private void ShowUserTransaction()
{
Console.WriteLine("\n----------------");
Console.WriteLine("Get User Information");
Console.WriteLine("----------------");
GetAndShowUser();
Console.WriteLine("\n\n\n\n");
}
//Prompts for an id and displays the user with that ID #
private void GetAndShowUser()
{
int userId;
Console.Write("Please enter the user id: ");
userId = Convert.ToInt32(Console.ReadLine());
//view specified user from user table
try
{
myUser.Populate(userId);
if (myUser.ID == 0)
Console.WriteLine("Not a valid user number.");
else
Console.WriteLine(myUser.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
//Prompts for new user's information then insersts the new user into the database
private void CreateNewUserTrans()
{
ReadAssignUserInput();
myUser.Insert();
}
//Prompts for and reads input for a user's variables (used in creation and modification)
//This would end up being a lot cleaner in a GUI situation
private void ReadAssignUserInput()
{
Console.Write("Please enter the banner Id: ");
myUser.BannerID = Console.ReadLine();
Console.Write("Please enter the first name: ");
myUser.FirstName = Console.ReadLine();
Console.Write("Please enter the last name: ");
myUser.LastName = Console.ReadLine();
Console.Write("Please enter the phone number: ");
myUser.PhoneNumber = Console.ReadLine();
Console.Write("Please enter the email address: ");
myUser.Email = Console.ReadLine();
Console.Write("Please enter the user type: ");
myUser.UserType = Console.ReadLine();
Console.Write("Please enter some notes: ");
myUser.Notes = Console.ReadLine();
Console.Write("Please enter the status: ");
myUser.Status = Console.ReadLine();
myUser.DateStatusUpdated = (DateTime.Now.ToString("yyyy-MM-dd"));
}
//Modify an existing user, Prompts for a user's ID then provides his inpormation and a prompt to modify the user
private void ModifyUserTrans()
{
GetAndShowUser();
Console.WriteLine("Is this the user to modify? Enter 'y' to confirm modify, any other input will cancel modify.");
string responce = Console.ReadLine();
if (responce == "y") { ReadAssignUserInput(); myUser.Update(); } else { Console.WriteLine("User not modified"); }
}
//Delete a user, Prompts for the user's ID, displays the user than prompts to confirm that this is the correct decision.
//Will delete after prompt
private void DeleteUserTrans()
{
Console.WriteLine("Delete a User,");
GetAndShowUser();
Console.WriteLine("Is this the user to delete? Enter 'y' to confirm delete, any other input will cancel deletion");
string responce = Console.ReadLine();
if (responce == "y") { myUser.Delete(); } else { Console.WriteLine("User not deleted"); }
}
//*****************************************************************************************
//
private void ShowVehicleTransaction()
{
Console.WriteLine("\n----------------");
Console.WriteLine("Get Vehicle Information");
Console.WriteLine("----------------");
GetAndShowVehicle();
Console.WriteLine("\n\n\n\n");
}
//Prompts for an id and displays the vehicle with that ID #
private void GetAndShowVehicle()
{
int vehicleId;
Console.Write("Please enter the vehicle id: ");
vehicleId = Convert.ToInt32(Console.ReadLine());
//view specified worker from worker table
try
{
myVehicle.Populate(vehicleId);
if (myVehicle.ID == 0)
Console.WriteLine("Not a valid vehicle number.");
else
Console.WriteLine(myVehicle.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
//Prompts for new vehicle's information then insersts the new vehicle into the database
private void CreateNewVehicleTrans()
{
Console.WriteLine("\n----------------");
Console.WriteLine("Create new Vehicle");
Console.WriteLine("----------------");
ReadAssignVehicleInput();
myVehicle.Insert();
}
//Prompts for and reads input for a vehicle's variables (used in creation and modification)
//This would end up being a lot cleaner in a GUI situation
private void ReadAssignVehicleInput()
{
Console.Write("Please enter the vehicle make: ");
myVehicle.BikeMake = Console.ReadLine();
Console.Write("Please enter the model number: ");
myVehicle.ModelNumber = Console.ReadLine();
Console.Write("Please enter serial number: ");
myVehicle.SerialNumber = Console.ReadLine();
Console.Write("Please enter the color: ");
myVehicle.Color = Console.ReadLine();
Console.Write("Please enter the description: ");
myVehicle.Description = Console.ReadLine();
Console.Write("Please enter the location: ");
myVehicle.Location = Console.ReadLine();
Console.Write("Please enter the physical condition: ");
myVehicle.PhysicalCondition = Console.ReadLine();
Console.Write("Please enter some notes: ");
myVehicle.Notes = Console.ReadLine();
Console.Write("Please enter the status: ");
myVehicle.Status = Console.ReadLine();
myVehicle.DateStatusUpdated = (DateTime.Now.ToString("yyyy-MM-dd"));
}
//Modify an existing vehicle, Prompts for a vehicle's ID then provides the information and a prompt to modify the vehicle
private void ModifyVehicleTrans()
{
Console.WriteLine("\n----------------");
Console.WriteLine("Modify an existing Vehicle");
Console.WriteLine("----------------");
GetAndShowVehicle();
Console.WriteLine("Is this the vehicle to modify? Enter 'y' to confirm delete, any other input will cancel modify");
string responce = Console.ReadLine();
if (responce == "y") { ReadAssignVehicleInput(); myVehicle.Update(); } else { Console.WriteLine("Vehicle not modified"); }
}
//Delete a vehicle, Prompts for the vehicle ID, displays the vehicle than prompts to confirm that this is the correct decision. Will delete after prompt
private void DeleteVehicleTrans()
{
Console.WriteLine("Delete a vehicle,");
GetAndShowVehicle();
Console.WriteLine("Is this the vehicle to delete? Enter 'y' to confirm delete, any other input will cancel deletion");
string responce = Console.ReadLine();
if (responce == "y") { myVehicle.Delete(); } else { Console.WriteLine("Vehicle not deleted"); }
}
}
}