unit uPantallaPrincipal; interface uses Windows, Forms, SysUtils, Messages, JvMenus, Menus, Graphics, AppEvnts, JvAppStorage, JvAppRegistryStorage, JvFormPlacement, JvComponentBase, Dialogs, JvNavigationPane, ImgList, Controls, PngImageList, Classes, ActnList, XPMan, JvXPCore, JvXPContainer, pngimage, ExtCtrls, TB2Item, SpTBXItem, StdCtrls, JvPageList, JvExControls, TB2Dock, SpTBXDkPanels, uGUIBase, uCustomEditor; type IMainForm = interface(IHostForm) ['{7F6F5574-5E5C-486C-AA24-D3AEAA52D243}'] procedure ReleaseEmbedded; end; TfPantallaPrincipal = class(TForm, IHostForm, IMainForm) GeneralActionList: TActionList; ModulesSmallImageList: TPngImageList; XPManifest1: TXPManifest; actSalir: TAction; ModulesActionList: TActionList; ModulesLargeImageList: TPngImageList; pnlContenido: TSpTBXDockablePanel; JvNavigationPane: TJvNavigationPane; pnlMain: TSpTBXDockablePanel; actLogin: TAction; StyleManagerButtons: TJvNavPaneStyleManager; JvFormStorage: TJvFormStorage; JvAppRegistryStorage: TJvAppRegistryStorage; actAdministracion: TAction; ApplicationEvents: TApplicationEvents; actCambiarPass: TAction; actConexion: TAction; actAcerca: TAction; pnlBorde: TJvXPContainer; HostMenu: TJvMainMenu; Archivo2_OLD: TMenuItem; Ayuda2_OLD: TMenuItem; Cambiarmicontrasea2_OLD: TMenuItem; N3_OLD: TMenuItem; Configurarconexin2_OLD: TMenuItem; Paneldeadministracin2_OLD: TMenuItem; N4_OLD: TMenuItem; Salir2_OLD: TMenuItem; Acercade2_OLD: TMenuItem; lblBienvenido: TLabel; Label22: TLabel; StatusPanelImageList: TPngImageList; Empresa1_OLD: TMenuItem; Listadeempresas1_OLD: TMenuItem; N1_OLD: TMenuItem; Opciones1_OLD: TMenuItem; Edicin1_OLD: TMenuItem; N1: TMenuItem; Compras1: TMenuItem; Ventas1: TMenuItem; actMenuCompras: TAction; actMenuLogistica: TAction; actMenuVentas: TAction; Logstica1: TMenuItem; pagInicio: TJvNavPanelPage; Panel1: TPanel; Label1: TLabel; Image1: TImage; actVerPanel: TAction; actVerBarraEstado: TAction; Paneldeexploracin1: TMenuItem; Paneldeexploracin2: TMenuItem; Informacindeempresa1: TMenuItem; Administracin1: TMenuItem; N2: TMenuItem; Usuarios1: TMenuItem; Perfiles1: TMenuItem; N3: TMenuItem; N4: TMenuItem; Datos1: TMenuItem; N5: TMenuItem; N6: TMenuItem; N7: TMenuItem; N8: TMenuItem; N9: TMenuItem; N10: TMenuItem; actMenuEmpresa: TAction; actMenuInformes: TAction; actInformacionEmpresa: TAction; SpTBXStatusBar1: TSpTBXStatusBar; SpTBXLabelItem1: TSpTBXLabelItem; SpTBXSeparatorItem1: TSpTBXSeparatorItem; SpTBXLabelItem2: TSpTBXLabelItem; actUsuarios: TAction; actPerfilesUsuario: TAction; actSeleccionEmpresas: TAction; Splitter1: TSplitter; procedure FormCreate(Sender: TObject); procedure actSalirExecute(Sender: TObject); procedure actCambiarPassExecute(Sender: TObject); procedure actAcercaExecute(Sender: TObject); procedure actConexionExecute(Sender: TObject); procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean); procedure JvNavigationPaneChange(Sender: TObject); procedure ApplicationEventsException(Sender: TObject; E: Exception); procedure actMenuComprasExecute(Sender: TObject); procedure actMenuComprasUpdate(Sender: TObject); procedure actMenuLogisticaExecute(Sender: TObject); procedure actMenuVentasExecute(Sender: TObject); procedure actActualizacionesExecute(Sender: TObject); procedure actVerPanelUpdate(Sender: TObject); procedure actVerPanelExecute(Sender: TObject); procedure actVerBarraEstadoUpdate(Sender: TObject); procedure actVerBarraEstadoExecute(Sender: TObject); procedure FormShow(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure actMenuInformesExecute(Sender: TObject); procedure actInformacionEmpresaExecute(Sender: TObject); procedure actUsuariosExecute(Sender: TObject); procedure actPerfilesUsuarioExecute(Sender: TObject); procedure actSeleccionEmpresasExecute(Sender: TObject); private FContenido : TCustomEditor; procedure ShowEmbedded(AEditor : ICustomEditor); procedure ReleaseEmbedded; procedure AplicarPerfil; procedure InicializarUI; procedure OnThemeChange(Sender: TObject); procedure ExecuteActionMenu(Sender : TObject); procedure InitStyleManager; //procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; protected function GetWorkPanel : TWinControl; procedure CreateParams(var Params: TCreateParams); override; public procedure RefrescarUI; function IsShortcut(var Message: TWMKey): Boolean; override; procedure OnWorkPanelChanged(AEditor : ICustomEditor); constructor Create(AOwner: TComponent); override; property WorkPanel : TWinControl read GetWorkPanel; end; var fPantallaPrincipal: TfPantallaPrincipal; implementation {$INCLUDE ..\FactuGES.inc} uses uSplash, uAcercaDe, UxTheme, Themes, uMenuUtils, uBizEmpresas, uFactuGES_App, uDMBase, uDataModuleConexion, uModuleController, uMainMenuController, uNavPaneController, uDialogUtils, cxControls, SpTBXSkins, SpTBXDefaultSkins; {$R *.dfm} { ***************************** TfPantallaPrincipal ****************************** } procedure TfPantallaPrincipal.FormClose(Sender: TObject; var Action: TCloseAction); begin //Tiene que ser en este método porque salta antes que liberar la aplicación, si lo dejamos //en el evento onDestroy no le da tiempo a liberar el contenido y se pone a liberar la aplicación //provocando un error de memoria ReleaseEmbedded; ApplicationEvents.CancelDispatch; end; procedure TfPantallaPrincipal.FormCloseQuery(Sender: TObject; var CanClose: Boolean); begin CanClose := True; if Assigned(FContenido) then CanClose := FContenido.CloseQuery; end; procedure TfPantallaPrincipal.FormCreate(Sender: TObject); begin ApplicationEvents.Activate; Application.Title := AppFactuGES.AppName + ' ' + AppFactuGES.AppVersion; Caption := Application.Title; actLogin.Execute; end; procedure TfPantallaPrincipal.FormShow(Sender: TObject); begin // Set skin type to sknTBX SkinManager.SetSkin('Office 2003'); dmBase.OnThemeChange := Self.OnThemeChange; JvNavigationPane.StyleManager := dmBase.StyleManager; InitStyleManager; InicializarUI; end; procedure TfPantallaPrincipal.RefrescarUI; var ATitulo : String; i: Integer; begin ATitulo := AppFactuGES.GetAppFullName; if Assigned(AppFactuGES.EmpresaActiva) then ATitulo := AppFactuGES.EmpresaActiva.NOMBRE + ' - ' + ATitulo; Application.Title := ATitulo; Caption := Application.Title; SpTBXLabelItem1.ImageIndex := 1; SpTBXLabelItem1.Caption := 'Conectado a: ' + dmConexion.TargetURL; if Assigned(AppFactuGES.UsuarioActivo) then begin SpTBXLabelItem2.ImageIndex := 0; SpTBXLabelItem2.Caption := AppFactuGES.UsuarioActivo.UserName end else begin SpTBXLabelItem2.ImageIndex := -1; SpTBXLabelItem2.Caption := ''; end; // Comprobar que el panel lateral tiene la empresa activa if Assigned(AppFactuGES.EmpresaActiva) then for i := 0 to JvNavigationPane.PageCount - 1 do if (JvNavigationPane.Pages[i].Tag = AppFactuGES.EmpresaActiva.ID) and (JvNavigationPane.ActivePageIndex <> i) then JvNavigationPane.ActivePageIndex := i; end; procedure TfPantallaPrincipal.ReleaseEmbedded; begin if Assigned(FContenido) then FContenido.Release; FContenido := Nil; Application.ProcessMessages; end; procedure TfPantallaPrincipal.actSalirExecute(Sender: TObject); begin Close; end; procedure TfPantallaPrincipal.actSeleccionEmpresasExecute(Sender: TObject); begin AppFactuGES.SeleccionarEmpresa; RefrescarUI; end; procedure TfPantallaPrincipal.actUsuariosExecute(Sender: TObject); begin AppFactuGES.UsuariosController.VerUsuarios; end; procedure TfPantallaPrincipal.actMenuVentasExecute(Sender: TObject); begin // end; procedure TfPantallaPrincipal.actPerfilesUsuarioExecute(Sender: TObject); begin AppFactuGES.UsuariosController.VerPerfiles; end; procedure TfPantallaPrincipal.actVerBarraEstadoExecute(Sender: TObject); begin SpTBXStatusBar1.Visible := not SpTBXStatusBar1.Visible; end; procedure TfPantallaPrincipal.actVerBarraEstadoUpdate(Sender: TObject); begin (Sender as TAction).Checked := SpTBXStatusBar1.Visible; end; procedure TfPantallaPrincipal.actVerPanelExecute(Sender: TObject); begin JvNavigationPane.Visible := not JvNavigationPane.Visible; if (JvNavigationPane.Visible) and (JvNavigationPane.Width = 0) then JvNavigationPane.Width := 210; end; procedure TfPantallaPrincipal.actVerPanelUpdate(Sender: TObject); begin (Sender as TAction).Checked := JvNavigationPane.Visible and (JvNavigationPane.Width > 0); end; procedure TfPantallaPrincipal.OnThemeChange(Sender: TObject); begin LockWindowUpdate(Handle); try Self.Color := dmBase.StyleManager.Colors.DividerColorTo; //pnlBorde.Color := dmBase.StyleManager.Colors.FrameColor; pnlBorde.BoundColor := dmBase.StyleManager.Colors.FrameColor; with StyleManagerButtons do begin Colors.ButtonColorFrom := clWindow; Colors.ButtonColorTo := clWindow; Colors.ButtonSeparatorColor := clWindow; Colors.SplitterColorFrom := clWindow; Colors.SplitterColorTo := clWindow; Colors.DividerColorFrom := clWindow; Colors.DividerColorTo := clWindow; Colors.HeaderColorFrom := clWindow; Colors.HeaderColorTo := clWindow; Colors.FrameColor := clWindow; Colors.ToolPanelHeaderColorFrom := clWindow; Colors.ToolPanelHeaderColorTo := clWindow; Colors.ButtonHotColorFrom := dmBase.StyleManager.Colors.ButtonHotColorFrom; Colors.ButtonHotColorTo := dmBase.StyleManager.Colors.ButtonHotColorTo; Colors.ButtonSelectedColorFrom := dmBase.StyleManager.Colors.ButtonSelectedColorFrom; Colors.ButtonSelectedColorTo := dmBase.StyleManager.Colors.ButtonSelectedColorTo; end; lblBienvenido.Font.Color := JvNavigationPane.Colors.ButtonColorTo; { JvGradient1.StartColor := JvNavigationPane.Colors.ButtonColorFrom; JvGradient1.EndColor := JvNavigationPane.Colors.ButtonColorTo;} finally LockWindowUpdate(0); Refresh; end; end; function TfPantallaPrincipal.GetWorkPanel: TWinControl; begin Result := pnlMain; end; procedure TfPantallaPrincipal.InicializarUI; var AListaEmpresas : IBizEmpresa; i : Integer; begin ShowHourglassCursor; try for i := 0 to AppFactuGES.ModuleManager.ModulesCount - 1 do MainMenuController.RegisterModule(AppFactuGES.ModuleManager.Modules[i]); MainMenuController.SortMenuByTag; MainMenuController.InitMainMenu; for i := 0 to AppFactuGES.ModuleManager.ModulesCount - 1 do NavPaneController.RegisterModule(AppFactuGES.ModuleManager.Modules[i]); NavPaneController.InitNavPane; try AListaEmpresas := AppFactuGES.EmpresasController.BuscarTodos; if Assigned(AListaEmpresas) then begin AListaEmpresas.Active := True; if AListaEmpresas.RecordCount = 1 then begin // Oculto la página de inicio para que no parezca // que se pueden manejar varias empresas. JvNavigationPane.ActivePageIndex := 1; pagInicio.PageList := NIL; pagInicio.Visible := False; end; end; finally AListaEmpresas.Close; AListaEmpresas := NIL; end; RefrescarUI; finally HideHourglassCursor; end; end; procedure TfPantallaPrincipal.actMenuComprasExecute(Sender: TObject); begin // end; procedure TfPantallaPrincipal.actMenuComprasUpdate(Sender: TObject); begin (Sender as TAction).Enabled := Assigned(AppFactuGES.EmpresaActiva); end; procedure TfPantallaPrincipal.actMenuInformesExecute(Sender: TObject); begin // end; procedure TfPantallaPrincipal.actMenuLogisticaExecute(Sender: TObject); begin // end; procedure TfPantallaPrincipal.ExecuteActionMenu(Sender: TObject); var i : integer; begin for i := 0 to JvNavigationPane.PageCount - 1 do begin if JvNavigationPane.NavPages[i].Caption = (Sender as TAction).Caption then begin JvNavigationPane.ActivePageIndex := i; Break; end; end; end; procedure TfPantallaPrincipal.AplicarPerfil; begin // end; procedure TfPantallaPrincipal.ApplicationEventsException(Sender: TObject; E: Exception); begin { if E is EROSessionNotFound then begin // OJOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO if not dmUsuarios.Login then ShowMessage(E.Message); end else} ShowMessage(E.Message); //ShowErrorMessage('Se ha producido un error', '', E); end; procedure TfPantallaPrincipal.OnWorkPanelChanged(AEditor: ICustomEditor); begin // end; procedure TfPantallaPrincipal.ShowEmbedded(AEditor: ICustomEditor); begin if Assigned(FContenido) and not FContenido.CloseQuery then begin AEditor.Release; AEditor := NIL; Exit; end; ShowHourglassCursor; LockWindowUpdate(Handle); ReleaseEmbedded; try FContenido := TCustomEditor(AEditor.GetInstance); with (FContenido) do begin Visible := False; BorderIcons := []; BorderStyle := bsNone; Parent := WorkPanel; FContenido.Show; Align := alClient; FContenido.SetFocus; end; finally Application.ProcessMessages; LockWindowUpdate(0); HideHourglassCursor; end; OnWorkPanelChanged(FContenido); end; {procedure TfPantallaPrincipal.WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND; begin // Sirve para recuperar el foco el formulario principal cuando // tenemos varios formularios hijos abiertos a la vez. case (Msg.cmdtype and $FFF0) of SC_MINIMIZE: begin ShowWindow(handle, SW_MINIMIZE); Msg.result := 0; end; SC_RESTORE: begin ShowWindow(handle, SW_RESTORE); Msg.result := 0; end; else DefaultHandler(Msg); end; end;} constructor TfPantallaPrincipal.Create(AOwner: TComponent); begin inherited; {$IFDEF MULTIEMPRESA} {$ELSE} Listadeempresas1_OLD.Destroy; {$ENDIF} FContenido := NIL; with AppFactuGES.ModuleManager do begin MainMenu := Self.Menu; MainForm := Self; end; with NavPaneController do begin SmallImages := ModulesSmallImageList; LargeImages := ModulesLargeImageList; NavigationPane := JvNavigationPane; MainForm := Self; end; with MainMenuController do begin SmallImages := ModulesSmallImageList; LargeImages := ModulesLargeImageList; MainMenu := HostMenu; MainForm := Self; end; end; procedure TfPantallaPrincipal.CreateParams(var Params: TCreateParams); begin { ¡¡¡No quitar este procedimiento aunque no haga nada!!!!! Si se quita, esta pantalla principal se queda en el fondo después de desaparecer la pantalla de login. } inherited CreateParams(Params); end; procedure TfPantallaPrincipal.actActualizacionesExecute(Sender: TObject); begin { fActualizacion := TfActualizacion.Create(Self); try fActualizacion.ShowModal; finally FreeAndNil(fActualizacion); end;} end; procedure TfPantallaPrincipal.actCambiarPassExecute(Sender: TObject); begin AppFactuGES.UsuariosController._ShowChangePassword; RefrescarUI; end; procedure TfPantallaPrincipal.actAcercaExecute(Sender: TObject); begin with TfAcercaDe.Create(NIL) do try HostManager := AppFactuGES.ModuleManager; ShowModal; finally Free; end; end; function TfPantallaPrincipal.IsShortcut(var Message: TWMKey): Boolean; Var ctrl: TWinControl; comp: TComponent; i: Integer; Begin ctrl := ActiveControl; If ctrl <> Nil Then Begin Repeat ctrl := ctrl.Parent Until (ctrl = nil) or (ctrl Is TCustomForm); // Note: replace TCustomFrame with TForm, check if the found form is // self, if not, execute the following block of code. If ctrl <> nil Then Begin For i:= 0 To ctrl.componentcount-1 Do Begin comp:= ctrl.Components[i]; If comp Is TCustomActionList Then Begin result := TCustomActionList(comp).IsShortcut( message ); If result Then Exit; End; End; End; End; //Result := inherited IsShortCut(Message); end; procedure TfPantallaPrincipal.JvNavigationPaneChange(Sender: TObject); begin { Cuando se destruye el formulario este evento salta pero no hay que cambiar de empresa } if (csDestroying in ComponentState) then Exit; //Se libera el contenido que tenga ya que cambiamos de empresa; ReleaseEmbedded; AppFactuGES.CambiarEmpresa(JvNavigationPane.ActivePage.Tag); RefrescarUI; end; procedure TfPantallaPrincipal.actConexionExecute(Sender: TObject); begin dmConexion.ConfigurarConexion; RefrescarUI; end; procedure TfPantallaPrincipal.actInformacionEmpresaExecute(Sender: TObject); begin AppFactuGES.EmpresasController.Ver(AppFactuGES.EmpresaActiva); end; procedure TfPantallaPrincipal.InitStyleManager; begin if not SkinManager.IsXPThemesEnabled then dmBase.StyleManager.Theme := nptStandard else begin //TBXSwitcher.EnableXPStyles := True; with dmBase.StyleManager do begin if SkinManager.CurrentSkin is TSpTBXOffice2003Skin then begin case SpGetLunaScheme of lusBlue : Theme := nptXPBlue; lusMetallic : Theme := nptXPSilver; lusGreen : Theme := nptXPOlive; else Theme := nptStandard; end; end; end; end; Self.Color := dmBase.StyleManager.Colors.DividerColorTo; Splitter1.Color := Self.Color; end; end.