else begin
oStartDate := FieldByName('offline_start_date').AsDateTime;
oTime := FieldByName('offline_hours').AsInteger;
if (FieldByName('offline_flag').asstring = '1')
and ( oStartDate <= StrToDate(FormatDateTime('YYYY-MM-DD', Now))) then
begin
if (ROUND((StrToDate(FormatDateTime('YYYY-MM-DD', Now))
- Trunc(oStartDate))) *24) < oTime then
begin
//可以脱机
dmComm.UserInfo.offlineHotType := '2'; // 2表示被动脱机
LoginOK := True;
dmcomm.SysParam.ConnectMode := 'off-line';
dmcomm.UserInfo.SysAccount := 'local';
CreateMainForm;
dmcomm.refreshLocalTables;
end
else begin
i_Offline_hours := FieldByName('ioffline_hours').AsInteger;
i_offline_flag := FieldByName('ioffline_flag').AsString;
if (i_offline_flag = '1') and (i_Offline_hours>used_i_offline_time) then
begin
LoginOK := True;
dmComm.UserInfo.i_offline_remaining_time := i_Offline_hours
- used_i_offline_time;
dmcomm.SysParam.ConnectMode := 'off-line';
dmComm.UserInfo.offlineHotType := '1'; //表示自主脱机
dmcomm.UserInfo.SysAccount := 'local';
CreateMainForm;
dmcomm.refreshLocalTables;
end
else begin
DialogInformation('此账号没有自主脱机权限或者自主脱机时长已用完');
exit;
end;
end;
end
end;
直接见代码就OK了
还有一个简单的DEMO,日期相减获得天数,注意函数的运用
procedure TForm1.btn1Click(Sender: TObject);
var d1, d2: TDateTime;
d3: Integer;
begin
d1 := StrToDate(FormatDateTime('YYYY-MM-DD', Now));
d2 := StrToDate('2001-09-01');
d3 := round(d2-d1);
Showmessage(IntTostr(d3));
end;