-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankking System.cs
More file actions
676 lines (554 loc) · 28.4 KB
/
Copy pathBankking System.cs
File metadata and controls
676 lines (554 loc) · 28.4 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
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
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
using System;
using System.Collections;
namespace ConsoleApp5
{
class Clinet
{
// Felds
private string fullname;
public long Clint_Id { set; get; }
private string job;
private long phonenum;
private string addres;
public Account Current { get; set; }
public Account Business { set; get; }
//Constructer
public Clinet() { }
public Clinet(string fullname, long clint_id, string job, long phonenum, string addres)
{
this.fullname = fullname;
Clint_Id = clint_id;
this.job = job;
this.phonenum = phonenum;
this.addres = addres;
Current = null;
Business = null;
}
public void Print_info()
{
Console.WriteLine("\n\n\n\n\n\n\n\n\n\n" +
" ####___________________________________________________________________###\n" +
" ####___________________________________________________________________###\n" +
" ####___________________________________________________________________###\n\n" +
$" Name is {fullname}\n " +
$" Clint_ID is {Clint_Id}\n" +
$" Job is {job}\n" +
$" PhoneNumber is {phonenum}\n" +
$" Addres is {addres}\n\n" +
$" __________________________\n" +
" Accounts Detalis\n");
if (Current == null) Console.WriteLine(" No Current Account yet");
else Current.Print();
if (Business == null) Console.WriteLine(" No Business Account yet");
else Business.Print();
Console.WriteLine(" ####___________________________________________________________________###\n" +
" ####___________________________________________________________________###\n" +
" ####___________________________________________________________________###\n");
}
}
class Account : Clinet
{
public string Account_ID { get; set; }
public long Balance { get; set; }
public DateTime Time_Modifed { set; get; }
public string Type { set; get; }
//Constructer
public Account(long account_ID, long balance, string type, long clint_Id)
{
if (type == "Business")
Account_ID = "0BuAc" + Convert.ToString(account_ID);
else Account_ID = "0CuAc" + Convert.ToString(account_ID);
Balance = balance;
Time_Modifed = DateTime.Now;
Type = type;
Clint_Id = clint_Id;
}
public void Print()
{
Console.WriteLine($" {Type} Detalis\n" +
$" Account_ID: { Account_ID}\n" +
$" Client Id: {Clint_Id}\n" +
$" Balance: {Balance}\n" +
$" Time modifed: {Time_Modifed}\n");
}
}
static class BankingSystems
{
//felds
private static long Account_ID;
private static long Clint_ID;
private static ArrayList Accounts;
private static ArrayList Clinets;
//constructor
static BankingSystems()
{
Clint_ID = 20201000;
Account_ID = 2020101000;
Clinets = new ArrayList();
Accounts = new ArrayList();
}
//methods
public static void Add_Clint()
{
Console.Write("\n\n\n\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Add Client ______________________________###\n\n\n");
// Ask the Client Fo It Detalies
Console.Write(" FullName: ");
string fullName = Console.ReadLine();
Console.Write(" Job: ");
string job = Console.ReadLine();
Console.Write(" PhoneNumber: ");
long phonenum = Chick_input(100000000, 999999999, "Phone Number Must Be 9 Digits");
Console.Write(" Addres: ");
string addres = Console.ReadLine();
Clinet c = new Clinet(fullName, Clint_ID, job, phonenum, addres);
Console.Write("\n\n Choice 1 to Add a current account\n" +
" And 2 to Add business account: ");
long x = Chick_input(1, 2, "1 OR 2");
Console.Write(" Enter Balance : ");
long balance = Chick_input(10000, 999999999, "At Lest 10000");
Account Ac = null;
if (x == 1)
{
Ac = new Account(Account_ID, balance, "Current", c.Clint_Id);
// attack the account to to Accounts list
c.Current = Ac;
}
else if (x == 2)
{
Ac = new Account(Account_ID, balance, "Business", c.Clint_Id);
// attack the account to Accounts list
c.Business = Ac;
}
c.Print_info();
Console.Write(" Is this Your Correct Detalis ? press Enter to continue\n" +
" or press any other button else to dismass: ");
string Userbermatchion = Console.ReadLine();
// user permatchion to add account
if (Userbermatchion == "")
{
// increac the Accounts Id
Account_ID++;
// add account to accounts list
Accounts.Add(Ac);
//increase th e Clint_ID
Clint_ID++;
//Add the Client to Clients list
Clinets.Add(c);
Console.WriteLine("\n\n Client has been add successsfully");
}
else Console.WriteLine("\n\n Clint Dismiss");
Console.WriteLine("\n Press Any key to go to main menu");
Console.ReadKey();
}
public static void Add_Account()
{
Console.Write("\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Add Account _____________________________###\n\n\n");
// Seach abount client
Clinet c = search_client();
// if client found
if (c != null)
{
//Chick if the Client have no Current Account OR Business Account
// if bouth accounts had been addedd
if (c.Current == null || c.Business == null)
{
Account Ac = null;
if (c.Current == null)
{
Console.Write("\n\n\n ####___________________________________________________________________###\n" +
" ####______________________ Add Current Account ________________________###\n\n\n");
Console.Write(" Enter Balance: ");
// Balance that user input
long balance = Chick_input(10000, 999999999, "At Lest 10000");
Ac = new Account(Account_ID, balance, "Current", c.Clint_Id);
// attack the account to to Accounts list
}
else if (c.Business == null)
{
Console.Write("\n\n\n ####___________________________________________________________________###\n" +
" ####______________________ Add Business Account _______________________###\n\n\n");
Console.Write(" Enter Balance: ");
// Balance that user input
long balance = Chick_input(10000, 999999999, "At Lest 10000");
Ac = new Account(Account_ID, balance, "Business", c.Clint_Id);
// attack the account to to Accounts list
}
Ac.Print();
Console.Write(" This is Your Account Detalis ? press Enter to continue\n" +
" or any other button else to dismass: ");
string Userbermatchion = Console.ReadLine();
// user permatchion to add account
if (Userbermatchion == "")
{
// increac the Accounts Id
Account_ID++;
// add account to accounts list
if (Ac.Type == "Business")
c.Business = Ac;
else if (Ac.Type == "Current")
c.Current = Ac;
//add account to accounts
Accounts.Add(Ac);
Console.WriteLine("\n\n Account has been add successfully");
}
else Console.WriteLine("\n\n Account Dismiss");
}
else Console.WriteLine(" Business And Current Accounts has been Added");
}
else Console.WriteLine("\n Client Not Found");
Console.WriteLine("\n Press Any key to go to main menu");
Console.ReadKey();
}
public static void Search_Clint()
{
Console.Write("\n\n\n\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Search Client ___________________________###\n\n\n");
// use function search_client to search about client
Clinet c = search_client();
if (c != null)
c.Print_info();
else
Console.WriteLine(" Not Found\n" +
" Please Chick the ID ");
Console.WriteLine("\n Press Any key to go to main menu");
Console.ReadKey();
}
public static void Search_Account()
{
//Function to search about Account
Console.Write("\n\n\n\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Search_Account __________________________###\n\n\n");
Account Ac = search_account();
if (Ac != null)
Ac.Print();
else Console.WriteLine(" No Found\n" +
" Please Chick the ID ");
Console.WriteLine("\n Press Any key to go to main menu");
Console.ReadKey();
}
public static void Despost_Money()
{
Console.Write("\n\n\n\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Despost_Money ___________________________###\n\n\n");
// Search About Account
Account Ac = search_account();
//Chick if the account is found
if (Ac != null)
{
Console.Write(" Enter Cash: ");
//int balance = Convert.ToInt32(Console.ReadLine());
long balance = Chick_input(1, 999999999, "1-999999999");
//Add the cash to balance
Ac.Balance += balance;
Console.WriteLine($"Despost {balance} Successsfully");
}
else Console.WriteLine("Not found");
Console.WriteLine("\n Press any key to go to main menu");
Console.ReadKey();
}
public static void Withdraw_Money()
{
//Function to search about Account
Console.Write("\n\n\n\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Withdraw Money __________________________###\n\n\n");
Account Ac = search_account();
//Chick if the account is found
if (Ac != null)
{
Console.Write(" Enter Cash: ");
long balance = Chick_input(1, 999999999, "1-999999999");
if (Ac.Type == "Current" && Ac.Balance >= balance)
{
//subtract from balance
Ac.Balance -= balance;
Console.WriteLine(" WidthDrew done Successsfully");
}
else if (Ac.Type == "Business" && -1000000 <= (Ac.Balance - balance))
{
//subtract from balance
Ac.Balance -= balance;
Console.WriteLine(" WidthDrew done Successsfully");
}
else
Console.WriteLine("\a No Enought Money");
}
else Console.WriteLine("\a Not found");
Console.WriteLine("\n Press any key to go to main menu");
Console.ReadKey();
}
public static void Treansfer_money()
{
Account from = null;
Account To = null;
Console.Write("\n\n\n\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Treansfer_money _________________________###\n\n\n");
//Chick if the Account is found
while (true)
{
Console.WriteLine(" From: ");
from = search_account();
if (from != null)
{
from.Print();
break;
}
Console.Write(" This Account not found\n" +
" press 1 to Exit: ");
if (Console.ReadLine() == "1") break;
}
while ((from != null))
{
Console.WriteLine(" To: ");
To = search_account();
if (To != null)
{
To.Print();
break;
}
Console.Write(" This Account not found\n" +
" press 1 to Exit: ");
if (Console.ReadLine() == "1") break;
}
if (To != null)
{
if (from.Type == To.Type)
{
Console.Write(" Enter Cash: ");
long balance = Chick_input(1, 999999999, "1-999999999");
if (from.Type == "Current")
{
if (from.Balance >= balance)
{
from.Balance -= balance;
To.Balance += balance;
Console.WriteLine(" Treansfer Done Successsfully");
}
else
Console.WriteLine(" \aNo Enought Money");
}
else
{
if (from.Balance - balance >= -1000000)
{
from.Balance -= balance;
To.Balance += balance;
Console.WriteLine(" Treansfer Done Successsfully");
}
else
Console.WriteLine(" \aNo Enought Money");
}
}
else Console.WriteLine(" Treansfer only between accounts with the same type");
}
else Console.WriteLine(" Both Accounts Not Found");
Console.WriteLine("\n Press any key to go to main menu");
Console.ReadKey();
}
public static void Display_Clint()
{
foreach (Clinet c in Clinets)
c.Print_info();
Console.WriteLine("\n Press any key to go to main menu");
Console.ReadKey();
}
public static void Display_Accounts()
{
foreach (Account a in Accounts)
a.Print();
Console.WriteLine("\n Press any key to go to main menu");
Console.ReadKey();
}
public static void Close_Accounts()
{
Console.Write("\n\n\n\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Close Accounts __________________________###\n\n\n");
Account Ac = search_account();
// if found the account print it is informatchion
if (Ac != null)
{
Ac.Print();
//chick if the balance's account
if (Ac.Balance < 0)
Console.WriteLine($"\a You can not delete this Account because your Balance is {Ac.Balance}");
else if (Ac.Balance >= 0)
{
// تاكيد الحذف
Console.WriteLine(" Is That The Account You Looking For ?\n" +
" press 1 to Continue\n" +
$" Your Balance is {Ac.Balance}\n");
if (Console.ReadLine() == "1")
{
// delet the account
Accounts.Remove(Ac);
Console.WriteLine(" Account Deleted Successfully");
//search about client
Clinet c = null;
foreach (Clinet i in Clinets)
{
if (i.Clint_Id == Ac.Clint_Id)
{
c = i;
}
}
if (Ac.Type == "Business")
{
c.Business = null;
}
else if (Ac.Type == "Current")
{
c.Current = null;
}
// to chick if the client has no accounts
if (c.Current == null && c.Business == null)
{
c.Print_info();
Console.WriteLine(" Client deleted\n" +
" because he Has no Accounts");
Clinets.Remove(c);
}
}
}
}
else Console.WriteLine("\n Not Found");
Console.WriteLine("\n Press any key to go to main menu");
Console.ReadKey();
}
public static void Display_Account_Time()
{
Console.Write("\n\n\n\n\n ####___________________________________________________________________###\n" +
" ####_________________________ Search By Data __________________________###\n\n\n");
Console.WriteLine("Enter Date");
Console.WriteLine("Start At");
try
{
DateTime from = Convert.ToDateTime(Console.ReadLine());
Console.WriteLine("To");
DateTime to = Convert.ToDateTime(Console.ReadLine());
foreach (Account a in Accounts)
{
if (a.Time_Modifed.CompareTo(from) == 1 && a.Time_Modifed.CompareTo(to) == -1)
{
a.Print();
}
}
}
catch
{
Console.WriteLine("\n Enter Data Like Month/Days/years");
}
Console.WriteLine("\n Done...");
Console.WriteLine("\n Press any key to go to main menu");
Console.ReadKey();
}
//
private static Clinet search_client()
{
Console.Write(" Enter Id client: ");
long id = Chick_input(20201000, 99999999, "Clients ID stat at 20201000");
Clinet c = null;
foreach (Clinet f in Clinets)
if (f.Clint_Id == id)
c = f;
return c;
}
private static Account search_account()
{
Console.Write(" Enter ID account: ");
string id = Console.ReadLine();
Account c = null;
foreach (Account f in Accounts)
if (f.Account_ID == id)
c = f;
return c;
}
private static long Chick_input(int from, int to, string message)
{
int x = 0;
while (true)
{
try
{
x = Convert.ToInt32(Console.ReadLine());
if (x >= from && x <= to)
break;
else Console.WriteLine("\a Error\n" +
$" Number Should Be Between {message}\n");
}
catch
{
Console.WriteLine($"\a Error\n" +
$" Enter Number Not String");
}
}
return x;
}
}
class Program
{
static void Main(string[] args)
{
Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n Welcome to GID Banking System\n");
Console.ReadKey();
while (true)
{
Console.Clear();
Console.Write(
"\n\n\n\n\n\n" +
" ####___________________________________________________________________###\n" +
" ####___________________________________________________________________###\n" +
" ####___________________________________________________________________###\n\n" +
" Enter 1 Add Clint \n" +
" Enter 2 Open New Account \n" +
" Enter 3 Search Clint\n" +
" Enter 4 Search Account\n" +
" Enter 5 Despost Money\n" +
" Enter 6 Withdraw Money\n" +
" Enter 7 Display list of Accounts\n" +
" Enter 8 Display list of Clients\n" +
" Enter 9 Treansfer money\n" +
" Enter 10 Close Account\n" +
" Enter 11 Display list of Account \n" +
" in specifed Time\n" +
" Enter 12 to Exit\n" +
" ####___________________________________________________________________###\n" +
" ####___________________________________________________________________###\n" +
" ####___________________________________________________________________###\n" +
" ");
string x = Convert.ToString(Console.ReadLine());
Console.Clear();
if (x == "1")
BankingSystems.Add_Clint();
else if (x == "2")
BankingSystems.Add_Account();
else if (x == "3")
BankingSystems.Search_Clint();
else if (x == "4")
BankingSystems.Search_Account();
else if (x == "5")
BankingSystems.Despost_Money();
else if (x == "6")
BankingSystems.Withdraw_Money();
else if (x == "7")
BankingSystems.Display_Accounts();
else if (x == "8")
BankingSystems.Display_Clint();
else if (x == "9")
BankingSystems.Treansfer_money();
else if (x == "10")
BankingSystems.Close_Accounts();
else if (x == "11")
BankingSystems.Display_Account_Time();
else if (x == "12")
break;
else
{
Console.WriteLine("\n\n\n\n\n\n\n\n\n\n\n\n\n Error enter a number bettwen 1-12");
Console.WriteLine("\n Press any key to go to main menu");
Console.ReadKey();
}
}
}
}
}