【delphi开源代码栏目提醒】:网学会员鉴于大家对delphi开源代码十分关注,论文会员在此为大家搜集整理了“custom.pas”一文,供大家参考学习
unit custom;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB,custinfo_unit, DBClient, Grids, DBGrids;
type
Tcustomfrm = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
CustId_Label: TLabel;
Button5: TButton;
DBGrid1: TDBGrid;
ClientDataSet1: TClientDataSet;
DataSource1: TDataSource;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
custinfo:Tcustinfo;
{ Private declarations }
public
{ Public declarations }
end;
var
customfrm: Tcustomfrm;
implementation
{$R *.dfm}
procedure Tcustomfrm.Button1Click(Sender: TObject);
var
insertsql:string;
begin
//实例化类
custinfo:=Tcustinfo.create ;
//保存时客户编号必须输入
if CustId_Label.Caption='' then
begin
showmessage('客户编号不能为空!');
exit;
end;
//判断输入的客户编号位数是否正确
if length(CustId_Label.Caption)<>3 then
begin
showmessage('对不起,客户编号位数不对!');
exit;
end;
//从客户基本信息表中查看该客户编号是否存在
if custinfo.CustRec(CustId_Label.Caption) then
begin
showmessage('该客户编号已经存在,请核查!');
exit;
end;
//如果不存在则执行插入操作
insertsql:='insert into CUSTINFO(CUSTID,CUSTNAME,'
+'LINKMAN,LINKPHONE,ADDRESS,FAX)values('''+CustId_Label.Caption+''','
+''''+EDIT2.Text+''','''+EDIT3.Text+''','''+EDIT4.Text+''','
+''''+EDIT5.Text+''','''+EDIT6.Text+''')';
custinfo.CustInfoInsert(insertsql);
showmessage('添加成功!');
//释放实例
custinfo.Free;
end;
procedure Tcustomfrm.Button2Click(Sender: TObject);
begin
//实例化类
custinfo:=Tcustinfo.create ;
if application.MessageBox('要删除吗?','警告:',mb_yesno+mb_iconquestion)=idyes then
begin
//删除时根据客户编号来进行,所以不能为空
if CustId_Label.Caption='' then
begin
showmessage('请输入要删除记录客户编号!');
exit;
end;
//判断客户编号位数是否正确
if length(CustId_Label.Caption)<>3 then
begin
showmessage('对不起,客户编号位数不对!');
exit;
end;
//删除前先通过类中方法查看该记录信息是否存在
if custinfo.CustRec(CustId_Label.Caption) then
begin
showmessage('该客户编号不存在,请核查!');
exit;
end;
//若存在则执行类中删除操作过程
custinfo.CustInfoDel(CustId_Label.Caption);
//清除掉文本框中原有的数据信息
CustId_Label.Caption:=''; EDIT2.Text:='';EDIT3.Text:='';
EDIT4.Text:='';EDIT5.Text:='';EDIT6.Text:='';
showmessage('删除成功!');
end;
custinfo.Free;
end;
procedure Tcustomfrm.Button3Click(Sender: TObject);
begin
//实例化类
custinfo:=Tcustinfo.create ;
//查询时根据客户编号来进行,所以不能为空
if CustId_Label.Caption='' then
begin
showmessage('请输入要查询记录客户编号!');
exit;
end;
//判断客户编号位数是否正确
if length(CustId_Label.Caption)<>3 then
begin
showmessage('对不起,客户编号位数不对!');
exit;
end;
//查询前先看该记录信息是否存在
if custinfo.CustRec(CustId_Label.Caption)=false then
begin
showmessage('该客户编号不存在,请核查!');
exit;
end;
//如果查询到记录信息则进取出相应的值
EDIT2.Text:=custinfo.GetCustName(CustId_Label.Caption);
EDIT3.Text:=custinfo.GetLinkMan (CustId_Label.Caption );
EDIT4.Text:=custinfo.GetLinkPhone (CustId_Label.Caption);
EDIT5.Text:=custinfo.GetAddress (CustId_Label.Caption);
EDIT6.Text:=custinfo.GetFax (CustId_Label.Caption);
//释放实例
custinfo.Free;
end;
procedure Tcustomfrm.Button4Click(Sender: TObject);
var
modsql:string;
begin
//实例化类
custinfo:=Tcustinfo.create ;
if application.MessageBox('要修改吗?','提示:',mb_yesno+mb_iconquestion)=idyes then
begin
//修改时必须知道记录的客户编号,所以不能为空
if CustId_Label.Caption='' then
begin
showmessage('请输入要修改记录的客户编号,查询到相应记录后修改!');
exit;
end;
//判断客户编号位数是否正确
if length(CustId_Label.Caption)<>3 then
begin
showmessage('对不起,客户编号位数不对!');
exit;
end;
//查看该客户编号是否已经存在,若不存在则不能执行修改操作
if custinfo.CustRec(CustId_Label.Caption) then
begin
showmessage('该客户编号不存在,请核查!');
exit;
end;
//执行修改操作
modsql:='update CUSTINFO set CUSTNAME='''+EDIT2.Text+''', '
+'LINKMAN='''+EDIT3.Text+''',LINKPHONE='''+EDIT4.Text+''',ADDRESS='''+EDIT5.Text+''','
+'FAX='''+EDIT6.Text+''' where CUSTID='''+CustId_Label.Caption+'''';
custinfo.CustInfoUpdate(modsql);
showmessage('修改成功!');
end;
//释放实例
custinfo.Free;
END;
end.
上一篇:
custlist_unit.pas
下一篇:
白色姜花,略微开了