123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- {*******************************************************************************
- 单元名称: Checker.pas
- 单元说明: 审核人类、管理类。
- 作者时间: Chenshilong, 2015-04-20
- *******************************************************************************}
- unit Checker;
- interface
- uses
- Classes, SysUtils;
- type
- TChecker = class(TObject) // 审核人类
- private
- FID: Integer;
- FRole: string;
- FMemo: string;
- FName: string;
- FNo: Integer;
- procedure SetID(const Value: Integer);
- procedure SetMemo(const Value: string);
- procedure SetName(const Value: string);
- procedure SetRole(const Value: string);
- procedure SetNo(const Value: Integer);
- public
- property No: Integer read FNo write SetNo; // 序号(审核人1、审核人2...)
- property ID: Integer read FID write SetID; // 审核人ID
- property Name: string read FName write SetName; // 审核人姓名
- property Role: string read FRole write SetRole; // 审核人职务
- property Memo: string read FMemo write SetMemo; // 审核人审核意见
- constructor Create;
- destructor Destroy; override;
- end;
- TCheckers = class(TObject) // 审核人管理类
- private
- FList: TList;
- function GetItem(Index: Integer): TChecker;
- function GetCount: Integer;
- public
- constructor Create;
- destructor Destroy; override;
- function Add(AChecker: TChecker): Integer; overload;
- function Add(AID: Integer; AName, ARole, AMemo: string): Integer; overload;
- procedure Delete(AIndex: Integer); overload;
- procedure Delete(AChecker: TChecker); overload;
- procedure Clear;
- procedure Exchange(AChecker1, AChecker2: TChecker);
- function FindByID(AID: Integer): TChecker;
- property Item[Index: Integer]: TChecker read GetItem; default;
- property Count: Integer read GetCount;
- end;
- implementation
- uses UtilMethods;
- { TCheckers }
- function TCheckers.Add(AID: Integer; AName, ARole, AMemo: string): Integer;
- var vCM: TChecker;
- begin
- vCM := TChecker.Create;
- Result := Add(vCM);
- vCM.No := Result;
- vCM.ID := AID;
- vCM.Name := AName;
- vCM.Role := ARole;
- vCM.Memo := RecoverCharsFromJson(AMemo);
- end;
- function TCheckers.Add(AChecker: TChecker): Integer;
- begin
- Result := FList.Add(AChecker);
- end;
- procedure TCheckers.Clear;
- var
- i: Integer;
- begin
- for i := 0 to FList.Count - 1 do
- TChecker(FList[i]).Free;
- FList.Clear;
- end;
- constructor TCheckers.Create;
- begin
- FList := TList.Create;
- end;
- procedure TCheckers.Delete(AIndex: Integer);
- begin
- TChecker(FList[AIndex]).Free;
- FList.Delete(AIndex);
- end;
- procedure TCheckers.Delete(AChecker: TChecker);
- begin
- FList.Remove(AChecker);
- end;
- destructor TCheckers.Destroy;
- begin
- Clear;
- FList.Free;
- inherited;
- end;
- procedure TCheckers.Exchange(AChecker1,
- AChecker2: TChecker);
- var
- idx1, idx2: Integer;
- begin
- idx1 := FList.IndexOf(AChecker1);
- idx2 := FList.IndexOf(AChecker2);
- if idx1 < 0 then Exit;
- if idx2 < 0 then Exit;
- FList.Exchange(idx1, idx2);
- end;
- function TCheckers.FindByID(AID: Integer): TChecker;
- var i: Integer;
- begin
- Result := nil;
- for i := 0 to FList.Count - 1 do
- begin
- if TChecker(FList[i]).ID = AID then
- begin
- Result := TChecker(FList[i]);
- Break;
- end;
- end;
- end;
- function TCheckers.GetCount: Integer;
- begin
- Result := FList.Count;
- end;
- function TCheckers.GetItem(Index: Integer): TChecker;
- begin
- Result := nil;
- if (Index > -1) and (Index < FList.Count) then
- Result := TChecker(FList[Index]);
- end;
- { TChecker }
- constructor TChecker.Create;
- begin
- end;
- destructor TChecker.Destroy;
- begin
- inherited;
- end;
- procedure TChecker.SetID(const Value: Integer);
- begin
- FID := Value;
- end;
- procedure TChecker.SetMemo(const Value: string);
- begin
- FMemo := StringReplace(Value, '\r\n', '|', [rfReplaceAll, rfIgnoreCase]);
- end;
- procedure TChecker.SetName(const Value: string);
- begin
- FName := Value;
- end;
- procedure TChecker.SetNo(const Value: Integer);
- begin
- FNo := Value;
- end;
- procedure TChecker.SetRole(const Value: string);
- begin
- FRole := Value;
- end;
- end.
|