unit uEditorPresupuestos; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, uCustomEditor, uEditorGrid, uBizPresupuestosCliente, ImgList, PngImageList, StdActns, ActnList, TB2ExtItems, TBXExtItems, TBX, TB2Item, TB2Dock, TB2Toolbar, JvExControls, JvComponent, JvNavigationPane, uViewPresupuestos, Menus, DB, uDADataTable, ComCtrls, uViewGrid, uDAScriptingProvider, uDACDSDataTable, JvAppStorage, JvAppRegistryStorage, JvFormPlacement, pngimage, ExtCtrls, uCustomView, uViewBase, uViewBarraSeleccion, JvComponentBase; type IEditorPresupuestos = interface(IEditorGrid) ['{7E6689A4-BEE7-4B36-80D8-411FA1B344F7}'] function GetPresupuestos: IBizPresupuestos; procedure SetPresupuestos(const Value: IBizPresupuestos); property Presupuestos: IBizPresupuestos read GetPresupuestos write SetPresupuestos; end; TfEditorPresupuestos = class(TfEditorGrid, IEditorPresupuestos) frViewBarraSeleccion: TfrViewBarraSeleccion; procedure actEliminarExecute(Sender: TObject); procedure actModificarExecute(Sender: TObject); procedure actNuevoExecute(Sender: TObject); procedure frViewBarraSeleccionactSeleccionarExecute(Sender: TObject); procedure frViewBarraSeleccionbCancelarClick(Sender: TObject); procedure actDuplicarExecute(Sender: TObject); procedure frViewBarraSeleccionactSeleccionarUpdate(Sender: TObject); private FPresupuestos: IBizPresupuestos; protected function GetPresupuestos: IBizPresupuestos; function GetSelectionBarVisible: Boolean; procedure SetPresupuestos(const Value: IBizPresupuestos); procedure SetSelectionBarVisible(const Value: Boolean); procedure SetViewGrid(const Value: IViewGrid); override; public constructor Create(AOwner: TComponent); override; destructor Destroy; override; property Presupuestos: IBizPresupuestos read GetPresupuestos write SetPresupuestos; property SelectionBarVisible: Boolean read GetSelectionBarVisible write SetSelectionBarVisible; end; var fEditorPresupuestos : TfEditorPresupuestos; implementation uses uDataModulePresupuestos, uEditorUtils, uEditorBase; {$R *.DFM} function ShowEditorPresupuestos (ABizObject : TDADataTableRules) : TModalResult; var AEditor: TfEditorPresupuestos; begin AEditor := TfEditorPresupuestos.Create(Application); try AEditor.Presupuestos := (ABizObject as IBizPresupuestos); Result := AEditor.ShowModal; finally AEditor.Release; end; end; function ShowSelectEditorPresupuestos (ABizObject : TDADataTableRules) : TModalResult; var AEditor: TfEditorPresupuestos; begin AEditor := TfEditorPresupuestos.Create(Application); try AEditor.Presupuestos := (ABizObject as IBizPresupuestos); AEditor.SelectionBarVisible := True; Result := AEditor.ShowModal; finally AEditor.Release; end; end; { TfEditorPresupuestos } { ***************************** TfEditorPresupuestos ***************************** } constructor TfEditorPresupuestos.Create(AOwner: TComponent); begin inherited; ViewGrid := CreateView(TfrViewPresupuestos) as IViewPresupuestos; end; destructor TfEditorPresupuestos.Destroy; begin FPresupuestos := NIL; inherited; end; procedure TfEditorPresupuestos.actEliminarExecute(Sender: TObject); begin if (Application.MessageBox('¿Desea borrar este presupuesto?', 'Atención', MB_YESNO) = IDYES) then begin inherited; ViewGrid.RefreshGrid; end; end; procedure TfEditorPresupuestos.actModificarExecute(Sender: TObject); begin inherited; Presupuestos.Show; ViewGrid.RefreshGrid; ViewGrid.SyncFocusedRecordsFromDataSet; end; procedure TfEditorPresupuestos.actNuevoExecute(Sender: TObject); begin inherited; Presupuestos.Insert; Presupuestos.Show; ViewGrid.RefreshGrid; ViewGrid.SyncFocusedRecordsFromDataSet; end; procedure TfEditorPresupuestos.frViewBarraSeleccionactSeleccionarExecute( Sender: TObject); begin inherited; if (Presupuestos.DataTable.RecordCount > 0) then begin ViewGrid.SyncFocusedRecordsFromGrid; ModalResult := mrOK; end; end; procedure TfEditorPresupuestos.frViewBarraSeleccionbCancelarClick(Sender: TObject); begin inherited; frViewBarraSeleccion.actCancelarExecute(Sender); end; function TfEditorPresupuestos.GetPresupuestos: IBizPresupuestos; begin Result := FPresupuestos; end; function TfEditorPresupuestos.GetSelectionBarVisible: Boolean; begin Result := frViewBarraSeleccion.Visible end; procedure TfEditorPresupuestos.SetPresupuestos(const Value: IBizPresupuestos); begin FPresupuestos := Value; dsDataTable.DataTable := FPresupuestos.DataTable; if Assigned(ViewGrid) then (ViewGrid as IViewPresupuestos).Presupuestos := Presupuestos; end; procedure TfEditorPresupuestos.SetSelectionBarVisible(const Value: Boolean); begin frViewBarraSeleccion.Visible := True; ViewGrid.OnDblClick := frViewBarraSeleccion.actSeleccionar.OnExecute; end; procedure TfEditorPresupuestos.SetViewGrid(const Value: IViewGrid); begin inherited; if Assigned(ViewGrid) and Assigned(Presupuestos) then (ViewGrid as IViewPresupuestos).Presupuestos := Presupuestos; end; procedure TfEditorPresupuestos.actDuplicarExecute(Sender: TObject); var APresupuesto : IBizPresupuestos; begin inherited; APresupuesto := dmPresupuestos.GetPresupuesto(Presupuestos.CODIGO); Presupuestos.Insert; Presupuestos.CopyFrom(APresupuesto); Presupuestos.DataTable.ApplyUpdates; ViewGrid.RefreshGrid; ViewGrid.GotoFirst; end; procedure TfEditorPresupuestos.frViewBarraSeleccionactSeleccionarUpdate( Sender: TObject); begin inherited; (Sender as TAction).Enabled := (Presupuestos.DataTable.RecordCount > 0); end; initialization RegisterEditor(IBizPresupuestos, ShowEditorPresupuestos, etItems); RegisterEditor(IBizPresupuestos, ShowSelectEditorPresupuestos, etSelectItems); finalization end.