AbetoDesign_FactuGES2/Source/Modulos/Tarifas/Views/uEditorTarifas.pas
2020-05-15 09:26:45 +00:00

182 lines
5.3 KiB
ObjectPascal

{
===============================================================================
Copyright (©) 2006. Rodax Software.
===============================================================================
Los contenidos de este fichero son propiedad de Rodax Software titular del
copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
bajo el que se suministra.
-----------------------------------------------------------------------------
Web: www.rodax-software.com
===============================================================================
Fecha primera versión: 22-05-2006
Versión actual: 1.0.0
Fecha versión actual: 22-05-2006
===============================================================================
Modificaciones:
Fecha Comentarios
---------------------------------------------------------------------------
===============================================================================
}
unit uEditorTarifas;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, StdCtrls, DBCtrls, uDADataTable, ActnList,
uIEditorTarifas, uCustomEditor, uGUIBase, ExtCtrls,
ComCtrls, uBizTarifas, uTarifasController, uDAInterfaces;
type
TfEditorTarifas = class(TCustomEditor, IEditorTarifas)
ActionList1: TActionList;
DADataSource: TDADataSource;
ListaTarifas: TDBLookupListBox;
actAnadir: TAction;
actEliminar: TAction;
bEliminar: TButton;
actAceptar: TAction;
actCancelar: TAction;
bAceptar: TButton;
bCancelar: TButton;
actCerrar: TAction;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
Label1: TLabel;
Label2: TLabel;
Bevel1: TBevel;
eCategoria: TLabel;
editTarifa: TEdit;
bAnadir: TButton;
procedure FormShow(Sender: TObject);
procedure CustomEditorClose(Sender: TObject; var Action: TCloseAction);
procedure actAnadirExecute(Sender: TObject);
procedure actEliminarExecute(Sender: TObject);
procedure actAceptarExecute(Sender: TObject);
procedure actCancelarExecute(Sender: TObject);
procedure actCerrarExecute(Sender: TObject);
procedure actAnadirUpdate(Sender: TObject);
procedure actEliminarUpdate(Sender: TObject);
protected
FTarifas: IBizTarifa;
FController: ITarifasController;
function GetTarifas: IBizTarifa;
procedure SetTarifas(const Value: IBizTarifa);
function GetController : ITarifasController;
procedure SetController (const Value : ITarifasController);
public
property Tarifas: IBizTarifa read GetTarifas write SetTarifas;
property Controller : ITarifasController read GetController write SetController;
end;
implementation
{$R *.dfm}
{ TfEditorTarifas }
uses
uDialogUtils, uFactuGES_App;
function TfEditorTarifas.GetController: ITarifasController;
begin
Result := FController;
end;
function TfEditorTarifas.GetTarifas: IBizTarifa;
begin
Result := FTarifas;
end;
procedure TfEditorTarifas.SetController(const Value: ITarifasController);
begin
FController := Value;
end;
procedure TfEditorTarifas.SetTarifas(const Value: IBizTarifa);
begin
FTarifas := Value;
DADataSource.DataTable := (FTarifas as IBizTarifa).DataTable;
DADataSource.DataTable.Open;
end;
procedure TfEditorTarifas.actAnadirExecute(Sender: TObject);
begin
if not FController.Localizar(Tarifas, editTarifa.Text) then
begin
Tarifas.Append;
Tarifas.DESCRIPCION := editTarifa.Text;
Tarifas.Post;
editTarifa.Clear;
ListaTarifas.SetFocus;
end
else
ShowErrorMessage('Ya existe la Tarifa ' + editTarifa.Text,
'Ya existe la Tarifa ''' + editTarifa.Text + ''' en la lista.');
end;
procedure TfEditorTarifas.actEliminarExecute(Sender: TObject);
begin
Tarifas.Delete;
ListaTarifas.SetFocus;
end;
procedure TfEditorTarifas.actEliminarUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := (FTarifas.DataTable.RecordCount > 0) and
(Length(ListaTarifas.SelectedItem) > 0) and
(AppFactuGES.UsuarioActivo.ID_PERFIL = CTE_PERFIL_ADMINISTRADOR);
end;
procedure TfEditorTarifas.CustomEditorClose(Sender: TObject; var Action: TCloseAction);
begin
FTarifas := Nil;
FController := Nil;
end;
procedure TfEditorTarifas.actAceptarExecute(Sender: TObject);
begin
try
Tarifas.DataTable.ApplyUpdates;
except
on E : Exception do begin
Tarifas.DataTable.CancelUpdates;
ShowErrorMessage('Error al guardar cambios', 'Se ha producido un error grave', E);
exit;
end;
end;
actCerrar.Execute;
end;
procedure TfEditorTarifas.actCancelarExecute(Sender: TObject);
begin
Tarifas.DataTable.CancelUpdates;
actCerrar.Execute;
end;
procedure TfEditorTarifas.actCerrarExecute(Sender: TObject);
begin
Close;
end;
procedure TfEditorTarifas.actAnadirUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := (Length(editTarifa.Text) > 0)
end;
procedure TfEditorTarifas.FormShow(Sender: TObject);
begin
if not FTarifas.DataTable.Active then
FTarifas.DataTable.Active := true;
EditTarifa.SetFocus;
end;
end.