Posicionar no registro após sorteio
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.
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
Curtidas 0
Respostas
Caninha51
01/11/2005
qrSorteio.RecNo := Random(i);
GOSTEI 0
Sarnhold
01/11/2005
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;
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;
GOSTEI 0
Massuda
01/11/2005
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).
GOSTEI 0
Sarnhold
01/11/2005
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.
Precisaria posicionar no anterior e não sei como poderia fazer através do moveby.
GOSTEI 0
Sarnhold
01/11/2005
Agora deu certo.
Fiz:
qrSorteio.MoveBy(numsorteado-1);
Obrigada.
Fiz:
qrSorteio.MoveBy(numsorteado-1);
Obrigada.
GOSTEI 0