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);
}
}
}
}