unit uUserstatus;
interface
uses System.Classes, system.sysutils, System.Generics.Collections, REST.Json;
type
TUserStatus=(usStarted, usStopped, usInIdle, usInWork);
TUserEntry=class
private
FDuration: Cardinal;
FStatus: TUserStatus;
FTime: TDateTime;
FUsername:
string;
FGuid:
string;
FUserGuid:
string;
procedure SetDuration(
const Value: Cardinal);
procedure SetStatus(
const Value: TUserStatus);
procedure SetTime(
const Value: TDateTime);
procedure SetUsername(
const Value:
string);
procedure SetGuid(
const Value:
string);
procedure SetUserGuid(
const Value:
string);
public
procedure Assign(Source: TObject);
function ToJson:
string;
procedure FromJson(Str:
string);
published
property UserGuid:
string read FUserGuid
write SetUserGuid;
property Guid:
string read FGuid
write SetGuid;
property Username:
string read FUsername
write SetUsername;
property Time: TDateTime
read FTime
write SetTime;
property Status: TUserStatus
read FStatus
write SetStatus;
property Duration: Cardinal
read FDuration
write SetDuration;
end;
TUserList=class(TObjectList<TUserEntry>)
end;
implementation
{ TUserEntry }
procedure TUserEntry.Assign(Source: TObject);
begin
if Source
is TUserEntry
then
begin
self.FUserGuid:=TUserEntry(Source).UserGuid;
self.FGuid:=TUserEntry(Source).Guid;
self.FUsername:=TUserEntry(Source).Username;
self.FTime:=TUserEntry(Source).Time;
self.FStatus:=TUserEntry(Source).Status;
self.FDuration:=TUserEntry(Source).Duration;
end;
end;
procedure TUserEntry.FromJson(Str:
string);
var
UE: TUserEntry;
begin
UE:=TJson.JsonToObject<TUserEntry>(Str, [joIgnoreEmptyStrings, joIgnoreEmptyArrays]);
try
Self.Assign(UE);
finally
UE.Free;
end;
end;
procedure TUserEntry.SetDuration(
const Value: Cardinal);
begin
FDuration := Value;
end;
procedure TUserEntry.SetGuid(
const Value:
string);
begin
FGuid := Value;
end;
procedure TUserEntry.SetStatus(
const Value: TUserStatus);
begin
FStatus := Value;
end;
procedure TUserEntry.SetTime(
const Value: TDateTime);
begin
FTime := Value;
end;
procedure TUserEntry.SetUserGuid(
const Value:
string);
begin
FUserGuid := Value;
end;
procedure TUserEntry.SetUsername(
const Value:
string);
begin
FUsername := Value;
end;
function TUserEntry.ToJson:
string;
begin
Result:=TJson.ObjectToJsonString(Self, [joIgnoreEmptyStrings, joIgnoreEmptyArrays]);
end;
end.