-
Notifications
You must be signed in to change notification settings - Fork 0
/
frmSelectSQLServer.cs
148 lines (122 loc) · 5.16 KB
/
frmSelectSQLServer.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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Sql;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WTUSA
{
public partial class frmSelectSQLServer : Form
{
public frmSelectSQLServer()
{
InitializeComponent();
//FormClosing += frmSelectSQLServer_FormClosing;
Load += frmSelectSQLServer_Load;
}
private void frmSelectSQLServer_Load(System.Object sender, System.EventArgs e)
{
cboxServers.Visible = false;
btnTestConnection.Enabled = false;
WriteStatus(@"Click ""Get SQL Servers"" to fetch a list of servers from the network." + Environment.NewLine
+ @"Click ""Add server manually"" to manually add a hostname & instance to the list." + Environment.NewLine);
//If WTConnection_CommandFactory.isOpen() Then
// WriteStatus(vbCrLf & "Connection information found." & vbCrLf & _
// "Click Test Connection to test the connection to:" & vbCrLf & _
// WTConnection_CommandFactory.Connection.DataSource.ToString & vbCrLf)
// btnTestConnection.Enabled = True
//End If
}
private void btnGetRefresh_Click(System.Object sender, System.EventArgs e)
{
btnGetRefresh.Enabled = false;
btnGetRefresh.Text = "Working...";
WriteStatus("Fetching SQL Servers from network...");
System.Threading.Thread.Sleep(200);
SqlDataSourceEnumerator instance = SqlDataSourceEnumerator.Instance;
foreach (DataRow row in instance.GetDataSources().Rows)
{
cboxServers.Items.Add(row[0].ToString() + "\\" + row[1].ToString());
WriteStatus(row[0].ToString() + "\\" + row[1].ToString());
}
if (cboxServers.Items.Count > 0)
{
WriteStatus(Environment.NewLine + "Found SQL Servers on the network." + Environment.NewLine + "Please select a server from the dropdown menu." + Environment.NewLine + "Click Refresh SQL Servers to fetch the list from the network again.");
btnGetRefresh.Text = "Refresh SQL Servers";
btnGetRefresh.Enabled = true;
cboxServers.Visible = true;
}
}
private void btnTestConnection_Click(System.Object sender, System.EventArgs e)
{
//close form and check connection back in WTConnection
this.Close();
}
private void WriteStatus(string str)
{
txtStatus.AppendText(str + Environment.NewLine);
}
//private void RunConnectionTests()
//{
// dynamic cString = new System.Data.SqlClient.SqlConnectionStringBuilder();
// cString.DataSource = cboxServers.SelectedItem.ToString();
// cString.IntegratedSecurity = true;
// cString.InitialCatalog = "WTData";
// cString.AsynchronousProcessing = true;
// var wtreg = new WTRegistry();
// wtreg.WriteBytesToRegistry(cString);
// if (radioSQLLogin.Checked)
// {
// ///get the sql credentials
// }
// else
// {
// }
// //WriteStatus(Environment.NewLine + "========================" + Environment.NewLine + "Testing current configuration...");
// //WTConnection.SetConnection(cString);
//}
//private void frmSelectSQLServer_FormClosing(System.Object sender, System.Windows.Forms.FormClosingEventArgs e)
//{
// //if ( IsConnectionActive == true)
// //{
// // MessageBox.Show(this, "Cannot close the form until " + "the pending asynchronous command has completed. Please wait...");
// // e.Cancel = true;
// //}
//}
private void radioSQLLogin_CheckedChanged(object sender, EventArgs e)
{
if (cboxServers.SelectedItem != null)
{
btnTestConnection.Enabled = true;
}
}
private void radioWinLogin_CheckedChanged(object sender, EventArgs e)
{
if (cboxServers.SelectedItem != null)
{
btnTestConnection.Enabled = true;
}
}
private void cboxServers_SelectedIndexChanged_1(object sender, EventArgs e)
{
if ((radioSQLLogin.Checked == true) || (radioWinLogin.Checked == true))
{
btnTestConnection.Enabled = true;
}
}
private void btnAddServer_Click(object sender, EventArgs e)
{
frmServerInputDialog input = new frmServerInputDialog();
input.ShowDialog(this);
if (!string.IsNullOrEmpty(input.txtResponse.Text))
{
cboxServers.Visible = true;
cboxServers.Items.Add(input.txtResponse.Text);
cboxServers.SelectedItem = input.txtResponse.Text;
}
}
}
}