/beta/reports/reports_tah.asp

http://github.com/khaneh/Orders · ASP · 158 lines · 109 code · 15 blank · 34 comment · 12 complexity · d1802610efacab174bc285e06fafe4af MD5 · raw file

  1. <%
  2. 'mySQL = Request.Form("SQL")
  3. 'connector = " WHERE ("
  4. 'Set Params = Request.Form
  5. 'For Each p in Params
  6. ' Param = Params(p)
  7. ' response.write "param : #" & p & " :: " & Param & "# <br>"
  8. ' If Param <> "" AND p <> "SQL" Then
  9. ' Do While Instr(Param,"||") <> 0
  10. ' mySQL = mySQL & connector & p & " " & Left(Param,Instr(Param,"||")-1)
  11. ' connector = " OR "
  12. ' Param = Right(Param,Len(Param) - Instr(Param,"||")-1)
  13. ' Loop
  14. ' mySQL = mySQL & connector & p & " " & Param & ")"
  15. ' connector = " AND ("
  16. ' End If
  17. 'Next
  18. ' ------------------
  19. ' ----- Show Result using:
  20. ' -----
  21. ' ----- String: mySQL ; the SQL
  22. ' ----- ADODB.Connection: conn: ; the connection string
  23. ' -----
  24. ' ------------------
  25. '---------------------------------------------
  26. '------------------------------------ Separate
  27. '---------------------------------------------
  28. function Separate(inputTxt)
  29. if not isnumeric(inputTxt) or "" & inputTxt="" then
  30. Separate=inputTxt
  31. else
  32. myMinus=""
  33. input=inputTxt
  34. t=instr(input, ".")
  35. if t>0 then
  36. expPart = mid(input, t+1, 2)
  37. input = left(input, t-1)
  38. end if
  39. if left(input,1)="-" then
  40. myMinus="-"
  41. input=right(input,len(input)-1)
  42. end if
  43. if len(input) > 3 then
  44. tmpr=right(input ,3)
  45. tmpl=left(input , len(input) - 3 )
  46. result = tmpr
  47. while len(tmpl) > 3
  48. tmpr=right(tmpl,3)
  49. result = tmpr & "," & result
  50. tmpl=left(tmpl , len(tmpl) - 3 )
  51. wend
  52. if len(tmpl) > 0 then
  53. result = tmpl & "," & result
  54. end if
  55. else
  56. result = input
  57. end if
  58. if t>0 then
  59. result = result & "." & expPart
  60. end if
  61. Separate=myMinus & result
  62. end if
  63. end function
  64. '-------------------------------------------------------
  65. '---------------------
  66. 'Set conn = Server.CreateObject("ADODB.Connection")
  67. 'conn.open "driver={Microsoft Access Driver (*.mdb)};dbq=" & Server.MapPath("db1.mdb") & ";"
  68. Set rs = Server.CreateObject("ADODB.Recordset")
  69. rs.Open mySQL, conn, 3, 3
  70. '----------------------------------G e n H T M L T a b l e------------------------------------
  71. Dim myXls
  72. myXls = "<style> .resTable1 { Font-family:tahoma; Font-Size:9pt; Background-color:#336699; border: 1 solid #336699;} .resTable1 th {Background-color:#6699CC;} .resRow1 {Background-color:#F8F8FF;} .resRow0 {Background-color:#CCCCDD;} </style>"
  73. myXls = myXls & "<CENTER><H3>"&Server.HTMLEncode(reportTitle)&"</H3></CENTER>"
  74. myXls = myXls & "<table class='resTable1' Cellspacing=1 Cellpadding=2 align=center><tr>"
  75. For i = 0 To rs.Fields.Count - 1
  76. myXls = myXls & "<th>"&Server.HTMLEncode(rs.Fields(i).Name)&"</th>"
  77. Next
  78. myXls = myXls & "</tr>"
  79. if rs.eof then
  80. myXls = myXls & "<tr><td width='100%' class=resRow1 colspan="&rs.Fields.Count&" align='center'>جوابي يافت نشد</td></tr>"
  81. else
  82. rs.MoveFirst
  83. rowCounter=0
  84. do while Not rs.eof
  85. rowCounter = rowCounter + 1
  86. myXls = myXls &"<tr class='resRow"& (rowCounter mod 2) &"'>"
  87. For i = 0 To rs.Fields.Count - 1
  88. FieldValue = trim(rs.Fields(rs.Fields(i).Name).Value)
  89. 'if isnumeric(FieldValue) then
  90. 'FieldValue = 111
  91. 'end if
  92. if FieldValue <> "" and not isnumeric(FieldValue) then
  93. FieldValue = Server.HTMLEncode(FieldValue)
  94. elseif FieldValue = "" then
  95. FieldValue = "&nbsp;"
  96. end if
  97. myXls = myXls & "<td >" & Separate(FieldValue) & "</td>"
  98. Next
  99. %>
  100. </tr>
  101. <%
  102. rs.MoveNext
  103. loop
  104. End if
  105. rs.Close
  106. set rs = nothing
  107. conn.Close
  108. set conn = nothing
  109. myXls = myXls & "</table>"
  110. Response.Clear()
  111. Response.Buffer = True
  112. Response.AddHeader "Content-Disposition", "attachment;filename=" & reportTitle & ".xls"
  113. Response.ContentType = "application/vnd.ms-excel"
  114. Response.Charset = "UTF-8"
  115. Response.Write myXls
  116. Response.End()
  117. else
  118. %>
  119. <CENTER><H3><%=reportTitle%></H3></CENTER>
  120. <form METHOD="Post" ACTION="?act=show">
  121. <div align="left">
  122. <table align=center border="0" cellpadding="0" cellspacing="0" width="300">
  123. <tr align="center">
  124. <td width="142">date From</td>
  125. <td width="190"><input onblur="acceptDate(this)" NAME="dateFrom" size="20"></td>
  126. </tr>
  127. <tr align="center">
  128. <td width="142">date To</td>
  129. <td width="190"><input onblur="acceptDate(this)" NAME="dateTo" size="20"></td>
  130. </tr>
  131. <tr align="center">
  132. <td colspan=2>
  133. <br><input TYPE="Submit" VALUE="Run Query">
  134. </td>
  135. </tr>
  136. </table>
  137. </div>
  138. </form>
  139. <%
  140. end if
  141. %>
  142. </body>
  143. </html>