Click here to Skip to main content
15,891,136 members
Articles / Programming Languages / C#

Class Library to Automatically Maintain Persistent Variables, Properties and Data Between Sessions

Rate me:
Please Sign up or sign in to vote.
4.50/5 (2 votes)
11 Jan 2008CPOL15 min read 44.1K   591   43  
A class library that maintains persistent variables, properties and data between sessions in XML files. It supports default values for new variables and events when the values in the XML file are changed
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace ConfigDemo {
	public partial class EmployeeForm : Form {
		public string _name;
		public string _function;
		public int _ID=-1;
		public bool forEdit=false;

		public EmployeeForm()
		{
			InitializeComponent();
		}

		private void buttonOK_Click(object sender, EventArgs e)
		{
			_name=textBoxName.Text;
			_function=textBoxFunction.Text;
			string strID=textBoxID.Text;
			bool bOk=true;

			if ((_name.Length==0 && !forEdit) || _function.Length==0 || strID.Length == 0) {
				MessageBox.Show("All fields must be entered!");
				bOk=false;
			} else {
				try {
					_ID=int.Parse(strID);
				} catch {
					MessageBox.Show("The field Employee ID must be numeric!");
					bOk=false;
				}
			}

			if (bOk){
				DialogResult = DialogResult.OK;
			}
		}

		private void EmployeeForm_Shown(object sender, EventArgs e)
		{
			textBoxName.Text = _name;
			if (forEdit) {
				textBoxName.ReadOnly = true;
			}
			textBoxFunction.Text = _function;
			if (_ID != -1) {
				textBoxID.Text = _ID.ToString();
			}
			if (forEdit) {
				textBoxFunction.Focus();
			} else {
				textBoxName.Focus();
			}
		}
	}
}

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 Code Project Open License (CPOL)


Written By
Software Developer (Senior) Svep DesignCenter
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions