ManageUsers.pas
上传用户:dh8233980
上传日期:2014-10-16
资源大小:1015k
文件大小:7k
源码类别:

Email服务器

开发平台:

Delphi

  1. unit ManageUsers;
  2. (******************************************************************************)
  3. (*                                                                            *)
  4. (* Hermes Manage Users Dialog Box                                             *)
  5. (* Part of Hermes SMTP/POP3 Server.                                           *)
  6. (* Copyright(C) 2000 by Alexander J. Fanti, All Rights Reserver Worldwide.    *)
  7. (*                                                                            *)
  8. (* Created January 17, 2000 by Alexander J. Fanti.  See License.txt           *)
  9. (*                                                                            *)
  10. (* Used by: Main                                                              *)
  11. (* Uses: DataU1, UtilU1, AddEditUser                                          *)
  12. (*                                                                            *)
  13. (* Description: This Modal dialog window allows the user to Add, Edit, Delete *)
  14. (*              and Rename email users                                        *)
  15. (*                                                                            *)
  16. (* Revisions: 1/21/2000  AJF  Commented                                       *)
  17. (*                                                                            *)
  18. (******************************************************************************)
  19. interface
  20. uses
  21.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  22.   StdCtrls, Buttons, Menus, FileCtrl;
  23. type
  24.   TfrmManageUsers = class(TForm)
  25.     lstList: TListBox;
  26.     btnDelete: TBitBtn;
  27.     btnAdd: TBitBtn;
  28.     btnEdit: TBitBtn;
  29.     btnImport: TBitBtn;
  30.     btnClose: TBitBtn;
  31.     btnRename: TBitBtn;
  32.     popupMenu: TPopupMenu;
  33.     puAdd: TMenuItem;
  34.     puEdit: TMenuItem;
  35.     puDelete: TMenuItem;
  36.     puRename: TMenuItem;
  37.     N1: TMenuItem;
  38.     puImport: TMenuItem;
  39.     puExport: TMenuItem;
  40.     btnExport: TBitBtn;
  41.     procedure FormShow(Sender: TObject);
  42.     procedure btnAddClick(Sender: TObject);
  43.     procedure btnEditClick(Sender: TObject);
  44.     procedure btnDeleteClick(Sender: TObject);
  45.     procedure btnImportClick(Sender: TObject);
  46.     procedure btnCloseClick(Sender: TObject);
  47.     procedure lstListClick(Sender: TObject);
  48.     procedure btnRenameClick(Sender: TObject);
  49.     procedure popupMenuPopup(Sender: TObject);
  50.     procedure btnExportClick(Sender: TObject);
  51.     procedure lstListDblClick(Sender: TObject);
  52.   private
  53.     { Private declarations }
  54.     procedure Add;      // Add User
  55.     procedure Edit;     // Edit User
  56.     procedure Delete;   // Delete User
  57.     procedure Rename;   // Rename User
  58.     procedure Import;   // Import Users
  59.     procedure DoExport; // Export Users
  60.     procedure EnableUI; // Enable buttons and popum menus based on selections
  61.   public
  62.     { Public declarations }
  63.   end;
  64. var
  65.   frmManageUsers: TfrmManageUsers;
  66. implementation
  67. uses DataU1, UtilU1, AddEditUser;
  68. {$R *.DFM}
  69. procedure TfrmManageUsers.FormShow(Sender: TObject);
  70. begin
  71.   // Populate list with users
  72.   INI.User_GetList(lstList.Items);
  73.   // Enable buttons based on list selection
  74.   EnableUI;
  75. end;
  76. procedure TfrmManageUsers.Add;
  77. begin
  78.   // if they added a user through the AddEditUser Dialog...
  79.   // then refresh the user list
  80.   if frmAddEditUser.Add then INI.User_GetList(lstList.Items);
  81. end;
  82. procedure TfrmManageUsers.Edit;
  83. begin
  84.   // if there's a selected user, then let them edit it
  85.   // through the AddEditUser Dialog...
  86.   // then refresh the user list
  87.   if lstList.ItemIndex > -1 then
  88.     if frmAddEditUser.Edit(lstList.Items[lstList.ItemIndex]) then
  89.       INI.User_GetList(lstList.Items);
  90. end;
  91. procedure TfrmManageUsers.Delete;
  92. var
  93.   x : Integer;
  94. begin
  95.   // Ask if they really want to delete, cause it can't be un-done
  96.   x := MessageDlg('Deleting user(s) cannot be undone.  Proceed?',
  97.                   mtConfirmation, [mbYes, mbNo], 0);
  98.   if x = mrYes then begin
  99.     // they really want to do it... for each selected user...
  100.     // call the delete function and refresh the user list
  101.     for x := 0 to lstList.Items.Count -1 do
  102.       if lstList.Selected[x] then INI.User_Delete(lstList.Items[x]);
  103.     INI.User_GetList(lstList.Items);
  104.   end;
  105. end;
  106. procedure TfrmManageUsers.Rename;
  107. var
  108.   OldUserID, NewUserID : String;
  109. begin
  110.   // if there's a user selected...
  111.   if lstList.ItemIndex > -1 then
  112.     OldUserID := lstList.Items[lstList.ItemIndex];
  113.   NewUserID := InputBox('Rename User', 'Enter New User Name', OldUserID);
  114.   if LowerCase(NewUserID) <> LowerCase(OldUserID) then begin
  115.     // and the new user name isn't the same as the old one...
  116.     // then rename the user and refresh the display
  117.     if not INI.User_Rename(OldUserID, NewUserID) then
  118.       ShowMessage('Error: Cound not re-name.' + #13 + #10 +
  119.                   'Users must have a unique ID.')
  120.     else
  121.       INI.User_GetList(lstList.Items);
  122.   end;
  123. end;
  124. procedure TfrmManageUsers.Import;
  125. begin // Import users
  126.   ShowMessage('Feature not implemented yet...');
  127.   // DEBUG
  128.   // How should I import users ?
  129. end;
  130. procedure TfrmManageUsers.DoExport;
  131. begin // Export users
  132.   ShowMessage('Feature not implemented yet...');
  133.   // DEBUG
  134.   // How will I export users ?
  135. end;
  136. procedure TfrmManageUsers.EnableUI;
  137. begin
  138.   // Enable buttons and menus based on list selection
  139.   btnEdit.Enabled   := lstList.SelCount = 1;
  140.   btnDelete.Enabled := lstList.SelCount > 0;
  141.   btnRename.Enabled := lstList.SelCount = 1;
  142.   btnExport.Enabled := lstList.Items.Count > 0;
  143.   puEdit.Enabled   := lstList.SelCount = 1;
  144.   puDelete.Enabled := lstList.SelCount > 0;
  145.   puRename.Enabled := lstList.SelCount = 1;
  146.   puExport.Enabled := lstList.Items.Count > 0;
  147. end;
  148. // Hook Buttond and menus up with functions for performing actions
  149. procedure TfrmManageUsers.btnAddClick(Sender: TObject);
  150. begin  Add;                                    end;
  151. procedure TfrmManageUsers.btnEditClick(Sender: TObject);
  152. begin  Edit;                                   end;
  153. procedure TfrmManageUsers.btnDeleteClick(Sender: TObject);
  154. begin  Delete;                                 end;
  155. procedure TfrmManageUsers.btnRenameClick(Sender: TObject);
  156. begin  Rename;                                 end;
  157. procedure TfrmManageUsers.btnImportClick(Sender: TObject);
  158. begin  Import;                                 end;
  159. procedure TfrmManageUsers.btnExportClick(Sender: TObject);
  160. begin  DoExport;                               end;
  161. procedure TfrmManageUsers.lstListClick(Sender: TObject);
  162. begin  EnableUI;                               end;
  163. procedure TfrmManageUsers.lstListDblClick(Sender: TObject);
  164. begin  Edit;                                   end;
  165. procedure TfrmManageUsers.popupMenuPopup(Sender: TObject);
  166. begin  EnableUI;                               end;
  167. procedure TfrmManageUsers.btnCloseClick(Sender: TObject);
  168. begin  Close;                                  end;
  169. end.