Skip to content

Commit

Permalink
Merge pull request #8 from jccsistemas/main
Browse files Browse the repository at this point in the history
Criado Campo TMemo (Bind4D.Component.Memo) e um tipo especial de form…
  • Loading branch information
bittencourtthulio authored Jun 17, 2021
2 parents 06a8bfb + 6a68d73 commit 1ad3c91
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/Bind4D.Attributes.pas
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ FieldDataSetBind = class(TCustomAttribute)
procedure SetFLimitWidth(const Value: Integer);
procedure SetFieldIndex(const Value: Integer);
public
constructor Create(aFieldName : String; aFdType : TFieldType; aVisible : Boolean = True; aWidth : Integer = 0; aDisplayName : String = ''; aEditMask : String = ''; aAlignment : TAlignment = taLeftJustify; aLimitWidth : Integer = 0; aFieldIndex : Integer = -1);
constructor Create(aFieldName : String; aFdType : TFieldType; aVisible : Boolean = True; aWidth : Integer = 0; aDisplayName : String = '';
aEditMask : String = ''; aAlignment : TAlignment = taLeftJustify; aLimitWidth : Integer = 0; aFieldIndex : Integer = -1);
property FieldName : String read FFieldName write SetFieldName;
property Width : Integer read FWidth write SetWidth;
property DisplayName : String read FDisplayName write SetDisplayName;
Expand Down
1 change: 1 addition & 0 deletions src/Bind4D.Component.DBGrid.pas
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function TBind4DComponentDBGrid.FormatFieldGrid(
aField.Visible := aAttr.Visible;
aField.DisplayWidth := Round((aAttr.Width * FComponent.Width ) / 1000);
aField.Alignment := aAttr.Alignment;

if aAttr.EditMask <> '' then
case aAttr.FDType of
ftString :
Expand Down
12 changes: 12 additions & 0 deletions src/Bind4D.Component.Edit.pas
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ function TBind4DComponentEdit.especialValidate: TBind4DComponentEdit;
(Sender as TEdit).SelStart := Length((Sender as TEdit).Text);
end)
end;
tePercent :
begin
TCommandMaster
.New
.Add(
FComponent,
procedure (Sender : TObject)
begin
(Sender as TEdit).Text := TBind4DUtils.FormataPercentual((Sender as TEdit).Text);
(Sender as TEdit).SelStart := Length((Sender as TEdit).Text);
end)
end;
teNull : ;
end;
end;
Expand Down
2 changes: 2 additions & 0 deletions src/Bind4D.Component.Factory.pas
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ implementation
Bind4D.Component.ComboBox,
Bind4D.Component.SpeedButton,
Bind4D.Component.Edit,
Bind4D.Component.Memo,
Bind4D.Helpers, Bind4D.Component.Helpers, Bind4D.Component.Mock;

{ TBind4DComponentFactory }
Expand All @@ -72,6 +73,7 @@ function TBind4DComponentFactory.Component(aValue: TComponent): iBind4DComponent
if aValue.TryGet<TSpeedButton> then Result := aValue.Get<TSpeedButton>.asIBind4DComponent;
if aValue.TryGet<TEdit> then Result := aValue.Get<TEdit>.asIBind4DComponent;
if aValue.TryGet<TImage> then Result := aValue.Get<TImage>.asIBind4DComponent;
if aValue.TryGet<TMemo> then Result := aValue.Get<TMemo>.asIBind4DComponent;
if not Assigned(Result) then Result := TBind4DComponentMock.New;

end;
Expand Down
16 changes: 15 additions & 1 deletion src/Bind4D.Component.Helpers.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TEditHelper = class helper for TEdit
function asIBind4DComponent : iBind4DComponent;
end;


TSpeedButtonHelper = class helper for TSpeedButton
public
function asIBind4DComponent : iBind4DComponent;
Expand Down Expand Up @@ -101,9 +102,15 @@ TMaskEditHelper = class helper for TMaskEdit

{$ENDIF}

TMemoHelper = class helper for TMemo
public
function asIBind4DComponent : iBind4DComponent;
end;

implementation

uses
Bind4D.Utils.Rtti,
Bind4D.Component.Edit,
Bind4D.Component.SpeedButton,
Bind4D.Component.ComboBox,
Expand All @@ -117,7 +124,7 @@ implementation
Bind4D.Component.ComboEdit,
Bind4D.Component.Rectangle,
Bind4D.Component.DateEdit,
Bind4D.Utils.Rtti,
Bind4D.Component.Memo,
Bind4D.Component.Image;

