【发布时间】:2017-03-31 12:33:28
【问题描述】:
我被投入了一个新项目,这显然不仅仅是过时的。该应用程序以一种非常奇怪的模式在数据库中保存了开放时间,这让我疯狂了一个多星期。
请看这张图片:
如您所见,营业时间以如下模式保存:
dayFrom | dayTo | timeFrom | timeTo
=======================================
monday | friday | 07:00 | 17:00
saturday | | 08:00 | 12:00
只是为了防止任何误解:
周一至周五 07:00 至 17:00 开放
从 08:00 到 12:00 开放 SA
周日休息
现在,这似乎已经有点不对了,但坚持下去,表格可能看起来像这样:
dayFrom | dayTo | timeFrom | timeTo
=======================================
monday | tuesday | 07:00 | 14:00
wednesday | | 08:00 | 12:00
thursday | friday | 07:30 | 13:00
saturday | | 08:00 | 12:00
所以,现在我的问题是:我需要创建一个循环(或类似的东西)来创建一个有效的 json 字符串,其中包含所有这些开放时间。
现在,我有这个:
jsonAppendix = "{""openingHours"":["
for i = 1 To cint(hoechsterTag)
jsonAppendix = jsonAppendix & "{""dayOfWeek"":" & i & ", ""from1"":""" & rs("ZeitVon") & """, ""to1"":""" & rs("ZeitBis") & """},"
next
'Remove last comma
jsonAppendix = LEFT(jsonAppendix, (LEN(jsonAppendix)-1))
jsonAppendix = jsonAppendix & "]}"
如果我只有“周一至周五”,它已经可以使用,但不考虑第二个(或下一个条目)。
输出看起来像这样,这显然是正确的:
{
"openingHours":[
{
"dayOfWeek":1,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":2,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":3,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":4,
"from1":"07:00",
"to1":"17:00"
},
{
"dayOfWeek":5,
"from1":"07:00",
"to1":"17:00"
}
]
}
但是“星期六”没有被识别。
我的函数如下所示:
SQL = "SELECT * FROM StandortOpen WHERE S_ID = " & iStandortId & " AND OpenArt = '" & sArt & "' ORDER BY Sort,OpenArt DESC"
call openRS(SQL)
'day-mapping
tageV(0) = replace(rs("TagVon"),"Mo", 1)
tageV(1) = replace(rs("TagVon"),"Di", 2)
tageV(2) = replace(rs("TagVon"),"Mi", 3)
tageV(3) = replace(rs("TagVon"),"Do", 4)
tageV(4) = replace(rs("TagVon"),"Fr", 5)
tageV(5) = replace(rs("TagVon"),"Sa", 6)
tageV(6) = 7
tageB(0) = replace(rs("TagBis"),"Mo", 1)
tageB(1) = replace(rs("TagBis"),"Di", 2)
tageB(2) = replace(rs("TagBis"),"Mi", 3)
tageB(3) = replace(rs("TagBis"),"Do", 4)
tageB(4) = replace(rs("TagBis"),"Fr", 5)
tageB(5) = replace(rs("TagBis"),"Sa", 6)
'for example: mo - fr
for each item in tageV
'save smallest weekday
if(isNumeric(item) AND item > "") then
if(cint(item) <= cint(niedrigsterTag)) then
niedrigsterTag = cint(item)
end if
end if
next
for each item in tageB
'save highest weekday
if(isNumeric(item) AND item > "") then
if(cint(item) >= cint(hoechsterTag)) then
hoechsterTag = cint(item)
end if
end if
next
还有openRS()-函数:
sub openRS(str_sql)
'Response.write "SQL: " & str_sql & "<br>"
set rs = CreateObject("ADODB.Recordset")
rs.open str_sql,conn,1,3
end sub
基本上:将数字映射到日期,迭代(或比较它们以获得时间跨度)。
我也在使用RecordSet。也许我需要使用数组或类似的东西?任何帮助将不胜感激。
我不能改变桌子和它的设计,我必须坚持那个gargabe
【问题讨论】:
标签: sql json tsql vbscript asp-classic