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; actAceptado: TAction; actRechazado: TAction; actPendiente: TAction; N3: TMenuItem; Aceptado1: TMenuItem; Rechazado1: TMenuItem; Pendiente1: TMenuItem; TBXItem36: TTBXItem; TBXSeparatorItem16: TTBXSeparatorItem; TBXItem38: TTBXItem; 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); procedure actAceptadoExecute(Sender: TObject); procedure actRechazadoExecute(Sender: TObject); procedure actPendienteExecute(Sender: TObject); procedure OnListaAnosChange(Sender: TObject; const Text: string); procedure FormShow(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; procedure CambiarEstado(const NuevoEstado: String); 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 cxControls, uDataModulePresupuestos, uEditorUtils, uEditorBase, DateUtils, uDataModuleMontajes, uDBSelectionList, uBizInformesBase; {$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; if Assigned(FPresupuestos) then begin //Se guarda el where de la sentencia origen, por si el editor tiene filtros que //afecten a este where y en un futuro se desea volver al where origen (filtro de año)) WhereDataTable := FPresupuestos.DataTable.Where.Clause; dsDataTable.DataTable := FPresupuestos.DataTable; if Assigned(ViewGrid) then (ViewGrid as IViewPresupuestos).Presupuestos := Presupuestos; end; 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; procedure TfEditorPresupuestos.actAceptadoExecute(Sender: TObject); begin CambiarEstado(SITUACION_ACEPTADO); end; procedure TfEditorPresupuestos.actRechazadoExecute(Sender: TObject); begin CambiarEstado(SITUACION_RECHAZADO); end; procedure TfEditorPresupuestos.actPendienteExecute(Sender: TObject); begin CambiarEstado(SITUACION_PENDIENTE); end; procedure TfEditorPresupuestos.CambiarEstado(const NuevoEstado: String); begin ViewGrid.SyncFocusedRecordsFromGrid; ShowHourglassCursor; Presupuestos.DataTable.DisableControls; try if not (Presupuestos.DataTable.State in dsEditModes) then begin Presupuestos.DataTable.Edit; Presupuestos.SITUACION := NuevoEstado; Presupuestos.FECHADECISION := Today; Presupuestos.DataTable.Post; Presupuestos.DataTable.ApplyUpdates; if (NuevoEstado = SITUACION_ACEPTADO) and (Presupuestos.REFERENCIA = '') then if (Application.MessageBox('¿Desea crear un montaje asociado a este presupuesto?', 'Atención', MB_YESNO) = IDYES) then dmMontajes.NuevoMontaje(Nil, Presupuestos); end; finally Presupuestos.DataTable.EnableControls; HideHourglassCursor; end; end; procedure TfEditorPresupuestos.OnListaAnosChange(Sender: TObject; const Text: string); var aAux : ISelectedRowList; begin dmPresupuestos.FiltrarAno(Presupuestos, WhereDataTable, Text); if Presupuestos.DataTable.Active then actRefrescar.Execute; // Quitar las selecciones que hubiera anteriormente porque ya no valen if Supports(Presupuestos, ISelectedRowList, aAux) then if (aAux.SelectedRows.Count > 0) then aAux.SelectedRows.Clear; end; procedure TfEditorPresupuestos.FormShow(Sender: TObject); begin ListaAnos := dmPresupuestos.DarListaAnosPresupuestos; cbxListaAnos.OnChange := OnListaAnosChange; //OJO SIEMPRE ANTES DEL INHERITED inherited; end; initialization RegisterEditor(IBizPresupuestos, ShowEditorPresupuestos, etItems); RegisterEditor(IBizPresupuestos, ShowSelectEditorPresupuestos, etSelectItems); finalization end.