Fórum Posicionar no registro após sorteio #301415

01/11/2005

0

Alguém sabe como faço para posicionar num registro, após um sorteio no Delphi?

A rotina é a seguinte:


procedure TfrmSorteio.SpeedButton1Click(Sender: TObject);
var j,i:integer;
begin
qrSorteio.Close;
qrSorteio.SQL.Clear;
qrSorteio.SQL.Add(´ select nome, bairro, rg, telefone, celular, email, premio, promocao, data, hora from pesquisa´);
qrSorteio.SQL.Add(´where data between :datai and :dataf´);
qrSorteio.ParamByName(´datai´).AsDate:=dtmini.DateTime;
qrSorteio.ParamByName(´dataf´).AsDate:=dtmfim.DateTime;
qrSorteio.SQL.Add(´and hora between :horai and :horaf´);
qrSorteio.ParamByName(´horai´).Astime:=dtmhorai.DateTime;
qrSorteio.ParamByName(´horaf´).Astime:=dtmhoraf.DateTime;
qrSorteio.SQL.Add(´and premio=:premio´);
qrSorteio.ParamByName(´premio´).AsInteger:=dm.tbPremiosCODIGO.AsInteger;
qrSorteio.SQL.Add(´or premio is null´);
qrSorteio.Prepare;
qrSorteio.Open;
i:=qrSorteio.RecordCount;
Randomize;
for j := 1 to spcount.Value do
begin
ShowMessage(´Numero sorteado: ´ + IntToStr(Random(i)));
dm.tbSorteio.Append;
dm.tbSorteioNOME.Value:=qrSorteio.fieldbyname(´nome´).AsString;
dm.tbSorteioBAIRRO.Value:=qrSorteio.fieldbyname(´bairro´).AsString;
dm.tbSorteioRG.Value:=qrSorteio.fieldbyname(´rg´).AsString;
dm.tbSorteioTELEFONE.Value:=qrSorteio.fieldbyname(´telefone´).AsString;
dm.tbSorteioCELULAR.Value:=qrSorteio.fieldbyname(´celular´).AsString;
dm.tbSorteioEMAIL.Value:=qrSorteio.fieldbyname(´email´).AsString;
dm.tbSorteioBAIRRO.Value:=qrSorteio.fieldbyname(´bairro´).AsString;
dm.tbSorteioPREMIO.Value:=dm.tbPremiosDESCRICAO.AsString;
dm.tbSorteioDATA.Value:=qrSorteio.fieldbyname(´data´).AsDateTime;
dm.tbSorteioHORA.Value:=qrSorteio.fieldbyname(´hora´).AsDateTime;
dm.tbSorteio.Post;
end;

Estou aplicando uma query para o filtro do sorteio e após aplicar o sorteio preciso gravar os sorteados em outra tabela, só que os registros sorteados não ficam posicionados na query.

Alguém pode me ajudar, por favor.

Grata.

Sandra.

[color=red:731366c885]Título editado por Massuda [b:731366c885]Removido: Urgente[/b:731366c885][/color:731366c885]



Sarnhold

Sarnhold

Responder

Posts

01/11/2005

Caninha51

qrSorteio.RecNo := Random(i);


Responder

Gostei + 0

01/11/2005

Sarnhold

Está sorteando, mas na hora de gravar para a outra tabela está pegando um registro posterior ao sorteado, ou seja, se o registro sorteado é 8 está gravando o 9.

Alguém sabe como posso resolver o problema?

A rotina é a seguinte:

procedure TfrmSorteio.SpeedButton1Click(Sender: TObject);
var j,i,numsorteado:integer;
begin
qrSorteio.Close;
qrSorteio.SQL.Clear;
qrSorteio.SQL.Add(´ select nome, bairro, rg, telefone, celular, email, premio, promocao, data, hora from pesquisa´);
qrSorteio.SQL.Add(´where data between :datai and :dataf´);
qrSorteio.ParamByName(´datai´).AsDate:=dtmini.DateTime;
qrSorteio.ParamByName(´dataf´).AsDate:=dtmfim.DateTime;
qrSorteio.SQL.Add(´and hora between :horai and :horaf´);
qrSorteio.ParamByName(´horai´).Astime:=dtmhorai.DateTime;
qrSorteio.ParamByName(´horaf´).Astime:=dtmhoraf.DateTime;
qrSorteio.SQL.Add(´and premio=:premio´);
qrSorteio.ParamByName(´premio´).AsInteger:=dm.tbPremiosCODIGO.AsInteger;
qrSorteio.SQL.Add(´or premio is null´);
qrSorteio.Prepare;
qrSorteio.Open;
if qrSorteio.RecordCount > 0 then
begin
i:=qrSorteio.RecordCount;
qrSorteio.First;
Randomize;
for j := 1 to spcount.Value do
begin
numsorteado:=Random(i);
ShowMessage(´Numero sorteado: ´ + IntToStr(numsorteado));
qrSorteio.MoveBy(numsorteado);
dm.tbSorteio.Append;
dm.tbSorteioNOME.Value:=qrSorteio.fieldbyname(´nome´).AsString;
dm.tbSorteioBAIRRO.Value:=qrSorteio.fieldbyname(´bairro´).AsString;
dm.tbSorteioRG.Value:=qrSorteio.fieldbyname(´rg´).AsString;
dm.tbSorteioTELEFONE.Value:=qrSorteio.fieldbyname(´telefone´).AsString;
dm.tbSorteioCELULAR.Value:=qrSorteio.fieldbyname(´celular´).AsString;
dm.tbSorteioEMAIL.Value:=qrSorteio.fieldbyname(´email´).AsString;
dm.tbSorteioBAIRRO.Value:=qrSorteio.fieldbyname(´bairro´).AsString;
dm.tbSorteioPREMIO.Value:=dm.tbPremiosDESCRICAO.AsString;
dm.tbSorteioDATA.Value:=qrSorteio.fieldbyname(´data´).AsDateTime;
dm.tbSorteioHORA.Value:=qrSorteio.fieldbyname(´hora´).AsDateTime;
dm.tbSorteio.Post;
end;
end
else showmessage(´Não há dados para os parâmetros informados...´);
end;


Responder

Gostei + 0

01/11/2005

Massuda

Não sei se entendi o seu problema, mas como você está usando MoveBy para ir ao registro sorteado, se você executar MoveBy( 8 ) isso irá posicionar no 9.o registro (8 registros após o atual).


Responder

Gostei + 0

01/11/2005

Sarnhold

Na verdade está posicionando 1 registro após o atual.
Precisaria posicionar no anterior e não sei como poderia fazer através do moveby.


Responder

Gostei + 0

01/11/2005

Sarnhold

Agora deu certo.

Fiz:

qrSorteio.MoveBy(numsorteado-1);

Obrigada.


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar