TheSwamp

Code Red => .NET => Topic started by: Kerry on November 19, 2007, 06:53:05 AM

Title: XML_ConsoleApplication_001
Post by: Kerry on November 19, 2007, 06:53:05 AM
Had a play tonight ..

DrivePath added:
Save as C:\ProjectStart.XML
Code: [Select]
<?xml version="1.0" encoding="utf-8" ?>
<ProjectList>
<LastProject>J1002</LastProject>
<Project>
    <ProjectID>1001</ProjectID>
    <ProjectNumber>J1001</ProjectNumber>
    <ProjectName>ALPHA</ProjectName>
    <ClientName>Us and Them</ClientName>   
    <JobServer> \\\\Screamer\Drive D\TestProjects</JobServer>     
    <JobSubstDrive>W:</JobSubstDrive>   
    <JobFolder> \J1001</JobFolder>
    <TSDFolder>\TSD</TSDFolder>   
     <StdConsSubstDrive>V:</StdConsSubstDrive>   
    <StdConsFolder>\V-Drive\V-Std</StdConsFolder>     
</Project>
<Project>
    <ProjectID>1002</ProjectID>
    <ProjectNumber>J1002</ProjectNumber>
    <ProjectName>BRAVO</ProjectName>
    <ClientName>Them and Co.</ClientName>
    <JobSubstDrive>W:</JobSubstDrive>
    <JobServer> \\\\Screamer\Drive D\TestProjects</JobServer>   
    <JobFolder> \J1002</JobFolder>
    <TSDFolder>\TSD</TSDFolder>   
    <StdConsSubstDrive>V:</StdConsSubstDrive>     
    <StdConsFolder>\V-Drive\V-Std</StdConsFolder>     
</Project>
<Project>
    <ProjectID>1003</ProjectID>
    <ProjectNumber>J1003</ProjectNumber>
    <ProjectName>CHARLIE</ProjectName>
    <ClientName>Bloggs and Assoc</ClientName>
     <JobSubstDrive>W:</JobSubstDrive>
    <JobServer> \\\\Screamer\Drive D\TestProjects</JobServer>   
    <JobFolder> \J1003</JobFolder>
    <TSDFolder>\TSD</TSDFolder>   
    <StdConsSubstDrive>V:</StdConsSubstDrive>
    <StdConsFolder>\V-Drive\V-Std</StdConsFolder>   
</Project>
</ProjectList>

Then run this ..
Note the projectNumbers are J1001, J1002, J1003 ..
Code: [Select]
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
//----------------------------------------------
// CodeHimBelonga kwb: 2007/11/19 21:40:04
//----------------------------------------------
namespace XML_ConsoleApplication_001
{
    class Program
    {
        static void Main(string[] args)
        {
            DataSet dsProjects = new DataSet();
            dsProjects.ReadXml(@"c:\ProjectStart.XML");

            DataView dvProject = new
                DataView(dsProjects.Tables["Project"]);
            dvProject.Sort = "ProjectNumber";

            Console.Write("\nEnter Project Number :");
            string input = Console.ReadLine();

            int rowIndex = dvProject.Find(input);
            if (rowIndex == -1)
            {
                // The ProjectNumber was not found in our data
                Console.WriteLine("\nProjectNumber {0} was not found.", input);
                Console.ReadKey();
                return;
            }
            //else proceed
            string ProjectID = dvProject[rowIndex]["ProjectID"].ToString();
            string ProjectNumber = dvProject[rowIndex]["ProjectNumber"].ToString();
            string ProjectName = dvProject[rowIndex]["ProjectName"].ToString();
            string ClientName = dvProject[rowIndex]["ClientName"].ToString();
            string JobServer = dvProject[rowIndex]["JobServer"].ToString();
            string JobSubstDrive = dvProject[rowIndex]["JobSubstDrive"].ToString();
            string JobFolder = dvProject[rowIndex]["JobFolder"].ToString();
            //
            Console.WriteLine("\nProjectID {0}"+
                    "\nProjectNumber : {1}"+                 
                    "\nProjectName : {2}"+
                    "\nClientName : {3}"+
                    "\nJobServer : {4}"+
                    "\nJobSubstDrive : {5}"+
                    "\nJobFolder : {6}",
                   rowIndex.ToString(),
                   ProjectNumber,
                   ProjectName,
                   ClientName,
                   JobServer,
                   JobSubstDrive,
                   JobFolder
               );
            //
            Console.Write("\nPress any key to proceed.");
            Console.ReadKey();           
         }
    }
}

