You've already forked lazarus-ccr
Fixed: manage properly Null values for dates and times in TJDBGridControl
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1989 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -23,6 +23,7 @@ type
|
|||||||
{ Protected declarations }
|
{ Protected declarations }
|
||||||
//procedure SelectEditor; override;
|
//procedure SelectEditor; override;
|
||||||
function GetDefaultEditor(Column: integer): TWinControl; override;
|
function GetDefaultEditor(Column: integer): TWinControl; override;
|
||||||
|
procedure UpdateData; override;
|
||||||
public
|
public
|
||||||
{ Public declarations }
|
{ Public declarations }
|
||||||
constructor Create(TheOwner: TComponent); override;
|
constructor Create(TheOwner: TComponent); override;
|
||||||
@ -67,20 +68,28 @@ begin
|
|||||||
if Result <> nil then
|
if Result <> nil then
|
||||||
begin
|
begin
|
||||||
//aColumn := Columns.Items[Column - 1];
|
//aColumn := Columns.Items[Column - 1];
|
||||||
aField:= GetFieldFromGridColumn(Column);
|
aField := GetFieldFromGridColumn(Column);
|
||||||
//if aColumn <> nil then
|
//if aColumn <> nil then
|
||||||
if aField <> nil then;
|
if aField <> nil then;
|
||||||
//case aColumn.Field.DataType of
|
//case aColumn.Field.DataType of
|
||||||
case aField.DataType of
|
case aField.DataType of
|
||||||
ftSmallint, ftInteger: Result := integerDbGridControl.Editor(Self);
|
ftSmallint, ftInteger: Result := integerDbGridControl.Editor(Self);
|
||||||
ftDate: Result := dateDbGridControl.Editor(Self);
|
ftDate: Result := dateDbGridControl.Editor(Self);
|
||||||
ftTime: Result := timeDbGridControl.Editor(Self);
|
ftTime: Result := timeDbGridControl.Editor(Self);
|
||||||
ftCurrency, ftFloat, ftBCD: Result := doubleDbGridControl.Editor(Self);
|
ftCurrency, ftFloat, ftBCD: Result := doubleDbGridControl.Editor(Self);
|
||||||
// TODO: ftDateTime. strings?
|
// TODO: ftDateTime. strings?
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TJDBGridControl.UpdateData;
|
||||||
|
begin
|
||||||
|
if not (SelectedField.DataType in [ftSmallInt, ftInteger, ftDate,
|
||||||
|
ftTime, ftCurrency, ftFloat, ftBCD]) then
|
||||||
|
inherited UpdateData;
|
||||||
|
// TODO... think more about this
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TJDBGridControl.Create(TheOwner: TComponent);
|
constructor TJDBGridControl.Create(TheOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(TheOwner);
|
inherited Create(TheOwner);
|
||||||
|
@ -151,7 +151,12 @@ procedure TJDbGridTimeCtrl.myEditOnEditingDone(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
CellEditor.Caption := NormalizeTime(CellEditor.Caption, theValue);
|
CellEditor.Caption := NormalizeTime(CellEditor.Caption, theValue);
|
||||||
if Length(CellEditor.Caption) = 0 then
|
if Length(CellEditor.Caption) = 0 then
|
||||||
theValue := 0
|
begin
|
||||||
|
Field.DataSet.Edit;
|
||||||
|
Field.Value := Null;
|
||||||
|
theValue := 0;
|
||||||
|
updated := True;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if IsValidTimeString(CellEditor.Caption) then
|
if IsValidTimeString(CellEditor.Caption) then
|
||||||
begin
|
begin
|
||||||
@ -190,7 +195,14 @@ end;
|
|||||||
procedure TJDbGridTimeCtrl.OnKeyDown(Sender: TObject; var Key: word;
|
procedure TJDbGridTimeCtrl.OnKeyDown(Sender: TObject; var Key: word;
|
||||||
Shift: TShiftState);
|
Shift: TShiftState);
|
||||||
begin
|
begin
|
||||||
if Length(CellEditor.Caption) <> 0 then
|
if Length(CellEditor.Caption) = 0 then
|
||||||
|
begin
|
||||||
|
Field.DataSet.Edit;
|
||||||
|
Field.Value := Null;
|
||||||
|
theValue := 0;
|
||||||
|
updated := True;
|
||||||
|
end
|
||||||
|
else
|
||||||
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 IsValidTimeString(NormalizeTime(CellEditor.Caption, theValue))) then
|
(not IsValidTimeString(NormalizeTime(CellEditor.Caption, theValue))) then
|
||||||
begin
|
begin
|
||||||
@ -225,7 +237,7 @@ begin
|
|||||||
begin
|
begin
|
||||||
theValue := StrToTime(CellEditor.Caption);
|
theValue := StrToTime(CellEditor.Caption);
|
||||||
Field.DataSet.Edit;
|
Field.DataSet.Edit;
|
||||||
Field.AsDateTime:= theValue ;
|
Field.AsDateTime := theValue;
|
||||||
CellEditor.SelectAll;
|
CellEditor.SelectAll;
|
||||||
updated := True;
|
updated := True;
|
||||||
end;
|
end;
|
||||||
@ -283,7 +295,12 @@ procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject);
|
|||||||
begin
|
begin
|
||||||
CellEditor.Caption := NormalizeDate(CellEditor.Caption, theValue);
|
CellEditor.Caption := NormalizeDate(CellEditor.Caption, theValue);
|
||||||
if Length(CellEditor.Caption) = 0 then
|
if Length(CellEditor.Caption) = 0 then
|
||||||
theValue := 0
|
begin
|
||||||
|
Field.DataSet.Edit;
|
||||||
|
Field.Value := Null;
|
||||||
|
theValue := 0;
|
||||||
|
updated := True;
|
||||||
|
end
|
||||||
else
|
else
|
||||||
if IsValidDateString(CellEditor.Caption) then
|
if IsValidDateString(CellEditor.Caption) then
|
||||||
begin
|
begin
|
||||||
|
Reference in New Issue
Block a user