AlonsoYSal_FactuGES2/Source/Modulos/Contabilidad/Views/uEditorApunte.pas
2019-11-18 10:36:42 +00:00

212 lines
5.8 KiB
ObjectPascal
Raw Blame History

unit uEditorApunte;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uEditorDBItem, ToolWin, ComCtrls, JvExControls, JvComponent,
uBizApuntes, JvNavigationPane, ActnList,
uEditorBase, StdActns, TB2Dock, TB2Toolbar, TBX, ImgList, PngImageList,
TB2Item, uEditorItem, DB, uDADataTable, uEditorDBBase, JvFormAutoSize,
uDAScriptingProvider, uDACDSDataTable, StdCtrls, pngimage, ExtCtrls,
TBXDkPanels, JvButton, AppEvnts, uCustomView, uViewBase,
JvAppStorage, JvAppRegistryStorage, JvFormPlacement, JvComponentBase,
uViewApuntes, uIEditorApunte, uApuntesController, JvExComCtrls,
JvStatusBar, dxLayoutLookAndFeels, uDAInterfaces, uViewDetallesGenerico,
cxDropDownEdit, cxCalendar, cxDBEdit, dxLayoutControl,
cxContainer, cxEdit, cxTextEdit, cxMaskEdit, cxSpinEdit, cxControls,
uViewApunte;
type
TfEditorApunte = class(TfEditorDBItem, IEditorApunte)
dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel;
procedure FormShow(Sender: TObject);
procedure dsDataTableDataChange(Sender: TObject; Field: TField);
procedure CustomEditorClose(Sender: TObject; var Action: TCloseAction);
protected
FController : IApuntesController;
FApunte: IBizApunte;
FViewApunte : IViewApunte;
function GetController : IApuntesController;
procedure SetController (const Value : IApuntesController); virtual;
function GetApunte: IBizApunte; virtual;
procedure SetApunte(const Value: IBizApunte); virtual;
function GetViewApunte: IViewApunte;
procedure SetViewApunte(const Value: IViewApunte);
property ViewApunte: IViewApunte read GetViewApunte write SetViewApunte;
procedure GuardarInterno; override;
procedure EliminarInterno; override;
procedure PonerTitulos(const ATitulo: string = ''); override;
//Si queremos crear otra vista para el editor heredado solo tendriamos que
//sobreescribir este metodo
procedure AsignarVista; virtual;
public
property Apunte: IBizApunte read GetApunte write SetApunte;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
{$R *.dfm}
uses
uCustomEditor, uDataModuleBase, uFactuGES_App;
function ShowEditorApunte (ABizObject : TDADataTableRules): TModalResult;
var
AEditor: TfEditorApunte;
begin
AEditor := TfEditorApunte.Create(Application);
try
AEditor.Apunte := (ABizObject as IBizApunte);
Result := AEditor.ShowModal;
finally
AEditor.Release;
end;
end;
{
******************************* TfEditorApunte *******************************
}
function TfEditorApunte.GetApunte: IBizApunte;
begin
Result := FApunte;
end;
function TfEditorApunte.GetController: IApuntesController;
begin
Result := FController;
end;
function TfEditorApunte.GetViewApunte: IViewApunte;
begin
Result := FViewApunte;
end;
procedure TfEditorApunte.GuardarInterno;
begin
inherited;
FController.Guardar(FApunte);
Modified := False;
end;
procedure TfEditorApunte.PonerTitulos(const ATitulo: string);
var
FTitulo : String;
begin
if Assigned(Apunte) then
begin
if Apunte.EsNuevo then
FTitulo := 'Nuevo apunte - ' + AppFactuGES.EjercicioActivo.NOMBRE + ' (' + AppFactuGES.EjercicioActivo.ESTADO + ')'
else
FTitulo := 'Apunte' + ' - ' + AppFactuGES.EjercicioActivo.NOMBRE + ' (' + AppFactuGES.EjercicioActivo.ESTADO + ')';
end;
inherited PonerTitulos(FTitulo);
end;
procedure TfEditorApunte.SetApunte(const Value: IBizApunte);
begin
FApunte := Value;
dsDataTable.DataTable := FApunte.DataTable;
if Assigned(FViewApunte) and Assigned(Apunte) then
FViewApunte.Apunte := Apunte;
end;
procedure TfEditorApunte.SetController(const Value: IApuntesController);
begin
FController := Value;
// if Assigned(ViewApunte) then
// ViewApunte.Controller := FController;
end;
procedure TfEditorApunte.SetViewApunte(const Value: IViewApunte);
begin
FViewApunte := Value;
if Assigned(FViewApunte) and Assigned(Apunte) then
FViewApunte.Apunte := Apunte;
end;
procedure TfEditorApunte.FormShow(Sender: TObject);
begin
inherited;
// if not Assigned(FViewApunte) then
// raise Exception.Create('No hay ninguna vista asignada');
if not Assigned(Apunte) then
raise Exception.Create('No hay ning<6E>n apunte asignado');
Apunte.DataTable.Active := True;
end;
destructor TfEditorApunte.Destroy;
begin
// Utilizar mejor OnClose;
inherited;
end;
procedure TfEditorApunte.AsignarVista;
var
AViewApunte: TfrViewApunte;
begin
AViewApunte := TfrViewApunte.create(Self);
with AViewApunte do
begin
Parent := pagGeneral;
Align := alClient;
// dxLayoutControlApunte.LookAndFeel := dxLayoutOfficeLookAndFeel1;
end;
ViewApunte := AViewApunte;
end;
constructor TfEditorApunte.Create(AOwner: TComponent);
begin
inherited;
FController := TApuntesController.Create;
pgPaginas.ActivePageIndex := 0;
AsignarVista;
end;
procedure TfEditorApunte.CustomEditorClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
dsDataTable.DataTable := NIL;
FController := Nil;
FViewApunte := NIL;
FApunte := NIL;
end;
procedure TfEditorApunte.dsDataTableDataChange(Sender: TObject;
Field: TField);
begin
inherited;
if Assigned(FApunte) and (not (FApunte.DataTable.Fetching) or
not (FApunte.DataTable.Opening) or not (FApunte.DataTable.Closing)) then
PonerTitulos;
end;
procedure TfEditorApunte.EliminarInterno;
begin
if (Application.MessageBox('<27>Desea borrar este apunte?', 'Atenci<63>n', MB_YESNO) = IDYES) then
begin
inherited;
if not FController.Eliminar(FApunte) then
actRefrescar.Execute;
end;
end;
end.