unit uEditorAsiento; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uEditorDBItem, ToolWin, ComCtrls, JvExControls, JvComponent, uViewAsiento, uBizAsientos, 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, uViewMensaje, JvAppStorage, JvAppRegistryStorage, JvFormPlacement, uViewAsientos; type IEditorAsiento = interface(IEditorDBItem) ['{D61A23CA-1C89-4734-B52C-CFD5AB807F3E}'] function GetAsiento: IBizAsiento; procedure SetAsiento(const Value: IBizAsiento); property Asiento: IBizAsiento read GetAsiento write SetAsiento; end; TfEditorAsiento = class(TfEditorDBItem, IEditorAsiento) frViewAsiento1: TfrViewAsiento; procedure FormShow(Sender: TObject); procedure dsDataTableDataChange(Sender: TObject; Field: TField); procedure actEliminarExecute(Sender: TObject); private FAsiento: IBizAsiento; FViewAsiento : IViewAsiento; protected function GetAsiento: IBizAsiento; virtual; procedure SetAsiento(const Value: IBizAsiento); virtual; function GetViewAsiento: IViewAsiento; procedure SetViewAsiento(const Value: IViewAsiento); property ViewAsiento: IViewAsiento read GetViewAsiento write SetViewAsiento; public property Asiento: IBizAsiento read GetAsiento write SetAsiento; constructor Create(AOwner: TComponent); override; destructor Destroy; override; end; implementation {$R *.dfm} uses uCustomEditor, uDataModuleAsientos, uDataModuleBase, uEditorUtils; function ShowEditorAsiento (ABizObject : TDADataTableRules): TModalResult; var AEditor: TfEditorAsiento; begin AEditor := TfEditorAsiento.Create(Application); try AEditor.Asiento := (ABizObject as IBizAsiento); Result := AEditor.ShowModal; finally AEditor.Release; end; end; { ******************************* TfEditorAsiento ******************************* } function TfEditorAsiento.GetAsiento: IBizAsiento; begin Result := FAsiento; end; function TfEditorAsiento.GetViewAsiento: IViewAsiento; begin Result := FViewAsiento; end; procedure TfEditorAsiento.SetAsiento(const Value: IBizAsiento); begin FAsiento := Value; dsDataTable.DataTable := FAsiento.DataTable; if Assigned(FViewAsiento) and Assigned(Asiento) then FViewAsiento.Asiento := Asiento; end; procedure TfEditorAsiento.SetViewAsiento(const Value: IViewAsiento); begin FViewAsiento := Value; if Assigned(FViewAsiento) and Assigned(Asiento) then FViewAsiento.Asiento := Asiento; end; procedure TfEditorAsiento.FormShow(Sender: TObject); begin inherited; if not Assigned(FViewAsiento) then raise Exception.Create('No hay ninguna vista asignada'); if not Assigned(Asiento) then raise Exception.Create('No hay ningún almacén asignado'); Asiento.DataTable.Active := True; FViewAsiento.ShowEmbedded(pagGeneral); FViewAsiento.SetFocus; end; destructor TfEditorAsiento.Destroy; begin FViewAsiento := NIL; FAsiento := NIL; inherited; end; constructor TfEditorAsiento.Create(AOwner: TComponent); begin inherited; // ViewAsiento := CreateView(TfrViewAsiento) as IViewAsiento; ViewAsiento := frViewAsiento1; end; procedure TfEditorAsiento.dsDataTableDataChange(Sender: TObject; Field: TField); begin inherited; if Assigned(FAsiento) and (not (FAsiento.DataTable.Fetching) or not (FAsiento.DataTable.Opening) or not (FAsiento.DataTable.Closing)) then begin if Length(FAsiento.DESCRIPCION) = 0 then JvNavPanelHeader.Caption := 'Nuevo asiento en ' + FAsiento.Cuenta.NOMBRE else JvNavPanelHeader.Caption := 'Asiento en ' + FAsiento.Cuenta.NOMBRE + ' - ' + FAsiento.DESCRIPCION; Caption := JvNavPanelHeader.Caption; end; end; procedure TfEditorAsiento.actEliminarExecute(Sender: TObject); begin if (Application.MessageBox('¿Desea borrar este asiento?', 'Atención', MB_YESNO) = IDYES) then inherited; end; initialization RegisterEditor(IBizAsiento, ShowEditorAsiento, etItem); end.