AlonsoYSal_FactuGES2/Source/ApplicationBase/Ejercicios/Views/uEditorEjercicio.pas
2019-11-18 10:36:42 +00:00

243 lines
7.1 KiB
ObjectPascal
Raw Permalink Blame History

unit uEditorEjercicio;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uEditorDBItem, ToolWin, ComCtrls, JvExControls, JvComponent,
uViewEjercicio, uBizEjercicios, 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,
uViewEjercicios, uIEditorEjercicio, uEjerciciosController, JvExComCtrls,
JvStatusBar, dxLayoutLookAndFeels, uDAInterfaces, JSDialog, dxGDIPlusClasses;
type
TfEditorEjercicio = class(TfEditorDBItem, IEditorEjercicio)
dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel;
JsNuevoEjercicioDialog: TJSDialog;
procedure FormShow(Sender: TObject);
procedure dsDataTableDataChange(Sender: TObject; Field: TField);
procedure CustomEditorClose(Sender: TObject; var Action: TCloseAction);
protected
FController : IEjerciciosController;
FEjercicio: IBizEjercicio;
FViewEjercicio : IViewEjercicio;
function GetController : IEjerciciosController;
procedure SetController (const Value : IEjerciciosController); virtual;
function GetEjercicio: IBizEjercicio; virtual;
procedure SetEjercicio(const Value: IBizEjercicio); virtual;
function GetViewEjercicio: IViewEjercicio;
procedure SetViewEjercicio(const Value: IViewEjercicio);
property ViewEjercicio: IViewEjercicio read GetViewEjercicio write SetViewEjercicio;
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 Ejercicio: IBizEjercicio read GetEjercicio write SetEjercicio;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
{$R *.dfm}
uses
uCustomEditor, uDataModuleEjercicios, uDataModuleBase, uDialogUtils;
function ShowEditorEjercicio (ABizObject : TDADataTableRules): TModalResult;
var
AEditor: TfEditorEjercicio;
begin
AEditor := TfEditorEjercicio.Create(Application);
try
AEditor.Ejercicio := (ABizObject as IBizEjercicio);
Result := AEditor.ShowModal;
finally
AEditor.Release;
end;
end;
{
******************************* TfEditorEjercicio *******************************
}
function TfEditorEjercicio.GetEjercicio: IBizEjercicio;
begin
Result := FEjercicio;
end;
function TfEditorEjercicio.GetController: IEjerciciosController;
begin
Result := FController;
end;
function TfEditorEjercicio.GetViewEjercicio: IViewEjercicio;
begin
Result := FViewEjercicio;
end;
procedure TfEditorEjercicio.GuardarInterno;
var
bEsNuevo: Boolean;
Respuesta : Integer;
AEjercicio: IBizEjercicio;
begin
inherited;
bEsNuevo := FEjercicio.EsNuevo;
//Si el ejercicio guardado es nuevo generamos el pgc
if bEsNuevo then
begin
Respuesta := JsNuevoEjercicioDialog.Execute;
if Respuesta <> IDCANCEL then
begin
case JsNuevoEjercicioDialog.CustomButtonResult of
300 : begin // No generar PGC
FController.Guardar(FEjercicio);
end;
200 : begin // Utilizar un ejercicio anterior para copiar el PGC, OJO ORDEN MUY IMPORTANTE
AEjercicio := FController.ElegirEjercicio(FController.BuscarTodos);
if Assigned(AEjercicio) then
begin
FController.Guardar(FEjercicio);
FController.GenerarPCG(AEjercicio.ID, FEjercicio.ID);
end;
end;
100 : begin // Utilizar el PGC base OJO ORDEN MUY IMPORTANTE
FController.Guardar(FEjercicio);
FController.GenerarPCG(0, FEjercicio.ID);
end;
end;
end;
end
//Es una modificaci<63>n
else FController.Guardar(FEjercicio);
Modified := False;
RefrescarInterno; //Es necesario sino no se actualiza el campo ACTIVO de todas las tuplas
end;
procedure TfEditorEjercicio.PonerTitulos(const ATitulo: string);
var
FTitulo : String;
begin
if Assigned(Ejercicio) then
begin
if Ejercicio.EsNuevo then
FTitulo := 'Nuevo ejercicio'
else
FTitulo := 'Ejercicio' + ' - ' + Ejercicio.NOMBRE;
end;
inherited PonerTitulos(FTitulo);
end;
procedure TfEditorEjercicio.SetEjercicio(const Value: IBizEjercicio);
begin
FEjercicio := Value;
dsDataTable.DataTable := FEjercicio.DataTable;
if Assigned(FViewEjercicio) and Assigned(Ejercicio) then
FViewEjercicio.Ejercicio := Ejercicio;
end;
procedure TfEditorEjercicio.SetController(const Value: IEjerciciosController);
begin
FController := Value;
end;
procedure TfEditorEjercicio.SetViewEjercicio(const Value: IViewEjercicio);
begin
FViewEjercicio := Value;
if Assigned(FViewEjercicio) and Assigned(Ejercicio) then
FViewEjercicio.Ejercicio := Ejercicio;
end;
procedure TfEditorEjercicio.FormShow(Sender: TObject);
begin
inherited;
if not Assigned(FViewEjercicio) then
raise Exception.Create('No hay ninguna vista asignada');
if not Assigned(Ejercicio) then
raise Exception.Create('No hay ning<6E>n almac<61>n asignado');
Ejercicio.DataTable.Active := True;
end;
destructor TfEditorEjercicio.Destroy;
begin
// Utilizar mejor OnClose;
inherited;
end;
procedure TfEditorEjercicio.AsignarVista;
var
AViewEjercicio: TfrViewEjercicio;
begin
AViewEjercicio := TfrViewEjercicio.create(Self);
with AViewEjercicio do
begin
Parent := pagGeneral;
Align := alClient;
// dxLayoutControlEjercicio.LookAndFeel := dxLayoutOfficeLookAndFeel1;
end;
ViewEjercicio := AViewEjercicio;
end;
constructor TfEditorEjercicio.Create(AOwner: TComponent);
begin
inherited;
pgPaginas.ActivePageIndex := 0;
AsignarVista;
end;
procedure TfEditorEjercicio.CustomEditorClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
dsDataTable.DataTable := NIL;
FViewEjercicio := NIL;
FEjercicio := NIL;
end;
procedure TfEditorEjercicio.dsDataTableDataChange(Sender: TObject;
Field: TField);
begin
inherited;
if Assigned(FEjercicio) and (not (FEjercicio.DataTable.Fetching) or
not (FEjercicio.DataTable.Opening) or not (FEjercicio.DataTable.Closing)) then
PonerTitulos;
end;
procedure TfEditorEjercicio.EliminarInterno;
begin
if (ShowConfirmMessage('Eliminar un ejercicio', '<27>Desea borrar este ejercicio?' + #10#13 + 'Tenga en cuenta que se eliminar<61> tambi<62>n todo el plan general contable asociado al ejercicio.') = IDYES) then
begin
inherited;
if not FController.Eliminar(FEjercicio) then
actRefrescar.Execute;
end;
end;
end.