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

📄 dbhandle.asp

📁 功能齐全的oa系统
💻 ASP
字号:
<%
	Class DBhandle
		Private ObjDB
		Private IntPageCount,IntRecordCount
		Private IntCols,IntRows
		
		Public Function Init(DB)
			Set ObjDB = DB
		End Function
		
		'-------------------------------------------
		'实现列表
		'输入参数
		'PageNo		页码
		'PageSize	每页面显示数目
		'StrSQL		列表SQL语句
		'输出
		'二维数组,第一维表示列,第二维表示行
		'-------------------------------------------
		Public Function List(PageNo,PageSize,StrSQL)
			Dim Result,ObjRS
			If IsNull(PageNo) Then PageNo = ""
			If PageNO = "" Then
				PageNO = 1
			Else
				PageNO = Cint(PageNO)
			End If
			
			If IsNull(PageSize) Then PageSize = ""
			If PageSize = "" Then
				PageSize = 20
			Else
				PageSize = Cint(PageSize)
			End If
						
			Set ObjRS = Server.CreateObject("Adodb.Recordset")
			ObjRS.Open StrSQL,ObjDB,1,3
			If ObjRS.EOF Then
				IntPageCount = 0
				Result = ""
			Else
				ObjRS.AbsolutePage = PageNo
				IntRecordCount = ObjRS.RecordCount
				If PageSize > 0 Then 
					ObjRS.PageSize = PageSize
					ObjRS.AbsolutePosition = PageSize * (PageNO - 1) + 1
					IntPageCount = ObjRS.PageCount
				End If
				If PageSize < 1 Then
					Result = ObjRS.GetRows()
				Else
					Result = ObjRS.GetRows(PageSize)
				End If
				IntCols = UBound(Result,1)
				IntRows = UBound(Result,2)
			End If
			
			ObjRS.Close
			Set ObjRS = Nothing
			List = Result
		End Function
		
		Public Function GetPageCount()
			GetPageCount = IntPageCount
		End Function
		
		Public Function GetRecordCount()
			GetRecordCount = IntRecordCount
		End Function
		
		Public Function GetRows()
			GetRows = IntRows
		End Function
		
		Public Function GetCols()
			GetCols = IntCols
		End Function

		'-------------------------------------------
		'实现显示
		'输入参数
		'StrSQL		列表SQL语句
		'输出
		'字典对象,Key为字段名,Item为字段名
		'-------------------------------------------
		Public Function View(StrSQL)
			Dim ObjRS,Result,i
			Dim StrKey,StrItem
			Set ObjRS = ObjDB.Execute(StrSQL)
			Set Result = Server.CreateObject("Scripting.Dictionary")
			If Not ObjRS.EOF Then
				For i = 0 To  ObjRs.Fields.Count - 1
					StrKey = Cstr(ObjRs.Fields(i).Name)
					StrItem = ObjRS.Fields(StrKey)
					Result.Add StrKey,StrItem
				Next	
			End If
			ObjRS.Close
			Set ObjRs = Nothing
			Set View = Result
		End Function

		'-------------------------------------------
		'实现添加
		'输入参数
		'FormHead	标志要添加表单域的前缀
		'StrTable	表名
		'输出
		'新记录的ID
		'-------------------------------------------
		Public Function AddNew(FormHead,StrTable)
			Dim Result,i,ObjRS,StrSQL
			Dim StrForm
			If IsNull(FormHead) Then FormHead = ""
			StrSQL = "Select Top 1 * From " & StrTable
			Set ObjRS = Server.CreateObject("Adodb.Recordset")
			ObjRS.Open StrSQL,ObjDB,1,2
			ObjRS.AddNew
			
			For Each i In Request.Form
				If Left(i,Len(FormHead)) = FormHead Then
					StrForm = Right(i,Len(i)-Len(FormHead))
					ObjRS(StrForm) = Request.Form(i)
				End If
			Next
			ObjRS.Update
			Result = ObjRS("ID")
			ObjRS.Close
			Set ObjRS = Nothing
			AddNew = Result
		End Function
		
		'-------------------------------------------
		'实现编辑
		'输入参数
		'ID			要编辑的记录ID
		'FormHead	标志要添加表单域的前缀
		'StrTable	表名
		'-------------------------------------------
		Public Sub Edit(ID,FormHead,StrTable)
			Dim Result,i,ObjRS,StrSQL
			Dim StrForm
			If IsNull(FormHead) Then FormHead = ""
			StrSQL = "Select * From " & StrTable & " Where ID = " & ID
			Set ObjRS = Server.CreateObject("Adodb.Recordset")
			ObjRS.Open StrSQL,ObjDB,1,2
			For Each i In Request.Form
				If Left(i,Len(FormHead)) = FormHead Then
					StrForm = Right(i,Len(i)-Len(FormHead))
					ObjRS(StrForm) = Request.Form(i)
				End If
			Next
			ObjRS.Update
			ObjRS.Close
			Set ObjRS = Nothing
		End Sub

		'-------------------------------------------
		'实现批量删除
		'输入参数
		'IDs		要删除的记录ID集合
		'StrTable	表名
		'-------------------------------------------
		Public Sub Delete(IDs,StrTable)
			Dim StrSQL
			StrSQL = "Delete From " & StrTable & " Where ID In (" & IDs & ")"
			ObjDB.Execute StrSQL
		End Sub		
		
		Public Function Search(CheckHead)
			Dim i,Result
			Dim StrForm
			For Each i In Request.Form
				If Left(i,Len(CheckHead)) = CheckHead Then
					StrForm = Right(i,Len(i)-Len(CheckHead))
					If Request.Form(i)<>"" Then
						If Request.Form(StrForm).Count = 2 Then
							Result = Result & " And " & StrForm & " Between '" & Request.Form(StrForm)(1) & "' And  '" & Request.Form(StrForm)(2) & "'" 
						Else
							Result = Result & " And " & StrForm & " Like '%" & Request.Form(StrForm) & "%'"
						End If
					End If
				End If
			Next
			
			Search = Result
		End Function
	End Class
	
%>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -