📄 ottdbedit.pas
字号:
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
begin
Parameters[i].Value := '%'+UpperCase(Trim(Text))+'%';
//SQL.Add(' order by instr('+Parameters[i].Name+','+QuotedStr(UpperCase(Trim(Text)))+'),len('+Parameters[i].Name+')');
end
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 TottDBEdit.SetAutoInit(Value: Boolean);
begin
if FAutoInit <> Value then
FAutoInit := Value;
if not (csDesigning in ComponentState) then
begin
if FAutoInit then
Init();
end;
end;
procedure TottDBEdit.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 TottDBEdit.SetFilterField(const Value: TStrings);
begin
FLocalFilterFields.Assign(Value);
end;
procedure TottDBEdit.SetInputParam(Value: Integer);
begin
if Value <> FInputParam then
FInputParam := Value;
if not (FInputParam in [0..3]) then
FInputParam := 0;
end;
procedure TottDBEdit.SetListColumnWidth(Value: String);
begin
if FListColumnWidth <> Value then
FListColumnWidth := Value;
end;
procedure TottDBEdit.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 TottDBEdit.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 TottDBEdit.SetListGridHeight(Value: Integer);
begin
if FListGridHeight <> Value then
FListGridHeight := Value;
end;
procedure TottDBEdit.SetListGridWidth(Value: Integer);
begin
if FListGridWidth <> Value then
FListGridWidth := Value;
end;
procedure TottDBEdit.SetLocalFilterSQL(Value: WideString);
begin
if FLocalFilterSQL <> Value then
FLocalFilterSQL := Value;
end;
procedure TottDBEdit.SetLocatFilter(Value: Boolean);
begin
if FLocalFilter <> Value then
FLocalFilter := Value;
end;
procedure TottDBEdit.SetParams(Value: TParams);
begin
FParams.Assign(Value);
end;
procedure TottDBEdit.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;
{ TottDBGrid }
constructor TottDBGrid.Create(AOwner: TComponent);
begin
inherited;
FVersion := 'OttLib 1.0';
Options := [dgTitles, dgRowSelect, dgIndicator, dgColumnResize
,dgColLines, dgAlwaysShowSelection, dgConfirmDelete, dgCancelOnExit];
Columns.Clear;
Visible := false;
TabStop := false;
ReadOnly := true;
OnClick := ottOnClick;
OnKeyDown := ottKeyDown;
OnExit := ottOnExit;
self.OnMouseDown := self.ottOnMouseDown;
end;
procedure TottDBGrid.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) then
begin
if (AComponent = FActiveControl) then
FActiveControl := nil;
end;
end;
procedure TottDBGrid.ottKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var mKeyDown: TKeyEvent;
M: TMethod;
begin
//如果是按回车或ESC键,将相应消息发给相应的录入控件
if Key in [VK_RETURN, VK_ESCAPE] then
begin
if Assigned(DataSource) then
if Assigned(DataSource.DataSet) then
if not DataSource.DataSet.IsEmpty then
begin
if Assigned(FActiveControl) then
begin
if IsPublishedProp(FActiveControl, 'OnKeyDown') then
begin
M := GetMethodProp(FActiveControl, 'OnKeyDown');
if Assigned(M.Code) then
begin
if FActiveControl.CanFocus then
FActiveControl.SetFocus;
mKeyDown := TKeyEvent(M);
mKeyDown(FActiveControl, Key, Shift);
Key := 0;
end;
end;
end;
end;
end;
end;
procedure TottDBGrid.ottOnClick(Sender: TObject);
begin
//如果是用鼠标点击选择记录,将给关联控件发回车选择消息
if Assigned(DataSource) then
if Assigned(DataSource.DataSet) then
if not DataSource.DataSet.IsEmpty then
begin
if Assigned(FActiveControl) then
begin
PostMessage(FActiveControl.Handle, $0100, 13, 0);
end;
end;
end;
procedure TottDBGrid.ottOnExit(Sender: TObject);
begin
if Assigned(FActiveControl) then
begin
if not FActiveControl.Focused then
begin
PostMessage(FActiveControl.Handle, $0100, 27, 0)
end;
end;
end;
procedure TottDBGrid.ottOnMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ottOnClick(Sender);
end;
procedure TottDBGrid.SetActiveControl(Value: TWinControl);
begin
if FActiveControl <> Value then
FActiveControl := Value;
if Value <> nil then Value.FreeNotification(Self);
end;
end.
//OttLib end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -