Agendamento de horários: problemas com repetição
Estou com o seguinte problema:
Quando vou fazer a geração dos horários no MEMO ele gera corretamente ou seja do inicio do horário(EditDataInicial = 01/03/2005 EditHoraInicial = 8h00)
até o final do horário(EditDataFinal = 03/05/2006 EditHoraFinal = 10h00), mas quando Eu vou fazer a INSERÇÃO na tabela ai o sistema continua com o horário
ou seja se o horário é das 9h00 as 10h00 na INSERÇÃO o sistema continua depois das 10h00 do dia Inicial e só termina no dia final.
Vou colocar o meu código para que alguem me ajudar indicando onde errei:
Agradeço a todos desde já a ajuda que puderam me dar.
//////////////////////////////////////////////////////////
procedure T_FrmInciaAgenda.btnOkClick(Sender: TObject);
var
Data :TDateTime;
Registro :Integer;
begin
////////
dtpINICIAL.Time := StrToTime(medtINICIAL.Text);
dtpFINAL.Time := StrToTime(medtFINAL.Text);
////////
dm.cdsMax.Close;
dm.cdsMode_Agenda.Close;
dm.cdsMax.Close;
dm.cdsMax.CommandText:=(´SELECT MAX(AGEN_COD) + 1 FROM AGENDAMENTO´);
dm.cdsMax.open;
Registro:=dm.cdsMaxCOLUMN1.AsInteger;
while dtpINICIAL.DateTime < dtpFINAL.DateTime do
begin
Data := dtpINICIAL.DateTime;
dtpINICIAL.Time := IncMinuto(dtpINICIAL.DateTime, 30);
if dtpINICIAL.DateTime<Data then
dtpINICIAL.DateTime := IncDia(dtpINICIAL.DateTime,1);
if (Frac(dtpINICIAL.Time) >= StrToTime(medtINICIAL.Text)) and
(Frac(dtpINICIAL.Time) <= StrToTime(medtFINAL.Text)) then
dm.cdsMax.Close;
dm.cdsMax.CommandText:=(´SELECT MAX(AGEN_COD) + 1 FROM AGENDAMENTO´);
dm.cdsMax.open;
Registro:=dm.cdsMaxCOLUMN1.AsInteger;
dm.cdsMode_Agenda.close;
dm.cdsMode_Agenda.commandtext :=´INSERT INTO AGENDAMENTO (AGEN_COD_INT, AGEN_DAT_AGE, AGEN_HOR_AGE)´ +
´VALUES(´ +
IntToStr(Registro) + ´, ´ +
QuotedStr(FormatDateTime(´dd/mm/yyyy´,Data)) + ´, ´ +
QuotedStr(FormatDateTime(´hh:mm:ss´,Data)) + ´) ´;
dm.cdsMode_Agenda.execute;
///////////////////////////////////////////////////////////
function AnoBis (Ano: Integer): Boolean;
var
Resto: Integer;
begin
Resto := Ano mod 4;
if Resto = 0 then Result := True //o ano é bissexto
else Result := False;//o ano não é bissexto
end;
function DiasNoMes (Data: TDate): Integer;
var
Y, M, D: Word;
Dias: Integer;
begin
Dias := 0;
DecodeDate (Data, Y, M, D);
//Especificando o número de dias de cada mês.
if M = 1 then Dias := 31;
if M = 2 then
begin
if AnoBis (Y) then Dias := 29
else Dias := 28;
end;
if M = 3 then Dias := 31;
if M = 4 then Dias := 30;
if M = 5 then Dias := 31;
if M = 6 then Dias := 30;
if M = 7 then Dias := 31;
if M = 8 then Dias := 31;
if M = 9 then Dias := 30;
if M = 10 then Dias := 31;
if M = 11 then Dias := 30;
if M = 12 then Dias := 31;
//Retornando o número do mês especificado.
Result := Dias;
end;
function IncDia (Data: TDate; Valor: Integer): TDate;
var
A, M, D: Word;
begin
DecodeDate (Data, A, M, D);
D := D + Valor;
if D > DiasNoMes (Data) then
begin
D := 1;
M := M+1;
end;
if M = 13 then
begin
M := 1;
A := A +1;
end;
Result := StrToDate (FormatFloat (´00/´, D)+FormatFloat (´00/´, M)+IntToStr (A));
end;
function IncMinuto (Hora: TTime; Valor: Integer): TTime;
var
H, M, S, Ms: Word;
begin
DecodeTime (Hora, H, M, S, Ms);
M := M + Valor;
if M = 60 then
begin
M := 0;
H := H +1;
end;
if H = 24 then H := 0;
Result := StrToTime (FormatFloat (´00:´,H)+FormatFloat (´00:´,M)+FormatFloat (´00´,S));
end;
Quando vou fazer a geração dos horários no MEMO ele gera corretamente ou seja do inicio do horário(EditDataInicial = 01/03/2005 EditHoraInicial = 8h00)
até o final do horário(EditDataFinal = 03/05/2006 EditHoraFinal = 10h00), mas quando Eu vou fazer a INSERÇÃO na tabela ai o sistema continua com o horário
ou seja se o horário é das 9h00 as 10h00 na INSERÇÃO o sistema continua depois das 10h00 do dia Inicial e só termina no dia final.
Vou colocar o meu código para que alguem me ajudar indicando onde errei:
Agradeço a todos desde já a ajuda que puderam me dar.
//////////////////////////////////////////////////////////
procedure T_FrmInciaAgenda.btnOkClick(Sender: TObject);
var
Data :TDateTime;
Registro :Integer;
begin
////////
dtpINICIAL.Time := StrToTime(medtINICIAL.Text);
dtpFINAL.Time := StrToTime(medtFINAL.Text);
////////
dm.cdsMax.Close;
dm.cdsMode_Agenda.Close;
dm.cdsMax.Close;
dm.cdsMax.CommandText:=(´SELECT MAX(AGEN_COD) + 1 FROM AGENDAMENTO´);
dm.cdsMax.open;
Registro:=dm.cdsMaxCOLUMN1.AsInteger;
while dtpINICIAL.DateTime < dtpFINAL.DateTime do
begin
Data := dtpINICIAL.DateTime;
dtpINICIAL.Time := IncMinuto(dtpINICIAL.DateTime, 30);
if dtpINICIAL.DateTime<Data then
dtpINICIAL.DateTime := IncDia(dtpINICIAL.DateTime,1);
if (Frac(dtpINICIAL.Time) >= StrToTime(medtINICIAL.Text)) and
(Frac(dtpINICIAL.Time) <= StrToTime(medtFINAL.Text)) then
dm.cdsMax.Close;
dm.cdsMax.CommandText:=(´SELECT MAX(AGEN_COD) + 1 FROM AGENDAMENTO´);
dm.cdsMax.open;
Registro:=dm.cdsMaxCOLUMN1.AsInteger;
dm.cdsMode_Agenda.close;
dm.cdsMode_Agenda.commandtext :=´INSERT INTO AGENDAMENTO (AGEN_COD_INT, AGEN_DAT_AGE, AGEN_HOR_AGE)´ +
´VALUES(´ +
IntToStr(Registro) + ´, ´ +
QuotedStr(FormatDateTime(´dd/mm/yyyy´,Data)) + ´, ´ +
QuotedStr(FormatDateTime(´hh:mm:ss´,Data)) + ´) ´;
dm.cdsMode_Agenda.execute;
///////////////////////////////////////////////////////////
function AnoBis (Ano: Integer): Boolean;
var
Resto: Integer;
begin
Resto := Ano mod 4;
if Resto = 0 then Result := True //o ano é bissexto
else Result := False;//o ano não é bissexto
end;
function DiasNoMes (Data: TDate): Integer;
var
Y, M, D: Word;
Dias: Integer;
begin
Dias := 0;
DecodeDate (Data, Y, M, D);
//Especificando o número de dias de cada mês.
if M = 1 then Dias := 31;
if M = 2 then
begin
if AnoBis (Y) then Dias := 29
else Dias := 28;
end;
if M = 3 then Dias := 31;
if M = 4 then Dias := 30;
if M = 5 then Dias := 31;
if M = 6 then Dias := 30;
if M = 7 then Dias := 31;
if M = 8 then Dias := 31;
if M = 9 then Dias := 30;
if M = 10 then Dias := 31;
if M = 11 then Dias := 30;
if M = 12 then Dias := 31;
//Retornando o número do mês especificado.
Result := Dias;
end;
function IncDia (Data: TDate; Valor: Integer): TDate;
var
A, M, D: Word;
begin
DecodeDate (Data, A, M, D);
D := D + Valor;
if D > DiasNoMes (Data) then
begin
D := 1;
M := M+1;
end;
if M = 13 then
begin
M := 1;
A := A +1;
end;
Result := StrToDate (FormatFloat (´00/´, D)+FormatFloat (´00/´, M)+IntToStr (A));
end;
function IncMinuto (Hora: TTime; Valor: Integer): TTime;
var
H, M, S, Ms: Word;
begin
DecodeTime (Hora, H, M, S, Ms);
M := M + Valor;
if M = 60 then
begin
M := 0;
H := H +1;
end;
if H = 24 then H := 0;
Result := StrToTime (FormatFloat (´00:´,H)+FormatFloat (´00:´,M)+FormatFloat (´00´,S));
end;
Exvasp
Curtidas 0
Respostas
Rjun
02/03/2006
Você criou duas funções que já existem no Delphi.
[b:02dd321f22]IncDays e IncMinute[/b:02dd321f22]
Outra coisa, sua função para saber se o ano é bissexto não está certa.
O ano bissexto deve ser divisivel por 4 e não por 100 ou ser divisivel por 400.
[b:02dd321f22]IncDays e IncMinute[/b:02dd321f22]
Outra coisa, sua função para saber se o ano é bissexto não está certa.
O ano bissexto deve ser divisivel por 4 e não por 100 ou ser divisivel por 400.
GOSTEI 0
Rjun
02/03/2006
Utilize as tags CODE e /CODE para exibir seus códigos. Fica mais fácil de entender.
Eu confesso que tenho preguiça de olhar código dos outros. Fiz algo rápido irá lhe ajudar.
Eu confesso que tenho preguiça de olhar código dos outros. Fiz algo rápido irá lhe ajudar.
var DataInicial, DataFinal, DataAtual: TDate; HoraInicial, HoraFinal, HoraAtual: TTime; begin DataInicial := StrToDate(Edit1.Text); DataFinal := StrToDate(Edit3.Text); DataAtual := DataInicial; while (DataAtual <= DataFinal) do begin HoraInicial := StrToTime(Edit2.Text); HoraFinal := StrToTime(Edit4.Text); HoraAtual := HoraInicial; while (HoraAtual <= HoraFinal) do begin // Insira seu código para gravar HoraAtual := IncMinute(HoraAtual, 30); end; DataAtual := IncDay(DataAtual, 1); end; end;
GOSTEI 0
Exvasp
02/03/2006
Utilize as tags CODE e /CODE para exibir seus códigos. Fica mais fácil de entender.
Eu confesso que tenho preguiça de olhar código dos outros. Fiz algo rápido irá lhe ajudar.
var DataInicial, DataFinal, DataAtual: TDate; HoraInicial, HoraFinal, HoraAtual: TTime; begin DataInicial := StrToDate(Edit1.Text); DataFinal := StrToDate(Edit3.Text); DataAtual := DataInicial; while (DataAtual <= DataFinal) do begin HoraInicial := StrToTime(Edit2.Text); HoraFinal := StrToTime(Edit4.Text); HoraAtual := HoraInicial; while (HoraAtual <= HoraFinal) do begin // Insira seu código para gravar HoraAtual := IncMinute(HoraAtual, 30); end; DataAtual := IncDay(DataAtual, 1); end; end;
Muito obrigado pela atenção!!!
Muito Obrigado mesmo!!!
GOSTEI 0