326 lines
8.5 KiB
ObjectPascal
326 lines
8.5 KiB
ObjectPascal
|
|
{
|
|||
|
|
===============================================================================
|
|||
|
|
Copyright (<EFBFBD>) 2001. Rodax Software.
|
|||
|
|
===============================================================================
|
|||
|
|
Los contenidos de este fichero son propiedad de Rodax Software titular del
|
|||
|
|
copyright. Este fichero s<EFBFBD>lo podr<EFBFBD> ser copiado, distribuido y utilizado,
|
|||
|
|
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
|
|||
|
|
acuerdo con los t<EFBFBD>rminos y condiciones establecidas en el acuerdo/contrato
|
|||
|
|
bajo el que se suministra.
|
|||
|
|
-----------------------------------------------------------------------------
|
|||
|
|
Web: www.rodax-software.com
|
|||
|
|
===============================================================================
|
|||
|
|
Fecha primera versi<EFBFBD>n: 13-05-2002
|
|||
|
|
Versi<EFBFBD>n actual: 1.0.4
|
|||
|
|
Fecha versi<EFBFBD>n actual: 06-03-2004
|
|||
|
|
===============================================================================
|
|||
|
|
Modificaciones:
|
|||
|
|
|
|||
|
|
Fecha Comentarios
|
|||
|
|
---------------------------------------------------------------------------
|
|||
|
|
19-08-2002 Se ha modificado darInstaladores para que la union de el telefono
|
|||
|
|
separado por TLF:
|
|||
|
|
|
|||
|
|
27-05-2002 Cambio a un objeto contador (TContadorInstalador)
|
|||
|
|
|
|||
|
|
16-11-2002 p250. Poner el n<EFBFBD>mero total de instaladores dados de alta
|
|||
|
|
en la inicializaci<EFBFBD>n del grid.
|
|||
|
|
|
|||
|
|
06-03-2004 P272. Adaptaci<EFBFBD>n a multiempresa.
|
|||
|
|
===============================================================================
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
unit TablaInstaladores;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
SysUtils, Windows, Messages, Classes, Graphics, Controls, Forms,
|
|||
|
|
Dialogs, DBTables, DB, IBCustomDataSet, IBSQL, BaseDatos, IBDatabase,
|
|||
|
|
dxDBGrid, dxDBCtrl, dbgrids, StrFunc, Mensajes, IB, Contadores;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TDatosInstalador = class(TPersistent)
|
|||
|
|
public
|
|||
|
|
Codigo : String;
|
|||
|
|
Nombre : String;
|
|||
|
|
Telefono1 : String;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TdmTablaInstaladores = class(TDataModule)
|
|||
|
|
private
|
|||
|
|
procedure IniciarSQL;
|
|||
|
|
public
|
|||
|
|
sqlInsertar : TStrings;
|
|||
|
|
sqlModificar : TStrings;
|
|||
|
|
sqlConsultar : TStrings;
|
|||
|
|
sqlEliminar : TStrings;
|
|||
|
|
sqlGrid : TStrings;
|
|||
|
|
|
|||
|
|
//Metodos que llamaran a contador
|
|||
|
|
function DarNuevoCodigo : String;
|
|||
|
|
function InsertarContador : boolean;
|
|||
|
|
function IncrementarCodigo : boolean;
|
|||
|
|
function ValidarCodigo(Codigo : String) : Boolean;
|
|||
|
|
function FormatearCodigo(Codigo : String) : String;
|
|||
|
|
|
|||
|
|
constructor Create (AOwner : TComponent); override;
|
|||
|
|
destructor Destroy; override;
|
|||
|
|
|
|||
|
|
function ExisteInstalador(CodigoInstalador : String) : Boolean;
|
|||
|
|
function DarDatosInstalador(var Datos: TDatosInstalador): Boolean;
|
|||
|
|
function DarListaInstaladores(Grid : TdxDBGrid; Tabla: TPTabla) : TStringList;
|
|||
|
|
|
|||
|
|
procedure InicializarGridInstaladores(var Grid: TdxDBGrid);
|
|||
|
|
function darInstaladores : TStrings;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
var
|
|||
|
|
dmTablaInstaladores: TdmTablaInstaladores;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
{$R *.DFM}
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Excepciones, RdxGestorContadores;
|
|||
|
|
|
|||
|
|
constructor TdmTablaInstaladores.Create (AOwner : TComponent);
|
|||
|
|
begin
|
|||
|
|
inherited;
|
|||
|
|
sqlInsertar := TStringList.Create;
|
|||
|
|
sqlModificar := TStringList.Create;
|
|||
|
|
sqlConsultar := TStringList.Create;
|
|||
|
|
sqlEliminar := TStringList.Create;
|
|||
|
|
sqlGrid := TStringList.Create;
|
|||
|
|
IniciarSQL;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
destructor TdmTablaInstaladores.Destroy;
|
|||
|
|
begin
|
|||
|
|
sqlInsertar.Free;
|
|||
|
|
sqlModificar.Free;
|
|||
|
|
sqlConsultar.Free;
|
|||
|
|
sqlEliminar.Free;
|
|||
|
|
sqlGrid.Free;
|
|||
|
|
inherited;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TdmTablaInstaladores.IniciarSQL;
|
|||
|
|
begin
|
|||
|
|
with sqlInsertar do
|
|||
|
|
begin
|
|||
|
|
Add('insert into INSTALADORES ');
|
|||
|
|
Add('(CODIGO, NOMBRE, TELEFONO1) ');
|
|||
|
|
Add('values (:CODIGO, :NOMBRE, :TELEFONO1)');
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
with sqlModificar do
|
|||
|
|
begin
|
|||
|
|
Add('update INSTALADORES set ');
|
|||
|
|
Add('NOMBRE = :NOMBRE, ');
|
|||
|
|
Add('TELEFONO1 = :TELEFONO1 ');
|
|||
|
|
Add('where CODIGO = :CODIGO');
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
with sqlEliminar do
|
|||
|
|
begin
|
|||
|
|
Add('delete from INSTALADORES ');
|
|||
|
|
Add('where CODIGO = :CODIGO');
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
with sqlConsultar do
|
|||
|
|
begin
|
|||
|
|
Add('select * from INSTALADORES ');
|
|||
|
|
Add('where CODIGO = :CODIGO');
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
with sqlGrid do
|
|||
|
|
begin
|
|||
|
|
Add('select CODIGO, NOMBRE, TELEFONO1 ');
|
|||
|
|
Add('from INSTALADORES ');
|
|||
|
|
Add('order by NOMBRE');
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.DarNuevoCodigo : String;
|
|||
|
|
begin
|
|||
|
|
Result := GestorContadores.DarNuevoCodigo(contInstaladores);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.IncrementarCodigo: boolean;
|
|||
|
|
begin
|
|||
|
|
Result := GestorContadores.IncrementarValor(contInstaladores);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.validarCodigo(Codigo : String) : Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := GestorContadores.ValidarCodigo(contInstaladores, Codigo);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.formatearCodigo(Codigo : String) : String;
|
|||
|
|
begin
|
|||
|
|
Result := GestorContadores.FormatearCodigo(contInstaladores, Codigo);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.insertarContador: boolean;
|
|||
|
|
begin
|
|||
|
|
Result := GestorContadores.InsertarContador(contInstaladores);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.existeInstalador(CodigoInstalador: String): Boolean;
|
|||
|
|
var
|
|||
|
|
oSQL : TIBSQL;
|
|||
|
|
Codigo : String;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if Length(Trim(CodigoInstalador)) = 0 then
|
|||
|
|
Exit;
|
|||
|
|
|
|||
|
|
oSQL := TIBSQL.Create(Self);
|
|||
|
|
with oSQL do
|
|||
|
|
begin
|
|||
|
|
Database := dmBaseDatos.BD;
|
|||
|
|
Transaction := dmBaseDatos.Transaccion;
|
|||
|
|
SQL.Add('select CODIGO ');
|
|||
|
|
SQL.Add('from INSTALADORES ');
|
|||
|
|
SQL.Add('where CODIGO = :CODIGO ');
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
ParamByName('CODIGO').AsString := CodigoInstalador;
|
|||
|
|
Prepare;
|
|||
|
|
ExecQuery;
|
|||
|
|
|
|||
|
|
Codigo := FieldByName('CODIGO').AsString;
|
|||
|
|
Result := (CodigoInstalador = Codigo);
|
|||
|
|
finally
|
|||
|
|
Close;
|
|||
|
|
Transaction := NIL;
|
|||
|
|
Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.DarDatosInstalador(var Datos: TDatosInstalador): Boolean;
|
|||
|
|
var
|
|||
|
|
oSQL : TIBSQL;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
|
|||
|
|
if EsCadenaVacia(Datos.Codigo) then
|
|||
|
|
Exit;
|
|||
|
|
|
|||
|
|
oSQL := TIBSQL.Create(Self);
|
|||
|
|
with oSQL do
|
|||
|
|
begin
|
|||
|
|
Database := dmBaseDatos.BD;
|
|||
|
|
Transaction := dmBaseDatos.Transaccion;
|
|||
|
|
SQL.Add('select * from INSTALADORES ');
|
|||
|
|
SQL.Add('where CODIGO = :CODIGO');
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
ParamByName('CODIGO').AsString := Datos.Codigo;
|
|||
|
|
Prepare;
|
|||
|
|
ExecQuery;
|
|||
|
|
|
|||
|
|
if (RecordCount > 0) then
|
|||
|
|
begin
|
|||
|
|
with Datos do
|
|||
|
|
begin
|
|||
|
|
Nombre := FieldByName('NOMBRE').AsString;
|
|||
|
|
Telefono1 := FieldByName('TELEFONO1').AsString;
|
|||
|
|
Result := True;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
Close;
|
|||
|
|
Transaction := NIL;
|
|||
|
|
Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
procedure TdmTablaInstaladores.InicializarGridInstaladores(var Grid: TdxDBGrid);
|
|||
|
|
var
|
|||
|
|
Columna : TdxDBTreeListColumn;
|
|||
|
|
begin
|
|||
|
|
with Grid do begin
|
|||
|
|
DestroyColumns;
|
|||
|
|
ShowSummaryFooter := True;
|
|||
|
|
{Columna CODIGO}
|
|||
|
|
Columna := CreateColumn(TdxDBTreeListColumn);
|
|||
|
|
Columna.FieldName := 'CODIGO';
|
|||
|
|
Columna.Visible := False;
|
|||
|
|
{Columna NOMBRE}
|
|||
|
|
Columna := CreateColumn(TdxDBTreeListColumn);
|
|||
|
|
Columna.FieldName := 'NOMBRE';
|
|||
|
|
Columna.Caption := 'Nombre y apellidos';
|
|||
|
|
Columna.Width := tamColDescripcion1;
|
|||
|
|
Columna.SummaryFooterType := cstCount;
|
|||
|
|
Columna.SummaryFooterFormat := 'Total: 0 instaladores';
|
|||
|
|
{Columna TELEFONO1}
|
|||
|
|
Columna := CreateColumn(TdxDBTreeListColumn);
|
|||
|
|
Columna.FieldName := 'TELEFONO1';
|
|||
|
|
Columna.Caption := 'Telefono';
|
|||
|
|
Columna.Width := tamColTelefono;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.DarListaInstaladores(Grid : TdxDBGrid; Tabla: TPTabla): TStringList;
|
|||
|
|
var
|
|||
|
|
i: integer;
|
|||
|
|
ListaInstaladores : TStringList;
|
|||
|
|
begin
|
|||
|
|
ListaInstaladores := Nil;
|
|||
|
|
|
|||
|
|
if Grid.SelectedCount = 0 then
|
|||
|
|
begin
|
|||
|
|
Result := ListaInstaladores;
|
|||
|
|
exit
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
ListaInstaladores := TStringList.Create;
|
|||
|
|
Tabla^.DisableControls;
|
|||
|
|
for i:=0 to Grid.SelectedCount-1 do
|
|||
|
|
begin
|
|||
|
|
Tabla^.GotoBookmark(Pointer(Grid.SelectedRows[i]));
|
|||
|
|
ListaInstaladores.Add(Tabla^.FieldByName('CODIGO').AsString);
|
|||
|
|
end;
|
|||
|
|
Tabla^.EnableControls;
|
|||
|
|
Result := ListaInstaladores;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function TdmTablaInstaladores.darInstaladores: TStrings;
|
|||
|
|
var
|
|||
|
|
oSQL : TIBSQL;
|
|||
|
|
Lista : TStringList;
|
|||
|
|
begin
|
|||
|
|
oSQL := TIBSQL.Create(Self);
|
|||
|
|
Lista := TStringList.Create;
|
|||
|
|
|
|||
|
|
with oSQL do
|
|||
|
|
begin
|
|||
|
|
Database := dmBaseDatos.BD;
|
|||
|
|
Transaction := dmBaseDatos.Transaccion;
|
|||
|
|
SQL.Add('select NOMBRE || '' TLF: '' || TELEFONO1 from INSTALADORES order by NOMBRE');
|
|||
|
|
|
|||
|
|
try
|
|||
|
|
Prepare;
|
|||
|
|
ExecQuery;
|
|||
|
|
Lista.Append('');
|
|||
|
|
while not EOF do begin
|
|||
|
|
Lista.Append(Fields[0].AsString);
|
|||
|
|
Next;
|
|||
|
|
end;
|
|||
|
|
result := Lista;
|
|||
|
|
finally
|
|||
|
|
Close;
|
|||
|
|
Transaction := NIL;
|
|||
|
|
Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|