2009-12-16 17:16:54 +00:00
unit uViewEmpresa;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
2010-02-02 12:57:11 +00:00
Dialogs, uViewBase, ExtCtrls, StdCtrls, Buttons, DB, uDADataTable, uDMBase,
2009-12-16 17:16:54 +00:00
DBCtrls, Grids, DBGrids, uBizEmpresas, Mask, ComCtrls, uCustomView,
JvComponent, JvFormAutoSize, cxControls, cxContainer, cxEdit, cxTextEdit,
cxDBEdit, dxLayoutControl, dxLayoutLookAndFeels, cxMemo, cxMaskEdit,
cxSpinEdit, cxImage, JvExControls, JvBitmapButton, ActnList, ImgList,
2010-01-22 09:52:58 +00:00
PngImageList, TB2Item, SpTBXItem, TB2Dock, TB2Toolbar, PngSpeedButton, uDAInterfaces,
2010-02-01 18:04:01 +00:00
cxCurrencyEdit, cxGraphics, cxDropDownEdit, uEmpresasController,
cxLookAndFeels, cxLookAndFeelPainters, dxLayoutcxEditAdapters, cxCheckBox;
2009-12-16 17:16:54 +00:00
type
IViewEmpresa = interface( IViewBase)
[ '{876DCEBD-9E92-491A-84CE-498B1A84B525}' ]
function GetEmpresa: IBizEmpresa;
procedure SetEmpresa( const Value: IBizEmpresa) ;
property Empresa: IBizEmpresa read GetEmpresa write SetEmpresa;
function GetController : IEmpresasController;
procedure SetController ( const Value : IEmpresasController) ;
property Controller : IEmpresasController read GetController write SetController;
end ;
TfrViewEmpresa = class( TfrViewBase, IViewEmpresa)
DADataSource: TDADataSource;
dxLayoutControl1Group_Root: TdxLayoutGroup;
dxLayoutControl1: TdxLayoutControl;
dxLayoutControl1Group1: TdxLayoutGroup;
dxLayoutControl1Group2: TdxLayoutGroup;
dxLayoutControl1Group3: TdxLayoutGroup;
dxLayoutControl1Group4: TdxLayoutGroup;
dxLayoutControl1Group5: TdxLayoutGroup;
dxLayoutControl1Group6: TdxLayoutGroup;
dxLayoutControl1Group7: TdxLayoutGroup;
dxLayoutControl1Item1: TdxLayoutItem;
eCalle: TcxDBTextEdit;
dxLayoutControl1Item4: TdxLayoutItem;
eCodigoPostal: TcxDBTextEdit;
dxLayoutControl1Item5: TdxLayoutItem;
ePaginaWeb: TcxDBTextEdit;
dxLayoutControl1Item6: TdxLayoutItem;
eMailParticular: TcxDBTextEdit;
dxLayoutControl1Item7: TdxLayoutItem;
eMailTrabajo: TcxDBTextEdit;
cxDBMemo1: TcxDBMemo;
dxLayoutControl1Item8: TdxLayoutItem;
dxLayoutControl1Item9: TdxLayoutItem;
eTlfParticular: TcxDBTextEdit;
dxLayoutControl1Item10: TdxLayoutItem;
eTlfTrabajo: TcxDBTextEdit;
dxLayoutControl1Item11: TdxLayoutItem;
eTlfMovil: TcxDBTextEdit;
dxLayoutControl1Item12: TdxLayoutItem;
eFax: TcxDBTextEdit;
dxLayoutControl1Item13: TdxLayoutItem;
eNombre: TcxDBTextEdit;
dxLayoutControl1Item14: TdxLayoutItem;
eNIFCIF: TcxDBTextEdit;
dxLayoutControl1Item15: TdxLayoutItem;
memRegistroMercantil: TcxDBMemo;
dxLayoutControl1Group10: TdxLayoutGroup;
dxLayoutControl1Group9: TdxLayoutGroup;
dxLayoutControl1Group11: TdxLayoutGroup;
ActionList1: TActionList;
actAnadir: TAction;
actEliminar: TAction;
SmallImages: TPngImageList;
OpenDialog1: TOpenDialog;
cxDBImage1: TcxDBImage;
dxLayoutControl1Item17: TdxLayoutItem;
PngSpeedButton1: TPngSpeedButton;
dxLayoutControl1Item19: TdxLayoutItem;
PngSpeedButton2: TPngSpeedButton;
dxLayoutControl1Item20: TdxLayoutItem;
dxLayoutControl1Group12: TdxLayoutGroup;
dxLayoutControl1Group13: TdxLayoutGroup;
dxLayoutControl1Item18: TdxLayoutItem;
eParamMargen: TcxDBSpinEdit;
dxLayoutControl1Item21: TdxLayoutItem;
eParamTiempo: TcxDBCurrencyEdit;
dxLayoutControl1Item22: TdxLayoutItem;
cbProvincia: TcxDBComboBox;
dxLayoutControl1Item3: TdxLayoutItem;
cbPoblacion: TcxDBComboBox;
dxLayoutControl1Group8: TdxLayoutGroup;
dxLayoutControl1Group15: TdxLayoutGroup;
dxLayoutControl1Item2: TdxLayoutItem;
cbFormaPago: TcxComboBox;
dxLayoutControl1Item16: TdxLayoutItem;
cbTipoIVA: TcxComboBox;
2010-02-01 18:04:01 +00:00
dxLayoutControl1Group14: TdxLayoutGroup;
cbPrioridad: TcxCheckBox;
dxLayoutControl1Item24: TdxLayoutItem;
2009-12-16 17:16:54 +00:00
procedure actAnadirExecute( Sender: TObject) ;
procedure actEliminarExecute( Sender: TObject) ;
procedure actEliminarUpdate( Sender: TObject) ;
procedure actAnadirUpdate( Sender: TObject) ;
procedure eParamTiempoPropertiesValidate( Sender: TObject;
var DisplayValue: Variant ; var ErrorText: TCaption; var Error: Boolean ) ;
procedure eParamMargenPropertiesValidate( Sender: TObject;
var DisplayValue: Variant ; var ErrorText: TCaption; var Error: Boolean ) ;
procedure cbProvinciaPropertiesInitPopup( Sender: TObject) ;
procedure cbPoblacionPropertiesInitPopup( Sender: TObject) ;
procedure FormaPagoEditValueChanged( Sender: TObject) ;
procedure TipoIVAEditValueChanged( Sender: TObject) ;
procedure CustomViewShow( Sender: TObject) ;
2010-02-01 18:04:01 +00:00
procedure cbPrioridadPropertiesEditValueChanged( Sender: TObject) ;
2009-12-16 17:16:54 +00:00
private
FEmpresa: IBizEmpresa;
FController : IEmpresasController;
FProvincias : TStringList;
FPoblaciones : TStringList;
FFormasPago: TStringList;
FTiposIVA: TStringList;
procedure CargarProvincias;
procedure CargarPoblaciones;
function GetEmpresa: IBizEmpresa;
procedure SetEmpresa( const Value: IBizEmpresa) ;
function GetController : IEmpresasController;
procedure SetController ( const Value : IEmpresasController) ;
public
bModificarCatalogo: Boolean ;
property Controller : IEmpresasController read GetController write SetController;
constructor Create( AOwner : TComponent) ; override ;
destructor Destroy; override ;
end ;
implementation
{$R *.dfm}
uses
uROClasses, uROTypes, uProvinciasPoblacionesController, uStringsUtils;
{ TfrViewEmpresas }
{
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * TfrViewEmpresa * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
}
procedure TfrViewEmpresa. actAnadirExecute( Sender: TObject) ;
{ var
StdStream: TMemoryStream;
StreamRO: IROStream;
}
begin
inherited ;
cxDBImage1. LoadFromFile;
{ if not OpenDialog1. Execute then
Exit;
try
StdStream : = TMemoryStream. Create;
StdStream. LoadFromFile( OpenDialog1. FileName) ;
StreamRO : = NewROStream( StdStream, False ) ;
DADataSource. DataTable. Edit;
// DADataSource.DataTable.FieldByName('LOGOTIPO').Clear;
DADataSource. DataTable. FieldByName( 'LOGOTIPO' ) . LoadFromStream( StreamRO) ;
DADataSource. DataTable. Post;
finally
StdStream. Free;
end ;
}
end ;
procedure TfrViewEmpresa. actAnadirUpdate( Sender: TObject) ;
begin
inherited ;
// (Sender as TAction).Enabled := cxDBImage1.Picture.Graphic.Empty;
end ;
procedure TfrViewEmpresa. actEliminarExecute( Sender: TObject) ;
begin
inherited ;
cxDBImage1. Clear;
{ DADataSource. DataTable. Edit;
DADataSource. DataTable. FieldByName( 'LOGOTIPO' ) . AsVariant : = Null;
DADataSource. DataTable. Post;
}
end ;
procedure TfrViewEmpresa. actEliminarUpdate( Sender: TObject) ;
begin
inherited ;
// (Sender as TAction).Enabled := not cxDBImage1.Picture.Graphic.Empty;
end ;
procedure TfrViewEmpresa. CargarPoblaciones;
var
i : integer ;
AID : Integer ;
begin
AID : = StrToInt( FProvincias. Values[ cbProvincia. Text ] ) ;
with TProvinciasPoblacionesController. Create do
try
FPoblaciones : = DarListaPoblaciones( AID) ;
with cbPoblacion. Properties. Items do
begin
BeginUpdate;
try
Clear;
for i : = 0 to FPoblaciones. Count - 1 do
Add( FPoblaciones. Names[ i] ) ;
finally
EndUpdate;
end ;
end ;
finally
Free;
end ;
end ;
procedure TfrViewEmpresa. CargarProvincias;
var
i : integer ;
begin
with TProvinciasPoblacionesController. Create do
try
FProvincias : = DarListaProvincias;
with cbProvincia. Properties. Items do
begin
BeginUpdate;
try
Clear;
for i : = 0 to FProvincias. Count - 1 do
Add( FProvincias. Names[ i] ) ;
finally
EndUpdate;
end ;
end ;
finally
Free;
end ;
end ;
procedure TfrViewEmpresa. cbPoblacionPropertiesInitPopup( Sender: TObject) ;
begin
inherited ;
ShowHourglassCursor;
try
FreeANDNIL( FPoblaciones) ;
if not Assigned( FProvincias) then
CargarProvincias;
if not EsCadenaVacia( cbProvincia. Text ) and ( FProvincias. IndexOfName( cbProvincia. Text ) < > - 1 ) then
CargarPoblaciones
finally
HideHourglassCursor;
end ;
end ;
2010-02-01 18:04:01 +00:00
procedure TfrViewEmpresa. cbPrioridadPropertiesEditValueChanged( Sender: TObject) ;
begin
inherited ;
if cbPrioridad. Checked then
begin
cbTipoIVA. Enabled : = True ;
cbFormaPago. Enabled : = True ;
end
else
begin
cbTipoIVA. ItemIndex : = 0 ;
cbFormaPago. ItemIndex : = 0 ;
cbTipoIVA. Enabled : = False ;
cbFormaPago. Enabled : = False ;
end ;
end ;
2009-12-16 17:16:54 +00:00
procedure TfrViewEmpresa. cbProvinciaPropertiesInitPopup( Sender: TObject) ;
begin
inherited ;
ShowHourglassCursor;
try
if not Assigned( FProvincias) then
CargarProvincias;
finally
HideHourglassCursor;
end ;
end ;
constructor TfrViewEmpresa. Create( AOwner : TComponent) ;
begin
inherited ;
FProvincias : = NIL ;
FPoblaciones : = NIL ;
bModificarCatalogo : = False ;
end ;
procedure TfrViewEmpresa. CustomViewShow( Sender: TObject) ;
var
i: Integer ;
begin
inherited ;
//Activamos la forma de pago que tenga la empresa
cbFormaPago. ItemIndex : = 0 ;
for i : = 0 to FFormasPago. Count - 1 do
if IntToStr( FEmpresa. ID_FORMA_PAGO) = FFormasPago. Values[ FFormasPago. Names[ i] ] then
2010-02-01 18:04:01 +00:00
cbFormaPago. ItemIndex : = i+ 1 ; //Se a<> ade uno porque hemos a<> adido a la lista la cadena vacia
2009-12-16 17:16:54 +00:00
cbFormaPago. Properties. OnEditValueChanged : = FormaPagoEditValueChanged;
//Activamos el tipo iva que tenga la empresa
cbTipoIVA. ItemIndex : = 0 ;
for i : = 0 to FTiposIVA. Count - 1 do
if IntToStr( FEmpresa. ID_TIPO_IVA) = FTiposIVA. Values[ FTiposIVA. Names[ i] ] then
2010-02-01 18:04:01 +00:00
cbTipoIVA. ItemIndex : = i+ 1 ; //Se a<> ade uno porque hemos a<> adido a la lista la cadena vacia
2009-12-16 17:16:54 +00:00
cbTipoIVA. Properties. OnEditValueChanged : = TipoIVAEditValueChanged;
2010-02-01 18:04:01 +00:00
cbPrioridad. Checked : = ( cbTipoIVA. ItemIndex > 0 ) and ( cbFormaPago. ItemIndex > 0 ) ;
if not cbPrioridad. Checked then
begin
cbTipoIVA. Enabled : = False ;
cbFormaPago. Enabled : = False ;
end ;
cbPrioridad. Properties. OnEditValueChanged : = cbPrioridadPropertiesEditValueChanged;
2009-12-16 17:16:54 +00:00
end ;
destructor TfrViewEmpresa. Destroy;
begin
FController : = Nil ;
2010-02-01 18:04:01 +00:00
cbPrioridad. Properties. OnEditValueChanged : = Nil ;
2009-12-16 17:16:54 +00:00
if Assigned( FTiposIVA) then
FreeANDNIL( FTiposIVA) ;
if Assigned( FFormasPago) then
FreeANDNIL( FFormasPago) ;
if Assigned( FProvincias) then
FreeANDNIL( FProvincias) ;
if Assigned( FPoblaciones) then
FreeANDNIL( FPoblaciones) ;
inherited ;
end ;
procedure TfrViewEmpresa. eParamMargenPropertiesValidate( Sender: TObject;
var DisplayValue: Variant ; var ErrorText: TCaption; var Error: Boolean ) ;
begin
inherited ;
if ( Application. MessageBox( 'Si modifica el margen de venta, se recalcular<61> n los precios del cat<61> logo de art<72> culos, <20> Esta seguro que desea continuar?' , 'Atenci<63> n' , MB_YESNO) = IDYES) then
bModificarCatalogo : = True
else
DisplayValue : = eParamTiempo. Value;
end ;
procedure TfrViewEmpresa. eParamTiempoPropertiesValidate( Sender: TObject;
var DisplayValue: Variant ; var ErrorText: TCaption; var Error: Boolean ) ;
begin
inherited ;
if ( Application. MessageBox( 'Si modifica el precio minuto, se recalcular<61> n los precios del cat<61> logo de art<72> culos, <20> Esta seguro que desea continuar?' , 'Atenci<63> n' , MB_YESNO) = IDYES) then
bModificarCatalogo : = True
else
DisplayValue : = eParamTiempo. Value;
end ;
procedure TfrViewEmpresa. FormaPagoEditValueChanged( Sender: TObject) ;
var
IDFormaPago: String ;
begin
IDFormaPago : = '' ;
if Assigned( FFormasPago) then
IDFormaPago : = FFormasPago. Values[ cbFormaPago. EditValue] ;
Controller. AsignarIDFormaPago( FEmpresa, IDFormaPago) ;
end ;
function TfrViewEmpresa. GetController: IEmpresasController;
begin
Result : = FController;
end ;
function TfrViewEmpresa. GetEmpresa: IBizEmpresa;
begin
Result : = FEmpresa;
end ;
procedure TfrViewEmpresa. SetController( const Value: IEmpresasController) ;
var
i: Integer ;
begin
FController : = Value;
if Assigned( FController) then
begin
FFormasPago : = FController. DarListaFormasPago;
if Assigned( FFormasPago) then
with cbFormaPago. Properties. Items do
begin
BeginUpdate;
try
Clear;
2010-02-01 18:04:01 +00:00
Add( '' ) ; //Valor nulo
2009-12-16 17:16:54 +00:00
for i : = 0 to FFormasPago. Count - 1 do
Add( FFormasPago. Names[ i] ) ;
finally
EndUpdate;
end ;
end ;
FTiposIVA : = FController. DarListaTiposIVA;
if Assigned( FTiposIVA) then
with cbTipoIVA. Properties. Items do
begin
BeginUpdate;
try
Clear;
2010-02-01 18:04:01 +00:00
Add( '' ) ; //Valor nulo
2009-12-16 17:16:54 +00:00
for i : = 0 to FTiposIVA. Count - 1 do
Add( FTiposIVA. Names[ i] ) ;
finally
EndUpdate;
end ;
end ;
end ;
end ;
procedure TfrViewEmpresa. SetEmpresa( const Value: IBizEmpresa) ;
begin
FEmpresa : = Value;
if Assigned( FEmpresa) then
DADataSource. DataTable : = FEmpresa. DataTable
else
2010-02-01 18:04:01 +00:00
DADataSource. DataTable : = NIL ;
2009-12-16 17:16:54 +00:00
end ;
procedure TfrViewEmpresa. TipoIVAEditValueChanged( Sender: TObject) ;
var
IDTipoIVA: String ;
begin
IDTipoIVA : = '' ;
if Assigned( FTiposIVA) then
IDTipoIVA : = FTiposIVA. Values[ cbTipoIVA. EditValue] ;
Controller. AsignarIDTipoIVA( FEmpresa, IDTipoIVA) ;
end ;
initialization
RegisterClass( TfrViewEmpresa) ;
finalization
UnRegisterClass( TfrViewEmpresa) ;
end .