2016-09-14 46 views
0

我试图将颜色应用于某些数据行,这通过使用下面的colswitch变量完成。它在软件中的工作原理是无关紧要的,因此我只包含了一个片段。它是将各种逻辑应用于数据的循环的一部分。编辑添加更多的代码...如果语句设置值,不能按预期方式工作

我希望遵循的规则如下,不幸的是,一切都变成了红色,除非我用if语句删除行,否则它会正确地将事情排除在外,除非状态为Open

dateadded是一个包含日期时间值的变量。其中至少有一个超过7天。

objstatus = Open - 设置colswitch黄色

objstatus = Third Party or Waiting for reply, unless older than 7 days - 设置colswitch蓝色

objstatus = >7 days after 'date_added' - 设置colswitch红色

代码:

 <% 
      if DispLastUpd_val = "Y" then 
       IF DBType = "Access" then response.write "<TD bgcolor='" & bghicol & "'><font face='" & stanfont & "' size='" & textsizenorm & "' color='" & menhcol & "'><a href='DispOpenCalls.asp?Type=" & ListType & "&sortit=Max(event_dateadded)&sortorder=" & SortOrder & "&callstat=" & request.querystring("callstat") & "&stat=" & request.querystring("stat")& "'>Last Update</a></font></TD>" 
       IF DBType = "SQL" then response.write "<TD bgcolor='" & bghicol & "'><font face='" & stanfont & "' size='" & textsizenorm & "' color='" & menhcol & "'><a href='DispOpenCalls.asp?Type=" & ListType & "&sortit=LastEvt&sortorder=" & SortOrder & "&callstat=" & request.querystring("callstat") & "&stat=" & request.querystring("stat")& "'>Last Update</a></font></TD>" 
      end if 
      if DispToFix_val = "Y" then 
       if SLAmonitor = 0 then 
        IF DBType = "Access" then response.write "<TD bgcolor='" & bghicol & "'><font face='" & stanfont & "' size='" & textsizenorm & "' color='" & menhcol & "'><a href='DispOpenCalls.asp?Type=" & ListType & "&sortit=(DateDiff({sq}h{sq},call_dateadded,Now())-PRIORITY_FIXHOURS)&sortorder=" & SortOrder & "&callstat=" & request.querystring("callstat") & "&stat=" & request.querystring("stat")& "'>To Fix</a></font></TD>" 
        IF DBType = "SQL" then response.write "<TD bgcolor='" & bghicol & "'><font face='" & stanfont & "' size='" & textsizenorm & "' color='" & menhcol & "'><a href='DispOpenCalls.asp?Type=" & ListType & "&sortit=(DateDiff(hh,call_dateadded,getdate())-PRIORITY_FIXHOURS)&sortorder=" & SortOrder & "&callstat=" & request.querystring("callstat") & "&stat=" & request.querystring("stat")& "'>To Fix</a></font></TD>" 
       end if 
       if SLAmonitor = 1 then 
        response.write "<TD bgcolor='" & bghicol & "'><font face='" & stanfont & "' size='" & textsizenorm & "' color='" & menhcol & "'><a href='DispOpenCalls.asp?Type=" & ListType & "&sortit=((sla_callhours - sla_defhours)-PRIORITY_FIXHOURS)&sortorder=" & SortOrder & "&callstat=" & request.querystring("callstat") & "&stat=" & request.querystring("stat")& "'>To Fix</a></font></TD>" 
       end if 
      end if 

     colswitch = LISTCOL1 
     Do Until myset.EOF 
      if colswitch = LISTCOL1 then colswitch = LISTCOL2 else colswitch = LISTCOL1 
    ' 
    ' 
    'MY CODE IS BELOW 
     if objstatus = "Open" then colswitch = "yellow" 'this works 
     calldays = DateDiff("d",dateadded,now()) 
     if calldays > 7 then colswitch = "red" 'this is where it breaks 
     if objstatus = "Third Party" or objstatus = "Waiting for Reply") and (calldays < 7) then colswitch = "blue" 

     ' 
     ' 
     ' end of my code 
