📄 ottedit.pas
字号:
end
else
begin
//Text := FKeyValue;
end;
end;
end;//if Sender is ClassType then
if Assigned(FOnExit) then
FOnExit(Sender);
end;
procedure TottEdit.ottKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Sender is ClassType then
begin
if Key in [VK_UP, VK_DOWN, VK_RETURN, VK_ESCAPE] then
begin
if Assigned(FListGrid) then
begin
if FListGrid.Visible then
begin
if Assigned(FListGrid.DataSource) then
begin
if Assigned(FListGrid.DataSource.DataSet) then
begin
if FListGrid.DataSource.DataSet.Active then
begin
if Key = VK_UP then
begin
FListGrid.DataSource.DataSet.Prior;
Key := 0;
end
else if Key = VK_DOWN then
begin
FListGrid.DataSource.DataSet.Next;
Key := 0;
end
else if Key = VK_ESCAPE then
begin
CheckInvaildValue;
HideListGrid;
if not (Focused or FListGrid.Focused) then
ottExit(self);
end
else if Key = VK_RETURN then
begin
if not FFindQuery.IsEmpty then
begin
if FFindQuery.FindField(FLookupKeyField) <> nil then
FKeyValue := FFindQuery.FieldByName(FLookupKeyField).Value
else
FKeyValue := FFindQuery.Fields[0].Value;
if FFindQuery.FindField(FLookupResultField) <> nil then
FListValue := FFindQuery.FieldByName(FLookupResultField).Value
else
FListValue := FFindQuery.Fields[0].Value;
if Assigned(FOnSelectValue) then
FOnSelectValue(self);
HideListGrid;
SetFocus;
PostMessage(Handle, $0100, VK_TAB, 0);
end;
Key := 0;
end;
end; //if FListGrid.DataSource.DataSet.Active then
end;//if Assigned(FListGrid.DataSource.DataSet) then
end;//if Assigned(FListGrid.DataSource) then
end; //if FListGrid.Visible then
end;//if Assigned(FListGrid) then
end //if Key in [VK_UP, VK_DOWN, VK_RETURN, VK_ESCAPE] then
else
begin
FInputFlag := true;
end;
end;//if Sender is ClassType then
if Key = VK_RETURN then
PostMessage(Handle, $0100, VK_TAB, 0);
if Assigned(FOnKeyDown) then
FOnKeyDown(Sender, Key, Shift);
end;
procedure TottEdit.SearchData;
var i: integer;
fStr: String;
begin
if Assigned(FFindQuery) then
begin
if Assigned(FConnection) then
begin
with FFindQuery do
begin
DisableControls;
try
if FLocalFilter then //以下代码为处理本地过滤查找的
begin
FFindQuery.Filtered := false;
fStr := '';
if FInputFlag then
begin
for i := 0 to FLocalFilterFields.Count-1 do
begin
if i = FInputParam then
if Trim(Text)<>'' then
begin
if FIsLike then
fStr := fStr + FLocalFilterFields.Strings[i] + ' like '+QuotedStr('*'+UpperCase(Trim(Text))+'*')+' and '
else
fStr := fStr + FLocalFilterFields.Strings[i] + ' like '+QuotedStr(UpperCase(Trim(Text))+'*')+' and ';
end;
if (i>3)and((i-3)<=FParams.Count) then
fStr := fStr + FLocalFilterFields.Strings[i] + '='+ QuotedStr(FParams.Items[i-4].AsString)+' and ';
end;
if Length(fStr)>4 then
System.Delete(fStr, Length(fStr)-4, 4);
end
else
begin
for i := 0 to FLocalFilterFields.Count-1 do
begin
if i = 2 then
if Trim(Text)<>'' then
if FIsLike then
fStr := fStr + FLocalFilterFields.Strings[i] + ' like '+QuotedStr('*'+UpperCase(Trim(Text))+'*')+' and '
else
fStr := fStr + FLocalFilterFields.Strings[i] + ' like '+QuotedStr(UpperCase(Trim(Text))+'*')+' and ';
if (i>3)and((i-3)<=FParams.Count) then
fStr := fStr + FLocalFilterFields.Strings[i] + '='+ QuotedStr(FParams.Items[i-4].AsString)+' and ';
end;
if Length(fStr)>4 then
System.Delete(fStr, Length(fStr)-4, 4);
end;
FFindQuery.Filter := fStr;
if Trim(FFindQuery.Filter)<>'' then
FFindQuery.Filtered := true
else
FFindQuery.Filtered := false;
end //本地过滤结束
else //以下代码为处理直接通过服务器查询的
begin
Close;
MaxRecords := FMaxRecord;
SQL.Clear;
SQL.Add(FSQL.Text);
if FInputFlag then
begin
for i:=0 to Parameters.Count -1 do
begin
if i = FInputParam then
if FIsLike then
Parameters[i].Value := '%'+UpperCase(Trim(Text))+'%'
else
Parameters[i].Value := UpperCase(Trim(Text))+'%'
else
Parameters[i].Value := '%';
if (i>3)and((i-3)<=FParams.Count) then
Parameters[i].Value := FParams.Items[i-4].Value;
end;
end
else
begin
for i:=0 to Parameters.Count -1 do
begin
if i = 2 then
if FIsLike then
Parameters[i].Value := '%'+UpperCase(Trim(Text))+'%'
else
Parameters[i].Value := UpperCase(Trim(Text))+'%'
else
Parameters[i].Value := '%';
if (i>3)and((i-3)<=FParams.Count) then
Parameters[i].Value := FParams.Items[i-4].Value;
end;
end;
Open;
end; //服务器端查询结束
SetListGridColumn;
FInputFlag := true;
finally
EnableControls;
end;
end;
end
else
raise Exception.Create('请先设置好Connection属性');
end;
end;
procedure TottEdit.SetAutoInit(Value: Boolean);
begin
if FAutoInit <> Value then
FAutoInit := Value;
if not (csDesigning in ComponentState) then
begin
if FAutoInit then
Init();
end;
end;
procedure TottEdit.SetConnection(Value: TADOConnection);
begin
if FConnection<>Value then
FConnection := Value;
if Value <> nil then Value.FreeNotification(Self);
if Assigned(FFindQuery) then
begin
if Assigned(FConnection) then
FFindQuery.Connection := FConnection;
FFindQuery.SQL.Assign(FSQL);
if FFindQuery.Connection.Connected then
FFindQuery.Connection.Connected := false;
end;
end;
procedure TottEdit.SetFilterField(const Value: TStrings);
begin
FLocalFilterFields.Assign(Value);
end;
procedure TottEdit.SetInputParam(Value: Integer);
begin
if Value <> FInputParam then
FInputParam := Value;
if not (FInputParam in [0..3]) then
FInputParam := 0;
end;
procedure TottEdit.SetListColumnWidth(Value: String);
begin
if FListColumnWidth <> Value then
FListColumnWidth := Value;
end;
procedure TottEdit.SetListGrid(Value: TottDBGrid);
begin
if Value <> nil then //设置显示的Grid ,先检测其它数据是否完整
begin
if not (csLoading in ComponentState) then
begin
//if not Assigned(FConnection) then
// raise Exception.Create('请先设置好Connection属性');
//if not Assigned(DataSource) then
// raise Exception.Create('请先设置好DataSource属性');
//if not Assigned(DataSource.DataSet) then
// raise Exception.Create('请先设置好DataSource关联的DataSet');
//if Trim(DataField) = '' then
// raise Exception.Create('请先设置好DataField属性');
//if DataSource.DataSet.FieldByName(DataField).FieldKind <> fkLookup then
// raise Exception.Create('该控件所对应的数据字段必须是Lookup字段');
end;
//if Assigned(DataSource) then
//if Assigned(DataSource.DataSet) then
{begin
FKeyField := DataSource.DataSet.FieldByName(DataField).KeyFields;
FListField := DataField;
FLookupKeyField := DataSource.DataSet.FieldByName(DataField).LookupKeyFields;
FLookupResultField := DataSource.DataSet.FieldByName(DataField).LookupResultField;
FLookupDataSet := DataSource.DataSet.FieldByName(DataField).LookupDataSet;
end;}
end;
if FListGrid<>Value then
FListGrid := Value;
if Value <> nil then
begin
if not (csLoading in ComponentState) then
begin
if (FListGridWidth=0)and(FListGridHeight=0) then
begin
FListGridWidth := FListGrid.Width;
FListGridHeight := FListGrid.Height;
end;
end;
Value.FreeNotification(Self);
end;
if Assigned(FListGrid) then
FListGrid.Hide;
//BuilderField;
end;
procedure TottEdit.SetListGridColumn;
var s: string;
i,j: integer;
begin
if Assigned(FListGrid) then
begin
if FListGridWidth > 0 then
FListGrid.Width := FListGridWidth;
if FListGridHeight > 0 then
FListGrid.Height := FListGridHeight;
FListGrid.Columns.Clear;
FListGrid.Columns.RebuildColumns;
s := FListColumnWidth;
s := Trim(s);
if Trim(s)='' then
exit;
with FListGrid do
begin
for i := 0 to Columns.Count - 1 do
begin
Columns.Items[i].Visible := false;
if Length(s)>=1 then
begin
for j := 1 to Length(s) do
begin
if not (s[j] in ['0'..'9']) then
break;
end;
if j>1 then
begin
try
Columns.Items[i].Visible := true;
Columns.Items[i].Width := StrToInt(Copy(s, 1, j-1));
except
end;
end;
System.Delete(s, 1, j);
end;
end;
end;
end;
end;
procedure TottEdit.SetListGridHeight(Value: Integer);
begin
if FListGridHeight <> Value then
FListGridHeight := Value;
end;
procedure TottEdit.SetListGridWidth(Value: Integer);
begin
if FListGridWidth <> Value then
FListGridWidth := Value;
end;
procedure TottEdit.SetLocalFilterSQL(Value: WideString);
begin
if FLocalFilterSQL <> Value then
FLocalFilterSQL := Value;
end;
procedure TottEdit.SetLocatFilter(Value: Boolean);
begin
if FLocalFilter <> Value then
FLocalFilter := Value;
end;
procedure TottEdit.SetParams(Value: TParams);
begin
FParams.Assign(Value);
end;
procedure TottEdit.SetSQL(const Value: TStrings);
begin
FSQL.Assign(Value);
if Assigned(FFindQuery) then
begin
if Assigned(FConnection) then
FFindQuery.Connection := FConnection;
FFindQuery.SQL.Assign(FSQL);
if FConnection.Connected then
FConnection.Connected := false;
end;
end;
end.
//OttLib end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -