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

Contents of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4 - (show annotations) (download)
Wed Jul 11 14:19:13 2012 UTC (7 years, 7 months ago) by william
File size: 41888 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 namespace AnywhereTS
2 {
3 using System;
4 using System.Collections.Generic;
5 using System.ComponentModel;
6 using System.Data;
7 using System.Drawing;
8 using System.Text;
9 using System.Windows.Forms;
10 using System.Runtime.InteropServices;
11 using System.IO; // For File operations
12
13
14 public partial class frmAdmin : Form
15 {
16 // Data variables
17
18 //DatabaseSupport dataSupport;
19 private atsDataSet datasetAllClients; // Dataset containing all clients
20 private atsDataSet datasetLicensedClients; // Dataset containing only the licensed clients, sorted in order of creation
21
22 private string selectedClientMacAddress; // The MAC address of the currently selected client.
23 public frmAdmin()
24 {
25 InitializeComponent();
26 }
27
28
29 private void frmAdmin_Load(object sender, EventArgs e)
30 {
31 this.Cursor = Cursors.WaitCursor;
32
33 UpdateControlsToReflectProgramVersion();
34
35 // Check if AnywhereTS is configured
36 if (ATSGlobals.configured == 0 || ATSGlobals.managedMode == 0)
37 { // ATS is not configured, configure
38 if (!ConfigureATS())
39 {
40 // ATS still not configured, abort
41 MessageBox.Show("You cannot run AnywhereTS without configuring it first.");
42 Application.Exit();
43 return;
44 }
45 }
46
47 // Setup controls and database
48 SetMode();
49
50 helpProvider.HelpNamespace = ATSGlobals.strHelpFilePath; // Initiate helpProvider
51
52 treeView.Nodes[1].Expand(); // Expand terminal servers node.
53
54 this.Cursor = Cursors.Default;
55
56 // Create a default record
57 ATSImageDesigntimeConfig newConfig = new ATSImageDesigntimeConfig();
58 newConfig.ReadDefaultFromDatabase();
59 newConfig.WriteDefaultsToDatabase();
60 } // form load
61
62 private void UpdateControlsToReflectProgramVersion()
63 {
64 // Update the application to reflect the type of license and release
65 ATSGlobals.isPro = true;
66 Globals.isPro = ATSGlobals.isPro; // Update program status for the VB part of the application.
67 // We are running in Pro Mode, add 'Open Source' to the Application name
68 ATSGlobals.ApplicationTitle = ATSGlobals.ApplicationName + " Open Source Version";
69
70 this.Text = ATSGlobals.ApplicationTitle; // Set name in window title
71 aboutToolStripMenuItem.Text = "About " + ATSGlobals.ApplicationTitle;
72 }
73
74 // Update database from terminal server sessions
75 private void UpdateClientsFromSession()
76 {
77 List<TSManager.TS_SESSION_INFO> Sessions;
78 Sessions = TSManager.ListSessions();
79 foreach (TSManager.TS_SESSION_INFO session in Sessions)
80 {
81 if (session.macAddress != "")
82 { // The client is an (Un-named) ATS client. We have a MAC address.
83
84 // Does the MAC adress for the session alreay exist in database?
85 if (datasetAllClients.Client.Rows.Find(session.macAddress) == null)
86 {
87 // The MAC address did not exist in database. Add the client, using properties from the default record.
88 DataRow newRow = datasetAllClients.Client.NewRow();
89 ATSImageRuntimeConfig newConfig = new ATSImageRuntimeConfig();
90 newConfig.ReadDefaultFromDatabase();
91 newConfig.WriteToDatabase(newRow);
92 newRow["macAddress"] = session.macAddress;
93 newRow["clientName"] = session.name;
94 datasetAllClients.Client.Rows.Add(newRow);
95 }
96 }
97 }
98 ProSupport.clientTableAdapter.Update(datasetAllClients.Client);
99 }
100
101
102 // Update the tree control and database from sessions
103 private void UpdateTree()
104 {
105 this.Cursor = Cursors.WaitCursor;
106
107 // Update the environment
108 AtsEnvironment.Refresh();
109 // Update general statistics
110 lblNoOfTS.Text = AtsEnvironment.TerminalServers.Count.ToString();
111 lblNoOfSessions.Text = AtsEnvironment.Sessions.Count.ToString();
112
113 // Get records from the database.
114 FillLicensedClients(datasetLicensedClients);
115 // Poulate a dataset with all clients (regardless of license) and default record for reference.
116 ProSupport.clientTableAdapter.FillClients(datasetAllClients.Client);
117
118 UpdateClientsFromSession();
119
120 // Update the no of clients text
121 if (datasetAllClients.Client.Rows.Count == 0)
122 {
123 rtxWelcome.Visible = true;
124 lblRoot.Text = "Welcome to " + ATSGlobals.ApplicationName + "!";
125 tlpGeneralData.Visible = false;
126 }
127 else
128 {
129 rtxWelcome.Visible = false;
130 lblRoot.Text = "Summary Statistics";
131 tlpGeneralData.Visible = true;
132 lblNoOfClients.Text = datasetAllClients.Client.Rows.Count.ToString();
133 }
134
135 // Add clients to the tree
136 treeView.Nodes[0].Nodes.Clear(); // Clear the clients node
137 foreach (DataRow row in datasetLicensedClients.Client.Rows)
138 {
139 AtsSession session; // Session for the current client
140 TreeNode addedNode;
141
142 session = TSManager.GetSession(row["MacAddress"].ToString());
143 if (session != null && session.username.Length > 0)
144 {
145 // There is a user name for the client, display client name and user name.
146 addedNode = treeView.Nodes[0].Nodes.Add(row["ClientName"].ToString() + " (" + session.username + ")");
147 }
148 else
149 {
150 // There is no user name for the client, just add client name.
151 addedNode = treeView.Nodes[0].Nodes.Add(row["ClientName"].ToString());
152 }
153
154 // Select the appropriate bitmap to show for the node according to its status.
155 // Default is disconnected, so no need to indicate that.
156 if (session != null)
157 {
158 // There is a session for the client
159 if (session.username.Length > 0)
160 { // There is a user logged in
161 addedNode.ImageIndex = 3;
162 addedNode.SelectedImageIndex = 3;
163 }
164 else
165 { // The session has no user
166 addedNode.ImageIndex = 2;
167 addedNode.SelectedImageIndex = 2;
168 }
169
170 } // if client has session
171 addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables to remove the client.
172
173 } // foreach client
174
175 ProSupport.WriteHostsFiles(); // Update the hosts files on all TFTP servers
176
177 // Add terminal servers to the tree
178 treeView.Nodes[1].Nodes.Clear(); // Clear the terminal server node
179 foreach (AtsTerminalServer ts in AtsEnvironment.TerminalServers)
180 {
181 // Add a terminal server to the tree
182 TreeNode addedServerNode;
183 if (ts.networkPath == "localhost")
184 {
185 addedServerNode = treeView.Nodes[1].Nodes.Add("This Computer");
186 }
187 else
188 {
189 addedServerNode = treeView.Nodes[1].Nodes.Add(ts.networkPath);
190 }
191 addedServerNode.ToolTipText = ts.strError;
192 if (ts.Online)
193 { // Display the online server icon
194 addedServerNode.ImageIndex = 5;
195 addedServerNode.SelectedImageIndex = 5;
196 }
197 else
198 { // Display the offline server icon
199 addedServerNode.ImageIndex = 6;
200 addedServerNode.SelectedImageIndex = 6;
201 }
202 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables to remove the client.
203
204 // Add sessions for the terminal server to the tree.
205 foreach (AtsSession session in ts.Session)
206 {
207 string sessionText;
208 int imageIndex;
209 if (session.sessionID == 0)
210 { // This is a console session
211 sessionText = "Console";
212 if (session.username.Length != 0)
213 { // Session has a username
214 sessionText += " (" + session.username + ")";
215 }
216 imageIndex = 7; // Display the active session icon
217 }
218 else if (session.sessionID == 65536)
219 { // This is the listener session
220 sessionText = "Listener";
221 imageIndex = 8; // Display the non-active session icon
222 }
223 else
224 { // This is a "normal" session
225 sessionText = session.sessionID.ToString() + " " + (session.username.Length != 0 ? " (" + session.username + ")" : "");
226 if (session.state == TSManager.WTS_CONNECTSTATE_CLASS.WTSActive)
227 { // Display the active session icon
228 imageIndex = 7;
229 }
230 else
231 { // Display the non-active session icon
232 imageIndex = 8;
233 }
234 }
235 TreeNode addedSessionNode;
236 addedSessionNode = addedServerNode.Nodes.Add(sessionText);
237 addedSessionNode.ImageIndex = imageIndex;
238 addedSessionNode.SelectedImageIndex = imageIndex;
239 addedSessionNode.Tag = session;
240 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables option to remove the client.
241 } // foreach session
242
243 } // foreach terminal server
244
245 // Add sesions to the tree
246 treeView.Nodes[2].Nodes.Clear(); // Clear the sessions node
247 foreach (AtsSession session in AtsEnvironment.Sessions)
248 {
249 string sessionText;
250 int imageIndex;
251 if (session.sessionID == 0)
252 { // This is a console session
253 sessionText = "Console";
254 if (session.username.Length != 0)
255 { // Session has a username
256 sessionText += " (" + session.username + ")";
257 }
258 imageIndex = 7; // Display the active session icon
259 }
260 else if (session.sessionID == 65536)
261 { // This is the listener session
262 sessionText = "Listener";
263 imageIndex = 8; // Display the non-active session icon
264 }
265 else
266 { // This is a "normal" session
267 if (session.username.Length != 0)
268 { // Session has a username
269 sessionText = session.username;
270 }
271 else
272 { // Session does not have a username
273 sessionText = "Not logged on";
274 }
275 // Select the icon to display
276 if (session.state == TSManager.WTS_CONNECTSTATE_CLASS.WTSActive)
277 { // Display the active session icon
278 imageIndex = 7;
279 }
280 else
281 { // Display the non-active session icon
282 imageIndex = 8;
283 }
284 }
285 // Add terminal server name if we have more than one terminal server
286 if (AtsEnvironment.TerminalServers.Count > 1)
287 { // We have more than one terminal server, display the name of the terminal server
288 sessionText += " (" + session.TerminalServerName + ")";
289 }
290
291 TreeNode addedSessionNode;
292 addedSessionNode = treeView.Nodes[2].Nodes.Add(sessionText);
293 addedSessionNode.ImageIndex = imageIndex;
294 addedSessionNode.SelectedImageIndex = imageIndex;
295 addedSessionNode.Tag = session;
296 //addedNode.ContextMenuStrip = contextMenuClient; // Add the context menu for the client. Enables option to remove the client.
297 } // foreach session
298
299 // Select the root node
300 treeView.SelectedNode = treeView.Nodes[0];
301 NodeSelected(treeView.Nodes[0]); // Update related controls
302
303 this.Cursor = Cursors.Default;
304 }
305
306 private void FillLicensedClients(atsDataSet dataset)
307 {
308 ProSupport.clientTableAdapter.FillClients(dataset.Client);
309 }
310
311 private void toolStripAddClient_Click(object sender, EventArgs e)
312 {
313 AddClient();
314 }
315
316 // Refresh database and controls
317 private void toolStripButtonRefresh_Click(object sender, EventArgs e)
318 {
319 UpdateTree();
320 }
321
322
323 private void treeView_AfterSelect(object sender, TreeViewEventArgs e)
324 {
325 this.Cursor = Cursors.WaitCursor;
326 TreeNode selectedNode = e.Node;
327 NodeSelected(selectedNode);
328 this.Cursor = Cursors.Default;
329 }
330
331 private void NodeSelected(TreeNode node)
332 {
333 if (node.Parent != null)
334 {
335 // A child node selected in the tree view
336
337 if (node.Parent.Name == "nodeClients")
338 { // A client node is selected in the tree view.
339
340 // A client was selected in the tree
341
342 // Enable the delete tool button.
343 toolStripButtonDelete.Enabled = true;
344 deleteClientToolStripMenuItem.Enabled = true;
345
346 // Display client data
347 AtsSession sessionInfo; // Session info for the client that was selected in the tree
348 selectedClientMacAddress = datasetLicensedClients.Client.Rows[node.Index]["MacAddress"].ToString();
349 //selectedConfig.ReadFromDatabase(datasetClient.Client.Rows[e.Node.Index]);
350
351 lblClientName.Text = datasetLicensedClients.Client.Rows[node.Index]["ClientName"].ToString();
352 lblMacAddress.Text = selectedClientMacAddress;
353 lblConnectionType.Text = datasetLicensedClients.Client.Rows[node.Index]["SessionType"].ToString();
354 lblResolution.Text = datasetLicensedClients.Client.Rows[node.Index]["ScreenResolution"].ToString();
355 lblColorDepth.Text = datasetLicensedClients.Client.Rows[node.Index]["ScreenColorDepth"].ToString();
356
357 sessionInfo = TSManager.GetSession(selectedClientMacAddress);
358 if (sessionInfo != null)
359 {
360 // Display the session data for the selected client
361 UpdateSessionPanel(sessionInfo);
362 }
363 else
364 {
365 // There is no session for the selected client
366 tlpSessionDetails.Visible = false;
367 lblClientHasNoSession.Visible = true;
368 }
369 // Display the client panelValue
370 pnlClientSession.Visible = true;
371 pnlDefault.Visible = false;
372 pnlClientDetails.Visible = true;
373 PositionClientSessionPanels(false); // Put the client panel over the session panel
374 propertiesToolStripMenuItem1.Enabled = true;
375 toolStripButtonProperties.Enabled = true;
376 } // end if client node selected
377
378 else if (node.Parent.Name == "nodeTerminalServers")
379 { // A terminal server is selected in the tree view
380 // Display the default panel
381 pnlDefault.Visible = true;
382 pnlClientSession.Visible = false;
383 // Disable the delete tool button.
384 toolStripButtonDelete.Enabled = false;
385 deleteClientToolStripMenuItem.Enabled = false;
386 propertiesToolStripMenuItem1.Enabled = false;
387 toolStripButtonProperties.Enabled = false;
388
389 }
390 else if (node.Parent.Name == "nodeSessions" || (node.Level == 2))
391 { // A session under the "Sesssions" node is selected in the tree view.
392 // Or a session under a terminal server node is selected in the tree view
393
394 // Display the session data
395 AtsSession session = (AtsSession)node.Tag;
396
397 PositionClientSessionPanels(true);
398 UpdateSessionPanel(session);
399
400 // Display the ClientSession panel
401 pnlClientSession.Visible = true;
402 pnlDefault.Visible = false;
403 // Hide client panel
404 pnlClientDetails.Visible = false;
405 }
406
407 else
408 { // Unhandled node
409 MessageBox.Show("Error: unhandled node (28843)");
410 }
411 }
412 else
413 {
414 // One of the root nodes is selected in the tree view.
415 // Display the default panel
416 pnlDefault.Visible = true;
417 pnlClientSession.Visible = false;
418
419 // Disable the delete tool button.
420 toolStripButtonDelete.Enabled = false;
421 deleteClientToolStripMenuItem.Enabled = false;
422 propertiesToolStripMenuItem1.Enabled = false;
423 toolStripButtonProperties.Enabled = false;
424 }
425 }
426
427 // Updates the session panel in the right pane with session data from the session in "session"
428 private void UpdateSessionPanel(AtsSession session)
429 {
430 tlpSessionDetails.Visible = true;
431 lblClientHasNoSession.Visible = false;
432 lblUserName.Text = session.username.Length != 0 ? session.username : "-";
433 lblSessionID.Text = session.sessionID.ToString();
434 lblState.Text = TSManager.StateToString(session.state);
435 lblIPAddress.Text = session.ipAddress.Length != 0 ? session.ipAddress : "-";
436 if (session.HorizontalResolution != 0)
437 {
438 lblSessionScreenResolution.Text = session.HorizontalResolution.ToString() + "x" + session.VerticalResolution.ToString();
439 }
440 else
441 { // No screen resolution
442 lblSessionScreenResolution.Text = "-";
443 }
444 }
445
446 // Position the panels for session info and client info.
447 // sessionOnTop = true > Place the session panel over the client panel.
448 // sessionOnTop = false > Place the client panel over the session panel.
449 private void PositionClientSessionPanels(bool sessionOnTop)
450 {
451 if (sessionOnTop)
452 {
453 pnlClientDetails.Top = 163;
454 pnlSessionDetails.Top = 3;
455 }
456 else
457 {
458 pnlClientDetails.Top = 3;
459 pnlSessionDetails.Top = 224;
460 }
461 }
462
463 private void btnDefault_Click(object sender, EventArgs e)
464 {
465 // Display client default properties dialog
466 ClientDefaultSettings();
467 }
468
469 private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
470 {
471 // Delete a client
472 DeleteClient();
473 }
474
475 // User clicked Properties on the client toolstrip
476 private void propertiesToolStripMenuItem_Click(object sender, EventArgs e)
477 {
478 // Display client properties
479 ClientProperties();
480 }
481
482 private void treeView_DoubleClick(object sender, EventArgs e)
483 {
484 //The user has double clicked a tree node
485 // The node will autmatically be selected on the mouse down event, so
486 // now the After_Select event has already been run and variables updated accordingly.
487
488
489 if (treeView.SelectedNode.Parent != null)
490 {
491 // A child node selected in the tree view
492 if (treeView.SelectedNode.Parent.Name == "nodeClients")
493 { // A client node is selected in the tree view.
494 // Check if a client is selected
495 if (treeView.SelectedNode.Name != "nodeLicenseWarning")
496 { // A client is selected in the tree
497 // Display client properties
498 ClientProperties();
499 }
500 }
501 else if (treeView.SelectedNode.Parent.Name == "nodeTerminalServers")
502 { // A terminal server is selected in the tree view
503
504 }
505 }
506 else
507 {
508 // The user has double clicked the root node.
509 }
510 }
511
512 private void treeView_KeyDown(object sender, KeyEventArgs e)
513 {
514 if (treeView.SelectedNode.Parent != null)
515 {
516 // A child node is selected in the tree view
517 if (treeView.SelectedNode.Parent.Name == "nodeClients")
518 { // A client node is selected in the tree view.
519 if (treeView.SelectedNode.Name != "nodeLicenseWarning")
520 { // A client is selected in the tree
521 if (e.KeyCode == Keys.Delete)
522 {
523 // Delete client
524 DeleteClient();
525 }
526 else if (e.KeyCode == Keys.Enter)
527 {
528 // Display client properties
529 ClientProperties();
530 }
531 }
532 }
533 }
534 }
535
536 // Display properties for the currently selected client
537 private void ClientProperties()
538 {
539 this.Cursor = Cursors.WaitCursor;
540
541 using (frmClientProperties objCustomDialogBox = new frmClientProperties())
542 {
543 objCustomDialogBox.macAddress = selectedClientMacAddress;
544 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.EDIT_CLIENT; // Select the mode to run the form in.
545 this.Cursor = Cursors.Default;
546
547 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
548 {
549 UpdateTree();
550 }
551 } // Unload frm
552 }
553
554 // Display the add client dialog and add a client
555 private void AddClient()
556 {
557 // Display client properties dialog in Add mode
558 this.Cursor = Cursors.WaitCursor;
559 frmClientProperties objCustomDialogBox = new frmClientProperties();
560 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.NEW_CLIENT; // Select the mode to run the form in.
561 this.Cursor = Cursors.Default;
562
563 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
564 {
565 UpdateTree();
566 }
567 objCustomDialogBox = null;
568 treeView.Nodes[0].Expand(); // Expand ATS client node, in order to show the newly added client
569 }
570
571 private void toolStripButtonAdd_Click(object sender, EventArgs e)
572 {
573 AddClient();
574 }
575
576 private void DeleteClient()
577 {
578 DialogResult result;
579 result = MessageBox.Show(this, "Are you sure you want to delete the client '" + lblClientName.Text + "'?", ATSGlobals.ApplicationName , MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
580 if (result == DialogResult.Yes)
581 {
582 this.Cursor = Cursors.WaitCursor;
583
584 // Delete the client
585 DataRow rowToDelete;
586
587 rowToDelete = datasetAllClients.Client.Rows.Find(selectedClientMacAddress);
588
589 if (rowToDelete != null)
590 {
591 // Delete the client database row.
592 rowToDelete.Delete();
593 ProSupport.clientTableAdapter.Update(datasetAllClients.Client);
594 UpdateTree();
595 // Delete the client config file.
596 string fileToDelete;
597 fileToDelete = ATSGlobals.strTFTPdir + @"\" + selectedClientMacAddress;
598 if (File.Exists(fileToDelete))
599 {
600 File.Delete(fileToDelete);
601 }
602 this.Cursor = Cursors.Default;
603
604 }
605 else
606 {
607 throw new Exception("Error: Cannot find record to delete (43556)");
608 }
609 }
610 }
611
612 // View and change default settings for all clients
613 private void ClientDefaultSettings()
614 {
615 // Display client default properties dialog
616 this.Cursor = Cursors.WaitCursor;
617
618 frmClientProperties objCustomDialogBox = new frmClientProperties();
619 objCustomDialogBox.macAddress = ProSupport.DEFAULT_RECORD_MAC;
620 objCustomDialogBox.dialogMode = frmClientProperties.ATSClientMode.EDIT_DEFAULT; // Select the mode to run the form in.
621 this.Cursor = Cursors.Default;
622
623 if (objCustomDialogBox.ShowDialog() == DialogResult.OK)
624 {
625 // Possible improvement: Did any parameters change?
626
627 // One of more parameters changed, save parameters to database.
628
629 UpdateTree();
630 }
631 objCustomDialogBox = null;
632 }
633
634 private void toolStripButtonDelete_Click(object sender, EventArgs e)
635 {
636 DeleteClient();
637 }
638
639 private void treeView_MouseDown(object sender, MouseEventArgs e)
640 {
641 if (treeView.GetNodeAt(e.X, e.Y) != null)
642 treeView.SelectedNode = treeView.GetNodeAt(e.X, e.Y);
643 }
644
645 private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
646 {
647 frmAboutPro objCustomDialogBox = new frmAboutPro();
648 objCustomDialogBox.ShowDialog();
649 }
650
651 private void anywhereTSHomepageToolStripMenuItem_Click(object sender, EventArgs e)
652 {
653 wizardSupport.AnywhereTSHomepage();
654 }
655
656 private void exitToolStripMenuItem_Click(object sender, EventArgs e)
657 {
658 Application.Exit();
659 }
660
661 private void cDToolStripMenuItem_Click(object sender, EventArgs e)
662 {
663 wizardSupport.PXEBootType = wizardSupport.PXEBootTask.PXE_Boot_CD;
664 wizardSupport.PXEBoot();
665 }
666
667 private void floppyToolStripMenuItem_Click(object sender, EventArgs e)
668 {
669 wizardSupport.PXEBootType = wizardSupport.PXEBootTask.PXE_Boot_Floppy;
670 wizardSupport.PXEBoot();
671 }
672
673 private void addClientToolStripMenuItem_Click(object sender, EventArgs e)
674 {
675 AddClient();
676 }
677
678 private void deleteClientToolStripMenuItem_Click(object sender, EventArgs e)
679 {
680 DeleteClient();
681 }
682
683 private void clientDefaultsToolStripMenuItem_Click(object sender, EventArgs e)
684 {
685 ClientDefaultSettings();
686 }
687
688 private void propertiesToolStripMenuItem1_Click(object sender, EventArgs e)
689 {
690 ClientProperties();
691 }
692
693 private void refreshToolStripMenuItem_Click(object sender, EventArgs e)
694 {
695 UpdateTree();
696 }
697
698 private void UserSelectedImage()
699 {
700 Globals.WizardMode = Globals.WizardTask.USER_SELECTED_DISTRIBUTION;
701 using (frmWizard objCustomDialogBox = new frmWizard())
702 {
703 objCustomDialogBox.ShowDialog();
704 } // Unload frmWizard, in order to run load event next time.
705 }
706
707 private void createClientBootToolStripMenuItem_Click(object sender, EventArgs e)
708 {
709 UserSelectedImage();
710 }
711
712 private void toolStripButtonProperties_Click(object sender, EventArgs e)
713 {
714 ClientProperties();
715 }
716
717 private void toolStripButtonNetworkBootImage_Click(object sender, EventArgs e)
718 {
719 UserSelectedImage();
720 }
721
722 private void toolStripButtonHomepage_Click(object sender, EventArgs e)
723 {
724 wizardSupport.AnywhereTSHomepage();
725 }
726
727 private void selectModeToolStripMenuItem_Click(object sender, EventArgs e)
728 {
729 ConfigureATS();
730 // Update controls and setup datbase etc.
731 SetMode();
732 }
733
734
735 // Configure AnywhereTS
736 // Run first time starting ATS and can also be invoked from the Tools menu.
737 private bool ConfigureATS()
738 {
739 DialogResult result;
740
741 if (!ProSupport.IsAnAdministrator())
742 {
743 MessageBox.Show("Only administrators can configure AnywhereTS, you do not have currently have administrator privileges (23114)");
744 return false;
745 }
746
747 // Setup managed mode. This can alternatively be set from frmConfigMode, but this form is now disabled
748 // Create Datbase directory
749 string dataDir = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + @"\AnywhereTS";
750 try
751 {
752 Directory.CreateDirectory(dataDir);
753 }
754 catch (Exception ex)
755 {
756 this.Cursor = Cursors.Default;
757 MessageBox.Show("Could not create directory '" + dataDir + "'. Error: " + ex.Message);
758 return false;
759 }
760
761 ATSGlobals.managedMode = 1; // We are running in Managed Mode
762
763 // Save the database directory to registry
764 ProSupport.strDatabasePath = dataDir;
765 ATSGlobals.SetATSRegValue(ProSupport.strRegDatabaseDir, ProSupport.strDatabasePath);
766
767 // Save mode
768 ATSGlobals.SetATSRegValue(ATSGlobals.strRegManagedMode, ATSGlobals.managedMode);
769
770 // Set up database
771 DatabaseSupport dataSupport = new DatabaseSupport();
772 dataSupport.SetupDatabase(); // Creates updates the database if necessary
773
774 DisplayMode: // Configure mode
775 /* The unmanged mode is presently not possible to select
776 using (frmConfigMode objCustomDialogBox = new frmConfigMode())
777 {
778 result = objCustomDialogBox.ShowDialog();
779 }
780 if (result == DialogResult.Cancel)
781 {
782 return false;
783 }
784 */
785
786 DisplayConfig: // Config services
787 if (ATSGlobals.managedMode == 1) // If managed mode
788 {
789 // Show configuration screen for terminal servers, TFTP, DHCP
790 using (frmConfigServices formConfig = new frmConfigServices())
791 {
792 result = formConfig.ShowDialog();
793 }
794 if (result == DialogResult.Cancel)
795 { // Cancel pressed
796 return false;
797 }
798 else if (result == DialogResult.No) // 'No' is used for Back, since there is no DialogResult.Back
799 { // Back pressed
800 goto DisplayMode; // Display the mode window again.
801 }
802
803 // Check if we are going to use the built in DHCP or TFTP server
804 if (ATSGlobals.dhcpConfig == 0 || ATSGlobals.tftpConfig == 0)
805 { // Use built in DHCP server
806 using (frmConfigInternalServices formDHCP = new frmConfigInternalServices())
807 {
808 result = formDHCP.ShowDialog();
809 }
810 if (result == DialogResult.Cancel)
811 {
812 return false;
813 }
814 else if (result == DialogResult.No)
815 {
816 goto DisplayConfig; // Display the server config screen again
817 }
818 }
819 }
820
821 // Configure and start/stop TFTPD32
822 AtsDhcp.ConfigureTFTPD32service(ATSGlobals.tftpConfig == 0, ATSGlobals.dhcpConfig == 0);
823
824 // Configuration completed
825 ATSGlobals.configured = 1; // Indicate that configuration process is completed
826 ATSGlobals.SetATSRegValue(ATSGlobals.strRegConfigured, ATSGlobals.configured); // Save to registry
827 return true;
828 }
829
830 void SetMode()
831 {
832 if (ATSGlobals.managedMode == 1)
833 { // We are running in managed mode, enable all controls related to client administration.
834 lblClientProperties.Enabled = true;
835 lblClientDefaultProperties.Enabled = true;
836 clientToolStripMenuItem.Visible = true;
837 toolStripButtonRefresh.Enabled = true;
838 toolStripButtonAdd.Enabled = true;
839 toolStripButtonProperties.Enabled = true;
840 treeView.Enabled = true;
841 lblNoOfClients.Text = "";
842 lblClientDefaultProperties.Enabled = true;
843 rtxWelcome.Rtf = @"{\rtf1\ansi\ansicpg1252\deff0\deflang1053\deflangfe2052\deftab1304{\fonttbl{\f0\fswiss\fprq2\fcharset0 Arial;}{\f1\froman\fprq2\fcharset0 Times New Roman;}}
844 {\*\generator Msftedit 5.41.21.2500;}\viewkind4\uc1\pard\lang2057\f0\fs16 1. Start creating your thin client solution by making a thin client image that will load onto your client PC:s.\par
845 Select \b Make client image\b0 on the \b MakeClient\b0 menu.\par
846 \par
847 2. Boot your clients and have them connect to one of the terminal servers you registered into AnywhereTS. \par
848 They will then appear in the tree to the left. You can also manually add clients on the \b ManageClients\b0 menu or by using the toolbar or right click in the tree. \par
849 If you want to register more terminal servers, select \b Configure \b0 from the \b Tools\b0 menu.\par
850 \par
851 3. Administer your clients, customise and change settings in the tree to the left and by using the \b ManageClients\b0 menu.\f1\fs24\par
852 }
853 ";
854
855 if (ATSGlobals.runFirstTime == 1)
856 { // This version of the application is run for the first time.
857
858 // Set up database
859 DatabaseSupport dataSupport = new DatabaseSupport();
860 dataSupport.SetupDatabase(); // Creates or updates the database if necessary
861 }
862
863 ProSupport.InitDatabase(); // Create the database connection
864 datasetAllClients = new atsDataSet();
865 datasetLicensedClients = new atsDataSet();
866
867 // Update dataset
868 try
869 {
870 ProSupport.clientTableAdapter.FillClients(datasetAllClients.Client);
871 }
872 catch (Exception ex)
873 {
874 MessageBox.Show("Unhandled SQL error, please restart AnywhereTS. Details: " + ex.Message);
875 Application.Exit();
876 return;
877 }
878
879 if (ATSGlobals.runFirstTime == 1)
880 { // This version of the application is run for the first time.
881
882 // Recreate all config files and hosts file.
883 ProSupport.RecreateConfigFiles();
884
885 // Indicate in registry that all the run first time stuff has been processed and should not be run again for this version.
886 ATSGlobals.SetATSRegValue(ATSGlobals.strRegRunFirstTime, 0);
887
888 SaveMachineNameToDatabase(); // Make sure the machine name is in the database, in order for the control panel to work from version 3.0
889 }
890
891
892 UpdateTree();
893 treeView.Nodes[0].ExpandAll();
894
895 }
896 else if (ATSGlobals.managedMode == 2)
897 { // We are running in unmanaged mode, disable all controls related to client administration.
898 lblClientProperties.Enabled = false;
899 lblClientDefaultProperties.Enabled = false;
900 clientToolStripMenuItem.Visible = false;
901 toolStripButtonRefresh.Enabled = false;
902 toolStripButtonAdd.Enabled = false;
903 toolStripButtonProperties.Enabled = false;
904 treeView.Enabled = false;
905 rtxWelcome.Visible = true;
906 rtxWelcome.Text = "AnywhereTS is running in unmanged mode. You can change mode on the Tools-Configure menu.";
907 lblClientDefaultProperties.Enabled = false;
908 pnlClientSession.Visible = false;
909 pnlDefault.Visible = false;
910 }
911 else
912 {
913 MessageBox.Show("Error, no mode selected (56541)");
914 }
915 }
916
917 private void frmAdmin_Resize(object sender, EventArgs e)
918 {
919 // Adjust the size of the splitter container to fit in the form.
920 splitContainerClient.Height = this.Height - 46; // Make space for the menubar and toolbar
921 splitContainerClient.Width = this.Width;
922 toolStrip1.Width = this.Width;
923 }
924
925 private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
926 {
927 // Display client properties dialog
928 ClientProperties();
929 }
930
931 private void lblClientDefault_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
932 {
933 // Display client default properties dialog
934 ClientDefaultSettings();
935 }
936
937 private void contentsToolStripMenuItem_Click(object sender, EventArgs e)
938 {
939 Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.TableOfContents);
940 }
941
942 private void searchForHelpToolStripMenuItem_Click(object sender, EventArgs e)
943 {
944 Help.ShowHelp(this, ATSGlobals.strHelpFilePath, HelpNavigator.Index);
945 }
946
947 // Save the computer name to database.
948 // Saves the computer name of the current computer, being the one running the admin tool into the database
949 private void SaveMachineNameToDatabase()
950 {
951 string machineName = Environment.MachineName;
952 atsDataSet datasetAppInfo;
953 DataRow row;
954 ProSupport.appInfoTableAdapter = new atsDataSetTableAdapters.AppInfoTableAdapter();
955 datasetAppInfo = new atsDataSet();
956
957 ProSupport.appInfoTableAdapter.Fill(datasetAppInfo.AppInfo);
958
959 // Loook up the row
960 row = datasetAppInfo.AppInfo.Rows.Find("AdminComputer");
961 if (row != null)
962 { // Found row, update
963 row["Value"] = machineName;
964 }
965 else
966 { // Row could not be found
967 // Create a license key row
968 DataRow newRow = datasetAppInfo.AppInfo.NewRow();
969 newRow["Property"] = "AdminComputer";
970 newRow["Value"] = machineName;
971 // Save default row
972 datasetAppInfo.AppInfo.Rows.Add(newRow);
973 }
974 // Save changes
975 ProSupport.appInfoTableAdapter.Update(datasetAppInfo.AppInfo);
976 }
977
978 } // FrmAdmin
979 } // Namespace AnywhereTS
980
981

  ViewVC Help
Powered by ViewVC 1.1.22