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

Annotation of /trunk/TSAdminTool/frmAdmin.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 63 - (hide annotations) (download)
Thu Jul 12 18:17:31 2012 UTC (8 years, 7 months ago) by william
File size: 43308 byte(s)
DeleteClient(): make sure to log if mac address cannot be found and show a messagebox

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

  ViewVC Help
Powered by ViewVC 1.1.22