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

584 lines
17 KiB
ObjectPascal

{
===============================================================================
Copyright (©) 2002. 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: 23-08-2003
Versión actual: 1.0.1
Fecha versión actual: 21-07-2005
===============================================================================
Modificaciones:
Fecha Comentarios
---------------------------------------------------------------------------
21-07-2005 Introducir el contrato de venta y las recomendaciones de
conservacion.
===============================================================================
}
unit Documentos;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, RdxPaneles, RdxBarras, DB, IBCustomDataSet, IBDatabase,
cxControls, cxContainer, cxListBox, cxDBEdit, DBCtrls,
Grids, DBGrids, RdxBotones, cxStyles, cxCustomData, cxGraphics, cxFilter,
cxData, cxEdit, cxDBData, cxGridLevel, cxClasses, cxGridCustomView,
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid,
cxRadioGroup, RdxRadioButton,
StdCtrls, ActnList, cxTextEdit, cxMaskEdit, cxDropDownEdit, cxLookupEdit,
cxDBLookupEdit, cxDBLookupComboBox, IBSQL, IBQuery, cxMemo, ComCtrls,
RdxPageControl, ImgList, RxMemDS, IBTable, cxDataStorage, cxRichEdit,
cxDBRichEdit;
type
TfrDocumentos = class(TForm)
BarraSuperior: TRdxBarraSuperior;
TablaDocumentos: TIBDataSet;
dsDocumentos: TDataSource;
bAceptar: TRdxBoton;
Label1: TLabel;
TablaPropiedadesDocumentos: TIBDataSet;
dsPropiedadesDocumentos: TDataSource;
cbDocumentos: TcxLookupComboBox;
Label2: TLabel;
cbFamilias: TcxDBLookupComboBox;
dsFamilias: TDataSource;
TablaFamilias: TIBQuery;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
FormaPago: TcxDBMemo;
PlazosEntrega: TcxDBMemo;
Notas: TcxDBMemo;
gridPropiedades: TcxGrid;
VistaPropiedades: TcxGridDBTableView;
gridPropiedadesLevel1: TcxGridLevel;
bAnadirValor: TRdxBoton;
bEliminarValor: TRdxBoton;
Acciones: TActionList;
actAnadirProp: TAction;
actEliminarProp: TAction;
VistaPropiedadesDBColumn1: TcxGridDBColumn;
VistaPropiedadesDBColumn2: TcxGridDBColumn;
TablaPropiedades: TIBQuery;
dsPropiedades: TDataSource;
imgSombra: TImage;
Paginas: TRdxPagesControl;
pagValores: TTabSheet;
pagPropiedades: TTabSheet;
pnlCuerpo: TPanel;
pnlInferior: TPanel;
pnlSuperior: TPanel;
pagPrecios: TTabSheet;
RdxBoton1: TRdxBoton;
RdxBoton2: TRdxBoton;
TablaPreciosDocumentos: TIBDataSet;
dsPreciosDocumentos: TDataSource;
actAnadirPre: TAction;
actEliminarPre: TAction;
bSubir: TRdxBoton;
actSubir: TAction;
actBajar: TAction;
bBajar: TRdxBoton;
VistaPropiedadesDBColumn4: TcxGridDBColumn;
TablaPropiedadesDocumentosMem: TRxMemoryData;
TablaPreciosDocumentosMem: TRxMemoryData;
gridPrecios: TcxGrid;
VistaPrecios: TcxGridDBTableView;
cxGridDBColumn1: TcxGridDBColumn;
cxGridDBColumn3: TcxGridDBColumn;
cxGridLevel2: TcxGridLevel;
VistaPropiedadesDBColumn3: TcxGridDBColumn;
Seccion: TcxComboBox;
eSeccion: TLabel;
pagContrato: TTabSheet;
pagRecomendaciones: TTabSheet;
ContratoVenta: TcxDBRichEdit;
Conservacion: TcxDBRichEdit;
Label6: TLabel;
Label7: TLabel;
procedure FormCreate(Sender: TObject);
procedure bAceptarClick(Sender: TObject);
procedure cbDocumentosPropertiesChange(Sender: TObject);
procedure actAnadirPropExecute(Sender: TObject);
procedure actEliminarPropExecute(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure TablaPropiedadesDocumentosNewRecord(DataSet: TDataSet);
procedure TablaPreciosDocumentosNewRecord(DataSet: TDataSet);
procedure actAnadirPreExecute(Sender: TObject);
procedure actEliminarPreExecute(Sender: TObject);
procedure actSubirExecute(Sender: TObject);
procedure actBajarExecute(Sender: TObject);
procedure actBajarUpdate(Sender: TObject);
procedure actSubirUpdate(Sender: TObject);
procedure TablaPropiedadesDocumentosAfterDelete(DataSet: TDataSet);
procedure TablaPropiedadesDocumentosAfterInsert(DataSet: TDataSet);
procedure TablaPropiedadesDocumentosMemFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
procedure TablaPreciosDocumentosMemFilterRecord(DataSet: TDataSet;
var Accept: Boolean);
procedure SeccionPropertiesChange(Sender: TObject);
private
FUltimaPropiedad : integer;
procedure SetUltimaPropiedad;
procedure EstadoDocumento;
procedure BorrarPropiedadesIB;
procedure BorrarPreciosIB;
procedure SalvarPropiedades;
procedure SalvarPrecios;
procedure ConfigurarPantalla;
public
{ Public declarations }
end;
var
frDocumentos: TfrDocumentos;
implementation
{$R *.dfm}
uses
IB, IBErrorCodes, BaseDatos, TablaDocumentos, StrFunc, Configuracion, Entidades;
procedure TfrDocumentos.FormCreate(Sender: TObject);
beGin
ConfigurarFrame(Self, entOpciones);
with TablaFamilias do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
Prepare;
Open;
end;
with TablaPropiedades do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
Prepare;
Open;
end;
with TablaDocumentos do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
InsertSQL.Assign(dmTablaDocumentos.sqlInsertar);
ModifySQL.Assign(dmTablaDocumentos.sqlModificar);
DeleteSQL.Assign(dmTablaDocumentos.sqlEliminar);
SelectSQL.Assign(dmTablaDocumentos.sqlConsultar);
RefreshSQL.Assign(dmTablaDocumentos.sqlRefresh);
Prepare;
Open;
end;
with TablaPropiedadesDocumentos do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
//Prepare;
end;
with TablaPreciosDocumentos do
begin
Database := dmBaseDatos.BD;
Transaction := dmBaseDatos.Transaccion;
//Prepare;
end;
with TablaPropiedadesDocumentosMem do
begin
CopyStructure(TablaPropiedadesDocumentos);
LoadFromDataSet(TablaPropiedadesDocumentos, 0, lmCopy);
Filtered := True;
Open;
end;
with TablaPreciosDocumentosMem do
begin
CopyStructure(TablaPreciosDocumentos);
LoadFromDataSet(TablaPreciosDocumentos, 0, lmCopy);
Filtered := True;
Open;
end;
FUltimaPropiedad := 0;
cbDocumentos.Text := TablaDocumentos.FieldByName('DESCRIPCION').AsString;
SetUltimaPropiedad;
Seccion.ItemIndex := 0;
Paginas.ActivePageIndex := 0;
end;
procedure TfrDocumentos.bAceptarClick(Sender: TObject);
begin
EstadoDocumento;
TablaDocumentos.Edit;
if ContratoVenta.Lines.Count = 0 then
ContratoVenta.DataBinding.Field.AsVariant := Null;
if Conservacion.Lines.Count = 0 then
Conservacion.DataBinding.Field.AsVariant := Null;
TablaDocumentos.Post;
BorrarPropiedadesIB;
SalvarPropiedades;
BorrarPreciosIB;
SalvarPrecios;
dmBaseDatos.Transaccion.CommitRetaining;
Close;
end;
procedure TfrDocumentos.cbDocumentosPropertiesChange(Sender: TObject);
begin
if not EsCadenaVacia(cbDocumentos.EditValue) then
begin
EstadoDocumento;
TablaDocumentos.Locate('CODIGO', cbDocumentos.EditValue, []);
TablaPreciosDocumentosMem.First;
ConfigurarPantalla;
SetUltimaPropiedad;
end;
end;
procedure TfrDocumentos.actAnadirPropExecute(Sender: TObject);
begin
TablaPropiedadesDocumentosMem.Append;
end;
procedure TfrDocumentos.actEliminarPropExecute(Sender: TObject);
begin
TablaPropiedadesDocumentosMem.Delete;
end;
procedure TfrDocumentos.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
TablaFamilias.Close;
TablaPropiedades.Close;
end;
procedure TfrDocumentos.TablaPropiedadesDocumentosNewRecord(
DataSet: TDataSet);
begin
with DataSet do
begin
FieldByName('CODIGODOCUMENTO').AsString := TablaDocumentos.FieldByName('CODIGO').AsString;
FieldByName('NUMPROPIEDAD').AsInteger := FUltimaPropiedad + 1;
if cbDocumentos.EditValue = 'ARMARIOS' then
FieldByName('SECCION').AsString := Seccion.Text;
end;
end;
procedure TfrDocumentos.TablaPreciosDocumentosNewRecord(DataSet: TDataSet);
begin
with DataSet do
begin
FieldByName('CODIGODOCUMENTO').AsString := TablaDocumentos.FieldByName('CODIGO').AsString;
FieldByName('NUMPRECIO').AsInteger := DataSet.RecNo;
end;
end;
procedure TfrDocumentos.actAnadirPreExecute(Sender: TObject);
begin
TablaPreciosDocumentosMem.Append;
end;
procedure TfrDocumentos.actEliminarPreExecute(Sender: TObject);
begin
TablaPreciosDocumentosMem.Delete;
end;
procedure TfrDocumentos.actSubirExecute(Sender: TObject);
var
NumPropiedad : Integer;
begin
NumPropiedad := TablaPropiedadesDocumentosMem.FieldByName('NUMPROPIEDAD').AsInteger;
IntercambiarPropiedades(@TablaPropiedadesDocumentosMem, NumPropiedad, NumPropiedad - 1);
VistaPropiedades.DataController.RefreshExternalData;
end;
procedure TfrDocumentos.actBajarExecute(Sender: TObject);
var
NumPropiedad : Integer;
begin
NumPropiedad := TablaPropiedadesDocumentosMem.FieldByName('NUMPROPIEDAD').AsInteger;
IntercambiarPropiedades(@TablaPropiedadesDocumentosMem, NumPropiedad, NumPropiedad + 1);
VistaPropiedades.DataController.RefreshExternalData;
end;
procedure TfrDocumentos.actBajarUpdate(Sender: TObject);
begin
with TablaPropiedadesDocumentosMem do
(Sender as TAction).Enabled := (FieldByName('NUMPROPIEDAD').AsInteger < FUltimaPropiedad);
end;
procedure TfrDocumentos.actSubirUpdate(Sender: TObject);
begin
with TablaPropiedadesDocumentosMem do
(Sender as TAction).Enabled := FieldByName('NUMPROPIEDAD').AsInteger > 0;
end;
procedure TfrDocumentos.SetUltimaPropiedad;
begin
with TablaPropiedadesDocumentosMem do
begin
try
DisableControls;
Last;
FUltimaPropiedad := FieldByName('NUMPROPIEDAD').AsInteger;
finally
EnableControls;
First;
end;
end;
end;
procedure TfrDocumentos.EstadoDocumento;
begin
with TablaPropiedadesDocumentosMem do
begin
if State in dsEditModes then
begin
if EsCadenaVacia(FieldByName('CODIGOPROPIEDAD').AsString) then
Cancel
else
Post;
end;
end;
with TablaPreciosDocumentosMem do
begin
if State in dsEditModes then
begin
if EsCadenaVacia(FieldByName('DESCRIPCION').AsString) then
Cancel
else
Post;
end;
end;
if TablaDocumentos.State in dsEditModes then
TablaDocumentos.Post;
end;
procedure TfrDocumentos.TablaPropiedadesDocumentosAfterDelete(
DataSet: TDataSet);
begin
FUltimaPropiedad := FUltimaPropiedad - 1;
end;
procedure TfrDocumentos.TablaPropiedadesDocumentosAfterInsert(
DataSet: TDataSet);
begin
FUltimaPropiedad := FUltimaPropiedad + 1;
end;
procedure TfrDocumentos.TablaPropiedadesDocumentosMemFilterRecord(
DataSet: TDataSet; var Accept: Boolean);
begin
Accept := DataSet['CODIGODOCUMENTO'] = TablaDocumentos['CODIGO'];
if Accept and (cbDocumentos.EditValue = 'ARMARIOS') then
Accept := (DataSet.FieldByName('SECCION').AsString = Seccion.Text);
end;
procedure TfrDocumentos.TablaPreciosDocumentosMemFilterRecord(
DataSet: TDataSet; var Accept: Boolean);
begin
Accept := DataSet['CODIGODOCUMENTO'] = TablaDocumentos['CODIGO'];
end;
procedure TfrDocumentos.BorrarPreciosIB;
begin
with TablaPreciosDocumentos do
begin
Open;
if IsEmpty then
Exit;
Filtered := False;
DisableControls;
Last;
while not BOF do
begin
Delete;
Prior;
end;
if not IsEmpty then
Delete;
EnableControls;
end;
end;
procedure TfrDocumentos.BorrarPropiedadesIB;
begin
with TablaPropiedadesDocumentos do
begin
Open;
if IsEmpty then
Exit;
DisableControls;
Filtered := False;
Last;
while not BOF do
begin
Delete;
Prior;
end;
if not IsEmpty then
Delete;
EnableControls;
end;
end;
procedure TfrDocumentos.SalvarPrecios;
var
CodDoc : String;
NumeroCampo : Integer;
NumeroPrecio : Integer;
begin
try
with TablaPreciosDocumentosMem do
begin
Filtered := False;
SortOnFields('CODIGODOCUMENTO; NUMPRECIO', False);
if IsEmpty then
Exit;
DisableControls;
First;
NumeroPrecio := 0;
CodDoc := '';
TablaPreciosDocumentos.Open;
while not EOF do
begin
TablaPreciosDocumentos.Append;
for NumeroCampo := 0 to FieldCount-1 do
begin
if Fields[NumeroCampo].FieldName = 'CODIGODOCUMENTO' then
if FieldS[NumeroCampo].AsString <> CodDoc then
begin
CodDoc := Fields[NumeroCampo].AsString;
NumeroPrecio := 0;
end;
if Fields[NumeroCampo].FieldName = 'NUMPRECIO' then
begin
TablaPreciosDocumentos.Fields[NumeroCampo].AsInteger := NumeroPrecio;
NumeroPrecio := NumeroPrecio + 1;
end
else
TablaPreciosDocumentos.Fields[NumeroCampo].AsVariant := Fields[NumeroCampo].AsVariant;
end;
TablaPreciosDocumentos.Post;
Next;
end;
EnableControls;
end
except
on E : EIBError do begin
if E.IBErrorCode = isc_unique_key_violation then
begin
TablaPreciosDocumentos.Delete;
TablaPreciosDocumentosMem.EnableControls;
end;
raise EIBError.Create(E.SQLCode, E.IBErrorCode, E.Message);
end;
end;
end;
procedure TfrDocumentos.SalvarPropiedades;
var
CodDoc : String;
NumeroCampo : Integer;
NumeroPropiedad : Integer;
begin
try
with TablaPropiedadesDocumentosMem do
begin
Filtered := False;
SortOnFields('CODIGODOCUMENTO; NUMPROPIEDAD', False);
if IsEmpty then
Exit;
DisableControls;
First;
NumeroPropiedad := 0;
CodDoc := '';
TablaPropiedadesDocumentos.Open;
while not EOF do
begin
TablaPropiedadesDocumentos.Append;
for NumeroCampo := 0 to FieldCount-1 do
begin
if Fields[NumeroCampo].FieldName = 'CODIGODOCUMENTO' then
if FieldS[NumeroCampo].AsString <> CodDoc then
begin
CodDoc := Fields[NumeroCampo].AsString;
NumeroPropiedad := 0;
end;
if Fields[NumeroCampo].FieldName = 'NUMPROPIEDAD' then
begin
TablaPropiedadesDocumentos.Fields[NumeroCampo].AsInteger := NumeroPropiedad;
NumeroPropiedad := NumeroPropiedad + 1;
end
else
TablaPropiedadesDocumentos.Fields[NumeroCampo].AsVariant := Fields[NumeroCampo].AsVariant;
end;
TablaPropiedadesDocumentos.Post;
Next;
end;
EnableControls;
end
except
on E : EIBError do begin
if E.IBErrorCode = isc_unique_key_violation then
begin
TablaPropiedadesDocumentos.Delete;
TablaPropiedadesDocumentosMem.EnableControls;
end;
raise EIBError.Create(E.SQLCode, E.IBErrorCode, E.Message);
end;
end;
end;
procedure TfrDocumentos.SeccionPropertiesChange(Sender: TObject);
begin
if TablaPropiedadesDocumentosMem.Active then
TablaPropiedadesDocumentosMem.First;
end;
procedure TfrDocumentos.ConfigurarPantalla;
begin
pagContrato.TabVisible := (cbDocumentos.EditValue = 'MCOCINA');
pagRecomendaciones.TabVisible := (cbDocumentos.EditValue = 'MCOCINA');
if cbDocumentos.EditValue = 'ARMARIOS' then
begin
eSeccion.Visible := True;
Seccion.Visible := True;
TablaPropiedadesDocumentos.Filtered := True;
if TablaPropiedadesDocumentos.Active then
TablaPropiedadesDocumentosMem.First;
end
else begin
eSeccion.Visible := False;
Seccion.Visible := False;
TablaPropiedadesDocumentos.Filtered := False;
if TablaPropiedadesDocumentos.Active then
TablaPropiedadesDocumentosMem.First;
end;
end;
end.