📄 consumptioninfo.pas
字号:
unit consumptionInfo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids, DBGrids, ComCtrls, ExtCtrls, DBCtrls, DB,
DBTables;
type
TfrmConsumptionInfo = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
memberId: TEdit;
Label2: TLabel;
memberName: TEdit;
GroupBox2: TGroupBox;
lowTime: TDateTimePicker;
highTime: TDateTimePicker;
Label3: TLabel;
Button1: TButton;
Button2: TButton;
GroupBox7: TGroupBox;
DBGrid1: TDBGrid;
GroupBox4: TGroupBox;
DBNavigator1: TDBNavigator;
GroupBox6: TGroupBox;
asc: TRadioButton;
desc: TRadioButton;
GroupBox5: TGroupBox;
id: TRadioButton;
name: TRadioButton;
money: TRadioButton;
date: TRadioButton;
amount: TRadioButton;
sqlConsumptionInfo: TQuery;
DataSource1: TDataSource;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ascClick(Sender: TObject);
procedure descClick(Sender: TObject);
procedure idClick(Sender: TObject);
procedure nameClick(Sender: TObject);
procedure amountClick(Sender: TObject);
procedure moneyClick(Sender: TObject);
procedure dateClick(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
s:string;
function isInteger(s:string):boolean;
public
{ Public declarations }
end;
var
frmConsumptionInfo: TfrmConsumptionInfo;
implementation
uses dataModule,IdGlobal;
{$R *.dfm}
procedure TfrmConsumptionInfo.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
self.free;
end;
procedure TfrmConsumptionInfo.FormCreate(Sender: TObject);
begin
lowTime.Date:=strToDate('1800-1-1');
highTime.Date:=now;
s:='select 商品编号,商品名称,单价 AS 原价,单位,数量 AS 购买数量,金额 AS 交易金额,日期 AS 消费日期 '+
'from mytransaction AS a, goods As b, member AS c '+
'where a.商品编号=b.商品编号 and a.会员编号=c.会员编号';
with sqlConsumptionInfo do
begin
close;
sql.Clear;
sql.Add(s);
open;
end;
end;
procedure TfrmConsumptionInfo.Button1Click(Sender: TObject);
begin
memberId.Text:='';
memberName.Text:='';
lowTime.Date:=strToDate('1800-1-1');
highTime.Date:=now;
end;
procedure TfrmConsumptionInfo.ascClick(Sender: TObject);
var
col:string;
begin
if id.Checked then col:='商品编号'
else if name.Checked then col:='商品名称'
else if amount.Checked then col:='数量'
else if money.Checked then col:='金额'
else if date.Checked then col:='日期';
with sqlConsumptionInfo do
begin
Close;
SQL.Clear;
SQL.Add(s+' order by '+col+' asc');
try
Open;
except
ExecSQL;
end;
end;
end;
procedure TfrmConsumptionInfo.descClick(Sender: TObject);
var
col:string;
begin
if id.Checked then col:='商品编号'
else if name.Checked then col:='商品名称'
else if amount.Checked then col:='数量'
else if money.Checked then col:='金额'
else if date.Checked then col:='日期';
with sqlConsumptionInfo do
begin
Close;
SQL.Clear;
SQL.Add(s+' order by '+col+' desc');
try
Open;
except
ExecSQL;
end;
end;
end;
procedure TfrmConsumptionInfo.idClick(Sender: TObject);
var
t:string;
begin
if asc.Checked then t:='asc'
else if desc.Checked then t:='desc';
with sqlConsumptionInfo do
begin
Close;
SQL.Clear;
SQL.Add(s+' order by a.商品编号 '+t);
try
Open;
except
ExecSQL;
end;
end;
end;
procedure TfrmConsumptionInfo.nameClick(Sender: TObject);
var
t:string;
begin
if asc.Checked then t:='asc'
else if desc.Checked then t:='desc';
with sqlConsumptionInfo do
begin
Close;
SQL.Clear;
SQL.Add(s+' order by 商品名称 '+t);
try
Open;
except
ExecSQL;
end;
end;
end;
procedure TfrmConsumptionInfo.amountClick(Sender: TObject);
var
t:string;
begin
if asc.Checked then t:='asc'
else if desc.Checked then t:='desc';
with sqlConsumptionInfo do
begin
Close;
SQL.Clear;
SQL.Add(s+' order by 数量 '+t);
try
Open;
except
ExecSQL;
end;
end;
end;
procedure TfrmConsumptionInfo.moneyClick(Sender: TObject);
var
t:string;
begin
if asc.Checked then t:='asc'
else if desc.Checked then t:='desc';
with sqlConsumptionInfo do
begin
Close;
SQL.Clear;
SQL.Add(s+' order by 金额 '+t);
try
Open;
except
ExecSQL;
end;
end;
end;
procedure TfrmConsumptionInfo.dateClick(Sender: TObject);
var
t:string;
begin
if asc.Checked then t:='asc'
else if desc.Checked then t:='desc';
with sqlConsumptionInfo do
begin
Close;
SQL.Clear;
SQL.Add(s+' order by 日期 '+t);
try
Open;
except
ExecSQL;
end;
end;
end;
procedure TfrmConsumptionInfo.Button2Click(Sender: TObject);
var
low,high:string;
begin
s:='select 商品编号,商品名称,单价 AS 原价,单位,数量 AS 购买数量,金额 AS 交易金额,日期 AS 消费日期 '+
'from mytransaction AS a, goods As b, member AS c '+
'where a.商品编号=b.商品编号 and a.会员编号=c.会员编号';
{处理会员编号}
if isInteger(memberId.Text) then
begin
s:=s+' and a.会员编号='+memberId.Text;
end;
{处理会员姓名}
if memberName.Text<>'' then
s:=s+' and c.会员姓名='''+memberName.Text+'''';
{处理消费时间}
low:=formatDateTime('mm''/''dd''/''yyyy',lowTime.Date);
high:=formatDateTime('mm''/''dd''/''yyyy',highTime.Date);
s:=s+' and 日期<'''+high+''' and 日期>'''+low+'''';
{开始查询}
with sqlConsumptionInfo do
begin
close;
sql.Clear;
sql.Add(s);
try
open;
except
execsql;
end;
end;
end;
function TfrmConsumptionInfo.isInteger(s: string): boolean;
var
i:integer;
begin
i:=1;
if length(s)=0 then
begin
result:=false;
exit;
end;
while i<=length(s) do
begin
if (isNumeric(s[i])=false) then
begin
result:=false;
exit;
end;
i:=i+1;
end;
result:=true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -