ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/AnywhereTS-MSSQL/trunk/TSAdminTool/frmClientProperties.cs
Revision: 47
Committed: Thu Jul 12 14:29:34 2012 UTC (10 years, 10 months ago) by william
File size: 45903 byte(s)
Log Message:
+ fix compilation errors

File Contents

# Content
1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Text;
7 using System.Windows.Forms;
8
9 namespace AnywhereTS
10 {
11 public partial class frmClientProperties : Form
12 {
13 public frmClientProperties()
14 {
15 InitializeComponent();
16 }
17
18
19 public enum ATSClientMode //The modes that this form can be started in.
20 { EDIT_CLIENT, // Normal mode edit a client (only admins)
21 EDIT_DEFAULT, // Edit the default record, that will be used for all new clients. (only admins)
22 NEW_CLIENT, // Create a new client (only admins)
23 CONTROL_PANEL}; // User control panel (all users)
24
25
26 public enum ATSRecordState //Indicates if we are adding a new record or editing an existing.
27 {
28 ADD, // Add a new record
29 EDIT // Edit an existing record
30 }
31
32 public ATSClientMode dialogMode; // The mode the form is running in.
33 private ATSImageRuntimeConfig currentConfig;
34 private ATSRecordState recordState;
35 public string macAddress; // The mac address for the currently selected client. If used for editing the default client, the value Globals.DEFAULT_RECORD_MAC is used. Not used when this form is used for creating a new client record.
36
37 // Data variables
38 private atsDataSet datasetAllClientsAndDefault;
39 DataRow rowCurrentClient; // The row for the selected client in the table "Client".
40
41 bool changedByUser = true; // Used on some checkbox controls to determine if state was changed by user or code.
42
43
44 private void frmClientProperties_Load(object sender, EventArgs e)
45 {
46 this.Cursor = Cursors.WaitCursor;
47 changedByUser = false; // To prevent the some controls from triggering changed event.
48
49
50 tbrScreenResolution.Maximum = ATSGlobals.ScreenResolutions.GetLength(0); // The number of predefined screen resolutions.
51
52 if (IntPtr.Size == 8)
53 { // 64 bit OS, change the background color on the track bar to controls, as it becomes white on 64 bit
54 tbrIcaAudioQuality.BackColor = System.Drawing.SystemColors.Control;
55 tbrPointerSpeed.BackColor = System.Drawing.SystemColors.Control;
56 tbrScreenResolution.BackColor = System.Drawing.SystemColors.Control;
57 tbrVolume.BackColor = System.Drawing.SystemColors.Control;
58 }
59
60 switch (dialogMode)
61 { case ATSClientMode.EDIT_CLIENT:
62 this.Text = "Client Properties";
63 tabClientProperties.SelectTab("TabGeneral"); // Make the General tab start tab when editing a client.
64 recordState = ATSRecordState.EDIT;
65 break;
66 case ATSClientMode.EDIT_DEFAULT:
67 this.Text = "Default settings for not yet discovered clients";
68
69 // Disable controls for Client name & MAC address, not applicable for default settings.
70 lblClientName.Enabled = false;
71 lblMacAddress.Enabled = false;
72 lblComment.Enabled = false;
73
74 txtClientName.Enabled = false;
75 txtMacAddress.Enabled = false;
76 txtComment.Enabled = false;
77 txtComment.Text = "You cannot change default settings for this tab, since all settings here are for idividual clients, and the default settings apply to all new clients. In order to change any of the settings here, select a client in the tree and then select 'Properties'.";
78 tabClientProperties.SelectTab("TabConnection"); // Make the Connections tab start tab when editing defaults
79
80 recordState = ATSRecordState.EDIT;
81
82 break;
83 case ATSClientMode.NEW_CLIENT:
84 this.Text = "Add client";
85 recordState = ATSRecordState.ADD;
86 break;
87 case ATSClientMode.CONTROL_PANEL:
88 this.Text = "Interface settings";
89
90 // Check that AnywhereTS is configured
91 if (ATSGlobals.configured == 0)
92 { // ATS is not configured
93 // Is user Admin?
94 if (ProSupport.IsAnAdministrator())
95 { // User is admin, show config screen
96
97 frmConfigureControlPanel objCustomDialogBox = new frmConfigureControlPanel();
98 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
99 {
100 ATSGlobals.configured = 2; // Control panel mode
101 ATSGlobals.SetATSRegValue(ATSGlobals.strRegConfigured,ATSGlobals.configured);
102
103 ATSGlobals.managedMode = 1; // ManagedMode
104 ATSGlobals.SetATSRegValue(ATSGlobals.strRegManagedMode, ATSGlobals.managedMode);
105
106 ATSGlobals.tftpConfig = 1; // This computer is not an AnywhereTS TFTP server.
107 ATSGlobals.SetATSRegValue(ATSGlobals.strRegTFTPconfig,ATSGlobals.tftpConfig);
108
109 }
110 objCustomDialogBox = null;
111
112 }
113 else
114 { // User is not admin
115 this.Cursor = Cursors.Default;
116 MessageBox.Show("The AnywhereTS control panel is not yet configured. Before you can use it, it needs to be configured by an administrator.");
117 Application.Exit();
118 return;
119 }
120 }
121
122 // Check if we are trying to run the control panel in unmanged mode
123 if (ATSGlobals.managedMode != 1)
124 {
125 MessageBox.Show("AnywhereTS is not running in managed mode. In order to run this application, an administrator must first run AnywhereTS Admin and configure AnywhereTS to run in Managed Mode");
126 Application.Exit();
127 }
128
129 // If we are running as control panel, we first need to set up the database, as this is
130 // not being done anywhere else.
131 ProSupport.InitDatabase();
132
133 recordState = ATSRecordState.EDIT;
134 tabClientProperties.TabPages.Remove(tabClientProperties.TabPages["tabGeneral"]);
135 tabClientProperties.TabPages.Remove(tabClientProperties.TabPages["tabICA"]);
136 tabClientProperties.TabPages.Remove(tabClientProperties.TabPages["tabRDP"]);
137 tabClientProperties.TabPages.Remove(tabClientProperties.TabPages["tabMisc"]);
138
139 // Swap the Interface and connection tab, so that interface will be the first tab displayed on the control panel.
140 TabPage tabTemp;
141 tabTemp = tabClientProperties.TabPages["TabInterface"];
142 tabClientProperties.TabPages.Remove(tabInterface);
143 tabClientProperties.TabPages.Insert(0, tabTemp);
144 tabClientProperties.SelectTab("TabInterface");
145
146 // Disable most controls on the connection tab, ordinary users should only be able to set user name
147 lblServer.Enabled = false;
148 txtServer.Enabled = false;
149 cboConnection.Enabled = false;
150
151 chkReconnect.Enabled = false;
152
153 chkRedirectSound.Visible = false; // Users cannot enable/disable audio.
154 break;
155 } // switch dialog mode
156 currentConfig = new ATSImageRuntimeConfig();
157
158 // Set up database
159 datasetAllClientsAndDefault = new atsDataSet();
160
161 // Update dataset
162 try
163 {
164 ProSupport.clientTableAdapter.Fill(datasetAllClientsAndDefault.Client);
165 }
166 catch (Exception ex)
167 {
168 MessageBox.Show("Could not open datbase (77886). Error: " + ex.Message, "AnywhereTS");
169 Application.Exit();
170 return;
171 }
172
173 // If this dialog is run in edit default client, the mac address
174 // should be set to the default record
175 if (dialogMode == ATSClientMode.EDIT_DEFAULT)
176 {
177 macAddress = ProSupport.DEFAULT_RECORD_MAC;
178 }
179
180 // If this dialog is run in control panel mode, the mac address
181 // should be set to the one belonging to the current session
182 if (dialogMode == ATSClientMode.CONTROL_PANEL)
183 {
184 string myName = TSManager.GetMyName();
185
186 // If the session does not have a client name. Most likely, the user is running in console mode.
187 if (myName.Length > 0)
188 { // Session has name
189 // Try to extract MAC address from client name.
190 macAddress = ATSGlobals.GetMacFromATSname(myName);
191 if (macAddress.Length == 0)
192 { // MAC not in name, try to lookup client name in database
193 atsDataSet datasetClientName = new atsDataSet();
194 // Update dataset
195 try
196 {
197 ProSupport.clientTableAdapter.FillOnName(datasetClientName.Client, myName);
198 }
199 catch (Exception ex)
200 {
201 MessageBox.Show("Could not open datbase (77887). Error: " + ex.Message, "AnywhereTS");
202 Application.Exit();
203 return;
204 }
205 if (datasetClientName.Client.Rows.Count > 0)
206 { // The client has a record in the database, get MAC address from database.
207 macAddress = datasetClientName.Client.Rows[0]["MacAddress"].ToString();
208 }
209 else
210 { // Name not found, client does not have a record in database.
211 macAddress = "";
212 }
213 } // Mac address is not in name
214 else
215 { // Mac address is in client name
216
217 }
218 }
219 else
220 { // The session does not have a client name. Most likely, the user is running in console mode.
221 macAddress = "";
222 }
223
224 if (macAddress == "")
225 {
226 this.Cursor = Cursors.Default;
227 MessageBox.Show("Your computer cannot be identified as an AnywhereTS client. This application is used to configure settings for AnywhereTS-clients and can only be run from a client powered by AnywhereTS. If you still get this error message, please contact your system adminstrator or feedback@anywherets.com");
228 Application.Exit(); //Quit
229 return;
230 }
231
232 // Check if the client belong to the ones that are licensed.
233 atsDataSet datasetLicensedClients = new atsDataSet();
234
235 // Populate dataset
236 try
237 {
238 ProSupport.clientTableAdapter.FillClients(datasetLicensedClients.Client);
239 }
240 catch (Exception ex)
241 {
242 MessageBox.Show("Could not open datbase (77887). Error: " + ex.Message, "AnywhereTS");
243 Application.Exit();
244 return;
245 }
246 // Try to locate the client in the dataset of licensed clients.
247 DataRow rowThisClient = datasetLicensedClients.Client.Rows.Find(macAddress);
248 // Does the MAC adress not exist in database?
249 if (rowThisClient == null)
250 { // We have exceeded the license limit, terminate.
251 MessageBox.Show("The maxiumum number of licensed clients is reached. Please contact your system administrator.");
252 using (log4net.NDC.Push(string.Format("client macaddress={0}", macAddress)))
253 {
254 Logging.ATSAdminLog.Warn("The maxiumum number of licensed clients has been reached");
255 }
256 Application.Exit();
257 return;
258 }
259
260 } // if (dialogMode == ATSClientMode.CONTROL_PANEL)
261
262 // Look for the client record to edit (not when adding client)
263 if (recordState == ATSRecordState.EDIT)
264 {
265 rowCurrentClient = datasetAllClientsAndDefault.Client.Rows.Find(macAddress);
266 }
267 // Does the MAC adress not exist in database?
268 if (rowCurrentClient == null)
269 {
270 recordState = ATSRecordState.ADD;
271 }
272
273 // If in add mode, add new record
274 if (recordState == ATSRecordState.ADD)
275 {
276 // Add the client, using properties from the default record.
277 // Look up default record
278 // improve samma som i frmAdmin
279
280 rowCurrentClient = datasetAllClientsAndDefault.Client.NewRow();
281
282 ATSImageRuntimeConfig newConfig = new ATSImageRuntimeConfig();
283 newConfig.ReadDefaultFromDatabase();
284 newConfig.WriteToDatabase(rowCurrentClient);
285
286 if (dialogMode == ATSClientMode.CONTROL_PANEL)
287 { // We are running as control panel for a user that yet has no record
288
289 rowCurrentClient["macAddress"] = macAddress;
290 rowCurrentClient["clientName"] = "ATS" + macAddress;
291 }
292 else
293 { // We are adding a client from the Admin tool
294 rowCurrentClient["macAddress"] = "";
295 macAddress = "";
296 rowCurrentClient["clientName"] = "";
297 }
298 }
299
300 // Load controls
301 if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
302 {
303 if (dialogMode != ATSClientMode.EDIT_DEFAULT)
304 {
305 txtMacAddress.Text = macAddress; // Mac address for the selected client
306 txtClientName.Text = rowCurrentClient["ClientName"].ToString();
307 txtComment.Text = rowCurrentClient["Comment"].ToString();
308 }
309 }
310
311 // Read config from database
312 currentConfig.ReadFromDatabase(rowCurrentClient);
313
314 // Update controls from config
315 UpdateScreenResolutionControls(currentConfig.ScreenResolutionX, currentConfig.ScreenResolutionY);
316
317 switch (currentConfig.ScreenColorDepth)
318 {
319 case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit:
320 cboColorQuality.SelectedIndex = 0;
321 break;
322 case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit:
323 cboColorQuality.SelectedIndex = 1;
324 break;
325 default:
326 throw new Exception("Error: Unhandled color depth: 29901");
327 }
328 chkDigitalMonitor.Checked = currentConfig.DigitalMonitor;
329 chkRedirectSound.Checked = currentConfig.RedirectSound;
330
331 txtServer.Text = currentConfig.ServerName;
332 txtDomain.Text = currentConfig.ServerDomain;
333 txtUsername.Text = currentConfig.UserName;
334 txtPassword.Text = currentConfig.Password;
335 txtApplicationSet.Text = currentConfig.ICAApplicationSet;
336 txtCitrixServerURL.Text = currentConfig.ICAServerURL;
337 txtCitrixResource.Text = currentConfig.ICAResource;
338
339 if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSRDP)
340 {
341 cboConnection.SelectedIndex = 0;
342 }
343 else if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSICA)
344 {
345 cboConnection.SelectedIndex = 1;
346 }
347 else if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSPNA)
348 {
349 cboConnection.SelectedIndex = 2;
350 }
351 else
352 throw new Exception("Unhandled session type 65332");
353
354 SessionTypeChanged(); // Enable and disable rdp and ica tabs
355
356 chkReconnect.Checked = !currentConfig.ReconnectPrompt;
357
358 if (dialogMode == ATSClientMode.CONTROL_PANEL)
359 { // We are running in control panel mode. Hide password box.
360 lblPassword.Visible = false;
361 txtPassword.Visible = false;
362 }
363
364 tbrVolume.Value = currentConfig.AudioLevel;
365 tbrPointerSpeed.Value = currentConfig.MouseResolution;
366
367 // If ICA tab exists (could have been removed in the control panel)
368 if (tabClientProperties.TabPages.ContainsKey("tabIca"))
369 {
370 chkIcaCompression.Checked = currentConfig.ICACompression;
371 if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.Low)
372 tbrIcaAudioQuality.Value = 1;
373 else if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.Medium)
374 tbrIcaAudioQuality.Value = 2;
375 else if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.High)
376 tbrIcaAudioQuality.Value = 3;
377 else
378 throw new Exception("Error: Unhandled audio quality (66432)");
379
380 if (currentConfig.ICAProtocol == ATSImageRuntimeConfig.ATSIcaProtocol.ATSUDP)
381 radIcaProtocolUDP.Checked = true;
382 else if (currentConfig.ICAProtocol == ATSImageRuntimeConfig.ATSIcaProtocol.ATSHTTPOnTCP)
383 radIcaProtocolHTTP.Checked = true;
384 else
385 throw new Exception("Error: Unhandlced ICA protocol (60032)");
386
387 int i = cboIcaEncryption.FindStringExact(currentConfig.ICAEncryption);
388 if (i != -1) // Check if the item was found in the combobox.
389 {
390 cboIcaEncryption.SelectedIndex = i;
391 }
392 else
393 throw new Exception("Error: Unhandlced ICA encryption(60033)");
394
395 }
396
397 // If RDP tab exists (could have been removed in the control panel)
398 if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
399 {
400 // Update RDP controls
401 chkRedirectFloppy.Checked = currentConfig.RedirectFloppy;
402 chkRedirectCD.Checked = currentConfig.RedirectCD;
403 chkMiscCOM1.Checked = currentConfig.MiscRedirectCom1;
404 chkMiscCOM2.Checked = currentConfig.MiscRedirectCom2;
405 chkUsbMemory.Checked = currentConfig.UsbDrive == ATSImageRuntimeConfig.ATSUsbDrive.One;
406 lblServerPort.Font = new Font(lblServerPort.Font, FontStyle.Regular);
407
408
409 // Initialise server port
410 if (currentConfig.ServerPort == -1)
411 {
412 txtServerPort.Text = "";
413 }
414 else
415 {
416 txtServerPort.Text = currentConfig.ServerPort.ToString();
417 }
418 }
419
420 // If Misc tab exists (could have been removed in the control panel)
421 if (tabClientProperties.TabPages.ContainsKey("tabMisc"))
422 {
423
424 chkMiscNumLock.Font = new Font(chkMiscNumLock.Font, FontStyle.Regular);
425
426 // Initate controls from current configuration
427 chkMiscDailyreboot.Checked = currentConfig.DailyReboot;
428 chkMiscMousefix.Checked = currentConfig.MiscMousefix;
429 chkMiscFlippedFix.Checked = currentConfig.MiscFlippedFix;
430 chkMiscNoaccel.Checked = currentConfig.MiscNoAcceleration;
431 chkMiscNumLock.Checked = currentConfig.NumLock; // Note that state of ChangedByUser affects this control.
432
433 // Initiate keyboard combo
434 cboKeyboard.Items.AddRange(ATSKeyboard.keyboardDescription); // Load keyboard descriptions
435 cboKeyboard.SelectedIndex = ATSKeyboard.KeyboardCodeToIndex(currentConfig.KeyboardMap);
436
437 // Initiate timezone combo
438 cboTimezone.Items.AddRange(ATSTimeZone.timeZoneCode); // Load timezones
439 cboTimezone.SelectedIndex = ATSTimeZone.TimeZoneCodeToIndex(currentConfig.TimeZone);
440 }
441 changedByUser = true;
442 this.Cursor = Cursors.Default;
443 }
444
445
446 // OK Pressed
447 private void btnOK_Click(object sender, EventArgs e)
448 {
449 string strValidatedMacAdress = ""; // The validated MAC address.
450 string strValidatedClientName = ""; // The validated client name.
451 string strValidatedServerName = ""; // The validated server name.
452 UriHostNameType hostname; // used to validate host name
453
454 // Validate MAC address and client name, unless in Default Parameters mode, where these two
455 // parameters do not exist.
456 if (dialogMode == ATSClientMode.EDIT_CLIENT || dialogMode == ATSClientMode.NEW_CLIENT)
457 {
458 if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
459 {
460 // Validate MAC address
461 if (txtMacAddress.Text == "")
462 {
463 tabClientProperties.SelectTab("TabGeneral");
464 MessageBox.Show("You must enter a MAC address!");
465 txtMacAddress.Focus();
466 return;
467 }
468 strValidatedMacAdress = ATSGlobals.IsValidMAC(txtMacAddress.Text);
469 if (strValidatedMacAdress == "")
470 {
471 tabClientProperties.SelectTab("TabGeneral");
472 MessageBox.Show("Invalid MAC address! Please enter a valid MAC address");
473 txtMacAddress.Focus();
474 txtMacAddress.SelectAll();
475 return;
476 }
477 // For new clients:
478 if (recordState == ATSRecordState.ADD)
479 { // Does MAC address already exist?
480 if (datasetAllClientsAndDefault.Client.Rows.Find(strValidatedMacAdress) != null)
481 {
482 tabClientProperties.SelectTab("TabGeneral");
483 MessageBox.Show("MAC address " + txtMacAddress.Text.ToUpper() + " is already in use by another client! Maybe you are trying to add the same client twice?");
484 using (log4net.NDC.Push(string.Format("macaddress={0}", strValidatedMacAdress)))
485 {
486 Logging.ATSAdminLog.Warn("Attempt to duplicate an already existing MAC Address.");
487 }
488 txtMacAddress.Focus();
489 txtMacAddress.SelectAll();
490 return;
491 }
492 }
493
494 // Validate Client name, maxlen 15 already given from text box.
495 if (txtClientName.Text == "")
496 {
497 tabClientProperties.SelectTab("TabGeneral");
498 MessageBox.Show("You must enter a name for the client!");
499 txtClientName.Focus();
500 return;
501 }
502
503 strValidatedClientName = txtClientName.Text.ToUpper();
504
505 hostname = Uri.CheckHostName(strValidatedClientName);
506 if (hostname == UriHostNameType.Unknown)
507 {
508 tabClientProperties.SelectTab("TabGeneral");
509 MessageBox.Show("Client name contains invalid characters! You must enter a valid client name.");
510 txtClientName.Focus();
511 txtClientName.SelectAll();
512 return;
513 }
514
515 // Currently possible to have the same name for two clients.
516
517 /*
518 // For new clients, client name alredy taken?
519 if (dialogMode == ATSClientMode.NEW_CLIENT)
520 {
521 if (datasetClient.Client.Rows.Find(strValidatedClientName) != null)
522 {
523 MessageBox.Show("Client name " + strValidatedClientName + " is already in use by another client!");
524 txtClientName.Focus();
525 txtClientName.SelectAll();
526 return;
527 }
528 }
529 */
530 } // Tab General
531 } // If edit client or new client (but not defuault)
532
533 // Check that server name is entered.
534 strValidatedServerName = txtServer.Text.Trim();
535 if (strValidatedServerName.Length == 0)
536 {
537 tabClientProperties.SelectTab("TabConnection");
538 MessageBox.Show("You must enter a server name!");
539 txtServer.Focus();
540 txtServer.SelectAll();
541 return;
542 }
543
544 // Validate server name, maxlen 30 already given from text box.
545 strValidatedServerName = txtServer.Text.ToUpper();
546
547 hostname = Uri.CheckHostName(strValidatedServerName);
548 if (hostname == UriHostNameType.Unknown)
549 {
550 tabClientProperties.SelectTab("TabConnection");
551 MessageBox.Show("Invalid server name!");
552 txtServer.Focus();
553 txtServer.SelectAll();
554 return;
555 }
556
557 // Validate and convert server port
558 if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
559 {
560 if (txtServerPort.Text.Trim().Length == 0)
561 { // No server port specified
562 currentConfig.ServerPort = -1;
563 }
564 else
565 { // The user has specified a server port
566 try
567 {
568 currentConfig.ServerPort = Int32.Parse(txtServerPort.Text.Trim());
569 }
570 catch (Exception ex)
571 {
572 tabClientProperties.SelectTab("tabRdp");
573 MessageBox.Show("Invalid server port!");
574 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
575 {
576 using (log4net.NDC.Push(string.Format("serverport={0}", txtServerPort.Text)))
577 {
578 Logging.ATSAdminLog.ErrorFormat("Invalid server port!");
579 }
580 }
581 txtServerPort.Focus();
582 txtServerPort.SelectAll();
583 return;
584 }
585 if (currentConfig.ServerPort < 0 || currentConfig.ServerPort > 65535)
586 { // Value to high or to low
587 tabClientProperties.SelectTab("tabRdp");
588 MessageBox.Show("Invalid server port!");
589 using (log4net.NDC.Push(string.Format("serverport={0}", txtServerPort.Text)))
590 {
591 Logging.ATSAdminLog.ErrorFormat("Invalid server port!");
592 }
593 txtServerPort.Focus();
594 txtServerPort.SelectAll();
595 return;
596 }
597 }
598 }
599
600
601 // Possible improvement: Did any parameters change?
602
603 // Possible improvement: One of more parameters changed, save parameters to database.
604
605
606 // Save properties to database
607 if(dialogMode != ATSClientMode.EDIT_DEFAULT) // If we are editing default, server name and MAC address should not be saved.
608 {
609 if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
610 {
611 rowCurrentClient["ClientName"] = strValidatedClientName;
612 macAddress = strValidatedMacAdress;
613 rowCurrentClient["MacAddress"] = macAddress;
614 rowCurrentClient["Comment"] = txtComment.Text;
615 }
616 }
617
618 // Resolution set by text boxes
619 try
620 {
621 currentConfig.ScreenResolutionX = Int32.Parse(txtScreenResX.Text.Trim());
622 }
623 catch (Exception ex)
624 {
625 tabClientProperties.SelectTab("TabInterface");
626 MessageBox.Show("Invalid screen resolution!");
627 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
628 {
629 using (log4net.NDC.Push(string.Format("ScreenResolutionX={0}", txtScreenResX.Text)))
630 {
631 Logging.ATSAdminLog.ErrorFormat("Invalid X screen resolution!");
632 }
633 }
634 txtScreenResX.Focus();
635 txtScreenResX.SelectAll();
636 return;
637 }
638 if (currentConfig.ScreenResolutionX < 100 || currentConfig.ScreenResolutionX > 9999)
639 { // Value to high or to low
640 tabClientProperties.SelectTab("TabInterface");
641 MessageBox.Show("Invalid screen resolution!");
642
643 using (log4net.NDC.Push(string.Format("ScreenResolutionX={0}", txtScreenResX.Text)))
644 {
645 Logging.ATSAdminLog.ErrorFormat("Invalid X screen resolution!");
646 }
647
648 txtScreenResX.Focus();
649 txtScreenResX.SelectAll();
650 return;
651 }
652
653 try
654 {
655 currentConfig.ScreenResolutionY = Int32.Parse(txtScreenResY.Text.Trim());
656 }
657 catch (Exception ex)
658 {
659 tabClientProperties.SelectTab("TabInterface");
660 MessageBox.Show("Invalid screen resolution!");
661 using (log4net.NDC.Push(string.Format("SqlException: MESSAGE={0}{1}Diagnostics:{1}{2}", ex.Message, System.Environment.NewLine, ex.ToString())))
662 {
663 using (log4net.NDC.Push(string.Format("ScreenResolutionY={0}", txtScreenResY.Text)))
664 {
665 Logging.ATSAdminLog.ErrorFormat("Invalid Y screen resolution!");
666 }
667 }
668 txtScreenResY.Focus();
669 txtScreenResY.SelectAll();
670 return;
671 }
672 if (currentConfig.ScreenResolutionY < 100 || currentConfig.ScreenResolutionY > 9999)
673 { // Value to high or to low
674 tabClientProperties.SelectTab("TabInterface");
675 MessageBox.Show("Invalid screen resolution!");
676 using (log4net.NDC.Push(string.Format("ScreenResolutionY={0}", txtScreenResY.Text)))
677 {
678 Logging.ATSAdminLog.ErrorFormat("Invalid Y screen resolution!");
679 }
680 txtScreenResY.Focus();
681 txtScreenResY.SelectAll();
682 return;
683 }
684
685 switch (cboColorQuality.SelectedIndex)
686 {
687 case 0:
688 currentConfig.ScreenColorDepth = ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit;
689 break;
690 case 1:
691 currentConfig.ScreenColorDepth = ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit;
692 break;
693 default:
694 throw new Exception("Error: Unhandled color depth (41255).");
695 }
696
697 currentConfig.ServerName = txtServer.Text.Trim();
698 currentConfig.ServerDomain = txtDomain.Text.Trim();
699 currentConfig.UserName = txtUsername.Text.Trim();
700 currentConfig.Password = txtPassword.Text;
701 currentConfig.ICAApplicationSet = txtApplicationSet.Text.Trim();
702 currentConfig.ICAServerURL = txtCitrixServerURL.Text.Trim();
703 currentConfig.ICAResource = txtCitrixResource.Text.Trim();
704
705 if (cboConnection.SelectedIndex == 0)
706 {
707 currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSRDP;
708 }
709 else if (cboConnection.SelectedIndex == 1)
710 {
711 currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSICA;
712 }
713 else if (cboConnection.SelectedIndex == 2)
714 {
715 currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSPNA;
716 }
717 else
718 throw new Exception("Error: Unhandled connection type(41283).");
719
720 currentConfig.ReconnectPrompt = !chkReconnect.Checked;
721 currentConfig.AudioLevel = tbrVolume.Value;
722 currentConfig.MouseResolution = tbrPointerSpeed.Value;
723 currentConfig.DigitalMonitor = chkDigitalMonitor.Checked;
724 currentConfig.RedirectSound = chkRedirectSound.Checked;
725
726 // If ICA tab exists (could have been removed in the control panel)
727 if (tabClientProperties.TabPages.ContainsKey("tabIca"))
728 {
729 currentConfig.ICACompression = chkIcaCompression.Checked;
730 currentConfig.ICAEncryption = cboIcaEncryption.Items[cboIcaEncryption.SelectedIndex].ToString();
731 if (radIcaProtocolUDP.Checked)
732 currentConfig.ICAProtocol = ATSImageRuntimeConfig.ATSIcaProtocol.ATSUDP;
733 else
734 currentConfig.ICAProtocol = ATSImageRuntimeConfig.ATSIcaProtocol.ATSHTTPOnTCP;
735
736 if (tbrIcaAudioQuality.Value == 1)
737 currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.Low;
738 else if (tbrIcaAudioQuality.Value == 2)
739 currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.Medium;
740 else
741 currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.High;
742 }
743
744 // If RDP tab exists (could have been removed in the control panel)
745 if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
746 {
747 // Save RDP options
748 currentConfig.RedirectFloppy = chkRedirectFloppy.Checked;
749 currentConfig.RedirectCD = chkRedirectCD.Checked;
750 currentConfig.MiscRedirectCom1 = chkMiscCOM1.Checked;
751 currentConfig.MiscRedirectCom2 = chkMiscCOM2.Checked;
752 if (chkUsbMemory.Checked)
753 {
754 currentConfig.UsbDrive = ATSImageRuntimeConfig.ATSUsbDrive.One;
755 }
756 else
757 {
758 currentConfig.UsbDrive = ATSImageRuntimeConfig.ATSUsbDrive.None;
759 }
760 }
761
762 // If Misc tab exists (could have been removed in the control panel)
763 if (tabClientProperties.TabPages.ContainsKey("tabMisc"))
764 {
765 // Update current configuration from controls
766 currentConfig.NumLock = chkMiscNumLock.Checked;
767 currentConfig.DailyReboot = chkMiscDailyreboot.Checked;
768 currentConfig.MiscMousefix = chkMiscMousefix.Checked;
769 currentConfig.MiscFlippedFix = chkMiscFlippedFix.Checked;
770 currentConfig.MiscNoAcceleration = chkMiscNoaccel.Checked;
771 currentConfig.TimeZone = cboTimezone.Items[cboTimezone.SelectedIndex].ToString();
772 currentConfig.KeyboardMap = ATSKeyboard.keyboardCode[cboKeyboard.SelectedIndex];
773 }
774
775 currentConfig.WriteToDatabase(rowCurrentClient); // Save config to the row
776
777 // If it is a new client, we need to add the row to the client table.
778 if (recordState == ATSRecordState.ADD)
779 {
780 datasetAllClientsAndDefault.Client.Rows.Add(rowCurrentClient);
781 }
782
783 try
784 {
785 ProSupport.clientTableAdapter.Update(datasetAllClientsAndDefault.Client);
786 }
787 catch
788 {
789 MessageBox.Show("Error, could not update database (10084). Try to redo the operation.");
790 }
791
792 if (dialogMode == ATSClientMode.EDIT_DEFAULT)
793 { // Write network config file, since the default values should be saved in the network file.
794 ProSupport.WriteConfigFiles(currentConfig, ProSupport.strNetworkConfigFilename, false);
795 }
796 else
797 {
798 // Write client config file
799 ProSupport.WriteConfigFiles(currentConfig, macAddress, true);
800 }
801
802 // If admin, try to send message to the session to restart
803
804 if (dialogMode == ATSClientMode.CONTROL_PANEL)
805 { // This form is the main and only form
806 Application.Exit();
807 }
808 else
809 { // This form is called from another form
810 DialogResult = DialogResult.OK;
811 }
812 this.Cursor = Cursors.Default;
813 }
814
815 private void btnCancel_Click(object sender, EventArgs e)
816 {
817 if (dialogMode == ATSClientMode.CONTROL_PANEL)
818 { // This form is the main and only form
819 Application.Exit();
820 }
821 else
822 { // This form is called from another form
823 DialogResult = DialogResult.Cancel;
824 }
825 }
826
827 // Display context sensitive ATS help, depending on mode (default properties or normal properties) and selected tab
828 private void ShowAtsHelp()
829 {
830 string helpKeyword = "";
831 if (dialogMode == ATSClientMode.EDIT_CLIENT || dialogMode == ATSClientMode.NEW_CLIENT)
832 { // We are running the form in edit or new mode
833 switch (tabClientProperties.SelectedTab.Name)
834 {
835 case "tabGeneral":
836 helpKeyword = "clientpropertiesgeneral.htm";
837 break;
838 case "tabConnection":
839 helpKeyword = "clientpropertiesconnection.htm";
840 break;
841 case "tabInterface":
842 helpKeyword = "clientpropertiesinterface.htm";
843 break;
844 case "tabRdp":
845 helpKeyword = "clientpropertiesrdp.htm";
846 break;
847 case "tabIca":
848 helpKeyword = "clientpropertiesica.htm";
849 break;
850 case "tabMisc":
851 helpKeyword = "clientpropertiesmisc.htm";
852 break;
853 default:
854 throw new Exception("Error: Invalid tab (63326): " + tabClientProperties.SelectedTab.Name);
855 }
856 }
857 else if (dialogMode == ATSClientMode.EDIT_DEFAULT)
858 { // We are running the form in default settings mode
859 switch (tabClientProperties.SelectedTab.Name)
860 {
861 case "tabGeneral":
862 helpKeyword = "defaultsettingsgeneral.htm";
863 break;
864 case "tabConnection":
865 helpKeyword = "defaultsettingsconnection.htm";
866 break;
867 case "tabInterface":
868 helpKeyword = "defaultsettingsinterface.htm";
869 break;
870 case "tabRdp":
871 helpKeyword = "defaultsettingsrdp.htm";
872 break;
873 case "tabIca":
874 helpKeyword = "defaultsettingsica.htm";
875 break;
876 case "tabMisc":
877 helpKeyword = "defaultsettingsmisc.htm";
878 break;
879 default:
880 throw new Exception("Error: Invalid tab (63327): " + tabClientProperties.SelectedTab.Name);
881 }
882 }
883 Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.Topic, helpKeyword);
884 }
885
886 private void frmClientProperties_KeyDown(object sender, KeyEventArgs e)
887 {
888 if (e.KeyCode == Keys.F1)
889 { // F1 pressed, show ATS help
890 ShowAtsHelp();
891 }
892 }
893
894 private void frmClientProperties_HelpRequested(object sender, HelpEventArgs hlpevent)
895 {
896 hlpevent.Handled = true;
897 }
898
899 // Changed connection type, enable rdp and ica tabs respectively
900 private void SessionTypeChanged()
901 {
902 if (cboConnection.SelectedIndex == 0)
903 { //RDP
904 pnlCitrixPN.Visible = false;
905 pnlApplicationSet.Visible = false;
906 }
907 else if (cboConnection.SelectedIndex == 1)
908 { //ICA
909 pnlCitrixPN.Visible = false;
910 pnlApplicationSet.Visible = true;
911 }
912 else if (cboConnection.SelectedIndex == 2)
913 { // PNA
914 pnlCitrixPN.Visible = true;
915 pnlApplicationSet.Visible = false;
916 }
917 else
918 throw new Exception("Unhandled session type 95333");
919 }
920
921 private void UpdateScreenResolutionControls(int x, int y)
922 {
923 txtScreenResX.Text = x.ToString();
924 txtScreenResY.Text = y.ToString();
925
926 for (int i = 0; i < ATSGlobals.ScreenResolutions.GetLength(0); i++)
927 {
928 if (x == ATSGlobals.ScreenResolutions[i, 0] && y == ATSGlobals.ScreenResolutions[i, 1])
929 {
930 tbrScreenResolution.Value = i + 1;
931 return;
932 }
933
934 }
935 // Values could not be expressed using the track bar. Set it at default.
936 tbrScreenResolution.Value = 4;
937 }
938
939 private void GetScreenResolutionFromTrackbar(TrackBar tbr, out int x, out int y)
940 {
941 x = ATSGlobals.ScreenResolutions[tbr.Value -1,0];
942 y = ATSGlobals.ScreenResolutions[tbr.Value - 1, 1];
943 }
944
945 private void tbrScreenResolution_Scroll(object sender, EventArgs e)
946 {
947 if (changedByUser)
948 {
949 int x, y;
950 // Convert values from trackbar
951 GetScreenResolutionFromTrackbar(tbrScreenResolution, out x, out y);
952 txtScreenResX.Text = x.ToString();
953 txtScreenResY.Text = y.ToString();
954 }
955 }
956
957 private void UpdateResolutionTrackbar()
958 { // Try to convert x, y values to trackbar.
959 int x, y;
960 try
961 {
962 x = Int32.Parse(txtScreenResX.Text.Trim());
963 }
964 catch (Exception)
965 {
966 x = 0;
967 }
968
969 try
970 {
971 y = Int32.Parse(txtScreenResY.Text.Trim());
972 }
973 catch (Exception)
974 {
975 y = 0;
976 }
977
978 UpdateScreenResolutionControls(x, y);
979 }
980
981
982 private void cboConnection_SelectedIndexChanged(object sender, EventArgs e)
983 {
984 SessionTypeChanged();
985 }
986
987 }
988 }