Click here to Skip to main content
15,897,187 members
Articles / Programming Languages / XML

Create Data Classes

Rate me:
Please Sign up or sign in to vote.
4.88/5 (31 votes)
4 Mar 2011CPOL10 min read 135.9K   2.5K   167  
An application that creates a C# class to read/write data to/from an Access, SQLite, or XML database.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.Text;
using System.Windows.Forms;
using JGBaseForm;

/*
 * Copyright Jeff Gaines 2007 - 2011 (jeff@jgaines.co.uk)
 * Free licence for private use
 * Please contact the author if you wish to use the code commercially
*/

namespace JGCreateDataClasses
{
	/// <summary>
	/// Miscellaneous Functions including converting database Access/XML
	/// </summary>
	public partial class JMiscFuncPanel : UserControl
	{
		internal event EventHandler<JMessageArgs> MessageRaised;
		protected virtual void OnMessageRaised(object sender, JMessageArgs e)
		{
			EventHandler<JMessageArgs> handler = MessageRaised;
			if (handler != null)
				handler(sender, e);
		}

		internal void RaiseMessageEvent(object sender, string message, bool beep)
		{
			JMessageArgs e = new JMessageArgs(message, beep);
			OnMessageRaised(sender, e);
		}
		
		public JMiscFuncPanel()
		{
			InitializeComponent();
			ControlInitialise();
		}

		private void JMiscFuncPanel_Resize(object sender, EventArgs e)
		{
			ControlResize();
		}

		private void ControlInitialise()
		{
		}

		private void btnCopyFiles_Click(object sender, EventArgs e)
		{
			int numCopied = 0;
			string folderPath = JCommon.AppSettingsPath();
			string fileName;

			foreach (ListViewItem current in lvFiles.CheckedItems)
			{
				try
				{
					fileName = Path.GetFileName(current.Text);
					File.Copy(current.Text, Path.Combine(folderPath, fileName));
					numCopied++;
				}
				catch
				{
				}
			}
			RaiseMessageEvent(this, numCopied.ToString() + " files copied", false);
		}

		private void btnFillLV_Click(object sender, EventArgs e)
		{
			FillListView();
		}

		private void btnShowAppSetttings_Click(object sender, EventArgs e)
		{
			lblApplicationSettingsPath.Text = JCommon.AppSettingsPath();
		}

		private void ControlResize()
		{
			lvFiles.Columns[0].Width = lvFiles.ClientSize.Width - 4;
		}

		private void FillListView()
		{
			ListViewItem lvItem;
			string appPath = Application.StartupPath;

			DirectoryInfo dInfo = new DirectoryInfo(appPath);
			FileInfo[] fInfo = dInfo.GetFiles("*.accdb");

			foreach (FileInfo current in fInfo)
			{
				lvItem = new ListViewItem(current.FullName);
				lvFiles.Items.Add(lvItem);
			}

			fInfo = dInfo.GetFiles("*.db3");

			foreach (FileInfo current in fInfo)
			{
				lvItem = new ListViewItem(current.FullName);
				lvFiles.Items.Add(lvItem);
			}
		}

		



	}
}

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
Retired
United Kingdom United Kingdom
I have been a keen hobbyist programmer since getting my first computer - a Vic 20 (you had to be able to write programs then since few programs were available and all were expensive).
Retired and now living in Pewsey, Wiltshire, where I spend (far too much of) my time writing computer programs to keep my mind active.

Comments and Discussions