This repository has been archived by the owner on Dec 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
EditConnection.ascx.cs
159 lines (123 loc) · 3.1 KB
/
EditConnection.ascx.cs
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
using System;
using DotNetNuke.Entities.Modules;
namespace DNNStuff.SQLViewPro
{
public partial class EditConnection : PortalModuleBase
{
//standard
#region Web Form Designer Generated Code
//This call is required by the Web Form Designer.
[System.Diagnostics.DebuggerStepThrough()]private void InitializeComponent()
{
}
private void Page_Init(Object sender, EventArgs e)
{
//CODEGEN: This method call is required by the Web Form Designer
//Do not modify it using the code editor.
InitializeComponent();
// initialize
if (Request.QueryString["ConnectionId"] != null)
{
ConnectionId = int.Parse(Request.QueryString["ConnectionId"].ToString());
}
else
{
ConnectionId = -1;
}
InitConnection();
}
#endregion
#region Page
private int _ConnectionId;
public int ConnectionId
{
get
{
return _ConnectionId;
}
set
{
_ConnectionId = value;
}
}
private ConnectionInfo _Connection;
public ConnectionInfo Connection
{
get
{
return _Connection;
}
set
{
_Connection = value;
}
}
private void Page_Load(Object sender, EventArgs e)
{
DNNUtilities.InjectCSS(Page, ResolveUrl("Resources/Support/edit.css"));
if (!Page.IsPostBack)
{
BindConnection();
}
}
#endregion
#region Data
private void InitConnection()
{
var objConnection = ConnectionController.GetConnection(ConnectionId);
// load from database
Connection = objConnection;
}
private void BindConnection()
{
if (Connection != null)
{
txtName.Text = Connection.ConnectionName;
txtConnectionString.Text = Connection.ConnectionString;
}
}
private void SaveConnection()
{
var objConnectionController = new ConnectionController();
ConnectionId = objConnectionController.UpdateConnection(PortalId, ConnectionId, txtName.Text, txtConnectionString.Text);
}
#endregion
#region Navigation
protected void cmdUpdate_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
SaveConnection();
// Redirect back to the Connection set
Response.Redirect(NavigateConnections());
}
}
protected void cmdCancel_Click(object sender, EventArgs e)
{
Response.Redirect(NavigateConnections());
}
private string NavigateConnections()
{
return EditUrl("EditConnections");
}
#endregion
protected void vldConnectionStringValid_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
try
{
Services.Data.Query.TestConnection(args.Value);
args.IsValid = true;
}
catch (System.Security.SecurityException ex)
{
vldConnectionStringValid.ErrorMessage = "Insufficient trust level to create OLEDB connections. You must configure DNN to use a lower trust level or add OLEDBPermission to the current trust level<br />" + "Connection string error: " + ex.Message;
args.IsValid = false;
}
catch (Exception ex)
{
vldConnectionStringValid.ErrorMessage = "Connection string error: " + ex.Message;
args.IsValid = false;
}
}
}
}