1
using System;
2
using System.Web;
3
using System.Web.UI;
4
using System.Text;
5
using System.IO;
6
using System.Net;
7
using System.Collections.Generic;
8
using System.Configuration;
9
using System.Xml;
10
11
/// <summary>
12
/// Cs里JAVASCRIPT控制
13
/// </summary>
14
/// Author: 姜辉
15
/// History:
16
/// 2007-02-08 姜辉 [创建]
17
18
19
public class Utility : Page
20
{
21
/// <summary>
22
/// 弹出提示
23
/// </summary>
24
/// <param name="message"></param>
25
protected void MsgBox(string message)
26
{
27
// Get a ClientScriptManager reference from the Page class.
28
ClientScriptManager cs = this.Page.ClientScript;
29
30
// Define the name and type of the client scripts on the page.
31
String csname = "PopupScript";
32
Type cstype = this.GetType();
33
34
// Check to see if the startup script is already registered.
35
if (!cs.IsStartupScriptRegistered(cstype, csname))
36
{
37
String cstext = "alert('" + Server.HtmlEncode(message) + "');";
38
cs.RegisterStartupScript(cstype, csname, cstext, true);
39
}
40
}
41
/// <summary>
42
/// 弹出提示并转向url
43
/// </summary>
44
/// <param name="message"></param>
45
/// <param name="url"></param>
46
protected void MsgBox(string message, string url)
47
{
48
// Get a ClientScriptManager reference from the Page class.
49
ClientScriptManager cs = Page.ClientScript;
50
51
// Define the name and type of the client scripts on the page.
52
String csname = "PopupScript";
53
Type cstype = this.GetType();
54
55
// Check to see if the startup script is already registered.
56
if (!cs.IsStartupScriptRegistered(cstype, csname))
57
{
58
String cstext = "alert('" + Server.HtmlEncode(message) + "');window.location='" + url + "';";
59
cs.RegisterStartupScript(cstype, csname, cstext, true);
60
}
61
}
62
/// <summary>
63
/// 最大化打开窗口
64
/// </summary>
65
/// <param name="pageName"></param>
66
protected void COpenMax(string pageName)
67
{
68
//Get a ClientScriptManager reference from the Page class
69
ClientScriptManager cs = Page.ClientScript;
70
71
//Define the name and type of the client scripts on the page
72
String csname = "open";
73
Type cstype = this.GetType();
74
75
//builder the script text
76
StringBuilder cstext = new StringBuilder();
77
cstext.Append("<script language='javascript'>");
78
cstext.Append("{window.open('" + pageName + "','aa','width='+screen.width+' height='+screen.height+' top=0 left=0 toolbar=no menubar=no resizable=yes status=yes');}");
79
cstext.Append("</script>");
80
81
// Check to see if the startup script is already registered.
82
if (!cs.IsStartupScriptRegistered(cstype, csname))
83
{
84
cs.RegisterStartupScript(cstype, csname, cstext.ToString());
85
}
86
}
87
/// <summary>
88
/// 全屏窗口
89
/// </summary>
90
/// <param name="pageName"></param>
91
protected void COpenFullScreen(string pageName)
92
{
93
//Get a ClientScriptManager reference from the Page class
94
ClientScriptManager cs = Page.ClientScript;
95
96
//Define the name and Type of the client scripts on the page
97
String csname = "open";
98
Type cstype = this.GetType();
99
100
//builder the script text
101
StringBuilder cstext = new StringBuilder();
102
cstext.Append("<script language='javascript'>");
103
cstext.Append("{window.open('" + pageName + "','aa','fullscreen');}");
104
cstext.Append("</script>");
105
// Check to see if the startup script is already registered
106
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
107
{
108
cs.RegisterStartupScript(cstype, csname, cstext.ToString());
109
}
110
}
111
/// <summary>
112
/// 打开最大化模式窗口
113
/// </summary>
114
/// <param name="pageName"></param>
115
protected void COpenModalDialog(string pageName)
116
{
117
//Get a ClientScriptManager reference from the Page class
118
ClientScriptManager cs = Page.ClientScript;
119
120
//Define the name and Type of the client script on the page
121
String csname = "showModalDialog";
122
Type cstype = this.GetType();
123
124
//builder the script text
125
StringBuilder cstext = new StringBuilder();
126
cstext.Append("<script language='javascript'>");
127
cstext.Append("{showModalDialog('" + pageName + "','aa','dialogWidth:'+screen.width+'; dialogHeight:'+screen.height+'; dialogTop:0; dialogLeft:0; center:yes; help:no; resizable:yes; status=yes');}");
128
cstext.Append("</script>");
129
130
//Check to see if the startup script is already registered
131
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
132
{
133
cs.RegisterStartupScript(cstype, csname, cstext.ToString());
134
}
135
}
136
/// <summary>
137
/// 打开规定大小的模式窗口
138
/// </summary>
139
/// <param name="MyPage"></param>
140
/// <param name="pageName"></param>
141
/// <param name="width"></param>
142
/// <param name="height"></param>
143
protected void COpenModalDialogSelf(string pageName, int width, int height)
144
{
145
//Get a ClientScriptManager reference from the Page class
146
ClientScriptManager cs = Page.ClientScript;
147
148
//Define the name and Type of the client script on the page
149
String csname = "showModalDialog";
150
Type cstype = GetType();
151
152
//builder the script
153
StringBuilder cstext = new StringBuilder();
154
cstext.Append("<script language='javascript'>");
155
cstext.Append("{showModalDialog('" + pageName + "','aa','dialogWidth:'" + width.ToString() + "'; dialogHeight:'" + height.ToString() + "'; dialogTop:0; dialogLeft:0; center:yes; help:no; resizable:yes; status=yes');}");
156
cstext.Append("</script>");
157
158
//Check to see if the startup script is already registered
159
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
160
{
161
cs.RegisterStartupScript(cstype, csname, cstext.ToString());
162
}
163
}
164
/// <summary>
165
/// 关闭窗口
166
/// </summary>
167
protected void CClose()
168
{
169
//Get a ClientScriptManager reference from the Page class
170
ClientScriptManager cs = Page.ClientScript;
171
172
//Define the name and Type of the client script on the page
173
String csname = "close";
174
Type cstype = GetType();
175
176
// builder the script text
177
StringBuilder cstext = new StringBuilder();
178
cstext.Append("<script language='javascript'>");
179
cstext.Append("{window.opener='anyone';window.close();}");
180
cstext.Append("</script>");
181
182
//Check to see if the startup script is already registered
183
if (!cs.IsClientScriptBlockRegistered(cstype, csname))
184
{
185
cs.RegisterStartupScript(cstype, csname, cstext.ToString());
186
}
187
188
}
189
/// <summary>
190
/// 下载文件
191
/// </summary>
192
/// <param name="DstrFileName"></param>
193
/// <param name="YstrUrl"></param>
194
/// <returns></returns>
195
protected bool DownLoadFile(string DstrFileName, string YstrUrl)
196
{
197
//打开上次下载的文件或新建文件
198
long lStartPos = 0;
199
System.IO.FileStream fs;
200
if (System.IO.File.Exists(DstrFileName))
201
{
202
fs = System.IO.File.OpenWrite(DstrFileName);
203
lStartPos = fs.Length;
204
fs.Seek(lStartPos, System.IO.SeekOrigin.Current); //移动文件流中的当前指针
205
}
206
else
207
{
208
fs = new System.IO.FileStream(DstrFileName, System.IO.FileMode.Create);
209
lStartPos = 0;
210
}
211
//打开网络连接
212
try
213
{
214
System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(YstrUrl);
215
if (lStartPos > 0)
216
request.AddRange((int)lStartPos); //设置Range值
217
//向服务器请求,获得服务器回应数据流
218
System.IO.Stream ns = request.GetResponse().GetResponseStream();
219
byte[] nbytes = new byte[512];
220
int nReadSize = 0;
221
nReadSize = ns.Read(nbytes, 0, 512);
222
while (nReadSize > 0)
223
{
224
fs.Write(nbytes, 0, nReadSize);
225
nReadSize = ns.Read(nbytes, 0, 512);
226
}
227
fs.Close();
228
ns.Close();
229
//("下载完成");
230
return true;
231
}
232
catch
233
{
234
fs.Close();
235
return false;
236
}
237
}
238
}

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

233

234

235

236

237

238
