/
YakuninAV
/
Convertors
Обзор
Документация
Войти
/
YakuninAV
/
Convertors
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Estimate/EstObjects.pas
382 строки
12 KB
YakuninAV
begin with gitflick
31 июл 2026, 15:21
31 июл 2026, 15:21
1dc0fc6
Код
Авторство
О чём код?
/// Модуль, содержащий объявления класса TEstObject unit EstObjects; {$I mormot.defines.inc} {$DEFINE USEWEAKREFS} interface uses {$IFDEF DELPHIXE2} SysUtils, Classes, Types, DateUtils, {$ELSE} SysUtils, Classes, Types, DateUtils, {$ENDIF} mormot.core.base, mormot.core.variants, mormot.core.os, mormot.core.unicode, mormot.core.text, mormot.core.json, mormot.core.rtti, mormot.core.interfaces, mormot.core.data, {$IFDEF USEWEAKREFS} WeakRefs, {$ENDIF} EstTypes, EstIntfsV2, EstIntfsV3, EstimatesV2, EstRequisites; type /// Класс реализующий интерфейс для работы с информацией об объектах строительства {$IFDEF USEWEAKREFS} TEstObject = class(TWeaklyInterfacedObject, IEstObjectV2) {$ELSE} TEstObject = class(TInterfacedObject, IEstObjectV2) {$ENDIF} protected class var FrName, FrNum, FrAddr, FrQty, FrQtyName, FrRegion, FrPrice, FrEstimate, FrRequisite: RawUTF8; private var FName, FNum, FAddress, FQtyUnit: RawUTF8; FQty: Double; FEstimates: TEstEstimates; FRequisites: IEstRequisitesListV2; {$IFDEF USEWEAKREFS} FOwner: IWeakRef; {$ELSE} [weak] FOwner: IEstConstructionV2; {$ENDIF} FOwnerPtr: Pointer; FPriceE: Currency; FRegion: TEstimateRegion; FReason, FReasonLink: RawUtf8; function GetAddress: string; function GetName: string; function GetNum: string; function GetEstimate(Index: Integer): IEstEstimateV2; function GetOwner: IEstConstructionV2; function GetOwnerPtr: Pointer; function GetQty: Double; function GetQtyUnit: string; function GetPriceE: Currency; function GetRegion: TEstimateRegion; function GetReason: string; function GetReasonLink: string; function GetRequisites: IEstRequisitesListV2; procedure SetAddress(const Value: string); procedure SetName(const Value: string); procedure SetNum(const Value: string); procedure SetOwner(const Value: IEstConstructionV2); procedure SetOwnerPtr(const Value: Pointer); procedure SetQty(const Value: Double); procedure SetQtyUnit(const Value: string); procedure SetPriceE(const Value: Currency); procedure SetReason(const Value: string); procedure SetReasonLink(const Value: string); procedure SetRegion(const Value: TEstimateRegion); function GetEstimates: TEstEstimates; public class property rName: RawUTF8 read FrName write FrName; class property rNum: RawUTF8 read FrNum write FrNum; class property rAddr: RawUTF8 read FrAddr write FrAddr; class property rQty: RawUTF8 read FrQty write FrQty; class property rQtyName: RawUTF8 read FrQtyName write FrQtyname; class property rPrice: RawUTF8 read FrPrice write FrPrice; class property rRegion: RawUTF8 read FrRegion write FrRegion; class property rEstimate: RawUTF8 read FrEstimate write FrEstimate; class property rRequisite: RawUTF8 read FrRequisite write FrRequisite; public /// Указатель на интерфейс для работы с информацией о строительстве, в которое входит объект property Owner: IEstConstructionV2 read GetOwner write SetOwner; property OwnerPtr: Pointer read GetOwnerPtr write SetOwnerPtr; /// Номер объекта property Num: string read GetNum write SetNum; /// Наименование объекта property Name: string read GetName write SetName; /// Адрес объекта property Address: string read GetAddress write SetAddress; /// Регион, в котором находится объект строительства property Region: TEstimateRegion read GetRegion write SetRegion; /// Основание ОСР(ОС) - проектная или иная техническая документация property Reason: string read GetReason write SetReason; /// Ссылка на файл с проектной или иной технической документацией property ReasonLink: string read GetReasonLink write SetReasonLink; /// Объём строительства property Qty: Double read GetQty write SetQty; /// Размерность единицы объёма property QtyUnit: string read GetQtyUnit write SetQtyUnit; /// Показатель единичной стоимости на расчетный измеритель объекта капитального строительства (реконструкции, капитального ремонта) property PriceE: Currency read GetPriceE write SetPriceE; /// Сметы, созданные для объекта property Estimate[Index: Integer]: IEstEstimateV2 read GetEstimate; /// Массив смет для строительного объекта property Estimates: TEstEstimates read GetEstimates; /// Список реквизитов объекта строительства property Requisites: IEstRequisitesListV2 read GetRequisites; /// Конструтор создаёт экземпляр класса constructor Create(const aName: string=''; const aNum: string=''); /// Деструктор освобождает занятую экземпляром класса память destructor Destroy; override; /// Добавить смету в список смет объекта function AddEstimate(aEstimate: IEstEstimateV2): Integer; /// Функция возвращает количестве смет, составленных для объекта строительства function EstimatesCount: Integer; /// Функция возвращает индекс сметы, из списка смет объекта строительства, с заданым номером function IndexOfNum(const aNum: string): Integer; /// Функция возвращает индекс объекта, из списка смет объекта строительства, с заданым наименованием function IndexOfName(const aName: string): Integer; /// Функция загружает информацию из JSON-документа function FromDoc(const PDoc: PDocVariantData): Boolean; /// Функция возвращает JSON-документ function ToDoc: Variant; end; implementation { TEstObject } function TEstObject.AddEstimate(aEstimate: IEstEstimateV2): Integer; begin if aEstimate<>nil then begin Result:=Length(FEstimates); aEstimate.Owner:=Self; SetLength(FEstimates,Result+1); FEstimates[Result]:=aEstimate; end else Result:=-1; end; constructor TEstObject.Create(const aName, aNum: string); begin inherited Create; SetName(aName); SetNum(aNum); SetQty(0); SetQtyUnit(''); FRequisites:=TEstRequisitesList.Create([]); FRegion:= TEstimateRegion.Create(77); end; destructor TEstObject.Destroy; var i: Integer; begin FRequisites.Clear; FRequisites:=nil; FOwner:=nil; for i := Low(FEstimates) to High(FEstimates) do begin FEstimates[i].Owner:=nil; FEstimates[i]:=nil; end; SetLength(FEstimates,0); inherited; end; function TEstObject.EstimatesCount: Integer; begin Result:=Length(FEstimates); end; function TEstObject.GetAddress: string; begin Result:=Utf8ToString(FAddress); end; function TEstObject.GetEstimate(Index: Integer): IEstEstimateV2; begin if (Low(FEstimates)<=Index) and (High(FEstimates)>=Index) then Result:=FEstimates[Index] else Result:=nil; end; function TEstObject.GetEstimates: TEstEstimates; begin Result:=FEstimates; end; function TEstObject.GetName: string; begin Result:=Utf8ToString(FName); end; function TEstObject.GetNum: string; begin Result:=Utf8ToString(FNum); end; function TEstObject.GetOwner: IEstConstructionV2; begin {$IFDEF USEWEAKREFS} result := nil; if IsAlive(FOwner) then if not Supports(FOwner.Get, IEstConstructionV2, result) then ; {$ELSE} Result:=FOwner; {$ENDIF} end; function TEstObject.GetOwnerPtr: Pointer; begin Result:=FOwnerPtr; end; function TEstObject.GetPriceE: Currency; begin Result:=FPriceE; end; function TEstObject.GetQty: Double; begin Result:=FQty; end; function TEstObject.GetQtyUnit: string; begin Result:=Utf8ToString(FQtyUnit); end; function TEstObject.GetReason: string; begin Result:=Utf8ToString(FReason); end; function TEstObject.GetReasonLink: string; begin Result:=Utf8ToString(FReasonLink); end; function TEstObject.GetRegion: TEstimateRegion; begin Result:=FRegion; end; function TEstObject.GetRequisites: IEstRequisitesListV2; begin Result:=FRequisites; end; function TEstObject.IndexOfName(const aName: string): Integer; var i: Integer; begin Result:=-1; for i := Low(FEstimates) to High(FEstimates) do if FEstimates[i].Name=aName then begin Result:=i; Break; end; end; function TEstObject.IndexOfNum(const aNum: string): Integer; var i: Integer; begin Result:=-1; for i := Low(FEstimates) to High(FEstimates) do if FEstimates[i].Num=aNum then begin Result:=i; Break; end; end; procedure TEstObject.SetAddress(const Value: string); begin FAddress:=StringToUtf8(Value); end; procedure TEstObject.SetName(const Value: string); begin FName:=StringToUtf8(Value); end; procedure TEstObject.SetNum(const Value: string); begin FNum:=StringToUtf8(Value); end; procedure TEstObject.SetOwner(const Value: IEstConstructionV2); var i: IWeakly; begin {$IFDEF USEWEAKREFS} i := nil; if Supports(Value, IWeakly, i) then FOwner := i.WeakRef; {$ELSE} FOwner:=Value; {$ENDIF} end; procedure TEstObject.SetOwnerPtr(const Value: Pointer); begin FOwnerPtr:=Value; end; procedure TEstObject.SetPriceE(const Value: Currency); begin FPriceE:=Value; end; procedure TEstObject.SetQty(const Value: Double); begin FQty:=Value; end; procedure TEstObject.SetQtyUnit(const Value: string); begin FQtyUnit:=StringToUtf8(Value); end; procedure TEstObject.SetReason(const Value: string); begin FReason:=StringToUtf8(Value); end; procedure TEstObject.SetReasonLink(const Value: string); begin FReasonLink:=StringToUtf8(Value); end; procedure TEstObject.SetRegion(const Value: TEstimateRegion); begin FRegion:=Value; end; function TEstObject.FromDoc(const PDoc: PDocVariantData): Boolean; var est: IEstEstimateV2; iCur: Int64; cCur: Currency absolute iCur; pEst: PDocVariantData; i: Integer; begin Result:=False; if (pDoc<>nil) and (pDoc^.Kind=dvObject) and (pDoc^.Count>8) then begin Result := pDoc^.GetAsRawUtf8(frName, FName) and pDoc^.GetAsRawUtf8(frNum, FNum) and pDoc^.GetAsRawUtf8(frAddr, FAddress) and pDoc^.GetAsRawUtf8(frQtyName, FQtyUnit) and pDoc^.GetAsInt64(frPrice, iCur) and pDoc^.GetAsDouble(frQty, FQty) and pDoc^.GetAsDocVariant(FrEstimate,pEst) and (pEst^.Kind=dvArray) and (pEst^.Count>0); if Result then begin FPriceE:=cCur; for i := 0 to pEst^.Count-1 do begin est:=TEstEstimate.Create('',''); Result:=est.FromDoc(pEst^._[i]); if Result then AddEstimate(est) else Break; end; end; end; end; function TEstObject.ToDoc: Variant; var e: IEstEstimateV2; a,v: Variant; iCur: Int64; cCur: Currency absolute iCur; begin v:=FRegion.ToDoc; cCur:=FPriceE; Result:=_Obj([FrName,FName, FrNum,FNum, FrAddr,FAddress, FrRegion,v, FrPrice,iCur, FrQty,FQty, FrQtyName,FQtyUnit]); TDocVariantData(v).Clear; if EstimatesCount>0 then begin TDocVariant.New(a); for e in FEstimates do begin v:=e.ToDoc; TDocVariantData(a).AddItem(v); TDocVariantData(v).Clear; end; TDocVariantData(Result).AddValue(FrEstimate,a); TDocVariantData(a).Clear; end; v:=FRequisites.ToDoc; if Assigned(FRequisites) then TDocVariantData(Result).AddValue(FrRequisite,v); TDocVariantData(v).Clear; end; initialization TEstObject.rName:=StringToUTF8('Name'); TEstObject.rNum:=StringToUTF8('Num'); TEstObject.rAddr:=StringToUTF8('Addr'); TEstObject.rQty:=StringToUTF8('Qty'); TEstObject.rQtyName:=StringToUTF8('QtyName'); TEstObject.rRegion:=StringToUTF8('Region'); TEstObject.rPrice:=StringToUTF8('Price'); TEstObject.rEstimate:=StringToUTF8('Estimates'); TEstObject.rRequisite:=StringToUTF8('OptRequisites'); end.