delphi 生成时间段 sql语句

最近在做排班 预约 功能

 vwtp = 上班时间    09:00 -  18:00

vrtp=休息时段     12:30-14:00

vmin = 完成某个项目的分钟数

function TF230370.GetClassDetailSql(ventryid,vwtp,vrtp,vHqty: string; vmin: integer): string;
var
  lsql,lstr,lap: string;
  lwb,lwe,lrb,lre,ltmp: TDateTime;
  lmin,i: Integer;
begin
  lwb := StrToDateTime('2019-01-01 ' + Copy(vwtp,1,pos('-',vwtp) - 1) + ':00' );
  lwe := StrToDateTime('2019-01-01 ' + Copy(vwtp,pos('-',vwtp) + 1,Length(vwtp)) + ':00');

  lrb := StrToDateTime('2019-01-01 ' + Copy(vrtp,1,pos('-',vrtp) - 1) +':00' );
  lre := StrToDateTime('2019-01-01 ' + Copy(vrtp,pos('-',vrtp) + 1,Length(vrtp)) + ':00' );

//  ShowMessage(formatdatetime('yyyy-mm-dd hh:nn:ss',lwb));
//  ShowMessage(formatdatetime('yyyy-mm-dd hh:nn:ss',lwe));
  lmin := MinutesBetween(lwb,lwe);
  ltmp := lwb;
  for I := 1 to lmin div vmin do
  begin
    if (ltmp < lrb) or (ltmp >= lre)  then
    begin
      if ltmp <= lwe then
      begin
        if isam(ltmp) then lap := 'AM'
        else if ispm(ltmp) then
        begin
         if HourOf(ltmp) > 18 then
         lap := 'NT'
         else
         lap := 'PM' ;
        end;
        if ltmp < lrb then
        begin
          if MinutesBetween(ltmp,lrb) < vmin then
          begin
            ltmp := IncMinute(ltmp,vmin);
            Continue;
          end;
        end;
        lstr := formatdatetime('hh:nn',ltmp);
        lsql := lsql + ' insert into tn_pre_ssinfodetail(entryid,TimePeriod,HQty,AQty,' +
	            ' CreatedDate,CreatedBy,EditDate,Editor,remark,ap) ' +
              ' values( '''+ventryid+''','''+lstr+''','+vHqty+',0,getdate(),'+curuserid+',' +
              ' getdate(),'+curuserid+','''','''+lap+''' ' +
              ') ;' + #13#10 ;
      end;
    end;

    ltmp := IncMinute(ltmp,vmin);

  end;

  Result := lsql;

end;
发布了90 篇原创文章 · 获赞 33 · 访问量 21万+

猜你喜欢

转载自blog.csdn.net/y281252548/article/details/95615174
今日推荐