📄 morestorequery.pas
字号:
unit morestorequery;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, losestorequery, DB, Grids, DBGrids, ComCtrls, StdCtrls, Buttons,
ExtCtrls;
type
Tf_morestorequery = class(Tf_losestorequery)
procedure QueryClick(Sender: TObject); override;
private
{ Private declarations }
public
{ Public declarations }
end;
var
f_morestorequery: Tf_morestorequery;
implementation
uses data;
{$R *.dfm}
//处理查询按钮单击事件
procedure Tf_morestorequery.QueryClick(Sender: TObject);
begin
if (Storagecon.Checked = True) or( Date.Checked = True) then //判断设置的查询条件
begin
if (Storagecon.Checked = True )and (Date.Checked = False)then //只按字段查询
begin
if(Trim(StorageField.Text)<>'')and(Trim(StorageValue.Text)<>'') then
begin
With t_data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from v_morestorequery where ');
case Storagefield.ItemIndex of
0: SQL.Add('storename = :Value');
1: SQL.Add('principal = :Value');
2: SQL.Add('operator = :Value');
3: SQL.Add('moreid = :Value');
end;
Parameters.ParamByName('Value').Value := Trim(Storagevalue.Text);
Open;
end;
if t_data.Query2.RecordCount>0 then
begin
With t_data.Query3 do //汇总物资数量
begin
Close;
SQL.Clear;
SQL.Add('Select sum(num) as storesum , storename from v_morestorequery where ');
case Storagefield.ItemIndex of
0: SQL.Add('storename = :Value');
1: SQL.Add('principal = :Value');
2: SQL.Add('operator = :Value');
3: SQL.Add('moreid = :Value');
end;
SQL.Add(' Group by storename');
Parameters.ParamByName('Value').Value := Trim(Storagevalue.Text);
Open;
end;
Source1.DataSet := t_data.Query2;
Source2.DataSet := t_data.Query3;
end
else
begin
Application.MessageBox('没有找到符合条件的记录.','提示',64);
Source1.DataSet := Nil;
Source2.DataSet := Nil;
end;
end;
end
else if (Storagecon.Checked = False )and (Date.Checked = True)then //只按时间查询
begin
With t_data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from v_morestorequery where');
SQL.Add(' TimeDate >= :FromDate and Timedate < :ToDate');
Parameters.ParamByName('FromDate').Value := Trunc(FromDate.DateTime);
Parameters.ParamByName('ToDate').Value := Trunc(ToDate.DateTime)+1;
Open;
end;
if t_data.Query2.RecordCount>0 then
begin
With t_data.Query3 do //汇总物资数量
begin
Close;
SQL.Clear;
SQL.Add('Select sum(num) as storesum ,storename from v_morestorequery where ');
SQL.Add(' TimeDate >= :FromDate and Timedate < :ToDate');
SQL.Add(' Group by storename');
Parameters.ParamByName('FromDate').Value := Trunc(FromDate.DateTime);
Parameters.ParamByName('ToDate').Value := Trunc(ToDate.DateTime)+1;
Open;
end;
Source1.DataSet := t_data.Query2;
Source2.DataSet := t_data.Query3;
end
else
begin
Application.MessageBox('没有找到符合条件的记录.','提示',64);
Source1.DataSet := Nil;
Source2.DataSet := Nil;
end;
end
else //即按字段又按时间查询
begin
if(Trim(StorageField.Text)<>'')and(Trim(StorageValue.Text)<>'') then
begin
With t_data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from v_morestorequery where ');
case Storagefield.ItemIndex of
0: SQL.Add('storename = :Value');
1: SQL.Add('principal = :Value');
2: SQL.Add('operator = :Value');
3: SQL.Add('moreid = :Value');
end;
SQL.Add(' and TimeDate >= :FromDate and Timedate < :ToDate');
Parameters.ParamByName('FromDate').Value := Trunc(Fromdate.DateTime);
Parameters.ParamByName('ToDate').Value := Trunc(ToDate.DateTime)+1;
Parameters.ParamByName('Value').Size := 100;
Parameters.ParamByName('Value').Value := Trim(Storagevalue.Text);
Open;
end;
if t_data.Query2.RecordCount>0 then
begin
With t_data.Query3 do //汇总总数量
begin
Close;
SQL.Clear;
SQL.Add('Select sum(num) as storesum ,storename from v_morestorequery where ');
case Storagefield.ItemIndex of
0: SQL.Add('storename = :Value');
1: SQL.Add('principal = :Value');
2: SQL.Add('operator = :Value');
3: SQL.Add('moreid = :Value');
end;
SQL.Add(' and TimeDate >= :FromDate and Timedate < :ToDate ');
SQL.Add(' Group by storename');
Parameters.ParamByName('Value').Size := 100;
Parameters.ParamByName('Value').Value := Trim(Storagevalue.Text);
Parameters.ParamByName('FromDate').Value := Trunc(FromDate.DateTime);
Parameters.ParamByName('ToDate').Value := Trunc(ToDate.DateTime)+1;
Open;
end;
Source1.DataSet := t_data.Query2;
Source2.DataSet := t_data.Query3;
end
else
begin
Application.MessageBox('没有找到符合条件的记录.','提示',64);
Source1.DataSet := Nil;
Source2.DataSet := Nil;
end;
end;
end;
end
else
Application.MessageBox('请设置查询条件.','提示',64);
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -