Click here to Skip to main content
15,879,535 members
Articles / Programming Languages / C#

AccountPlus

Rate me:
Please Sign up or sign in to vote.
4.47/5 (63 votes)
10 Sep 2009LGPL320 min read 239.3K   61.8K   209  
A Complete Account Management System
using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Windows.Forms;
namespace AccountPlus.BusinessLogic
{
    /// <summary>
    /// Class to be used for reading the Preferences.xml file
    /// </summary>
public class XMLHelper
{
    private XmlDocument xmlDocument = null;
    public XMLHelper()
    {
        xmlDocument = GetXMLDoc();
    }

    /// <summary>
    /// Reads the value of passed node name
    /// </summary>
    /// <param name="itemName">Node name for which vale needs to be read</param>
    /// <returns>Value of the node</returns>
    public string GetValue(string itemName)
    {
        string value = string.Empty;
        XmlNodeList nodes = xmlDocument.DocumentElement.ChildNodes;

        foreach (XmlNode node in nodes)
        {
            if (node.Attributes["name"].Value.Trim().ToLower() == itemName.Trim().ToLower())
            {
                value = node.Attributes["value"].Value.Trim();
                break; 
            }
        }

        return value;
    }

    /// <summary>
    /// Saves the value for the passed xml node into Preference.xml file
    /// </summary>
    /// <param name="itemName">XML Node name</param>
    /// <param name="value">value to be saved</param>
    public void SetValue(string itemName, string value)
    {
        XmlNodeList nodes = xmlDocument.DocumentElement.ChildNodes;
        foreach (XmlNode node in nodes)
        {
            if (node.Attributes["name"].Value.Trim().ToLower() == itemName.Trim().ToLower())
            {
                node.Attributes["value"].Value = value.Trim();
                break; // TODO: might not be correct. Was : Exit For
            }
        }
        xmlDocument.Save(FileName);
    }

    /// <summary>
    /// Saves the modifications done into the XML Document.
    /// </summary>
    public void Save()
    {
        xmlDocument.Save(FileName);
        xmlDocument = GetXMLDoc();
    }

    /// <summary>
    /// Loads XML document for reading or writing purpose.
    /// </summary>
    public XmlDocument GetXMLDoc()
    {
        XmlDocument xmlDoc = new XmlDocument();
        try
        {
            xmlDoc.Load(FileName);
        }
        catch (Exception ex)
        {
            throw ex;
        }

        return xmlDoc;
    }

    /// <summary>
    /// Gets the User Preference file name.
    /// </summary>
    private string FileName
    {
        get { return Application.StartupPath + "\\Preferences.xml"; }
    }
}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Founder Aspirea Technologies Pvt Ltd
India India
• 8 years of experience in IT Industry as a Developer.
• Experience of End-To-End Software Development and Implementation (Entire SDLC i.e Software Development Life Cycle)
• Real time Exposure to Banking, Finance and Energy industry.
• Expertise in distributed application architecture as well as web based applications using Microsoft.NET platform.
• Expertise in database design, SQL programming and SQL performance tuning.
• Expertise in Web Services and WCF Services.
• Experience of Rich Internet Application using Adobe Flex.
• Experience in migration of legacy application to latest technology, migration of VB application to .NET.
• Knowledge of OOPS and Design Concepts.
• Expertise in Agile/ Scrum software development processes.

Specialties
• Languages\ Technologies-
.NET Framework 1.1/2.0/3.0/3.5, C#.NET, VB.NET, ASP.NET, VB6, AJAX, ASP.NET, Adobe Flex 3.0, Web Services, Windows Communication Foundation (WCF), LINQ, SQL Server, Oracle, MySql, MS Access, HTML, XML, JavaScript, C# Script, CSS and XSLT.

• Methodology/ Concepts-
OOPS, Data Structures, Design Concepts and Agile/ Scrum Software Development

Comments and Discussions