Question

Looking for Cleaner Code structure, and little xml help.

Asked by: Smyken

I'm pretty new to C# and need advise on how to Structure up code in a good way, making classes and methods.

Here is a small example code I wrote that I would like to structure better.
For example the xml node fetching is declared 2 times, when thay load on a button and when they are saved by another button.

How could I for example write a class or method that is located in a different .cs file and just call the method or class instead of writing the code several times ?

I also wonder how I can create the LocalTitle node directly under Root as the first child ?
As it is now I create LocalTitle node by saying that it should be added before OriginalTitle which is the firstchild, but if the OriginalTitle is missing then this wont work I guess.

Any examples ?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
 
 
namespace XML_Update_sample
{
    public partial class Form1 : Form
    {
        XmlDocument xmlDoc = new XmlDocument();
        public String Xml_File;
 
        public Form1()
        {
            InitializeComponent();
        }
    
        private void Load_xml_button_Click(object sender, EventArgs e)
        {
            if (open_xml_dialog.ShowDialog() == DialogResult.OK)
            {
                
                Xml_File = open_xml_dialog.FileName;
                xmlDoc.Load(Xml_File);
 
                XmlNode root = xmlDoc.DocumentElement;
                XmlNode LocalTitle = xmlDoc.SelectSingleNode("/Title/LocalTitle");
                XmlNode OriginalTitle = xmlDoc.SelectSingleNode("/Title/OriginalTitle");
                XmlNode SortTitle = xmlDoc.SelectSingleNode("/Title/SortTitle");
 
                
                if (LocalTitle == null)
                {
                    //MessageBox.Show("Node Missing Creating New Element");
                    XmlElement New_LocalTitle = xmlDoc.CreateElement("LocalTitle");
                    root.AppendChild(New_LocalTitle);
                    root.InsertBefore(New_LocalTitle, xmlDoc.SelectSingleNode("/Title/OriginalTitle"));
                }
                if (LocalTitle != null)
                {
                    LocalTitle_textbox.Text = LocalTitle.InnerText;
                }
 
                
                if (OriginalTitle == null)
                {
                    //MessageBox.Show("Node Missing Creating New Element");
                    XmlElement New_OriginalTitle = xmlDoc.CreateElement("OriginalTitle");
                    root.AppendChild(New_OriginalTitle);
                    root.InsertAfter(New_OriginalTitle, xmlDoc.SelectSingleNode("/Title/LocalTitle"));
                }
                if (OriginalTitle != null)
                {
                    OriginalTitle_textbox.Text = OriginalTitle.InnerText;
                }
 
 
 
                if (SortTitle == null)
                {
                    //MessageBox.Show("Node Missing Creating New Element");
                    XmlElement New_SortTitle = xmlDoc.CreateElement("SortTitle");
                    root.AppendChild(New_SortTitle);
                    root.InsertAfter(New_SortTitle, xmlDoc.SelectSingleNode("/Title/OriginalTitle"));
                }
                if (SortTitle != null)
                {
                    SortTitle_textbox.Text = SortTitle.InnerText;
                }
 
 
            }
 
        
        }
 
        private void Load_trailer_button_Click(object sender, EventArgs e)
        {
            if (open_trailer_dialog.ShowDialog() == DialogResult.OK)
            {
                string Trailer_File = open_trailer_dialog.FileName;
                Trailer_textbox.Text = Trailer_File;
                MessageBox.Show(Trailer_File);
            }  
        }
 
 
 
 
        private void Save_xml_button_Click(object sender, EventArgs e)
        {
            XmlNode LocalTitle = xmlDoc.SelectSingleNode("/Title/LocalTitle");
            XmlNode OriginalTitle = xmlDoc.SelectSingleNode("/Title/OriginalTitle");
            XmlNode SortTitle = xmlDoc.SelectSingleNode("/Title/SortTitle");
 
            LocalTitle.InnerText = LocalTitle_textbox.Text;
            OriginalTitle.InnerText = OriginalTitle_textbox.Text;
            SortTitle.InnerText = SortTitle_textbox.Text;
 
            xmlDoc.Save(Xml_File);
        }
 
    }
}

                                  
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:

Select allOpen in new window

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-04-25 at 04:34:35ID24354802
Topic

Microsoft Visual C#.Net

