unit uEditorAgentes;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  uEditorContactos, Menus, DB, uDADataTable, JvAppStorage,
  JvAppRegistryStorage, JvComponentBase, JvFormPlacement, ImgList, PngImageList,
  StdActns, ActnList, uCustomView, uViewBase, uViewBarraSeleccion, ComCtrls,
  TB2ExtItems, TBXExtItems, TBX, TB2Item, TB2Dock, TB2Toolbar, ExtCtrls,
  JvExControls, JvComponent, JvNavigationPane, uViewGridBase, uViewGrid,
  uViewContactos, uViewAgentes, uIEditorAgentes, pngimage, TBXStatusBars,
  JvExComCtrls, JvStatusBar, JSDialog, uContactosController, uDAInterfaces,
  dxGDIPlusClasses;

type
  TfEditorAgentes = class(TfEditorContactos, IEditorAgentes)
    frViewAgentes1: TfrViewAgentes;
    JsPrevisualizarDialog: TJSDialog;
    JsImprimirDialog: TJSDialog;
    JsListaContactosNoEliminados: TJSDialog;

  protected
    procedure EliminarInterno; override;

  public
    constructor Create(AOwner: TComponent); override;
    procedure PonerTitulos(const ATitulo: string = ''); override;
  end;

implementation

uses
  uGridStatusUtils, uEditorGridBase, uDataModuleUsuarios, uDialogUtils, uBizContactos,
  uAgentesController, uDBSelectionListUtils, uFactuGES_App;

{$R *.dfm}

constructor TfEditorAgentes.Create(AOwner: TComponent);
begin
  inherited;
  ViewGrid := frViewAgentes1;
end;

procedure TfEditorAgentes.EliminarInterno;
var
  AContactos: IBizContacto;
  AllItems: Boolean;
begin
  AContactos := Nil;
  AllItems := False;

  if MultiSelect and Assigned(ViewGrid) then
     AllItems :=  (ViewGrid.NumSeleccionados > 1);

  if AllItems then
  begin
    if (Application.MessageBox('¿Desea borrar los agentes seleccionados?', 'Atención', MB_YESNO) = IDYES) then
    begin
      SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Contactos as ISeleccionable).SelectedRecords);
      AContactos := (Controller as IAgentesController).ExtraerSeleccionados(Contactos) as IBizContacto;
    end
  end
  else begin
    if (Application.MessageBox('¿Desea borrar el agente seleccionado?', 'Atención', MB_YESNO) = IDYES) then
        AContactos := Contactos;
  end;

  if Assigned(AContactos) then
  begin
    (FController as IAgentesController).Eliminar(AContactos, AllItems);
    if AllItems then
    begin
      if (AContactos.DataTable.RecordCount > 0) then
      begin
        with  AContactos.DataTable do
        begin
          First;
          while not EOF do
          begin
            JsListaContactosNoEliminados.Content.Add('Agente: ' + AContactos.NOMBRE);
            Next;
          end;
        end;
        JsListaContactosNoEliminados.Execute;
      end;
      actRefrescar.Execute;
    end;
  end;

  ViewGrid.GotoFirst;
end;

procedure TfEditorAgentes.PonerTitulos(const ATitulo: string);
var
  FTitulo : String;
begin
  FTitulo := 'Lista de agentes - ' + AppFactuGES.EmpresaActiva.NOMBRE;
  inherited PonerTitulos(FTitulo);
end;

end.
