User Management for an Internet Access Control Application - User Management Module
(Page 2 of 4 )
_html_m45cd9548.png)
The user management module has the following options:
The “add new user” option allows an administrator to add a new staff member to the database. This procedure essentially sends the new staff member's name, username, password and access level to the database. The code below demonstrates how this is achieved:
unit newUser;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, DB, ADODB;
type
TForm6 = class(TForm)
edname: TEdit;
StaticText1: TStaticText;
StaticText2: TStaticText;
StaticText3: TStaticText;
StaticText4: TStaticText;
StaticText5: TStaticText;
cb: TComboBox;
edupass2: TEdit;
edupass: TEdit;
eduname: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ado1: TADOTable;
procedure BitBtn1Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ado1AfterPost(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form6: TForm6;
implementation
uses Logon;
{$R *.dfm}
procedure TForm6.BitBtn1Click(Sender: TObject);
begin
if (edname.Text = '') OR (eduname.Text = '') OR (edupass.Text = '') OR (edupass2.Text = '') OR (edupass.Text <> edupass2.Text) then begin
messagedlg('Please ensure that you fill in all the fields and that the password fields are the same.',mtInformation,[mbOK],0);
exit;
end
else begin
ado1.TableName:='users';
ado1.Active := True;
ado1.Insert;
ado1.FieldByName('name').AsString := edname.Text;
ado1.FieldByName('username').AsString :=eduname.text;
ado1.FieldByName('password').AsString := edupass.text;
ado1.FieldByName('Alevel').AsString :=cb.Text;
ado1.Post;
end;
end;
procedure TForm6.FormShow(Sender: TObject);
begin
form3.q.close;
form3.q.SQL.Text:='SELECT * from Levels';
form3.q.Open;
while not form3.q.Eof do begin
cb.Items.Add(form3.q.fieldbyname('level').AsString);
form3.q.Next;
end;
end;
procedure TForm6.ado1AfterPost(DataSet: TDataSet);
begin
messagedlg(edname.Text + ' has now been created.',mtinformation,[mbOK],0);
end;
end.
_html_m3e2f233d.png)
Next: User Management Module Explained >>
More Delphi-Kylix Articles
More By David Web