Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Autosearch on DateTime fields

edited September 2001 in General
Hi.

I have a datetime column, and I want the user to be able to autosearch on
the column but only matching the date part. Unfortunately sql server does a
complete match on the whole datetime string rather than just the date part.
I have found that way to get around this is to use a between operator
instead of equals. That way you can do a between the Given Date and the
Given Date plus one day.

I created a custom TppAutoSearchDialog that does the following

procedure
TCustomAutoSearchDialog.GetPanelClassForField(AField:TppAutoSearchField;var
APanelClass:TppAutoSearchPanelClass);
begin

if (aField.DataType=dtDateTime) and (aField.SearchOperator=soEqual) then
begin
aField.SearchOperator:=soBetween;
APanelClass:=TCustomOneDateSearchPanel;
end;
end;


I then derived a new TppAutoSearchPanel exactly the same as
TppSimpleSearchPanel except with a DateEdit rather than a TEdit plus the
following simple change:-

function TCustomOneDateSearchPanel.Valid: Boolean;
var Date2:TDate;
begin
Result := False;

if not(ShowAllValues.Visible) or ((ShowAllValues.Visible) and
not(ShowAllValues.Checked)) then
if not(ValidateEditControl(FDateEdit)) then Exit;

Result := True;

Date2:= FDateEdit.Date+1;

// Field.SearchExpression := FDateEdit.Text;

Field.SearchExpression := FDateEdit.Text + ',' + DateToStr(Date2);
Field.ShowAllValues := (ShowAllValues.Visible) and
(ShowAllValues.Checked);
end;

This works perfectly, and the user gets the desired data but only has to
enter the one date. So to them it only looks as though they are doing a
date equals comparison, but in reality they are doing a between comparison.
The only problem is that the next time they use autosearch the panel now
shows the between dates dialog. At what point can I reset the
aField.SearchOperator value to be soequal and avoid this happening?

TIA.

John.

--
I don't like spammers so send your spam to
abuse@hotmail.com

Comments

  • edited September 2001

    Have you tried using Report.BeforeAutoSearchDialogCreate?




    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.