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 }
|
||||
//procedure SelectEditor; override;
|
||||
function GetDefaultEditor(Column: integer): TWinControl; override;
|
||||
procedure UpdateData; override;
|
||||
public
|
||||
{ Public declarations }
|
||||
constructor Create(TheOwner: TComponent); override;
|
||||
@ -67,20 +68,28 @@ begin
|
||||
if Result <> nil then
|
||||
begin
|
||||
//aColumn := Columns.Items[Column - 1];
|
||||
aField:= GetFieldFromGridColumn(Column);
|
||||
aField := GetFieldFromGridColumn(Column);
|
||||
//if aColumn <> nil then
|
||||
if aField <> nil then;
|
||||
//case aColumn.Field.DataType of
|
||||
case aField.DataType of
|
||||
ftSmallint, ftInteger: Result := integerDbGridControl.Editor(Self);
|
||||
ftDate: Result := dateDbGridControl.Editor(Self);
|
||||
ftTime: Result := timeDbGridControl.Editor(Self);
|
||||
ftCurrency, ftFloat, ftBCD: Result := doubleDbGridControl.Editor(Self);
|
||||
// TODO: ftDateTime. strings?
|
||||
end;
|
||||
//case aColumn.Field.DataType of
|
||||
case aField.DataType of
|
||||
ftSmallint, ftInteger: Result := integerDbGridControl.Editor(Self);
|
||||
ftDate: Result := dateDbGridControl.Editor(Self);
|
||||
ftTime: Result := timeDbGridControl.Editor(Self);
|
||||
ftCurrency, ftFloat, ftBCD: Result := doubleDbGridControl.Editor(Self);
|
||||
// TODO: ftDateTime. strings?
|
||||
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);
|
||||
begin
|
||||
inherited Create(TheOwner);
|
||||
|
@ -151,7 +151,12 @@ procedure TJDbGridTimeCtrl.myEditOnEditingDone(Sender: TObject);
|
||||
begin
|
||||
CellEditor.Caption := NormalizeTime(CellEditor.Caption, theValue);
|
||||
if Length(CellEditor.Caption) = 0 then
|
||||
theValue := 0
|
||||
begin
|
||||
Field.DataSet.Edit;
|
||||
Field.Value := Null;
|
||||
theValue := 0;
|
||||
updated := True;
|
||||
end
|
||||
else
|
||||
if IsValidTimeString(CellEditor.Caption) then
|
||||
begin
|
||||
@ -190,7 +195,14 @@ end;
|
||||
procedure TJDbGridTimeCtrl.OnKeyDown(Sender: TObject; var Key: word;
|
||||
Shift: TShiftState);
|
||||
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
|
||||
(not IsValidTimeString(NormalizeTime(CellEditor.Caption, theValue))) then
|
||||
begin
|
||||
@ -225,7 +237,7 @@ begin
|
||||
begin
|
||||
theValue := StrToTime(CellEditor.Caption);
|
||||
Field.DataSet.Edit;
|
||||
Field.AsDateTime:= theValue ;
|
||||
Field.AsDateTime := theValue;
|
||||
CellEditor.SelectAll;
|
||||
updated := True;
|
||||
end;
|
||||
@ -283,7 +295,12 @@ procedure TJDbGridDateCtrl.myEditOnEditingDone(Sender: TObject);
|
||||
begin
|
||||
CellEditor.Caption := NormalizeDate(CellEditor.Caption, theValue);
|
||||
if Length(CellEditor.Caption) = 0 then
|
||||
theValue := 0
|
||||
begin
|
||||
Field.DataSet.Edit;
|
||||
Field.Value := Null;
|
||||
theValue := 0;
|
||||
updated := True;
|
||||
end
|
||||
else
|
||||
if IsValidDateString(CellEditor.Caption) then
|
||||
begin
|
||||
|
Reference in New Issue
Block a user