unit uEditorPresupuesto; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uEditorItem, ImgList, PngImageList, StdActns, ActnList, TBX, TB2Item, TB2Dock, TB2Toolbar, ComCtrls, JvExControls, JvComponent, JvNavigationPane, uEditorDBItem, DB, uDADataTable, uBizPresupuestos, uViewPresupuesto, uCustomView, uViewBase, uViewTotales, uViewGrid, TBXDkPanels, ExtCtrls, uDAScriptingProvider, uDACDSDataTable, JvAppStorage, JvAppRegistryStorage, JvFormPlacement, pngimage, StdCtrls, Mask, DBCtrls, JvComponentBase, uIEditorPresupuesto, uPresupuestosController, uViewDetallesBase, uViewDetallesPresupuesto, dxLayoutLookAndFeels, uViewDatosYSeleccionCliente, JvExComCtrls, JvStatusBar; type TfEditorPresupuesto = class(TfEditorDBItem, IEditorPresupuesto) pagContenido: TTabSheet; frViewDetallesPresupuesto1: TfrViewDetallesPresupuesto; frViewTotales1: TfrViewTotales; dxLayoutLookAndFeelList1: TdxLayoutLookAndFeelList; dxLayoutOfficeLookAndFeel1: TdxLayoutOfficeLookAndFeel; frViewPresupuesto1: TfrViewPresupuesto; procedure FormShow(Sender: TObject); procedure dsDataTableDataChange(Sender: TObject; Field: TField); procedure CustomEditorClose(Sender: TObject; var Action: TCloseAction); procedure frViewTotales1edtDescuentoPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); procedure frViewTotales1edtIVAPropertiesValidate(Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); procedure frViewClientePresupuesto1edtlNombrePropertiesChange( Sender: TObject); procedure OnSituacionEditValueChanged(Sender: TObject); private FController : IPresupuestosController; FPresupuesto : IBizPresupuesto; FViewPresupuesto : IViewPresupuesto; // FViewDocumentosPresupuesto : IViewDocumentosAsociados; protected function GetController : IPresupuestosController; procedure SetController (const Value : IPresupuestosController); function GetPresupuesto: IBizPresupuesto; procedure SetPresupuesto(const Value: IBizPresupuesto); function GetViewPresupuesto: IViewPresupuesto; procedure SetViewPresupuesto(const Value: IViewPresupuesto); procedure GuardarInterno; override; procedure EliminarInterno; override; procedure ImprimirInterno; override; procedure PrevisualizarInterno; override; property ViewPresupuesto: IViewPresupuesto read GetViewPresupuesto write SetViewPresupuesto; procedure OnContactoChanged(Sender : TObject); //DOCUMENTOS ASOCIADOS // function GetViewDocumentosPresupuesto: IViewDocumentosAsociados; // procedure SetViewDocumentosPresupuesto(const Value: IViewDocumentosAsociados); // property ViewDocumentosPresupuesto: IViewDocumentosAsociados read GetViewDocumentosPresupuesto write // SetViewDocumentosPresupuesto; public procedure PonerTitulos(const ATitulo: string = ''); override; property Controller : IPresupuestosController read GetController write SetController; property Presupuesto: IBizPresupuesto read GetPresupuesto write SetPresupuesto; constructor Create(AOwner: TComponent); override; destructor Destroy; override; end; implementation {$R *.dfm} uses DateUtils, schPresupuestosClient_Intf, cxDBEdit, uBizContactos, uDataModuleUsuarios, uDataModulePresupuestos; { TfEditorPresupuesto } function TfEditorPresupuesto.GetController: IPresupuestosController; begin Result := FController; end; function TfEditorPresupuesto.GetPresupuesto: IBizPresupuesto; begin Result := FPresupuesto; end; function TfEditorPresupuesto.GetViewPresupuesto: IViewPresupuesto; begin Result := FViewPresupuesto; end; procedure TfEditorPresupuesto.GuardarInterno; begin inherited; if (FPresupuesto.SITUACION = SITUACION_PENDIENTE) and (DateOf(FPresupuesto.FECHA_PRESUPUESTO) < DateOf(Now)) then begin if (MessageDlg('Ha realizado modificaciones en este presupuesto' + #10#13 + 'y la fecha del presupuesto es antigua. ¿Desea actualizarla a día de hoy?' + #10#13 + '(La nueva fecha de validez del presupuesto se calculará automáticamente)', mtConfirmation, [mbYes, mbNo], 0) = mrYes) then begin FPresupuesto.Edit; FPresupuesto.FECHA_PRESUPUESTO := DateOf(Now); FPresupuesto.Post; end; end; FController.Guardar(FPresupuesto); Modified := False; end; procedure TfEditorPresupuesto.ImprimirInterno; begin inherited; FController.Print(FPresupuesto); end; procedure TfEditorPresupuesto.OnContactoChanged(Sender: TObject); begin FPresupuesto.Cliente := frViewPresupuesto1.frViewClientePresupuesto1.Cliente; end; procedure TfEditorPresupuesto.PonerTitulos(const ATitulo: string); var FTitulo : String; begin FTitulo := ATitulo; if (FTitulo = '') and Assigned(FPresupuesto) then begin if FPresupuesto.EsNuevo then FTitulo := 'Nuevo presupuesto' else FTitulo := 'Presupuesto' + ' - ' + FPresupuesto.Cliente.Nombre end; inherited PonerTitulos(FTitulo); Self.Caption := FTitulo + ' (' + dmUsuarios.EmpresaActual.NOMBRE + ')'; end; procedure TfEditorPresupuesto.PrevisualizarInterno; begin inherited; FController.Preview(FPresupuesto); end; procedure TfEditorPresupuesto.SetController(const Value: IPresupuestosController); begin FController := Value; if Assigned(FController) then begin frViewPresupuesto1.frViewClientePresupuesto1.Controller := Controller.ClienteController; frViewDetallesPresupuesto1.Controller := Controller.DetallesController; end; end; procedure TfEditorPresupuesto.SetPresupuesto(const Value: IBizPresupuesto); begin FPresupuesto := Value; if Assigned(FPresupuesto) then begin dsDataTable.DataTable := FPresupuesto.DataTable; frViewTotales1.DADataSource.DataTable := FPresupuesto.DataTable; if Assigned(FViewPresupuesto) then begin FViewPresupuesto.Presupuesto := Presupuesto; frViewPresupuesto1.frViewClientePresupuesto1.Cliente := Presupuesto.Cliente;//(Controller.ClienteController.Buscar(Presupuesto.ID_CLIENTE) as IBizCliente); frViewPresupuesto1.frViewClientePresupuesto1.OnClienteChanged := OnContactoChanged; frViewDetallesPresupuesto1.Detalles := FPresupuesto.Detalles; end; //DOCUMENTOS ASOCIADOS { if Assigned(FViewDocumentosPresupuesto) then begin FViewDocumentosPresupuesto.GestorDocumentos := (Presupuesto as IBizDocumentosAsociados).GestorDocumentos; FViewDocumentosPresupuesto.GestorDocumentos.ModoInsert := (Presupuesto.DataTable.State = dsInsert); end; } Presupuesto.DataTable.Active := True; end; end; procedure TfEditorPresupuesto.SetViewPresupuesto( const Value: IViewPresupuesto); begin FViewPresupuesto := Value; if Assigned(FViewPresupuesto) and Assigned(Presupuesto) then FViewPresupuesto.Presupuesto := Presupuesto; end; procedure TfEditorPresupuesto.FormShow(Sender: TObject); begin inherited; if not Assigned(FViewPresupuesto) then raise Exception.Create('No hay ninguna vista asignada'); if not Assigned(Presupuesto) then raise Exception.Create('No hay ningún presupuesto asignado'); //DOCUMENTOS ASOCIADOS //En el caso de no existir el gestor de documentos no habilitamos la vista { if Assigned(Presupuesto.GestorDocumentos) then begin ViewDocumentosPresupuesto := CreateView(TfrViewDocumentosAsociados) as IViewDocumentosAsociados; ViewDocumentosPresupuesto.ShowEmbedded(pagPlanos); end else pagPlanos.TabVisible := False; } pgPaginas.ActivePage := pagGeneral; frViewPresupuesto1.cbSituacion.Properties.OnEditValueChanged := OnSituacionEditValueChanged; end; procedure TfEditorPresupuesto.frViewClientePresupuesto1edtlNombrePropertiesChange( Sender: TObject); begin inherited; PonerTitulos; end; procedure TfEditorPresupuesto.OnSituacionEditValueChanged(Sender: TObject); begin inherited; if (csDestroying in ComponentState) then Exit; { ATENCION! Añadiendo un presupuesto nuevo falla al pulsar 'ESC' sin haber introducido nada PERO no tiene que haber ningún presupuesto en la empresa. Error: StartChange has already been called; cannot log more than one change at a time. } // FController.CambiarSituacion(FPresupuesto, VarToStr((Sender as TcxDBComboBox).EditValue), Date, False); end; procedure TfEditorPresupuesto.frViewTotales1edtDescuentoPropertiesValidate( Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); begin inherited; FPresupuesto.DESCUENTO := DisplayValue; end; procedure TfEditorPresupuesto.frViewTotales1edtIVAPropertiesValidate( Sender: TObject; var DisplayValue: Variant; var ErrorText: TCaption; var Error: Boolean); begin inherited; FPresupuesto.IVA := DisplayValue; end; constructor TfEditorPresupuesto.Create(AOwner: TComponent); begin inherited; FViewPresupuesto := NIL; FPresupuesto := NIL; pgPaginas.ActivePageIndex := 0; ViewPresupuesto := frViewPresupuesto1; //DOCUMENTOS ASOCIADOS // FViewDocumentosPresupuesto := Nil; end; procedure TfEditorPresupuesto.CustomEditorClose(Sender: TObject; var Action: TCloseAction); begin inherited; frViewPresupuesto1.cbSituacion.Properties.OnEditValueChanged := Nil; dsDataTable.DataTable := NIL; frViewTotales1.DADataSource.DataTable := NIL; FViewPresupuesto := NIL; FPresupuesto := NIL; end; destructor TfEditorPresupuesto.Destroy; begin // Utilizar mejor OnClose; //DOCUMENTOS ASOCIADOS // FViewDocumentosPresupuesto := NIL; inherited; end; procedure TfEditorPresupuesto.dsDataTableDataChange(Sender: TObject; Field: TField); begin inherited; if Assigned(FPresupuesto) and (not (FPresupuesto.DataTable.Fetching) or not (FPresupuesto.DataTable.Opening) or not (FPresupuesto.DataTable.Closing)) then PonerTitulos; end; procedure TfEditorPresupuesto.EliminarInterno; begin if (Application.MessageBox('¿Desea borrar este presupuesto?', 'Atención', MB_YESNO) = IDYES) then begin FController.Eliminar(Presupuesto); inherited; end end; { function TfEditorPresupuesto.GetViewDocumentosPresupuesto: IViewDocumentosAsociados; begin Result := FViewDocumentosPresupuesto; end; procedure TfEditorPresupuesto.SetViewDocumentosPresupuesto(const Value: IViewDocumentosAsociados); begin FViewDocumentosPresupuesto := Value; if Assigned(FViewDocumentosPresupuesto) and Assigned(Presupuesto) then FViewDocumentosPresupuesto.GestorDocumentos := (Presupuesto as IBizDocumentosASociados).GestorDocumentos; end; } end.