Note, this is not meant to be in the least indicative of good code .. just posting what i'm learning :-)

.. and the obligatory piccy,
Title: Re: XML_ConsoleApplication_001
Post by: JohnK on November 19, 2007, 09:32:10 AM
Cool.

I can learn from this. Thank you Kerry.
Title: Re: XML_ConsoleApplication_001
Post by: David Hall on November 19, 2007, 10:04:48 AM
Very cool Kerry!
Title: Re: XML_ConsoleApplication_001
Post by: Kerry on November 19, 2007, 07:11:55 PM
John, David ;
yep, this is fun ..
and you're most welcome.
Title: Re: XML_ConsoleApplication_001
Post by: MickD on November 19, 2007, 07:18:02 PM
That looks easy enough Kerry, very clean example and a very good starting point.

Gotta love text based documents :)
Title: Re: XML_ConsoleApplication_001
Post by: Kerry on November 20, 2007, 01:39:40 AM
Wheeeee .. in VS2008  Linq in Xml has some potential.
Time to hit the books I think .. :-)
Title: Re: XML_ConsoleApplication_001
Post by: Kerry on November 20, 2007, 02:00:18 AM
I'm wetting myself ..

[/too much information]

A piccy is enough !
Title: Re: XML_ConsoleApplication_001
Post by: It's Alive! on November 20, 2007, 04:09:51 AM
I'm wetting myself ..

Well, off to buy cleaning supplies  :lol:
Title: Re: XML_ConsoleApplication_001
Post by: Kerry on November 20, 2007, 04:33:30 AM
I'm really going to enjoy this Dan ..
Title: Re: XML_ConsoleApplication_001
Post by: Glenn R on November 20, 2007, 07:28:04 AM
This looks like something we were discussing not so long ago Kerry...good to see you're making progress with it.

Cheers,
Glenn.
Title: Re: XML_ConsoleApplication_001
Post by: Kerry on November 20, 2007, 08:16:39 AM
This looks like something we were discussing not so long ago Kerry...good to see you're making progress with it.

Cheers,
Glenn.

Hi Glenn,
yep, this is the start of the beast.

Has your body clock adjusted to Greenwich Mean Time yet ?
Title: Re: XML_ConsoleApplication_001
Post by: joseguia on November 20, 2007, 09:19:48 AM
WOW, .. no way for me to bookmark this topic so I guess I'll reply so I can find it again later.

Thanks for the SAMPLE
Title: Re: XML_ConsoleApplication_001
Post by: TR on November 20, 2007, 11:17:32 PM
The beauty of DataSets is their ability to:

1) Hold a collection of DataTables
2) Read and Write XML data.
3) The ability to connect them to a DataGridView

I am in the process of working on a BOM program using all 3 features listed above. The nicest feature is I can write the DataSets XML to an XRecord in the drawing, which then can be loaded every time my BOM program is initiated.

I can provide code if needed when I get back on my windows laptop but unfortunately for most I do all my coding in BOO so SharpDevelop's translator would be needed.
Title: Re: XML_ConsoleApplication_001
Post by: Glenn R on November 22, 2007, 06:29:52 AM
Has your body clock adjusted to Greenwich Mean Time yet ?

Yep - all's good Kerry. Will speak to you soon.

Cheers,
Glenn.