uprstorage.pas
来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· PAS 代码 · 共 182 行
PAS
182 行
unit Uprstorage;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, Grids, StdCtrls, ExtCtrls, DB, ADODB, RpCon, RpConDS,
RpDefine, RpRave, RpBase, RpSystem,RvCsRpt,RVProj,RVClass,RVCsStd;
type
Tfrmprstorage = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
StringGrid1: TStringGrid;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
ADOQuery1: TADOQuery;
RvProject1: TRvProject;
storageConnection1: TRvDataSetConnection;
procedure FormCreate(Sender: TObject);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmprstorage: Tfrmprstorage;
sqlstr:string;
implementation
uses Udatamodule;
{$R *.dfm}
procedure Tfrmprstorage.FormCreate(Sender: TObject);
begin
stringgrid1.Cells[0,0]:=' 商品编号';
stringgrid1.Cells[1,0]:=' 商品名称';
stringgrid1.Cells[2,0]:=' 条 码';
stringgrid1.Cells[3,0]:=' 库存数量';
stringgrid1.Cells[4,0]:=' 单 价';
adoquery1.SQL.Text:='select filname from filiale';
adoquery1.Open;
while not adoquery1.Eof do
begin
combobox1.Items.Add(adoquery1.Fieldbyname('filname').AsString);
adoquery1.Next;
end;
adoquery1.Close;
adoquery1.SQL.text:='select classname from classinfo';
adoquery1.Open;
while not adoquery1.eof do
begin
combobox2.Items.Add(adoquery1.Fields[0].asstring);
adoquery1.Next;
end;
adoquery1.Close;
end;
procedure Tfrmprstorage.SpeedButton1Click(Sender: TObject);
var
sfiliale,skind:string;
i,arow:integer;
begin
for i:=1 to stringgrid1.RowCount-1 do
stringgrid1.Rows[i].Clear;
stringgrid1.RowCount:=2;
if combobox1.Text <> '全部分店' then
begin
adoquery1.SQL.Text:='select filid from filiale where filname = '''+combobox1.Text+'''';
adoquery1.Open;
sfiliale:=adoquery1.fieldbyname('filid').AsString;
adoquery1.Close;
end;
if combobox2.Text <> '全部部类' then
begin
adoquery1.SQL.Text:='select classid from classinfo where classname = '''+combobox2.Text+'''';
adoquery1.Open;
skind:=adoquery1.fieldbyname('classid').AsString;
adoquery1.Close;
end;
adoquery1.SQL.Text:='select busary.prid,busary.busanum,pluinfo.prname,'
+'pluinfo.plu,pluinfo.prrate from busary inner join pluinfo on busary.prid'
+' = pluinfo.prid where 1=1';
if combobox1.Text <> '全部分店' then
adoquery1.SQL.Add(' and filid = '''+sfiliale+'''');
if combobox2.Text <> '全部部类' then
adoquery1.SQL.Add(' and pluinfo.classid = '''+skind+'''');
if edit1.Text <> '' then
adoquery1.SQL.Add(' and busary.prid = '''+edit1.Text+'''');
if edit2.Text <> '' then
adoquery1.SQL.Add('and prname = '''+edit2.Text+'''');
adoquery1.SQL.Add('order by busary.prid');
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
sqlstr:=adoquery1.SQL.Text;
while not adoquery1.Eof do
begin
if stringgrid1.Cells[0,stringgrid1.RowCount-1] <> '' then
stringgrid1.RowCount:=stringgrid1.RowCount+1;
arow:=stringgrid1.RowCount-1;
stringgrid1.Cells[0,arow]:=adoquery1.Fields[0].AsString;
stringgrid1.Cells[1,arow]:=adoquery1.Fields[2].AsString;
stringgrid1.Cells[2,arow]:=adoquery1.Fields[3].AsString;
stringgrid1.Cells[3,arow]:=adoquery1.Fields[1].AsString;
stringgrid1.Cells[4,arow]:=adoquery1.Fields[4].AsString;
adoquery1.Next;
while ((adoquery1.FieldValues['prid'] = stringgrid1.Cells[0,arow]) and (not adoquery1.Eof)) do
begin
stringgrid1.Cells[3,arow]:=strtocurr(stringgrid1.Cells[3,arow])+adoquery1.FieldValues['busanum'];
adoquery1.Next;
end;
end;
end;
end;
procedure Tfrmprstorage.SpeedButton3Click(Sender: TObject);
begin
close;
end;
procedure Tfrmprstorage.SpeedButton2Click(Sender: TObject);
var
mypage:travepage;
mytext:travetext;
i:integer;
begin
rvproject1.Open;
with rvproject1.ProjMan do
begin
mypage:=findravecomponent('Report1.Page1',nil) as TRavePage;
mytext:=findravecomponent('text9',mypage) as travetext;
mytext.Text:=combobox1.Text;
mytext:=findravecomponent('text10',mypage) as travetext;
mytext.Text:=combobox2.Text;
end;
if stringgrid1.Cells[0,1] <> '' then
begin
adoquery1.SQL.Text:='create table prstore (prid char(7) not null unique,'+
'prname char(20),plu char(13),storenum float,wareprice float)';
adoquery1.ExecSQL;
adoquery1.Close;
for i:=1 to stringgrid1.RowCount-1 do
begin
adoquery1.SQL.Text:='insert into prstore values('''+stringgrid1.Cells[0,i]
+''','''+stringgrid1.Cells[1,i]+''','''+stringgrid1.Cells[2,i]+''','
+stringgrid1.Cells[3,i]+','+stringgrid1.Cells[4,i]+')';
adoquery1.ExecSQL;
adoquery1.Close;
end;
adoquery1.SQL.Text:='select * from prstore';
adoquery1.Open;
try
rvproject1.Execute;
finally
rvproject1.Close;
adoquery1.Close;
adoquery1.SQL.Text:='drop table prstore';
adoquery1.ExecSQL;
adoquery1.Close;
end;
end
else
showmessage('请先查询要打印的数据');
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?