You've already forked lazarus-ccr
Use new NormalizeDate code in jdbgridutils
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1951 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -54,7 +54,12 @@ var
|
|||||||
ds, ms, ys: string;
|
ds, ms, ys: string;
|
||||||
aDate: TDateTime;
|
aDate: TDateTime;
|
||||||
tokens: TStringList;
|
tokens: TStringList;
|
||||||
|
aDateFormat: string;
|
||||||
begin
|
begin
|
||||||
|
if theFormat <> '' then
|
||||||
|
aDateFormat := ShortDateFormat
|
||||||
|
else
|
||||||
|
aDateFormat := theFormat;
|
||||||
if theValue = 0 then
|
if theValue = 0 then
|
||||||
DecodeDate(Now, y, m, d)
|
DecodeDate(Now, y, m, d)
|
||||||
else
|
else
|
||||||
@@ -82,7 +87,8 @@ begin
|
|||||||
texto := ds + DateSeparator + ms + DateSeparator + ys;
|
texto := ds + DateSeparator + ms + DateSeparator + ys;
|
||||||
if IsValidDateString(texto) then
|
if IsValidDateString(texto) then
|
||||||
begin
|
begin
|
||||||
Result:= texto;
|
aDate := StrToDate(texto);
|
||||||
|
Result := FormatDateTime(aDateFormat, aDate);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
tokens.Free;
|
tokens.Free;
|
||||||
|
@@ -42,7 +42,6 @@ type
|
|||||||
procedure setFormat(const AValue: string);
|
procedure setFormat(const AValue: string);
|
||||||
procedure OnKeyPress(Sender: TObject; var key: char);
|
procedure OnKeyPress(Sender: TObject; var key: char);
|
||||||
procedure OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
|
procedure OnKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
|
||||||
function IsValidDate(const Value: string): boolean;
|
|
||||||
public
|
public
|
||||||
CellEditor: TStringCellEditor;
|
CellEditor: TStringCellEditor;
|
||||||
theGrid: TDBGrid;
|
theGrid: TDBGrid;
|
||||||
@@ -129,10 +128,11 @@ end;
|
|||||||
|
|
||||||
procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject);
|
procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
|
CellEditor.Caption:= NormalizeDate(CellEditor.Caption, theValue);
|
||||||
if Length(CellEditor.Caption) = 0 then
|
if Length(CellEditor.Caption) = 0 then
|
||||||
theValue := 0
|
theValue := 0
|
||||||
else
|
else
|
||||||
if IsValidDate(CellEditor.Caption) then
|
if IsValidDateString(CellEditor.Caption) then
|
||||||
begin
|
begin
|
||||||
if (not updated) then
|
if (not updated) then
|
||||||
begin
|
begin
|
||||||
@@ -172,10 +172,9 @@ procedure TJDbGridDateCtrl.OnKeyDown(Sender: TObject; var Key: word;
|
|||||||
begin
|
begin
|
||||||
if Length(CellEditor.Caption) <> 0 then
|
if Length(CellEditor.Caption) <> 0 then
|
||||||
if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and
|
if (Key in [VK_RETURN, VK_TAB, VK_UP, VK_DOWN, VK_LEFT, VK_RIGHT]) and
|
||||||
(not IsValidDate(CellEditor.Caption)) then
|
(not IsValidDateString(NormalizeDate(CellEditor.Caption, theValue))) then
|
||||||
begin
|
begin
|
||||||
ShowMessage(CellEditor.Caption + ' no es una fecha válida' +
|
ShowMessage(CellEditor.Caption + ' no es una fecha válida');
|
||||||
CellEditor.Text);
|
|
||||||
CellEditor.Text := FormatDateTime(format, theValue);
|
CellEditor.Text := FormatDateTime(format, theValue);
|
||||||
CellEditor.SelectAll;
|
CellEditor.SelectAll;
|
||||||
Key := VK_UNKNOWN;
|
Key := VK_UNKNOWN;
|
||||||
@@ -198,10 +197,11 @@ begin
|
|||||||
else
|
else
|
||||||
if Key in [VK_RETURN, VK_TAB] then
|
if Key in [VK_RETURN, VK_TAB] then
|
||||||
begin
|
begin
|
||||||
|
CellEditor.Caption:= NormalizeDate(CellEditor.Caption, theValue);
|
||||||
if Length(CellEditor.Caption) = 0 then
|
if Length(CellEditor.Caption) = 0 then
|
||||||
theValue := 0
|
theValue := 0
|
||||||
else
|
else
|
||||||
if IsValidDate(CellEditor.Caption) then
|
if IsValidDateString(CellEditor.Caption) then
|
||||||
begin
|
begin
|
||||||
theValue := StrToDate(CellEditor.Caption);
|
theValue := StrToDate(CellEditor.Caption);
|
||||||
Field.DataSet.Edit;
|
Field.DataSet.Edit;
|
||||||
@@ -211,31 +211,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TJDbGridDateCtrl.IsValidDate(const Value: string): boolean;
|
|
||||||
var
|
|
||||||
texto: string;
|
|
||||||
i: integer;
|
|
||||||
d, m, y: word;
|
|
||||||
begin
|
|
||||||
Result := False;
|
|
||||||
// normalize date
|
|
||||||
texto := CellEditor.Caption;
|
|
||||||
texto := replacechar(texto, '.', DateSeparator);
|
|
||||||
texto := replacechar(texto, '-', DateSeparator);
|
|
||||||
texto := replacechar(texto, '/', DateSeparator);
|
|
||||||
i := countchar(texto, DateSeparator);
|
|
||||||
decodedate(theValue, y, m, d);
|
|
||||||
case i of
|
|
||||||
1: texto := texto + DateSeparator + IntToStr(y);
|
|
||||||
0: texto := texto + DateSeparator + IntToStr(m) + DateSeparator + IntToStr(y);
|
|
||||||
end;
|
|
||||||
CellEditor.Caption := texto;
|
|
||||||
// comprobar que la fecha es valida
|
|
||||||
if StrToDateDef(texto, MaxDateTime) = MaxDateTime then
|
|
||||||
Result := False
|
|
||||||
else
|
|
||||||
Result := True;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TJDbGridDateCtrl.isNull: boolean;
|
function TJDbGridDateCtrl.isNull: boolean;
|
||||||
begin
|
begin
|
||||||
|
Reference in New Issue
Block a user