用户注册窗口制作
效果:
源码:
unit URegister; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons,Data.Win.ADODB; type TFRegister = class(TForm) lbl1: TLabel; lbl2: TLabel; edtAdmid2: TEdit; edtAdmps2: TEdit; btn1: TBitBtn; btn2: TBitBtn; procedure btn1Click(Sender: TObject); procedure FormShow(Sender: TObject); private { Private declarations } public { Public declarations } end; var FRegister: TFRegister; implementation {$R *.dfm} uses FDataPool, 日常管理助手; procedure TFRegister.btn1Click(Sender: TObject); var Asql:string; MyAdoq:TADOQuery; begin MyAdoq:=TADOQuery.Create(nil); MyAdoq.Connection:= frmDataPool.ADOConnection1; with MyAdoq do begin Close; SQL.Clear; sql.Add('select * from 用户账号表 where admid = :admid'); Parameters.ParamByName('admid').Value:= edtAdmid2.Text;//为admid参数赋值 Open; end; if MyAdoq.isempty then with MyAdoq do begin Close; sql.Clear; SQL.Text:= 'insert into 用户账号表(admid,admps) values ('''+edtAdmid2.Text+''','''+edtAdmps2.Text+''')'; ExecSQL; //插入一条注册账号记录 if MessageDlg('注册成功!是否关闭窗口?',mtConfirmation,[mbYes,mbno],0)=mrYes then Self.Close; end else begin FRegister.ModalResult:=0; ShowMessage('该账号已存在,不能再注册'); Exit; end; MyAdoq.Free; end; procedure TFRegister.FormShow(Sender: TObject); begin edtAdmid2.Clear;//预清 edtAdmps2.Clear;//预清 end; end.