unit uEditorVendedores;

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, uIEditorVendedores, pngimage, TBXStatusBars,
  JvExComCtrls, JvStatusBar, JSDialog, uContactosController, uDAInterfaces,
  uViewVendedores;

type
  TfEditorVendedores = class(TfEditorContactos, IEditorVendedores)
    frViewVendedores1: TfrViewVendedores;
    JsPrevisualizarDialog: TJSDialog;
    JsImprimirDialog: TJSDialog;
    JsListaContactosNoEliminados: TJSDialog;
    
  protected
    procedure EliminarInterno; override;
    procedure ImprimirInterno; override;
    procedure PrevisualizarInterno; override;

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

implementation

uses
  uGridUtils, uEditorGridBase, uDataModuleUsuarios, uDialogUtils, uBizContactos,
  uVendedoresController, uDBSelectionListUtils, uFactuGES_App;

{$R *.dfm}

constructor TfEditorVendedores.Create(AOwner: TComponent);
begin
  inherited;
  ViewGrid := frViewVendedores1;
end;

procedure TfEditorVendedores.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 vendedores seleccionados?', 'Atención', MB_YESNO) = IDYES) then
    begin
      SeleccionarFilasDesdeGrid(ViewGrid._FocusedView, (Contactos as ISeleccionable).SelectedRecords);
      AContactos := (Controller as IVendedoresController).ExtraerSeleccionados(Contactos) as IBizContacto;
    end
  end
  else begin
    if (Application.MessageBox('¿Desea borrar el vendedor seleccionado?', 'Atención', MB_YESNO) = IDYES) then
        AContactos := Contactos;
  end;

  if Assigned(AContactos) then
  begin
    (FController as IVendedoresController).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('Vendedor: ' + AContactos.NOMBRE);
            Next;
          end;
        end;
        JsListaContactosNoEliminados.Execute;
      end;
      actRefrescar.Execute;
    end;
  end;

  ViewGrid.GotoFirst;
end;

procedure TfEditorVendedores.ImprimirInterno;
begin
  inherited;
end;

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

procedure TfEditorVendedores.PrevisualizarInterno;
begin
  inherited;
end;

end.