Participating Experts
2
Points
500
Comments
9

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

    Free Tech Articles

    1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
      It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
    2. SCCM OSD Basic troubleshooting
      SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
    3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
      This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
    4. Create a Win7 Gadget
      This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
    5. Outlook continually prompting for username and password
      There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
    6. Backup Exchange 2010 Information Store using Windows Backup
      There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

    Cloud Class Webinars

    1. Avoiding Bugs in Microsoft Access
      Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
    2. Top 10 Best New Features in Visio 2010
      Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
    3. IT Consultant Business Secrets Revealed
      Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
    4. Disaster Recovery and Business Continuity
      Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
    5. Organize Your Visio Diagrams with Containers and Lists
      Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
    6. How to Us Objects, Properties, Events and Methods in Microsoft Access
      Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

    Join the Community

    Give a Little. Get a Lot.

    Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

    Join the Community

    Answers

     

    by: anyoneisPosted on 2009-04-25 at 17:40:42ID: 24234087

    Well, the first thing that comes to mind is to create a specialized version of XmlDocument by deriving your own MediaDocument from it. That said, you should "prefer containment to inheritance."

    This latter path would have you create a similar MediaDocument with similar methods and properties, but rather than inherit from XmlDocument, it would contain an XmlDocument field, and its methods and properties would forward calls to the contained XmlDocument as needed.

    David

     

    by: SmykenPosted on 2009-04-26 at 00:54:58ID: 24235021

    Ouch I don't understand a bit of what you wrote, as I said I'm totally new to C#.

     

    by: TiggeritoPosted on 2009-04-26 at 01:48:33ID: 24235201

    Heres the basis of a class you could use to manage this XML better. Typical use would be:

    // loading
    Title title = new Title();
    title.Load(Xml_File);
    string localTitle = title.LocalTitle;

    // saving
    title.LocalTitle = LocalTitle_textbox.Text;
    title.Save(Xml_File);

    namespace PlayRoom
    {
    	/// <summary>
    	/// Contains info about a Title
    	/// Can read/write to/from an XML file
    	/// </summary>
    	public class Title
    	{
    		#region Constructors
    		/// <summary>
    		/// Default constructor
    		/// </summary>
    		public void Title() {}
     
    		/// <summary>
    		/// set all the porperties
    		/// </summary>
    		public void Title(string localTitle, string originalTitle, string sortTitle) 
    		{ 
    			// TODO: set the properties
    		}
    		#endregion
     
    		#region Properties
    		public string LocalTitle { get; set;}
    		public string OriginalTitle { get; set;}
    		public string SortTitle { get; set;}
    		#endregion
     
    		#region XML Serialisation
    		/// <summary>
    		/// Sets properties based on data from an XML file
    		/// </summary>
    		/// <param name="xmlFile"></param>
    		public void Load(string xmlFile) 
    		{
    			// TODO: load into an XML document and set properties based on its content
    		}
     
    		/// <summary>
    		/// Write properties to a file in XML format
    		/// </summary>
    		/// <param name="xmlFile"></param>
    		public void Save(string xmlFile) 
    		{
    			// TODO: create an XmlDocument that contains our properties then save it
    		}
    		#endregion
     
     
    	}
    }
    
                                                  
    1:
    2:
    3:
    4:
    5:
    6:
    7:
    8:
    9:
    10:
    11:
    12:
    13:
    14:
    15:
    16:
    17:
    18:
    19:
    20:
    21:
    22:
    23:
    24:
    25:
    26:
    27:
    28:
    29:
    30:
    31:
    32:
    33:
    34:
    35:
    36:
    37:
    38:
    39:
    40:
    41:
    42:
    43:
    44:
    45:
    46:
    47:
    48:
    49:
    50:
    51:
    52:
    

    Select allOpen in new window

     

    by: SmykenPosted on 2009-04-26 at 02:52:22ID: 24235395

    Thanks Tiggerito

    This seems to be the right way, I have looked at some opensource application and they are written in this way.
    Is there any chance that you could explain a bit more ?
    Also I will be using a treeview that when selectedindex changes the path will be picked from the selected node to set the path to the xml file, how would I pull that to the save void ?
    I'm not sure how I would go about using the get/set values.
    Also could you tell me why you write this:  public void Title() {}

    Thanks !

     

    by: TiggeritoPosted on 2009-04-26 at 08:45:28ID: 24236503

    Your indicating that the XML contains more than one instance of your Title item. i.e. there will be mutliple Title elements in the XML.

    Could you comfirm this and provide a complete example of the XML that you will be working with.

    The get; set; is automaitic in .Net 3.5 and is just a way to say a property that has a private field.

    I stated the default constructor i.e. Title() as you heave to implicetly specify it if other constructors are specified.

     

    by: SmykenPosted on 2009-04-26 at 10:35:43ID: 24236882

    Here is a copy/paste of a mymovies.xml example file:

    Below the Xml is my current source code for reading the xml file that is picked when a node in treeview is selected.

    My problem is that I somehow have hard time to make a code simple or to put it in some classes, methods or/and into different .cs files, all my code is sadly in my form.cs file.
    This looks awful and is not so good even if Im a total newbie to programming.
    Any code example and explanation would be greatly appriciated !

    
     
    <Title>
      <LocalTitle>American Psycho</LocalTitle>
      <OriginalTitle>American Psycho</OriginalTitle>
      <SortTitle>American Psycho</SortTitle>
      <LocalTrailer>
        <URL>\\HOMESERVER\Trailers\American Psycho\american psycho trailer.flv</URL>
      </LocalTrailer>
      <Added>2009-03-19 01:57:52</Added>
      <ProductionYear>2000</ProductionYear>
      <RunningTime>101</RunningTime>
      <IMDBrating>7.7</IMDBrating>
      <MPAARating />
      <Description>American Psycho is about the life of an upper class Wall Street business man in the 1980s whos psychotic behavior is increased more and more as his business life goes on. Based on the Bret Easton novel of the same name, this dark comical look into the lives of yuppies is violent yet beautifully done by the flawless Christian Bale as the serial killer/investment banker who just wants to fit in.</Description>
      <Type />
      <AspectRatio />
      <TMDbId>1359</TMDbId>
      <Genres>
        <Genre>Thriller</Genre>
        <Genre>Psychological Thriller</Genre>
        <Genre>Mature</Genre>
        <Genre>Violence</Genre>
      </Genres>
      <Persons>
        <Person>
          <Name>Mary Harron</Name>
          <Type>Director</Type>
          <Role />
        </Person>
        <Person>
          <Name>Christian Bale</Name>
          <Type>Actor</Type>
          <Role>Patrick Bateman</Role>
        </Person>
        <Person>
          <Name>Reese Witherspoon</Name>
          <Type>Actor</Type>
          <Role>Evelyn Williams</Role>
        </Person>
        <Person>
          <Name>Justin Theroux</Name>
          <Type>Actor</Type>
          <Role>Timothy Bryce</Role>
        </Person>
        <Person>
          <Name>Josh Lucas</Name>
          <Type>Actor</Type>
          <Role>Craig McDermott</Role>
        </Person>
        <Person>
          <Name>Bill Sage</Name>
          <Type>Actor</Type>
          <Role>David Van Patten</Role>
        </Person>
        <Person>
          <Name>Chloë Sevigny</Name>
          <Type>Actor</Type>
          <Role>Jean</Role>
        </Person>
        <Person>
          <Name>Samantha Mathis</Name>
          <Type>Actor</Type>
          <Role>Courtney Rawlinson</Role>
        </Person>
        <Person>
          <Name>Matt Ross</Name>
          <Type>Actor</Type>
          <Role>Luis Carruthers</Role>
        </Person>
        <Person>
          <Name>Jared Leto</Name>
          <Type>Actor</Type>
          <Role>Paul Allen</Role>
        </Person>
        <Person>
          <Name>Willem Dafoe</Name>
          <Type>Actor</Type>
          <Role>Det. Donald Kimball</Role>
        </Person>
        <Person>
          <Name>Cara Seymour</Name>
          <Type>Actor</Type>
          <Role>Christie</Role>
        </Person>
        <Person>
          <Name>Guinevere Turner</Name>
          <Type>Actor</Type>
          <Role>Elizabeth</Role>
        </Person>
        <Person>
          <Name>Stephen Bogaert</Name>
          <Type>Actor</Type>
          <Role>Harold Carnes</Role>
        </Person>
        <Person>
          <Name>Monika Meier</Name>
          <Type>Actor</Type>
          <Role>Daisy</Role>
        </Person>
        <Person>
          <Name>Krista Sutton</Name>
          <Type>Actor</Type>
          <Role>Sabrina</Role>
        </Person>
      </Persons>
      <Studios />
    </Title>
     
     
     
     
     
     
     
     
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Xml;
     
     
    namespace XML_Update_sample
    {
        public partial class Form1 : Form
        {
            public XmlDocument xmlDoc = new XmlDocument();
     
            public Form1()
            {
                InitializeComponent();
     
                TreeNode booktitles = treeView1.Nodes.Add("Movies");
                treeView1.Sort();
                treeView1.ExpandAll();
                treeView1.FullRowSelect = true;
                treeView1.ShowLines = false;
                treeView1.ShowNodeToolTips = true;
     
     
                XmlDocument doc = new XmlDocument();
                doc.Load("AMFOPTIONS.xml");
     
                XmlNodeList LocationList = doc.GetElementsByTagName("Location");
     
                foreach (XmlNode node in LocationList)
                {
                    XmlElement LocationElement = (XmlElement)node;
     
                    string Location = LocationElement.InnerText;
     
                    DirectoryInfo dir = new DirectoryInfo(Location);
                    AddNode(dir, booktitles);
                }
     
            }
     
            public void AddNode(DirectoryInfo dir, TreeNode node)
            {
                try
                {
                    foreach (DirectoryInfo dInfo in dir.GetDirectories())
                    {
                        TreeNode mainNext = node.Nodes.Add(dInfo.Name);
                        AddNode(dInfo, mainNext);
                        mainNext.ToolTipText = dInfo.FullName;
                        mainNext.Name = dInfo.FullName;
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    node.Nodes.Add("Access denied");
                }
     
                // Catch other exceptions
                catch (Exception)
                {
                    node.Nodes.Add("Error accessing directory!");
                }
     
     
            }
     
            private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
            {
                xmlDoc = new XmlDocument();
                Front_picbox.Invalidate();
                Front_picbox.Image = null;
                Back_picbox.Invalidate();
                Back_picbox.Image = null;
                Drop_picbox.Invalidate();
                Drop_picbox.Image = null;
                LocalTitle_textbox.Invalidate();
                LocalTitle_textbox.Clear();
                OriginalTitle_textbox.Invalidate();
                OriginalTitle_textbox.Clear();
                SortTitle_textbox.Invalidate();
                SortTitle_textbox.Clear();
                Year_textbox.Invalidate();
                Year_textbox.Clear();
                Time_textbox.Invalidate();
                Time_textbox.Clear();
                Imdb_textbox.Invalidate();
                Imdb_textbox.Clear();
                Mpaa_combobox.Invalidate();
                Mpaa_combobox.Text = "";
                Description_textbox.Invalidate();
                Description_textbox.Clear();
                Type_combobox.Invalidate();
                Type_combobox.Text ="";
                Trailer_textbox.Invalidate();
                Trailer_textbox.Clear();
                Aratio_combobox.Invalidate();
                Aratio_combobox.Text = "";
     
     
                string path_xml = (treeView1.SelectedNode.Name.ToString() + @"\mymovies.xml");
                string path_front = (treeView1.SelectedNode.Name.ToString() + @"\Folder.jpg");
                string path_back = (treeView1.SelectedNode.Name.ToString() + @"\Back.jpg");
                string path_backdrop = (treeView1.SelectedNode.Name.ToString() + @"\backdrop.jpg");
     
                if (File.Exists(path_front))
                {
     
                    Image bild = Image.FromFile(path_front);
                    Front_picbox.Image = bild;
                }
                if (File.Exists(path_back))
                {
     
                    Image bild = Image.FromFile(path_back);
                    Back_picbox.Image = bild;
                }
                if (File.Exists(path_backdrop))
                {
     
                    Image bild = Image.FromFile(path_backdrop);
                    Drop_picbox.Image = bild;
                }
     
                if (File.Exists(path_xml))
                {
     
     
     
                    xmlDoc.Load(path_xml);
     
                    XmlNode root = xmlDoc.DocumentElement;
                    XmlNode LocalTitle = xmlDoc.SelectSingleNode("/Title/LocalTitle");
                    XmlNode OriginalTitle = xmlDoc.SelectSingleNode("/Title/OriginalTitle");
                    XmlNode SortTitle = xmlDoc.SelectSingleNode("/Title/SortTitle");
                    XmlNode Year = xmlDoc.SelectSingleNode("/Title/ProductionYear");
                    XmlNode Time = xmlDoc.SelectSingleNode("/Title/RunningTime");
                    XmlNode Trailer = xmlDoc.SelectSingleNode("/Title/LocalTrailer/URL");
                    XmlNode Imdb = xmlDoc.SelectSingleNode("/Title/IMDBrating");
                    XmlNode Mpaa = xmlDoc.SelectSingleNode("/Title/MPAARating");
                    XmlNode Description = xmlDoc.SelectSingleNode("/Title/Description");
                    XmlNode MType = xmlDoc.SelectSingleNode("/Title/Type");
                    XmlNode Aratio = xmlDoc.SelectSingleNode("/Title/AspectRatio");
     
                    if (LocalTitle == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_LocalTitle = xmlDoc.CreateElement("LocalTitle");
                        root.AppendChild(New_LocalTitle);
                        root.InsertBefore(New_LocalTitle, xmlDoc.SelectSingleNode("/Title/OriginalTitle"));
                    }
                    if (LocalTitle != null)
                    {
                        LocalTitle_textbox.Text = LocalTitle.InnerText;
                    }
     
     
                    if (OriginalTitle == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_OriginalTitle = xmlDoc.CreateElement("OriginalTitle");
                        root.AppendChild(New_OriginalTitle);
                        root.InsertAfter(New_OriginalTitle, xmlDoc.SelectSingleNode("/Title/LocalTitle"));
                    }
                    if (OriginalTitle != null)
                    {
                        OriginalTitle_textbox.Text = OriginalTitle.InnerText;
                    }
     
     
     
                    if (SortTitle == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_SortTitle = xmlDoc.CreateElement("SortTitle");
                        root.AppendChild(New_SortTitle);
                        root.InsertAfter(New_SortTitle, xmlDoc.SelectSingleNode("/Title/OriginalTitle"));
                    }
                    if (SortTitle != null)
                    {
                        SortTitle_textbox.Text = SortTitle.InnerText;
                    }
     
     
                    if (Year == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_Year = xmlDoc.CreateElement("ProductionYear");
                        root.AppendChild(New_Year);
                        root.InsertAfter(New_Year, xmlDoc.SelectSingleNode("/Title/SortTitle"));
                    }
                    if (Year != null)
                    {
                        Year_textbox.Text = Year.InnerText;
                    }
     
     
                    if (Time == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_Time = xmlDoc.CreateElement("RunningTime");
                        root.AppendChild(New_Time);
                        root.InsertAfter(New_Time, xmlDoc.SelectSingleNode("/Title/ProductionYear"));
                    }
                    if (Time != null)
                    {
                        Time_textbox.Text = Time.InnerText;
                    }
     
     
                    if (Trailer == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_LocalTrailer = xmlDoc.CreateElement("LocalTrailer");
                        root.AppendChild(New_LocalTrailer);
                        root.InsertAfter(New_LocalTrailer, xmlDoc.SelectSingleNode("/Title/RunningTime"));
                        XmlElement New_Trailer = xmlDoc.CreateElement("URL");
                        New_LocalTrailer.AppendChild(New_Trailer);
     
                    }
                    if (Trailer != null)
                    {
                        Trailer_textbox.Text = Trailer.InnerText;
                    }
     
     
     
                    if (Imdb == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_Imdb = xmlDoc.CreateElement("IMDBrating");
                        root.AppendChild(New_Imdb);
                        root.InsertAfter(New_Imdb, xmlDoc.SelectSingleNode("/Title/LocalTrailer"));
                    }
                    if (Imdb != null)
                    {
                        Imdb_textbox.Text = Imdb.InnerText;
                    }
     
     
                    if (Mpaa == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_Mpaa = xmlDoc.CreateElement("MPAARating");
                        root.AppendChild(New_Mpaa);
                        root.InsertAfter(New_Mpaa, xmlDoc.SelectSingleNode("/Title/IMDBrating"));
                    }
                    if (Mpaa != null)
                    {
                        Mpaa_combobox.SelectedText = Mpaa.InnerText;
                    }
     
     
                    if (Description == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_Description = xmlDoc.CreateElement("Description");
                        root.AppendChild(New_Description);
                        root.InsertAfter(New_Description, xmlDoc.SelectSingleNode("/Title/MPAARating"));
                    }
                    if (Description != null)
                    {
                        Description_textbox.Text = Description.InnerText;
                    }
     
     
                    if (MType == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_MType = xmlDoc.CreateElement("Type");
                        root.AppendChild(New_MType);
                        root.InsertAfter(New_MType, xmlDoc.SelectSingleNode("/Title/Description"));
                    }
                    if (MType != null)
                    {
                        Type_combobox.SelectedText = MType.InnerText;
                    }
     
     
                    if (Aratio == null)
                    {
                        //MessageBox.Show("Node Missing Creating New Element");
                        XmlElement New_Aratio = xmlDoc.CreateElement("AspectRatio");
                        root.AppendChild(New_Aratio);
                        root.InsertAfter(New_Aratio, xmlDoc.SelectSingleNode("/Title/Type"));
                    }
                    if (Aratio != null)
                    {
                        Aratio_combobox.SelectedText = Aratio.InnerText;
                    }
     
                }
            }
     
            private void Load_trailer_button_Click(object sender, EventArgs e)
            {
                if (open_trailer_dialog.ShowDialog() == DialogResult.OK)
                {
                    string Trailer_File = open_trailer_dialog.FileName;
                    Trailer_textbox.Text = Trailer_File;
                }  
            }
     
     
     
     
            private void Save_xml_button_Click(object sender, EventArgs e)
            {
                XmlNode LocalTitle = xmlDoc.SelectSingleNode("/Title/LocalTitle");
                XmlNode OriginalTitle = xmlDoc.SelectSingleNode("/Title/OriginalTitle");
                XmlNode SortTitle = xmlDoc.SelectSingleNode("/Title/SortTitle");
                XmlNode Year = xmlDoc.SelectSingleNode("/Title/ProductionYear");
                XmlNode Time = xmlDoc.SelectSingleNode("/Title/RunningTime");
                XmlNode Trailer = xmlDoc.SelectSingleNode("/Title/LocalTrailer/URL");
                XmlNode Imdb = xmlDoc.SelectSingleNode("/Title/IMDBrating");
                XmlNode Mpaa = xmlDoc.SelectSingleNode("/Title/MPAARating");
                XmlNode Description = xmlDoc.SelectSingleNode("/Title/Description");
                XmlNode MType = xmlDoc.SelectSingleNode("/Title/Type");
                XmlNode Aratio = xmlDoc.SelectSingleNode("/Title/AspectRatio");
     
                LocalTitle.InnerText = LocalTitle_textbox.Text;
                OriginalTitle.InnerText = OriginalTitle_textbox.Text;
                SortTitle.InnerText = SortTitle_textbox.Text;
                Year.InnerText = Year_textbox.Text;
                Time.InnerText = Time_textbox.Text;
                Trailer.InnerText = Trailer_textbox.Text;
                Imdb.InnerText = Imdb_textbox.Text;
                Mpaa.InnerText = Mpaa_combobox.Text;
                Description.InnerText = Description_textbox.Text;
                MType.InnerText = Type_combobox.Text;
                Aratio.InnerText = Aratio_combobox.Text;
     
                xmlDoc.Save(treeView1.SelectedNode.Name.ToString() + @"\mymovies.xml");
            }
     
        }
    }
                                                  
    1:
    2:
    3:
    4:
    5:
    6:
    7:
    8:
    9:
    10:
    11:
    12:
    13:
    14:
    15:
    16:
    17:
    18:
    19:
    20:
    21:
    22:
    23:
    24:
    25:
    26:
    27:
    28:
    29:
    30:
    31:
    32:
    33:
    34:
    35:
    36:
    37:
    38:
    39:
    40:
    41:
    42:
    43:
    44:
    45:
    46:
    47:
    48:
    49:
    50:
    51:
    52:
    53:
    54:
    55:
    56:
    57:
    58:
    59:
    60:
    61:
    62:
    63:
    64:
    65:
    66:
    67:
    68:
    69:
    70:
    71:
    72:
    73:
    74:
    75:
    76:
    77:
    78:
    79:
    80:
    81:
    82:
    83:
    84:
    85:
    86:
    87:
    88:
    89:
    90:
    91:
    92:
    93:
    94:
    95:
    96:
    97:
    98:
    99:
    100:
    101:
    102:
    103:
    104:
    105:
    106:
    107:
    108:
    109:
    110:
    111:
    112:
    113:
    114:
    115:
    116:
    117:
    118:
    119:
    120:
    121:
    122:
    123:
    124:
    125:
    126:
    127:
    128:
    129:
    130:
    131:
    132:
    133:
    134:
    135:
    136:
    137:
    138:
    139:
    140:
    141:
    142:
    143:
    144:
    145:
    146:
    147:
    148:
    149:
    150:
    151:
    152:
    153:
    154:
    155:
    156:
    157:
    158:
    159:
    160:
    161:
    162:
    163:
    164:
    165:
    166:
    167:
    168:
    169:
    170:
    171:
    172:
    173:
    174:
    175:
    176:
    177:
    178:
    179:
    180:
    181:
    182:
    183:
    184:
    185:
    186:
    187:
    188:
    189:
    190:
    191:
    192:
    193:
    194:
    195:
    196:
    197:
    198:
    199:
    200:
    201:
    202:
    203:
    204:
    205:
    206:
    207:
    208:
    209:
    210:
    211:
    212:
    213:
    214:
    215:
    216:
    217:
    218:
    219:
    220:
    221:
    222:
    223:
    224:
    225:
    226:
    227:
    228:
    229:
    230:
    231:
    232:
    233:
    234:
    235:
    236:
    237:
    238:
    239:
    240:
    241:
    242:
    243:
    244:
    245:
    246:
    247:
    248:
    249:
    250:
    251:
    252:
    253:
    254:
    255:
    256:
    257:
    258:
    259:
    260:
    261:
    262:
    263:
    264:
    265:
    266:
    267:
    268:
    269:
    270:
    271:
    272:
    273:
    274:
    275:
    276:
    277:
    278:
    279:
    280:
    281:
    282:
    283:
    284:
    285:
    286:
    287:
    288:
    289:
    290:
    291:
    292:
    293:
    294:
    295:
    296:
    297:
    298:
    299:
    300:
    301:
    302:
    303:
    304:
    305:
    306:
    307:
    308:
    309:
    310:
    311:
    312:
    313:
    314:
    315:
    316:
    317:
    318:
    319:
    320:
    321:
    322:
    323:
    324:
    325:
    326:
    327:
    328:
    329:
    330:
    331:
    332:
    333:
    334:
    335:
    336:
    337:
    338:
    339:
    340:
    341:
    342:
    343:
    344:
    345:
    346:
    347:
    348:
    349:
    350:
    351:
    352:
    353:
    354:
    355:
    356:
    357:
    358:
    359:
    360:
    361:
    362:
    363:
    364:
    365:
    366:
    367:
    368:
    369:
    370:
    371:
    372:
    373:
    374:
    375:
    376:
    377:
    378:
    379:
    380:
    381:
    382:
    383:
    384:
    385:
    386:
    387:
    388:
    389:
    390:
    391:
    392:
    393:
    394:
    395:
    396:
    397:
    398:
    399:
    400:
    401:
    402:
    403:
    404:
    405:
    406:
    407:
    408:
    409:
    410:
    411:
    412:
    413:
    414:
    415:
    416:
    417:
    418:
    419:
    420:
    421:
    422:
    423:
    424:
    425:
    426:
    427:
    428:
    429:
    430:
    431:
    432:
    433:
    434:
    435:
    436:
    437:
    438:
    439:
    440:
    441:
    442:
    443:
    444:
    445:
    446:
    447:
    448:
    449:
    450:
    451:
    452:
    453:
    454:
    455:
    456:
    457:
    458:
    459:
    

    Select allOpen in new window

     

    by: anyoneisPosted on 2009-04-26 at 14:09:32ID: 24237614

    I can't think of anything more valuable to a beginning C# programmer than the this book:

    Design Patterns Explained: A New Perspective on Object-Oriented Design (Second Edition) by Alan Shalloway and James R. Trott

    The web site for the book is here:

    http://www.netobjectives.com/resources/books/design-patterns-explained

    I would advise buying it and making the commitment to working through it.

    David

     

    by: TiggeritoPosted on 2009-04-27 at 04:12:58ID: 24240542

    20120131-EE-VQP-002

    3 Ways to Join

    30-Day Free Trial

    The Experts

    98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

    He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

    The Experts

    97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

    The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

    Testimonials

    "...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

    Testimonials

    "I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

    Testimonials

    "WOW! You guys have great, active, and knowledgeable people on here." moore50

    Business Clients

    Business Clients

    In the Press

    "If you’ve got a question... Experts Exchange can supply an answer.”

    In the Press

    "...an invaluable aid for both IT professionals and those who require tech support."

    In the Press

    "where IT professionals provide quick answers on just about any topic"

    Business Account Plans

    Loading Advertisement...