SoftAuthorizeModel.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. using System;
  2. using System.ComponentModel;
  3. namespace SWRIS.Models
  4. {
  5. public class SoftAuthorizeModel : INotifyPropertyChanged
  6. {
  7. private string machineCode;
  8. private FinalData finalData = new FinalData();
  9. public string MachineCode
  10. {
  11. get { return machineCode; }
  12. set { machineCode = value; OnPropertyChanged("MachineCode"); }
  13. }
  14. public FinalData FinalData
  15. {
  16. get { return finalData; }
  17. set { finalData = value; OnPropertyChanged("FinalData"); }
  18. }
  19. public string FinalCode => FinalData?.ToString();
  20. public event PropertyChangedEventHandler PropertyChanged;
  21. protected internal virtual void OnPropertyChanged(string propertyName)
  22. {
  23. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  24. }
  25. }
  26. public class FinalData : INotifyPropertyChanged
  27. {
  28. private string first;
  29. private string second;
  30. private string third;
  31. private string fourth;
  32. public string First
  33. {
  34. get { return first; }
  35. set { first = value; OnPropertyChanged("First"); }
  36. }
  37. public string Second
  38. {
  39. get { return second; }
  40. set { second = value; OnPropertyChanged("Second"); }
  41. }
  42. public string Third
  43. {
  44. get { return third; }
  45. set { third = value; OnPropertyChanged("Third"); }
  46. }
  47. public string Fourth
  48. {
  49. get { return fourth; }
  50. set { fourth = value; OnPropertyChanged("Fourth"); }
  51. }
  52. public override string ToString()
  53. {
  54. return first + second + third + fourth;
  55. }
  56. public void Set(string finalCode)
  57. {
  58. if (finalCode is null)
  59. {
  60. throw new ArgumentNullException(nameof(finalCode));
  61. }
  62. finalCode = finalCode.Replace("-", "");
  63. First = finalCode.Length > 4 ? finalCode.Substring(0, 4) : finalCode;
  64. Second = finalCode.Length > 8 ? finalCode.Substring(4, 4) : finalCode.Substring(4);
  65. Third = finalCode.Length > 12 ? finalCode.Substring(8, 4) : finalCode.Substring(8);
  66. Fourth = finalCode.Length > 16 ? finalCode.Substring(12, 4) : finalCode.Substring(12);
  67. }
  68. public event PropertyChangedEventHandler PropertyChanged;
  69. protected internal virtual void OnPropertyChanged(string propertyName)
  70. {
  71. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  72. }
  73. }
  74. }