{ TEditHelper }
Expand Down Expand Up @@ -225,4 +232,11 @@ function TImageHelper.asIBind4DComponent: iBind4DComponent;
Result := TBind4DComponentImage.New(Self);
end;

{ TMemoHelper }

function TMemoHelper.asIBind4DComponent: iBind4DComponent;
begin
Result := TBind4DComponentMemo.New(Self);
end;

end.
143 changes: 143 additions & 0 deletions src/Bind4D.Component.Memo.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
unit Bind4D.Component.Memo;

interface

uses
{$IFDEF HAS_FMX}
FMX.StdCtrls,
{$ELSE}
Vcl.ExtCtrls,
Vcl.StdCtrls,
{$ENDIF}
Bind4D.Component.Interfaces, Bind4D.Attributes;

type
TBind4DComponentMemo = class(TInterfacedObject, iBind4DComponent)
private
FComponent : TMemo;
FAttributes : iBind4DComponentAttributes;
public
constructor Create(aValue : TMemo);
destructor Destroy; override;
class function New(aValue : TMemo) : iBind4DComponent;
function Attributes : iBind4DComponentAttributes;
function AdjusteResponsivity : iBind4DComponent;
function FormatFieldGrid (aAttr : FieldDataSetBind) : iBind4DComponent;
function ApplyStyles : iBind4DComponent;
function ApplyText : iBind4DComponent;
function ApplyImage : iBind4DComponent;
function ApplyValue : iBind4DComponent;
function ApplyRestData : iBind4DComponent;
function GetValueString : String;
function GetCaption : String;
function Clear : iBind4DComponent;
end;

implementation

uses
Bind4D.Component.Attributes;

{ TBind4DComponentMemo }

function TBind4DComponentMemo.FormatFieldGrid(
aAttr: FieldDataSetBind): iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentMemo.AdjusteResponsivity: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentMemo.ApplyImage: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentMemo.ApplyRestData: iBind4DComponent;
begin
Result := Self;
end;

function TBind4DComponentMemo.ApplyStyles: iBind4DComponent;
begin
Result := Self;
{$IFDEF HAS_FMX}
FComponent.StyledSettings := FAttributes.StyleSettings;
FComponent.TextSettings.FontColor := FAttributes.FontColor;
FComponent.TextSettings.Font.Family := FAttributes.FontName;
FComponent.TextSettings.Font.Size := FAttributes.FontSize;
{$ELSE}
FComponent.StyleElements := FAttributes.StyleSettings;
FComponent.Color := FAttributes.Color;
FComponent.Font.Color := FAttributes.FontColor;
FComponent.Font.Name := FAttributes.FontName;
FComponent.Font.Size := FAttributes.FontSize;
{$ENDIF}
end;

function TBind4DComponentMemo.ApplyText: iBind4DComponent;
begin
Result := Self;
{$IFDEF HAS_FMX}
FComponent.Text := FAttributes.Text;
{$ELSE}
FComponent.Lines.Text := FAttributes.Text;
{$ENDIF}
end;

function TBind4DComponentMemo.ApplyValue: iBind4DComponent;
begin
Result := Self;
FComponent.Lines.Text := FAttributes.ValueVariant;
end;

function TBind4DComponentMemo.Attributes: iBind4DComponentAttributes;
begin
Result := FAttributes;
end;

function TBind4DComponentMemo.Clear: iBind4DComponent;
begin
Result := Self;
FComponent.Lines.Text := '';
end;

constructor TBind4DComponentMemo.Create(aValue : TMemo);
begin
FAttributes := TBind4DComponentAttributes.Create(Self);
FComponent := aValue;
end;

destructor TBind4DComponentMemo.Destroy;
begin

inherited;
end;

function TBind4DComponentMemo.GetCaption: String;
begin
{$IFDEF HAS_FMX}
Result := FComponent.Text;
{$ELSE}
Result := FComponent.Lines.Text;
{$ENDIF}
end;

function TBind4DComponentMemo.GetValueString: String;
begin
{$IFDEF HAS_FMX}
Result := FComponent.Text;
{$ELSE}
Result := FComponent.Lines.Text;
{$ENDIF}
end;

class function TBind4DComponentMemo.New(aValue : TMemo) : iBind4DComponent;
begin
Result := Self.Create(aValue);
end;

end.
2 changes: 1 addition & 1 deletion src/Bind4D.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
interface

