📄 untinfosearch.pas
字号:
(*===========================================================*)
(* *)
(* Jerk Computer Assembly Manager *)
(* *)
(* 程序作者:杨芹勍 *)
(* 武汉科技大学 理学院 信息与计算科学031班 *)
(* 武汉科技大学 莘特工作室 *)
(* *)
(* IDE:Borland Delphi 2006 Update 2 *)
(* 第三方控件:Raize 4.03 *)
(* 数据库:Microsoft SQL Server 2000 *)
(* 数据库访问引擎:原生ADO(ADODB_TLB) *)
(* 数据库管理引擎:JERK DBMANAGER ALPHA *)
(* *)
(* 此软件及源代码归 JERK SYSTEM 版权所有 *)
(* (C)Copyright 2002-2006 Jerk System. *)
(* *)
(*===========================================================*)
unit untInfoSearch;
interface
uses
Windows,
Messages,
SysUtils,
Variants,
Classes,
Graphics,
Controls,
Forms,
Dialogs,
ComCtrls,
ExtCtrls,
Menus,
StdCtrls,
StrUtils,
Mask,
ADODB_TLB,
RzButton,
RzBtnEdt,
RzCmboBx,
RzCommon,
RzEdit,
RzListVw,
RzRadChk,
RzSplit,
RzPanel,
RzTabs,
JSDBListView,
JCAMConsts,
JCAMUtils,
JCAMDialogForm,
JCAMManagerForm,
JCAMTableViewEditor;
type
TfrmInfoSearch = class( TfrmJCAMDialogForm )
Label1: TLabel;
cboFieldsCondition: TRzComboBox;
chkByLastResult: TRzCheckBox;
RzPanel1: TRzPanel;
sbxInfoSearch: TScrollBox;
procedure FormCreate( Sender: TObject );
procedure sbxInfoSearchResize( Sender: TObject );
procedure pCHKOnClick( Sender: TObject );
procedure pBTEOnButtonClick( Sender: TObject );
procedure btnOKClick( Sender: TObject );
private
m_cn: _Connection;
m_sKeyFieldName: string;
m_sTableViewName: string;
m_bShowKeyField: Boolean;
procedure SetConnection( const Value: _Connection );
procedure SetTableViewName( const Value: string );
procedure SetKeyFieldName( const Value: string );
procedure SetShowKeyField( const Value: Boolean );
public
property Connection: _Connection
read m_cn
write SetConnection;
property TableViewName: string
read m_sTableViewName
write SetTableViewName;
property KeyFieldName: string
read m_sKeyFieldName
write SetKeyFieldName;
property ShowKeyField: Boolean
read m_bShowKeyField
write SetShowKeyField
default False;
procedure StartSurf;
end;
var
frmInfoSearch: TfrmInfoSearch;
implementation
{$R *.dfm}
uses
untTField,
untFieldValuesList;
type
PInfoSearchFieldProp = ^TInfoSearchFieldProp;
TInfoSearchFieldProp = record
CheckBox: TRzCheckBox;
ComboBox: TRzComboBox;
ButtonEdit: TRzButtonEdit;
FieldName: string;
FieldType: DataTypeEnum;
CodeTable: string;
IDFromCode: string;
NameFromCode: string;
end;
{ TfrmInfoSearch }
procedure TfrmInfoSearch.btnOKClick( Sender: TObject );
var
cmp: TComponent;
pisfp: PInfoSearchFieldProp;
sCondition, sFieldsCondition, sFieldValue: string;
n: Integer;
begin
{ 开始搜索 }
inherited;
// TODO: 获取每个字段间的条件
if cboFieldsCondition.ItemIndex = 0 then
sFieldsCondition := ' AND '
else
sFieldsCondition := ' OR';
// TODO: 获取上次搜索结果的语句
if chkByLastResult.Checked then
begin
sCondition := TfrmJCAMManagerForm( Owner ).InfoSearchCondition;
if sCondition <> EmptyStr then
sCondition := sCondition + sFieldsCondition;
end;
// 生成语句
for n := 0 to sbxInfoSearch.ComponentCount - 1 do
begin
cmp := sbxInfoSearch.Components[ n ];
if ( cmp is TRzCheckBox ) and ( TRzCheckBox( cmp ).Checked ) then
begin
pisfp := PInfoSearchFieldProp( Pointer( TControl( cmp ).Tag ) );
sCondition := sCondition + '[' + pisfp^.FieldName + ']' +
Trim( pisfp^.ComboBox.Text );
sFieldValue := Trim( pisfp^.ButtonEdit.Text );
if pisfp^.ComboBox.ItemIndex = 6 then
sFieldValue := '%' + sFieldValue + '%';
// TODO: 根据字段属性判断是否要加引号
if pisfp^.FieldType <= adBoolean then
sCondition := sCondition + sFieldValue + sFieldsCondition
else
sCondition := sCondition + '''' + sFieldValue + '''' + sFieldsCondition;
end;
end;
sCondition := LeftBStr( sCondition, Length( sCondition ) - Length(
sFieldsCondition ) );
// TODO: 回调
with TfrmJCAMManagerForm( Owner ) do
begin
InfoSearchCondition := sCondition;
ListItemsByCondition( sCondition );
end;
end;
procedure TfrmInfoSearch.FormCreate( Sender: TObject );
begin
inherited;
m_sKeyFieldName := EmptyStr;
m_sTableViewName := EmptyStr;
m_bShowKeyField := False;
end;
procedure TfrmInfoSearch.pBTEOnButtonClick( Sender: TObject );
var
pisfp: PInfoSearchFieldProp;
begin
{}
if Sender is TRzButtonEdit then
begin
pisfp := PInfoSearchFieldProp( Pointer( TRzButtonEdit( Sender ).Tag ) );
frmFieldValuesList := TfrmFieldValuesList.Create( Self );
with frmFieldValuesList do
begin
Connection := Self.Connection;
TableViewName := Self.TableViewName;
FieldName := pisfp.FieldName;
FieldValue := pisfp.ButtonEdit.Text;
StartSurf;
ShowModal;
if ModalResult = mrOK then
pisfp.ButtonEdit.Text := FieldValue;
end;
FreeAndNil( frmFieldValuesList );
end;
end;
procedure TfrmInfoSearch.pCHKOnClick( Sender: TObject );
var
bIsChecked: Boolean;
begin
{ 条件选择改变了选择 }
with TRzCheckBox( Sender ) do
begin
bIsChecked := Checked;
with PInfoSearchFieldProp( Tag )^ do
begin
ComboBox.Enabled := bIsChecked;
ButtonEdit.Enabled := bIsChecked;
end;
end;
end;
procedure TfrmInfoSearch.sbxInfoSearchResize( Sender: TObject );
var
cmpContained: TComponent;
n, nMaxCboWidth: Integer;
begin
inherited;
{ 搜索面板改变大小 }
// TODO: 获取最宽的cbo的宽度
nMaxCboWidth := 0;
if sbxInfoSearch.ComponentCount > 0 then
begin
for n := 0 to sbxInfoSearch.ComponentCount - 1 do
begin
cmpContained := sbxInfoSearch.Components[ n ];
if cmpContained is TRzCheckBox then
nMaxCboWidth := Max( Canvas.TextWidth( TRzCheckBox( cmpContained
).Caption ) + 30, nMaxCboWidth );
end;
// TODO: 改变控件的宽度
for n := 0 to sbxInfoSearch.ComponentCount - 1 do
begin
cmpContained := sbxInfoSearch.Components[ n ];
if TControl( cmpContained ).Parent <> Self then
begin
if cmpContained is TRzCheckBox then
with TRzCheckBox( cmpContained ) do
SetBounds( 12, Top, nMaxCboWidth, Height );
if cmpContained is TRzComboBox then
with TRzComboBox( cmpContained ) do
SetBounds( 16 + nMaxCboWidth, Top, 60, Height );
if cmpContained is TRzButtonEdit then
with TRzButtonEdit( cmpContained ) do
SetBounds( 84 + nMaxCboWidth, Top, sbxInfoSearch.ClientWidth -
nMaxCboWidth - 90, Height );
end;
end;
end;
end;
procedure TfrmInfoSearch.SetConnection( const Value: _Connection );
begin
m_cn := Value;
end;
procedure TfrmInfoSearch.SetKeyFieldName( const Value: string );
begin
m_sKeyFieldName := Value;
end;
procedure TfrmInfoSearch.SetTableViewName( const Value: string );
begin
m_sTableViewName := Value;
end;
procedure TfrmInfoSearch.SetShowKeyField( const Value: Boolean );
begin
m_bShowKeyField := Value;
end;
procedure TfrmInfoSearch.StartSurf;
var
tf: TTableField;
rsFields: _Recordset;
cmpContained: TComponent;
chkInfoSearch: TRzCheckBox;
cboInfoSearch: TRzComboBox;
bteInfoSearch: TRzButtonEdit;
pisfp: PInfoSearchFieldProp;
sFieldName: string;
n, nCmpCount, nCmpTop: Integer;
begin
{ 开始列出字段数据 }
Screen.Cursor := crHourGlass;
tf := TTableField.Create;
tf.Connection := Connection;
sbxInfoSearch.Visible := False;
// TODO: 首先卸载原来的控件
nCmpCount := sbxInfoSearch.ComponentCount;
if nCmpCount > 0 then
try
for n := nCmpCount - 1 downto 0 do
begin
cmpContained := sbxInfoSearch.Components[ n ];
if ( cmpContained is TRzEdit ) or ( cmpContained is TRzComboBox ) then
FreeAndNil( cmpContained );
if cmpContained is TRzCheckBox then
begin
Dispose( Pointer( TRzCheckBox( cmpContained ).Tag ) );
FreeAndNil( cmpContained );
end;
end;
except
end;
// TODO: 以下代码初始化控件
nCmpTop := 8;
rsFields := CoRecordset.Create;
rsFields.Open( 'SELECT TOP 0 * FROM [' + TableViewName + ']',
Connection, adOpenForwardOnly, adLockReadOnly, adCmdText );
for n := 0 to rsFields.Fields.Count - 1 do
begin
sFieldName := rsFields.Fields[ n ].Name;
// TODO: 判断是否为KeyFieldName
if ( sFieldName = KeyFieldName ) and not m_bShowKeyField then
Continue;
tf.FieldName := sFieldName;
// TODO: 初始化搜索信息属性
New( pisfp );
pisfp.FieldName := sFieldName;
pisfp.FieldType := rsFields.Fields[ n ].type_;
pisfp.CodeTable := tf.CodeTable;
pisfp.IDFromCode := tf.IDFromCode;
pisfp.NameFromCode := tf.NameFromCode;
// TODO: 生成复选框
chkInfoSearch := TRzCheckBox.Create( sbxInfoSearch );
pisfp.CheckBox := chkInfoSearch;
with chkInfoSearch do
begin
Parent := sbxInfoSearch;
Tag := Integer( pisfp );
Caption := tf.FieldChs;
Top := nCmpTop + 3;
HotTrack := True;
HotTrackColorType := htctComplement;
HotTrackStyle := htsFrame;
OnClick := pCHKOnClick;
Visible := True;
end;
// TODO: 生成条件选择列表
cboInfoSearch := TRzComboBox.Create( sbxInfoSearch );
pisfp.ComboBox := cboInfoSearch;
with cboInfoSearch do
begin
Parent := sbxInfoSearch;
Tag := Integer( pisfp );
Items.Add( '=' );
Items.Add( '>' );
Items.Add( '>=' );
Items.Add( '<' );
Items.Add( '<=' );
Items.Add( '<>' );
Items.Add( 'LIKE' );
ItemIndex := 0;
Enabled := False;
Top := nCmpTop;
FlatButtons := True;
FrameVisible := True;
FrameHotTrack := True;
FramingPreference := fpCustomFraming;
Visible := True;
end;
// TODO: 生成输入编辑框
bteInfoSearch := TRzButtonEdit.Create( sbxInfoSearch );
pisfp.ButtonEdit := bteInfoSearch;
with bteInfoSearch do
begin
Parent := sbxInfoSearch;
Tag := Integer( pisfp );
Enabled := False;
Top := nCmpTop;
FlatButtons := True;
FrameVisible := True;
FrameHotTrack := True;
FramingPreference := fpCustomFraming;
OnButtonClick := pBTEOnButtonClick;
Visible := True;
end;
Inc( nCmpTop, 22 );
end;
FreeAndNil( tf );
rsFields := nil;
sbxInfoSearchResize( Self );
sbxInfoSearch.Visible := True;
Screen.Cursor := crDefault;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -