This repository has been archived by the owner on Feb 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPanamahSDK.ValidationUtils.pas
74 lines (61 loc) · 1.93 KB
/
PanamahSDK.ValidationUtils.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
unit PanamahSDK.ValidationUtils;
interface
uses
SysUtils, Classes, Variants, PanamahSDK.Types;
function ModelValueIsEmpty(AValue: Variant): Boolean;
function ModelDateValueIsEmpty(AValue: Variant): Boolean;
function ModelListIsEmpty(AList: IPanamahStringValueList): Boolean; overload;
function ModelListIsEmpty(AList: IJSONSerializableList): Boolean; overload;
function ModelStringListEmptyIndex(AList: IPanamahStringValueList): Integer;
function ModelHasId(AModel: IPanamahModel): Boolean;
function IsValueBetween(AValue, AMin, AMax: Double): Boolean;
implementation
uses
uLkJSON, PanamahSDK.JsonUtils;
function ModelValueIsEmpty(AValue: Variant): Boolean;
begin
Result := VarIsNull(AValue) or
VarIsEmpty(AValue) or
SameText(VarToStrDef(AValue, EmptyStr), EmptyStr);
end;
function ModelDateValueIsEmpty(AValue: Variant): Boolean;
begin
Result := ModelValueIsEmpty(AValue) or (VarToDateTime(AValue) = 0);
end;
function ModelListIsEmpty(AList: IPanamahStringValueList): Boolean;
begin
Result := not Assigned(AList) or (AList.Count = 0);
end;
function ModelListIsEmpty(AList: IJSONSerializableList): Boolean; overload;
begin
Result := not Assigned(AList) or (AList.Count = 0);
end;
function ModelStringListEmptyIndex(AList: IPanamahStringValueList): Integer;
var
I: Integer;
begin
Result := -1;
if Assigned(AList) then
for I := 0 to AList.Count - 1 do
if ModelValueIsEmpty(AList[I]) then
begin
Result := I;
Exit;
end;
end;
function ModelHasId(AModel: IPanamahModel): Boolean;
var
DataJSONObject: TlkJSONobject;
begin
DataJSONObject := TlkJSON.ParseText(AModel.SerializeToJSON) as TlkJSONobject;
try
Result := not ModelValueIsEmpty(GetFieldValueAsString(DataJSONObject, 'id'));
finally
DataJSONObject.Free;
end;
end;
function IsValueBetween(AValue, AMin, AMax: Double): Boolean;
begin
Result := (AValue >= AMin) and (AValue <= AMax);
end;
end.