diff --git a/src/Bind4D.Attributes.pas b/src/Bind4D.Attributes.pas index 778c8f6..69e2146 100644 --- a/src/Bind4D.Attributes.pas +++ b/src/Bind4D.Attributes.pas @@ -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; diff --git a/src/Bind4D.Component.DBGrid.pas b/src/Bind4D.Component.DBGrid.pas index cca9a86..1399172 100644 --- a/src/Bind4D.Component.DBGrid.pas +++ b/src/Bind4D.Component.DBGrid.pas @@ -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 : diff --git a/src/Bind4D.Component.Edit.pas b/src/Bind4D.Component.Edit.pas index 23177f8..0e6824e 100644 --- a/src/Bind4D.Component.Edit.pas +++ b/src/Bind4D.Component.Edit.pas @@ -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; diff --git a/src/Bind4D.Component.Factory.pas b/src/Bind4D.Component.Factory.pas index e654050..24a9cc9 100644 --- a/src/Bind4D.Component.Factory.pas +++ b/src/Bind4D.Component.Factory.pas @@ -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 } @@ -72,6 +73,7 @@ function TBind4DComponentFactory.Component(aValue: TComponent): iBind4DComponent if aValue.TryGet then Result := aValue.Get.asIBind4DComponent; if aValue.TryGet then Result := aValue.Get.asIBind4DComponent; if aValue.TryGet then Result := aValue.Get.asIBind4DComponent; + if aValue.TryGet then Result := aValue.Get.asIBind4DComponent; if not Assigned(Result) then Result := TBind4DComponentMock.New; end; diff --git a/src/Bind4D.Component.Helpers.pas b/src/Bind4D.Component.Helpers.pas index 7d3fa91..f4ef783 100644 --- a/src/Bind4D.Component.Helpers.pas +++ b/src/Bind4D.Component.Helpers.pas @@ -35,6 +35,7 @@ TEditHelper = class helper for TEdit function asIBind4DComponent : iBind4DComponent; end; + TSpeedButtonHelper = class helper for TSpeedButton public function asIBind4DComponent : iBind4DComponent; @@ -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, @@ -117,7 +124,7 @@ implementation Bind4D.Component.ComboEdit, Bind4D.Component.Rectangle, Bind4D.Component.DateEdit, - Bind4D.Utils.Rtti, + Bind4D.Component.Memo, Bind4D.Component.Image; { TEditHelper } @@ -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. diff --git a/src/Bind4D.Component.Memo.pas b/src/Bind4D.Component.Memo.pas new file mode 100644 index 0000000..19f263b --- /dev/null +++ b/src/Bind4D.Component.Memo.pas @@ -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. \ No newline at end of file diff --git a/src/Bind4D.Types.pas b/src/Bind4D.Types.pas index aba798e..60de6df 100644 --- a/src/Bind4D.Types.pas +++ b/src/Bind4D.Types.pas @@ -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); diff --git a/src/Bind4D.Utils.Rtti.pas b/src/Bind4D.Utils.Rtti.pas index d54dd0d..26c023c 100644 --- a/src/Bind4D.Utils.Rtti.pas +++ b/src/Bind4D.Utils.Rtti.pas @@ -36,11 +36,13 @@ function TBind4DUtilsRtti.ClearCache: TBind4DUtilsRtti; FComponentList.Clear; FprpRttiList.Clear; end; + constructor TBind4DUtilsRtti.Create; begin FComponentList := TDictionary.Create; FprpRttiList := TDictionary.Create; end; + destructor TBind4DUtilsRtti.Destroy; begin FprpRttiList.Free; diff --git a/src/Bind4D.Utils.pas b/src/Bind4D.Utils.pas index 51247dc..478c287 100644 --- a/src/Bind4D.Utils.pas +++ b/src/Bind4D.Utils.pas @@ -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; @@ -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 @@ -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 @@ -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; diff --git a/src/Bind4D.inc b/src/Bind4D.inc index 90c4bdb..cd2a2d7 100644 --- a/src/Bind4D.inc +++ b/src/Bind4D.inc @@ -1 +1 @@ -{$DEFINE HAS_FMX} \ No newline at end of file +//{$DEFINE HAS_FMX} \ No newline at end of file diff --git a/src/Bind4D.pas b/src/Bind4D.pas index 76c6349..2a4ecbf 100644 --- a/src/Bind4D.pas +++ b/src/Bind4D.pas @@ -128,6 +128,9 @@ function TBind4D.BindDataSetToForm(aDataSet : TDataSet) : iBind4D; aTeste: string; begin Result := Self; + + ClearFieldForm; + for Attribute in RttiUtils.Get(FForm) do begin aTeste := Attribute.FieldName; @@ -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