Mapear atendimentos apenas dentro do horário de expediente

Delphi

16/02/2006

Como Eu fasso para o código acima apenas informar os atendimentos no horario de trabalho do atendente, já que o código acima continua gerando horário de atendimentos depois expediente do funcionario até chegar a data final com a hora final?

Exemplo:
Data inicial 13/02/2006
Data final 14/02/2006
O funcionário trabalha diariamente das 12:30 até as 16:00
O código está gerando assim como se o funcionario continuasse a trabalhar depois das 16:00 do dia 13/02 e só parasse as 16:00 do dia 14/02.
13/02/2006 12:30:00
13/02/2006 13:00:00
13/02/2006 13:30:00
13/02/2006 14:00:00
13/02/2006 14:30:00
13/02/2006 15:00:00
13/02/2006 15:30:00
13/02/2006 16:00:00
13/02/2006 16:30:00
13/02/2006 17:00:00
13/02/2006 17:30:00
13/02/2006 18:00:00
13/02/2006 18:30:00
13/02/2006 19:00:00
13/02/2006 19:30:00
13/02/2006 20:00:00
13/02/2006 20:30:00
13/02/2006 21:00:00
13/02/2006 21:30:00
13/02/2006 22:00:00
13/02/2006 22:30:00
13/02/2006 23:00:00
13/02/2006 23:30:00
14/02/2006
14/02/2006 00:30:00
14/02/2006 01:00:00
14/02/2006 01:30:00
14/02/2006 02:00:00
14/02/2006 02:30:00
14/02/2006 03:00:00
14/02/2006 03:30:00
14/02/2006 04:00:00
14/02/2006 04:30:00
14/02/2006 05:00:00
14/02/2006 05:30:00
14/02/2006 06:00:00
14/02/2006 06:30:00
14/02/2006 07:00:00
14/02/2006 07:30:00
14/02/2006 08:00:00
14/02/2006 08:30:00
14/02/2006 09:00:00
14/02/2006 09:30:00
14/02/2006 10:00:00
14/02/2006 10:30:00
14/02/2006 11:00:00
14/02/2006 11:30:00
14/02/2006 12:00:00
14/02/2006 12:30:00
14/02/2006 13:00:00
14/02/2006 13:30:00
14/02/2006 14:00:00
14/02/2006 14:30:00
14/02/2006 15:00:00
14/02/2006 15:30:00
14/02/2006 16:00:00

Esse é o código completo do meu form:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Mask, ComCtrls, StdCtrls, DateUtils;

type
  TForm1 = class(TForm)
    Button1: TButton;
    dtpINICIAL: TDateTimePicker;
    dtpFINAL: TDateTimePicker;
    medtINICIAL: TMaskEdit;
    medtFINAL: TMaskEdit;
    Edit1: TEdit;
    mmoAGENDA: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

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;

procedure TForm1.Button1Click(Sender: TObject);
var Data: TDateTime;
begin
  dtpINICIAL.Time      := StrToTime(medtINICIAL.Text);
  dtpFINAL.Time     := StrToTime(medtFINAL.Text);
  mmoAGENDA.Lines.Clear;
  while dtpINICIAL.DateTime < dtpFINAL.DateTime do
  begin
    Data := dtpINICIAL.DateTime;
//    dtpINICIAL.Time   := IncMinuto(dtpINICIAL.DateTime, 30);
    dtpINICIAL.Time   := IncMinuto(dtpINICIAL.DateTime, StrToInt(Edit1.Text));
    if dtpINICIAL.DateTime<Data then
       dtpINICIAL.DateTime := IncDia(dtpINICIAL.DateTime,1);
    mmoAGENDA.Lines.Add(DateTimeToStr(dtpINICIAL.DateTime)); 
  end; 
end;

end.

[quote:2675ab2cce=´Moderação´][b:2675ab2cce][color=blue:2675ab2cce]O Titulo desta mensagem foi editado por Vinicius2K:[/color:2675ab2cce][/b:2675ab2cce]
[list:2675ab2cce][b:2675ab2cce][color=red:2675ab2cce][*:2675ab2cce]Título com conotação de desafio e não esclarecedor. Removido: ´Alguém se habilita?´[/color:2675ab2cce][/b:2675ab2cce][/list:u:2675ab2cce]
Peço que leia atentamente as [url=http://forum.clubedelphi.net/viewtopic.php?t=6689]Regras de Conduta[/url] e se algum esclarecimento sobre o funcionamento do fórum ou sobre as Regras de Conduta for necessário, envie-me uma [url=http://forum.clubedelphi.net/privmsg.php?mode=post&u=2796]Mensagem Particular[/url].[/quote:2675ab2cce]


Exvasp

Exvasp

Curtidas 0

Respostas

Rjun

Rjun

16/02/2006

Que banco de dados você esta usando?


GOSTEI 0
Aroldo Zanela

Aroldo Zanela

16/02/2006

Colega,

    if (Frac(dtpINICIAL.Time) >= StrToTime(medtINICIAL.Text)) and
       (Frac(dtpINICIAL.Time) <= StrToTime(medtFINAL.Text)) then
    mmoAGENDA.Lines.Add(DateTimeToStr(dtpINICIAL.DateTime));



GOSTEI 0
Exvasp

Exvasp

16/02/2006

Que banco de dados você esta usando?

OK!!!
Estou trabalhando com o SQL Server 2005


GOSTEI 0
Exvasp

Exvasp

16/02/2006

[quote:ba6a41e965=´Aroldo Zanela´]Colega,

    if (Frac(dtpINICIAL.Time) >= StrToTime(medtINICIAL.Text)) and
       (Frac(dtpINICIAL.Time) <= StrToTime(medtFINAL.Text)) then
    mmoAGENDA.Lines.Add(DateTimeToStr(dtpINICIAL.DateTime));
[/quote:ba6a41e965]


Perfeito!!!!
Muito obrigado mesmo!!!
Não sei como agradecer!!!
Funciona perfeito!!!!
Desculpe por ficar pertubando enviando a mensagem postada!!!
Muito obrigado!!!


GOSTEI 0
POSTAR