type
TEspecialType = (teNull, teCoin, teCell, teDate, teDateTime, teCPF, teCNPJ, teCEP, tePhone);
TEspecialType = (teNull, teCoin, teCell, teDate, teDateTime, teCPF, teCNPJ, teCEP, tePhone, tePercent);
TTypeBindFormJson = (fbGet, fbPost, fbPut, fbDelete);
TTypeBindZipCode = (zcNull, zcCEP, zcLogradouro, zcComplemento, zcBairro, zcCidade, zcEstado, zcIBGE, zcDDD);

Expand Down
2 changes: 2 additions & 0 deletions src/Bind4D.Utils.Rtti.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@ function TBind4DUtilsRtti.ClearCache: TBind4DUtilsRtti;
FComponentList.Clear;
FprpRttiList.Clear;
end;

constructor TBind4DUtilsRtti.Create;
begin
FComponentList := TDictionary<TCustomAttribute, TComponent>.Create;
FprpRttiList := TDictionary<TComponent, TRttiField>.Create;
end;

destructor TBind4DUtilsRtti.Destroy;
begin
FprpRttiList.Free;
Expand Down
30 changes: 30 additions & 0 deletions src/Bind4D.Utils.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TBind4DUtils = class
class function FormatDateTimeDataSet(aValue : String) : String;
class function FormatTimeDataSet(aValue : String) : String;
class function FormatarMoeda(valor: string): string;
class function FormataPercentual(valor: string): string;
class function FormatarCelular(valor : string) : string;
class function ApenasNumeros(valor : String) : String;
class function SendImageS3Storage( var aImage : TImage; aAttr : S3Storage) : String;
Expand Down Expand Up @@ -62,11 +63,16 @@ class function TBind4DUtils.ApenasNumeros(valor: String): String;
var
i: Integer;
begin

for i := 0 to Length(valor) - 1 do
if not CharInSet(valor[i], ['0' .. '9']) then
delete(valor, i, 1);

valor := StringReplace(valor, ' ', '', [rfReplaceAll]);
valor := StringReplace(valor, '%', '', [rfReplaceAll]);

Result := valor;

end;
class function TBind4DUtils.ExtrairMoeda(aValue: String): String;
begin
Expand Down Expand Up @@ -237,6 +243,7 @@ class function TBind4DUtils.FormatarMoeda(valor: string): string;
else
Result := LeftStr(valor, Length(valor) - 2) + ',' + decimais;
end;

end;
class function TBind4DUtils.FormatarPhone(valor: string): string;
var
Expand Down Expand Up @@ -369,6 +376,29 @@ class function TBind4DUtils.FormatDateTimeToJson(aValue: TDateTime): String;
segundo := Copy(Result, 13, 2);
Result := ano + '-' + mes + '-' + dia + ' ' + hora + ':' + minuto + ':' + segundo +'.000';
end;
class function TBind4DUtils.FormataPercentual(valor: string): string;
var
aux: string;
i: Integer;
ValorInteiro : Integer;
ValorFloat : Double;
begin
Result := EmptyStr;
aux := ApenasNumeros(Valor);
ValorFloat := 0.0;
ValorInteiro := 0;

if aux <> '' then
begin
aux := RightStr(aux,4);

ValorInteiro := StrToInt(aux);
ValorFloat := ValorInteiro / 100;
end;

result := Format('%3.2f', [ValorFloat]);
end;

class function TBind4DUtils.FormatStrJsonToDateTime(aValue: String): TDateTime;
var
i: Integer;
Expand Down
2 changes: 1 addition & 1 deletion src/Bind4D.inc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{$DEFINE HAS_FMX}
//{$DEFINE HAS_FMX}
5 changes: 5 additions & 0 deletions src/Bind4D.pas
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ function TBind4D.BindDataSetToForm(aDataSet : TDataSet) : iBind4D;
aTeste: string;
begin
Result := Self;

ClearFieldForm;

for Attribute in RttiUtils.Get<FieldDataSetBind>(FForm) do
begin
aTeste := Attribute.FieldName;
Expand Down Expand Up @@ -268,8 +271,10 @@ function TBind4D.ClearFieldForm: iBind4D;
var
aComp : TComponent;
begin

for aComp in RttiUtils.GetComponents(FForm) do
TBind4DComponentFactory.New.Component(aComp).Clear;

end;
constructor TBind4D.Create;
begin
Expand Down

0 comments on commit 1ad3c91

Please sign in to comment.