ManageUsers.pas
上传用户:dh8233980
上传日期:2014-10-16
资源大小:1015k
文件大小:7k
- unit ManageUsers;
- (******************************************************************************)
- (* *)
- (* Hermes Manage Users Dialog Box *)
- (* Part of Hermes SMTP/POP3 Server. *)
- (* Copyright(C) 2000 by Alexander J. Fanti, All Rights Reserver Worldwide. *)
- (* *)
- (* Created January 17, 2000 by Alexander J. Fanti. See License.txt *)
- (* *)
- (* Used by: Main *)
- (* Uses: DataU1, UtilU1, AddEditUser *)
- (* *)
- (* Description: This Modal dialog window allows the user to Add, Edit, Delete *)
- (* and Rename email users *)
- (* *)
- (* Revisions: 1/21/2000 AJF Commented *)
- (* *)
- (******************************************************************************)
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls, Buttons, Menus, FileCtrl;
- type
- TfrmManageUsers = class(TForm)
- lstList: TListBox;
- btnDelete: TBitBtn;
- btnAdd: TBitBtn;
- btnEdit: TBitBtn;
- btnImport: TBitBtn;
- btnClose: TBitBtn;
- btnRename: TBitBtn;
- popupMenu: TPopupMenu;
- puAdd: TMenuItem;
- puEdit: TMenuItem;
- puDelete: TMenuItem;
- puRename: TMenuItem;
- N1: TMenuItem;
- puImport: TMenuItem;
- puExport: TMenuItem;
- btnExport: TBitBtn;
- procedure FormShow(Sender: TObject);
- procedure btnAddClick(Sender: TObject);
- procedure btnEditClick(Sender: TObject);
- procedure btnDeleteClick(Sender: TObject);
- procedure btnImportClick(Sender: TObject);
- procedure btnCloseClick(Sender: TObject);
- procedure lstListClick(Sender: TObject);
- procedure btnRenameClick(Sender: TObject);
- procedure popupMenuPopup(Sender: TObject);
- procedure btnExportClick(Sender: TObject);
- procedure lstListDblClick(Sender: TObject);
- private
- { Private declarations }
- procedure Add; // Add User
- procedure Edit; // Edit User
- procedure Delete; // Delete User
- procedure Rename; // Rename User
- procedure Import; // Import Users
- procedure DoExport; // Export Users
- procedure EnableUI; // Enable buttons and popum menus based on selections
- public
- { Public declarations }
- end;
- var
- frmManageUsers: TfrmManageUsers;
- implementation
- uses DataU1, UtilU1, AddEditUser;
- {$R *.DFM}
- procedure TfrmManageUsers.FormShow(Sender: TObject);
- begin
- // Populate list with users
- INI.User_GetList(lstList.Items);
- // Enable buttons based on list selection
- EnableUI;
- end;
- procedure TfrmManageUsers.Add;
- begin
- // if they added a user through the AddEditUser Dialog...
- // then refresh the user list
- if frmAddEditUser.Add then INI.User_GetList(lstList.Items);
- end;
- procedure TfrmManageUsers.Edit;
- begin
- // if there's a selected user, then let them edit it
- // through the AddEditUser Dialog...
- // then refresh the user list
- if lstList.ItemIndex > -1 then
- if frmAddEditUser.Edit(lstList.Items[lstList.ItemIndex]) then
- INI.User_GetList(lstList.Items);
- end;
- procedure TfrmManageUsers.Delete;
- var
- x : Integer;
- begin
- // Ask if they really want to delete, cause it can't be un-done
- x := MessageDlg('Deleting user(s) cannot be undone. Proceed?',
- mtConfirmation, [mbYes, mbNo], 0);
- if x = mrYes then begin
- // they really want to do it... for each selected user...
- // call the delete function and refresh the user list
- for x := 0 to lstList.Items.Count -1 do
- if lstList.Selected[x] then INI.User_Delete(lstList.Items[x]);
- INI.User_GetList(lstList.Items);
- end;
- end;
- procedure TfrmManageUsers.Rename;
- var
- OldUserID, NewUserID : String;
- begin
- // if there's a user selected...
- if lstList.ItemIndex > -1 then
- OldUserID := lstList.Items[lstList.ItemIndex];
- NewUserID := InputBox('Rename User', 'Enter New User Name', OldUserID);
- if LowerCase(NewUserID) <> LowerCase(OldUserID) then begin
- // and the new user name isn't the same as the old one...
- // then rename the user and refresh the display
- if not INI.User_Rename(OldUserID, NewUserID) then
- ShowMessage('Error: Cound not re-name.' + #13 + #10 +
- 'Users must have a unique ID.')
- else
- INI.User_GetList(lstList.Items);
- end;
- end;
- procedure TfrmManageUsers.Import;
- begin // Import users
- ShowMessage('Feature not implemented yet...');
- // DEBUG
- // How should I import users ?
- end;
- procedure TfrmManageUsers.DoExport;
- begin // Export users
- ShowMessage('Feature not implemented yet...');
- // DEBUG
- // How will I export users ?
- end;
- procedure TfrmManageUsers.EnableUI;
- begin
- // Enable buttons and menus based on list selection
- btnEdit.Enabled := lstList.SelCount = 1;
- btnDelete.Enabled := lstList.SelCount > 0;
- btnRename.Enabled := lstList.SelCount = 1;
- btnExport.Enabled := lstList.Items.Count > 0;
- puEdit.Enabled := lstList.SelCount = 1;
- puDelete.Enabled := lstList.SelCount > 0;
- puRename.Enabled := lstList.SelCount = 1;
- puExport.Enabled := lstList.Items.Count > 0;
- end;
- // Hook Buttond and menus up with functions for performing actions
- procedure TfrmManageUsers.btnAddClick(Sender: TObject);
- begin Add; end;
- procedure TfrmManageUsers.btnEditClick(Sender: TObject);
- begin Edit; end;
- procedure TfrmManageUsers.btnDeleteClick(Sender: TObject);
- begin Delete; end;
- procedure TfrmManageUsers.btnRenameClick(Sender: TObject);
- begin Rename; end;
- procedure TfrmManageUsers.btnImportClick(Sender: TObject);
- begin Import; end;
- procedure TfrmManageUsers.btnExportClick(Sender: TObject);
- begin DoExport; end;
- procedure TfrmManageUsers.lstListClick(Sender: TObject);
- begin EnableUI; end;
- procedure TfrmManageUsers.lstListDblClick(Sender: TObject);
- begin Edit; end;
- procedure TfrmManageUsers.popupMenuPopup(Sender: TObject);
- begin EnableUI; end;
- procedure TfrmManageUsers.btnCloseClick(Sender: TObject);
- begin Close; end;
- end.