📄 ucbase.pas
字号:
procedure IniSettings2(DestSettings: TUCSettings);
implementation
{$R UCLock.res}
{ TUserControl }
uses
Dialogs, CadPerfil_U, CadUser_U, UserPermis_U, TrocaSenha_U,
MsgRecForm_U, MsgsForm_U, LoginWindow_U, UCXPStyle, ViewLog_U;
constructor TUserControl.Create(AOwner: TComponent);
begin
inherited;
FUser := TUserDef.Create(self);
ControlRight := TUCControlRight.Create(Self);
Login := TLogin.Create(Self);
LogControl := TLogControl.Create(Self);
UsersForm := TCadastroUsuarios.Create(Self);
UsersProfile := TPerfilUsuarios.Create(Self);
ChangePasswordForm := TTrocarSenha.Create(Self);
FUserSettings := TUserSettings.Create(Self);
FNaoPermitidos := TNaoPermitidos.Create(Self);
FRightItems := TUCCollection.Create(Self);
TableUsers := TUCTableUsers.Create(Self);
TableRights := TUCTableRights.Create(Self);
if csDesigning in ComponentState then
begin
FMode := lmActive;
with TableUsers do
begin
if TableName = '' then TableName := 'UCTabUsers';
if FieldUserID = '' then FieldUserID := 'UCIdUser';
if FieldUserName = '' then FieldUserName := 'UCUserName';
if FieldLogin = '' then FieldLogin := 'UCLogin';
if FieldPassword = '' then FieldPassword := 'UCPassword';
if FieldEmail = '' then FieldEmail := 'UCEmail';
if FieldPrivileged = '' then FieldPrivileged := 'UCPrivileged';
if FieldTypeRec = '' then FieldTypeRec := 'UCTypeRec';
if FieldProfile = '' then FieldProfile := 'UCProfile';
if FieldKey = '' then FieldKey := 'UCKey';
end;
with TableRights do
begin
if TableName = '' then TableName := 'UCTabRights';
if FieldUserID = '' then FieldUserID := 'UCIdUser';
if FieldModule = '' then FieldModule := 'UCModule';
if FieldComponentName = '' then FieldComponentName := 'UCCompName';
if FieldFormName = '' then FieldFormName := 'UCFormName';
if FieldKey = '' then FieldKey := 'UCKey';
end;
if LogControl.TableLog = '' then LogControl.TableLog := 'UCLog';
if ApplicationID = '' then ApplicationID := 'NewProject';
if Login.InitialLogin.User = '' then Login.InitialLogin.User := 'Admin';
if Login.InitialLogin.Password = '' then Login.InitialLogin.Password := '#delphi';
if Login.InitialLogin.Email = '' then Login.InitialLogin.Email := 'qmd@usercontrol.com.br';
FAutoStart := True;
UsersProfile.Active := True;
UsersForm.UsePrivilegedField := False;
UsersForm.ProtectAdmin := True;
NotAllowedItems.MenuVisible := True;
NotAllowedItems.ActionVisible := True;
end else begin
UCControlList := TList.Create;
LoginMonitorList := TList.Create;
end;
IniSettings(Settings);
end;
procedure TUserControl.Loaded;
var
Contador : integer;
begin
inherited;
if not (csDesigning in ComponentState) then
begin
for Contador := 0 to Pred(Owner.ComponentCount) do
if Owner.Components[Contador] is TUCSettings then ApplySettings(TUCSettings(Owner.Components[Contador]));
//retornou 2.13 qmd
if Assigned(UsersForm.MenuItem) and (not Assigned(UsersForm.MenuItem.OnClick)) then UsersForm.MenuItem.OnClick := ActionCadUser;
if Assigned(UsersForm.Action) and (not Assigned(UsersForm.Action.OnExecute)) then UsersForm.Action.OnExecute := ActionCadUser;
if UsersProfile.Active then
begin
if Assigned(UsersProfile.MenuItem) and (not Assigned(UsersProfile.MenuItem.OnClick)) then UsersProfile.MenuItem.OnClick := ActionUserProfile;
if Assigned(UsersProfile.Action) and (not Assigned(UsersProfile.Action.OnExecute)) then UsersProfile.Action.OnExecute := ActionUserProfile;
end;
if Assigned(ChangePasswordForm.MenuItem) and (not Assigned(ChangePasswordForm.MenuItem.OnClick)) then ChangePasswordForm.MenuItem.OnClick := ActionTrocaSenha;
if Assigned(ChangePasswordForm.Action) and (not Assigned(ChangePasswordForm.Action.OnExecute)) then ChangePasswordForm.Action.OnExecute := ActionTrocaSenha;
if (LogControl.Active) then
begin
if Assigned(LogControl.MenuItem) and (not Assigned(LogControl.MenuItem.OnClick)) then LogControl.MenuItem.OnClick := ActionLog;
if Assigned(LogControl.Action) and (not Assigned(LogControl.Action.OnExecute))then LogControl.Action.OnExecute := ActionLog;
end;
if not Assigned(DataConnector) then raise Exception.Create('Property DataConnector not defined!');
if ApplicationID = '' then raise Exception.Create(MsgExceptAppID);
with TableUsers do
begin
if TableName = '' then Exception.Create(MsgExceptUsersTable);
if FieldUserID = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldUserID***');
if FieldUserName = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldUserName***');
if FieldLogin = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldLogin***');
if FieldPassword = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldPassword***');
if FieldEmail = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldEmail***');
if FieldPrivileged = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldPrivileged***');
if FieldTypeRec = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldTypeRec***');
if FieldKey = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldKey***');
if FieldProfile = '' then Exception.Create(MsgExceptUsersTable +#13+#10+ 'FieldProfile***');
end;
with TableRights do
begin
if TableName = '' then Exception.Create(MsgExceptRightsTable);
if FieldUserID = '' then Exception.Create(MsgExceptRightsTable +#13+#10+ 'FieldProfile***');
if FieldModule = '' then Exception.Create(MsgExceptRightsTable +#13+#10+ 'FieldModule***');
if FieldComponentName = '' then Exception.Create(MsgExceptRightsTable +#13+#10+ 'FieldComponentName***');
if FieldFormName = '' then Exception.Create(MsgExceptRightsTable +#13+#10+ 'FieldFormName***');
if FieldKey = '' then Exception.Create(MsgExceptRightsTable +#13+#10+ 'FieldKey***');
end;
if Assigned(OnStartApplication) then OnStartApplication(self);
//desviar para thread monitorando conexao ao banco qmd 30/01/2004
if FAutoStart then
begin
FThUCRun := TUCRun.Create(True);
FThUCRun.AOwner := Self;
FThUCRun.FreeOnTerminate := True;
FThUCRun.Resume;
end;
end;
end;
procedure TUserControl.ActionUserProfile(Sender : TObject);
begin
if Assigned(OnCustomUsersProfileForm) then OnCustomUsersProfileForm(Self, FormPerfilUsuarios);
if FormPerfilUsuarios = nil then CriaProfileUserForm;
FormPerfilUsuarios.ShowModal;
FreeAndNil(FormPerfilUsuarios);
end;
procedure TUserControl.CriaProfileUserForm;
begin
FormPerfilUsuarios := TCadPerfil.Create(self);
with Settings.UsersProfile, TCadPerfil(FormPerfilUsuarios) do
begin
Caption := WindowCaption;
lbDescricao.Caption := LabelDescription;
btAdic.Caption := BtAdd;
BtAlt.Caption := BtChange;
BtExclui.Caption := BtDelete;
BtAcess.Caption := BtRights;
BtExit.Caption := BtClose;
BtAcess.OnClick := ActionBtPermissProfile;
UCComponent := Self;
UCXPStyle.XPSettings.Assign(Self.Settings.XpStyleSet);
UCXPStyle.Active := Self.Settings.XPStyle;
Position := Self.Settings.WindowsPosition;
end;
end;
procedure TUserControl.ActionBtPermissProfile(Sender: TObject);
begin
if TCadPerfil(FormPerfilUsuarios).DSPerfilUser.IsEmpty then Exit;
UserPermis := TUserPermis.Create(self);
UserPermis.UCComponent := Self;
SetWindowProfile;
UserPermis.lbUser.Caption := TCadPerfil(FormPerfilUsuarios).DSPerfilUser.FieldByName('Nome').asString;
ActionBtPermissProfileDefault;
end;
procedure TUserControl.SetWindowProfile;
begin
with Settings.Rights do
begin
UserPermis.Caption := WindowCaption;
UserPermis.LbDescricao.Caption := LabelProfile;
UserPermis.lbUser.Left := UserPermis.LbDescricao.Left + UserPermis.LbDescricao.Width + 5;
UserPermis.PageMenu.Caption := PageMenu;
UserPermis.PageAction.Caption := PageActions;
UserPermis.BtLibera.Caption := BtUnlock;
UserPermis.BtBloqueia.Caption := BtLock;
UserPermis.BtGrava.Caption := BtSave;
UserPermis.BtCancel.Caption := BtCancel;
UserPermis.UCXPStyle.XPSettings.Assign(Self.Settings.XpStyleSet);
UserPermis.UCXPStyle.Active := Settings.XPStyle;
end;
end;
procedure TUserControl.ActionCadUser(Sender: TObject);
begin
if Assigned(OnCustomUsersForm) then OnCustomUsersForm(Self, FormCadastroUsuarios);
if FormCadastroUsuarios = nil then CriaCadUserForm;
FormCadastroUsuarios.ShowModal;
FreeAndNil(FormCadastroUsuarios);
end;
procedure TUserControl.ActionTrocaSenha(Sender: TObject);
begin
if Assigned(OnCustomChangePasswordForm) then OnCustomChangePasswordForm(Self, FormTrocarSenha);
if FormTrocarSenha = nil then CriaTrocaSenhaForm;
FormTrocarSenha.ShowModal;
FreeAndNil(FormTrocarSenha);
end;
procedure TUserControl.CriaCadUserForm;
begin
FormCadastroUsuarios := TCadUser.Create(self);
with Settings.UsersForm, TCadUser(FormCadastroUsuarios) do
begin
Caption := WindowCaption;
lbDescricao.Caption := LabelDescription;
btAdic.Caption := BtAdd;
BtAlt.Caption := BtChange;
BtExclui.Caption := BtDelete;
BtAcess.Caption := BtRights;
BtPass.Caption := BtPassword;
BtExit.Caption := BtClose;
BtAcess.OnClick := Self.ActionBtPermiss;
UCComponent := Self;
UCXPStyle.XPSettings.Assign(Self.Settings.XpStyleSet);
UCXPStyle.Active := Self.Settings.XPStyle;
Position := Self.Settings.WindowsPosition;
end;
end;
procedure TUserControl.ActionBtPermiss(Sender: TObject);
begin
if TCadUser(FormCadastroUsuarios).DSCadUser.IsEmpty then Exit;
UserPermis := TUserPermis.Create(self);
UserPermis.UCComponent := Self;
SetWindow;
UserPermis.lbUser.Caption := TCadUser(FormCadastroUsuarios).DSCadUser.FieldByName('Login').asString;
ActionBtPermissDefault;
end;
procedure TUserControl.SetWindow;
begin
with Settings.Rights do
begin
UserPermis.Caption := WindowCaption;
UserPermis.LbDescricao.Caption := LabelUser;
UserPermis.lbUser.Left := UserPermis.LbDescricao.Left + UserPermis.LbDescricao.Width + 5;
UserPermis.PageMenu.Caption := PageMenu;
UserPermis.PageAction.Caption := PageActions;
UserPermis.BtLibera.Caption := BtUnlock;
UserPermis.BtBloqueia.Caption := BtLOck;
UserPermis.BtGrava.Caption := BtSave;
UserPermis.BtCancel.Caption := BtCancel;
UserPermis.UCXPStyle.XPSettings.Assign(Self.Settings.XpStyleSet);
UserPermis.UCXPStyle.Active := Self.Settings.XPStyle;
end;
end;
procedure TUserControl.CriaTrocaSenhaForm;
begin
FormTrocarSenha := TTrocaSenha.Create(Self);
with Settings.ChangePassword do begin
TTrocaSenha(FormTrocarSenha).Caption := WindowCaption;
TTrocaSenha(FormTrocarSenha).lbDescricao.Caption := LabelDescription;
TTrocaSenha(FormTrocarSenha).lbSenhaAtu.Caption := LabelCurrentPassword;
TTrocaSenha(FormTrocarSenha).lbNovaSenha.Caption := LabelNewPassword;
TTrocaSenha(FormTrocarSenha).lbConfirma.Caption := LabelConfirm;
TTrocaSenha(FormTrocarSenha).btGrava.Caption := BtSave;
TTrocaSenha(FormTrocarSenha).btCancel.Caption := BtCancel;
TTrocaSenha(FormTrocarSenha).UCXPStyle.XPSettings.Assign(Self.Settings.XpStyleSet);
TTrocaSenha(FormTrocarSenha).UCXPStyle.Active := Self.Settings.XPStyle;
end;
TTrocaSenha(FormTrocarSenha).btGrava.OnClick := ActionTSBtGrava;
if CurrentUser.Password = '' then TTrocaSenha(FormTrocarSenha).EditAtu.Enabled := False;
end;
procedure TUserControl.ActionTSBtGrava(Sender: TObject);
begin
if CurrentUser.Password <> TTrocaSenha(FormTrocarSenha).EditAtu.text then
begin
MessageDlg(Settings.CommonMessages.ChangePasswordError.InvalidCurrentPassword, mtWarning, [mbOK], 0);
TTrocaSenha(FormTrocarSenha).EditAtu.SetFocus;
Exit;
end;
if TTrocaSenha(FormTrocarSenha).EditNova.Text <> TTrocaSenha(FormTrocarSenha).EditConfirma.Text then
begin
MessageDlg(Settings.CommonMessages.ChangePasswordError.InvalidNewPassword, mtWarning, [mbOK], 0);
TTrocaSenha(FormTrocarSenha).EditNova.SetFocus;
Exit;
end;
if TTrocaSenha(FormTrocarSenha).EditNova.Text = CurrentUser.Password then
begin
MessageDlg(Settings.CommonMessages.ChangePasswordError.NewEqualCurrent, mtWarning, [mbOK], 0);
TTrocaSenha(FormTrocarSenha).EditNova.SetFocus;
Exit;
end;
if (ChangePasswordForm.ForcePassword) and (TTrocaSenha(FormTrocarSenha).EditNova.Text = '') then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -