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; type TfEditorEjercicio = class(TfEditorDBItem, IEditorEjercicio) dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList; dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel; 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; 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; begin inherited; FController.Guardar(FEjercicio); Modified := False; end; procedure TfEditorEjercicio.PonerTitulos(const ATitulo: string); var FTitulo : String; begin if Assigned(Ejercicio) then begin if Ejercicio.EsNuevo then FTitulo := 'Nuevo almacén' else FTitulo := 'Almacén' + ' - ' + 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ún almacé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 (Application.MessageBox('¿Desea borrar este Ejercicio?', 'Atención', MB_YESNO) = IDYES) then begin inherited; if not FController.Eliminar(FEjercicio) then actRefrescar.Execute; end; end; end.