-
-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathConditionalTablesExport.aspx.cs
More file actions
133 lines (112 loc) · 4.17 KB
/
Copy pathConditionalTablesExport.aspx.cs
File metadata and controls
133 lines (112 loc) · 4.17 KB
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
using MySqlConnector;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace System.pages
{
public partial class ConditionalTablesExport : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LoadData();
}
}
void LoadData()
{
try
{
string dbName = "";
MySqlDatabase d = new MySqlDatabase();
using (MySqlConnection conn = config.GetNewConnection())
{
using (var cmd = conn.CreateCommand())
{
conn.Open();
dbName = QueryExpress.ExecuteScalarStr(cmd, "select database();");
if (!string.IsNullOrEmpty(dbName))
{
d.GetDatabaseInfo(cmd, GetTotalRowsMethod.Skip);
}
}
}
if (string.IsNullOrEmpty(dbName))
{
((masterPage1)this.Master).WriteTopMessageBar("No database defined.", false);
((masterPage1)this.Master).ShowMessage("Error", "No database selected", false);
return;
}
StringBuilder sb = new StringBuilder();
sb.Append($@"
<table>
<thead>
<tr>
<th style='text-align: left;'>Table Name</th>
<th>Export Rows<br />
<input type='checkbox' onchange='toggleSelectAll(this);' checked />
</th>
<th>Condition Select Statement</th>
</tr>
</thead>
<tbody id='maintb_body'>
");
foreach (var table in d.Tables)
{
string encodedTableName = Server.HtmlEncode(table.Name);
string txtSqlId = $"txtSql_{encodedTableName}";
sb.Append($@"
<tr>
<td>{table.Name}</td>
<td style='text-align: center;'><input type='checkbox' name='cbExportTable_{encodedTableName}' onchange=""enableTable(this, '{txtSqlId}')"" checked /></td>
<td><input id='{txtSqlId}' type='text' name='{txtSqlId}' value='select * from `{Server.HtmlEncode(QueryExpress.EscapeIdentifier(table.Name))}`'></td>
</tr>
");
}
sb.Append("</tbody></table>");
ph1.Controls.Add(new LiteralControl(sb.ToString()));
}
catch (Exception ex)
{
((masterPage1)this.Master).ShowMessage("Error", ex.Message, false);
((masterPage1)this.Master).WriteTopMessageBar("Error<br />" + ex.Message, false);
}
}
protected void btFetchTables_Click(object sender, EventArgs e)
{
LoadData();
}
protected async void btExport_Click(object sender, EventArgs e)
{
Dictionary<string, string> dicTableSelctSql = new Dictionary<string, string>();
foreach (var key in Request.Form.AllKeys)
{
if (key.StartsWith("cbExportTable_"))
{
string tableName = key.Substring(14);
string selectSql = Request.Form[$"txtSql_{tableName}"];
if (!string.IsNullOrEmpty(selectSql))
{
dicTableSelctSql[tableName] = selectSql;
}
else
{
dicTableSelctSql[tableName] = $"select * from `{QueryExpress.EscapeIdentifier(tableName)}`";
}
}
}
MySqlConnector.ExportInformations exportInfo = new ExportInformations();
exportInfo.TablesToBeExportedDic = dicTableSelctSql;
// this task async
ServiceBackup backup = new ServiceBackup();
await backup.StartAsync(exportInfo);
// redirect to this page to see the progress report, while waiting for the task to finish
Header.Controls.Add(new LiteralControl("<script>window.location = '/ReportProgress';</script>"));
}
}
}