unit uViewDocumentosAsociados; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewBase, ComCtrls, ShlObj, cxShellCommon, Menus, cxControls, DB, cxContainer, cxShellListView, ExtCtrls, ActnList, StdCtrls, JvComponent, JvChangeNotify, uBizDocumentosAsociados, JvComponentBase; type IViewDocumentosAsociados = interface(IViewBase) ['{38C44437-BAC5-4155-A737-4A448062653C}'] function GetGestorDocumentos: TGestorDocumentos; procedure SetGestorDocumentos(const Value: TGestorDocumentos); property GestorDocumentos: TGestorDocumentos read GetGestorDocumentos write SetGestorDocumentos; end; TfrViewDocumentosAsociados = class(TfrViewBase, IViewDocumentosAsociados) Panel10: TPanel; Panel11: TPanel; explo: TcxShellListView; pnlBarraDocumentos: TPanel; OpenDialog1: TOpenDialog; ActionList1: TActionList; actAnadirDocumento: TAction; actElliminarDocumento: TAction; actAbrirDocumento: TAction; Button1: TButton; Button2: TButton; GridPopupMenu: TPopupMenu; Modificar1: TMenuItem; N1: TMenuItem; Nuevo1: TMenuItem; Previsualizar1: TMenuItem; JvChangeNotify1: TJvChangeNotify; procedure actAnadirDocumentoExecute(Sender: TObject); procedure actElliminarDocumentoExecute(Sender: TObject); procedure actAbrirDocumentoExecute(Sender: TObject); procedure actAbrirDocumentoUpdate(Sender: TObject); procedure actElliminarDocumentoUpdate(Sender: TObject); procedure JvChangeNotify1ChangeNotify(Sender: TObject; Dir: String; Actions: TJvChangeActions); procedure CustomViewDestroy(Sender: TObject); procedure exploDblClick(Sender: TObject); private FGestorDocumentos: TGestorDocumentos; function GetGestorDocumentos: TGestorDocumentos; procedure SetGestorDocumentos(const Value: TGestorDocumentos); procedure HabilitarDocumentos; procedure DeshabilitarDocumentos; public property GestorDocumentos: TGestorDocumentos read GetGestorDocumentos write SetGestorDocumentos; end; var frViewDocumentosAsociados: TfrViewDocumentosAsociados; implementation {$R *.dfm} uses ShellApi, uSysFunc; procedure TfrViewDocumentosAsociados.actAnadirDocumentoExecute(Sender: TObject); var FicheroOrigen : String; i : Integer; begin if OpenDialog1.Execute then begin for i:=0 to OpenDialog1.Files.Count - 1 do begin FicheroOrigen := OpenDialog1.Files.Strings[i]; if not (length(trim(FicheroOrigen))=0) then if not FGestorDocumentos.AnadirDocumento(FicheroOrigen) then raise Exception.Create('Error al añadir el documento'); end; end; Explo.Root.CustomPath := Explo.Root.CustomPath; end; procedure TfrViewDocumentosAsociados.actElliminarDocumentoExecute(Sender: TObject); var i : Integer; cadena: String; begin if (Application.MessageBox('¿Desea eliminar los documentos seleccionados?', 'Atención', MB_YESNO) = IDYES) then begin for i:=0 to explo.InnerListView.Items.Count - 1 do begin if explo.InnerListView.Items[i].Selected then begin cadena := GetPidlName(explo.GetItemAbsolutePIDL(i)); if not SysUtils.DeleteFile(cadena) then raise Exception.Create('Error al eliminar el documento'); end; end; end; Explo.Root.CustomPath := Explo.Root.CustomPath; end; procedure TfrViewDocumentosAsociados.actAbrirDocumentoExecute(Sender: TObject); var FileHandle : Integer; cadena : String; begin if explo.InnerListView.SelCount <> 0 then begin cadena := GetPidlName(explo.GetItemAbsolutePIDL(explo.InnerListView.ItemFocused.Index)); ShellExecute(Handle, 'open', PAnsiChar(cadena), nil, nil, SW_SHOWNORMAL); end; end; procedure TfrViewDocumentosAsociados.actAbrirDocumentoUpdate(Sender: TObject); begin (Sender as TAction).Enabled := explo.InnerListView.SelCount <> 0; end; procedure TfrViewDocumentosAsociados.actElliminarDocumentoUpdate(Sender: TObject); begin (Sender as TAction).Enabled := explo.InnerListView.SelCount <> 0; end; function TfrViewDocumentosAsociados.GetGestorDocumentos: TGestorDocumentos; begin Result := FGestorDocumentos; end; procedure TfrViewDocumentosAsociados.SetGestorDocumentos(const Value: TGestorDocumentos); begin FGestorDocumentos := Value; if Assigned(FGestorDocumentos) then begin DeshabilitarDocumentos; FGestorDocumentos.HabilitarDirectorio; HabilitarDocumentos; end; end; procedure TfrViewDocumentosAsociados.DeshabilitarDocumentos; begin JvChangeNotify1.Active := False; JvChangeNotify1.Notifications.Clear; explo.Enabled := False; explo.Options.ShowNonFolders := False; explo.Root.CustomPath := FGestorDocumentos.RootDocumentos; end; procedure TfrViewDocumentosAsociados.HabilitarDocumentos; begin explo.Options.ShowNonFolders := True; explo.Root.CustomPath := FGestorDocumentos.darRutaDocumentos; JvChangeNotify1.Notifications.Clear; with JvChangeNotify1.Notifications.Add do begin Actions := [caChangeFileName, caChangeDirName]; Directory := explo.Root.CustomPath; end; JvChangeNotify1.Active := True; explo.Enabled := True; end; procedure TfrViewDocumentosAsociados.JvChangeNotify1ChangeNotify( Sender: TObject; Dir: String; Actions: TJvChangeActions); begin Explo.Root.CustomPath := Explo.Root.CustomPath; end; procedure TfrViewDocumentosAsociados.CustomViewDestroy(Sender: TObject); begin //Eliminaremos el directorio si no tiene documentos, solo tendremos direcctorios //en el caso que el presupuesto tenga documentos asociados RemoveDir(FGestorDocumentos.darRutaDocumentos); FGestorDocumentos := NIL; inherited; end; procedure TfrViewDocumentosAsociados.exploDblClick(Sender: TObject); begin inherited; actAbrirDocumento.Execute; end; end.