Advertisement
Guest User

program

a guest
Jun 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using Newtonsoft.Json;
  4.  
  5. namespace ispit
  6. {
  7.     class Program
  8.     {
  9.         static List<Customers> AllCustomers = new List<Customers>();
  10.         static void Main(string[] args)
  11.         {
  12.             // data receiver
  13.             if (System.IO.File.ReadAllText("./user.json").Length != 0)
  14.             {
  15.                 var i = System.IO.File.ReadAllText("./user.json");
  16.              AllCustomers = JsonConvert.DeserializeObject<List<Customers>>(i);
  17.            
  18.             foreach (var customer in AllCustomers)
  19.             {
  20.              var k = System.IO.File.ReadAllText("./user.json");
  21.              AllCustomers = JsonConvert.DeserializeObject<List<Customers>>(k);
  22.             }
  23.             }
  24.            
  25.  
  26.             // program
  27.             while (true)
  28.             {
  29.                 Console.WriteLine("Welcome to our bank \n 1. New Account \n 2. Operations \n 3. Exit \n*");
  30.                 int selection = Convert.ToInt32(Console.ReadLine());
  31.                 switch (selection)
  32.                 {
  33.                 case 1:
  34.                 NewAccount();
  35.                 break;
  36.  
  37.                 case 2:
  38.                 SelectOperation2(SelectOperation1());
  39.                 break;
  40.  
  41.                 case 3:
  42.                 Console.WriteLine("Operations done, goodbye!");
  43.                 break;
  44.                 default:
  45.                 Console.WriteLine("Invalid input!");
  46.                 break;
  47.                 }
  48.                 if(selection==3)
  49.                 {
  50.                     break;
  51.                 }
  52.                 Console.WriteLine("*");                
  53.             }
  54.  
  55.             // data saver
  56.             foreach (var customer in AllCustomers)
  57.             {
  58.                 var j = JsonConvert.SerializeObject(AllCustomers);
  59.                 System.IO.File.WriteAllText("./user.json", j);
  60.             }
  61.            
  62.         }
  63.  
  64.         public static Customers NewAccount()
  65.         {
  66.             Customers ACustomer = new Customers();
  67.             Console.WriteLine("Enter your name: ");
  68.             ACustomer.Name = Console.ReadLine();
  69.             Console.WriteLine("Enter your address: ");
  70.             ACustomer.Address = Console.ReadLine();
  71.             Console.WriteLine("Enter your phone number: ");
  72.             ACustomer.Phone = Convert.ToInt32(Console.ReadLine());
  73.             Console.WriteLine("The initial ammount: ");
  74.             ACustomer.InitialAmmount = Convert.ToDouble(Console.ReadLine());
  75.             Console.WriteLine("Enter your password: ");
  76.             ACustomer.Password = Convert.ToInt32(Console.ReadLine());
  77.             Console.WriteLine("Re-enter your password: ");
  78.             while (true)
  79.             {
  80.                 int PwCheck = Convert.ToInt32(Console.ReadLine());
  81.                 if (PwCheck == ACustomer.Password)
  82.                 {
  83.                     Console.WriteLine("Password saved!");
  84.                     break;
  85.                 }
  86.                 else
  87.                 {
  88.                     Console.WriteLine("Passwords do not match, retype your password");
  89.                 }                
  90.             }
  91.  
  92.             ACustomer.AccountNumber = AllCustomers.Count;
  93.             AllCustomers.Add(ACustomer);
  94.             Console.WriteLine("Your account has successfully been created as: ");
  95.             Console.WriteLine("Name: {0}\n Adress: {1}\n Phone number: {2}\n Initial ammount: {3}\n Account number: {4}\n Do not forget your account number and password",
  96.                  AllCustomers[ACustomer.AccountNumber].Name,
  97.                  AllCustomers[ACustomer.AccountNumber].Address,
  98.                  AllCustomers[ACustomer.AccountNumber].Phone,
  99.                  AllCustomers[ACustomer.AccountNumber].InitialAmmount,
  100.                  AllCustomers[ACustomer.AccountNumber].AccountNumber);  
  101.             return ACustomer;
  102.         }
  103.  
  104.         public static int SelectOperation1()
  105.         {
  106.             Console.WriteLine("Enter your account number: ");
  107.             int AccNmbr = Convert.ToInt32(Console.ReadLine());
  108.             if (AccNmbr == AllCustomers[AccNmbr].AccountNumber)
  109.             {
  110.                 Console.WriteLine("Enter your password: ");
  111.                 for (int i = 0; i < 3; i++)
  112.                 {
  113.                     if (i == 3)
  114.                     {
  115.                         Console.WriteLine("Your account has been blocked since your password is wrong. Call your bank! ");
  116.                         break;
  117.                     }
  118.             int AccPw = Convert.ToInt32(Console.ReadLine());
  119.             if (AccPw == AllCustomers[AccNmbr].Password)
  120.                 {
  121.                     Console.WriteLine("Entering: ");
  122.                     break;
  123.                 }
  124.                 Console.WriteLine("Re-enter your password: ");
  125.                 }            
  126.             }
  127.  
  128.             return AllCustomers[AccNmbr].AccountNumber;
  129.            
  130.         }
  131.         public static int SelectOperation2 (int AccNmbr)
  132.         {
  133.            
  134.             while(true)
  135.             {
  136.                 Console.WriteLine("Choose an operation from the menu \n 1. Change Password \n 2. Deposite \n 3. Withdraw \n 4. Print \n 5. Exit");
  137.                 int input = Convert.ToInt32(Console.ReadLine());
  138.             switch (input)
  139.             {
  140.                 case 1:
  141.                 Operations.ChangePassword();
  142.                 break;
  143.  
  144.                 case 2:    
  145.                 double addition = Operations.Deposite(AllCustomers[AccNmbr].InitialAmmount);
  146.                 AllCustomers[AccNmbr].InitialAmmount = AllCustomers[AccNmbr].InitialAmmount + addition;
  147.                 break;
  148.  
  149.                 case 3:
  150.                 double substract = Operations.Withdraw(AllCustomers[AccNmbr].InitialAmmount);
  151.                 AllCustomers[AccNmbr].InitialAmmount = AllCustomers[AccNmbr].InitialAmmount - substract;                
  152.                 break;
  153.  
  154.                 case 4:
  155.                 Operations.Print(AllCustomers[AccNmbr]);
  156.                 break;
  157.                 case 5:
  158.                 Console.WriteLine("Good Bye!");
  159.                 return 0;
  160.                 default:
  161.                 Console.WriteLine("Invalid input!");
  162.                 break;              
  163.             }
  164.                 Console.WriteLine("*");
  165.             }
  166.         }
  167.        
  168.     }
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement