using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Text;
using System.Windows.Forms;
/*
* 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>
/// Allows creation of an Access database for current project
/// </summary>
public partial class FormCreateAccessDB : Form
{
private bool m_Access12 = false;
private string m_AccessDBPath = "";
private string m_AccessTableName = "";
// Tooltip for buttons
private ToolTip m_ToolTip = new ToolTip();
public FormCreateAccessDB()
{
InitializeComponent();
jFileFolderPicker1.SelectedPath = "";
// ToolTips
m_ToolTip.SetToolTip(btnCreateDB, "Create Access Database");
m_ToolTip.SetToolTip(btnClose, "Close Dialog");
}
private void FormCreateAccessDB_Load(object sender, EventArgs e)
{
jFileFolderPicker1.Focus();
}
private void btnCreateDB_Click(object sender, EventArgs e)
{
// All fields must be entered
string mes = "", folderName = "", fileExt = "", fileName = "";
if (!string.IsNullOrEmpty(jFileFolderPicker1.SelectedPath))
{
folderName = jFileFolderPicker1.SelectedPath;
}
else
{
mes = "Database Folder ";
}
if (!string.IsNullOrEmpty(txtDBFileName.Text))
{
fileName = txtDBFileName.Text;
}
else
{
mes = "Database File Name ";
}
if (!string.IsNullOrEmpty(txtTableName.Text))
{
this.m_AccessTableName = txtTableName.Text;
}
else
{
mes = "Table Name ";
}
if (!string.IsNullOrEmpty(mes))
{
ShowMessage("Required Fields: " + mes, true);
return;
}
else
{
this.m_AccessDBPath = Path.Combine(folderName, fileName);
this.m_Access12 = rbAccess12.Checked;
if (this.m_Access12)
fileExt = ".accdb";
else
fileExt = ".mdb";
if (!this.m_AccessDBPath.EndsWith(fileExt, true, System.Globalization.CultureInfo.CurrentCulture))
this.m_AccessDBPath += fileExt;
this.DialogResult = DialogResult.OK;
Close();
}
}
private void btnClose_Click(object sender, EventArgs e)
{
Close();
}
private void ShowMessage(string strMes, bool blnBeep)
{
tslblMessage.Text = strMes;
if (blnBeep)
JCommon.MessageBeep(-1);
}
private void txtDatabasePath_TextChanged(object sender, EventArgs e)
{
btnCreateDB.Enabled = ((!string.IsNullOrEmpty(jFileFolderPicker1.SelectedPath)) && (!string.IsNullOrEmpty(txtDBFileName.Text)) && (!string.IsNullOrEmpty(txtTableName.Text)));
}
public bool Access12
{
get { return this.m_Access12; }
}
public string AccessDatabasePath
{
get { return this.m_AccessDBPath; }
}
public string AccessTableName
{
get { return this.m_AccessTableName; }
}
}
}