Checker.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. {*******************************************************************************
  2. 单元名称: Checker.pas
  3. 单元说明: 审核人类、管理类。
  4. 作者时间: Chenshilong, 2015-04-20
  5. *******************************************************************************}
  6. unit Checker;
  7. interface
  8. uses
  9. Classes, SysUtils;
  10. type
  11. TChecker = class(TObject) // 审核人类
  12. private
  13. FID: Integer;
  14. FRole: string;
  15. FMemo: string;
  16. FName: string;
  17. FNo: Integer;
  18. procedure SetID(const Value: Integer);
  19. procedure SetMemo(const Value: string);
  20. procedure SetName(const Value: string);
  21. procedure SetRole(const Value: string);
  22. procedure SetNo(const Value: Integer);
  23. public
  24. property No: Integer read FNo write SetNo; // 序号(审核人1、审核人2...)
  25. property ID: Integer read FID write SetID; // 审核人ID
  26. property Name: string read FName write SetName; // 审核人姓名
  27. property Role: string read FRole write SetRole; // 审核人职务
  28. property Memo: string read FMemo write SetMemo; // 审核人审核意见
  29. constructor Create;
  30. destructor Destroy; override;
  31. end;
  32. TCheckers = class(TObject) // 审核人管理类
  33. private
  34. FList: TList;
  35. function GetItem(Index: Integer): TChecker;
  36. function GetCount: Integer;
  37. public
  38. constructor Create;
  39. destructor Destroy; override;
  40. function Add(AChecker: TChecker): Integer; overload;
  41. function Add(AID: Integer; AName, ARole, AMemo: string): Integer; overload;
  42. procedure Delete(AIndex: Integer); overload;
  43. procedure Delete(AChecker: TChecker); overload;
  44. procedure Clear;
  45. procedure Exchange(AChecker1, AChecker2: TChecker);
  46. function FindByID(AID: Integer): TChecker;
  47. property Item[Index: Integer]: TChecker read GetItem; default;
  48. property Count: Integer read GetCount;
  49. end;
  50. implementation
  51. uses UtilMethods;
  52. { TCheckers }
  53. function TCheckers.Add(AID: Integer; AName, ARole, AMemo: string): Integer;
  54. var vCM: TChecker;
  55. begin
  56. vCM := TChecker.Create;
  57. Result := Add(vCM);
  58. vCM.No := Result;
  59. vCM.ID := AID;
  60. vCM.Name := AName;
  61. vCM.Role := ARole;
  62. vCM.Memo := RecoverCharsFromJson(AMemo);
  63. end;
  64. function TCheckers.Add(AChecker: TChecker): Integer;
  65. begin
  66. Result := FList.Add(AChecker);
  67. end;
  68. procedure TCheckers.Clear;
  69. var
  70. i: Integer;
  71. begin
  72. for i := 0 to FList.Count - 1 do
  73. TChecker(FList[i]).Free;
  74. FList.Clear;
  75. end;
  76. constructor TCheckers.Create;
  77. begin
  78. FList := TList.Create;
  79. end;
  80. procedure TCheckers.Delete(AIndex: Integer);
  81. begin
  82. TChecker(FList[AIndex]).Free;
  83. FList.Delete(AIndex);
  84. end;
  85. procedure TCheckers.Delete(AChecker: TChecker);
  86. begin
  87. FList.Remove(AChecker);
  88. end;
  89. destructor TCheckers.Destroy;
  90. begin
  91. Clear;
  92. FList.Free;
  93. inherited;
  94. end;
  95. procedure TCheckers.Exchange(AChecker1,
  96. AChecker2: TChecker);
  97. var
  98. idx1, idx2: Integer;
  99. begin
  100. idx1 := FList.IndexOf(AChecker1);
  101. idx2 := FList.IndexOf(AChecker2);
  102. if idx1 < 0 then Exit;
  103. if idx2 < 0 then Exit;
  104. FList.Exchange(idx1, idx2);
  105. end;
  106. function TCheckers.FindByID(AID: Integer): TChecker;
  107. var i: Integer;
  108. begin
  109. Result := nil;
  110. for i := 0 to FList.Count - 1 do
  111. begin
  112. if TChecker(FList[i]).ID = AID then
  113. begin
  114. Result := TChecker(FList[i]);
  115. Break;
  116. end;
  117. end;
  118. end;
  119. function TCheckers.GetCount: Integer;
  120. begin
  121. Result := FList.Count;
  122. end;
  123. function TCheckers.GetItem(Index: Integer): TChecker;
  124. begin
  125. Result := nil;
  126. if (Index > -1) and (Index < FList.Count) then
  127. Result := TChecker(FList[Index]);
  128. end;
  129. { TChecker }
  130. constructor TChecker.Create;
  131. begin
  132. end;
  133. destructor TChecker.Destroy;
  134. begin
  135. inherited;
  136. end;
  137. procedure TChecker.SetID(const Value: Integer);
  138. begin
  139. FID := Value;
  140. end;
  141. procedure TChecker.SetMemo(const Value: string);
  142. begin
  143. FMemo := StringReplace(Value, '\r\n', '|', [rfReplaceAll, rfIgnoreCase]);
  144. end;
  145. procedure TChecker.SetName(const Value: string);
  146. begin
  147. FName := Value;
  148. end;
  149. procedure TChecker.SetNo(const Value: Integer);
  150. begin
  151. FNo := Value;
  152. end;
  153. procedure TChecker.SetRole(const Value: string);
  154. begin
  155. FRole := Value;
  156. end;
  157. end.