Help cleaning up C# Code (WMI code) - Neewbie
-
I'm not a programmer by any measure so I'm turning to you all for help. I'm creating an InfoPath form which is housing some C# code to run WMI queries when the form is entered. The user will then enter in a few bits of information about them self and submit the form to a SharePoint library to help keep track of our users inventory. My question is can someone help me clean up this code before i get too far into it? I've been using the WMI Code Creator from Microsoft's Website to get the code samples and by brut force I've gotten them to start to pull the information i'm looking for, but the code seems a little ugly and messy for me. I'm sure there has to be a way to condense some of this code and make it easier to manage and i want to start to figure that out before i get too far, once I see how it's done I should be able to figure it out from there. My code sample just has the video card and the sound card query, but eventually i'll have RAM, Hard drive, CPU, etc. Code Sample:
using Microsoft.Office.InfoPath;
using System;
using System.Xml;
using System.Xml.XPath;
using System.Management;
//using System.Windows.Forms;namespace Inventory_Rev1
{
public partial class FormCode
{
// Member variables are not supported in browser-enabled forms.
// Instead, write and read these values from the FormState
// dictionary using code such as the following:
//
// private object _memberVariable
// {
// get
// {
// return FormState["_memberVariable"];
// }
// set
// {
// FormState["_memberVariable"] = value;
// }
// }// NOTE: The following procedure is required by Microsoft Office InfoPath. // It can be modified using Microsoft Office InfoPath. public void InternalStartup() { EventManager.FormEvents.Loading += new LoadingEventHandler(FormEvents\_Loading); } public void FormEvents\_Loading(object sender, LoadingEventArgs e) { ManagementObjectSearcher searcherRAM = new ManagementObjectSearcher("root\\\\CIMV2", "SELECT \* FROM Win32\_PhysicalMemory"); //ManagementObjectCollection oReturnCollection = searcher.Get(); ManagementObjectSearcher searcherDisplay = new ManagementObjectSearcher("root\\\\CIMV2", "SELECT \* FROM Win32\_VideoController