-
Notifications
You must be signed in to change notification settings - Fork 0
/
DestinationConn.cs
190 lines (156 loc) · 6.21 KB
/
DestinationConn.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
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
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.Data.Sql;
using Monitor.Helpers;
using Monitor.Classes;
using DevExpress.XtraGrid.Views.Grid;
namespace Monitor
{
public partial class DestinationConn : DevExpress.XtraEditors.XtraForm
{
#region Fields
private DataTable tblServer = null;
ServerSource serverSource = null;
Destination dest = null;
#endregion
#region Ctor
public DestinationConn()
{
InitializeComponent();
}
public DestinationConn(ref ServerSource serverSource)
{
InitializeComponent();
this.serverSource = serverSource;
}
#endregion
#region Form Events
private void DestinationConn_Load(object sender, EventArgs e)
{
memConnString.Text = ConnectionHelper.GetDestConnString();
txtLogin.Text = "sa";
if (cmbServer.Properties.Items.Count == 0)
{
if (serverSource == null)
{
//tblServer = new DataTable();
//tblServer = SqlDataSourceEnumerator.Instance.GetDataSources();
//serverSource = new ServerSource();
//serverSource.List = new string[tblServer.Rows.Count];
string host = System.Net.Dns.GetHostName();
System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(host);
System.Net.IPAddress[] ipAddr = ipEntry.AddressList;
for (int i = 0; i < ipAddr.Length; i++)
{
if (ipAddr[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
cmbServer.Properties.Items.Add(ipAddr[i].ToString());
//serverSource.List[i] = tblServer.Rows[i].ItemArray.First().ToString();
}
//for (int i = 0; i < tblServer.Rows.Count; i++)
//{
// cmbServer.Properties.Items.Add(tblServer.Rows[i].ItemArray.First().ToString());
// serverSource.List[i] = tblServer.Rows[i].ItemArray.First().ToString();
//}
}
else
{
for (int i = 0; i < serverSource.List.Count(); i++)
{
cmbServer.Properties.Items.Add(serverSource.List[i].ToString());
}
}
}
Helpers.Reader.GridDataSet(ref gridDestination, "select * from MonitorDest", CommandType.Text, true);
}
#endregion
#region UI Events
private void txtServer_TextChanged(object sender, EventArgs e)
{
for (int i = 0; i < ((GridView)gridDestination.MainView).RowCount; i++)
{
DataRowView selRow = (DataRowView)(((GridView)gridDestination.MainView).GetRow(i));
if (selRow["ip_name"].ToString() == txtServer.Text)
{
txtLogin.Text = selRow["userid"].ToString();
txtPassword.Text = selRow["password"].ToString();
return;
}
}
}
#endregion
#region Button Events
private void btnBuildConnString_Click(object sender, EventArgs e)
{
if (txtServer.Text == String.Empty || cmbDatabase.SelectedItem == null)
{
MessageErrorDialog error = new MessageErrorDialog("Nedostaju podaci", "Server i baza nisu odabrani.", null);
error.ShowDialog();
return;
}
memConnString.Text = "Data source=" + txtServer.Text + ";Initial Catalog=" + cmbDatabase.SelectedItem.ToString() + ";User ID=" + txtLogin.Text + ";Password=" + txtPassword.Text;
}
private void btnTest_Click(object sender, EventArgs e)
{
lblInfo.Text = Reader.TestConnection(memConnString.Text);
lblInfo.Visible = true;
}
private void btnSpremi_Click(object sender, EventArgs e)
{
try
{
ConnectionHelper.SetDestConnString(memConnString.Text);
lblInfo.Text = "ConnString za destinaciju je pohranjen.";
lblInfo.Visible = true;
dest = new Destination();
dest.IP = txtServer.Text;
dest.UserId = txtLogin.Text;
dest.Password = txtPassword.Text;
dest.Save(dest);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void btnOdustani_Click(object sender, EventArgs e)
{
this.Close();
}
#endregion
private void btnServer_Click(object sender, EventArgs e)
{
cmbDatabase.Properties.Items.Clear();
bool state = false;
try
{
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping();
if (ping.Send(txtServer.Text).Status == System.Net.NetworkInformation.IPStatus.Success)
state = true;
}
catch (Exception ex)
{
MessageErrorDialog error = new MessageErrorDialog("Destinacija!?", "Ping destinacije nije uspio! Provjerite IP.", ex.ToString());
error.ShowDialog();
}
if (state)
{
//Helpers.Reader.GetDatabases(ref cmbDatabase, cmbServer, txtLogin.Text, txtPassword.Text);
Helpers.Reader.GetDestDatabases(ref cmbDatabase, txtServer.Text, txtLogin.Text, txtPassword.Text);
btnServer.Text = "VPN ok!";
btnServer.Appearance.BackColor = Color.DarkSeaGreen;
}
else
{
btnServer.Text = "VPN??";
btnServer.Appearance.BackColor = Color.IndianRed;
}
}
}
}