Checker.pas 4.1 KB

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