unit Configuracion; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, dxCntner, cxContainer, cxEdit, am2000options, am2000skin, am2000, RdxFrame, Tipos, Menus, am2000menuitem, am2000utils, am2000popupmenu, ImgList, cxintl; const FICHERO_CONFIGURACION = 'factuges.ini'; FICHERO_COLORES = 'colores.ini'; type TdmConfiguracion = class(TDataModule) dxEstiloOscuro: TdxEditStyleController; cxEstiloOscuro: TcxEditStyleController; cxEstiloEditoresFondoOscuro: TcxEditStyleController; cxEstiloEditoresFondoClaro: TcxEditStyleController; cxIntl1: TcxIntl; ilEtiquetado: TImageList; private { Private declarations } public { Public declarations } end; function LeerConfiguracion : boolean; procedure ConfigurarVentanaPrincipal (Objeto : TWinControl); procedure ConfigurarPantallaAcceso (Objeto : TWinControl); procedure ConfigurarBarraLateral(Objeto : TWinControl; Entidad : TRdxEntidad); procedure ConfigurarFrame(Objeto : TWinControl; Entidad : TRdxEntidad); function PuedeSincronizar : boolean; var ListaBD : TStringList; ListaInformes : TStringList; dmConfiguracion: TdmConfiguracion; implementation {$R *.DFM} uses Colores, IniFiles, Mensajes, extctrls, RdxPaneles, Entidades, stdctrls, RdxBotones, pngimage, RdxBarras, RdxTitulos, RdxPageControl, cxTextEdit, FthImage, OutlookXP; var FColores : TStringList; function DarColorEntidad (Entidad : String; NombreColor : String) : TColor; var i : Integer; begin i := FColores.IndexOf(Entidad); with (FColores.Objects[i] as TStringList) do Result := StrToInt(Values[NombreColor]); end; function LeerConfiguracion: boolean; var Fichero : String; i : Integer; begin Fichero := ExtractFileDir(ParamStr(0))+ '\' + FICHERO_CONFIGURACION; if not FileExists(Fichero) then begin VerMensaje('No se ha encontrado el fichero de configuración.'); Result := False; exit; end; with TIniFile.Create(Fichero) do begin ListaBD := TStringList.Create; ReadSectionValues('BD', ListaBD); ListaInformes := TStringList.Create; ReadSectionValues('INFORMES', ListaInformes); if (ListaBD.Count = 0) or (ListaInformes.Count = 0) then Result := False else Result := True; end; if Result = False then exit; // Leer Colores; Fichero := ExtractFileDir(ParamStr(0))+ '\' + FICHERO_COLORES; if not FileExists(Fichero) then begin VerMensaje('No se ha encontrado el fichero de configuración de colores.'); Result := False; exit; end; with TIniFile.Create(Fichero) do begin FColores := TStringList.Create; ReadSections(FColores); if FColores.Count = 0 then Result := False; for i := 0 to FColores.Count - 1 do begin FColores.Objects[i] := TStringList.Create; ReadSectionValues(FColores.Strings[i], TStringList(FColores.Objects[i])); end; end; end; function GetResourceAsPNG(const resname: string): TPngObject; var Stream: TResourceStream; begin Stream := TResourceStream.Create(hInstance, ResName, 'PNG'); try Result := TPngObject.Create; Result.LoadFromStream(Stream); finally Stream.Free; end; end; procedure ConfigurarVentanaPrincipal (Objeto : TWinControl); var i : integer; ImagenPNG : TPNGObject; CadenaAux : String; begin if (Objeto is TCustomForm) then (Objeto as TCustomForm).Color := DarColorEntidad('General', 'BackgroundColor'); for i := 0 to Objeto.ComponentCount-1 do begin if Objeto.Components[i] is TLabel then (Objeto.Components[i] as TLabel).Font.Color := DarColorEntidad('barraprincipal', 'ToolbarFontColor'); if Objeto.Components[i] is TFourthImage then with (Objeto.Components[i] as TFourthImage) do begin if Name = 'bEmpresas' then CadenaAux := 'BT_EMPRESAS'; if Name = 'bAlmacen' then CadenaAux := 'BT_ALMACENES'; if Name = 'bObras' then CadenaAux := 'BT_OBRAS'; if Name = 'bDatos' then CadenaAux := 'BT_DATOS'; if Name = 'bClientes' then CadenaAux := 'BT_CLIENTES'; if Name = 'bProveedores' then CadenaAux := 'BT_PROVEEDORES'; if Name = 'bInformes' then CadenaAux := 'BT_INFORMES'; if Name = 'bCartas' then CadenaAux := 'BT_CARTAS'; if Name = 'bOpciones' then CadenaAux := 'BT_OPCIONES'; if Name = 'bSincronizacion' then CadenaAux := 'BT_SINCRONIZAR'; ImagenPNG := GetResourceAsPNG(CadenaAux); Options.EnabledPicture.Assign(ImagenPNG); ImagenPNG.Free; ImagenPNG := GetResourceAsPNG(CadenaAux + '_HOT'); Options.HotPicture.Assign(ImagenPNG); Options.UpPicture.Assign(ImagenPNG); ImagenPNG.Free; ImagenPNG := GetResourceAsPNG(CadenaAux + '_CLICK'); Options.DownPicture.Assign(ImagenPNG); ImagenPNG.Free; ImagenPNG := GetResourceAsPNG(CadenaAux + '_DISABLED'); Options.DisabledPicture.Assign(ImagenPNG); ImagenPNG.Free; if Enabled then Picture.Assign(Options.EnabledPicture) else Picture.Assign(Options.DisabledPicture); end; if Objeto.Components[i].Name = 'imgFondo' then begin ImagenPNG := GetResourceAsPNG('WP_FONDO'); try (Objeto.Components[i] as TImage).Picture.Assign(ImagenPNG); finally ImagenPNG.Free; end; end; if Objeto.Components[i].Name = 'pnlBarraSuperior' then begin with Objeto.Components[i] as TRdxGradientePanel do begin BackGroundEffect := bdDown; ColorStart := DarColorEntidad('barraprincipal', 'ToolbarColor2'); ColorEnd := DarColorEntidad('barraprincipal', 'ToolbarColor1'); end; end; if Objeto.Components[i] is TPopupMenu2000 then begin with (Objeto.Components[i] as TPopupMenu2000).Options.Colors do begin Bevel := DarColorEntidad('barraprincipal', 'ToolbarColor1'); BevelShadow := DarColorEntidad('barraprincipal', 'ToolbarColor1'); Frame := DarColorEntidad('barraprincipal', 'ToolbarColor1'); FrameShadow := DarColorEntidad('barraprincipal', 'ToolbarColor1'); Border := DarColorEntidad('barraprincipal', 'ToolbarColor2'); Highlight := DarColorEntidad('barraprincipal', 'ToolbarColor1'); HighlightText := DarColorEntidad('barraprincipal', 'ToolbarFontColor'); Pressed := DarColorEntidad('barraprincipal', 'ToolbarColor2'); PressedText := DarColorEntidad('barraprincipal', 'ToolbarFontColor'); Line := DarColorEntidad('barraprincipal', 'ToolbarColor1'); Menu := DarColorEntidad('barraprincipal', 'ToolbarColor2'); MenuText := DarColorEntidad('barraprincipal', 'ToolbarFontColor'); end; with (Objeto.Components[i] as TPopupMenu2000).Options.Margins do begin Border := 2; Bevel := 1; Frame := 1; end; end; if ((Objeto.Components[i] is TWinControl) and (csAcceptsControls in (Objeto.Components[i] as TWinControl).ControlStyle)) then ConfigurarVentanaPrincipal(Objeto.Components[i] as TWinControl) end; end; procedure ConfigurarPantallaAcceso (Objeto : TWinControl); var i : integer; ImagenPNG : TPNGObject; CadenaAux : String; begin for i := 0 to Objeto.ComponentCount-1 do begin if Objeto.Components[i] is TcxTextEdit then (Objeto.Components[i] as TcxTextEdit).Style.BorderColor := DarColorEntidad('barraprincipal', 'ToolbarColor1'); {if Objeto.Controls[i].Name = 'imgSombra' then begin ImagenPNG := GetResourceAsPNG('SOMBRA'); try (Objeto.Controls[i] as TImage).Picture.Assign(ImagenPNG); finally ImagenPNG.Free; end; end;} if Objeto.Components[i].Name = 'imgFondo' then begin ImagenPNG := GetResourceAsPNG('WP_FONDO'); try (Objeto.Components[i] as TImage).Picture.Assign(ImagenPNG); finally ImagenPNG.Free; end; end; if Objeto.Components[i].Name = 'pnlBarraSuperior' then begin with Objeto.Components[i] as TRdxGradientePanel do begin BackGroundEffect := bdDown; ColorStart := DarColorEntidad('barraprincipal', 'ToolbarColor2'); ColorEnd := DarColorEntidad('barraprincipal', 'ToolbarColor1'); end; end; if Objeto.Components[i].Name = 'eVersion' then begin with Objeto.Components[i] as TLabel do Font.Color := DarColorEntidad('barraprincipal', 'ToolbarColor1'); end; if Objeto.Components[i].Name = 'eEmpresa' then begin with Objeto.Components[i] as TLabel do Font.Color := DarColorEntidad('barraprincipal', 'ToolbarColor2'); end; if Objeto.Components[i].Name = 'eBienvenido' then begin with Objeto.Components[i] as TLabel do Font.Color := DarColorEntidad('barraprincipal', 'ToolbarColor2'); end; if ((Objeto.Components[i] is TWinControl) and (csAcceptsControls in (Objeto.Components[i] as TWinControl).ControlStyle)) then ConfigurarPantallaAcceso(Objeto.Components[i] as TWinControl) end; end; procedure ConfigurarBarraLateral(Objeto : TWinControl; Entidad : TRdxEntidad); var i : integer; TextoEntidad : String; ImagenPNG : TPNGObject; CadenaAux : String; begin TextoEntidad := DarNombreGrupo(Entidad); if (Objeto is TCustomForm) then (Objeto as TCustomForm).Color := DarColorEntidad('General', 'BackgroundColor'); for i := 0 to Objeto.ControlCount-1 do begin if Objeto.Controls[i].Name = 'pnlTitulo' then (Objeto.Controls[i] as TPanel).Color := DarColorEntidad(TextoEntidad, 'Color1'); if Objeto.Controls[i].Name = 'eTitulo' then (Objeto.Controls[i] as TLabel).Font.Color := clWhite; if Objeto.Controls[i].Name = 'pnlBarraLateral' then (Objeto.Controls[i] as TPanel).Color := DarColorEntidad(TextoEntidad, 'Color3'); if Objeto.Controls[i].Name = 'shSeparador' then (Objeto.Controls[i] as TShape).Pen.Color := DarColorEntidad(TextoEntidad, 'Color2'); if Objeto.Controls[i].Name = 'imgSombra' then begin ImagenPNG := GetResourceAsPNG('SOMBRA'); try (Objeto.Controls[i] as TImage).Picture.Assign(ImagenPNG); finally ImagenPNG.Free; end; end; if Objeto.Controls[i].Name = 'imgFondo' then begin case Entidad of entAlmacen : CadenaAux := 'WP_ALMACENES'; entAlmacenObra : CadenaAux := 'WP_OBRAS'; entDatos : CadenaAux := 'WP_DATOS'; entCliente : CadenaAux := 'WP_CLIENTES'; entProveedor : CadenaAux := 'WP_PROVEEDORES'; entInformes : CadenaAux := 'WP_INFORMES'; end; ImagenPNG := GetResourceAsPNG(CadenaAux); try (Objeto.Controls[i] as TImage).Picture.Assign(ImagenPNG); finally ImagenPNG.Free; end; end; if Objeto.Controls[i] is TRdxBotonLateral then with Objeto.Controls[i] as TRdxBotonLateral do begin Height := 50; Color := DarColorEntidad(TextoEntidad, 'Color3'); ColorFocused := DarColorEntidad('General', 'ControlFocusColor'); ColorDown := DarColorEntidad(TextoEntidad, 'Color2'); ColorBorder := DarColorEntidad(TextoEntidad, 'Color3'); ColorHighLight := DarColorEntidad(TextoEntidad, 'Color2'); ColorShadow := DarColorEntidad(TextoEntidad, 'Color2'); Font.Color := clBlack; Font.Style := []; FontDown.Color := clWhite; FontDown.Style := [fsBold]; end; if csAcceptsControls in Objeto.Controls[i].ControlStyle then ConfigurarBarraLateral(Objeto.Controls[i] as TWinControl, Entidad) end; end; procedure ConfigurarFrame(Objeto : TWinControl; Entidad : TRdxEntidad); var i : integer; TextoEntidad : String; ImagenPNG : TPNGObject; CadenaAux : String; begin TextoEntidad := DarNombreGrupo(Entidad); if (Objeto is TCustomForm) then (Objeto as TCustomForm).Color := DarColorEntidad('General', 'BackgroundColor'); for i := 0 to Objeto.ComponentCount-1 do begin if Objeto.Components[i].Name = 'imgSombra' then begin ImagenPNG := GetResourceAsPNG('SOMBRA'); try (Objeto.Components[i] as TImage).Picture.Assign(ImagenPNG); finally ImagenPNG.Free; end; end; { Esto es para que no falle cuando la entidad es EntVacia porque en el fichero de colores no está definida esa entidad. } if Entidad = entVacia then Continue; if (Objeto.Components[i] is TRdxCabecera) then begin (Objeto.Components[i] as TRdxCabecera).Font.Color := DarColorEntidad(TextoEntidad, 'Color1'); end; if (Objeto.Components[i] is TRdxPagesControl) then begin (Objeto.Components[i] as TRdxPagesControl).ColorTab := DarColorEntidad(TextoEntidad, 'Color3'); (Objeto.Components[i] as TRdxPagesControl).FontTab.Color := DarColorEntidad(TextoEntidad, 'Color1'); end; if (Objeto.Components[i] is TRdxPanelTituloOperacion) then begin (Objeto.Components[i] as TRdxPanelTituloOperacion).Color := DarColorEntidad(TextoEntidad, 'Color3'); (Objeto.Components[i] as TRdxPanelTituloOperacion).Font.Color := DarColorEntidad(TextoEntidad, 'Color1'); end; if (Objeto.Components[i] is TRdxBarraSuperior) and (Objeto.Components[i].Name = 'pnlExtra') then begin (Objeto.Components[i] as TRdxBarraSuperior).Color := $00D9E5E9; end; if (Objeto.Components[i] is TRdxBarraSuperior) and (Objeto.Components[i].Name <> 'pnlExtra') then begin (Objeto.Components[i] as TRdxBarraSuperior).Color := DarColorEntidad(TextoEntidad, 'Color1'); (Objeto.Components[i] as TRdxBarraSuperior).Font.Color := DarColorEntidad(TextoEntidad, 'Color3'); end; if ((Objeto.Components[i] is TRdxBotonSuperior) or (Objeto.Components[i] is TRdxBotonMenu)) then begin with (Objeto.Components[i] as TRdxBoton) do begin Color := DarColorEntidad(TextoEntidad, 'Color1'); ColorFocused := DarColorEntidad(TextoEntidad, 'Color2'); ColorDown := DarColorEntidad(TextoEntidad, 'Color2'); ColorBorder := DarColorEntidad(TextoEntidad, 'Color3'); ColorHighLight := DarColorEntidad(TextoEntidad, 'Color2'); ColorShadow := DarColorEntidad(TextoEntidad, 'Color2'); Font.Color := DarColorEntidad(TextoEntidad, 'Color3'); Font.Style := [fsBold]; FontDown.Color := DarColorEntidad(TextoEntidad, 'Color1'); FontDown.Style := [fsBold]; end; end; if Objeto.Components[i] is TPopupMenu2000 then begin with (Objeto.Components[i] as TPopupMenu2000).Options.Colors do begin Bevel := DarColorEntidad(TextoEntidad, 'Color3'); BevelShadow := DarColorEntidad(TextoEntidad, 'Color3'); Frame := DarColorEntidad(TextoEntidad, 'Color2'); FrameShadow := DarColorEntidad(TextoEntidad, 'Color2'); Border := DarColorEntidad(TextoEntidad, 'Color1'); Highlight := DarColorEntidad(TextoEntidad, 'Color3'); HighlightText := DarColorEntidad(TextoEntidad, 'Color1'); Pressed := DarColorEntidad(TextoEntidad, 'Color2'); PressedText := DarColorEntidad(TextoEntidad, 'Color1'); Line := DarColorEntidad(TextoEntidad, 'Color2'); Menu := DarColorEntidad(TextoEntidad, 'Color1'); MenuText := DarColorEntidad(TextoEntidad, 'Color3'); end; with (Objeto.Components[i] as TPopupMenu2000).Options.Margins do begin Border := 2; Bevel := 1; Frame := 1; end; end; if ((Objeto.Components[i] is TWinControl) and (csAcceptsControls in (Objeto.Components[i] as TWinControl).ControlStyle)) then ConfigurarFrame(Objeto.Components[i] as TWinControl, Entidad) end; end; function PuedeSincronizar : boolean; var Outlook: TOutlookApplication; begin Result := False; Outlook := TOutlookApplication.Create(nil); try try Outlook.Connect; Outlook.Disconnect; Result := True; except end; finally Outlook.Free; end; end; initialization ListaBD := NIL; ListaInformes := NIL; FColores := NIL; finalization if ListaBD <> NIL then FreeAndNil(ListaBD); if ListaInformes <> NIL then FreeAndNil(ListaInformes); if FColores <> NIL then FreeAndNil(FColores); end.