MyDesktop_Form

    1| /*
    2| NTC C# II Programming 152-124
    3| Instructor: John Heckendorf
    4| Student: Keith Gallistel
    5| Lab ID: <35176>
    6| 
    7| Project Name: My Desktop Launch Menu
    8| 
    9| Purpose: Allow a user to lauch favorite applications, drives, and websites from a menu
  10|     on the desktop.
  11| */
  12| 
  13| using System;
  14| using System.Collections.Generic;
  15| using System.ComponentModel;
  16| using System.Data;
  17| using System.Drawing;
  18| using System.Linq;
  19| using System.Text;
  20| using System.Windows.Forms;
  21| 
  22| //add references
  23| using DLL_User_ID;
  24| 
  25| namespace MyDesktop
  26| {
  27|     public partial class MyDesktop_Form : Form
  28|     {
  29|         string sUser_ID = "";
  30|         string sXML_Drives_Location = "";
  31|         string sXML_Apps_Location = "";
  32|         string sXML_Sites_Location = "";
  33| 
  34|         public bool bPass = false;
  35|         frmPassword oFP;
  36| 
  37|         //First time switches
  38|         bool bFirst_Drive_Read = true;
  39|         bool bFirst_App_Read = true;
  40|         bool bFirst_Site_Read = true;
  41| 
  42|         //Declare an array of objects in the User_Class
  43|         User_Class[] oUser;
  44|         Drives_Class[] oDrive;
  45|         Apps_Class[] oApp;
  46|         Sites_Class[] oSite;
  47| 
  48|         public MyDesktop_Form()
  49|         {
  50|             InitializeComponent();
  51| 
  52|             oFP = new frmPassword();
  53| 
  54|             //instantiate class
  55| 
  56|             DLL_User_ID_Class oUserID = new DLL_User_ID_Class();
  57| 
  58|             sUser_ID = oUserID.Get_User_ID();
  59| 
  60|             this.Text = "Menu for " + sUser_ID;
  61| 
  62|             Read_User_XML_File();
  63| 
  64|             //ID and retrieve logged in user's parameters
  65|             Get_Logged_User();
  66| 
  67|             rbnDrives.Checked = true;
  68|         }
  69| 
  70|     private void Read_User_XML_File()
  71|     {
  72|         Read_User_XML_Parameters_Class oRUXP = new Read_User_XML_Parameters_Class();
  73| 
  74|         User_Class.iNextObj = 0;
  75| 
  76|         if (oRUXP.Parameter_File_Exist())
  77|         {
  78|             if (oRUXP.Open_XML_Parameter_File())
  79|             {
  80|                 oRUXP.Read_User_Nodes();
  81|                 oUser = oRUXP.oUser;
  82|             }
  83|             else
  84|             {
  85|                 MessageBox.Show("The parameter file cannot be opened", "Error", MessageBoxButtons.OK,
  86|                 MessageBoxIcon.Error);
  87|                 //perform any other tasks here
  88|             }
  89|         }
  90|         else
  91|         {
  92|             MessageBox.Show ("MyDesktop_Users.xml does not exist", "Error", MessageBoxButtons.OK,
  93|               MessageBoxIcon.Error);
  94| 
  95|             //perform any other tasks here
  96|         }
  97|     }
  98| 
  99|     //find out what user is logged in and get the parameter file for this user
100|     private void Get_Logged_User()
101|     {
102|         bool bHit = false;
103| 
104|         DLL_User_ID_Class oUI = new DLL_User_ID_Class();
105| 
106|         string sLogged_User = oUI.Get_User_ID();
107| 
108|         for (int x = 0; x < User_Class.iNextObj; x++)
109|         {
110|             if (oUser[x].Get_UserID().Equals(sLogged_User))
111|             {
112|                 sXML_Drives_Location = oUser[x].Get_Drives();
113|                 sXML_Apps_Location = oUser[x].Get_Apps();
114|                 sXML_Sites_Location = oUser[x].Get_Sites();
115|                 bHit = true;
116|                 break;
117|             }
118|         }
119| 
120|         if (!bHit)
121|         {
122|             MessageBox.Show("No User Parameter Files Found.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
123|             sXML_Drives_Location = "";
124|         }
125| 
126|         //MessageBox.Show(sXML_Drives_Location, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
127|     }
128| 
129|     private void rbnDrives_Checked()
130|     {
131|         bool bRead = false;
132| 
133|         //garbage collect after the first read
134|         if (!bFirst_Drive_Read)
135|         {
136|             Destroy_Class oDC = new Destroy_Class();
137|             oDC.Destroy_Drive_Objects(oDrive);
138|         }
139| 
140|         //Declare an object
141|         Read_XML_Drives_Class oRXDC;
142| 
143|         Drives_Class.iNextDriveObj = 0;
144| 
145|         if (!sXML_Drives_Location.Equals(""))
146|         {
147|             //Instantiate an object
148|             oRXDC = new Read_XML_Drives_Class(sXML_Drives_Location);
149| 
150|             if (oRXDC.Parameter_File_Exist())
151|             {
152|                 if (oRXDC.Open_XML_Parameter_File())
153|                 {
154|                     oRXDC.Read_Drive_Nodes();
155|                     oDrive = oRXDC.oDrive;
156|                     bFirst_Drive_Read = false;
157|                     Load_ListBox_Class.Load_ListBox_Drives(lbxItems, oDrive);
158|                     bRead = true;
159|                 }
160|  161|             }
162|         }
163|         if(!bRead)
164|         {
165|             MessageBox.Show("Drives Parameter File doesn't exist.\nProgram will abort.");
166|             //Application.Exit();
167|         }
168| 
169|     } 170|  171|     private void rbnApps_Checked()
172|     {
173|         bool bRead = false;
174| 
175|         //garbage collect after the first read
176|         if (!bFirst_App_Read)
177|         {
178|             Destroy_Class oDC = new Destroy_Class();
179|             oDC.Destroy_App_Objects(oApp);
180|         }
181| 
182|         //Declare an object
183|         Read_XML_Apps_Class oRXAC;
184| 
185|         Apps_Class.iNextAppObj = 0;
186| 
187|         if (!sXML_Apps_Location.Equals(""))
188|         {
189|             //Instantiate an object
190|             oRXAC = new Read_XML_Apps_Class(sXML_Apps_Location);
191| 
192|                 if (oRXAC.Parameter_File_Exist())
193|                 {
194|                     if (oRXAC.Open_XML_Parameter_File())
195|                     {
196|                         oRXAC.Read_Drive_Nodes();
197|                         oApp = oRXAC.oApp;
198|                         bFirst_App_Read = false;
199|                     Load_ListBox_Class.Load_ListBox_Apps(lbxItems, oApp);
200|                         bRead = true;
201|                     }
202| 
203|                 }
204|             }
205|             if (!bRead)
206|             {
207|                 MessageBox.Show("Apps Parameter File doesn't exist.\nProgram will abort.");
208|                 //Application.Exit();
209|             }
210| 
211|         }
212| 
213|         private void rbnSites_Checked()
214|         {
215|             bool bRead = false;
216| 
217|             //garbage collect after the first read
218|             if (!bFirst_Site_Read)
219|             {
220|                 Destroy_Class oDC = new Destroy_Class();
221|             oDC.Destroy_Site_Objects(oSite);
222|             }
223| 
224|             //Declare an object
225|             Read_XML_Sites_Class oRXSC;
226| 
227|             Sites_Class.iNextSiteObj = 0;
228| 
229|             if (!sXML_Sites_Location.Equals(""))
230|             {
231|                 //Instantiate an object
232|                 oRXSC = new Read_XML_Sites_Class(sXML_Sites_Location);
233| 
234|                 if (oRXSC.Parameter_File_Exist())
235|                 {
236|                     if (oRXSC.Open_XML_Parameter_File())
237|                     {
238|                         oRXSC.Read_Drive_Nodes();
239|                         oSite = oRXSC.oSite;
240|                     bFirst_Site_Read = false;
241|                     Load_ListBox_Class.Load_ListBox_Sites(lbxItems, oSite);
242|                     bRead = true;
243|                     }
244| 
245|                 }
246|             }
247|             if (!bRead)
248|             {
249|                 MessageBox.Show("Sites Parameter File doesn't exist.\nProgram will abort.");
250|                 //Application.Exit();
251|             }
252|         }
253| 
254|         //one click event for all buttons
255|         private void rbnButtons_Click(object sender, EventArgs e)
256|         {
257|             //Made changes in MyDesktop_Form.Designer.cs
258|             if (rbnDrives.Checked)
259|             {
260|                 rbnDrives_Checked();
261|             }
262| 
263|             if (rbnApps.Checked)
264|             {
265|                 rbnApps_Checked();
266|             }
267| 
268|             if (rbnSites.Checked)
269|             {
270|                 rbnSites_Checked();
271|             }
272|         }
273| 
274|         private void lbxItems_SelectedIndexChanged(object sender, EventArgs e)
275|         {
276|             //int iIndex = lbxItems.SelectedIndex;
277| 
278|             if (rbnDrives.Checked)
279|             {
280|                 Launch_Programs_Class oLaunch = new Launch_Programs_Class();
281|                 oLaunch.Launch_Drive(oDrive, lbxItems.SelectedIndex);
282|                 // MessageBox.Show(oDrive[iIndex].Get_Path());
283|             }
284| 
285|             if (rbnApps.Checked)
286|             {
287|                 Launch_Programs_Class oLaunch = new Launch_Programs_Class();
288|                 oLaunch.Launch_App(oApp, lbxItems.SelectedIndex);
289|                 // MessageBox.Show(oApp[iIndex].Get_Path());
290|             }
291| 
292|             if (rbnSites.Checked)
293|             {
294|                 if (oSite[lbxItems.SelectedIndex].Get_Password().Equals("yes"))
295|                 {
296|                     if (!bPass)
297|                     {
298|                         oFP.Set_Up(this);
299|                         oFP.Show();
300|                     }
301|                     else
302|                     {
303|                         Launch_Site();
304|                     }
305|                 }
306|                 else
307|                 {
308|                     Launch_Site();
309|                 }
310|             }
311|         }
312| 
313|         public void Launch_Site()
314|         {
315|             Launch_Programs_Class oLaunch = new Launch_Programs_Class();
316|             oLaunch.Launch_Site(oSite, lbxItems.SelectedIndex);
317|         }
318| 
319|     }//end of class
320| }