📄 uquery.~pas
字号:
unit uquery;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls, StdCtrls, Buttons,DBTables;
type
Tuqueryfrm = class(TForm)
GroupBox1: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
RadioButton4: TRadioButton;
RadioButton5: TRadioButton;
CheckBox1: TCheckBox;
Label1: TLabel;
Edit1: TEdit;
BitBtn1: TBitBtn;
ListView1: TListView;
Label2: TLabel;
BitBtn2: TBitBtn;
BitBtn4: TBitBtn;
Bevel1: TBevel;
ComboBox1: TComboBox;
Memo1: TMemo;
Sdialog: TSaveDialog;
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure RadioButton4Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
procedure is_check; //检查是否选择了“按图书类别”查询
procedure setbooksql(var q:Tquery);//设置SQL语句
procedure setbookparam(var q:Tquery;param:string);//设置参数化查询的参数
procedure bookquery;//查询过程
{ Private declarations }
public
{ Public declarations }
end;
var
uqueryfrm: Tuqueryfrm;
implementation
uses main,global;
{$R *.dfm}
procedure Tuqueryfrm.is_check ;
begin
if radiobutton5.Checked then
begin
combobox1.Left :=edit1.Left ;
combobox1.Top :=edit1.Top ;
combobox1.Width :=edit1.Width ;
combobox1.Height :=edit1.Height ;
combobox1.Visible :=true;
edit1.Visible :=false;
end
else
if edit1.Visible=false then
begin
edit1.Left :=combobox1.Left ;
edit1.Top :=combobox1.Top ;
edit1.Width :=combobox1.Width ;
edit1.Height :=combobox1.Height ;
edit1.Visible :=true;
combobox1.Visible :=false;
end;
end;
procedure Tuqueryfrm.setbookparam(var q:Tquery;param:string);
begin
if checkbox1.Checked then param:=param+'%';
if radiobutton1.Checked then
q.ParamByName('b_no').AsString :=param;
if radiobutton2.Checked then
q.ParamByName('b_name').AsString :=param;
if radiobutton3.Checked then
q.ParamByName('b_author').AsString :=param;
if radiobutton4.Checked then
q.ParamByName('b_publisher').AsString :=param;
if radiobutton5.Checked then
q.ParamByName('b_type').AsString :=param;
end;
procedure Tuqueryfrm.setbooksql(var q:Tquery);
begin
q.SQL.Clear ;
if radiobutton1.Checked then
q.SQL.Add('select * from book_info where 图书编号 like :b_no');
if radiobutton2.Checked then
q.SQL.Add('select * from book_info where 书名 like :b_name');
if radiobutton3.Checked then
q.SQL.Add('select * from book_info where 作者 like :b_author');
if radiobutton4.Checked then
q.SQL.Add('select * from book_info where 出版社 like :b_publisher');
if radiobutton5.Checked then
q.SQL.Add('select * from book_info where 类别 like :b_type');
end;
procedure Tuqueryfrm.bookquery ;
var q:Tquery;
begin
ListView1.Items.Clear;
q := TQuery.Create(nil);
q.DatabaseName :=DBName;
SetBookSQL(q);
if radiobutton5.Checked then setbookparam(q,combobox1.Items[combobox1.itemindex])
else SetBookParam(q,edit1.Text);
q.Open;
while not q.Eof do
begin
with ListView1.Items.Add do
begin
Caption := q.FieldByName('图书编号').AsString;
SubItems.Add(q.FieldByName('书名').AsString);
SubItems.Add(q.FieldByName('作者').AsString);
SubItems.Add(q.FieldByName('出版社').AsString);
SubItems.Add(q.FieldByName('出版时间').AsString);
SubItems.Add(q.FieldByName('书价').AsString);
subitems.Add(q.fieldbyname('借阅次数').AsString);
if isborrowed(caption) then subitems.Add('是') else subitems.Add('否');
end;
q.Next;
end;
label2.Caption:= '共'+IntToStr(q.RecordCount)+'本';
q.Close;
q.Free;
end;
procedure Tuqueryfrm.BitBtn4Click(Sender: TObject);
begin
close;
end;
procedure Tuqueryfrm.BitBtn1Click(Sender: TObject);
begin
try
Bookquery;
except
MessageDlg('查询失败',mtError,[mbok],0);
end;
end;
procedure Tuqueryfrm.FormShow(Sender: TObject);
begin
listview1.Items.Clear ;
label2.Caption :='共0本';
if edit1.Visible then
begin
edit1.Clear ;
edit1.SetFocus ;
end;
end;
procedure Tuqueryfrm.RadioButton4Click(Sender: TObject);
begin
is_check;
end;
procedure Tuqueryfrm.BitBtn2Click(Sender: TObject);
var i,j:integer;
begin
if sdialog.Execute then
begin
memo1.Lines.Clear ;
for i:=0 to listview1.Items.Count-1 do
with memo1.Lines do
begin
add(listview1.Columns[0].Caption +':'+listview1.Items[i].Caption);
for j:=0 to listview1.Columns.Count-2 do
add(listview1.Columns[j+1].Caption+':'+listview1.Items[i].SubItems.Strings[j]);
add('----------------------');
end;
memo1.Lines.SaveToFile(sdialog.FileName);
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -