-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.c
449 lines (423 loc) · 16 KB
/
config.c
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
/*
*Name : Hussein Muhammad Ahmad AlBaqry
*Embedded System Track
*Group 4
*New Adminstrative Capital Branch
*/
// Implementation file (Functions implementation)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "std_types.h"
#include "config.h"
/*-----------------------------------********************Admin Interface*********************--------------------------------------------*/
/*
* Function : Create New Client account (Node) And Append It to List To Make Linked list
* Operands : Head : takes The Start of the list (Head) to Know the end of list to append New one
*/
void Create_Account(client_Acc **head_ref) {
client_Acc *new = (client_Acc *)malloc(sizeof(client_Acc));
if (new != NULL) {
Data(new);
client_Acc *current = *head_ref;
if (*head_ref == NULL) {
*head_ref = new;
} else {
while (current->Next != NULL) {
current = current->Next;
}
current->Next = new;
}
} else {
printf("Records are Full");
}
}
/*
* Function : The Data that will be Entered Each Time Create New client (Node)
* Operands : temp : The New client account (Node) That created to Enter Data
*/
void Data(client_Acc *temp) {
uint8 x = 0;
srand(time(NULL));
while (x < 3)
{
printf("Kindly Provide Full Name (at least first 4 names) -:\n ");
scanf(" %[^\n]", temp->Name);
for (uint8 i = 0; temp->Name[i] != '\0'; i++)
{ if (temp->Name[i] == ' ')
{
x++;
}
}
}
printf("Please Enter Address -: \n");
scanf(" %[^\n]", temp->Address);
while (strlen(temp->ID) < 14) {
printf("Kindly Provide ID Consisting of 14 Digits -: ");
scanf("%s", temp->ID);
}
printf("Please Enter age ");
scanf("%hu", &temp->age);
if (temp->age < 21) {
while (strlen(temp->Guardian_ID) < 14) {
printf("Kindly provide Guardian_ID Consisting of 14 Digits -: ");
scanf("%s", temp->Guardian_ID);
}
}
temp->Account_Status = 'A';
temp->Balance = 1000;
temp->Bank_ACC_ID = rand() + 10000000000;
temp->Pass = rand() + 10000;
temp->Next = NULL;
PrintN(temp);
}
/*
* Function : To Print The Client_Bank_ID and The Client_Password
* Operands : Nod : The New client (Node) That created to Print The User_Bank_ID and The Client_Password
*/
void PrintN(client_Acc *Nod) {
printf("\n\n********************************************************\n");
printf("******** Client_Bank_ID = %lu ********\n",
Nod->Bank_ACC_ID);
printf("******** Client_Password = %lu ********\n",
Nod->Pass);
printf("********************************************************\n\n\n");
}
/*
* Function : To Search In Data Of Client account what user_account i want to make (Transaction & change_account_status & Get_cash & Deposit)
* Operands : head : The first Address of My data to go search in list on what Client_account i want
* ID : the Client Account ID that i want to open it
*/
void Search_Admin(client_Acc *head_ref, uint32 ID) {
client_Acc *curr = head_ref;
uint16 sw;
uint16 lo = 1;
while (curr != NULL) {
if (curr->Bank_ACC_ID == ID) {
while (lo) {
printf("\n\n Name is %s \n", curr->Name);
printf(" Your ID is %s \n\n", curr->ID);
printf("\nPlease Choese What Process You Want\n");
printf("1-Make Transaction\n");
printf("2-Change Account Status\n");
printf("3-Get Cash\n");
printf("4-Deposit in Account\n");
printf("5-Return to main Menu\n");
scanf("%hu", &sw);
switch (sw) {
case 1:
admin_Transaction(curr, head_ref);
break;
case 2:
Change_Account_Status(curr);
break;
case 3:
Get_Cash(curr);
break;
case 4:
Deposit_in_Account(curr);
break;
case 5:
lo = 0;
break;
}
}
} else {
printf("\t\t\tNot found in our Records!...\n"
"\t----------------*******--*******--*******----------------\n");
}
if (lo == 0) {
break;
}
curr = curr->Next;
}
}
/*
* Function : That Function responsible for The Transaction Between Two Accunt The Current Account and The Account That I Want to Make Transaction With
* Operands : Curr : The current User
* Head : The first Address To Search on The List with the account id that i want to transfer money to him return
*/
void admin_Transaction(client_Acc *curr, client_Acc *head)
{
client_Acc *Tran = head;
uint32 ID_Transaction;
uint32 Money_Trans;
if (curr->Account_Status == 'A')
{
printf("\nKindly Provide Bank Account ID Consisting of 10 Digits -: ");
scanf("%lu", &ID_Transaction);
while (Tran != NULL)
{
if (Tran->Bank_ACC_ID == ID_Transaction)
{
if (Tran->Account_Status == 'A')
{
printf(
"\n\tPlease enter Balance to be transfered to "
"this account ");
scanf("%lu", &Money_Trans);
if (curr->Balance > Money_Trans)
{
curr->Balance = curr->Balance - Money_Trans;
Tran->Balance = Tran->Balance + Money_Trans;
printf(
"\n\n--------- Transaction accomplished successfully "
" --------- \n");
printf("--------- The Balance Transacted is %lu \n",
Money_Trans);
printf("--------- Your Balance Now is %lu \n",
curr->Balance);
printf(
"--------- The Balance Of Account you send "
"Money Now is %lu \n\n\n",
Tran->Balance);
} else
{
printf(
"\n Transaction has Failed, Please Checke Your "
"Balance \n");
break;
}
break;
} else
{
printf(
"\n***** The Account_Status is '%c' make sure The "
"Account you "
"want to send the money is 'A'ctive *****\n",
Tran->Account_Status);
break;
}
}
Tran = Tran->Next;
}
}
else
{
printf(
"\n\nThe Bank Account_Status Is '%c' Please Make sure your Account "
"Is 'A'ctive\n",
curr->Account_Status);
}
}
/*
* Function : the function that i can change the Account status to ("Active","Closed","Restricted")
* Operands : Curr : The current user to change account status
*/
void Change_Account_Status(client_Acc *curr)
{
uint16 Status;
printf("Please Select What Account Status\n");
printf("1-Set Account to Active State \n");
printf("2-Set Account to Restricted State \n");
printf("3-Set Account to Closed \n");
scanf("%hu", &Status);
switch (Status)
{
case 1:
curr->Account_Status = 'A';
printf("\n*****\t Accunt Status is Active \t*****\n");
break;
case 2:
curr->Account_Status = 'R';
printf("\n*****\t Accunt Status is Restricted \t*****\n");
break;
case 3:
curr->Account_Status = 'C';
printf("\n*****\t Accunt Status is Closed \t*****\n");
break;
}
}
/*
* Function : That function make me Withdraw money from my account
* Operands : Curr : the current user account that i want to Withdraw money
*/
void Get_Cash(client_Acc *curr)
{
uint32 Cash;
printf("\nPlease Enter Cash to get -: ");
scanf("%lu", &Cash);
if (curr->Balance > Cash)
{
printf("\n ---------------------------------------\n");
printf("------- Your Cash Before operation %lu --------\n",
curr->Balance);
printf(" ---------------------------------------\n\n");
curr->Balance = curr->Balance - Cash;
printf("\n ---------------------------------------\n");
printf("------- Your Cash After operation %lu --------\n",
curr->Balance);
printf(" ---------------------------------------\n\n");
}
else
{
printf("\tFailed !... Please check Your Balance\n");
printf("----------------*******************************************************----------------\n");
}
}
/*
* Function : That function make me Deposit on my account and increment My Balance of money
* Operands : Curr : the current user account that i want to Deposit
*/
void Deposit_in_Account(client_Acc *curr) {
uint32 Dep;
printf("\nPlease Enter Your Deposit -: ");
scanf("%lu", &Dep);
printf("\n ---------------------------------------\n");
printf("------- Your Cash Before Deposit %lu -------\n",
curr->Balance);
printf(" ---------------------------------------\n");
curr->Balance = curr->Balance + Dep;
printf("\n ---------------------------------------\n");
printf("------- Your Cash After Deposit %lu -------\n",
curr->Balance);
printf(" ---------------------------------------\n");
}
/*-----------------------------------********************Client Interface*********************--------------------------------------------*/
/*
* Function : To Search In Data Of User account what user_account I want to make (Transaction & change_account_status & Get_cash & Deposit)
* Operands : head : The first Address of My data to go search in list on what user_account I want
* ID : the Account ID that I want to open it
*/
void Search(client_Acc *head_ref, uint32 ID)
{
client_Acc *curr = head_ref;
uint16 sw;
uint16 lo = 1;
while (curr != NULL) {
if (curr->Bank_ACC_ID == ID) {
while (lo) {
printf("\n\n Name is %s \n", curr->Name);
printf(" Your ID is %s \n\n", curr->ID);
printf("\nPlease Choose What Operation You Want\n");
printf("1-Make Transaction\n");
printf("2-Change Account Password\n");
printf("3-Get Cash\n");
printf("4-Deposit in Account\n");
printf("5-Return to main Menu\n");
scanf("%hu", &sw);
switch (sw) {
case 1:
make_Transaction(curr, head_ref);
break;
case 2:
Change_Password(curr);
break;
case 3:
Get_Cash(curr);
break;
case 4:
Deposit_Acc(curr);
break;
case 5:
lo = 0;
break;
}
}
} else {
printf("\t\t\tNot found in our Records!...\n"
"\t----------------*******--*******--*******----------------\n");
}
if (lo == 0) {
break;
}
curr = curr->Next;
}
}
/*
* Function : for Transacting Between Two Account The Current Account and The Account That I Want to Make the make_Transaction With
* Operands : Curr : The current User
* Head : The first Address To Search on The List with the account ID that I want to transfer money to
*/
void make_Transaction(client_Acc *curr, client_Acc *head) {
client_Acc *Tran = head;
uint32 ID_Transaction;
uint32 Money_Trans;
if (curr->Account_Status == 'A') {
printf("\nPlease Enter Bank Account ID Consisting of 10 Digits -: ");
scanf("%lu", &ID_Transaction);
while (Tran != NULL) {
if (Tran->Bank_ACC_ID == ID_Transaction) {
if (Tran->Account_Status == 'A') {
printf(
"\nPlease enter balance to be transfered to "
"this account ");
scanf("%lu", &Money_Trans);
if (curr->Balance > Money_Trans) {
curr->Balance = curr->Balance - Money_Trans;
Tran->Balance = Tran->Balance + Money_Trans;
printf(
"\n\n--------- Transaction Accomplished Successfully "
" --------- \n");
printf("--------- The Money Transacted is %lu \n",
Money_Trans);
printf("--------- Your New Balance Now is %lu \n",
curr->Balance);
printf(
"--------- The Balance Of Account you send "
"Money Now is %lu \n\n\n",
Tran->Balance);
} else {
printf(
"\nTransaction has failed Please Checke Your "
"Money \n");
break;
}
break;
} else {
printf(
"***** The Account_Status is '%c' make sure The "
"Account you "
"want to send money is 'A'ctive *****\n",
Tran->Account_Status);
break;
}
}
Tran = Tran->Next;
}
} else {
printf(
"\n\nThe Bank Account_Status Is '%c' Please Make sure your Account "
"Is 'A'ctive\n",
curr->Account_Status);
}
}
/*
* Function : That function make me change My Password Account
* Operands : Curr : The current user account to change its Password
*/
void Change_Password(client_Acc *curr) {
uint32 pass;
// uint32 new_pass;
uint8 x = 3;
while (x--) {
printf("\nPlease Enter Your Current Password -: ");
scanf("%lu", &pass);
if (curr->Pass == pass) {
printf("Please Enter Your New Password ");
scanf("%lu", &curr->Pass);
// curr->Pass = new_pass;
printf("\n\t*****\t Your New Password is %lu \t*****\n\n",
curr->Pass);
break;
} else {
printf("\n Worng Password, remainning trials : %d \n", x);
}
}
}
/*
* Function : for Depositing on my account increasing My Balance of money
* Operands : Curr : the current user account that I want to Deposit to
*/
void Deposit_Acc(client_Acc *curr) {
uint32 Dep;
printf("\nPlease Enter Your Deposit -: ");
scanf("%lu", &Dep);
curr->Balance = curr->Balance + Dep;
printf(" ---------------------------------------\n");
printf("------- Your Cash After Deposit %lu -------\n",
curr->Balance);
printf(" ---------------------------------------\n");
}
/*******************------------------------------E.N.D--------------------------***********************/