📄 wwdbdatetimepicker.pas
字号:
{Determine Datatype of Combos}
function TwwDBCustomDateTimePicker.isDateField:boolean;
begin
result:=((FDatalink.Field<>Nil) and (wwGetDataType(FDataLink.Field) = ftDate))
or ((FDatalink.Field=Nil) and (FUnboundDataType = wwDTEdtDate));
end;
//12/4/2001-PYW-Check for ftTimeStamp datatype.
function TwwDBCustomDateTimePicker.isTimeOnlyField:boolean;
begin
result := ((FDatalink.Field<>Nil) and (wwGetDataType(FDataLink.Field) = ftTime))
or ((FDatalink.Field=Nil) and(FUnboundDataType = wwDTEdtTime)) or
// Check to see if this is a TDateTime field with a displayformat that does not show any date information.
((FDatalink.Field<>nil) and
((wwGetDataType(FDataLink.Field)=ftDateTime) or (wwGetDataType(FDataLink.Field)=ftTimeStamp)) and
(not DateTokenInString(GetEffectiveDisplayFormat(True))));
end;
function TwwDBCustomDateTimePicker.isDateOnlyField:boolean;
begin
result:= False;
if (FDatalink.Field<>Nil) and
(wwGetDataType(FDataLink.Field) = ftDate) then result:= True;
if ((FDatalink.Field=Nil) and(FUnboundDataType = wwDTEdtTime)) then result:= True;
// Check to see if this is a TDateTime field with a displayformat that
// does not show any time information.
if ((FDatalink.Field<>nil) and
((wwGetDataType(FDataLink.Field)=ftDateTime) or (wwGetDataType(FDataLink.Field)=ftTimeStamp)) and
(not TimeTokenInString(GetEffectiveDisplayFormat(True)))) then result:= True;
end;
function TwwDBCustomDateTimePicker.isDateTimeField:boolean;
begin
result:=((FDatalink.Field<>Nil) and
((wwGetDataType(FDataLink.Field)=ftDateTime) or (wwGetDataType(FDataLink.Field)=ftTimeStamp)))
or ((FDatalink.Field=Nil) and (FUnboundDataType = wwDTEdtDateTime));
end;
{Get the Maximum allowable Tokens for this DateTimePicker based on the formatstr}
function TwwDBCustomDateTimePicker.GetMaxTokens(formatstr:string):integer;
var s:string;
i,tokenct:integer;
begin
// formatstr:=GetFormatStr;
i:=1;
tokenct:=0;
while (i < length(formatstr)) do begin
case AnsiUpperCase(formatstr[i])[1] of
'D': begin
GetCompleteToken('d',formatstr,s,i);
if isDateTimeField or isDateField then
tokenct:= tokenct+1;
end;
'M': begin
GetCompleteToken('m',formatstr,s,i);
{If this is a TDateField, then don't count minutes as a token}
if (s = 'mm') or (s = 'm') then begin
if isDateTimeField or isDateField then
tokenct := tokenct+1;
end
else if (s='nn') or (s='n') then begin
if isTimeOnlyField or isDateTimeField then
tokenct := tokenct+1;
end
else begin
if isDateTimeField or isDateField then
tokenct := tokenct+1;
end;
end;
'Y': begin
if isDateTimeField or isDateField then
tokenct:= tokenct+1;
GetCompleteToken('y',formatstr,s,i);
end;
'H': begin
if isTimeOnlyField or isDateTimeField then
tokenct:= tokenct+1;
GetCompleteToken('h',formatstr,s,i);
end;
'N': begin
if isDateTimeField or isTimeOnlyField then
tokenct:= tokenct+1;
GetCompleteToken('n',formatstr,s,i);
end;
'S': begin
if isDateTimeField or isTimeOnlyField then
tokenct:= tokenct+1;
GetCompleteToken('s',formatstr,s,i);
end;
'A': begin
if isDateTimeField or isTimeOnlyField then
tokenct:= tokenct+1;
GetCompleteToken('a',formatstr,s,i);
end;
end;
i:=i+1;
end;
result := tokenct;
end;
{This function parses the passed in Format string to determine if this
format string is an AM/PM or 24 hour Time Field}
function TwwDBCustomDateTimePicker.IsAMPM(str:string):boolean;
var i:integer;
begin
for i:= 1 to length(str) do {9/10/98 - Fix range check error and loop from 1 to length(str)}
begin
if (AnsiUpperCase(str[i])[1]='A') then begin
result := True;
exit;
end;
end;
result := False;
end;
//Check to see if there is any datetokens in the passed format string.
function TwwDBCustomDateTimePicker.DateTokenInString(formatStr:string):boolean;
var i:integer;
s:String;
begin
Result := False;
if formatstr = '' then begin
result := True;
exit;
end;
formatstr := ReplaceStrWithStr(formatstr,'c',shortdateformat+' '+longtimeformat);
formatstr := ReplaceStrWithStr(formatstr,'dddddd',longdateformat);
formatstr := ReplaceStrWithStr(formatstr,'ddddd',shortdateformat);
formatstr := ReplaceStrWithStr(formatstr,'tt',longtimeformat);
formatstr := ReplaceStrWithStr(formatstr,'t',shorttimeformat);
i:=1;
s:='';
while (i < length(formatstr)) do begin
case AnsiUpperCase(formatstr[i])[1] of
'D':begin
GetCompleteToken('d',formatstr,s,i);
result := True;
end;
'M':begin
GetCompleteToken('m',formatstr,s,i);
if not((s = 'n') or (s='nn')) then
result := True;
end;
'Y':begin
GetCompleteToken('y',formatstr,s,i);
result := True;
end;
'H':GetCompleteToken('h',formatstr,s,i);
'N':GetCompleteToken('n',formatstr,s,i);
'S':GetCompleteToken('s',formatstr,s,i);
'A':GetCompleteToken('a',formatstr,s,i);
end;
if Result then exit;
i:=i+1;
end;
end;
//Check to see if there is any datetokens in the passed format string.
function TwwDBCustomDateTimePicker.TimeTokenInString(formatStr:string):boolean;
begin
Result := False;
if formatstr = '' then begin
result := True;
exit;
end;
formatstr:= uppercase(formatstr);
if pos('H', formatstr)>0 then result:= True;
if pos('N', formatstr)>0 then result:= True;
if pos('S', formatstr)>0 then result:= True;
if pos('T', formatstr)>0 then result:= True;
if pos('C', formatstr)>0 then result:= True;
end;
function TwwDBCustomDateTimePicker.GetDatetimeToken(datetime1:TDateTime;index:integer;
var pos,len:integer;var S:string):string;
var i,tokenct:integer;
totalstr,tempstr:string;
Year, Month, Day:Word;
Hour, Minute, Second, Msec:Word;
formatstr,AMstring:string;
AMPMflag:boolean;
begin
tokenct := 0;
len:=0;
pos:=0;
totalstr:='';
DecodeDate(DateTime1, Year, Month, Day);
DecodeTime(DateTime1, Hour, Minute, Second, Msec);
formatstr := GetFormatStr;
AMPMFlag := IsAMPM(formatstr);
i:=1;
//1/10/2002 Needs to handle case where yyyy/m/d or yyyy/d/m where last character is single letter token.
while (i <= length(formatstr)) do begin
s:='';
case AnsiUpperCase(formatstr[i])[1] of
'D':begin
if isDateTimeField or isDateField then
tokenct:= tokenct+1;
GetCompleteToken('d',formatstr,s,i);
if (s = 'ddddd') or (s= 'dddddd') then
tempstr := '';
if s = 'dddd' then
tempstr:=longdaynames[DayOfWeek(DateTime1)]
else if s = 'ddd' then
tempstr := Shortdaynames[DayOfWeek(DateTime1)]
else if (s = 'dd') or (s = 'd') then begin
if (s='dd') and (length(IntToStr(Day))=1) then
tempstr := '0'+IntToStr(Day)
else tempstr := IntToStr(Day);
end;
len := length(tempstr);
totalstr := totalstr+tempstr;
if tokenct = index then break;
pos:=pos+len;
end;
'M':begin
GetCompleteToken('m',formatstr,s,i);
if s = 'mmmm' then
tempstr := longmonthnames[Month]
else if s = 'mmm' then
tempstr := Shortmonthnames[Month]
else if (s = 'mm') or (s = 'm') then begin
if (s='mm') and (length(IntToStr(Month))=1) then
tempstr := '0'+IntToStr(Month)
else tempstr := IntToStr(Month);
end
else if (s='nn') or (s='n') then begin
if (s='nn') and (length(IntToStr(Minute))=1) then
tempstr := '0'+IntToStr(Minute)
else tempstr := IntToStr(Minute);
end;
len := length(tempstr);
totalstr := totalstr+tempstr;
if ((s='n') or (s='nn')) then begin
if isDateTimeField or isTimeOnlyField then begin
tokenct:= tokenct+1;
if tokenct = index then break;
end
else begin
s:='';
end;
end
else begin
if isDateTimeField or isDateField then
tokenct:= tokenct+1;
if tokenct = index then break;
end;
pos:=pos+len;
end;
'Y':begin
if isDateTimeField or isDateField then
tokenct:= tokenct+1;
GetCompleteToken('y',formatstr,s,i);
len := length(s);
if (s = 'yy') then
totalstr := totalstr+IntToStr(Year mod 100)
else
totalstr := totalstr+IntToStr(Year);
if tokenct = index then break;
pos:=pos+len;
end;
'H':begin {Get complete token}
GetCompleteToken('h',formatstr,s,i);
{If Hour = 0 then set Hour to 12}
if Hour = 0 then Hour := 12;
if (s='hh') and (length(IntToStr(Hour))=1) then
{Pad Single Digit Hours with a '0'}
tempstr := '0'+IntToStr(Hour)
else begin
if AMPMFlag and (Hour >12) and (Hour < 22) then
tempstr := IntToStr(Hour-12)
else
tempstr := IntToStr(Hour);
end;
{Check to See if this is a Single or Double Digit Hour}
if (s='h') and ((Hour < 10) or
(AMPMFlag and (Hour > 12) and (Hour < 22))) then
len:=1
else len:=2;
totalstr := totalstr+tempstr;
if isDateTimeField or isTimeOnlyField then begin
tokenct:= tokenct+1;
if tokenct = index then break;
end
else begin
s:='';
end;
pos:=pos+len;
end;
'N':begin
GetCompleteToken('n',formatstr,s,i);
if (s='nn') and (length(IntToStr(Minute))=1) then
tempstr := '0'+IntToStr(Minute)
else tempstr := IntToStr(Minute);
len := length(tempstr);
totalstr := totalstr+tempstr;
if isDateTimeField or isTimeOnlyField then begin
tokenct:= tokenct+1;
if tokenct = index then break;
end
else begin
s:='';
end;
pos:=pos+len;
end;
'S':begin
GetCompleteToken('s',formatstr,s,i);
if (s='ss') and (length(IntToStr(Second))=1) then
tempstr := '0'+IntToStr(Second)
else tempstr := IntToStr(Second);
len := length(tempstr);
totalstr := totalstr+tempstr;
if isDateTimeField or isTimeOnlyField then begin
tokenct:= tokenct+1;
if tokenct = index then break;
end
else begin
s:='';
end;
pos:=pos+len;
end;
'/':begin
pos:=pos+1;
totalstr := totalstr+'/';
end;
':':begin
pos:=pos+1;
totalstr := totalstr+':';
end;
'A':begin
if Hour = 0 then Hour := 12;
GetCompleteToken('a',formatstr,s,i);
AMString := '';
if (length(s)=3) then {Handle A/P DateTime DisplayFormat}
begin
if (hour < 12) then
AMstring := s[1]
else AMstring := s[3];
end
else if (length(s) = 5) then {Handle Am/Pm DateTime DisplayFormat}
begin
// if (hour < 12) then
// AMString := formatstr[1]+formatstr[2]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -