procedure TFormPrincipal.BAceptarClick(Sender: TObject);
var
Fecha:TDate;
Hora:TTime;
Año,Mes,Dia:Word;
NombreTablaRC, NombreTablaRU:String;
SumarTurno:String;
NombreConductor,aux:String;
NotaFlag:String;
I:Integer;
TurnosActuales,TurnosCTActuales,TurnosNuevos,TurnosCTNuevos:Real;
begin
BarraProgreso.StepIt;
DesactivarBotones(False);
BarraProgreso.StepIt;
DecodeDate(Date, Año, Mes, Dia);
NombreTablaRC:='RC'+AgregarCeroAlMes(IntToStr(Mes))+IntToStr(Año)+VectorInformacionSalidaChoferPorID[6];
NombreTablaRU:='RU'+AgregarCeroAlMes(IntToStr(Mes))+IntToStr(Año)+VectorInformacionSalidaChoferPorID[6];
ZQuery1.Close;
ZQuery1.SQL.Text:= 'Select `'+IntToStr(Dia)+'` From Relaciones.'+NombreTablaRU+' Where IdentificadorRuta = '+VectorInformacionSalidaChoferPorID[2]+' And TurnoRuta = '+VectorInformacionSalidaChoferPorID[3];
ZQuery1.Open;
BarraProgreso.StepIt;
if (ZQuery1.Fields[0].AsString='0') Or (ZQuery1.Fields[0].AsString='') then
begin
ZQuery1.Close;
ZQuery1.SQL.Text:='Update Relaciones.'+NombreTablaRU+' Set `'+IntToStr(Dia)+'` = "'+VectorInformacionSalidaChofer[1]+'" Where IdentificadorRuta = '+VectorInformacionSalidaChoferPorID[2]+' And TurnoRuta = '+VectorInformacionSalidaChoferPorID[3];
ZQuery1.ExecSQL;
BarraProgreso.StepIt;
ZQuery1.Close;
ZQuery1.SQL.Text:='Update Relaciones.'+NombreTablaRC+' Set `'+IntToStr(Dia)+'` = "'+VectorInformacionSalidaChoferPorID[7]+'" Where IdentificadorRuta = '+VectorInformacionSalidaChoferPorID[2]+' And TurnoRuta = '+VectorInformacionSalidaChoferPorID[3];
ZQuery1.ExecSQL;
BarraProgreso.StepIt;
ZQuery1.Close;
ZQuery1.SQL.Text:='Select TurnosConductor From Relaciones.TurnosConductores Where NumeroConductor = "'+VectorInformacionSalidaChoferPorID[7]+'"';
ZQuery1.Open;
TurnosActuales:=ZQuery1.Fields[0].AsFloat;
TurnosNuevos:=StrToFloat(VectorInformacionSalidaChoferPorID[5])+TurnosActuales;
SumarTurno:=FloatToStr(TurnosNuevos);
BarraProgreso.StepIt;
ZQuery1.Close;
ZQuery1.SQL.Text:='Update Relaciones.TurnosConductores Set TurnosConductor = "'+SumarTurno+'" Where NumeroConductor = "'+VectorInformacionSalidaChoferPorID[7]+'"';
ZQuery1.ExecSQL;
ZQuery1.Close;
ZQuery1.SQL.Text:='Select TurnosUnidad From Relaciones.TurnosUnidades Where NumeroUnidad = "'+VectorInformacionSalidaChoferPorID[1]+'"';
ZQuery1.Open;
SumarTurno:=FloatToStr(StrToFloat(ZQuery1.Fields[0].AsString)+1);
BarraProgreso.StepIt;
ZQuery1.Close;
ZQuery1.SQL.Text:='Update Relaciones.TurnosUnidades Set TurnosUnidad = "'+SumarTurno+'" Where NumeroUnidad = "'+VectorInformacionSalidaChoferPorID[1]+'"';
ZQuery1.ExecSQL;
ZQuery1.Close;
ZQuery1.SQL.Text:='Select TurnosActuales From Relaciones.TurnosRutas Where IdentificadorRuta = "'+VectorInformacionSalidaChoferPorID[2]+'" And HoraTurno = "'+VectorInformacionSalidaChoferPorID[3]+'"';
ZQuery1.Open;
SumarTurno:=FloatToStr(StrToFloat(ZQuery1.Fields[0].AsString)+1);
BarraProgreso.StepIt;
ZQuery1.Close;
ZQuery1.SQL.Text:='Update Relaciones.TurnosRutas Set TurnosActuales = "'+SumarTurno+'" Where IdentificadorRuta = "'+VectorInformacionSalidaChoferPorID[2]+'" And HoraTurno = "'+VectorInformacionSalidaChoferPorID[3]+'"';
ZQuery1.ExecSQL;
SumarTurno:='';
ZQuery1.Close;
ZQuery1.SQL.Text:='Select CestaTickets From Relaciones.TurnosConductores Where NumeroConductor = "'+VectorInformacionSalidaChoferPorID[7]+'"';
ZQuery1.Open;
TurnosCTActuales:=ZQuery1.Fields[0].AsFloat;
TurnosCTNuevos:=StrToFloat(VectorInformacionSalidaChoferPorID[8])+TurnosCTActuales;
SumarTurno:=FloatToStr(TurnosCTNuevos);
BarraProgreso.StepIt;
ZQuery1.Close;
ZQuery1.SQL.Text:='Update Relaciones.TurnosConductores Set CestaTickets = "'+SumarTurno+'" Where NumeroConductor = "'+VectorInformacionSalidaChoferPorID[7]+'"';
ZQuery1.ExecSQL;
Hora:=Time;
BarraProgreso.StepIt;
ZConnection1.Disconnect;
ZConnection1.Database:='Transportes';
ZConnection1.Connect;
BarraProgreso.StepIt;
ZQuery1.Close;
ZQuery1.SQL.Text:='Update Transportes.EstadoUnidades Set Activa = "DES", QuienDesactivo = "SYS", HoraDesactivacion = "'+TimeToStr(Hora)+'" Where NumeroUnidad = "'+VectorInformacionSalidaChoferPorID[1]+'"';
ZQuery1.ExecSQL;
ZQuery1.Close;
ZQuery1.SQL.Text:='Select Nombre1,Apellido1 From Conductores Where NumeroConductor = "'+VectorInformacionSalidaChoferPorID[7]+'"';
ZQuery1.Open;
NombreConductor:=ZQuery1.Fields[0].AsString+' '+ZQuery1.Fields[1].AsString;
BarraProgreso.StepIt;
ZQuery1.Close;
ZQuery1.SQL.Clear;
ZQuery1.SQL.Add('Insert Into EstadisticasConductores.RegistrosConductoresRutas(NumeroConductor,EstadoReporte,QuienRegistro,FechaR egistro,HoraRegistro,FechaValidacion,HoraValidacion,Ruta,IdentificadorRuta,Turno,TipoRuta,Unidad,Nom breConductor) Values(');
ZQuery1.SQL.Add('"'+VectorInformacionSalidaChoferPorID[7]+'",');
ZQuery1.SQL.Add('"PENDIENTE",');
ZQuery1.SQL.Add('"SYS",');
ZQuery1.SQL.Add('"'+FormatDateTime('yyyy/mm/dd', Date)+'",');
ZQuery1.SQL.Add('"'+TimeToStr(Time)+'",');
ZQuery1.SQL.Add('"'+FormatDateTime('yyyy/mm/dd', Date)+'",');
ZQuery1.SQL.Add('"'+TimeToStr(Time)+'",');
ZQuery1.SQL.Add('"'+VectorInformacionSalidaChofer[2]+'",');
ZQuery1.SQL.Add('"'+VectorInformacionSalidaChoferPorID[2]+'",');
ZQuery1.SQL.Add('"'+VectorInformacionSalidaChoferPorID[3]+'",');
ZQuery1.SQL.Add('"'+VectorInformacionSalidaChoferPorID[9]+'",');
ZQuery1.SQL.Add('"'+VectorInformacionSalidaChofer[1]+'",');
ZQuery1.SQL.Add('"'+NombreConductor+'")');
ZQuery1.ExecSQL;
NotaFlag:=VectorInformacionSalidaChoferPorID[9]+' | '+VectorInformacionSalidaChofer[2]+' | '+VectorInformacionSalidaChoferPorID[3]+' | '+NombreConductor+' | '+FormatDateTime('yyyy/mm/dd', Date)+' | '+TimeToStr(Time);
ZQuery1.Close;
ZQuery1.SQL.Clear;
ZQuery1.SQL.Add('Insert Into Transportes.FlagsPendientes(FechaCreacion,HoraCreacion,Estado,TipoFlag,Nota) Values(');
ZQuery1.SQL.Add('"'+FormatDateTime('yyyy/mm/dd', Date)+'",');
ZQuery1.SQL.Add('"'+TimeToStr(Time)+'",');
ZQuery1.SQL.Add('"S",');
ZQuery1.SQL.Add('"3",');
ZQuery1.SQL.Add('"'+NotaFlag+'")');
ZQuery1.ExecSQL;
for I := 1 to 9 do
VectorInformacionSalidaChoferPorID[i]:='';
for I := 1 to 3 do
VectorInformacionSalidaChofer[i]:='';
BarraProgreso.StepIt;
Label1.Caption:='Ok! Bon Voyage!';
BarraProgreso.StepIt;
while BarraProgreso.Position<100 do
BarraProgreso.StepIt;
ZConnection1.Disconnect;
ZConnection1.Database:='Transportes';
ZConnection1.Connect;
OkMeVoy.Enabled:=True;
end else
begin
DesactivarBotones(True);
ShowMessage('ERROR! Esta ruta ya fue registrada!');
BAceptar.Enabled:=False;
end;
end;