uchobook.pas
来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· PAS 代码 · 共 149 行
PAS
149 行
unit Uchobook;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Grids, StdCtrls;
type
Tfrmchobook = class(TForm)
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
ADOQuery1: TADOQuery;
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmchobook: Tfrmchobook;
implementation
uses Udatamodule, Ustockin;
{$R *.dfm}
procedure Tfrmchobook.FormCreate(Sender: TObject);
var
i,j:integer;
begin
stringgrid1.Cells[1,0]:='订单编号';
stringgrid1.Cells[2,0]:='供应商';
stringgrid1.Cells[3,0]:='订货日期';
stringgrid1.Cells[4,0]:='到货日期';
stringgrid1.Cells[5,0]:='经手人';
stringgrid2.Cells[1,0]:='商品编号';
stringgrid2.Cells[2,0]:='商品名称';
stringgrid2.Cells[3,0]:='订购数量';
adoquery1.SQL.Text:='select bookid,provid,bookdate,reachdate,handleman from'
+' stockbook where ifdeal = false';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
i:=1;
stringgrid1.RowCount:=adoquery1.RecordCount+1;
while not adoquery1.Eof do
begin
for j:=1 to stringgrid1.ColCount-1 do
stringgrid1.Cells[j,i]:=adoquery1.Fields[j-1].AsString;
inc(i);
adoquery1.Next;
end;
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,1]:='*';
end;
adoquery1.Close;
if stringgrid1.Cells[1,1] <> '' then
begin
adoquery1.SQL.Text:='select stockbook1.prid ,pluinfo.prname,stockbook1.booknum'+
' from stockbook1 inner join pluinfo on stockbook1.prid = pluinfo.prid'+
' where stockbook1.bookid = '''+stringgrid1.Cells[1,1]+'''';
adoquery1.Open;
stringgrid2.RowCount:=adoquery1.RecordCount+1;
i:=1;
while not adoquery1.Eof do
begin
stringgrid2.Cells[1,i]:=adoquery1.Fields[0].AsString;
stringgrid2.Cells[2,i]:=adoquery1.Fields[1].AsString;
stringgrid2.Cells[3,i]:=adoquery1.Fields[2].AsString;
inc(i);
adoquery1.Next;
end;
adoquery1.Close;
end;
end;
procedure Tfrmchobook.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
var
i:integer;
begin
if stringgrid1.Cells[1,arow] <> '' then
begin
stringgrid1.Cols[0].Clear;
stringgrid1.Cells[0,arow]:='*';
for i:=1 to stringgrid2.RowCount-1 do
stringgrid2.Rows[i].Clear;
stringgrid2.RowCount:=2;
adoquery1.SQL.Text:='select stockbook1.prid ,pluinfo.prname,stockbook1.booknum'+
' from stockbook1 inner join pluinfo on stockbook1.prid = pluinfo.prid'+
' where stockbook1.bookid = '''+stringgrid1.Cells[1,arow]+'''';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
stringgrid2.RowCount:=adoquery1.RecordCount+1;
i:=1;
while not adoquery1.Eof do
begin
stringgrid2.Cells[1,i]:=adoquery1.Fields[0].AsString;
stringgrid2.Cells[2,i]:=adoquery1.Fields[1].AsString;
stringgrid2.Cells[3,i]:=adoquery1.Fields[2].AsString;
inc(i);
adoquery1.Next;
end;
adoquery1.Close;
end;
end;
end;
procedure Tfrmchobook.Button2Click(Sender: TObject);
begin
self.Close;
end;
procedure Tfrmchobook.Button1Click(Sender: TObject);
var
i,oldrowcount:integer;
begin
with frmstockin do
begin
for i:= 0 to combobox2.Items.Count-1 do
begin
if copy(combobox2.Items.Strings[i],1,5) = self.StringGrid1.Cells[2,self.StringGrid1.Row] then
combobox2.ItemIndex:=i;
break;
end;
stringgrid2.RowCount:=self.StringGrid2.RowCount;
for i:=1 to self.StringGrid2.RowCount-1 do
begin
stringgrid2.Cells[1,i]:=self.StringGrid2.Cells[1,i];
stringgrid2.Cells[2,i]:=self.StringGrid2.Cells[2,i];
stringgrid2.Cells[3,i]:=self.StringGrid2.Cells[3,i];
end;
speedbutton8.Enabled:=false;
end;
self.Close;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?