unit1.pas
来自「进销存数据库基于数据库上开发的源代码 支持SQL嵌入式语言」· PAS 代码 · 共 264 行
PAS
264 行
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Mask, DBCtrls, DB, DBTables, Grids, DBGrids, DBClient,
MConnect, SConnect;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
Query1: TQuery;
DataSource1: TDataSource;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Edit1: TEdit;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
GroupBox1: TGroupBox;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Edit2KeyPress(Sender: TObject; var Key: Char);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.ComboBox1Change(Sender: TObject);
begin
if combobox1.text='销售信息查询' then
with query1 do
begin
close;
sql.clear;
sql.add('select * from xiaoshou');
open;
end;
if combobox1.text='采购信息查询' then
with query1 do
begin
close;
sql.clear;
sql.add('select * from caigou');
open;
end;
if combobox1.text='库存信息查询' then
with query1 do
begin
close;
sql.clear;
sql.add('select * from kucun');
open;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if (combobox1.text='采购信息查询')and(combobox2.text='按编号查询') then
with query1 do
begin
close;
sql.clear;
sql.add('select * from caigou ');
sql.Add('where id=:a');
query1.ParamByName('a').asstring:=edit1.text;
prepare;
open;
if recordcount=0 then
begin
showmessage('没有相应记录');
edit1.setfocus;
end
else
begin
edit2.text:=query1.fieldbyname('id').asstring;
edit3.text:=query1.fieldbyname('name').asstring;
edit4.text:=query1.fieldbyname('number').asstring;
end;
end;
if (combobox1.text='采购信息查询')and(combobox2.text='按名称查询') then
with query1 do
begin
close;
sql.clear;
sql.add('select * from caigou ');
sql.Add('where name=:a');
params[0].asstring:=edit1.text;
prepare;
open;
if recordcount=0 then
begin
showmessage('没有相应记录');
edit1.setfocus;
end
else
begin
edit2.text:=query1.fieldbyname('id').asstring;
edit3.text:=query1.fieldbyname('name').asstring;
edit4.text:=query1.fieldbyname('number').asstring;
end;
end;
if (combobox1.text='销售信息查询')and(combobox2.text='按编号查询') then
with query1 do
begin
close;
sql.clear;
sql.add('select * from xiaoshou ');
sql.Add('where id=:a');
params[0].asstring:=edit1.text;
prepare;
open;
if recordcount=0 then
begin
showmessage('没有相应记录');
edit1.setfocus;
end
else
begin
edit2.text:=query1.fieldbyname('id').asstring;
edit3.text:=query1.fieldbyname('name').asstring;
edit4.text:=query1.fieldbyname('nember').asstring;
edit5.text:=query1.fieldbyname('cangku').asstring;
end;
end;
if (combobox1.text='销售信息查询')and(combobox2.text='按名称查询') then
with query1 do
begin
close;
sql.clear;
sql.add('select * from xiaoshou ');
sql.Add('where name=:a');
params[0].asstring:=edit1.text;
prepare;
open;
if recordcount=0 then
begin
showmessage('没有相应记录');
edit1.setfocus;
end
else
begin
edit2.text:=query1.fieldbyname('id').asstring;
edit3.text:=query1.fieldbyname('name').asstring;
edit4.text:=query1.fieldbyname('nember').asstring;
edit5.text:=query1.fieldbyname('cangku').asstring;
end;
end;
if (combobox1.text='库存信息查询')and(combobox2.text='按编号查询') then
with query1 do
begin
close;
sql.clear;
sql.add('select * from kucun ');
sql.Add('where id=:a');
params[0].asstring:=edit1.text;
prepare;
open;
if recordcount=0 then
begin
showmessage('没有相应记录');
edit1.setfocus;
end
else
begin
edit2.text:=query1.fieldbyname('id').asstring;
edit3.text:=query1.fieldbyname('name').asstring;
edit4.text:=query1.fieldbyname('nember').asstring;
end;
end;
if (combobox1.text='库存信息查询')and(combobox2.text='按名称查询') then
with query1 do
begin
close;
sql.clear;
sql.add('select * from kucun ');
sql.Add('where name=:a');
params[0].asstring:=edit1.text;
prepare;
open;
if recordcount=0 then
begin
showmessage('没有相应记录');
edit1.setfocus;
end
else
begin
edit2.text:=query1.fieldbyname('id').asstring;
edit3.text:=query1.fieldbyname('name').asstring;
edit4.text:=query1.fieldbyname('nember').asstring;
end;
end;
end;
procedure TForm1.Edit2KeyPress(Sender: TObject; var Key: Char);
begin
if ord(key)=13 then
begin
with query1 do
begin
close;
sql.Clear;
sql.add('select * from caigou where id='''+trim(edit1.text)+'''');
open;
end;
if query1.recordcount>0 then
begin
edit2.text:=query1.fieldbyname('id').asstring;
edit3.text:=query1.fieldbyname('name').asstring;
edit4.text:=query1.fieldbyname('nember').asstring;
exit;
end
else
showmessage('没有该用户!');
edit1.SetFocus;
with query1 do
begin
close;
sql.Clear;
sql.add('select * from caigou ');
open;
end;
edit2.Clear;
edit3.Clear;
edit4.Clear;
edit1.Clear;
end;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
if ord(key)=13 then
button1.Click;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?