-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDialogWindowSettingProgram.xaml.cs
200 lines (162 loc) · 8.11 KB
/
DialogWindowSettingProgram.xaml.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
191
192
193
194
195
196
197
198
199
200
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Win32;
namespace SCADA
{
/// <summary>
/// Логика взаимодействия для DialogWindowSettingProject.xaml
/// </summary>
public partial class DialogWindowSettingProgram : Window
{
GridOptionsGeneralProgramm OptionsGeneralProgramm;
GridOptionsDatabaseProgramm OptionsDatabaseProgramm;
bool OldCreateFolder;
string OldPathCreateProject;
bool OldSQLList;
bool OldSQLSecuritySSPI;
bool OldUseDatabase;
string OldSQLServerName;
string OldSQLDatabaseName;
string OldSQLPassword;
string OldSQLUserName;
public DialogWindowSettingProgram()
{
AppWPF application = ((AppWPF)Application.Current);
InitializeComponent();
OptionsGeneralProgramm = new GridOptionsGeneralProgramm();
OptionsDatabaseProgramm = new GridOptionsDatabaseProgramm();
OldCreateFolder = application.ConfigProgramBin.CreateFolder;
OldPathCreateProject = application.ConfigProgramBin.PathBrowseProject;
OldSQLSecuritySSPI = application.ConfigProgramBin.SQLSecuritySSPI;
OldUseDatabase = application.ConfigProgramBin.UseDatabase;
OldSQLServerName = application.ConfigProgramBin.SQLServerName;
OldSQLDatabaseName = application.ConfigProgramBin.SQLDatabaseName;
OldSQLPassword = application.ConfigProgramBin.SQLPassword;
OldSQLUserName = application.ConfigProgramBin.SQLUserName;
}
private void TreeViewProperties_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
TreeViewItem Selected = (TreeViewItem)e.NewValue;
if ((string)Selected.Header == "Общие")
{
OptionsGeneralProgramm.SetValue(Grid.ColumnProperty, 1);
if (PropertiesGrid.Children.Contains(OptionsDatabaseProgramm))
{
PropertiesGrid.Children.Remove(OptionsDatabaseProgramm);
}
PropertiesGrid.Children.Add(OptionsGeneralProgramm);
}
else if ((string)Selected.Header == "База данных")
{
OptionsDatabaseProgramm.SetValue(Grid.ColumnProperty, 1);
if (PropertiesGrid.Children.Contains(OptionsGeneralProgramm))
{
PropertiesGrid.Children.Remove(OptionsGeneralProgramm);
}
PropertiesGrid.Children.Add(OptionsDatabaseProgramm);
}
}
void WindowLoaded(object sender, RoutedEventArgs e)
{
TreeViewItemGeneral.IsSelected = true;
e.Handled = true;
}
private void Close(object sender, RoutedEventArgs e)
{
e.Handled = true;
this.Close();
}
private void Apply(object sender, RoutedEventArgs e)
{
e.Handled = true;
AppWPF application = ((AppWPF)Application.Current);
if (OptionsDatabaseProgramm.TBDatabaseName.Text.Length > 40)
{
if (TreeViewProperties.SelectedItem != TreeViewItemDatabase)
{
TreeViewItemDatabase.IsSelected = true;
}
OptionsDatabaseProgramm.LPopupMessage.Content = "Имя базы данных не может быть длинее 40 символов.";
OptionsDatabaseProgramm.PopupMessage.PlacementTarget = OptionsDatabaseProgramm.TBDatabaseName;
OptionsDatabaseProgramm.PopupMessage.IsOpen = true;
return;
}
else if (OptionsDatabaseProgramm.TBServerName.Text.Length > 40)
{
if (TreeViewProperties.SelectedItem != TreeViewItemDatabase)
{
TreeViewItemDatabase.IsSelected = true;
}
OptionsDatabaseProgramm.LPopupMessage.Content = "Имя сервера не может быть длинее 40 символов.";
OptionsDatabaseProgramm.PopupMessage.PlacementTarget = OptionsDatabaseProgramm.TBServerName;
OptionsDatabaseProgramm.PopupMessage.IsOpen = true;
return;
}
if (!(bool)OptionsDatabaseProgramm.RBSecuritySSPI.IsChecked)
{
if (OptionsDatabaseProgramm.TBUserName.Text.Length > 40)
{
if (TreeViewProperties.SelectedItem != TreeViewItemDatabase)
{
TreeViewItemDatabase.IsSelected = true;
}
OptionsDatabaseProgramm.LPopupMessage.Content = "Имя пользователя не может быть длинее 40 символов.";
OptionsDatabaseProgramm.PopupMessage.PlacementTarget = OptionsDatabaseProgramm.TBUserName;
OptionsDatabaseProgramm.PopupMessage.IsOpen = true;
return;
}
else if (OptionsDatabaseProgramm.TBUserPassword.Text.Length > 40)
{
if (TreeViewProperties.SelectedItem != TreeViewItemDatabase)
{
TreeViewItemDatabase.IsSelected = true;
}
OptionsDatabaseProgramm.LPopupMessage.Content = "Пароль не может быть длинее 40 символов.";
OptionsDatabaseProgramm.PopupMessage.PlacementTarget = OptionsDatabaseProgramm.TBUserPassword;
OptionsDatabaseProgramm.PopupMessage.IsOpen = true;
return;
}
}
if (OldUseDatabase != (bool)OptionsDatabaseProgramm.chbUseDatabase.IsChecked)
{
application.ConfigProgramBin.UseDatabase = (bool)OptionsDatabaseProgramm.chbUseDatabase.IsChecked;
}
if (OldCreateFolder != OptionsGeneralProgramm.CheckBoxCreateFolder.IsChecked || OldPathCreateProject != OptionsGeneralProgramm.TextBoxBrowseProject.Text)
{
application.ConfigProgramBin.PathBrowseProject = OptionsGeneralProgramm.TextBoxBrowseProject.Text;
application.ConfigProgramBin.CreateFolder = (bool)OptionsGeneralProgramm.CheckBoxCreateFolder.IsChecked;
}
if (OldSQLServerName != OptionsDatabaseProgramm.TBServerName.Text || OldSQLDatabaseName != OptionsDatabaseProgramm.TBDatabaseName.Text)
{
application.ConfigProgramBin.SQLServerName = OptionsDatabaseProgramm.TBServerName.Text;
application.ConfigProgramBin.SQLDatabaseName = OptionsDatabaseProgramm.TBDatabaseName.Text;
}
if(OldSQLSecuritySSPI != OptionsDatabaseProgramm.RBSecuritySSPI.IsChecked)
{
application.ConfigProgramBin.SQLSecuritySSPI = (bool)OptionsDatabaseProgramm.RBSecuritySSPI.IsChecked;
}
if (OptionsDatabaseProgramm.RBSecuritySSPI.IsChecked == false)
{
if (OldSQLUserName != OptionsDatabaseProgramm.TBUserName.Text || OldSQLPassword != OptionsDatabaseProgramm.TBUserPassword.Text)
{
application.ConfigProgramBin.SQLUserName = OptionsDatabaseProgramm.TBUserName.Text;
application.ConfigProgramBin.SQLPassword = OptionsDatabaseProgramm.TBUserPassword.Text;
}
}
this.Close();
}
}
}