<OBJECT id=
"DICT"
RUNAT=
"SERVER"
SCOPE=
"Application"
progid=
"Scripting.Dictionary"
></OBJECT>
<SCRIPT LANGUAGE=
"JAVASCRIPT"
RUNAT=
"SERVER"
>
function
Application_OnStart()
{
var
getConfig =
function
(config, args) {
if
(args) {
for
(
var
proto
in
args) {
config[proto] = args[proto];
}
}
return
config;
}
var
getConnection =
function
() {
return
new
ActiveXObject(
"ADODB.Connection"
);
}
var
getRecordset =
function
() {
return
new
ActiveXObject(
"ADODB.Recordset"
);
}
var
DB = {};
DB.ConnectionString =
'Provider=Sqloledb;User ID=sa;Password=sa;Initial Catalog=db;Data Source=127.0.0.1;'
;
//添加 一条记录
DB.Add =
function
(table, keyValueCol) {
var
returnID=
null
;
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
var
Rs = getRecordset();
Rs.Open(
'select * from '
+table+
' where 1=2'
, Conn, 3, 2);
Rs.AddNew();
for
(
var
key
in
keyValueCol) {
Rs.Fields.Item(key).Value = keyValueCol[key];
}
Rs.Update();
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
return
DB.Get(
"select IDENT_CURRENT('"
+table+
"') as ID"
)[
"ID"
];
}
//修改一条记录
DB.Upd =
function
(sql, keyValueCol) {
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
var
Rs = getRecordset();
Rs.Open(sql, Conn, 3, 2);
for
(
var
key
in
keyValueCol) {
Rs.Fields.Item(key).Value = keyValueCol[key];
}
Rs.Update();
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
}
//执行 无返回结果的查询
DB.Exe =
function
(sql) {
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
Conn.Execute(sql);
Conn.Close();
Conn =
null
;
}
//获得 一个查询记录
DB.Get =
function
(sql) {
var
_record =
null
;
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
var
Rs = getRecordset();
Rs.Open(sql, Conn, 1, 1);
if
(!Rs.EOF) {
_record = {};
for
(
var
i = 0; i < Rs.Fields.Count; i++) {
_record[Rs.Fields.Item(i).Name] = Rs.Fields.Item(i).Value;
}
}
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
return
_record;
}
//批量 获得/添加 数据
DB.Batch =
function
() {
var
Conn = getConnection();
var
Rs = getRecordset();
var
_Batch =
this
;
var
_table =
null
;
_Batch.Open =
function
(sql) {
Conn.Open(DB.ConnectionString);
Rs.Open(sql, Conn, 3, 2);
}
_Batch.Add =
function
(table , keyValueCol) {
Rs.AddNew();
for
(
var
key
in
keyValueCol) {
Rs.Fields.Item(key).Value = keyValueCol[key];
}
Rs.Update();
return
DB.Get(
"Select IDENT_CURRENT('"
+ table +
"') as ID"
)[
"ID"
];
}
_Batch.Get =
function
() {
var
record_arr = [];
while
(!Rs.EOF) {
var
_record = {};
for
(
var
i = 0; i < Rs.Fields.Count; i++) {
_record[Rs.Fields.Item(i).Name] = Rs.Fields.Item(i).Value;
}
record_arr.push(_record);
Rs.MoveNext();
}
return
record_arr;
}
_Batch.Close =
function
() {
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
}
}
//获得 sql 的某页的数据
DB.List =
function
() {
var
_Config;
var
_List =
this
;
_List.Page = {
PS : 20,
AP : 1,
PC : 1,
RC : 1
};
_List.Query =
function
() {
_Config =
new
getConfig({
fields :
" * "
,
table :
null
,
where :
" 1=1 "
,
sort :
" ID desc "
,
pk :
" ID "
}, arguments[0]);
_List.Page.RC = DB.Get(
"select count("
+ _Config.pk +
") as [count] from "
+
_Config.table +
" where "
+ _Config.where).count;
_List.Page.PC = Math.ceil(_List.Page.RC / _List.Page.PS);
if
(_List.Page.AP>_List.Page.PC) _List.Page.AP = _List.Page.PC;
}
_List.Get =
function
(p) {
p = isNaN(p) ? 1 : parseInt(p);
_List.Page.AP = p;
var
sql =
''
;
if
(p > 1) {
sql =
"select top "
+ _List.Page.PS +
" "
+ _Config.fields +
" from "
+ _Config.table +
" where "
+ _Config.where +
" and "
+ _Config.pk +
" not in(select top "
+ (p - 1) * _List.Page.PS +
" "
+ _Config.pk +
" from "
+ _Config.table +
" where "
+ _Config.where +
" order by "
+ _Config.sort +
") order by "
+ _Config.sort;
}
else
{
sql =
"select top "
+ _List.Page.PS +
" "
+ _Config.fields +
" from "
+ _Config.table +
" where "
+ _Config.where +
" order by "
+ _Config.sort;
}
var
return_arr =
null
;
var
Batch =
new
DB.Batch();
Batch.Open(sql);
return_arr = Batch.Get();
Batch.Close();
return
return_arr;
}
}
//sql 只读
DB.Reader =
function
() {
var
Conn = getConnection();
var
Rs = getRecordset();
var
_Reader =
this
;
_Reader.EOF =
false
;
_Reader.Open =
function
(sql) {
Conn.Open(DB.ConnectionString);
Rs.Open(sql, Conn, 1, 1);
_Reader.EOF = Rs.EOF;
}
_Reader.Read =
function
() {
if
(!Rs.EOF) {
var
_record = {};
for
(
var
i = 0; i < Rs.Fields.Count; i++) {
_record[Rs.Fields.Item(i).Name] = Rs.Fields.Item(i).Value;
}
Rs.MoveNext();
return
_record;
}
else
{
_Reader.EOF =
true
;
}
}
_Reader.Close =
function
() {
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
}
}
var
Page =
function
(p, pc, size, prefix, suffix) {
var
args = arguments;
p = args[0] || 1;
pc = args[1] || 1;
size = args[2] || 5;
prefix = args[3] ||
''
;
suffix = args[4] ||
''
;
p < 1 ? p = 1 : p;
p > pc ? p = pc : p;
size > pc ? size = pc : size;
this
.getCode =
function
(cssNormal, cssSelect) {
var
code =
""
;
if
(pc <= size) {
for
(
var
i = 1; i <= pc; i++) {
if
(i == p) {
code +=
' <span'
+ (cssSelect ?
' class="'
+ cssSelect +
'"'
:
''
) +
'>'
+ i +
'</span> '
;
}
else
{
code +=
' <a'
+ (cssNormal ?
' class="'
+ cssNormal +
'"'
:
''
) +
' href="'
+ prefix + i + suffix +
'">'
+ i +
'</a> '
;
}
}
}
else
{
var
minx = (size / 2).toFixed(0);
var
sinx = p - minx + 1;
sinx = (sinx > 1 ? sinx : 1);
//开始
einx = (pc + 1 > sinx + size ? sinx + size : pc + 1);
//结束
for
(
var
i = sinx; i < einx; i++) {
if
(i == p) {
code +=
' <span'
+ (cssSelect ?
' class="'
+ cssSelect +
'"'
:
''
) +
'>'
+ i +
'</span> '
;
}
else
{
code +=
' <a'
+ (cssNormal ?
' class="'
+ cssNormal +
'"'
:
''
) +
' href="'
+ prefix + i + suffix +
'">'
+ i +
'</a> '
;
}
}
}
return
code;
}
this
.getPrev =
function
(css) {
return
p > 1 ?
'<a'
+ (css ?
' class="'
+ css +
'"'
:
''
) +
' href="'
+ prefix + (p - 1) + suffix +
'">上一页</a>'
:
''
;
}
this
.getNext =
function
(css) {
return
p < pc ?
'<a'
+ (css ?
' class="'
+ css +
'"'
:
''
) +
' href="'
+ prefix + (p + 1) + suffix +
'">下一页</a>'
:
''
;
}
}
var
FSO =
new
ActiveXObject(
"Scripting.FileSystemObject"
);
function
Path(path) {
if
(path.indexOf(
':'
) < 0)
path = Server.MapPath(path);
return
path;
}
function
File(path) {
path = Path(path);
this
.Delete =
function
() {
File.Delete(path);
}
this
.Exists =
function
() {
return
File.Exists(path);
}
}
File.Read =
function
(path) {
path = Path(path);
var
ForReading = 1;
var
File = FSO.OpenTextFile(path, ForReading);
return
File.ReadAll();
}
File.Create =
function
(path, content) {
path = Path(path);
var
File = FSO.CreateTextFile(path,
true
);
File.Write(content);
File.Close();
}
File.Delete =
function
(path) {
path = Path(path);
if
(
this
.Exist(path)) {
FSO.DeleteFile(path);
}
}
File.Exists =
function
(path) {
path = Path(path);
return
FSO.FileExists(path);
}
function
Folder(path) {
path = Path(path);
this
.Delete =
function
() {
Folder.Delete(path);
}
this
.Exists =
function
() {
return
Folder.Exists(path);
}
}
Folder.Create =
function
(path) {
path = Path(path);
if
(!Folder.Exists(path)) {
FSO.CreateFolder(path);
}
}
Folder.Delete =
function
(path) {
path = Path(path);
if
(Folder.Exists(path)) {
FSO.DeleteFolder(path);
}
}
Folder.Exists =
function
(path) {
path = Path(path);
return
FSO.FolderExists(path);
}
Application.StaticObjects(
"DICT"
).Add(
"DB"
,DB);
Application.StaticObjects(
"DICT"
).Add(
"Page"
,Page);
Application.StaticObjects(
"DICT"
).Add(
"File"
,File);
Application.StaticObjects(
"DICT"
).Add(
"Folder"
,Folder);
}
function
Application_OnEnd()
{
}
</SCRIPT>
其实呢,我本来是封装了多个文件的,
如DB.ASP、IO.ASP、Page.ASP....
DB.ASP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
function
getConfig(config, args) {
if
(args) {
for
(
var
proto
in
args) {
config[proto] = args[proto];
}
}
return
config;
}
function
getConnection() {
return
new
ActiveXObject(
"ADODB.Connection"
);
}
function
getRecordset() {
return
new
ActiveXObject(
"ADODB.Recordset"
);
}
var
DB = {};
DB.ConnectionString =
'Provider=Sqloledb;User ID=sa;Password=sa;Initial Catalog=db;Data Source=127.0.0.1;'
;
//添加 一条记录
DB.Add =
function
(table, keyValueCol) {
var
returnID=
null
;
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
var
Rs = getRecordset();
Rs.Open(
'select * from '
+table+
' where 1=2'
, Conn, 3, 2);
Rs.AddNew();
for
(
var
key
in
keyValueCol) {
Rs.Fields.Item(key).Value = keyValueCol[key];
}
Rs.Update();
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
return
DB.Get(
"select IDENT_CURRENT('"
+table+
"') as ID"
)[
"ID"
];
}
//修改一条记录
DB.Upd =
function
(sql, keyValueCol) {
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
var
Rs = getRecordset();
Rs.Open(sql, Conn, 3, 2);
for
(
var
key
in
keyValueCol) {
Rs.Fields.Item(key).Value = keyValueCol[key];
}
Rs.Update();
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
}
//执行 无返回结果的查询
DB.Exe =
function
(sql) {
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
Conn.Execute(sql);
Conn.Close();
Conn =
null
;
}
//获得 一个查询记录
DB.Get =
function
(sql) {
var
_record =
null
;
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
var
Rs = getRecordset();
Rs.Open(sql, Conn, 1, 1);
if
(!Rs.EOF) {
_record = {};
for
(
var
i = 0; i < Rs.Fields.Count; i++) {
_record[Rs.Fields.Item(i).Name] = Rs.Fields.Item(i).Value;
}
}
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
return
_record;
}
//获得一个sql 查询的结果集
DB.GetArray =
function
(sql){
var
record_arr = [];
var
Conn = getConnection();
Conn.Open(DB.ConnectionString);
var
Rs = getRecordset();
Rs.Open(sql, Conn, 1, 1);
while
(!Rs.EOF) {
var
_record = {};
for
(
var
i = 0; i < Rs.Fields.Count; i++) {
_record[Rs.Fields.Item(i).Name] = Rs.Fields.Item(i).Value;
}
record_arr.push(_record);
Rs.MoveNext();
}
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
return
record_arr;
}
//批量 获得/添加 数据
DB.Batch =
function
() {
var
Conn = getConnection();
var
Rs = getRecordset();
var
_Batch =
this
;
_Batch.Open =
function
(sql) {
Conn.Open(DB.ConnectionString);
Rs.Open(sql, Conn, 3, 2);
}
_Batch.Add =
function
(table , keyValueCol) {
Rs.AddNew();
for
(
var
key
in
keyValueCol) {
Rs.Fields.Item(key).Value = keyValueCol[key];
}
Rs.Update();
return
DB.Get(
"Select IDENT_CURRENT('"
+ table +
"') as ID"
)[
"ID"
];
}
_Batch.Close =
function
() {
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
}
}
//获得 sql 的某页的数据
DB.List =
function
() {
var
_Config;
var
_List =
this
;
_List.Page = {
PS : 20,
AP : 1,
PC : 1,
RC : 1
};
_List.Query =
function
() {
_Config =
new
getConfig({
fields :
" * "
,
table :
null
,
where :
" 1=1 "
,
sort :
" ID desc "
,
pk :
" ID "
}, arguments[0]);
_List.Page.RC = DB.Get(
"select count("
+ _Config.pk +
") as [count] from "
+
_Config.table +
" where "
+ _Config.where).count;
_List.Page.PC = Math.ceil(_List.Page.RC / _List.Page.PS);
if
(_List.Page.AP>_List.Page.PC) _List.Page.AP = _List.Page.PC;
}
_List.Get =
function
(p) {
p = isNaN(p) ? 1 : parseInt(p);
_List.Page.AP = p;
var
sql =
''
;
if
(p > 1) {
sql =
"select top "
+ _List.Page.PS +
" "
+ _Config.fields +
" from "
+ _Config.table +
" where "
+ _Config.where +
" and "
+ _Config.pk +
" not in(select top "
+ (p - 1) * _List.Page.PS +
" "
+ _Config.pk +
" from "
+ _Config.table +
" where "
+ _Config.where +
" order by "
+ _Config.sort +
") order by "
+ _Config.sort;
}
else
{
sql =
"select top "
+ _List.Page.PS +
" "
+ _Config.fields +
" from "
+ _Config.table +
" where "
+ _Config.where +
" order by "
+ _Config.sort;
}
var
return_arr =
null
;
var
Batch =
new
DB.Batch();
Batch.Open(sql);
return_arr = Batch.Get();
Batch.Close();
return
return_arr;
}
}
//sql 只读
DB.Reader =
function
() {
var
Conn = getConnection();
var
Rs = getRecordset();
var
_Reader =
this
;
_Reader.EOF =
false
;
_Reader.Open =
function
(sql) {
Conn.Open(DB.ConnectionString);
Rs.Open(sql, Conn, 1, 1);
_Reader.EOF = Rs.EOF;
}
_Reader.Read =
function
() {
if
(!Rs.EOF) {
var
_record = {};
for
(
var
i = 0; i < Rs.Fields.Count; i++) {
_record[Rs.Fields.Item(i).Name] = Rs.Fields.Item(i).Value;
}
Rs.MoveNext();
return
_record;
}
else
{
_Reader.EOF =
true
;
}
}
_Reader.Close =
function
() {
Rs.Close();
Rs =
null
;
Conn.Close();
Conn =
null
;
}
}
|
IO.ASP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
var
FSO =
new
ActiveXObject(
"Scripting.FileSystemObject"
);
function
Path(path) {
if
(path.indexOf(
':'
) < 0)
path = Server.MapPath(path);
return
path;
}
function
File(path) {
path = Path(path);
this
.Delete =
function
() {
File.Delete(path);
}
this
.Exists =
function
() {
return
File.Exists(path);
}
}
File.Read =
function
(path) {
path = Path(path);
var
ForReading = 1;
var
File = FSO.OpenTextFile(path, ForReading);
return
File.ReadAll();
}
File.Create =
function
(path, content) {
path = Path(path);
var
File = FSO.CreateTextFile(path,
true
);
File.Write(content);
File.Close();
}
File.Delete =
function
(path) {
path = Path(path);
if
(
this
.Exist(path)) {
FSO.DeleteFile(path);
}
}
File.Exists =
function
(path) {
path = Path(path);
return
FSO.FileExists(path);
}
function
Folder(path) {
path = Path(path);
this
.Delete =
function
() {
Folder.Delete(path);
}
this
.Exists =
function
() {
return
Folder.Exists(path);
}
}
Folder.Create =
function
(path) {
path = Path(path);
if
(!Folder.Exists(path)) {
FSO.CreateFolder(path);
}
}
Folder.Delete =
function
(path) {
path = Path(path);
if
(Folder.Exists(path)) {
FSO.DeleteFolder(path);
}
}
Folder.Exists =
function
(path) {
path = Path(path);
return
FSO.FolderExists(path);
}
|
Page.ASP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
function
Page(p, pc, size, prefix, suffix) {
var
args = arguments;
p = args[0] || 1;
pc = args[1] || 1;
size = args[2] || 5;
prefix = args[3] ||
''
;
suffix = args[4] ||
''
;
p < 1 ? p = 1 : p;
p > pc ? p = pc : p;
size > pc ? size = pc : size;
this
.getCode =
function
(cssNormal, cssSelect) {
var
code =
""
;
if
(pc <= size) {
for
(
var
i = 1; i <= pc; i++) {
if
(i == p) {
code +=
' <span'
+ (cssSelect ?
' class="'
+ cssSelect +
'"'
:
''
) +
'>'
+ i +
'</span> '
;
}
else
{
code +=
' <a'
+ (cssNormal ?
' class="'
+ cssNormal +
'"'
:
''
) +
' href="'
+ prefix + i + suffix +
'">'
+ i +
'</a> '
;
}
}
}
else
{
var
minx = (size / 2).toFixed(0);
var
sinx = p - minx + 1;
sinx = (sinx > 1 ? sinx : 1);
//开始
einx = (pc + 1 > sinx + size ? sinx + size : pc + 1);
//结束
for
(
var
i = sinx; i < einx; i++) {
if
(i == p) {
code +=
' <span'
+ (cssSelect ?
' class="'
+ cssSelect +
'"'
:
''
) +
'>'
+ i +
'</span> '
;
}
else
{
code +=
' <a'
+ (cssNormal ?
' class="'
+ cssNormal +
'"'
:
''
) +
' href="'
+ prefix + i + suffix +
'">'
+ i +
'</a> '
;
}
}
}
return
code;
}
this
.getPrev =
function
(css) {
return
p > 1 ?
'<a'
+ (css ?
' class="'
+ css +
'"'
:
''
) +
' href="'
+ prefix + (p - 1) + suffix +
'">上一页</a>'
:
''
;
}
this
.getNext =
function
(css) {
return
p < pc ?
'<a'
+ (css ?
' class="'
+ css +
'"'
:
''
) +
' href="'
+ prefix + (p + 1) + suffix +
'">下一页</a>'
:
''
;
}
}
|
String.ASP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
//html 转换为 实体
String.prototype.htmlEntity =
function
() {
html =
this
.replace(/\&/g,
"&"
)
.replace(/</g,
"<"
)
.replace(/>/g,
">"
)
.replace(/
"/g, "
"
")
.replace(/'/g, "
&
#39;");
return
html;
}
//实体 转换为 html
String.prototype.entityHtml =
function
() {
entity =
this
.replace(/\&/g, "&
")
.replace(/\</g, "
<
")
.replace(/\>/g, "
>
")
.replace(/\"/g, '"
')
.replace(/\'/g, "'
");
return
entity;
}
String.prototype.Trim=
function
(){
return
this
.replace(/(^\s*)|(\s*$)/g,
""
);
}
String.prototype.toSafeSQL=
function
(){
return
this
.replace(/
'/g,"'
'")
|