' 

    objslastat = "<img border='0' src='../IMAGES/blanksla.gif'>" 
    masticon = "" 
    urgicon = "" 
    probicon = "" 
    changeicon = "" 
    atticon = "" 

    if SLAmonitor = 0 then 
     If objCallTime => objtimeesc and objstatus = "Open" then objslastat = "<img border='0' src='../IMAGES/Button_sla_esc.gif' title='Exceeds Response Escalation time'>" 
     If objCallTime => objtimesla and objstatus = "Open" then objslastat = "<img border='0' src='../IMAGES/Button_sla.gif' title='Exceeds Response time'>" 
     If objCallTime => objtimefixesc and objstatus <> "Closed" then objslastat = "<img border='0' src='../IMAGES/Button_fix_esc.gif' title='Exceeds Resolve Escalation time'>" 
     If objCallTime => objtimefix and objstatus <> "Closed" then objslastat = "<img border='0' src='../IMAGES/Button_fix.gif' title='Exceeds Resolve time'>" 
    end if 

    if SLAmonitor = 1 then 
     If objsla = "ESC" and objstatus = "Open" then objslastat = "<img border='0' src='../IMAGES/Button_sla_esc.gif' title='Exceeds Response Escalation time'>" 
     If objsla = "RES" and objstatus = "Open" then objslastat = "<img border='0' src='../IMAGES/Button_sla.gif' title='Exceeds Response time'>" 
     If objsla = "ESF" and objstatus <> "Closed" then objslastat = "<img border='0' src='../IMAGES/Button_fix_esc.gif' title='Exceeds Resolve Escalation time'>" 
     If objsla = "FIX" and objstatus <> "Closed" then objslastat = "<img border='0' src='../IMAGES/Button_fix.gif' title='Exceeds Resolve time'>" 
    End if 

    if objmastcallcode > 0 then masticon = "<img border='0' src='../IMAGES/linked.gif' title='Linked " & tgencallterm & " - Master " & objMastCallCode & "'>" 
    if objmastcall = "Y" then masticon = "<img border='0' src='../IMAGES/linkedm.gif' title='Master " & tgencallterm & "'>" 

    if objurg = "T" then urgicon = "<img border='0' src='../IMAGES/urgent.gif' title='Urgent'>" 
    if objurguser = "T" then urgicon = "<img border='0' src='../IMAGES/urgent.gif' title='Urgent'>" 

    if objki = "T" then probicon = "<img border='0' src='../IMAGES/prob.gif' title='Problem " & tgencallterm & "'>" 

    if objnochange > 0 then changeicon = "<img border='0' src='../IMAGES/change.gif' title='" & tchangetext & "'>" 

    if objnoatt > 0 then atticon = "<img border='0' src='../IMAGES/attachment.gif' title='Attachments'>" 

    ' This bit avoids issue with Team Calls when using Next/Prev 
    if request.querystring("type") = "Team" then qry = "" 

     Response.Write "<TR><TD nowrap bgcolor='" & colswitch & "'>" & urgicon & "</TD>" 
     Response.Write "<TD nowrap bgcolor='" & colswitch & "'>" & atticon & "</TD>" 
     Response.Write "<TD nowrap bgcolor='" & colswitch & "'><a href='UpdateCall.asp?inp_call_id=" & objcallcode & "&qry=" & qry & "'><font face='" & stanfont & "' size='" & textsizelist & "' color='" & menicol & "'>" & objcallcode & "</font></TD><TD bgcolor='" & colswitch & "'><font face='" & stanfont & "' size='" & textsizelist & "' color='" & menicol & "'>" & objslastat & "</font></TD>" 
     response.write "<TD bgcolor='" & colswitch & "'>" & masticon & "</font></TD>" 
     response.write "<TD bgcolor='" & colswitch & "'>" & probicon & "</font></TD>" 
     response.write "<TD bgcolor='" & colswitch & "'>" & changeicon & "</font></TD>" 

     ' Loop through data results 
     For x = 0 to ColCount 
     response.write "<TD " & ColWrap(x) & " bgcolor='" & colswitch & "'><font face='" & stanfont & "' size='" & textsizelist & "' color='" & menicol & "'>" 
     if isdate(ColResults(x)) then response.write FmtDateDisp(ColResults(x)) else response.write ColResults(x) 
     response.write "</font></TD>" 
    Next 

     if DispLastUpd_val = "Y" then response.write "<TD nowrap bgcolor='" & colswitch & "'><font face='" & stanfont & "' size='" & textsizelist & "' color='" & menicol & "'>" & FmtDateDisp(objLastEvt) & " (" & DateDiff("d",objLastEvt ,now()) & " Days)</font></TD>" 

     if DispToFix_val = "Y" then 
      if objtimefix = "" or isnull(objtimefix) then objtimefix = 0 
      if objCallTime= "" or isnull(objCallTime) then objCallTime= 0 
      response.write "<TD nowrap align='right' bgcolor='" & colswitch & "'><font face='" & stanfont & "' size='" & textsizelist & "' color='" & menicol & "'>" & formatnumber(objtimefix - objCallTime,2) & " Hrs</font></TD></TR>" 
     end if 

     colswitch = ocolswitch 
     myset.MoveNext 

Loop 
%> 

我在这里做得不对?

+0

尝试评论我的答案。然后尝试运行它。如果错误仍然存​​在,那么错误必须在您的循环中 – Muj

+0

错误只发生在'elseif' x2语句中。如果我将它们更改回'if'并移除'endif',它可以正常工作,但不能正确分配颜色。 –

回答

0

你的问题对我来说不是很清楚。

尝试用它来取代你的代码:

if objstatus = "Open" then colswitch = "yellow" 
calldays = DateDiff("d",dateadded,now()) 
elseif calldays > 7 then colswitch = "red" 
elseif (objstatus = "Third Party" or objstatus = "Waiting for Reply") and (calldays < 7) then colswitch = "blue" 
end if 

如果有任何事情是错的只是通知我。

+0

当我尝试这个时,我得到一个错误; 'Loop' –

+0

如果 –

+0

@ jbab8能告诉你所有代码,那么即使结束,它仍然给我预期的循环错误。所以我可以赶上它为什么会有这样的错误。用这个编辑你的问题 – Muj