git-svn-id: https://192.168.0.254/svn/Proyectos.Acana_FactuGES/trunk@4 3f40d355-893c-4141-8e64-b1d9be72e7e7
453 lines
12 KiB
ObjectPascal
453 lines
12 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: 20-12-2004
|
|
Versión actual: 1.0.0
|
|
Fecha versión actual: 20-12-2004
|
|
===============================================================================
|
|
Modificaciones:
|
|
|
|
Fecha Comentarios
|
|
---------------------------------------------------------------------------
|
|
===============================================================================
|
|
}
|
|
|
|
unit TablaAgenda;
|
|
|
|
interface
|
|
|
|
uses
|
|
//Generales
|
|
SysUtils, Classes, Controls, IBSQL, cxGridDBTableView, cxCustomData, DB,
|
|
//Particulares
|
|
cxGridDBCardView, cxMemo, cxTimeEdit, cxCalendar, StdCtrls, Variants,
|
|
|
|
//Aplicacion
|
|
Framework, StrFunc, Entidades, Constantes, BaseDatos,
|
|
|
|
// Contador
|
|
Contadores, RdxGestorContadores;
|
|
|
|
const
|
|
CITA_BORRADA = 'X';
|
|
|
|
type
|
|
TDatosVisita = class(TObjeto)
|
|
public
|
|
Codigo : Integer;
|
|
Usuario : String;
|
|
FechaIni : TDateTime;
|
|
HoraIni : TTime;
|
|
FechaFin : TDateTime;
|
|
HoraFin : TTime;
|
|
FechaAlta : TDateTime;
|
|
UsuarioAlta : String;
|
|
Descripcion : String;
|
|
EntryID : Integer;
|
|
Borrado : Boolean;
|
|
constructor Create; overload;
|
|
//constructor Create(EntryID : String); overload;
|
|
constructor Create(Codigo : Integer); overload;
|
|
procedure ObtenerDatos; override;
|
|
procedure SalvarDatos;
|
|
destructor Destroy; override;
|
|
end;
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
type
|
|
TdmTablaAgenda = class(TDataModule)
|
|
private
|
|
procedure IniciarSQL;
|
|
public
|
|
sqlInsertar : TStrings;
|
|
sqlModificar : TStrings;
|
|
sqlConsultar : TStrings;
|
|
sqlEliminar : TStrings;
|
|
sqlGrid : TStrings;
|
|
|
|
function DarNuevoCodigo : Integer;
|
|
|
|
function EliminarVisitas(Dia: TDateTime; Usuario: Variant) : Boolean;
|
|
constructor Create (AOwner : TComponent); override;
|
|
destructor Destroy; override;
|
|
|
|
procedure InicializarTablaVisitas(Tabla: TPTabla);
|
|
procedure InicializarGridVisitas(var vGrid: TcxGridDBCardView);
|
|
end;
|
|
|
|
var
|
|
dmTablaAgenda: TdmTablaAgenda;
|
|
|
|
implementation
|
|
{$R *.DFM}
|
|
|
|
uses
|
|
Mensajes, Literales;
|
|
|
|
constructor TdmTablaAgenda.Create (AOwner : TComponent);
|
|
begin
|
|
inherited;
|
|
sqlInsertar := TStringList.Create;
|
|
sqlModificar := TStringList.Create;
|
|
sqlConsultar := TStringList.Create;
|
|
sqlEliminar := TStringList.Create;
|
|
sqlGrid := TStringList.Create;
|
|
IniciarSQL;
|
|
end;
|
|
|
|
destructor TdmTablaAgenda.Destroy;
|
|
begin
|
|
sqlInsertar.Free;
|
|
sqlModificar.Free;
|
|
sqlConsultar.Free;
|
|
sqlEliminar.Free;
|
|
sqlGrid.Free;
|
|
inherited;
|
|
end;
|
|
|
|
procedure TdmTablaAgenda.IniciarSQL;
|
|
begin
|
|
with sqlInsertar do
|
|
begin
|
|
Add('insert into AGENDA (');
|
|
Add('CODIGO, USUARIO, FECHAINI, HORAINI, FECHAFIN, HORAFIN, FECHAALTA, USUARIOALTA, DESCRIPCION, ENTRYID, ULTIMOCAMBIO, BORRADO) ');
|
|
Add('values (:CODIGO, :USUARIO, :FECHAINI, :HORAINI, :FECHAFIN, :HORAFIN, :FECHAALTA, :USUARIOALTA, :DESCRIPCION, :ENTRYID, CURRENT_TIME, :BORRADO)');
|
|
end;
|
|
|
|
with sqlModificar do
|
|
begin
|
|
Add('update AGENDA set ');
|
|
Add('FECHAINI = :FECHAINI, ');
|
|
Add('HORAINI = :HORAINI, ');
|
|
Add('FECHAFIN = :FECHAFIN, ');
|
|
Add('HORAFIN = :HORAFIN, ');
|
|
Add('DESCRIPCION = :DESCRIPCION, ');
|
|
Add('ENTRYID = :ENTRYID, ');
|
|
Add('ULTIMOCAMBIO = CURRENT_TIME, ');
|
|
Add('BORRADO = :BORRADO ');
|
|
Add('where (CODIGO = :CODIGO)');
|
|
end;
|
|
|
|
with sqlEliminar do
|
|
begin
|
|
Add('delete from AGENDA ');
|
|
Add('where (CODIGO = :CODIGO)');
|
|
end;
|
|
|
|
with sqlConsultar do
|
|
begin
|
|
Add('select * from AGENDA ');
|
|
Add('where (CODIGO = :CODIGO)');
|
|
end;
|
|
|
|
with sqlGrid do
|
|
begin
|
|
Add('select * ');
|
|
Add('from AGENDA ');
|
|
Add('where USUARIO = :USUARIO ');
|
|
Add('and FECHAINI = :FECHAINI ');
|
|
Add('order by FECHAINI Desc, HORAINI Asc');
|
|
end;
|
|
end;
|
|
|
|
procedure TdmTablaAgenda.InicializarGridVisitas(var vGrid: TcxGridDBCardView);
|
|
var
|
|
Columna : TcxGridDBCardViewRow;
|
|
begin
|
|
with vGrid do begin
|
|
{Columna CODIGO}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'CODIGO';
|
|
Columna.Caption := 'Codigo';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.Visible := False;
|
|
{Columna USUARIO}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'USUARIO';
|
|
Columna.Caption := 'Usuario';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.Visible := False;
|
|
{Columna FECHAALTA}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'FECHAALTA';
|
|
Columna.Caption := 'Fecha Alta';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.Visible := False;
|
|
{Columna USUARIOALTA}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'USUARIOALTA';
|
|
Columna.Caption := 'Usuario alta';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.Visible := False;
|
|
|
|
{Columna BORRADO}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'BORRADO';
|
|
Columna.Caption := 'Borrado';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.Visible := False;
|
|
|
|
{Columna FECHAINI}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'FECHAINI';
|
|
Columna.Caption := 'Fecha inicio';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.Visible := True;
|
|
Columna.PropertiesClassName := 'TcxDateEditProperties';
|
|
with TcxDateEditProperties(Columna.Properties) do
|
|
begin
|
|
ShowTime := False;
|
|
SaveTime := False;
|
|
ImmediatePost := True;
|
|
end;
|
|
{Columna HORAINI}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'HORAINI';
|
|
Columna.Caption := 'Hora inicio';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.PropertiesClassName := 'TcxTimeEditProperties';
|
|
with TcxTimeEditProperties(Columna.Properties) do
|
|
begin
|
|
TimeFormat := tfHourMin;
|
|
ImmediatePost := True;
|
|
end;
|
|
Columna.Visible := True;
|
|
{Columna FECHAFIN}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'FECHAFIN';
|
|
Columna.Caption := 'Fecha fin';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.Visible := True;
|
|
Columna.PropertiesClassName := 'TcxDateEditProperties';
|
|
with TcxDateEditProperties(Columna.Properties) do
|
|
begin
|
|
ShowTime := False;
|
|
SaveTime := False;
|
|
ImmediatePost := True;
|
|
end;
|
|
{Columna HORAFIN}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'HORAFIN';
|
|
Columna.Caption := 'Hora fin';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.PropertiesClassName := 'TcxTimeEditProperties';
|
|
with TcxTimeEditProperties(Columna.Properties) do
|
|
begin
|
|
TimeFormat := tfHourMin;
|
|
end;
|
|
Columna.Visible := True;
|
|
{Columna DESCRIPCION}
|
|
Columna := CreateRow;
|
|
Columna.DataBinding.FieldName := 'DESCRIPCION';
|
|
Columna.Caption := 'Descripción';
|
|
Columna.CaptionAlignmentHorz := taRightJustify;
|
|
Columna.PropertiesClassName := 'TcxMemoProperties';
|
|
with TcxMemoProperties(Columna.Properties) do
|
|
begin
|
|
ScrollBars := ssVertical;
|
|
end;
|
|
Columna.Visible := True;
|
|
end;
|
|
end;
|
|
|
|
function TdmTablaAgenda.EliminarVisitas(Dia: TDateTime; Usuario: Variant): Boolean;
|
|
var
|
|
oSQL : TIBSQL;
|
|
begin
|
|
// REALIZA UN BORRADO FÍSICO Y NO UNA BAJA LÓGICA EN LA AGENDA.
|
|
// NO CAMBIAR PORQUE SE NECESITA ASÍ.
|
|
|
|
Result := False;
|
|
|
|
oSQL := TIBSQL.Create(Self);
|
|
with oSQL do
|
|
begin
|
|
Database := dmBaseDatos.BD;
|
|
Transaction := dmBaseDatos.Transaccion;
|
|
SQL.Add('delete from AGENDA ');
|
|
SQL.Add('where (FECHAINI = :FECHAINI)');
|
|
SQL.Add('and (UPPER(USUARIO) = UPPER(:USUARIO))');
|
|
try
|
|
ParamByName('FECHAINI').AsDateTime := Dia;
|
|
ParamByName('USUARIO').AsVariant := Usuario;
|
|
Prepare;
|
|
ExecQuery;
|
|
Result := True;
|
|
finally
|
|
Close;
|
|
Transaction := NIL;
|
|
Free;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TdmTablaAgenda.InicializarTablaVisitas(Tabla: TPTabla);
|
|
begin
|
|
with Tabla^.Fields do
|
|
begin
|
|
if FindField('HORAINI') <> NIL then
|
|
with (FieldByName('HORAINI') as TDateTimeField) do begin
|
|
DisplayFormat := DISPLAY_HORA;
|
|
end;
|
|
|
|
if FindField('HORAFIN') <> NIL then
|
|
with (FieldByName('HORAFIN') as TDateTimeField) do begin
|
|
DisplayFormat := DISPLAY_HORA;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function TdmTablaAgenda.DarNuevoCodigo: Integer;
|
|
var
|
|
oSQL : TIBSQL;
|
|
begin
|
|
oSQL := TIBSQL.Create(Self);
|
|
with oSQL do
|
|
begin
|
|
Database := dmBaseDatos.BD;
|
|
Transaction := dmBaseDatos.Transaccion;
|
|
SQL.Add('select max(CODIGO) + 1 from AGENDA ');
|
|
try
|
|
Prepare;
|
|
ExecQuery;
|
|
Result := Fields[0].AsInteger;
|
|
if Result = 0 then
|
|
Result := 1;
|
|
finally
|
|
Close;
|
|
Transaction := NIL;
|
|
Free;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
{ TDatosVisita }
|
|
|
|
constructor TDatosVisita.Create;
|
|
begin
|
|
inherited Create;
|
|
end;
|
|
|
|
constructor TDatosVisita.Create(Codigo: Integer);
|
|
begin
|
|
inherited Create;
|
|
Self.Codigo := Codigo;
|
|
// Recuperar los datos
|
|
ObtenerDatos;
|
|
end;
|
|
|
|
destructor TDatosVisita.Destroy;
|
|
begin
|
|
inherited;
|
|
end;
|
|
|
|
procedure TDatosVisita.ObtenerDatos;
|
|
var
|
|
oSQL : TIBSQL;
|
|
begin
|
|
if (EntryID = 0) and EsCadenaVacia(Codigo) then
|
|
raise Exception.Create('');
|
|
|
|
oSQL := TIBSQL.Create(NIL);
|
|
with oSQL do
|
|
begin
|
|
Database := dmBaseDatos.BD;
|
|
Transaction := dmBaseDatos.Transaccion;
|
|
SQL.Add('select * from AGENDA ');
|
|
if not EsCadenaVacia(Codigo) then
|
|
begin
|
|
SQL.Add('where CODIGO = :CODIGO');
|
|
ParamByName('CODIGO').AsInteger := Codigo;
|
|
end
|
|
else begin
|
|
if not (EntryID = 0) then begin
|
|
SQL.Add('where ENTRYID = :ENTRYID');
|
|
ParamByName('ENTRYID').AsInteger := EntryID;
|
|
end;
|
|
end;
|
|
|
|
try
|
|
Prepare;
|
|
ExecQuery;
|
|
|
|
// Compruebo si se han recuperado datos
|
|
if (RecordCount > 0) then
|
|
begin
|
|
Codigo := FieldByName('CODIGO').AsInteger;
|
|
Usuario := FieldByName('USUARIO').AsString;
|
|
FechaIni := FieldByName('FECHAINI').AsDate;
|
|
HoraIni := FieldByName('HORAINI').AsTime;
|
|
FechaFin := FieldByName('FECHAFIN').AsDate;
|
|
HoraFin := FieldByName('HORAFIN').AsTime;
|
|
FechaAlta := FieldByName('FECHAALTA').AsDateTime;
|
|
UsuarioAlta := FieldByName('USUARIOALTA').AsString;
|
|
Descripcion := FieldByName('DESCRIPCION').AsString;
|
|
EntryID := FieldByName('ENTRYID').AsInteger;
|
|
Borrado := not VarIsNull(FieldByName('BORRADO').AsVariant);
|
|
end;
|
|
finally
|
|
Close;
|
|
Transaction := NIL;
|
|
Free;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
procedure TDatosVisita.SalvarDatos;
|
|
var
|
|
oSQL : TIBSQL;
|
|
EsInsercion : Boolean;
|
|
begin
|
|
EsInsercion := False;
|
|
oSQL := TIBSQL.Create(NIL);
|
|
with oSQL do
|
|
begin
|
|
Database := dmBaseDatos.BD;
|
|
Transaction := dmBaseDatos.Transaccion;
|
|
|
|
if (Codigo = 0) then
|
|
begin
|
|
Codigo := dmTablaAgenda.DarNuevoCodigo;
|
|
SQL.Assign(dmTablaAgenda.sqlInsertar);
|
|
ParamByName('FECHAALTA').AsDateTime := dmBaseDatos.DarFecha;
|
|
ParamByName('USUARIOALTA').AsString := dmBaseDatos.Usuario;
|
|
ParamByName('USUARIO').AsString := UpperCase(Usuario);
|
|
EsInsercion := True;
|
|
end
|
|
else
|
|
SQL.Assign(dmTablaAgenda.sqlModificar);
|
|
|
|
ParamByName('CODIGO').AsInteger := Codigo;
|
|
ParamByName('FECHAINI').AsDate := FechaIni;
|
|
ParamByName('HORAINI').AsTime := HoraIni;
|
|
ParamByName('FECHAFIN').AsDate := FechaFin;
|
|
ParamByName('HORAFIN').AsTime := HoraFin;
|
|
ParamByName('DESCRIPCION').AsString := Descripcion;
|
|
ParamByName('ENTRYID').AsInteger := EntryID;
|
|
if Borrado then
|
|
ParamByName('BORRADO').AsString := CITA_BORRADA
|
|
else
|
|
ParamByName('BORRADO').AsVariant := null;
|
|
try
|
|
Prepare;
|
|
ExecQuery;
|
|
finally
|
|
Close;
|
|
Transaction := NIL;
|
|
Free;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
end.
|