From 40807160928ea01b200f9afb7970bf16eda22bda Mon Sep 17 00:00:00 2001 From: jujibo Date: Mon, 3 Oct 2011 08:23:50 +0000 Subject: [PATCH] Fix: Date/Time, restore old value. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2059 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/jujiboutils/src/jdbgridutils.pas | 85 +++++++++++---------- 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/components/jujiboutils/src/jdbgridutils.pas b/components/jujiboutils/src/jdbgridutils.pas index a36e97622..6421ff5df 100644 --- a/components/jujiboutils/src/jdbgridutils.pas +++ b/components/jujiboutils/src/jdbgridutils.pas @@ -286,7 +286,6 @@ end; procedure TJDbGridDateTimeCtrl.myEditOnEditingDone(Sender: TObject); begin - CellEditor.Caption := NormalizeDateTime(CellEditor.Caption, theValue); if Length(CellEditor.Caption) = 0 then begin if edited then @@ -300,21 +299,25 @@ begin end; end else - if IsValidDateTimeString(CellEditor.Caption) then begin - if edited and (not updated) then + CellEditor.Caption := NormalizeDateTime(CellEditor.Caption, theValue); + if IsValidDateTimeString(CellEditor.Caption) then begin - Field.DataSet.DisableControls; - theValue := StrToDateTime(CellEditor.Caption); - Field.DataSet.Edit; - Field.AsDateTime := theValue; - Field.DataSet.EnableControls; + if edited and (not updated) then + begin + Field.DataSet.DisableControls; + theValue := StrToDateTime(CellEditor.Caption); + Field.DataSet.Edit; + Field.AsDateTime := theValue; + Field.DataSet.EnableControls; + end; + end + else + begin + ShowMessage(Format(SInvalidDateTime, [CellEditor.Caption])); + CellEditor.Text := FormatDateTime(DisplayFormat, Field.AsDateTime); end; - end - else - begin - ShowMessage(Format(SInvalidDateTime, [CellEditor.Caption])); - CellEditor.Text := FormatDateTime(DisplayFormat, theValue); + end; end; @@ -446,7 +449,6 @@ end; procedure TJDbGridTimeCtrl.myEditOnEditingDone(Sender: TObject); begin - CellEditor.Caption := NormalizeTime(CellEditor.Caption, theValue); if Length(CellEditor.Caption) = 0 then begin if edited then @@ -460,21 +462,24 @@ begin end; end else - if IsValidTimeString(CellEditor.Caption) then begin - if edited and (not updated) then + CellEditor.Caption := NormalizeTime(CellEditor.Caption, theValue); + if IsValidTimeString(CellEditor.Caption) then begin - Field.DataSet.DisableControls; - theValue := StrToTime(CellEditor.Caption); - Field.DataSet.Edit; - Field.AsDateTime := theValue; - Field.DataSet.EnableControls; + if edited and (not updated) then + begin + Field.DataSet.DisableControls; + theValue := StrToTime(CellEditor.Caption); + Field.DataSet.Edit; + Field.AsDateTime := theValue; + Field.DataSet.EnableControls; + end; + end + else + begin + ShowMessage(Format(SInvalidTime, [CellEditor.Caption])); + CellEditor.Text := FormatDateTime(DisplayFormat, Field.AsDateTime); end; - end - else - begin - ShowMessage(Format(SInvalidTime, [CellEditor.Caption])); - CellEditor.Text := FormatDateTime(DisplayFormat, theValue); end; end; @@ -605,7 +610,6 @@ end; procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject); begin - CellEditor.Caption := NormalizeDate(CellEditor.Caption, theValue); if Length(CellEditor.Caption) = 0 then begin if edited then @@ -619,21 +623,24 @@ begin end; end else - if IsValidDateString(CellEditor.Caption) then begin - if edited and (not updated) then + CellEditor.Caption := NormalizeDate(CellEditor.Caption, theValue); + if IsValidDateString(CellEditor.Caption) then begin - Field.DataSet.DisableControls; - theValue := StrToDate(CellEditor.Caption); - Field.DataSet.Edit; - Field.AsDateTime := theValue; - field.DataSet.EnableControls; + if edited and (not updated) then + begin + Field.DataSet.DisableControls; + theValue := StrToDate(CellEditor.Caption); + Field.DataSet.Edit; + Field.AsDateTime := theValue; + field.DataSet.EnableControls; + end; + end + else + begin + ShowMessage(Format(SInvalidDate, [CellEditor.Caption])); + CellEditor.Text := FormatDateTime(DisplayFormat, Field.AsDateTime); end; - end - else - begin - ShowMessage(Format(SInvalidDate, [CellEditor.Caption])); - CellEditor.Text := FormatDateTime(DisplayFormat, theValue); end; //formatInput; end;