@@ -23,7 +23,7 @@ public partial class CreateServerForm : System.Windows.Forms.Form
23
23
public string UserValue => UserInput . Text ;
24
24
private Label KeyLabel ;
25
25
private ComboBox KeyInput ;
26
- public string KeyValue
26
+ public string ? KeyValue
27
27
{
28
28
get
29
29
{
@@ -120,12 +120,15 @@ public CreateServerForm()
120
120
foreach ( var item in items )
121
121
{
122
122
KeyObject key = item . Value as KeyObject ;
123
- KeyInput . Items . Add ( new KeyValuePair < string , string > ( key . Filename , key . Filename ) ) ;
123
+ if ( key != null && key . Filename != null )
124
+ {
125
+ KeyInput . Items . Add ( new KeyValuePair < string , string > ( key . Filename , key . Filename ) ) ;
126
+ }
124
127
}
125
128
KeyInput . SelectedIndex = 0 ;
126
129
KeyInput . GotFocus += ( sender , e ) =>
127
130
{
128
- ComboBox comboBox = sender as ComboBox ;
131
+ ComboBox ? comboBox = sender as ComboBox ;
129
132
if ( comboBox != null )
130
133
{
131
134
comboBox . DroppedDown = true ;
@@ -141,7 +144,7 @@ public CreateServerForm()
141
144
CreateButton . AutoSizeMode = AutoSizeMode . GrowAndShrink ;
142
145
CreateButton . Location = new Point ( 10 , KeyInput . Bottom + 10 ) ;
143
146
CreateButton . UseVisualStyleBackColor = true ;
144
- CreateButton . Click += new EventHandler ( OnCreateButtonClick ) ;
147
+ CreateButton . Click += OnCreateButtonClick ;
145
148
Controls . Add ( CreateButton ) ;
146
149
147
150
// Layout
@@ -157,7 +160,7 @@ public CreateServerForm()
157
160
ClientSize = new Size ( ClientSize . Width , FormHeight + 20 ) ;
158
161
}
159
162
160
- protected void OnCreateButtonClick ( object sender , EventArgs e )
163
+ protected void OnCreateButtonClick ( object ? sender , EventArgs e )
161
164
{
162
165
163
166
string hostValue = HostValue . Trim ( ) ;
@@ -181,12 +184,12 @@ protected void OnCreateButtonClick(object sender, EventArgs e)
181
184
return ;
182
185
}
183
186
184
- string keyValue = KeyValue . Trim ( ) ;
187
+ string keyValue = ( KeyValue != null ) ? KeyValue . Trim ( ) : "" ;
185
188
if ( string . IsNullOrWhiteSpace ( keyValue ) )
186
189
{
187
190
MessageBox . Show ( "Пожалуйста Выберите ключ" , "Ошибка ввода" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
188
191
return ;
189
- }
192
+ }
190
193
191
194
if ( keyValue == "rwt_generete" )
192
195
{
@@ -202,7 +205,16 @@ protected void OnCreateButtonClick(object sender, EventArgs e)
202
205
key = new KeyObject ( newKeyName ) ;
203
206
}
204
207
205
- keyValue = key . Filename ;
208
+ if ( key . Filename != null )
209
+ {
210
+ keyValue = key . Filename ;
211
+ }
212
+ }
213
+
214
+ if ( keyValue == null )
215
+ {
216
+ MessageBox . Show ( "Пожалуйста Выберите ключ" , "Ошибка ввода" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
217
+ return ;
206
218
}
207
219
208
220
if ( ServersManager . CreateServer ( hostValue , hostnameValue , userValue , keyValue ) )
0 commit comments