This repository has been archived on 2024-12-02. You can view files and clone it, but cannot push or open issues or pull requests.
FactuGES/Datos/ArticuloModelo.pas
2007-06-26 08:08:27 +00:00

995 lines
25 KiB
ObjectPascal
Raw Blame History

unit ArticuloModelo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, DB,
Dialogs, RdxFrameArticulos, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
cxEdit, cxDBData, Menus, am2000menuitem, am2000popupmenu, am2000,
cxButtonEdit, cxDBEdit, cxMaskEdit, cxDropDownEdit, cxContainer,
cxTextEdit, cxMemo, StdCtrls, cxGridLevel, cxClasses, cxControls,
cxGridCustomView, cxGridCustomTableView, cxGridCardView,
cxGridDBCardView, cxGrid, AdvPanel, ExtCtrls, RdxBotones, RdxPaneles,
RdxBarras, RdxTitulos, RxMemDS, Configuracion, IBCustomDataSet, IBQuery,
cxDBLookupComboBox, cxLookupEdit, cxDBLookupEdit, ActnList, cxDataStorage;
type
TfrArticuloModelo = class(TRdxFrameArticulos)
Titulo: TRdxPanelTituloOperacion;
pnlCuerpo: TPanel;
pnlPropiedades: TAdvPanel;
pnlGridPropiedades: TPanel;
gridPropiedades: TcxGrid;
gridPropiedadesDBCardView: TcxGridDBCardView;
gridPropiedadesLevel: TcxGridLevel;
pnlBarraGrid: TPanel;
bAnadir: TRdxBoton;
bEliminar: TRdxBoton;
bEliminarTodo: TRdxBoton;
pnlDatos: TAdvPanel;
eCodigoArticulo: TLabel;
eDescripcion: TLabel;
eFamilia: TLabel;
Descripcion: TcxDBMemo;
Codigo: TcxDBButtonEdit;
brSimple: TRdxBarraInferior;
bSalir: TRdxBoton;
brDoble: TRdxBarraInferior;
bAceptar: TRdxBoton;
bCancelar: TRdxBoton;
dsArticulo: TDataSource;
dsPropiedades: TDataSource;
dsPropiedadesAux: TDataSource;
dsValoresAux: TDataSource;
dsFamilias: TDataSource;
cbxFamilia: TcxDBLookupComboBox;
procedure bAceptarClick(Sender: TObject);
procedure bCancelarClick(Sender: TObject);
procedure bSalirClick(Sender: TObject);
procedure gridPropiedadesResize(Sender: TObject);
procedure CodigoPropertiesButtonClick(Sender: TObject;AButtonIndex: Integer); virtual;
procedure CodigoExit(Sender: TObject);
procedure actAnadirUpdate(Sender: TObject);
procedure actEliminarTodoUpdate(Sender: TObject);
procedure actEliminarUpdate(Sender: TObject);
procedure bAnadirClick(Sender: TObject);
procedure bEliminarClick(Sender: TObject);
procedure bEliminarTodoClick(Sender: TObject);
private
FTablaPropiedadesMem : TRxMemoryData;
procedure VALORGetProperties(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AProperties: TcxCustomEditProperties);
protected
FTablaFamilias : TIBDataSet;
FTablaPropiedadesAux : TIBDataSet;
FTablaValoresAux : TIBDataSet;
// Metodos de detalle
procedure EliminarTodo;
procedure CargarDatosPropiedades;
procedure BorrarDatosPropiedadesIB;
procedure SalvarDatosPropiedades;
procedure PropiedadesMemNewRecord(DataSet: TDataSet);
procedure ActualizarBotones;
procedure dsDetallesStateChange(Sender: TObject);
procedure ActivarModoAnadir; override;
procedure ActivarModoModificar; override;
procedure ActivarModoConsultar; override;
procedure ActivarModoEliminar; override;
function AnadirDatos : Boolean; override;
function ModificarDatos : Boolean; override;
function EliminarDatos : Boolean; override;
function CancelarAnadir : Boolean; override;
function CancelarModificar : Boolean; override;
function CancelarEliminar : Boolean; override;
function ComprobarDatos : Boolean; override;
procedure BuscarArticulo; override;
procedure FreeContenido; override;
procedure InicializarTablas; virtual;
public
constructor Create (AOwner : TComponent); override;
destructor Destroy; override;
published
property TablaArticulos;
property TablaPropiedades;
property TablaPropiedadesMem : TRxMemoryData read FTablaPropiedadesMem write FTablaPropiedadesMem;
property CodigoArticulo;
end;
var
frArticuloModelo: TfrArticuloModelo;
implementation
uses
TablaArticulos, BaseDatos, TablaPropiedadesArticulo, TablaPropiedades,
IBErrorCodes, IB, Excepciones, Mensajes, Literales, StrFunc, RdxFrame,
TablaFamilias, Entidades, ArticulosModelo, TablaValores;
{$R *.dfm}
{ TfrArticuloModelo }
procedure TfrArticuloModelo.ActivarModoAnadir;
var
CodNuevo : Variant;
begin
dsArticulo.AutoEdit := True;
dsPropiedades.AutoEdit := True;
pnlBarraGrid.Visible := True;
ActivarEdicionGridDetalles(gridPropiedades);
Codigo.Properties.Buttons[0].Visible := False;
Codigo.Properties.ReadOnly := False;
try
CodNuevo := dmTablaArticulos.DarNuevoCodigo;
with TablaArticulos do
begin
Close;
Prepare;
Open;
Insert;
FieldByName('CODIGO').AsString := CodNuevo;
FieldByName('FECHAALTA').AsDateTime := dmBaseDatos.DarFecha;
FieldByName('USUARIO').AsString := dmBaseDatos.Usuario;
end;
with TablaPropiedades do
begin
Close;
Prepare;
Params.ByName('CODIGOARTICULO').AsString := CodNuevo;
Open;
end;
with TablaPropiedadesMem do
begin
Close;
OnNewRecord := PropiedadesMemNewRecord;
Open;
end;
Visible := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.ActivarModoConsultar;
begin
dsArticulo.AutoEdit := False;
dsPropiedades.AutoEdit := False;
pnlBarraGrid.Visible := False;
DesactivarEdicionGridDetalles(gridPropiedades);
Codigo.Properties.Buttons[0].Visible := True;
Codigo.Properties.ReadOnly := True;
try
with TablaArticulos do
begin
Prepare;
Open;
if RecordCount = 0 then
begin
VerMensajeFmt(msgDatosNoExisteArt, [CodigoArticulo]);
CloseFrame;
Exit;
end;
Cancel;
end;
with TablaPropiedades do
begin
Close;
Params.ByName('CODIGOARTICULO').AsString := Codigo.DataBinding.Field.asString;
Prepare;
Open;
end;
with TablaPropiedadesMem do
begin
Close;
Open;
CargarDatosPropiedades;
end;
Visible := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.ActivarModoEliminar;
begin
dsArticulo.AutoEdit := False;
dsPropiedades.AutoEdit := False;
pnlBarraGrid.Visible := False;
DesactivarEdicionGridDetalles(gridPropiedades);
Codigo.Properties.Buttons[0].Visible := True;
Codigo.Properties.ReadOnly := True;
try
with TablaArticulos do
begin
Prepare;
Open;
if RecordCount = 0 then
begin
VerMensajeFmt(msgDatosNoExisteArt, [CodigoArticulo]);
CancelarEliminar;
CloseFrame;
Exit;
end;
Cancel;
end;
with TablaPropiedades do
begin
Close;
Params.ByName('CODIGOARTICULO').AsString := Codigo.DataBinding.Field.asString;
Prepare;
Open;
end;
with TablaPropiedadesMem do
begin
Close;
Open;
CargarDatosPropiedades;
end;
Visible := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.ActivarModoModificar;
begin
dsArticulo.AutoEdit := True;
dsPropiedades.AutoEdit := True;
pnlBarraGrid.Visible := True;
ActivarEdicionGridDetalles(gridPropiedades);
Codigo.Properties.Buttons[0].Visible := True;
Codigo.Properties.ReadOnly := True;
try
with TablaArticulos do
begin
Open;
if RecordCount = 0 then
begin
VerMensajeFmt(msgDatosNoExisteArt, [CodigoArticulo]);
CancelarModificar;
CloseFrame;
Exit;
end;
Edit;
Post;
Edit;
end;
with TablaPropiedades do
begin
Close;
Params.ByName('CODIGOARTICULO').AsString := Codigo.DataBinding.Field.asString;
Prepare;
Open;
end;
with TablaPropiedadesMem do
begin
Close;
Open;
CargarDatosPropiedades;
OnNewRecord := PropiedadesMemNewRecord;
if not IsEmpty then
Edit;
end;
// Bloquear las propiedades del art<72>culo
{with TablaPropiedades do
begin
if RecordCount > 0 then
begin
Edit;
Post;
Edit;
end;
end;}
Visible := True;
except
on E : EIBError do
begin
case E.IBErrorCode of
isc_lock_conflict : begin
VerMensajeFmt(msgDatosArtBloqueado, [CodigoArticulo]);
CancelarModificar;
CloseFrame;
Exit;
end
else
TratarExcepcion(E);
end;
end;
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrArticuloModelo.AnadirDatos: Boolean;
begin
Result := False;
try
TablaArticulos.Post;
//Tratamos detalle
BorrarDatosPropiedadesIB;
SalvarDatosPropiedades;
dmTablaArticulos.IncrementarCodigo;
CodigoArticulo := TablaArticulos.FieldByName('CODIGO').AsString;
Commit;
TablaArticulos.Close;
TablaPropiedades.Close;
TablaPropiedadesMem.Close;
Result := True;
except
on E : EIBError do begin
if E.IBErrorCode = isc_unique_key_violation then
begin
VerMensajeFmt(msgDatosCodArtRepetido, [Codigo.DataBinding.Field.AsString]);
TablaArticulos.Edit;
TablaPropiedadesMem.Edit;
end
else begin
TratarExcepcion(E);
TablaArticulos.Edit;
end;
end;
on E : Exception do begin
TratarExcepcion(E);
TablaArticulos.Edit;
end;
end;
end;
procedure TfrArticuloModelo.BuscarArticulo;
begin
if Transaccion = NIL then
Exit;
try
TablaArticulos.DisableControls;
TablaArticulos.Close;
// Buscar la fila a tratar si es necesario
if not EsCadenaVacia(CodigoArticulo) then begin
TablaArticulos.Params.ByName('CODIGO').AsString := CodigoArticulo;
//Asignamos el codigo de articulo
TablaPropiedades.Params.ByName('CODIGOARTICULO').AsString := CodigoArticulo;
end;
TablaArticulos.Prepare;
TablaPropiedades.Prepare;
TablaArticulos.Open;
TablaPropiedades.Open;
TablaArticulos.EnableControls;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrArticuloModelo.CancelarAnadir: Boolean;
begin
Result := False;
try
RollBack;
TablaArticulos.Close;
TablaPropiedades.Close;
TablaPropiedadesMem.Close;
Result := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrArticuloModelo.CancelarEliminar: Boolean;
begin
Result := False;
try
RollBack;
TablaArticulos.Close;
TablaPropiedades.Close;
TablaPropiedadesMem.Close;
Result := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrArticuloModelo.CancelarModificar: Boolean;
begin
Result := False;
try
RollBack;
TablaArticulos.Close;
TablaPropiedades.Close;
TablaPropiedadesMem.Close;
Result := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
function TfrArticuloModelo.ComprobarDatos: Boolean;
var
ListaPropiedades : TStringList;
Indice : Integer;
CurBookmark: string;
begin
Result := True;
if EsCadenaVacia(Descripcion.Text) then
begin
VerMensaje(msgDatosFaltaDescripcionArt);
Descripcion.SetFocus;
Result := False;
Exit;
end;
if EsCadenaVacia(cbxFamilia.Text) then
begin
VerMensaje(msgDatosFaltaFamilia);
cbxFamilia.SetFocus;
Result := False;
Exit;
end;
ListaPropiedades := TStringList.Create;
try
with TablaPropiedadesMem, ListaPropiedades do
begin
DisableControls;
CurBookmark := Bookmark;
Last;
while not BOF do
begin
if not ListaPropiedades.Find(FieldByName('CODIGOPROPIEDAD').AsString, Indice) then
begin
ListaPropiedades.Add(FieldByName('CODIGOPROPIEDAD').AsString);
Sort;
end
else begin
VerMensaje(msgDatosPropRepetida);
Result := False;
break;
end;
Prior;
end
end;
finally
ListaPropiedades.Free;
TablaPropiedadesMem.Bookmark := CurBookmark;
TablaPropiedadesMem.EnableControls;
end;
end;
constructor TfrArticuloModelo.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
BaseDatos := dmBaseDatos.BD;
Transaccion := dmBaseDatos.Transaccion;
TablaArticulos := TIBDataSet.Create(Self);
TablaPropiedades := TIBDataSet.Create(Self);
TablaPropiedadesMem := TRxMemoryData.Create(Self);
dsArticulo.DataSet := TablaArticulos;
dsPropiedades.DataSet := TablaPropiedadesMem;
InicializarTablas;
TablaPropiedadesMem.CopyStructure(TablaPropiedades);
FTablaFamilias := TIBDataSet.Create(Self);
dsFamilias.DataSet := FTablaFamilias;
with FTablaFamilias do
begin
Database := BaseDatos;
Transaction := Transaccion;
SelectSQL.Assign(dmTablaFamilias.sqlConsultar);
prepare;
open;
end;
FTablaPropiedadesAux := TIBDataSet.Create(Self);
dsPropiedadesAux.DataSet := FTablaPropiedadesAux;
with FTablaPropiedadesAux do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
SelectSQL.Assign(dmTablaPropiedades.sqlListaPropiedades);
Open;
end;
FTablaValoresAux := TIBDataSet.Create(Self);
dsValoresAux.DataSet := FTablaValoresAux;
with FTablaValoresAux do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
SelectSQL.Assign(dmTablaValores.sqlListaValores);
end;
dmTablaPropiedadesArticulo.InicializarGridPropiedadesArticulo(gridPropiedadesDBCardView);
with TcxLookupComboBoxProperties(gridPropiedadesDBCardView.GetRowByFieldName('CODIGOPROPIEDAD').Properties) do
ListSource := dsPropiedadesAux;
gridPropiedadesDBCardView.GetRowByFieldName('VALOR').OnGetProperties := VALORGetProperties;
bCancelar.Cancel := True;
bSalir.Cancel := True;
end;
procedure TfrArticuloModelo.dsDetallesStateChange(Sender: TObject);
begin
if not (Modo in [Anadir, Modificar]) then
Exit;
ActualizarBotones;
end;
function TfrArticuloModelo.EliminarDatos: Boolean;
begin
Result := False;
try
TablaArticulos.Delete;
Commit;
TablaArticulos.Close;
TablaPropiedades.Close;
TablaPropiedadesMem.Close;
Result := True;
except
on E : EIBError do
begin
case E.IBErrorCode of
isc_lock_conflict : VerMensajeFmt(msgDatosArtBloqueado, [Codigo.DataBinding.Field.AsString]);
else
TratarExcepcion(E);
end;
end;
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.FreeContenido;
begin
if (ContenidoModal is TRdxFrameArticulos) then
begin
CodigoArticulo := (ContenidoModal as TRdxFrameArticulos).CodigoArticulo;
ActivarModo;
end;
inherited FreeContenido;
end;
function TfrArticuloModelo.ModificarDatos: Boolean;
begin
Result := False;
try
BorrarDatosPropiedadesIB;
SalvarDatosPropiedades;
TablaArticulos.Post;
Commit;
TablaArticulos.Close;
TablaPropiedades.Close;
TablaPropiedadesMem.Close;
Result := True;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.SalvarDatosPropiedades;
var
NumeroCampo : Integer;
Valor : Variant;
NumProp : Integer;
begin
try
with TablaPropiedadesMem do
begin
if IsEmpty then
Exit;
DisableControls;
First;
TablaPropiedades.First;
NumProp := 0;
while not EOF do
begin
TablaPropiedades.Insert;
for NumeroCampo := 0 to FieldCount-1 do
begin
Valor := Fields[NumeroCampo].AsVariant;
if (Fields[NumeroCampo].FieldName = 'PROPIEDAD')
and (EsCadenaVacia(Valor)) then
raise Exception.Create(msgDatosFaltaDescripcionPro);
if TablaPropiedades.Fields[NumeroCampo].FieldName = 'CODIGOARTICULO' then
Valor := Codigo.DataBinding.Field.AsString;
if TablaPropiedades.Fields[NumeroCampo].FieldName = 'NUMPROPIEDAD' then
Valor := IntToStr(NumProp);
TablaPropiedades.Fields[NumeroCampo].AsVariant := Valor;
end;
TablaPropiedades.Post;
Inc(NumProp);
Next;
end;
EnableControls;
end;
except
on E : EIBError do begin
TablaPropiedadesMem.EnableControls;
raise;
end;
on E : Exception do begin
TablaPropiedadesMem.EnableControls;
raise;
end;
end;
end;
procedure TfrArticuloModelo.bSalirClick(Sender: TObject);
begin
try
Rollback;
CloseFrame;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.bCancelarClick(Sender: TObject);
begin
if (TratarCambios = IDOK) then
CloseFrame;
end;
procedure TfrArticuloModelo.CodigoExit(Sender: TObject);
begin
if (Modo <> Anadir) or (Visible = false) then
exit;
if not esCadenaVacia(Codigo.Text) then
begin
if (dmTablaArticulos.validarCodigo(Codigo.Text)) then begin
Codigo.DataBinding.Field.asString := dmTablaArticulos.formatearCodigo(Codigo.Text);
if (dmTablaArticulos.ExisteCodigo(Codigo.Text)) then begin
VerMensajeFmt(msgDatosCodArtRepetido, [Codigo.Text]);
Codigo.SetFocus;
end;
end
else begin
VerMensajeFmt(msgDatosCodArtIncorrecto, [Codigo.Text]);
Codigo.SetFocus;
end;
end
else
Codigo.DataBinding.Field.AsString := dmTablaArticulos.darNuevoCodigo;
end;
procedure TfrArticuloModelo.bAceptarClick(Sender: TObject);
begin
if (RealizarOperacion) then
CloseFrame;
end;
procedure TfrArticuloModelo.gridPropiedadesResize(Sender: TObject);
begin
gridPropiedadesDBCardView.OptionsView.CardWidth := (gridPropiedades.Width - 50) div 2;
end;
procedure TfrArticuloModelo.CodigoPropertiesButtonClick(Sender: TObject;AButtonIndex: Integer);
begin
if (TratarCambios = IDCANCEL) then
exit;
{ Esto es porque en modo 'Modificar' hacemos un cambio y pulsamos
este bot<6F>n se cierra la tabla y si en el frame hijo (el del grid) damos
a cancelar, FCodigoArticulo es NULL y da error al activar modo porque
no se inicializa los par<61>metros de la sql. Lo hace BuscarInstalador. }
if not TablaArticulos.Active then
BuscarArticulo;
ContenidoModal := TfrArticulosModelo.Create(Self);
end;
procedure TfrArticuloModelo.EliminarTodo;
begin
try
with TablaPropiedadesMem do
begin
DisableControls;
Last;
while RecordCount > 0 do begin
Delete;
Prior;
end;
EnableControls;
end;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.BorrarDatosPropiedadesIB;
begin
with TablaPropiedades do
begin
if (RecordCount = 0) then
Exit;
Last;
while not BOF do
begin
Delete;
Prior;
end;
if not IsEmpty then
Delete;
end;
end;
procedure TfrArticuloModelo.CargarDatosPropiedades;
var
iContador : Integer;
begin
with TablaPropiedadesMem do
begin
if TablaPropiedades.IsEmpty then
exit;
DisableControls;
TablaPropiedades.First;
while not TablaPropiedades.EOF do
begin
Append;
for iContador := 0 to TablaPropiedades.FieldCount-1 do
Fields[iContador].Value := TablaPropiedades.Fields[iContador].Value;
Post;
TablaPropiedades.Next;
end;
First;
EnableControls;
end;
end;
destructor TfrArticuloModelo.Destroy;
begin
TablaArticulos.Close;
TablaArticulos.UnPrepare;
TablaArticulos.Free;
TablaPropiedades.Close;
TablaPropiedades.UnPrepare;
TablaPropiedades.Free;
TablaPropiedadesMem.Close;
TablaPropiedadesMem.Free;
FTablaFamilias.Close;
FTablaFamilias.UnPrepare;
FTablaFamilias.Free;
FTablaPropiedadesAux.Close;
FTablaPropiedadesAux.UnPrepare;
FTablaPropiedadesAux.Free;
FTablaValoresAux.Close;
FTablaValoresAux.UnPrepare;
FTablaValoresAux.Free;
inherited;
end;
procedure TfrArticuloModelo.InicializarTablas;
begin
Entidad := entArticuloModelo;
dmTablaArticulos.ArtModelo := entArticuloModelo;
with TablaArticulos do
begin
Database := BaseDatos;
Transaction := Transaccion;
SelectSQL.Assign(dmTablaArticulos.sqlConsultarArtModelo);
InsertSQL.Assign(dmTablaArticulos.sqlInsertarArtModelo);
ModifySQL.Assign(dmTablaArticulos.sqlModificarArtModelo);
DeleteSQL.Assign(dmTablaArticulos.sqlEliminarArtModelo);
RefreshSQL.Assign(dmTablaArticulos.sqlConsultarArtModelo);
end;
with TablaPropiedades do
begin
Database := BaseDatos;
Transaction := Transaccion;
SelectSQL.Assign(dmTablaPropiedadesArticulo.sqlGridProArtModelo);
InsertSQL.Assign(dmTablaPropiedadesArticulo.sqlInsertarProArtModelo);
ModifySQL.Assign(dmTablaPropiedadesArticulo.sqlModificarProArtModelo);
DeleteSQL.Assign(dmTablaPropiedadesArticulo.sqlEliminarProArtModelo);
RefreshSQL.Assign(dmTablaPropiedadesArticulo.sqlConsultarProArtModelo);
end;
end;
procedure TfrArticuloModelo.ActualizarBotones;
begin
bEliminar.Enabled := not (TablaPropiedadesMem.RecordCount = 0);
bEliminarTodo.Enabled := not (TablaPropiedadesMem.RecordCount = 0);
end;
procedure TfrArticuloModelo.VALORGetProperties(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AProperties: TcxCustomEditProperties);
begin
if not Sender.Focused then
begin
AProperties := TcxTextEditProperties.Create(Self);
//dmConfiguracion.ItemEdit.Properties;
end
else begin
with FTablaValoresAux do
begin
try
DisableControls;
Close;
// <20>Tiene 'copia'?
if FTablaPropiedadesAux.FieldByName('COPIA').AsVariant <> NULL then
ParamByName('CODIGOPROPIEDAD').AsInteger := FTablaPropiedadesAux.FieldByName('COPIA').AsInteger
else // No tiene 'copia'
ParamByName('CODIGOPROPIEDAD').AsInteger := TablaPropiedadesMem.FieldByName('CODIGOPROPIEDAD').AsInteger;
Prepare;
Open;
if RecordCount = 0 then
begin
AProperties := TcxTextEditProperties.Create(Self);//dmConfiguracion.ItemEdit.Properties;
EnableControls;
Exit;
end;
AProperties := TcxLookupComboBoxProperties.Create(Self);
with TcxLookupComboBoxProperties(AProperties) do
begin
DropDownListStyle := lsEditList;
ImmediatePost := True;
KeyFieldNames := 'DESCRIPCION';
ListColumns.Clear;
ListColumns.Add.FieldName := 'DESCRIPCION';
ListOptions.AnsiSort := True;
ListOptions.GridLines := glNone;
ListOptions.ShowHeader := False;
ListSource := dsValoresAux;
end;
finally
EnableControls;
end;
end;
end;
end;
procedure TfrArticuloModelo.PropiedadesMemNewRecord(DataSet: TDataSet);
begin
with DataSet do
begin
FieldByName('CODIGOARTICULO').AsString := Codigo.DataBinding.Field.AsString;
end;
end;
procedure TfrArticuloModelo.actAnadirUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := not BaseDatos.IsReadOnly;
end;
procedure TfrArticuloModelo.actEliminarTodoUpdate(Sender: TObject);
begin
if not (Modo in [Anadir, Modificar]) then
(Sender as TAction).Enabled := False
else
(Sender as TAction).Enabled := not (TablaPropiedadesMem.RecordCount = 0);
end;
procedure TfrArticuloModelo.actEliminarUpdate(Sender: TObject);
begin
if not (Modo in [Anadir, Modificar]) then
(Sender as TAction).Enabled := False
else
(Sender as TAction).Enabled := not (TablaPropiedadesMem.RecordCount = 0);
end;
procedure TfrArticuloModelo.bAnadirClick(Sender: TObject);
begin
try
gridPropiedades.SetFocus;
with TablaPropiedadesMem do
begin
Append;
FieldByName('CODIGOPROPIEDAD').FocusControl;
end;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.bEliminarClick(Sender: TObject);
begin
if TablaPropiedadesMem.RecordCount = 0 then begin
{ Hacemos un cancel de la tabla por si el registro actual estuviera
recien creado }
TablaPropiedadesMem.Cancel;
Exit;
end;
try
if (VerMensajePregunta(msgDatosBorrarPropiedad) <> IDYES) then
Exit;
TablaPropiedadesMem.Delete;
except
on E : EIBError do
TratarExcepcion(E);
on E : Exception do
TratarExcepcion(E);
end;
end;
procedure TfrArticuloModelo.bEliminarTodoClick(Sender: TObject);
begin
if (VerMensajePregunta(msgDatosBorrarPropiedades) = IDYES) then
EliminarTodo;
end;
end.