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/Clientes/PropiedadesArticulo.pas
2007-06-26 08:08:27 +00:00

272 lines
8.2 KiB
ObjectPascal
Raw Permalink Blame History

unit PropiedadesArticulo;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter,
cxData, cxEdit, DB, cxDBData, RdxPaneles, RdxBarras, RdxBotones,
cxGridLevel, cxClasses, cxControls, cxGridCustomView,
cxGridCustomTableView, cxGridCardView, cxGridDBCardView, cxGrid,
ExtCtrls, AdvPanel, RxMemDS, Grids, DBGrids, StdCtrls, ActnList,
TablaArticulos, cxContainer, cxTextEdit, cxMemo, cxDBEdit,
IBCustomDataSet, IBQuery, cxDBLookupComboBox, cxDataStorage;
type
TfrPropiedadesArticulo = class(TForm)
gridPropiedades: TcxGrid;
gridPropiedadesDBCardView: TcxGridDBCardView;
gridPropiedadesLevel: TcxGridLevel;
brDoble: TRdxBarraInferior;
bAceptar: TRdxBoton;
bCancelar: TRdxBoton;
TablaPropiedadesArt: TRxMemoryData;
dsPropiedadesArt: TDataSource;
RdxPanel1: TRdxPanel;
bAnadir: TRdxBoton;
bEliminar: TRdxBoton;
bEliminarTodo: TRdxBoton;
eDescripcionArticulo: TLabel;
ActionList1: TActionList;
actAnadir: TAction;
actEliminar: TAction;
actEliminarTodo: TAction;
actAceptar: TAction;
actCancelar: TAction;
eDescripcion: TLabel;
Descripcion: TcxMemo;
TablaValores: TIBQuery;
TablaPropiedades: TIBQuery;
dsPropiedades: TDataSource;
dsValores: TDataSource;
gridPropiedadesDBCardViewDBCardViewRow1: TcxGridDBCardViewRow;
gridPropiedadesDBCardViewDBCardViewRow2: TcxGridDBCardViewRow;
gridPropiedadesDBCardViewDBCardViewRow3: TcxGridDBCardViewRow;
procedure gridPropiedadesResize(Sender: TObject);
procedure actAnadirExecute(Sender: TObject);
procedure actEliminarExecute(Sender: TObject);
procedure actEliminarTodoExecute(Sender: TObject);
procedure actEliminarUpdate(Sender: TObject);
procedure actEliminarTodoUpdate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure actAceptarExecute(Sender: TObject);
procedure actCancelarExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
FDatosArticulo : TDatosArticulo;
procedure SetDatosArticulo(const Value: TDatosArticulo);
procedure VALORGetProperties(
Sender: TcxCustomGridTableItem; ARecord: TcxCustomGridRecord;
var AProperties: TcxCustomEditProperties);
public
property DatosArticulo : TDatosArticulo read FDatosArticulo write SetDatosArticulo;
end;
var
frPropiedadesArticulo: TfrPropiedadesArticulo;
implementation
{$R *.dfm}
{ TfrPropiedadesArticulo }
uses
BaseDatos, cxDropDownEdit, Mensajes,
Literales, TablaPropiedadesArticulo, TablaPropiedades, Configuracion, Entidades;
procedure TfrPropiedadesArticulo.gridPropiedadesResize(Sender: TObject);
begin
gridPropiedadesDBCardView.OptionsView.CardWidth := (gridPropiedades.Width - 50) div 2;
end;
procedure TfrPropiedadesArticulo.actAnadirExecute(Sender: TObject);
begin
gridPropiedades.SetFocus;
with TablaPropiedadesArt do
begin
Append;
Post;
Edit;
FieldByName('CODIGOPROPIEDAD').FocusControl;
end;
end;
procedure TfrPropiedadesArticulo.actEliminarExecute(Sender: TObject);
begin
if TablaPropiedadesArt.RecordCount = 0 then begin
{ Hacemos un cancel de la tabla por si el registro actual estuviera
recien creado }
TablaPropiedadesArt.Cancel;
Exit;
end;
if (VerMensajePregunta(msgDatosBorrarPropiedad) <> IDYES) then
Exit;
TablaPropiedadesArt.Delete;
end;
procedure TfrPropiedadesArticulo.actEliminarTodoExecute(Sender: TObject);
begin
if (VerMensajePregunta(msgDatosBorrarPropiedades) = IDYES) then
TablaPropiedadesArt.EmptyTable;
end;
procedure TfrPropiedadesArticulo.actEliminarUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := not (TablaPropiedadesArt.RecordCount = 0);
end;
procedure TfrPropiedadesArticulo.actEliminarTodoUpdate(Sender: TObject);
begin
(Sender as TAction).Enabled := not (TablaPropiedadesArt.RecordCount = 0);
end;
procedure TfrPropiedadesArticulo.FormShow(Sender: TObject);
var
Contador : Integer;
FPropiedad : TDatosPropiedad;
begin
Descripcion.Text := FDatosArticulo.Descripcion;
with TablaPropiedadesArt do
begin
DisableControls;
try
EmptyTable;
Open;
for Contador := 0 to (FDatosArticulo.ListaPropiedades.Count - 1) do
begin
FPropiedad := FDatosArticulo.ListaPropiedades.Items[Contador];
Insert;
FieldByName('CODIGOPROPIEDAD').AsInteger := FPropiedad.CodigoPropiedad;
FieldByName('VALOR').AsString := FPropiedad.Valor;
Post;
end;
finally
EnableControls;
end;
end;
end;
procedure TfrPropiedadesArticulo.SetDatosArticulo(
const Value: TDatosArticulo);
begin
FDatosArticulo := Value;
end;
procedure TfrPropiedadesArticulo.actAceptarExecute(Sender: TObject);
var
FPropiedad : TDatosPropiedad;
FBookmark : string;
begin
FDatosArticulo.Descripcion := Descripcion.Text;
FDatosArticulo.ListaPropiedades.Clear;
// Copiar las nuevas propiedades
with TablaPropiedadesArt do
begin
FBookmark := Bookmark;
DisableControls;
try
First;
while not EOF do
begin
FPropiedad := TDatosPropiedad.Create;
FPropiedad.CodigoPropiedad := FieldByName('CODIGOPROPIEDAD').AsInteger;
FPropiedad.Valor := FieldByName('VALOR').AsString;
FDatosArticulo.ListaPropiedades.Add(FPropiedad);
Next;
end;
finally
Bookmark := FBookmark;
EnableControls;
ModalResult := mrOk;
end;
end;
end;
procedure TfrPropiedadesArticulo.actCancelarExecute(Sender: TObject);
begin
ModalResult := mrCancel;
end;
procedure TfrPropiedadesArticulo.FormCreate(Sender: TObject);
begin
ConfigurarFrame(Self, entPresupuestoCliente);
with TablaPropiedades do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
Open;
end;
with TablaValores do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
end;
//dmTablaPropiedadesArticulo.InicializarGridPropiedadesArticulo(gridPropiedadesDBCardView);
with TcxLookupComboBoxProperties(gridPropiedadesDBCardView.GetRowByFieldName('CODIGOPROPIEDAD').Properties) do
ListSource := dsPropiedades;
gridPropiedadesDBCardView.GetRowByFieldName('VALOR').OnGetProperties := VALORGetProperties;
end;
procedure TfrPropiedadesArticulo.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
TablaPropiedades.Close;
end;
procedure TfrPropiedadesArticulo.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 TablaValores do
begin
try
DisableControls;
Close;
// <20>Tiene 'copia'?
if TablaPropiedades.FieldByName('COPIA').AsVariant <> NULL then
ParamByName('CODIGOPROPIEDAD').AsInteger := TablaPropiedades.FieldByName('COPIA').AsInteger
else // No tiene 'copia'
ParamByName('CODIGOPROPIEDAD').AsInteger := TablaPropiedadesArt.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 := dsValores;
end;
finally
EnableControls;
end;
end;
end;
end;
end.