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

215 lines
6.1 KiB
ObjectPascal
Raw Blame History

unit uEditorSubCuenta;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, uEditorDBItem, ToolWin, ComCtrls, JvExControls, JvComponent,
uViewSubCuenta, uBizSubCuentas, 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,
uViewSubCuentas, uIEditorSubCuenta, uSubCuentasController, JvExComCtrls,
JvStatusBar, dxLayoutLookAndFeels, uDAInterfaces, dxGDIPlusClasses;
type
TfEditorSubCuenta = class(TfEditorDBItem, IEditorSubCuenta)
dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList;
dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel;
procedure FormShow(Sender: TObject);
procedure dsDataTableDataChange(Sender: TObject; Field: TField);
procedure CustomEditorClose(Sender: TObject; var Action: TCloseAction);
procedure actEliminarUpdate(Sender: TObject);
protected
FController : ISubCuentasController;
FSubCuenta: IBizSubCuenta;
FViewSubCuenta : IViewSubCuenta;
function GetController : ISubCuentasController;
procedure SetController (const Value : ISubCuentasController); virtual;
function GetSubCuenta: IBizSubCuenta; virtual;
procedure SetSubCuenta(const Value: IBizSubCuenta); virtual;
function GetViewSubCuenta: IViewSubCuenta;
procedure SetViewSubCuenta(const Value: IViewSubCuenta);
property ViewSubCuenta: IViewSubCuenta read GetViewSubCuenta write SetViewSubCuenta;
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 SubCuenta: IBizSubCuenta read GetSubCuenta write SetSubCuenta;
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
implementation
{$R *.dfm}
uses
uCustomEditor, uDataModuleBase, uFactuGES_App, uBizEjercicios;
function ShowEditorSubCuenta (ABizObject : TDADataTableRules): TModalResult;
var
AEditor: TfEditorSubCuenta;
begin
AEditor := TfEditorSubCuenta.Create(Application);
try
AEditor.SubCuenta := (ABizObject as IBizSubCuenta);
Result := AEditor.ShowModal;
finally
AEditor.Release;
end;
end;
{
******************************* TfEditorSubCuenta *******************************
}
function TfEditorSubCuenta.GetSubCuenta: IBizSubCuenta;
begin
Result := FSubCuenta;
end;
function TfEditorSubCuenta.GetController: ISubCuentasController;
begin
Result := FController;
end;
function TfEditorSubCuenta.GetViewSubCuenta: IViewSubCuenta;
begin
Result := FViewSubCuenta;
end;
procedure TfEditorSubCuenta.GuardarInterno;
begin
inherited;
FController.Guardar(FSubCuenta);
Modified := False;
end;
procedure TfEditorSubCuenta.PonerTitulos(const ATitulo: string);
var
FTitulo : String;
begin
if Assigned(SubCuenta) then
begin
if SubCuenta.EsNuevo then
FTitulo := 'Nueva subcuenta - ' + AppFactuGES.EjercicioActivo.NOMBRE
else
FTitulo := 'Cuenta' + ' - ' + SubCuenta.DESCRIPCION + ' - ' + AppFactuGES.EjercicioActivo.NOMBRE + ' (' + AppFactuGES.EjercicioActivo.ESTADO + ')';
end;
inherited PonerTitulos(FTitulo);
end;
procedure TfEditorSubCuenta.SetSubCuenta(const Value: IBizSubCuenta);
begin
FSubCuenta := Value;
dsDataTable.DataTable := FSubCuenta.DataTable;
if Assigned(FViewSubCuenta) and Assigned(SubCuenta) then
FViewSubCuenta.SubCuenta := SubCuenta;
end;
procedure TfEditorSubCuenta.SetController(const Value: ISubCuentasController);
begin
FController := Value;
if Assigned(ViewSubCuenta) then
ViewSubCuenta.Controller := FController;
end;
procedure TfEditorSubCuenta.SetViewSubCuenta(const Value: IViewSubCuenta);
begin
FViewSubCuenta := Value;
if Assigned(FViewSubCuenta) and Assigned(SubCuenta) then
FViewSubCuenta.SubCuenta := SubCuenta;
end;
procedure TfEditorSubCuenta.FormShow(Sender: TObject);
begin
inherited;
if not Assigned(FViewSubCuenta) then
raise Exception.Create('No hay ninguna vista asignada');
if not Assigned(SubCuenta) then
raise Exception.Create('No hay ning<6E>n almac<61>n asignado');
SubCuenta.DataTable.Active := True;
end;
destructor TfEditorSubCuenta.Destroy;
begin
// Utilizar mejor OnClose;
inherited;
end;
procedure TfEditorSubCuenta.actEliminarUpdate(Sender: TObject);
begin
inherited;
if (Sender as TAction).Enabled then
(Sender as TAction).Enabled := (SubCuenta.ESTADO = CTE_ABIERTO);
end;
procedure TfEditorSubCuenta.AsignarVista;
var
AViewSubCuenta: TfrViewSubCuenta;
begin
AViewSubCuenta := TfrViewSubCuenta.create(Self);
with AViewSubCuenta do
begin
Parent := pagGeneral;
Align := alClient;
dxLayoutControlSubCuenta.LookAndFeel := dxLayoutOfficeLookAndFeel1;
end;
ViewSubCuenta := AViewSubCuenta;
end;
constructor TfEditorSubCuenta.Create(AOwner: TComponent);
begin
inherited;
pgPaginas.ActivePageIndex := 0;
AsignarVista;
end;
procedure TfEditorSubCuenta.CustomEditorClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
dsDataTable.DataTable := NIL;
FViewSubCuenta := NIL;
FSubCuenta := NIL;
end;
procedure TfEditorSubCuenta.dsDataTableDataChange(Sender: TObject;
Field: TField);
begin
inherited;
if Assigned(FSubCuenta) and (not (FSubCuenta.DataTable.Fetching) or
not (FSubCuenta.DataTable.Opening) or not (FSubCuenta.DataTable.Closing)) then
PonerTitulos;
end;
procedure TfEditorSubCuenta.EliminarInterno;
begin
if (Application.MessageBox('<27>Desea borrar este SubCuenta?', 'Atenci<63>n', MB_YESNO) = IDYES) then
begin
inherited;
if not FController.Eliminar(FSubCuenta) then
actRefrescar.Execute;
end;
end;
end.