PC_Spy_Menu_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: PC Spy Menu
    8| 
    9| Note: MDI stands for MultiDocument Interface
  10| 
  11| 

  12| Maintenance Log:
  13| By:Date:Change:
  14| Keith Gallistel10/06/08-started project
  15|  -added list box
  16|  -added Select a Database Button
  17|  -added Select Parameters Button
  18|  -added necessary code for buttons and list box
  19|  -added Parameter Class
  20|  
  21| Keith Gallistel10/13/08-added Get PC Spy Info Program's Location Button
  22|  -added Run PC_Spy_Info Program button
  23|  -added code to use these buttons
  24|  
  25| Keith Gallistel10/20/08-connected to PC Spy Info Program to pass a database location
  26|  -added Exit Button and programmed it
  27|  -added Date/Time Sort Button
  28|  -added ID/Date/Time Sort Button
  29|  
  30| Keith Gallistel11/03/08-added PC Spy Report Program Button
  31| */

  32| 
  33| 
  34| using System;
  35| using System.Collections.Generic;
  36| using System.ComponentModel;
  37| using System.Data;
  38| using System.Drawing;
  39| using System.Linq;
  40| using System.Text;
  41| using System.Windows.Forms;
  42| 
  43| //add references
  44| using Open_File_Dialog;
  45| using System.Collections;
  46| using DB_Interface_DLL;
  47| 
  48| namespace PC_SPY_Menu
  49| {
  50|     public partial class PC_Spy_Menu_Form : Form
  51|     {
  52|         //Delcare an object
  53|         Parameter_Class oPC;
  54| 
  55|         //Declare Grid MDI
  56|         Grid_View_Form oGrid;
  57| 
  58|         public PC_Spy_Menu_Form()
  59|         {
  60|             InitializeComponent();
  61| 
  62|             Load_Drive_Roots();
  63| 
  64|             //Instantiate an object
  65|             oPC = new Parameter_Class();
  66|         }
  67| 
  68|         //Load the root drives into the list box
  69|         private void Load_Drive_Roots()
  70|         {
  71|             ArrayList oDriveRootList;
  72| 
  73|             oDriveRootList = Open_File_Dialog.OFD_Class.oFD_Get_Drive_Roots();
  74| 
  75|             foreach (string sRoot in oDriveRootList)
  76|             {
  77|                 lbxDrives.Items.Add(sRoot);
  78|             }
  79| 
  80|         }
  81| 
  82|         private void lbxDrives_SelectedIndexChanged(object sender, EventArgs e)
  83|         {
  84|             string sUserSelection = "";
  85| 
  86|             //Get the user's drive root selection
  87|             sUserSelection = lbxDrives.GetItemText(lbxDrives.SelectedItem);
  88| 
  89|             //Call a method to access/set the object's private attribute
  90|             oPC.Set_sDriveRoot(sUserSelection);
  91| 
  92|             this.Text = sUserSelection;
  93|         }
  94| 
  95|         private void btnGetDatabase_Click(object sender, EventArgs e)
  96|         {
  97|             const string sDatabase_File_ID = "dbPC_Spy.mdb";
  98|             string sDatabase = "";
  99| 
100|             //Call the method to retrieve the file
101|             sDatabase = Get_File(sDatabase_File_ID);
102| 
103|             //Process the user selection
104|             if (!sDatabase.Equals(""))
105|             {
106|                 oPC.Set_Database_Location(sDatabase);
107|                 this.Text += "-" + sDatabase;
108|             }
109|         }
110| 
111|         private void btnGetParameters_Click(object sender, EventArgs e)
112|         {
113|             string sMessage = "";
114| 
115|             sMessage = "Drive " + oPC.Get_sDriveRoot() + "\n";
116|             sMessage += "Database Location: " + oPC.Get_Database_Location();
117| 
118|             MessageBox.Show(sMessage);
119|         }
120| 
121|         private void btnPCSpyInfo_Click(object sender, EventArgs e)
122|         {
123|             const string sPC_Spy_Info_File_ID = "PC_Spy_Info.exe";
124|             string sPC_Spy_Info = "";
125| 
126|             //Call the method to retrieve the file
127|             sPC_Spy_Info = Get_File(sPC_Spy_Info_File_ID);
128| 
129|             //Process the user selection
130|             if (!sPC_Spy_Info.Equals(""))
131|             {
132|                 oPC.Set_PC_Spy_Information(sPC_Spy_Info);
133|                 this.Text += "-" + sPC_Spy_Info;
134|                 btnPCSpyInfo.Text = sPC_Spy_Info;
135|             }
136|         }
137| 
138|         private string Get_File(string sFile_Name)
139|         {
140|             ArrayList oFileList;
141|             bool bOK = true;
142|             string sFile_Selected = "";
143| 
144|             //Call the dll method to get a database file selection
145| 
146|             oFileList = Open_File_Dialog.OFD_Class.OFD_Get_Files(oPC.Get_sDriveRoot(), false, "Select the " + sFile_Name + " File.");
147| 
148|             //Did user select one file?
149|             if (oFileList.Count != 1)
150|             {
151|                 bOK = false;
152|                 sFile_Selected = "";
153|                 MessageBox.Show("You must select ONE file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
154|             }
155| 
156|             //Retrieve the user's selection
157|             if (bOK)
158|             {
159|                 foreach (string sFile in oFileList)
160|                 {
161|                     sFile_Selected = sFile;
162|                     break;
163|                 }
164|             }
165| 
166|             //Did the user select the correct file?
167|             if (bOK)
168|             {
169|                 if (!sFile_Selected.EndsWith(sFile_Name))
170|                 {
171|                     MessageBox.Show("You must select the " + sFile_Name + " file.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
172|                    bOK = false;
173|                     sFile_Selected = "";
174|                 }
175|             }
176| 
177|             return sFile_Selected;
178|         }//end of method
179| 
180|         //Runs PC_Spy_Info and passes database location
181|         private void btnRunPCSpyInfo_Click(object sender, EventArgs e)
182|         {
183|             string sPC_Spy_Info = "";
184|             //string sDatabase_Location = "";
185| 
187|             //Gets information from Parameter_Class
188|             sPC_Spy_Info = oPC.Get_PC_Spy_Information();
189|             //sDatabase_Location = oPC.Get_Database_Location();
190| 
191|             if (!sPC_Spy_Info.Equals(""))
192|             {
193|                 //Does the actual activation of PC_Spy_Info and actual database location passing.
194|                 System.Diagnostics.Process.Start(sPC_Spy_Info/*, sDatabase_Location*/);
195|             }
196|             else
197|             {
198|                 MessageBox.Show("You must select the PC_Spy_Info program first.");
199|             }
200| 
201|         }
202| 
203|         private void bntExit_Click(object sender, EventArgs e)
204|         {
205|             Application.Exit();
206|         }
207| 
208|         private void btnSortD_T_Click(object sender, EventArgs e)
209|         {
210|             string sQuery = "SELECT * FROM tblUser_Information ORDER BY fldFormattedDate, fldMilitaryTime";
211| 
212|             Query_Block(sQuery);
213| 
214|         }
215| 
216|         private void btnSortID_D_T_Click(object sender, EventArgs e)
217|         {
218|             string sQuery = "SELECT * FROM tblUser_Information ORDER BY fldUserID, fldFormattedDate, fldMilitaryTime";
219| 
220|             Query_Block(sQuery);
221|         }
222| 
224|         private void Query_Block(string sQuery)
225|         {
226|             DB_Interface_DLL.DB_Interface_DLL_Class oDB = new DB_Interface_DLL.DB_Interface_DLL_Class();
227| 
228|             oDB.OpenDB(oPC.Get_Database_Location());
229| 
230|             oDB.ReQuery(sQuery);
231| 
232|             oGrid = new Grid_View_Form(DB_Interface_DLL_Class.sTableName);
233|             oGrid.Show();
234| 
235|         }
236| 
237|         private void btnPCSpyReport_Click(object sender, EventArgs e)
238|         {
239|             string sPC_Spy_Reports = "E:\\CS Prog 2\\Class_6to8\\PC_Spy_System\\exe\\PC_Spy_Reports.exe";
240| 
241|             System.Diagnostics.Process.Start(sPC_Spy_Reports);
242|         }
243| 
244|     }//end of class
245| }