⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 count.asp

📁 Lirong网络办公系统
💻 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) & "&nbsp;</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 & "&nbsp;</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) & "&nbsp;</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("&nbsp;")
			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 & "&nbsp;</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) & "&nbsp;</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 + -