Click here to Skip to main content
15,899,314 members
Home / Discussions / C#
   

C#

 
QuestionNeed Advice about Inserting Pin
soulidentities18-Mar-09 9:00
soulidentities18-Mar-09 9:00 
AnswerRe: Need Advice about Inserting [modified] Pin
fly90418-Mar-09 9:16
fly90418-Mar-09 9:16 
GeneralRe: Need Advice about Inserting Pin
soulidentities18-Mar-09 9:18
soulidentities18-Mar-09 9:18 
GeneralRe: Need Advice about Inserting Pin
fly90418-Mar-09 9:36
fly90418-Mar-09 9:36 
GeneralRe: Need Advice about Inserting Pin
soulidentities18-Mar-09 9:43
soulidentities18-Mar-09 9:43 
QuestionOutlook Macro/Addon Pin
partialdata18-Mar-09 8:58
partialdata18-Mar-09 8:58 
QuestionWhat's better : SmartCard or CardSpace ? [modified] Pin
hdv21218-Mar-09 8:35
hdv21218-Mar-09 8:35 
QuestionHelp cleaning up C# Code (WMI code) - Neewbie Pin
Buck_Murdock18-Mar-09 8:19
Buck_Murdock18-Mar-09 8:19 
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");

            ManagementObjectSearcher searcherAudio =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_SoundDevice");

            ManagementObjectSearcher searcherNIC =
                    new ManagementObjectSearcher("root\\CIMV2",
                    "SELECT * FROM Win32_NetworkAdapter");

            //Display Audio Controller Information
            foreach (ManagementObject queryObj in searcherAudio.Get())
            {
                string audioController = queryObj["Name"].ToString();

                // Create an XPathNavigator to walk the main data source
                // of the form.
                XPathNavigator xnMyForm = this.CreateNavigator();
                XmlNamespaceManager ns = this.NamespaceManager;

                xnMyForm.SelectSingleNode("/my:myFields/my:SoundCard", ns).SetValue(audioController);
            }

            //Display Video Controller Information
            foreach (ManagementObject queryObj in searcherDisplay.Get())
            {
                string displayAdapter = queryObj["Name"].ToString();

                // Create an XPathNavigator to walk the main data source
                // of the form.
                XPathNavigator xnMyForm = this.CreateNavigator();
                XmlNamespaceManager ns = this.NamespaceManager;

                xnMyForm.SelectSingleNode("/my:myFields/my:VideoAdapter", ns).SetValue(displayAdapter);
            }
        }
    }
}

QuestionForeignKeyConstraint requires the child key values to exist in the parent table! Pin
Lodeclaw18-Mar-09 8:17
Lodeclaw18-Mar-09 8:17 
AnswerRe: ForeignKeyConstraint requires the child key values to exist in the parent table! Pin
Fayu18-Mar-09 9:58
Fayu18-Mar-09 9:58 
AnswerRe: ForeignKeyConstraint requires the child key values to exist in the parent table! Pin
Matt Graham24-Mar-11 7:44
Matt Graham24-Mar-11 7:44 
QuestionDatagridview cell painting Pin
Dan Neely18-Mar-09 8:11
Dan Neely18-Mar-09 8:11 
AnswerRe: Datagridview cell painting Pin
Henry Minute19-Mar-09 7:18
Henry Minute19-Mar-09 7:18 
GeneralRe: Datagridview cell painting Pin
Dan Neely19-Mar-09 8:02
Dan Neely19-Mar-09 8:02 
GeneralRe: Datagridview cell painting Pin
Henry Minute19-Mar-09 11:41
Henry Minute19-Mar-09 11:41 
GeneralRe: Datagridview cell painting Pin
Dan Neely20-Mar-09 5:36
Dan Neely20-Mar-09 5:36 
GeneralRe: Datagridview cell painting Pin
Henry Minute20-Mar-09 9:50
Henry Minute20-Mar-09 9:50 
GeneralRe: Datagridview cell painting Pin
Dan Neely20-Mar-09 10:12
Dan Neely20-Mar-09 10:12 
GeneralRe: Datagridview cell painting Pin
Henry Minute20-Mar-09 10:18
Henry Minute20-Mar-09 10:18 
AnswerRe: Datagridview cell painting Pin
Jake Myers29-Apr-09 22:34
Jake Myers29-Apr-09 22:34 
GeneralRe: Datagridview cell painting Pin
Dan Neely30-Apr-09 8:41
Dan Neely30-Apr-09 8:41 
GeneralRe: Datagridview cell painting Pin
Jake Myers1-May-09 4:20
Jake Myers1-May-09 4:20 
GeneralRe: Datagridview cell painting Pin
Dan Neely1-May-09 4:37
Dan Neely1-May-09 4:37 
GeneralRe: Datagridview cell painting [modified] Pin
Jake Myers1-May-09 5:06
Jake Myers1-May-09 5:06 
QuestionUnlocking account in AD Pin
Jacob Dixon18-Mar-09 7:53
Jacob Dixon18-Mar-09 7:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.