/[AnywhereTS-MSSQL]/trunk/TSAdminTool/frmClientProperties.cs
ViewVC logotype

Annotation of /trunk/TSAdminTool/frmClientProperties.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (hide annotations) (download)
Wed Jul 11 14:19:13 2012 UTC (8 years, 11 months ago) by william
File size: 43206 byte(s)
imported from https://anywherets.svn.sourceforge.net/svnroot/anywherets/trunk/
Revision: 1
Author: beartown
Date: 3:10:40 AM, Monday, June 21, 2010
Message:
First upload. Still todo in order to get a fully working product: Replace Thinstation images with vanilla Thinstation, modify ImageDesigntimeConfig.cs, ImageRuntimeConfig.cs in order to support the Thinstation image
1 william 4 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     Application.Exit();
253     return;
254     }
255    
256     } // if (dialogMode == ATSClientMode.CONTROL_PANEL)
257    
258     // Look for the client record to edit (not when adding client)
259     if (recordState == ATSRecordState.EDIT)
260     {
261     rowCurrentClient = datasetAllClientsAndDefault.Client.Rows.Find(macAddress);
262     }
263     // Does the MAC adress not exist in database?
264     if (rowCurrentClient == null)
265     {
266     recordState = ATSRecordState.ADD;
267     }
268    
269     // If in add mode, add new record
270     if (recordState == ATSRecordState.ADD)
271     {
272     // Add the client, using properties from the default record.
273     // Look up default record
274     // improve samma som i frmAdmin
275    
276     rowCurrentClient = datasetAllClientsAndDefault.Client.NewRow();
277    
278     ATSImageRuntimeConfig newConfig = new ATSImageRuntimeConfig();
279     newConfig.ReadDefaultFromDatabase();
280     newConfig.WriteToDatabase(rowCurrentClient);
281    
282     if (dialogMode == ATSClientMode.CONTROL_PANEL)
283     { // We are running as control panel for a user that yet has no record
284    
285     rowCurrentClient["macAddress"] = macAddress;
286     rowCurrentClient["clientName"] = "ATS" + macAddress;
287     }
288     else
289     { // We are adding a client from the Admin tool
290     rowCurrentClient["macAddress"] = "";
291     macAddress = "";
292     rowCurrentClient["clientName"] = "";
293     }
294     }
295    
296     // Load controls
297     if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
298     {
299     if (dialogMode != ATSClientMode.EDIT_DEFAULT)
300     {
301     txtMacAddress.Text = macAddress; // Mac address for the selected client
302     txtClientName.Text = rowCurrentClient["ClientName"].ToString();
303     txtComment.Text = rowCurrentClient["Comment"].ToString();
304     }
305     }
306    
307     // Read config from database
308     currentConfig.ReadFromDatabase(rowCurrentClient);
309    
310     // Update controls from config
311     UpdateScreenResolutionControls(currentConfig.ScreenResolutionX, currentConfig.ScreenResolutionY);
312    
313     switch (currentConfig.ScreenColorDepth)
314     {
315     case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit:
316     cboColorQuality.SelectedIndex = 0;
317     break;
318     case ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit:
319     cboColorQuality.SelectedIndex = 1;
320     break;
321     default:
322     throw new Exception("Error: Unhandled color depth: 29901");
323     }
324     chkDigitalMonitor.Checked = currentConfig.DigitalMonitor;
325     chkRedirectSound.Checked = currentConfig.RedirectSound;
326    
327     txtServer.Text = currentConfig.ServerName;
328     txtDomain.Text = currentConfig.ServerDomain;
329     txtUsername.Text = currentConfig.UserName;
330     txtPassword.Text = currentConfig.Password;
331     txtApplicationSet.Text = currentConfig.ICAApplicationSet;
332     txtCitrixServerURL.Text = currentConfig.ICAServerURL;
333     txtCitrixResource.Text = currentConfig.ICAResource;
334    
335     if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSRDP)
336     {
337     cboConnection.SelectedIndex = 0;
338     }
339     else if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSICA)
340     {
341     cboConnection.SelectedIndex = 1;
342     }
343     else if (currentConfig.SessionType == ATSImageRuntimeConfig.ATSSessionType.ATSPNA)
344     {
345     cboConnection.SelectedIndex = 2;
346     }
347     else
348     throw new Exception("Unhandled session type 65332");
349    
350     SessionTypeChanged(); // Enable and disable rdp and ica tabs
351    
352     chkReconnect.Checked = !currentConfig.ReconnectPrompt;
353    
354     if (dialogMode == ATSClientMode.CONTROL_PANEL)
355     { // We are running in control panel mode. Hide password box.
356     lblPassword.Visible = false;
357     txtPassword.Visible = false;
358     }
359    
360     tbrVolume.Value = currentConfig.AudioLevel;
361     tbrPointerSpeed.Value = currentConfig.MouseResolution;
362    
363     // If ICA tab exists (could have been removed in the control panel)
364     if (tabClientProperties.TabPages.ContainsKey("tabIca"))
365     {
366     chkIcaCompression.Checked = currentConfig.ICACompression;
367     if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.Low)
368     tbrIcaAudioQuality.Value = 1;
369     else if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.Medium)
370     tbrIcaAudioQuality.Value = 2;
371     else if (currentConfig.IcaAudioQuality == ATSImageRuntimeConfig.ATSIcaAudioQuality.High)
372     tbrIcaAudioQuality.Value = 3;
373     else
374     throw new Exception("Error: Unhandled audio quality (66432)");
375    
376     if (currentConfig.ICAProtocol == ATSImageRuntimeConfig.ATSIcaProtocol.ATSUDP)
377     radIcaProtocolUDP.Checked = true;
378     else if (currentConfig.ICAProtocol == ATSImageRuntimeConfig.ATSIcaProtocol.ATSHTTPOnTCP)
379     radIcaProtocolHTTP.Checked = true;
380     else
381     throw new Exception("Error: Unhandlced ICA protocol (60032)");
382    
383     int i = cboIcaEncryption.FindStringExact(currentConfig.ICAEncryption);
384     if (i != -1) // Check if the item was found in the combobox.
385     {
386     cboIcaEncryption.SelectedIndex = i;
387     }
388     else
389     throw new Exception("Error: Unhandlced ICA encryption(60033)");
390    
391     }
392    
393     // If RDP tab exists (could have been removed in the control panel)
394     if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
395     {
396     // Update RDP controls
397     chkRedirectFloppy.Checked = currentConfig.RedirectFloppy;
398     chkRedirectCD.Checked = currentConfig.RedirectCD;
399     chkMiscCOM1.Checked = currentConfig.MiscRedirectCom1;
400     chkMiscCOM2.Checked = currentConfig.MiscRedirectCom2;
401     chkUsbMemory.Checked = currentConfig.UsbDrive == ATSImageRuntimeConfig.ATSUsbDrive.One;
402     lblServerPort.Font = new Font(lblServerPort.Font, FontStyle.Regular);
403    
404    
405     // Initialise server port
406     if (currentConfig.ServerPort == -1)
407     {
408     txtServerPort.Text = "";
409     }
410     else
411     {
412     txtServerPort.Text = currentConfig.ServerPort.ToString();
413     }
414     }
415    
416     // If Misc tab exists (could have been removed in the control panel)
417     if (tabClientProperties.TabPages.ContainsKey("tabMisc"))
418     {
419    
420     chkMiscNumLock.Font = new Font(chkMiscNumLock.Font, FontStyle.Regular);
421    
422     // Initate controls from current configuration
423     chkMiscDailyreboot.Checked = currentConfig.DailyReboot;
424     chkMiscMousefix.Checked = currentConfig.MiscMousefix;
425     chkMiscFlippedFix.Checked = currentConfig.MiscFlippedFix;
426     chkMiscNoaccel.Checked = currentConfig.MiscNoAcceleration;
427     chkMiscNumLock.Checked = currentConfig.NumLock; // Note that state of ChangedByUser affects this control.
428    
429     // Initiate keyboard combo
430     cboKeyboard.Items.AddRange(ATSKeyboard.keyboardDescription); // Load keyboard descriptions
431     cboKeyboard.SelectedIndex = ATSKeyboard.KeyboardCodeToIndex(currentConfig.KeyboardMap);
432    
433     // Initiate timezone combo
434     cboTimezone.Items.AddRange(ATSTimeZone.timeZoneCode); // Load timezones
435     cboTimezone.SelectedIndex = ATSTimeZone.TimeZoneCodeToIndex(currentConfig.TimeZone);
436     }
437     changedByUser = true;
438     this.Cursor = Cursors.Default;
439     }
440    
441    
442     // OK Pressed
443     private void btnOK_Click(object sender, EventArgs e)
444     {
445     string strValidatedMacAdress = ""; // The validated MAC address.
446     string strValidatedClientName = ""; // The validated client name.
447     string strValidatedServerName = ""; // The validated server name.
448     UriHostNameType hostname; // used to validate host name
449    
450     // Validate MAC address and client name, unless in Default Parameters mode, where these two
451     // parameters do not exist.
452     if (dialogMode == ATSClientMode.EDIT_CLIENT || dialogMode == ATSClientMode.NEW_CLIENT)
453     {
454     if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
455     {
456     // Validate MAC address
457     if (txtMacAddress.Text == "")
458     {
459     tabClientProperties.SelectTab("TabGeneral");
460     MessageBox.Show("You must enter a MAC address!");
461     txtMacAddress.Focus();
462     return;
463     }
464     strValidatedMacAdress = ATSGlobals.IsValidMAC(txtMacAddress.Text);
465     if (strValidatedMacAdress == "")
466     {
467     tabClientProperties.SelectTab("TabGeneral");
468     MessageBox.Show("Invalid MAC address! Please enter a valid MAC address");
469     txtMacAddress.Focus();
470     txtMacAddress.SelectAll();
471     return;
472     }
473     // For new clients:
474     if (recordState == ATSRecordState.ADD)
475     { // Does MAC address already exist?
476     if (datasetAllClientsAndDefault.Client.Rows.Find(strValidatedMacAdress) != null)
477     {
478     tabClientProperties.SelectTab("TabGeneral");
479     MessageBox.Show("MAC address " + txtMacAddress.Text.ToUpper() + " is already in use by another client! Maybe you are trying to add the same client twice?");
480     txtMacAddress.Focus();
481     txtMacAddress.SelectAll();
482     return;
483     }
484     }
485    
486     // Validate Client name, maxlen 15 already given from text box.
487     if (txtClientName.Text == "")
488     {
489     tabClientProperties.SelectTab("TabGeneral");
490     MessageBox.Show("You must enter a name for the client!");
491     txtClientName.Focus();
492     return;
493     }
494    
495     strValidatedClientName = txtClientName.Text.ToUpper();
496    
497     hostname = Uri.CheckHostName(strValidatedClientName);
498     if (hostname == UriHostNameType.Unknown)
499     {
500     tabClientProperties.SelectTab("TabGeneral");
501     MessageBox.Show("Client name contains invalid characters! You must enter a valid client name.");
502     txtClientName.Focus();
503     txtClientName.SelectAll();
504     return;
505     }
506    
507     // Currently possible to have the same name for two clients.
508    
509     /*
510     // For new clients, client name alredy taken?
511     if (dialogMode == ATSClientMode.NEW_CLIENT)
512     {
513     if (datasetClient.Client.Rows.Find(strValidatedClientName) != null)
514     {
515     MessageBox.Show("Client name " + strValidatedClientName + " is already in use by another client!");
516     txtClientName.Focus();
517     txtClientName.SelectAll();
518     return;
519     }
520     }
521     */
522     } // Tab General
523     } // If edit client or new client (but not defuault)
524    
525     // Check that server name is entered.
526     strValidatedServerName = txtServer.Text.Trim();
527     if (strValidatedServerName.Length == 0)
528     {
529     tabClientProperties.SelectTab("TabConnection");
530     MessageBox.Show("You must enter a server name!");
531     txtServer.Focus();
532     txtServer.SelectAll();
533     return;
534     }
535    
536     // Validate server name, maxlen 30 already given from text box.
537     strValidatedServerName = txtServer.Text.ToUpper();
538    
539     hostname = Uri.CheckHostName(strValidatedServerName);
540     if (hostname == UriHostNameType.Unknown)
541     {
542     tabClientProperties.SelectTab("TabConnection");
543     MessageBox.Show("Invalid server name!");
544     txtServer.Focus();
545     txtServer.SelectAll();
546     return;
547     }
548    
549     // Validate and convert server port
550     if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
551     {
552     if (txtServerPort.Text.Trim().Length == 0)
553     { // No server port specified
554     currentConfig.ServerPort = -1;
555     }
556     else
557     { // The user has specified a server port
558     try
559     {
560     currentConfig.ServerPort = Int32.Parse(txtServerPort.Text.Trim());
561     }
562     catch (Exception)
563     {
564     tabClientProperties.SelectTab("tabRdp");
565     MessageBox.Show("Invalid server port!");
566     txtServerPort.Focus();
567     txtServerPort.SelectAll();
568     return;
569     }
570     if (currentConfig.ServerPort < 0 || currentConfig.ServerPort > 65535)
571     { // Value to high or to low
572     tabClientProperties.SelectTab("tabRdp");
573     MessageBox.Show("Invalid server port!");
574     txtServerPort.Focus();
575     txtServerPort.SelectAll();
576     return;
577     }
578     }
579     }
580    
581    
582     // Possible improvement: Did any parameters change?
583    
584     // Possible improvement: One of more parameters changed, save parameters to database.
585    
586    
587     // Save properties to database
588     if(dialogMode != ATSClientMode.EDIT_DEFAULT) // If we are editing default, server name and MAC address should not be saved.
589     {
590     if (tabClientProperties.TabPages.ContainsKey("TabGeneral"))
591     {
592     rowCurrentClient["ClientName"] = strValidatedClientName;
593     macAddress = strValidatedMacAdress;
594     rowCurrentClient["MacAddress"] = macAddress;
595     rowCurrentClient["Comment"] = txtComment.Text;
596     }
597     }
598    
599     // Resolution set by text boxes
600     try
601     {
602     currentConfig.ScreenResolutionX = Int32.Parse(txtScreenResX.Text.Trim());
603     }
604     catch (Exception)
605     {
606     tabClientProperties.SelectTab("TabInterface");
607     MessageBox.Show("Invalid screen resolution!");
608     txtScreenResX.Focus();
609     txtScreenResX.SelectAll();
610     return;
611     }
612     if (currentConfig.ScreenResolutionX < 100 || currentConfig.ScreenResolutionX > 9999)
613     { // Value to high or to low
614     tabClientProperties.SelectTab("TabInterface");
615     MessageBox.Show("Invalid screen resolution!");
616     txtScreenResX.Focus();
617     txtScreenResX.SelectAll();
618     return;
619     }
620    
621     try
622     {
623     currentConfig.ScreenResolutionY = Int32.Parse(txtScreenResY.Text.Trim());
624     }
625     catch (Exception)
626     {
627     tabClientProperties.SelectTab("TabInterface");
628     MessageBox.Show("Invalid screen resolution!");
629     txtScreenResY.Focus();
630     txtScreenResY.SelectAll();
631     return;
632     }
633     if (currentConfig.ScreenResolutionY < 100 || currentConfig.ScreenResolutionY > 9999)
634     { // Value to high or to low
635     tabClientProperties.SelectTab("TabInterface");
636     MessageBox.Show("Invalid screen resolution!");
637     txtScreenResY.Focus();
638     txtScreenResY.SelectAll();
639     return;
640     }
641    
642     switch (cboColorQuality.SelectedIndex)
643     {
644     case 0:
645     currentConfig.ScreenColorDepth = ATSImageRuntimeConfig.ATSScreenColorDepth.ATS16Bit;
646     break;
647     case 1:
648     currentConfig.ScreenColorDepth = ATSImageRuntimeConfig.ATSScreenColorDepth.ATS24Bit;
649     break;
650     default:
651     throw new Exception("Error: Unhandled color depth (41255).");
652     }
653    
654     currentConfig.ServerName = txtServer.Text.Trim();
655     currentConfig.ServerDomain = txtDomain.Text.Trim();
656     currentConfig.UserName = txtUsername.Text.Trim();
657     currentConfig.Password = txtPassword.Text;
658     currentConfig.ICAApplicationSet = txtApplicationSet.Text.Trim();
659     currentConfig.ICAServerURL = txtCitrixServerURL.Text.Trim();
660     currentConfig.ICAResource = txtCitrixResource.Text.Trim();
661    
662     if (cboConnection.SelectedIndex == 0)
663     {
664     currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSRDP;
665     }
666     else if (cboConnection.SelectedIndex == 1)
667     {
668     currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSICA;
669     }
670     else if (cboConnection.SelectedIndex == 2)
671     {
672     currentConfig.SessionType = ATSImageRuntimeConfig.ATSSessionType.ATSPNA;
673     }
674     else
675     throw new Exception("Error: Unhandled connection type(41283).");
676    
677     currentConfig.ReconnectPrompt = !chkReconnect.Checked;
678     currentConfig.AudioLevel = tbrVolume.Value;
679     currentConfig.MouseResolution = tbrPointerSpeed.Value;
680     currentConfig.DigitalMonitor = chkDigitalMonitor.Checked;
681     currentConfig.RedirectSound = chkRedirectSound.Checked;
682    
683     // If ICA tab exists (could have been removed in the control panel)
684     if (tabClientProperties.TabPages.ContainsKey("tabIca"))
685     {
686     currentConfig.ICACompression = chkIcaCompression.Checked;
687     currentConfig.ICAEncryption = cboIcaEncryption.Items[cboIcaEncryption.SelectedIndex].ToString();
688     if (radIcaProtocolUDP.Checked)
689     currentConfig.ICAProtocol = ATSImageRuntimeConfig.ATSIcaProtocol.ATSUDP;
690     else
691     currentConfig.ICAProtocol = ATSImageRuntimeConfig.ATSIcaProtocol.ATSHTTPOnTCP;
692    
693     if (tbrIcaAudioQuality.Value == 1)
694     currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.Low;
695     else if (tbrIcaAudioQuality.Value == 2)
696     currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.Medium;
697     else
698     currentConfig.IcaAudioQuality = ATSImageRuntimeConfig.ATSIcaAudioQuality.High;
699     }
700    
701     // If RDP tab exists (could have been removed in the control panel)
702     if (tabClientProperties.TabPages.ContainsKey("tabRdp"))
703     {
704     // Save RDP options
705     currentConfig.RedirectFloppy = chkRedirectFloppy.Checked;
706     currentConfig.RedirectCD = chkRedirectCD.Checked;
707     currentConfig.MiscRedirectCom1 = chkMiscCOM1.Checked;
708     currentConfig.MiscRedirectCom2 = chkMiscCOM2.Checked;
709     if (chkUsbMemory.Checked)
710     {
711     currentConfig.UsbDrive = ATSImageRuntimeConfig.ATSUsbDrive.One;
712     }
713     else
714     {
715     currentConfig.UsbDrive = ATSImageRuntimeConfig.ATSUsbDrive.None;
716     }
717     }
718    
719     // If Misc tab exists (could have been removed in the control panel)
720     if (tabClientProperties.TabPages.ContainsKey("tabMisc"))
721     {
722     // Update current configuration from controls
723     currentConfig.NumLock = chkMiscNumLock.Checked;
724     currentConfig.DailyReboot = chkMiscDailyreboot.Checked;
725     currentConfig.MiscMousefix = chkMiscMousefix.Checked;
726     currentConfig.MiscFlippedFix = chkMiscFlippedFix.Checked;
727     currentConfig.MiscNoAcceleration = chkMiscNoaccel.Checked;
728     currentConfig.TimeZone = cboTimezone.Items[cboTimezone.SelectedIndex].ToString();
729     currentConfig.KeyboardMap = ATSKeyboard.keyboardCode[cboKeyboard.SelectedIndex];
730     }
731    
732     currentConfig.WriteToDatabase(rowCurrentClient); // Save config to the row
733    
734     // If it is a new client, we need to add the row to the client table.
735     if (recordState == ATSRecordState.ADD)
736     {
737     datasetAllClientsAndDefault.Client.Rows.Add(rowCurrentClient);
738     }
739    
740     try
741     {
742     ProSupport.clientTableAdapter.Update(datasetAllClientsAndDefault.Client);
743     }
744     catch
745     {
746     MessageBox.Show("Error, could not update database (10084). Try to redo the operation.");
747     }
748    
749     if (dialogMode == ATSClientMode.EDIT_DEFAULT)
750     { // Write network config file, since the default values should be saved in the network file.
751     ProSupport.WriteConfigFiles(currentConfig, ProSupport.strNetworkConfigFilename, false);
752     }
753     else
754     {
755     // Write client config file
756     ProSupport.WriteConfigFiles(currentConfig, macAddress, true);
757     }
758    
759     // If admin, try to send message to the session to restart
760    
761     if (dialogMode == ATSClientMode.CONTROL_PANEL)
762     { // This form is the main and only form
763     Application.Exit();
764     }
765     else
766     { // This form is called from another form
767     DialogResult = DialogResult.OK;
768     }
769     this.Cursor = Cursors.Default;
770     }
771    
772     private void btnCancel_Click(object sender, EventArgs e)
773     {
774     if (dialogMode == ATSClientMode.CONTROL_PANEL)
775     { // This form is the main and only form
776     Application.Exit();
777     }
778     else
779     { // This form is called from another form
780     DialogResult = DialogResult.Cancel;
781     }
782     }
783    
784     // Display context sensitive ATS help, depending on mode (default properties or normal properties) and selected tab
785     private void ShowAtsHelp()
786     {
787     string helpKeyword = "";
788     if (dialogMode == ATSClientMode.EDIT_CLIENT || dialogMode == ATSClientMode.NEW_CLIENT)
789     { // We are running the form in edit or new mode
790     switch (tabClientProperties.SelectedTab.Name)
791     {
792     case "tabGeneral":
793     helpKeyword = "clientpropertiesgeneral.htm";
794     break;
795     case "tabConnection":
796     helpKeyword = "clientpropertiesconnection.htm";
797     break;
798     case "tabInterface":
799     helpKeyword = "clientpropertiesinterface.htm";
800     break;
801     case "tabRdp":
802     helpKeyword = "clientpropertiesrdp.htm";
803     break;
804     case "tabIca":
805     helpKeyword = "clientpropertiesica.htm";
806     break;
807     case "tabMisc":
808     helpKeyword = "clientpropertiesmisc.htm";
809     break;
810     default:
811     throw new Exception("Error: Invalid tab (63326): " + tabClientProperties.SelectedTab.Name);
812     }
813     }
814     else if (dialogMode == ATSClientMode.EDIT_DEFAULT)
815     { // We are running the form in default settings mode
816     switch (tabClientProperties.SelectedTab.Name)
817     {
818     case "tabGeneral":
819     helpKeyword = "defaultsettingsgeneral.htm";
820     break;
821     case "tabConnection":
822     helpKeyword = "defaultsettingsconnection.htm";
823     break;
824     case "tabInterface":
825     helpKeyword = "defaultsettingsinterface.htm";
826     break;
827     case "tabRdp":
828     helpKeyword = "defaultsettingsrdp.htm";
829     break;
830     case "tabIca":
831     helpKeyword = "defaultsettingsica.htm";
832     break;
833     case "tabMisc":
834     helpKeyword = "defaultsettingsmisc.htm";
835     break;
836     default:
837     throw new Exception("Error: Invalid tab (63327): " + tabClientProperties.SelectedTab.Name);
838     }
839     }
840     Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.Topic, helpKeyword);
841     }
842    
843     private void frmClientProperties_KeyDown(object sender, KeyEventArgs e)
844     {
845     if (e.KeyCode == Keys.F1)
846     { // F1 pressed, show ATS help
847     ShowAtsHelp();
848     }
849     }
850    
851     private void frmClientProperties_HelpRequested(object sender, HelpEventArgs hlpevent)
852     {
853     hlpevent.Handled = true;
854     }
855    
856     // Changed connection type, enable rdp and ica tabs respectively
857     private void SessionTypeChanged()
858     {
859     if (cboConnection.SelectedIndex == 0)
860     { //RDP
861     pnlCitrixPN.Visible = false;
862     pnlApplicationSet.Visible = false;
863     }
864     else if (cboConnection.SelectedIndex == 1)
865     { //ICA
866     pnlCitrixPN.Visible = false;
867     pnlApplicationSet.Visible = true;
868     }
869     else if (cboConnection.SelectedIndex == 2)
870     { // PNA
871     pnlCitrixPN.Visible = true;
872     pnlApplicationSet.Visible = false;
873     }
874     else
875     throw new Exception("Unhandled session type 95333");
876     }
877    
878     private void UpdateScreenResolutionControls(int x, int y)
879     {
880     txtScreenResX.Text = x.ToString();
881     txtScreenResY.Text = y.ToString();
882    
883     for (int i = 0; i < ATSGlobals.ScreenResolutions.GetLength(0); i++)
884     {
885     if (x == ATSGlobals.ScreenResolutions[i, 0] && y == ATSGlobals.ScreenResolutions[i, 1])
886     {
887     tbrScreenResolution.Value = i + 1;
888     return;
889     }
890    
891     }
892     // Values could not be expressed using the track bar. Set it at default.
893     tbrScreenResolution.Value = 4;
894     }
895    
896     private void GetScreenResolutionFromTrackbar(TrackBar tbr, out int x, out int y)
897     {
898     x = ATSGlobals.ScreenResolutions[tbr.Value -1,0];
899     y = ATSGlobals.ScreenResolutions[tbr.Value - 1, 1];
900     }
901    
902     private void tbrScreenResolution_Scroll(object sender, EventArgs e)
903     {
904     if (changedByUser)
905     {
906     int x, y;
907     // Convert values from trackbar
908     GetScreenResolutionFromTrackbar(tbrScreenResolution, out x, out y);
909     txtScreenResX.Text = x.ToString();
910     txtScreenResY.Text = y.ToString();
911     }
912     }
913    
914     private void UpdateResolutionTrackbar()
915     { // Try to convert x, y values to trackbar.
916     int x, y;
917     try
918     {
919     x = Int32.Parse(txtScreenResX.Text.Trim());
920     }
921     catch (Exception)
922     {
923     x = 0;
924     }
925    
926     try
927     {
928     y = Int32.Parse(txtScreenResY.Text.Trim());
929     }
930     catch (Exception)
931     {
932     y = 0;
933     }
934    
935     UpdateScreenResolutionControls(x, y);
936     }
937    
938    
939     private void cboConnection_SelectedIndexChanged(object sender, EventArgs e)
940     {
941     SessionTypeChanged();
942     }
943    
944     }
945     }

  ViewVC Help
Powered by ViewVC 1.1.22