?? count.asp
字號:
<%response.expires=0%>
<%Response.Buffer=true%>
<!-- #include file="../conn_lr.asp"-->
<!-- #include file="../css.asp"-->
<%
oabusyname=session("oabusyname")
oabusyusername=session("oabusyusername")
oabusyuserdept=session("oabusyuserdept")
oabusyuserlevel=session("oabusyuserlevel")
if oabusyusername="" then
response.write("<script language=""javascript"">")
response.write("window.top.location.href='../../default.asp';")
response.write("</script>")
response.end
end if
%>
<%
href="count.asp"
'on error resume next
Dim mTable
Dim Item
Dim mRecordCount, mFieldCount
Dim mCond, mSortBy, mQueryString
Dim mExcludeFieldTypes
Dim mFieldType, mFieldContent
Dim mPageSize, mPageCount, mPageNo
Dim i, j , FieldsInfo()
Dim LinkFlag,LinkItem(),LinkItemLink()
Dim ReCount '是否重新計算查詢語句
Dim Count()
mTable =Request("mTable") ' 數據表名稱
mFiledsCount=CINT(Request("mFiledsCount")) ' 要顯示的字段數目
mFileds=Request("mFileds") ' 要顯示的字段列表
mFiledsCaptions=Request("mFiledsCaptions") ' 要顯示的標題列表
mFiledsWidths=Request("mFiledsWidths") ' 要顯示的字段寬度列表
mCond2 = Request("mCond2") ' 基本查詢條件
mSortBy2=Request("mSortBy2") ' 排序的字段
mTitle = Request("mTitle") ' 頁面標題
mImage=Request("mImage") ' 標題圖標
mCountField=Request("mCountField") ' 要統計的字段
mGroupField=Request("mGroupField") ' 要分組的字段
ReCount=0
IF Request("mTable").count>0 THEN
ReCount=1
Session("mTable")=mTable
Session("mFiledsCount")=mFiledsCount
Session("mFileds")=mFileds
Session("mFiledsCaptions")=mFiledsCaptions
Session("mFiledsWidths")=mFiledsWidths
Session("mCond2")=mCond2
Session("mSortBy2")=mSortBy2
Session("mTitle")=mTitle
Session("mImage")=mImage
Session("mCountField")=mCountField
Session("mGroupField")=mGroupField
Session("mCond")=""
Session("mSortBy")=""
ELSE
ReCount=0
mImage=Session("mImage")
mTitle=Session("mTitle")
mTable=Session("mTable")
mFiledsCount=Session("mFiledsCount")
mFileds=Session("mFileds")
mFiledsCaptions=Session("mFiledsCaptions")
mFiledsWidths=Session("mFiledsWidths")
mCond2=Session("mCond2")
mSortBy2=Session("mSortBy2")
mCountField=Session("mCountField")
mGroupField=Session("mGroupField")
END IF
CountField=mCountField
if CountField<>"" then
Set Rs1 = Server.CreateObject("ADODB.Recordset")
Rs1.open "select DISTINCT " & CountField & " from " & mTable ,oconn,1,1
mFiledsCount = rs1.recordcount + mFiledsCount+1
ListFields=""
ListNames=""
ListWidths=""
while not rs1.eof
if len(rs1.Fields(CountField).type)>=3 then
ListFields=ListFields & "sum(abs(" & CountField & "='" & rs1(CountField) & "')),"
else
ListFields=ListFields & "sum(abs(" & CountField & "=0" & rs1(CountField) & ")),"
end if
ListNames =ListNames & rs1(CountField) & ","
ListWidths=ListWidths & "60,"
rs1.movenext
wend
mFileds = mFileds+ListFields +"count(*),"
mFiledsCaptions = mFiledsCaptions+ListNames+"合計,"
mFiledsWidths = mFiledsWidths+ListWidths+"60,"
end if
if mGroupField<>"" then mCond2=mCond2 & " Group By " & mGroupField & " "
'response.clear
'response.write(mFileds & "<br>" & mFiledsCaptions & "<br>" & mFiledsWidths & "<br>" & mFiledsCount)
'response.end
title=mTitle
image=mImage
Redim FieldsInfo(3,mFiledsCount)
t2=1
t4=1
t6=1
For i=1 to mFiledsCount
t1=instr(t2,mFiledsWidths,",")
t3=instr(t4,mFileds,",")
t5=instr(t6,mFiledsCaptions,",")
temp1=mid(mFiledsWidths,t2,t1-t2)
temp2=mid(mFileds,t4,t3-t4)
temp3=mid(mFiledsCaptions,t6,t5-t6)
t2=t1+1
t4=t3+1
t6=t5+1
FieldsInfo(1,i)=temp1
FieldsInfo(2,i)=replace(temp2,"^",",")
FieldsInfo(3,i)=temp3
Next
mCond = Request("key") & " LIKE '%" & trim(Request("keyword")) & "%'"
if Request("key").count>0 then
Session("mCond")=mCond
ELSE
mCond=Session("mCond")
END IF
mSortBy =Request("mSortBy")
if Request("mSortBy").count>0 then
if Session("Forward")="ASC" then Session("Forward")="DESC" else Session("Forward")="ASC"
Session("mSortBy")=mSortBy
ELSE
mSortBy=Session("mSortBy")
END IF
IF ReCount THEN
'/////////////////////開始計算SQL查詢字符串////////////////////////////////////////
temp=replace(left(mFileds,len(mFileds)-1),"^",",")
mQueryString = "SELECT " & temp & " from " & mTable
Session("mQueryString")=mQueryString
ELSE
mQueryString=Session("mQueryString")
END IF
'/////////////////////計算SQL查詢字符串結束/////////////////////////////////////////
'/////////////////////處理查詢條件/////////////////////////////
if mCond2<>"" then
Cond=" where " +mCond2
end if
'///////////////////////處理排序條件///////////////////////////////
if mSortBy<>"" and mSortBy2<>"" then
SortBy=" ORDER BY "+mSortBy+","+mSortBy2
elseif mSortBy+mSortBy2="" then
SortBy=""
else
SortBy=" ORDER BY "+mSortBy+mSortBy2
end if
if mSortBy<>"" then SortBy=" ORDER BY " + mSortBy + " " + Session("Forward")
mQueryString= mQueryString & Cond & SortBy
Session("SQL")="select * from " & mTable & Cond & SortBy
mPageSize = Session("iPageSize")
Set Rs = Server.CreateObject("ADODB.Recordset")
Rs.PageSize=mPageSize
'response.write(mQueryString)
'response.end
Rs.Open mQueryString,oconn,1,3
' response.end
Response.Buffer = True
mPageCount=Rs.PageCount
mFieldCount=Rs.Fields.count
redim count(mFieldCount)
Select case Request("opFlag")
case "cmdExportExcel"
Response.ContentType = "*/*.csv"
For i=1 to mFiledsCount
if FieldsInfo(1,i)<>"0" then
Response.write(FieldsInfo(3,i))
Response.write(",")
end if
Next
Response.write(chr(13)+chr(10))
Do While Not Rs.EOF
For i = 0 to mFieldCount-1
if FieldsInfo(1,i+1)<>"0" then
Response.write(Rs.Fields(i))
Response.write(",")
end if
Next
Response.write(chr(13)+chr(10))
Rs.MoveNext
Loop
Rs.Close
Set Rs = Nothing
Response.end
'//////////////////////執行打印操作////////////////////////////////////////
case "cmdPrint"
'Response.clear
rs.PageSize=25
For pn=1 to rs.PageCount
Response.Write("<TITLE>" & mTitle & "</TITLE><style>table{border:solid windowtext .5pt;border-right:none;border-bottom:none;}td{border:solid windowtext .5pt;border-left:none;border-top:none;mso-border-left-alt:solid windowtext .5pt;padding:0mm 5.4pt 0mm 5.4pt }</style><body style='font-size:10pt'><p align=center style='font-size:14pt;font-family:黑體'>" & mTitle & "</p><TABLE CELLPADDING=0 CELLSPACING=0 BORDER=1 WIDTH=100% bgcolor='#000000' align=center style='font-size:10pt' >")
Response.Write("<TR bgcolor='#ffffff' height=30 align=center >")
'輸出列標題
For i=1 to mFiledsCount
if FieldsInfo(1,i)<>"0" then
Response.write("<TD ")
if FieldsInfo(1,i)<>"" then Response.write("width=" & FieldsInfo(1,i))
Response.Write("><b>" & FieldsInfo(3,i) & " </b></TD>")
END IF
Next
Response.write("</TR>")
'///////////////////遍歷數據記錄集,輸出數據表/////////////////////////
Do While Not Rs.EOF
'///////////////////////行開輸出始///////////////////////////
Response.write("<TR bgcolor=#ffffff height=30 >")
'遍歷每一個字段
For i = 0 to mFieldCount-1
if FieldsInfo(1,i+1)<>"0" then
mFieldType = Rs.Fields(i).Type
If Len(mFieldType) < 3 Then '數字型
count(i)=count(i)+Rs.Fields(i).value '求和
mFieldType = mFieldType & "XX"
End If
If InStr(mExcludeFieldTypes, mFieldType) = 0 Then
mFieldContent = Rs.Fields(i)
Response.Write("<TD width='" & FieldsInfo(1,i+1) &"'")
if FieldsInfo(1,i+1)="" then Response.write" align=left " else Response.write " align=center "
Response.write(" >" & mFieldContent & " </TD>")
End If
END IF
Next
Response.write("</tr>")
Rs.MoveNext
Loop
Response.write("<TR bgcolor=#ffffff height=30 >")
Response.Write("<TD style='border:solid windowtext .5pt;border-left:none;border-top:none;mso-border-left-alt:solid windowtext .5pt;padding:0mm 5.4pt 0mm 5.4pt'' ")
Response.write " align=center "
Response.write(" >合計</TD>")
For i = 1 to mFieldCount-1
if FieldsInfo(1,i+1)<>"0" then
Response.Write("<TD style='border:solid windowtext .5pt;border-left:none;border-top:none;mso-border-left-alt:solid windowtext .5pt;padding:0mm 5.4pt 0mm 5.4pt'' width='" & FieldsInfo(1,i+1) &"'")
if FieldsInfo(1,i+1)="" then Response.write" align=left " else Response.write " align=center "
Response.write(" >" & count(i) & " </TD>")
end if
Next
Response.write("</table>")
next
Rs.Close
Set Rs = Nothing
Response.write("<SCRIPT language='Javascript'>window.print();</script></body>")
Response.end
'//////////////////////打印操作結束////////////////////////////////////////
end Select
IF mPageCount > 1 Then
if Request("PageNo")<>"" then mPageNo =cint(Request("PageNo"))
Else
mPageNo = 1
End If
if mPageNo<1 then mPageNo=1
if mPageNo>mPageCount then mPageNo=mPageCount
'當前頁
if not Rs.eof then Rs.AbsolutePage = mPageNo
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!-- #include file="../inc/css.asp" -->
<style>
table{font-size:12px}
</style>
</head>
<body leftmargin="0" topmargin="0" onselectstart="if(event.srcElement.tagName!='INPUT') event.returnValue=false " toncontextmenu=self.event.returnValue=false>
<!-- #include file="../inc/title.asp" -->
<table bgcolor=#49A7F4 cellspacing=1 cellpadding=1 width=95% border=0 class=vtext align=center>
<tr bgcolor=#49A7F4 >
<td height="25" bgcolor="#49A7F4" > <b></b>
<%if not rs.eof then%>
<td height="25" class=coolBarflat onClick="window.location.href='<%=href%>?opFlag=cmdPrint'" onMouseOver="this.className='coolbar'" onMouseOut="this.className='coolBarflat'" onMouseDown="this.className='coolBardown'" width="25" align="center" valign="middle">
<img src="images/print.GIF" width="16" height="16"align="absmiddle" onClick="window.location.href='<%=href%>?opFlag=cmdPrint'" alt="打印">
</td>
<td height="25" class=coolBarflat onClick="window.location.href='<%=href%>?opFlag=cmdExportExcel'"onMouseOver="this.className='coolbar'" onMouseOut="this.className='coolBarflat'" alt="數據導出" onMouseDown="this.className='coolBardown'" width="25" align="center" valign="middle">
<img src="images/save.GIF" width="16" height="16" align="absmiddle" onClick="window.location.href='<%=href%>?opFlag=cmdExportExcel'" alt="數據導出">
</td>
<%end if%>
</tr>
</table>
<br>
<%
Response.Write("<TABLE CELLPADDING=0 CELLSPACING=1 BORDER=0 WIDTH=95% bgcolor=#ffffff align=center class='" & Session("vtext") & "' >")
Response.Write("<TR bgcolor=#F4F3F3 height=25 align=center class=coolBar>")
'輸出列標題
For i=1 to mFiledsCount
if FieldsInfo(1,i)<>"0" then
tSort=replace(FieldsInfo(2,i)," ","%20")
if instr(FieldsInfo(2,i)," ")<>0 or instr(FieldsInfo(2,i),",")<>0 then tSort=""
Response.write("<a href=" & href & "?mSortBy=" & tSort & "><TD class=coolBarflat onMouseOver=this.className='coolbar' onMouseOut=this.className='coolBarflat' onMouseDown=this.className='coolBardown' ")
if FieldsInfo(1,i)<>"" then Response.write("width=" & FieldsInfo(1,i))
Response.Write("><b>" & FieldsInfo(3,i))
if FieldsInfo(3,i)="" then Response.Write(" ")
Response.Write( "</b>")
if instr(SortBy,FieldsInfo(2,i))<>0 then
if Session("Forward")="ASC" then Response.write(" <img src=images/up.gif >") else Response.write(" <img src=images/down.gif >")
end if
Response.Write("</TD></a>")
end if
Next
Response.write("</TR>")
'///////////////////遍歷數據記錄集,輸出數據表/////////////////////////
Do While Not Rs.EOF
'///////////////////////行開輸出始///////////////////////////
Response.write("<TR bgcolor=#ffffff height=25 onmouseover=ov(this) onmouseout=mo(this)>")
'遍歷每一個字段
For i = 0 to mFieldCount-1
if FieldsInfo(1,i+1)<>"0" then
mFieldType = Rs.Fields(i).Type
If Len(mFieldType) < 3 Then
count(i)=count(i)+Rs.Fields(i).value '求和
mFieldType = mFieldType & "XX"
End If
If InStr(mExcludeFieldTypes, mFieldType) = 0 Then
mFieldContent = Rs.Fields(i)
Response.Write("<TD width='" & FieldsInfo(1,i+1) &"'")
if instr(SortBy,FieldsInfo(2,i+1))<>0 then Response.write(" bgcolor=#f6f6f6 ") 'EFF9E8
if FieldsInfo(1,i+1)="" then Response.write" align='left' " else Response.write " align='center' "
Response.write(" >" & mFieldContent & " </TD>")
End If
end if
Next
Response.write("</TR>")
'///////////////////////行輸出結束,轉向下一行///////////////////////////
Rs.MoveNext
Loop
Response.write("<TR bgcolor=#ffffff height=25 onmouseover=ov(this) onmouseout=mo(this)><TD align=center>合計</TD> ")
For i = 1 to mFieldCount-1
if FieldsInfo(1,i+1)<>"0" then
Response.Write("<TD align=center")
Response.write(" >" & count(i) & " </TD>")
end if
Next
Response.Write("</TABLE>")
IF Rs.RecordCount=0 then '如果沒有找到任何記錄,自動清除查詢條件
Session("mCond")=""
%>
<table bgcolor=#49A7F4 cellspacing=1 cellpadding=0 width=95% border=0 class=vtext align=center >
<tr bgcolor=ffffff align=right>
<td height="25" align="left" ><b><font color=red>對不起,沒有所要的記錄!</font></b>
</td>
</tr>
</table>
<%end if%>
<p align="center">
<input type="button" name="Button" value="返回" class=vinputbutton onClick="javascript:window.history.back()">
</p>
</body>
</html>
<%
Rs.Close
Set Rs = Nothing
%>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -