316 lines
8.5 KiB
ObjectPascal
316 lines
8.5 KiB
ObjectPascal
|
|
unit ArticuloPresupuesto;
|
||
|
|
|
||
|
|
interface
|
||
|
|
|
||
|
|
uses
|
||
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||
|
|
Dialogs, RdxFrameArticulos, cxStyles, cxCustomData, cxGraphics, cxFilter,
|
||
|
|
cxData, cxEdit, DB, 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, cxSpinEdit, Configuracion;
|
||
|
|
|
||
|
|
type
|
||
|
|
TfrArticuloPresupuesto = class(TRdxFrameArticulos)
|
||
|
|
Cantidad: TcxDBSpinEdit;
|
||
|
|
Label1: TLabel;
|
||
|
|
Label2: TLabel;
|
||
|
|
ImporteUnidad: TcxDBSpinEdit;
|
||
|
|
Label3: TLabel;
|
||
|
|
ImporteTotal: TcxDBButtonEdit;
|
||
|
|
private
|
||
|
|
FCodigoPresupuesto: Variant;
|
||
|
|
FNumConcepto: Variant;
|
||
|
|
procedure SalvarDatosPropiedades;
|
||
|
|
procedure PropiedadesMemAfterInsert(DataSet: TDataSet);
|
||
|
|
function ComprobarDatos: Boolean; override;
|
||
|
|
procedure SetCodigoPresupuesto(const Value: Variant);
|
||
|
|
procedure SetNumConcepto(const Value: Variant);
|
||
|
|
procedure dsDetallesStateChange(Sender: TObject);
|
||
|
|
protected
|
||
|
|
procedure ActivarModoModificar; override;
|
||
|
|
function ModificarDatos : Boolean; override;
|
||
|
|
function CancelarModificar : Boolean; override;
|
||
|
|
procedure BuscarArticulo; override;
|
||
|
|
public
|
||
|
|
constructor Create (AOwner : TComponent); override;
|
||
|
|
property CodigoPresupuesto : Variant read FCodigoPresupuesto write SetCodigoPresupuesto;
|
||
|
|
property NumConcepto : Variant read FNumConcepto write SetNumConcepto;
|
||
|
|
end;
|
||
|
|
|
||
|
|
var
|
||
|
|
frArticuloPresupuesto: TfrArticuloPresupuesto;
|
||
|
|
|
||
|
|
implementation
|
||
|
|
|
||
|
|
{$R *.dfm}
|
||
|
|
|
||
|
|
uses
|
||
|
|
TablaPresupuestos, TablaPropiedades, Mensajes, Literales, IB, Excepciones,
|
||
|
|
IBErrorCodes, StrFunc, RdxFrame;
|
||
|
|
|
||
|
|
{ TfrArticuloPresupuesto }
|
||
|
|
|
||
|
|
procedure TfrArticuloPresupuesto.ActivarModoModificar;
|
||
|
|
begin
|
||
|
|
inherited;
|
||
|
|
// Codigo.Properties.Buttons[0].Visible := False;
|
||
|
|
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;
|
||
|
|
Prepare;
|
||
|
|
Open;
|
||
|
|
end;
|
||
|
|
{
|
||
|
|
with TablaPropiedadesMem do
|
||
|
|
begin
|
||
|
|
Close;
|
||
|
|
Open;
|
||
|
|
CargarDatosPropiedades;
|
||
|
|
AfterInsert := PropiedadesMemAfterInsert;
|
||
|
|
if not IsEmpty then
|
||
|
|
Edit;
|
||
|
|
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;
|
||
|
|
|
||
|
|
procedure TfrArticuloPresupuesto.BuscarArticulo;
|
||
|
|
begin
|
||
|
|
if Transaccion = NIL then
|
||
|
|
Exit;
|
||
|
|
try
|
||
|
|
TablaArticulos.DisableControls;
|
||
|
|
TablaPropiedades.DisableControls;
|
||
|
|
|
||
|
|
TablaArticulos.Close;
|
||
|
|
TablaPropiedades.Close;
|
||
|
|
|
||
|
|
// Buscar la fila a tratar si es necesario
|
||
|
|
if not EsCadenaVacia(CodigoPresupuesto) and not EsCadenaVacia(NumConcepto) then
|
||
|
|
begin
|
||
|
|
TablaArticulos.Params.ByName('CODIGOPRESUPUESTO').AsString := CodigoPresupuesto;
|
||
|
|
TablaArticulos.Params.ByName('NUMCONCEPTO').AsString := NumConcepto;
|
||
|
|
TablaPropiedades.Params.ByName('CODIGOPRESUPUESTO').AsString := CodigoPresupuesto;
|
||
|
|
TablaPropiedades.Params.ByName('NUMCONCEPTO').AsString := NumConcepto;
|
||
|
|
end;
|
||
|
|
|
||
|
|
TablaArticulos.Prepare;
|
||
|
|
TablaPropiedades.Prepare;
|
||
|
|
|
||
|
|
TablaArticulos.Open;
|
||
|
|
TablaPropiedades.Open;
|
||
|
|
|
||
|
|
TablaArticulos.EnableControls;
|
||
|
|
TablaPropiedades.EnableControls;
|
||
|
|
except
|
||
|
|
on E : EIBError do
|
||
|
|
TratarExcepcion(E);
|
||
|
|
on E : Exception do
|
||
|
|
TratarExcepcion(E);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
function TfrArticuloPresupuesto.CancelarModificar: Boolean;
|
||
|
|
begin
|
||
|
|
Result := False;
|
||
|
|
try
|
||
|
|
TablaArticulos.Cancel;
|
||
|
|
Result := True;
|
||
|
|
except
|
||
|
|
on E : EIBError do
|
||
|
|
TratarExcepcion(E);
|
||
|
|
on E : Exception do
|
||
|
|
TratarExcepcion(E);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
function TfrArticuloPresupuesto.ComprobarDatos: Boolean;
|
||
|
|
begin
|
||
|
|
Result := False;
|
||
|
|
{
|
||
|
|
if EsCadenaVacia(Descripcion.Text) then
|
||
|
|
begin
|
||
|
|
VerMensaje(msgDatosFaltaDescripcionArt);
|
||
|
|
Descripcion.SetFocus;
|
||
|
|
Exit;
|
||
|
|
end;
|
||
|
|
}
|
||
|
|
Result := True;
|
||
|
|
end;
|
||
|
|
|
||
|
|
constructor TfrArticuloPresupuesto.Create(AOwner: TComponent);
|
||
|
|
begin
|
||
|
|
inherited;
|
||
|
|
with TablaArticulos do
|
||
|
|
begin
|
||
|
|
Database := BaseDatos;
|
||
|
|
Transaction := Transaccion;
|
||
|
|
SelectSQL.Assign(dmTablaPresupuestos.sqlConsultarDetalles);
|
||
|
|
InsertSQL.Assign(dmTablaPresupuestos.sqlInsertarDetalles);
|
||
|
|
ModifySQL.Assign(dmTablaPresupuestos.sqlModificarDetalles);
|
||
|
|
DeleteSQL.Assign(dmTablaPresupuestos.sqlEliminarDetalles);
|
||
|
|
RefreshSQL.Assign(dmTablaPresupuestos.sqlConsultarDetalles);
|
||
|
|
end;
|
||
|
|
|
||
|
|
with TablaPropiedades do
|
||
|
|
begin
|
||
|
|
Database := BaseDatos;
|
||
|
|
Transaction := Transaccion;
|
||
|
|
SelectSQL.Assign(dmTablaPresupuestos.sqlConsultarGridPropiedadesModal);
|
||
|
|
InsertSQL.Assign(dmTablaPresupuestos.sqlInsertarPropiedades);
|
||
|
|
ModifySQL.Assign(dmTablaPresupuestos.sqlModificarPropiedades);
|
||
|
|
DeleteSQL.Assign(dmTablaPresupuestos.sqlEliminarPropiedades);
|
||
|
|
RefreshSQL.Assign(dmTablaPresupuestos.sqlConsultarPropiedades);
|
||
|
|
end;
|
||
|
|
|
||
|
|
{ TablaPropiedadesMem.CopyStructure(TablaPropiedades);
|
||
|
|
dmTablaPresupuestos.InicializarGridPropiedades(gridPropiedadesDBCardView);
|
||
|
|
with TcxComboBoxProperties(gridPropiedadesDBCardView.GetRowByFieldName('PROPIEDAD').Properties) do
|
||
|
|
Items := dmTablaPropiedades.darPropiedades;
|
||
|
|
dsPropiedades.OnStateChange := dsDetallesStateChange;
|
||
|
|
}
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TfrArticuloPresupuesto.dsDetallesStateChange(Sender: TObject);
|
||
|
|
begin
|
||
|
|
if not (Modo in [Anadir, Modificar]) then
|
||
|
|
Exit;
|
||
|
|
|
||
|
|
// bEliminar.Enabled := not (TablaPropiedadesMem.RecordCount = 0);
|
||
|
|
// bEliminarTodo.Enabled := not (TablaPropiedadesMem.RecordCount = 0);
|
||
|
|
end;
|
||
|
|
|
||
|
|
function TfrArticuloPresupuesto.ModificarDatos: Boolean;
|
||
|
|
begin
|
||
|
|
Result := False;
|
||
|
|
try
|
||
|
|
TablaArticulos.Post;
|
||
|
|
// BorrarDatosPropiedadesIB;
|
||
|
|
SalvarDatosPropiedades;
|
||
|
|
|
||
|
|
Result := True;
|
||
|
|
except
|
||
|
|
on E : EIBError do
|
||
|
|
TratarExcepcion(E);
|
||
|
|
on E : Exception do
|
||
|
|
TratarExcepcion(E);
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TfrArticuloPresupuesto.PropiedadesMemAfterInsert(
|
||
|
|
DataSet: TDataSet);
|
||
|
|
begin
|
||
|
|
with DataSet do
|
||
|
|
begin
|
||
|
|
FieldByName('CODIGOPRESUPUESTO').AsString := CodigoPresupuesto;
|
||
|
|
FieldByName('NUMCONCEPTO').AsString := NumConcepto;
|
||
|
|
FieldByName('NUMPROPIEDAD').AsString := '-';
|
||
|
|
end;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TfrArticuloPresupuesto.SalvarDatosPropiedades;
|
||
|
|
var
|
||
|
|
NumeroCampo : Integer;
|
||
|
|
NumeroPropiedad : Integer;
|
||
|
|
Valor : Variant;
|
||
|
|
begin
|
||
|
|
NumeroPropiedad := 1;
|
||
|
|
try
|
||
|
|
with TablaPropiedadesMem do
|
||
|
|
begin
|
||
|
|
if IsEmpty then
|
||
|
|
Exit;
|
||
|
|
DisableControls;
|
||
|
|
First;
|
||
|
|
TablaPropiedades.First;
|
||
|
|
|
||
|
|
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 = 'CODIGOPRESUPUESTO' then
|
||
|
|
Valor := CodigoPresupuesto;
|
||
|
|
|
||
|
|
if TablaPropiedades.Fields[NumeroCampo].FieldName = 'NUMCONCEPTO' then
|
||
|
|
Valor := NumConcepto;
|
||
|
|
|
||
|
|
if TablaPropiedades.Fields[NumeroCampo].FieldName = 'NUMPROPIEDAD' then
|
||
|
|
Valor := NumeroPropiedad;
|
||
|
|
|
||
|
|
TablaPropiedades.Fields[NumeroCampo].AsVariant := Valor;
|
||
|
|
end;
|
||
|
|
TablaPropiedades.Post;
|
||
|
|
Inc(NumeroPropiedad);
|
||
|
|
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 TfrArticuloPresupuesto.SetCodigoPresupuesto(const Value: Variant);
|
||
|
|
begin
|
||
|
|
FCodigoPresupuesto := Value;
|
||
|
|
end;
|
||
|
|
|
||
|
|
procedure TfrArticuloPresupuesto.SetNumConcepto(const Value: Variant);
|
||
|
|
begin
|
||
|
|
FNumConcepto := Value;
|
||
|
|
BuscarArticulo;
|
||
|
|
end;
|
||
|
|
|
||
|
|
end.
|