uclient.~pas
来自「DELPHI编程入门篇.从基础入手,浅显易懂,一定物有所值.」· ~PAS 代码 · 共 166 行
~PAS
166 行
unit Uclient;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Buttons, StdCtrls, ExtCtrls, Grids, ImgList, ComCtrls, ToolWin,
DB, ADODB;
type
Tfrmclient = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
StringGrid1: TStringGrid;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
MenuImges: TImageList;
ADOQuery1: TADOQuery;
procedure ToolButton3Click(Sender: TObject);
procedure ToolButton2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ToolButton7Click(Sender: TObject);
procedure ToolButton6Click(Sender: TObject);
procedure ToolButton1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmclient: Tfrmclient;
implementation
uses Uclientmod, Udatamodule;
{$R *.dfm}
procedure Tfrmclient.ToolButton3Click(Sender: TObject);
begin
Application.CreateForm(Tfrmclientmod, frmclientmod);
frmclientmod.ShowModal;
frmclientmod.Release;
end;
procedure Tfrmclient.ToolButton2Click(Sender: TObject);
begin
Application.CreateForm(Tfrmclientmod, frmclientmod);
if stringgrid1.Row > 0 then
begin
frmclientmod.Edit1.Enabled:=false;
frmclientmod.Edit1.Text:=stringgrid1.Cells[0,stringgrid1.Row];
frmclientmod.Edit2.Text:=stringgrid1.Cells[1,stringgrid1.Row];
frmclientmod.Edit3.Text:=stringgrid1.Cells[2,stringgrid1.Row];
frmclientmod.Edit4.Text:=stringgrid1.Cells[3,stringgrid1.Row];
frmclientmod.Edit5.Text:=stringgrid1.Cells[4,stringgrid1.Row];
frmclientmod.Edit6.Text:=stringgrid1.Cells[5,stringgrid1.Row];
frmclientmod.Edit7.Text:=stringgrid1.Cells[6,stringgrid1.Row];
frmclientmod.Edit8.Text:=stringgrid1.Cells[7,stringgrid1.Row];
frmclientmod.Edit9.Text:=stringgrid1.Cells[8,stringgrid1.Row];
end;
frmclientmod.ShowModal;
frmclientmod.Release;
end;
procedure Tfrmclient.FormCreate(Sender: TObject);
var
arow,acol:integer;
begin
stringgrid1.Cells[0,0]:='客户编号';
stringgrid1.Cells[1,0]:='客户名称';
stringgrid1.Cells[2,0]:='地址';
stringgrid1.Cells[3,0]:='联系人';
stringgrid1.Cells[4,0]:='电话';
stringgrid1.Cells[5,0]:='开户行';
stringgrid1.Cells[6,0]:='帐号';
stringgrid1.Cells[7,0]:='税号';
stringgrid1.Cells[8,0]:='说明';
adoquery1.SQL.Text:='select clientid,clientname,address,linkman,clienttel,opbanck,accounts,taxation,explain from clients';
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
stringgrid1.RowCount:=adoquery1.RecordCount+1;
arow:=1;
while not adoquery1.Eof do
begin
for acol:=0 to stringgrid1.ColCount-1 do
stringgrid1.Cells[acol,arow]:=adoquery1.Fields[acol].AsString;
adoquery1.Next;
inc(arow);
end;
end;
adoquery1.Close;
end;
procedure Tfrmclient.ToolButton7Click(Sender: TObject);
begin
self.close;
end;
procedure Tfrmclient.ToolButton6Click(Sender: TObject);
var
i:integer;
begin
if ((stringgrid1.Row > 0) and (stringgrid1.Cells[0,stringgrid1.Row] <> '')) then
begin
if messagedlg('真的要删除吗?',mtconfirmation,[mbyes,mbno],0) = mryes then
begin
adoquery1.SQL.Text:='delete from clients where clientid = '''+stringgrid1.Cells[0,stringgrid1.Row]+'''';
showmessage(adoquery1.SQL.Text);
adoquery1.ExecSQL;
adoquery1.Close;
if stringgrid1.RowCount > 2 then
begin
for i:=stringgrid1.Row to stringgrid1.RowCount-2 do
stringgrid1.Rows[i]:=stringgrid1.Rows[i+1];
stringgrid1.Rows[stringgrid1.RowCount-1].Clear;
stringgrid1.RowCount:=stringgrid1.RowCount-1;
end
else
stringgrid1.Rows[1].Clear;
end;
end;
end;
procedure Tfrmclient.ToolButton1Click(Sender: TObject);
var
i,arow:integer;
sclientid:string;
begin
for i:=1 to stringgrid1.RowCount - 1 do
stringgrid1.Rows[i].Clear;
stringgrid1.RowCount:=2;
sclientid:=edit1.Text;
while length(sclientid) < 5 do sclientid:='0'+sclientid;
adoquery1.SQL.Text:='select * from clients where 1=1';
if edit1.Text <> '' then
adoquery1.SQL.Add('and clientid = '''+sclientid+'''');
if edit2.Text <> '' then
adoquery1.SQL.Add('and clientname = '''+edit2.Text+'''');
adoquery1.Open;
if adoquery1.RecordCount > 0 then
begin
stringgrid1.RowCount:=adoquery1.RecordCount+1;
arow:=1;
while not adoquery1.Eof do
begin
for i:=0 to stringgrid1.ColCount - 1 do
stringgrid1.Cells[i,arow]:=adoquery1.Fields[i].AsString;
adoquery1.Next;
inc(arow);
end;
end;
adoquery1.Close;
end;
end.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?