AccountSubsystem.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace FacadePattern
  5. {
  6. /// <summary>
  7. /// 账户管理子系统
  8. /// </summary>
  9. public static class AccountSubsystem
  10. {
  11. private static readonly List<BankAccount> Accounts = new List<BankAccount>
  12. {
  13. new BankAccount("123455", "555555", "圣杰", "138****9309", 1000000),
  14. new BankAccount("123454", "444444", "产品汪", "157****9309", 2000000),
  15. new BankAccount("123453", "333333", "运营喵", "154****9309", 3000000),
  16. new BankAccount("123452", "222222", "程序猿", "187****9309", 4000000),
  17. new BankAccount("123451", "111111", "设计狮", "189****9309", 5000000)
  18. };
  19. public static BankAccount Login(string bankNo, string password)
  20. {
  21. var bankAccount = Accounts.FirstOrDefault(a => a.BankNo == bankNo);
  22. if (bankAccount == null)
  23. throw new Exception("无效卡号!!!");
  24. if (bankAccount.Password != password)
  25. throw new Exception("密码错误!!!");
  26. return bankAccount;
  27. }
  28. public static BankAccount GetAccount(string bankNo)
  29. {
  30. var bankAccount = Accounts.FirstOrDefault(a => a.BankNo == bankNo);
  31. if (bankAccount == null)
  32. throw new Exception("无效卡号!!!");
  33. return bankAccount;
  34. }
  35. public static void Display(BankAccount account)
  36. {
  37. Console.WriteLine("卡号:{0},持卡人姓名:{1},手机号:{2},余额:{3}", account.BankNo, account.Name, account.Phone,
  38. account.TotalMoney);
  39. }
  40. public static bool ChangePassword()
  41. {
  42. throw new NotImplementedException();
  43. }
  44. }
  45. }