Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

451 lines
14 KiB

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using Microsoft.Win32;
  7. using System.Security.Permissions;
  8. namespace OCAReports
  9. {
  10. /// <summary>
  11. /// Summary description for frmLocation.
  12. /// </summary>
  13. public class frmLocation : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.GroupBox groupBox1;
  16. private System.Windows.Forms.Label label1;
  17. private System.Windows.Forms.Label label2;
  18. private Microsoft.VisualBasic.Compatibility.VB6.DriveListBox driveListBox1;
  19. private System.Windows.Forms.Button cmdDone;
  20. private System.Windows.Forms.Button cmdAdd;
  21. private System.Windows.Forms.RadioButton optArchive;
  22. private System.Windows.Forms.RadioButton optWatson;
  23. private System.Windows.Forms.ListBox lstLocations;
  24. private System.Windows.Forms.TextBox txtNetwork;
  25. private System.Windows.Forms.Button cmdRemove;
  26. private System.Windows.Forms.RadioButton rDirectory;
  27. private System.Windows.Forms.RadioButton rPath;
  28. /// <summary>
  29. /// Required designer variable.
  30. /// </summary>
  31. private System.ComponentModel.Container components = null;
  32. public frmLocation()
  33. {
  34. //
  35. // Required for Windows Form Designer support
  36. //
  37. InitializeComponent();
  38. //
  39. // TODO: Add any constructor code after InitializeComponent call
  40. //
  41. }
  42. /// <summary>
  43. /// Clean up any resources being used.
  44. /// </summary>
  45. protected override void Dispose( bool disposing )
  46. {
  47. if( disposing )
  48. {
  49. if(components != null)
  50. {
  51. components.Dispose();
  52. }
  53. }
  54. base.Dispose( disposing );
  55. }
  56. #region Windows Form Designer generated code
  57. /// <summary>
  58. /// Required method for Designer support - do not modify
  59. /// the contents of this method with the code editor.
  60. /// </summary>
  61. private void InitializeComponent()
  62. {
  63. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmLocation));
  64. this.cmdDone = new System.Windows.Forms.Button();
  65. this.cmdAdd = new System.Windows.Forms.Button();
  66. this.groupBox1 = new System.Windows.Forms.GroupBox();
  67. this.optArchive = new System.Windows.Forms.RadioButton();
  68. this.optWatson = new System.Windows.Forms.RadioButton();
  69. this.lstLocations = new System.Windows.Forms.ListBox();
  70. this.label1 = new System.Windows.Forms.Label();
  71. this.label2 = new System.Windows.Forms.Label();
  72. this.driveListBox1 = new Microsoft.VisualBasic.Compatibility.VB6.DriveListBox();
  73. this.txtNetwork = new System.Windows.Forms.TextBox();
  74. this.rDirectory = new System.Windows.Forms.RadioButton();
  75. this.rPath = new System.Windows.Forms.RadioButton();
  76. this.cmdRemove = new System.Windows.Forms.Button();
  77. this.groupBox1.SuspendLayout();
  78. this.SuspendLayout();
  79. //
  80. // cmdDone
  81. //
  82. this.cmdDone.Location = new System.Drawing.Point(440, 16);
  83. this.cmdDone.Name = "cmdDone";
  84. this.cmdDone.TabIndex = 0;
  85. this.cmdDone.Text = "&Done";
  86. this.cmdDone.Click += new System.EventHandler(this.cmdDone_Click);
  87. //
  88. // cmdAdd
  89. //
  90. this.cmdAdd.Location = new System.Drawing.Point(440, 52);
  91. this.cmdAdd.Name = "cmdAdd";
  92. this.cmdAdd.TabIndex = 1;
  93. this.cmdAdd.Text = "&Add";
  94. this.cmdAdd.Click += new System.EventHandler(this.cmdAdd_Click);
  95. //
  96. // groupBox1
  97. //
  98. this.groupBox1.Controls.AddRange(new System.Windows.Forms.Control[] {
  99. this.optArchive,
  100. this.optWatson});
  101. this.groupBox1.Location = new System.Drawing.Point(408, 120);
  102. this.groupBox1.Name = "groupBox1";
  103. this.groupBox1.Size = new System.Drawing.Size(112, 72);
  104. this.groupBox1.TabIndex = 2;
  105. this.groupBox1.TabStop = false;
  106. //
  107. // optArchive
  108. //
  109. this.optArchive.Location = new System.Drawing.Point(16, 48);
  110. this.optArchive.Name = "optArchive";
  111. this.optArchive.Size = new System.Drawing.Size(64, 16);
  112. this.optArchive.TabIndex = 1;
  113. this.optArchive.Text = "Archive";
  114. this.optArchive.CheckedChanged += new System.EventHandler(this.optArchive_CheckedChanged);
  115. //
  116. // optWatson
  117. //
  118. this.optWatson.Checked = true;
  119. this.optWatson.Location = new System.Drawing.Point(16, 16);
  120. this.optWatson.Name = "optWatson";
  121. this.optWatson.Size = new System.Drawing.Size(64, 16);
  122. this.optWatson.TabIndex = 0;
  123. this.optWatson.TabStop = true;
  124. this.optWatson.Text = "Watson";
  125. this.optWatson.CheckedChanged += new System.EventHandler(this.optWatson_CheckedChanged);
  126. //
  127. // lstLocations
  128. //
  129. this.lstLocations.Location = new System.Drawing.Point(240, 48);
  130. this.lstLocations.Name = "lstLocations";
  131. this.lstLocations.Size = new System.Drawing.Size(144, 147);
  132. this.lstLocations.TabIndex = 3;
  133. this.lstLocations.Leave += new System.EventHandler(this.lstLocations_Leave);
  134. this.lstLocations.Enter += new System.EventHandler(this.lstLocations_Enter);
  135. this.lstLocations.SelectedIndexChanged += new System.EventHandler(this.lstLocations_SelectedIndexChanged);
  136. //
  137. // label1
  138. //
  139. this.label1.Location = new System.Drawing.Point(16, 16);
  140. this.label1.Name = "label1";
  141. this.label1.Size = new System.Drawing.Size(120, 24);
  142. this.label1.TabIndex = 4;
  143. this.label1.Text = "Directory";
  144. //
  145. // label2
  146. //
  147. this.label2.Location = new System.Drawing.Point(248, 16);
  148. this.label2.Name = "label2";
  149. this.label2.Size = new System.Drawing.Size(120, 24);
  150. this.label2.TabIndex = 5;
  151. this.label2.Text = "Location:";
  152. //
  153. // driveListBox1
  154. //
  155. this.driveListBox1.Location = new System.Drawing.Point(40, 48);
  156. this.driveListBox1.Name = "driveListBox1";
  157. this.driveListBox1.Size = new System.Drawing.Size(168, 21);
  158. this.driveListBox1.TabIndex = 7;
  159. //
  160. // txtNetwork
  161. //
  162. this.txtNetwork.Location = new System.Drawing.Point(40, 88);
  163. this.txtNetwork.Name = "txtNetwork";
  164. this.txtNetwork.Size = new System.Drawing.Size(168, 20);
  165. this.txtNetwork.TabIndex = 8;
  166. this.txtNetwork.Text = "";
  167. this.txtNetwork.KeyUp += new System.Windows.Forms.KeyEventHandler(this.txtNetwork_KeyUp);
  168. this.txtNetwork.Enter += new System.EventHandler(this.txtNetwork_Enter);
  169. //
  170. // rDirectory
  171. //
  172. this.rDirectory.Checked = true;
  173. this.rDirectory.Location = new System.Drawing.Point(16, 48);
  174. this.rDirectory.Name = "rDirectory";
  175. this.rDirectory.Size = new System.Drawing.Size(16, 16);
  176. this.rDirectory.TabIndex = 10;
  177. this.rDirectory.TabStop = true;
  178. //
  179. // rPath
  180. //
  181. this.rPath.Location = new System.Drawing.Point(16, 88);
  182. this.rPath.Name = "rPath";
  183. this.rPath.Size = new System.Drawing.Size(16, 16);
  184. this.rPath.TabIndex = 1;
  185. this.rPath.CheckedChanged += new System.EventHandler(this.rPath_CheckedChanged);
  186. //
  187. // cmdRemove
  188. //
  189. this.cmdRemove.Location = new System.Drawing.Point(440, 88);
  190. this.cmdRemove.Name = "cmdRemove";
  191. this.cmdRemove.TabIndex = 11;
  192. this.cmdRemove.Text = "&Remove";
  193. this.cmdRemove.Click += new System.EventHandler(this.cmdRemove_Click);
  194. //
  195. // frmLocation
  196. //
  197. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  198. this.ClientSize = new System.Drawing.Size(536, 206);
  199. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  200. this.rDirectory,
  201. this.txtNetwork,
  202. this.driveListBox1,
  203. this.label2,
  204. this.label1,
  205. this.lstLocations,
  206. this.groupBox1,
  207. this.cmdAdd,
  208. this.cmdDone,
  209. this.rPath,
  210. this.cmdRemove});
  211. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  212. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  213. this.MaximizeBox = false;
  214. this.MinimizeBox = false;
  215. this.Name = "frmLocation";
  216. this.Text = "Locate directories to search";
  217. this.Load += new System.EventHandler(this.frmLocation_Load);
  218. this.groupBox1.ResumeLayout(false);
  219. this.ResumeLayout(false);
  220. }
  221. #endregion
  222. private void cmdAdd_Click(object sender, System.EventArgs e)
  223. {
  224. AddToList();
  225. }
  226. private void lstLocations_SelectedIndexChanged(object sender, System.EventArgs e)
  227. {
  228. }
  229. private void lstLocations_Enter(object sender, System.EventArgs e)
  230. {
  231. }
  232. private void lstLocations_Leave(object sender, System.EventArgs e)
  233. {
  234. }
  235. private void cmdRemove_Click(object sender, System.EventArgs e)
  236. {
  237. RegistryKey reg;
  238. if(optArchive.Checked == true)
  239. {
  240. reg = Registry.CurrentUser.OpenSubKey("software").OpenSubKey("microsoft", true).CreateSubKey("OCATools").CreateSubKey("OCAReports").CreateSubKey("Archive");
  241. }
  242. else
  243. {
  244. reg = Registry.CurrentUser.OpenSubKey("software").OpenSubKey("microsoft", true).CreateSubKey("OCATools").CreateSubKey("OCAReports").CreateSubKey("Watson");
  245. }
  246. int x = 0;
  247. // RegistryPermission f = new RegistryPermission(RegistryPermissionAccess.Read | RegistryPermissionAccess.Write,
  248. // "HKEY_CURRENT_USER\\Software\\Microsoft\\OCATools\\OCAReports\\Watson");
  249. // f.AddPathList(RegistryPermissionAccess.Write | RegistryPermissionAccess.Read | RegistryPermissionAccess.Write,
  250. // "HKEY_CURRENT_USER\\Software\\Microsoft\\OCATools\\OCAReports\\Watson");
  251. if(lstLocations.SelectedIndex > -1)
  252. {
  253. lstLocations.Items.Remove(lstLocations.SelectedItem);
  254. }
  255. for(x = 0;x < 5; x++)
  256. {
  257. reg.SetValue("Loc" + x.ToString(), "");
  258. }
  259. for(x = 0;x < lstLocations.Items.Count; x++)
  260. {
  261. reg.SetValue("Loc" + x.ToString(), lstLocations.Items[x].ToString());
  262. }
  263. }
  264. private void cmdDone_Click(object sender, System.EventArgs e)
  265. {
  266. this.Close();
  267. }
  268. private void txtNetwork_Enter(object sender, System.EventArgs e)
  269. {
  270. rPath.Checked = true;
  271. }
  272. private void txtNetwork_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
  273. {
  274. if(e.KeyCode == System.Windows.Forms.Keys.Enter)
  275. {
  276. AddToList();
  277. }
  278. }
  279. private void AddToList()
  280. {
  281. string sDrive;
  282. int x = 0;
  283. bool bolFound = false;
  284. string[] strWatson = new string[5];
  285. RegistryKey reg;
  286. if(optArchive.Checked == true)
  287. {
  288. reg = Registry.CurrentUser.OpenSubKey("software").OpenSubKey("microsoft", true).CreateSubKey("OCATools").CreateSubKey("OCAReports").CreateSubKey("Archive");
  289. }
  290. else
  291. {
  292. reg = Registry.CurrentUser.OpenSubKey("software").OpenSubKey("microsoft", true).CreateSubKey("OCATools").CreateSubKey("OCAReports").CreateSubKey("Watson");
  293. }
  294. if(lstLocations.Items.Count >= 11)
  295. {
  296. MessageBox.Show("The maximum drives is 10", "Cannot add drive", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  297. return;
  298. }
  299. if(rDirectory.Checked == true)
  300. {
  301. sDrive = driveListBox1.Drive.ToString();
  302. sDrive = sDrive.Substring(0, 1);
  303. sDrive = sDrive + ":\\";
  304. for(x = 0; x < lstLocations.Items.Count;x++)
  305. {
  306. if(sDrive == lstLocations.Items[x].ToString())
  307. {
  308. bolFound = true;
  309. }
  310. }
  311. if(bolFound == false)
  312. {
  313. lstLocations.Items.Add(sDrive);
  314. }
  315. else
  316. {
  317. MessageBox.Show("This item already exist in the listbox", "Cannot add drive", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  318. }
  319. }
  320. if(rPath.Checked == true)
  321. {
  322. sDrive = txtNetwork.Text;
  323. for(x = 0; x < lstLocations.Items.Count;x++)
  324. {
  325. if(sDrive == lstLocations.Items[x].ToString())
  326. {
  327. bolFound = true;
  328. }
  329. }
  330. if(bolFound == false)
  331. {
  332. lstLocations.Items.Add(sDrive);
  333. }
  334. else
  335. {
  336. MessageBox.Show("This item already exist in the listbox", "Cannot add drive", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
  337. }
  338. txtNetwork.Focus();
  339. txtNetwork.SelectAll();
  340. }
  341. for(x = 0;x < 10; x++)
  342. {
  343. reg.SetValue("Loc" + x.ToString(), "");
  344. }
  345. for(x = 0;x < lstLocations.Items.Count; x++)
  346. {
  347. reg.SetValue("Loc" + x.ToString(), lstLocations.Items[x].ToString());
  348. }
  349. }
  350. private void rPath_CheckedChanged(object sender, System.EventArgs e)
  351. {
  352. if(rPath.Checked == true)
  353. {
  354. txtNetwork.Focus();
  355. }
  356. }
  357. private void frmLocation_Load(object sender, System.EventArgs e)
  358. {
  359. int x = 0;
  360. RegistryKey reg = Registry.CurrentUser.OpenSubKey("software").OpenSubKey("microsoft", true).CreateSubKey("OCATools").CreateSubKey("OCAReports").CreateSubKey("Watson");
  361. for(x = 0;x < 10; x++)
  362. {
  363. try
  364. {
  365. if(reg.GetValue("Loc" + x.ToString()).ToString().Length > 0)
  366. {
  367. lstLocations.Items.Add(reg.GetValue("Loc" + x.ToString()));
  368. }
  369. }
  370. catch
  371. {
  372. x = 10;
  373. }
  374. }
  375. }
  376. private void optWatson_CheckedChanged(object sender, System.EventArgs e)
  377. {
  378. int x = 0;
  379. lstLocations.Items.Clear();
  380. RegistryKey reg = Registry.CurrentUser.OpenSubKey("software").OpenSubKey("microsoft", true).CreateSubKey("OCATools").CreateSubKey("OCAReports").CreateSubKey("Watson");
  381. for(x = 0;x < 5; x++)
  382. {
  383. try
  384. {
  385. if(reg.GetValue("Loc" + x.ToString()).ToString().Length > 0)
  386. {
  387. lstLocations.Items.Add(reg.GetValue("Loc" + x.ToString()));
  388. }
  389. }
  390. catch
  391. {
  392. x = 10;
  393. }
  394. }
  395. }
  396. private void optArchive_CheckedChanged(object sender, System.EventArgs e)
  397. {
  398. int x = 0;
  399. lstLocations.Items.Clear();
  400. RegistryKey reg = Registry.CurrentUser.OpenSubKey("software").OpenSubKey("microsoft", true).CreateSubKey("OCATools").CreateSubKey("OCAReports").CreateSubKey("Archive");
  401. for(x = 0;x < 10; x++)
  402. {
  403. try
  404. {
  405. if(reg.GetValue("Loc" + x.ToString()).ToString().Length > 0)
  406. {
  407. lstLocations.Items.Add(reg.GetValue("Loc" + x.ToString()));
  408. }
  409. }
  410. catch
  411. {
  412. x = 10;
  413. }
  414. }
  415. }
  416. }
  417. }