[Adapdev-commits] Adapdev/src/Adapdev.Windows.Forms Adapdev.Windows.Forms.csproj,1.6,1.7 DatabaseExp
Status: Beta
Brought to you by:
intesar66
Update of /cvsroot/adapdev/Adapdev/src/Adapdev.Windows.Forms In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv909/src/Adapdev.Windows.Forms Added Files: Adapdev.Windows.Forms.csproj DatabaseExplorer.cs DatabaseExplorer.resx DatabaseSetting.cs DatabaseWizard.cs DatabaseWizard.resx DatabaseWizardForm.cs DatabaseWizardForm.resx FileTreeView.cs FileTreeView.resx IconListManager.cs IconReader.cs NewFolderForm.cs NewFolderForm.resx Settings.cs SmartTreeView.cs SmartTreeView.resx SmoothProgressBar.cs SmoothProgressBar.resx SystemInfo.cs SystemType.cs Log Message: --- NEW FILE: SmoothProgressBar.resx --- <?xml version="1.0" encoding="utf-8"?> <root> <!-- Microsoft ResX Schema Version 1.3 The primary goals of this format is to allow a simple XML format that is mostly human readable. The generation and parsing of the various data types are done through the TypeConverter classes associated with the data types. Example: ... ado.net/XML headers & schema ... <resheader name="resmimetype">text/microsoft-resx</resheader> <resheader name="version">1.3</resheader> <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader> <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader> <data name="Name1">this is my long string</data> <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data> <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64"> [base64 mime encoded serialized .NET Framework object] </data> <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64"> [base64 mime encoded string representing a byte array form of the .NET Framework object] </data> There are any number of "resheader" rows that contain simple name/value pairs. Each data row contains a name, and value. The row also contains a type or mimetype. Type corresponds to a .NET class that support text/value conversion through the TypeConverter architecture. Classes that don't support this are serialized and stored with the mimetype set. The mimetype is used for serialized objects, and tells the ResXResourceReader how to depersist the object. This is currently not extensible. For a given mimetype the value must be set accordingly: Note - application/x-microsoft.net.object.binary.base64 is the format that the ResXResourceWriter will generate, however the reader can read any of the formats listed below. mimetype: application/x-microsoft.net.object.binary.base64 value : The object must be serialized with : System.Serialization.Formatters.Binary.BinaryFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.soap.base64 value : The object must be serialized with : System.Runtime.Serialization.Formatters.Soap.SoapFormatter : and then encoded with base64 encoding. mimetype: application/x-microsoft.net.object.bytearray.base64 value : The object must be serialized into a byte array : using a System.ComponentModel.TypeConverter : and then encoded with base64 encoding. --> <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xsd:element name="root" msdata:IsDataSet="true"> <xsd:complexType> <xsd:choice maxOccurs="unbounded"> <xsd:element name="data"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" /> <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" /> <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" /> </xsd:complexType> </xsd:element> <xsd:element name="resheader"> <xsd:complexType> <xsd:sequence> <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string" use="required" /> </xsd:complexType> </xsd:element> </xsd:choice> </xsd:complexType> </xsd:element> </xsd:schema> <resheader name="resmimetype"> <value>text/microsoft-resx</value> </resheader> <resheader name="version"> <value>1.3</value> </resheader> <resheader name="reader"> <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <resheader name="writer"> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> </resheader> <data name="$this.Name"> <value>SmoothProgressBar</value> </data> </root> --- NEW FILE: NewFolderForm.cs --- using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.IO; using System.Windows.Forms; namespace Adapdev.Windows.Forms { /// <summary> /// Summary description for SingleInputForm. /// </summary> internal class NewFolderForm : System.Windows.Forms.Form { private System.Windows.Forms.Label lblQuestion; private System.Windows.Forms.TextBox txtInput; private System.Windows.Forms.Button btnCancel; private System.Windows.Forms.Button btnSubmit; private System.Windows.Forms.Label lblError; private SystemInfo info = null; internal NewFolderForm(SystemInfo info) { // // Required for Windows Form Designer support // InitializeComponent(); this.info = info; } /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.lblQuestion = new System.Windows.Forms.Label(); this.txtInput = new System.Windows.Forms.TextBox(); this.btnCancel = new System.Windows.Forms.Button(); this.btnSubmit = new System.Windows.Forms.Button(); this.lblError = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lblQuestion // this.lblQuestion.Location = new System.Drawing.Point(8, 8); this.lblQuestion.Name = "lblQuestion"; this.lblQuestion.Size = new System.Drawing.Size(168, 24); this.lblQuestion.TabIndex = 0; this.lblQuestion.Text = "Enter the new folder to create:"; // // txtInput // this.txtInput.Location = new System.Drawing.Point(192, 8); this.txtInput.Name = "txtInput"; this.txtInput.Size = new System.Drawing.Size(184, 20); this.txtInput.TabIndex = 1; this.txtInput.Text = ""; // // btnCancel // this.btnCancel.Location = new System.Drawing.Point(304, 40); this.btnCancel.Name = "btnCancel"; this.btnCancel.TabIndex = 2; this.btnCancel.Text = "Cancel"; this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click); // // btnSubmit // this.btnSubmit.Location = new System.Drawing.Point(216, 40); this.btnSubmit.Name = "btnSubmit"; this.btnSubmit.TabIndex = 3; this.btnSubmit.Text = "Submit"; this.btnSubmit.Click += new System.EventHandler(this.btnSubmit_Click); // // lblError // this.lblError.ForeColor = System.Drawing.Color.Red; this.lblError.Location = new System.Drawing.Point(8, 32); this.lblError.Name = "lblError"; this.lblError.Size = new System.Drawing.Size(168, 40); this.lblError.TabIndex = 4; // // NewFolderForm // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(384, 70); this.Controls.Add(this.lblError); this.Controls.Add(this.btnSubmit); this.Controls.Add(this.btnCancel); this.Controls.Add(this.txtInput); this.Controls.Add(this.lblQuestion); this.Name = "NewFolderForm"; this.Text = "New Folder Form"; this.ResumeLayout(false); } #endregion private void btnSubmit_Click(object sender, System.EventArgs e) { if(this.txtInput.Text.Length > 0) { this.lblError.Text = ""; string dir = ""; if(info.Type == SystemType.Directory) { dir = System.IO.Path.Combine(info.Path, this.txtInput.Text); } else { dir = Path.Combine(info.Path.Substring(0, info.Path.LastIndexOf("\\")), this.txtInput.Text); } if(!Directory.Exists(dir)) { Directory.CreateDirectory(dir); this.Close(); } else { this.lblError.Text = this.txtInput.Text + " already exists."; } } } private void btnCancel_Click(object sender, System.EventArgs e) { this.Close(); } } } --- NEW FILE: IconReader.cs --- // Copyright Paul Ingles - http://www.codeproject.com/csharp/fileicon.asp using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Data; using System.Runtime.InteropServices; namespace Adapdev.Windows.Forms { /// <summary> /// Provides static methods to read system icons for both folders and files. /// </summary> /// <example> /// <code>IconReader.GetFileIcon("c:\\general.xls");</code> /// </example> public class IconReader { /// <summary> /// Options to specify the size of icons to return. /// </summary> public enum IconSize { /// <summary> /// Specify large icon - 32 pixels by 32 pixels. /// </summary> Large = 0, /// <summary> /// Specify small icon - 16 pixels by 16 pixels. /// </summary> Small = 1 } /// <summary> /// Options to specify whether folders should be in the open or closed state. /// </summary> public enum FolderType { /// <summary> /// Specify open folder. /// </summary> Open = 0, /// <summary> /// Specify closed folder. /// </summary> Closed = 1 } /// <summary> /// Returns an icon for a given file - indicated by the name parameter. /// </summary> /// <param name="name">Pathname for file.</param> /// <param name="size">Large or small</param> /// <param name="linkOverlay">Whether to include the link icon</param> /// <returns>System.Drawing.Icon</returns> public static System.Drawing.Icon GetFileIcon(string name, IconSize size, bool linkOverlay) { Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO(); uint flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES; if (true == linkOverlay) flags += Shell32.SHGFI_LINKOVERLAY; /* Check the size specified for return. */ if (IconSize.Small == size) { flags += Shell32.SHGFI_SMALLICON ; } else { flags += Shell32.SHGFI_LARGEICON ; } Shell32.SHGetFileInfo( name, Shell32.FILE_ATTRIBUTE_NORMAL, ref shfi, (uint) System.Runtime.InteropServices.Marshal.SizeOf(shfi), flags ); // Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly System.Drawing.Icon icon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shfi.hIcon).Clone(); User32.DestroyIcon( shfi.hIcon ); // Cleanup return icon; } /// <summary> /// Used to access system folder icons. /// </summary> /// <param name="size">Specify large or small icons.</param> /// <param name="folderType">Specify open or closed FolderType.</param> /// <returns>System.Drawing.Icon</returns> public static System.Drawing.Icon GetFolderIcon( IconSize size, FolderType folderType ) { // Need to add size check, although errors generated at present! uint flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES; if (FolderType.Open == folderType) { flags += Shell32.SHGFI_OPENICON; } if (IconSize.Small == size) { flags += Shell32.SHGFI_SMALLICON; } else { flags += Shell32.SHGFI_LARGEICON; } // Get the folder icon Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO(); Shell32.SHGetFileInfo( null, Shell32.FILE_ATTRIBUTE_DIRECTORY, ref shfi, (uint) System.Runtime.InteropServices.Marshal.SizeOf(shfi), flags ); System.Drawing.Icon.FromHandle(shfi.hIcon); // Load the icon from an HICON handle // Now clone the icon, so that it can be successfully stored in an ImageList System.Drawing.Icon icon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shfi.hIcon).Clone(); User32.DestroyIcon( shfi.hIcon ); // Cleanup return icon; } } /// <summary> /// Wraps necessary Shell32.dll structures and functions required to retrieve Icon Handles using SHGetFileInfo. Code /// courtesy of MSDN Cold Rooster Consulting case study. /// </summary> /// // This code has been left largely untouched from that in the CRC example. The main changes have been moving // the icon reading code over to the IconReader type. public class Shell32 { public const int MAX_PATH = 256; [StructLayout(LayoutKind.Sequential)] public struct SHITEMID { public ushort cb; [MarshalAs(UnmanagedType.LPArray)] public byte[] abID; } [StructLayout(LayoutKind.Sequential)] public struct ITEMIDLIST { public SHITEMID mkid; } [StructLayout(LayoutKind.Sequential)] public struct BROWSEINFO { public IntPtr hwndOwner; public IntPtr pidlRoot; public IntPtr pszDisplayName; [MarshalAs(UnmanagedType.LPTStr)] public string lpszTitle; public uint ulFlags; public IntPtr lpfn; public int lParam; public IntPtr iImage; } // Browsing for directory. public const uint BIF_RETURNONLYFSDIRS = 0x0001; public const uint BIF_DONTGOBELOWDOMAIN = 0x0002; public const uint BIF_STATUSTEXT = 0x0004; public const uint BIF_RETURNFSANCESTORS = 0x0008; public const uint BIF_EDITBOX = 0x0010; public const uint BIF_VALIDATE = 0x0020; public const uint BIF_NEWDIALOGSTYLE = 0x0040; public const uint BIF_USENEWUI = (BIF_NEWDIALOGSTYLE | BIF_EDITBOX); public const uint BIF_BROWSEINCLUDEURLS = 0x0080; public const uint BIF_BROWSEFORCOMPUTER = 0x1000; public const uint BIF_BROWSEFORPRINTER = 0x2000; public const uint BIF_BROWSEINCLUDEFILES = 0x4000; public const uint BIF_SHAREABLE = 0x8000; [StructLayout(LayoutKind.Sequential)] public struct SHFILEINFO { public const int NAMESIZE = 80; public IntPtr hIcon; public int iIcon; public uint dwAttributes; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=MAX_PATH)] public string szDisplayName; [MarshalAs(UnmanagedType.ByValTStr, SizeConst=NAMESIZE)] public string szTypeName; }; public const uint SHGFI_ICON = 0x000000100; // get icon public const uint SHGFI_DISPLAYNAME = 0x000000200; // get display name public const uint SHGFI_TYPENAME = 0x000000400; // get type name public const uint SHGFI_ATTRIBUTES = 0x000000800; // get attributes public const uint SHGFI_ICONLOCATION = 0x000001000; // get icon location public const uint SHGFI_EXETYPE = 0x000002000; // return exe type public const uint SHGFI_SYSICONINDEX = 0x000004000; // get system icon index public const uint SHGFI_LINKOVERLAY = 0x000008000; // put a link overlay on icon public const uint SHGFI_SELECTED = 0x000010000; // show icon in selected state public const uint SHGFI_ATTR_SPECIFIED = 0x000020000; // get only specified attributes public const uint SHGFI_LARGEICON = 0x000000000; // get large icon public const uint SHGFI_SMALLICON = 0x000000001; // get small icon public const uint SHGFI_OPENICON = 0x000000002; // get open icon public const uint SHGFI_SHELLICONSIZE = 0x000000004; // get shell size icon public const uint SHGFI_PIDL = 0x000000008; // pszPath is a pidl public const uint SHGFI_USEFILEATTRIBUTES = 0x000000010; // use passed dwFileAttribute public const uint SHGFI_ADDOVERLAYS = 0x000000020; // apply the appropriate overlays public const uint SHGFI_OVERLAYINDEX = 0x000000040; // Get the index of the overlay public const uint FILE_ATTRIBUTE_DIRECTORY = 0x00000010; public const uint FILE_ATTRIBUTE_NORMAL = 0x00000080; [DllImport("Shell32.dll")] public static extern IntPtr SHGetFileInfo( string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, uint cbFileInfo, uint uFlags ); } /// <summary> /// Wraps necessary functions imported from User32.dll. Code courtesy of MSDN Cold Rooster Consulting example. /// </summary> public class User32 { /// <summary> /// Provides access to function required to delete handle. This method is used internally /// and is not required to be called separately. /// </summary> /// <param name="hIcon">Pointer to icon handle.</param> /// <returns>N/A</returns> [DllImport("User32.dll")] public static extern int DestroyIcon( IntPtr hIcon ); } } --- NEW FILE: Adapdev.Windows.Forms.csproj --- <VisualStudioProject> <CSHARP ProjectType = "Local" ProductVersion = "7.10.3077" SchemaVersion = "2.0" ProjectGuid = "{0BE602B6-D67E-414E-B852-A2AC61305E8E}" > <Build> <Settings ApplicationIcon = "" AssemblyKeyContainerName = "" AssemblyName = "Adapdev.Windows.Forms" AssemblyOriginatorKeyFile = "" DefaultClientScript = "JScript" DefaultHTMLPageLayout = "Grid" DefaultTargetSchema = "IE50" DelaySign = "false" OutputType = "Library" PreBuildEvent = "" PostBuildEvent = "" RootNamespace = "Adapdev.Windows.Forms" RunPostBuildEvent = "OnBuildSuccess" StartupObject = "" > <Config Name = "Debug" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "DEBUG;TRACE" DocumentationFile = "" DebugSymbols = "true" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "false" OutputPath = "bin\Debug\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> <Config Name = "Release" AllowUnsafeBlocks = "false" BaseAddress = "285212672" CheckForOverflowUnderflow = "false" ConfigurationOverrideFile = "" DefineConstants = "TRACE" DocumentationFile = "" DebugSymbols = "false" FileAlignment = "4096" IncrementalBuild = "false" NoStdLib = "false" NoWarn = "" Optimize = "true" OutputPath = "bin\Release\" RegisterForComInterop = "false" RemoveIntegerChecks = "false" TreatWarningsAsErrors = "false" WarningLevel = "4" /> </Settings> <References> <Reference Name = "System" AssemblyName = "System" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll" /> <Reference Name = "System.Data" AssemblyName = "System.Data" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll" /> <Reference Name = "System.XML" AssemblyName = "System.Xml" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll" /> <Reference Name = "System.Windows.Forms" AssemblyName = "System.Windows.Forms" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Windows.Forms.dll" /> <Reference Name = "System.Drawing" AssemblyName = "System.Drawing" HintPath = "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Drawing.dll" /> <Reference Name = "Adapdev" Project = "{CC30A321-2569-4B1F-8E1A-781B5509B56D}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "Adapdev.Data" Project = "{08C5794D-44ED-4E75-A1C1-48A28C3D0044}" Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}" /> <Reference Name = "log4net" AssemblyName = "log4net" HintPath = "..\..\lib\log4net.dll" /> </References> </Build> <Files> <Include> <File RelPath = "AdapdevAssemblyInfo.cs" Link = "..\AdapdevAssemblyInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "DatabaseExplorer.cs" SubType = "UserControl" BuildAction = "Compile" /> <File RelPath = "DatabaseExplorer.resx" DependentUpon = "DatabaseExplorer.cs" BuildAction = "EmbeddedResource" /> <File RelPath = "DatabaseSetting.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "DatabaseWizard.cs" SubType = "UserControl" BuildAction = "Compile" /> <File RelPath = "DatabaseWizard.resx" DependentUpon = "DatabaseWizard.cs" BuildAction = "EmbeddedResource" /> <File RelPath = "DatabaseWizardForm.cs" SubType = "Form" BuildAction = "Compile" /> <File RelPath = "DatabaseWizardForm.resx" DependentUpon = "DatabaseWizardForm.cs" BuildAction = "EmbeddedResource" /> <File RelPath = "FileTreeView.cs" SubType = "Component" BuildAction = "Compile" /> <File RelPath = "FileTreeView.resx" DependentUpon = "FileTreeView.cs" BuildAction = "EmbeddedResource" /> <File RelPath = "IconListManager.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "IconReader.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "NewFolderForm.cs" SubType = "Form" BuildAction = "Compile" /> <File RelPath = "NewFolderForm.resx" DependentUpon = "NewFolderForm.cs" BuildAction = "EmbeddedResource" /> <File RelPath = "Settings.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SmartTreeView.cs" SubType = "Component" BuildAction = "Compile" /> <File RelPath = "SmartTreeView.resx" DependentUpon = "SmartTreeView.cs" BuildAction = "EmbeddedResource" /> <File RelPath = "SmoothProgressBar.cs" SubType = "UserControl" BuildAction = "Compile" /> <File RelPath = "SmoothProgressBar.resx" DependentUpon = "SmoothProgressBar.cs" BuildAction = "EmbeddedResource" /> <File RelPath = "SystemInfo.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "SystemType.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Commands\AbstractGUICommand.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Commands\IGUICommand.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Commands\ShowErrorMessageCommand.cs" SubType = "Code" BuildAction = "Compile" /> <File RelPath = "Commands\vssver.scc" BuildAction = "None" /> <File RelPath = "Progress\ProgressWindow.cs" SubType = "Form" BuildAction = "Compile" /> <File RelPath = "Progress\ProgressWindow.resx" DependentUpon = "ProgressWindow.cs" BuildAction = "EmbeddedResource" /> </Include> </Files> </CSHARP> </VisualStudioProject> --- NEW FILE: IconListManager.cs --- // Copyright Paul Ingles - http://www.codeproject.com/csharp/fileicon.asp using System; using System.Collections; using System.Windows.Forms; namespace Adapdev.Windows.Forms { /// <summary> /// Maintains a list of currently added file extensions /// </summary> public class IconListManager { private Hashtable _extensionList = new Hashtable(); private System.Collections.ArrayList _imageLists = new ArrayList(); //will hold ImageList objects private IconReader.IconSize _iconSize; bool ManageBothSizes = false; //flag, used to determine whether to create two ImageLists. /// <summary> /// Creates an instance of <c>IconListManager</c> that will add icons to a single <c>ImageList</c> using the /// specified <c>IconSize</c>. /// </summary> /// <param name="imageList"><c>ImageList</c> to add icons to.</param> /// <param name="iconSize">Size to use (either 32 or 16 pixels).</param> public IconListManager(System.Windows.Forms.ImageList imageList, IconReader.IconSize iconSize ) { // Initialise the members of the class that will hold the image list we're // targeting, as well as the icon size (32 or 16) _imageLists.Add( imageList ); _iconSize = iconSize; } /// <summary> /// Creates an instance of IconListManager that will add icons to two <c>ImageList</c> types. The two /// image lists are intended to be one for large icons, and the other for small icons. /// </summary> /// <param name="smallImageList">The <c>ImageList</c> that will hold small icons.</param> /// <param name="largeImageList">The <c>ImageList</c> that will hold large icons.</param> public IconListManager(System.Windows.Forms.ImageList smallImageList, System.Windows.Forms.ImageList largeImageList ) { //add both our image lists _imageLists.Add( smallImageList ); _imageLists.Add( largeImageList ); //set flag ManageBothSizes = true; } /// <summary> /// Used internally, adds the extension to the hashtable, so that its value can then be returned. /// </summary> /// <param name="Extension"><c>String</c> of the file's extension.</param> /// <param name="ImageListPosition">Position of the extension in the <c>ImageList</c>.</param> private void AddExtension( string Extension, int ImageListPosition ) { _extensionList.Add( Extension, ImageListPosition ); } /// <summary> /// Called publicly to add a file's icon to the ImageList. /// </summary> /// <param name="filePath">Full path to the file.</param> /// <returns>Integer of the icon's position in the ImageList</returns> public int AddFileIcon( string filePath ) { // Check if the file exists, otherwise, throw exception. if (!System.IO.File.Exists( filePath )) throw new System.IO.FileNotFoundException("File does not exist"); // Split it down so we can get the extension string[] splitPath = filePath.Split(new Char[] {'.'}); string extension = (string)splitPath.GetValue( splitPath.GetUpperBound(0) ); //Check that we haven't already got the extension, if we have, then //return back its index if (_extensionList.ContainsKey( extension.ToUpper() )) { return (int)_extensionList[extension.ToUpper()]; //return existing index } else { // It's not already been added, so add it and record its position. int pos = ((ImageList)_imageLists[0]).Images.Count; //store current count -- new item's index if (ManageBothSizes == true) { //managing two lists, so add it to small first, then large ((ImageList)_imageLists[0]).Images.Add( IconReader.GetFileIcon( filePath, IconReader.IconSize.Small, false ) ); ((ImageList)_imageLists[1]).Images.Add( IconReader.GetFileIcon( filePath, IconReader.IconSize.Large, false ) ); } else { //only doing one size, so use IconSize as specified in _iconSize. ((ImageList)_imageLists[0]).Images.Add( IconReader.GetFileIcon( filePath, _iconSize, false ) ); //add to image list } AddExtension( extension.ToUpper(), pos ); // add to hash table return pos; } } /// <summary> /// Clears any <c>ImageLists</c> that <c>IconListManager</c> is managing. /// </summary> public void ClearLists() { foreach( ImageList imageList in _imageLists ) { imageList.Images.Clear(); //clear current imagelist. } _extensionList.Clear(); //empty hashtable of entries too. } } } --- NEW FILE: Settings.cs --- namespace Adapdev.Windows.Forms { using System; using System.Collections; /// <summary> /// Summary description for Settings. /// </summary> /// [Serializable] public class Settings { private ArrayList dbsettings = new ArrayList(); public ArrayList DatabaseSettings { get { return dbsettings; } } public void AddDatabaseSetting(DatabaseSetting ds) { this.dbsettings.Add(ds); } } } --- NEW FILE: DatabaseWizard.cs --- using System; using System.Collections; using System.Data; using System.Windows.Forms; using Adapdev.Data; namespace Adapdev.Windows.Forms { /// <summary> /// Summary description for DatabaseWizard. /// </summary> public class DatabaseWizard : System.Windows.Forms.UserControl { private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.TextBox tbConnectionString; private System.Windows.Forms.Label lblConnection; private System.Windows.Forms.Button btnNewDatabase; private System.Windows.Forms.Button btnTestConnection; private System.ComponentModel.IContainer components; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Button btnOpenFile; private System.Windows.Forms.TextBox tbConnectionName; private System.Windows.Forms.Label label1; private System.Windows.Forms.Label lblName; private System.Windows.Forms.TextBox tbName; private System.Windows.Forms.Label lblPassword; private System.Windows.Forms.Label lblUsername; private System.Windows.Forms.Label lblLocation; private System.Windows.Forms.TextBox tbPassword; private System.Windows.Forms.TextBox tbUsername; private System.Windows.Forms.TextBox tbLocation; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.TreeView tvConnectionTypes; private readonly string AllFilesMask = "All files (*.*)|*.*"; private readonly int iconDatabase = 0; private readonly int iconDisabled = 3; private readonly int iconProvider = 2; private readonly int iconSelected = 1; private DbConnectionProvider _connectionProvider = null; private System.Windows.Forms.Label lblFilter; private System.Windows.Forms.TextBox tbFilter; private ProviderConfig _providersConfig = null; public DatabaseWizard() { // This call is required by the Windows.Forms Form Designer. InitializeComponent(); // Hack, since VS.NET IDE bombs out when loading // this control since it can't find the // ProviderConfig.xml file try{ this._providersConfig = new ProviderConfig(); this.BuildConnectionsTree(this.tvConnectionTypes); this.SetGUIProperties(null); } catch(Exception){} // TODO: Add any initialization after the InitializeComponent call } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Component Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.components = new System.ComponentModel.Container(); System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(DatabaseWizard)); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.tbConnectionString = new System.Windows.Forms.TextBox(); this.lblConnection = new System.Windows.Forms.Label(); this.btnNewDatabase = new System.Windows.Forms.Button(); this.btnTestConnection = new System.Windows.Forms.Button(); this.imageList1 = new System.Windows.Forms.ImageList(this.components); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.tbFilter = new System.Windows.Forms.TextBox(); this.lblFilter = new System.Windows.Forms.Label(); this.tbLocation = new System.Windows.Forms.TextBox(); this.btnOpenFile = new System.Windows.Forms.Button(); this.lblName = new System.Windows.Forms.Label(); this.tbName = new System.Windows.Forms.TextBox(); this.lblPassword = new System.Windows.Forms.Label(); this.lblUsername = new System.Windows.Forms.Label(); this.lblLocation = new System.Windows.Forms.Label(); this.tbPassword = new System.Windows.Forms.TextBox(); this.tbUsername = new System.Windows.Forms.TextBox(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.tbConnectionName = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.tvConnectionTypes = new System.Windows.Forms.TreeView(); this.groupBox1.SuspendLayout(); this.groupBox2.SuspendLayout(); this.groupBox3.SuspendLayout(); this.SuspendLayout(); // // openFileDialog1 // this.openFileDialog1.RestoreDirectory = true; // // tbConnectionString // this.tbConnectionString.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbConnectionString.Location = new System.Drawing.Point(112, 256); this.tbConnectionString.Name = "tbConnectionString"; this.tbConnectionString.ReadOnly = true; this.tbConnectionString.Size = new System.Drawing.Size(424, 20); this.tbConnectionString.TabIndex = 9; this.tbConnectionString.Text = ""; // // lblConnection // this.lblConnection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.lblConnection.Location = new System.Drawing.Point(8, 256); this.lblConnection.Name = "lblConnection"; this.lblConnection.Size = new System.Drawing.Size(104, 23); this.lblConnection.TabIndex = 40; this.lblConnection.Text = "Connection String:"; this.lblConnection.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // btnNewDatabase // this.btnNewDatabase.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnNewDatabase.Location = new System.Drawing.Point(112, 280); this.btnNewDatabase.Name = "btnNewDatabase"; this.btnNewDatabase.Size = new System.Drawing.Size(56, 23); this.btnNewDatabase.TabIndex = 10; this.btnNewDatabase.Text = "New"; this.btnNewDatabase.Click += new System.EventHandler(this.btnNewDatabase_Click); // // btnTestConnection // this.btnTestConnection.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.btnTestConnection.Location = new System.Drawing.Point(176, 280); this.btnTestConnection.Name = "btnTestConnection"; this.btnTestConnection.Size = new System.Drawing.Size(96, 23); this.btnTestConnection.TabIndex = 11; this.btnTestConnection.Text = "Test Connection"; this.btnTestConnection.Click += new System.EventHandler(this.btnTestConnection_Click); // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit; this.imageList1.ImageSize = new System.Drawing.Size(16, 16); this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream"))); this.imageList1.TransparentColor = System.Drawing.Color.Transparent; // // groupBox1 // this.groupBox1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox1.Controls.Add(this.tbFilter); this.groupBox1.Controls.Add(this.lblFilter); this.groupBox1.Controls.Add(this.tbLocation); this.groupBox1.Controls.Add(this.btnOpenFile); this.groupBox1.Controls.Add(this.lblName); this.groupBox1.Controls.Add(this.tbName); this.groupBox1.Controls.Add(this.lblPassword); this.groupBox1.Controls.Add(this.lblUsername); this.groupBox1.Controls.Add(this.lblLocation); this.groupBox1.Controls.Add(this.tbPassword); this.groupBox1.Controls.Add(this.tbUsername); this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System; this.groupBox1.Location = new System.Drawing.Point(248, 64); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(288, 184); this.groupBox1.TabIndex = 3; this.groupBox1.TabStop = false; this.groupBox1.Text = "Enter the Database Properties"; // // tbFilter // this.tbFilter.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbFilter.Location = new System.Drawing.Point(112, 152); this.tbFilter.Name = "tbFilter"; this.tbFilter.Size = new System.Drawing.Size(136, 20); this.tbFilter.TabIndex = 7; this.tbFilter.Text = ""; this.tbFilter.TextChanged += new System.EventHandler(this.tbFilter_TextChanged); // // lblFilter // this.lblFilter.Location = new System.Drawing.Point(8, 152); this.lblFilter.Name = "lblFilter"; this.lblFilter.TabIndex = 0; this.lblFilter.Text = "Schema Filter:"; this.lblFilter.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // tbLocation // this.tbLocation.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbLocation.Location = new System.Drawing.Point(112, 24); this.tbLocation.Name = "tbLocation"; this.tbLocation.Size = new System.Drawing.Size(136, 20); this.tbLocation.TabIndex = 3; this.tbLocation.Text = ""; this.tbLocation.TextChanged += new System.EventHandler(this.tbLocation_TextChanged); // // btnOpenFile // this.btnOpenFile.Location = new System.Drawing.Point(248, 24); this.btnOpenFile.Name = "btnOpenFile"; this.btnOpenFile.Size = new System.Drawing.Size(24, 20); this.btnOpenFile.TabIndex = 4; this.btnOpenFile.Text = "..."; this.btnOpenFile.Click += new System.EventHandler(this.btnOpenFile_Click); // // lblName // this.lblName.Location = new System.Drawing.Point(8, 56); this.lblName.Name = "lblName"; this.lblName.TabIndex = 0; this.lblName.Text = "Name: "; this.lblName.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // tbName // this.tbName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbName.Location = new System.Drawing.Point(112, 56); this.tbName.Name = "tbName"; this.tbName.Size = new System.Drawing.Size(136, 20); this.tbName.TabIndex = 4; this.tbName.Text = ""; this.tbName.TextChanged += new System.EventHandler(this.tbName_TextChanged); // // lblPassword // this.lblPassword.Location = new System.Drawing.Point(8, 120); this.lblPassword.Name = "lblPassword"; this.lblPassword.TabIndex = 0; this.lblPassword.Text = "Password: "; this.lblPassword.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // lblUsername // this.lblUsername.Location = new System.Drawing.Point(8, 88); this.lblUsername.Name = "lblUsername"; this.lblUsername.TabIndex = 0; this.lblUsername.Text = "Username: "; this.lblUsername.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // lblLocation // this.lblLocation.Location = new System.Drawing.Point(8, 24); this.lblLocation.Name = "lblLocation"; this.lblLocation.TabIndex = 0; this.lblLocation.Text = "Server / Location: "; this.lblLocation.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // tbPassword // this.tbPassword.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbPassword.Location = new System.Drawing.Point(112, 120); this.tbPassword.Name = "tbPassword"; this.tbPassword.Size = new System.Drawing.Size(136, 20); this.tbPassword.TabIndex = 6; this.tbPassword.Text = ""; this.tbPassword.TextChanged += new System.EventHandler(this.tbPassword_TextChanged); // // tbUsername // this.tbUsername.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbUsername.Location = new System.Drawing.Point(112, 88); this.tbUsername.Name = "tbUsername"; this.tbUsername.Size = new System.Drawing.Size(136, 20); this.tbUsername.TabIndex = 5; this.tbUsername.Text = ""; this.tbUsername.TextChanged += new System.EventHandler(this.tbUsername_TextChanged); // // groupBox2 // this.groupBox2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.groupBox2.Controls.Add(this.tbConnectionName); this.groupBox2.Controls.Add(this.label1); this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.groupBox2.Location = new System.Drawing.Point(248, 8); this.groupBox2.Name = "groupBox2"; this.groupBox2.Size = new System.Drawing.Size(288, 48); this.groupBox2.TabIndex = 1; this.groupBox2.TabStop = false; this.groupBox2.Text = "Connection Settings"; // // tbConnectionName // this.tbConnectionName.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tbConnectionName.Location = new System.Drawing.Point(112, 16); this.tbConnectionName.Name = "tbConnectionName"; this.tbConnectionName.Size = new System.Drawing.Size(168, 20); this.tbConnectionName.TabIndex = 2; this.tbConnectionName.Text = ""; // // label1 // this.label1.Location = new System.Drawing.Point(8, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(88, 23); this.label1.TabIndex = 0; this.label1.Text = "Name: "; this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight; // // groupBox3 // this.groupBox3.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.groupBox3.Controls.Add(this.tvConnectionTypes); this.groupBox3.Location = new System.Drawing.Point(0, 8); this.groupBox3.Name = "groupBox3"; this.groupBox3.Size = new System.Drawing.Size(240, 240); this.groupBox3.TabIndex = 1; this.groupBox3.TabStop = false; this.groupBox3.Text = "Select the connection type:"; // // tvConnectionTypes // this.tvConnectionTypes.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.tvConnectionTypes.FullRowSelect = true; this.tvConnectionTypes.ImageIndex = 2; this.tvConnectionTypes.ImageList = this.imageList1; this.tvConnectionTypes.Location = new System.Drawing.Point(8, 16); this.tvConnectionTypes.Name = "tvConnectionTypes"; this.tvConnectionTypes.SelectedImageIndex = 1; this.tvConnectionTypes.Size = new System.Drawing.Size(224, 208); this.tvConnectionTypes.TabIndex = 1; this.tvConnectionTypes.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.tvConnectionTypes_AfterSelect); // // DatabaseWizard // this.Controls.Add(this.groupBox3); this.Controls.Add(this.btnTestConnection); this.Controls.Add(this.btnNewDatabase); this.Controls.Add(this.lblConnection); this.Controls.Add(this.tbConnectionString); this.Controls.Add(this.groupBox1); this.Controls.Add(this.groupBox2); this.Name = "DatabaseWizard"; this.Size = new System.Drawing.Size(536, 304); this.groupBox1.ResumeLayout(false); this.groupBox2.ResumeLayout(false); this.groupBox3.ResumeLayout(false); this.ResumeLayout(false); } #endregion #region Form Public Properties public string DbLocation { get { return this.tbLocation.Text; } set { this.tbLocation.Text = value; } } public string DbName { get { return this.tbName.Text; } set { this.tbName.Text = value; } } public string Username { get { return this.tbUsername.Text; } set { this.tbUsername.Text = value; } } public string Password { get { return this.tbPassword.Text; } set { this.tbPassword.Text = value; } } public string Filter { get { return this.tbFilter.Text; } set { this.tbFilter.Text = value; } } public string ConnectionName { get { return this.tbConnectionName.Text; } set { this.tbConnectionName.Text = value; } } public TextBox ConnectionControl { get { return this.tbConnectionName; } } public TreeView TypesTreeView { get { return this.tvConnectionTypes; } } #endregion #region Form Event Handlers private void btnOpenFile_Click(object sender, EventArgs e) { if (_connectionProvider != null) { this.openFileDialog1.Filter = _connectionProvider.FileMask == "" ? AllFilesMask : _connectionProvider.FileMask + "|" + AllFilesMask ; } DialogResult dr = this.openFileDialog1.ShowDialog(); if (dr == DialogResult.OK) { this.tbLocation.Text = this.openFileDialog1.FileName; } } private void btnNewDatabase_Click(object sender, System.EventArgs e) { this.Clear(); } private void btnTestConnection_Click(object sender, System.EventArgs e) { TestConnection(); } public void Clear() { this.tbConnectionName.Text = ""; this.tbLocation.Text = ""; this.tbName.Text = ""; this.tbPassword.Text = ""; this.tbUsername.Text = ""; this.tbFilter.Text = ""; } #endregion #region Form KeyPress Handlers private void DatabasePropertiesUC_TextChanged(object sender, System.EventArgs e) { this.tbConnectionString.Text = GetConnectionString(); } private void tbLocation_TextChanged(object sender, System.EventArgs e) { this.DatabasePropertiesUC_TextChanged(sender, e); } private void tbUsername_TextChanged(object sender, System.EventArgs e) { this.DatabasePropertiesUC_TextChanged(sender, e); } private void tbPassword_TextChanged(object sender, System.EventArgs e) { this.DatabasePropertiesUC_TextChanged(sender, e); } private void tbFilter_TextChanged(object sender, System.EventArgs e) { this.DatabasePropertiesUC_TextChanged(sender, e); } private void tbName_TextChanged(object sender, System.EventArgs e) { this.DatabasePropertiesUC_TextChanged(sender, e); } #endregion #region Connection Methods /// <summary> /// Tests Connections using the selected provider type AND OLEDB since OLEDB is required to be able /// to retrieve the relevant Table Information. /// </summary> /// <returns>true if we can connect</returns> /// public void TestConnection() { this.btnTestConnection.Enabled = false; if (this.TestConnections()) { MessageBox.Show(this, "Successfully connected!", "Success!", MessageBoxButtons.OK, MessageBoxIcon.Information); } this.btnTestConnection.Enabled = true; } /// <summary> /// This routine actually does the work of testing the Main and INternal connection methods. /// </summary> /// <returns>true if both connections were sucessfull</returns> public bool TestConnections() { bool validSelected = false; bool validInternal = false; try { validSelected = TestConnectionType(_connectionProvider.ProviderType, GetConnectionString()); // // 7/17/2005 benr: // changed parameter of TestConnectionType to read from the internal // provider as specified in the ProviderConfig.xml file // validInternal = (_connectionProvider.ProviderType == DbProviderType.OLEDB ? true : TestConnectionType(_connectionProvider.InternalProvider.ProviderType, this.GetInternalProviderConnectionString())); } catch (Exception ex) { if (!validSelected) { MessageBox.Show(this, "Unable to connect using the selected Provider. \nMessage: " + ex.Message, "Failure!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show(this, "Unable to connect using the Internal Provider. (Usually OLEDB and needed to retrieve Table information)\nMessage: " + ex.Message, "Failure!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } return (validSelected && validInternal); } /// <summary> /// Tests a given connection Provider Type for a given database. /// </summary> /// <param name="type"></param> /// <returns></returns> public bool TestConnectionType(DbProviderType type, string conString) { using (IDbConnection connection = DbProviderFactory.CreateConnection(type)) { connection.ConnectionString = conString; connection.Open(); } return true; } public string GetConnectionString() { return (_connectionProvider == null) ? string.Empty : _connectionProvider.ConnectionString(this.tbLocation.Text, this.tbName.Text, this.tbUsername.Text, this.tbPassword.Text); } public string GetInternalProviderConnectionString() { return (_connectionProvider == null) ? string.Empty : _connectionProvider.InternalProviderString(this.tbLocation.Text, this.tbName.Text, this.tbUsername.Text, this.tbPassword.Text); } public void SetDatabaseSetting(DatabaseSetting settings) { this.ConnectionName = settings.ConnectionName; this.DbLocation = settings.DatabaseLocation; this.DbName = settings.DatabaseName; this.Password = settings.Password; this.Username = settings.UserName; this.Filter = settings.Filter; try { _connectionProvider = _providersConfig.ConnectionTypes[settings.ConnectionRef].Providers[settings.ProviderRef]; FindConnectionInList(_connectionProvider); SetGUIProperties (_connectionProvider.Parent); } catch (Exception ex) { MessageBox.Show(this, "Unable to load settings. \nMessage: " + ex.Message, "Failure!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } public DatabaseSetting GetDatabaseSetting() { DatabaseSetting ds = new DatabaseSetting(); ds.ConnectionName = this.ConnectionName; ds.DatabaseLocation = this.DbLocation; ds.DatabaseName = this.DbName; ds.Password = this.Password; ds.UserName = this.Username; ds.Filter = this.Filter; ds.ConnectionString = this.GetConnectionString(); ds.OleDbConnectionString = this.GetInternalProviderConnectionString(); ds.DbProviderType = _connectionProvider.ProviderType; ds.DbType = _connectionProvider.DbType; ds.ConnectionRef = _connectionProvider.Parent.Name; ds.ProviderRef = _connectionProvider.Name; return ds; } #endregion #region UI Update methods /// <summary> /// Finds a connection by the Name in the listbox and marks that entry as the active entry /// </summary> public void FindConnectionInList(string type, string provider) { foreach (TreeNode parent in this.tvConnectionTypes.Nodes) { if (parent.Text.Equals(type)) { foreach (TreeNode child in parent.Nodes) { if (child.Text.Equals(provider)) { child.EnsureVisible(); tvConnectionTypes.SelectedNode = child; return; } } } } } public void FindConnectionInList(DbConnectionProvider provider) { FindConnectionInList(provider.Parent.Name, provider.Name); } /// <summary> /// Builds a TreeView control with the Connection->Providers information /// </summary> /// <param name="treeView">TreeView control to populate</param> public void BuildConnectionsTree ( System.Windows.Forms.TreeView treeView) { if (_providersConfig != null) { foreach (DictionaryEntry entryType in this._providersConfig.ConnectionTypes) { DbConnectionType dbType = (DbConnectionType)entryType.Value; TreeNode parent = new TreeNode(dbType.Name); parent.Tag = null; parent.ImageIndex = iconDatabase; parent.SelectedImageIndex = iconDatabase; foreach (DictionaryEntry entryProvider in dbType.Providers) { DbConnectionProvider dbProvider = (DbConnectionProvider)entryProvider.Value; if (dbProvider.Enabled) { TreeNode child = new TreeNode(dbProvider.Name); child.Tag = dbProvider; child.ImageIndex = iconProvider; child.SelectedImageIndex = iconSelected; parent.Nodes.Add(child); } } if (parent.Nodes.Count == 0) { parent.ImageIndex = iconDisabled; parent.SelectedImageIndex = iconDisabled; } treeView.Nodes.Add(parent); } } } private void tvConnectionTypes_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e) { SetConnectionProvider(e.Node.Tag); } private void SetConnectionProvider(object obj) { if (obj == null) { _connectionProvider = null; SetGUIProperties (null); } else { _connectionProvider = obj as DbConnectionProvider; if (_connectionProvider != null) SetGUIProperties (_connectionProvider.Parent); } } /// <summary> /// Depending on the selected Connection/Provider, sets the relevant UI controls enabled/disabled /// </summary> /// <param name="connectionType">A reference to a DbConnectionProvider instance</param> private void SetGUIProperties ( DbConnectionType connectionType) { if (connectionType != null) { SetPromptLabels(connectionType); SetPromptState(true); SetPromptState(true, this.lblLocation, this.tbLocation); SetPromptState(connectionType.SupportsName, this.lblName, this.tbName); SetPromptState(connectionType.SupportsUserID, this.lblUsername, this.tbUsername); SetPromptState(connectionType.SupportsPassword, this.lblPassword, this.tbPassword); SetPromptState(connectionType.SupportsFilter, this.lblFilter, this.tbFilter); this.tbConnectionString.Text = GetConnectionString(); } else { SetPromptLabels(DbConnectionTypes.UnknownConnectionType()); SetPromptState (false); this.tbConnectionString.Text = String.Empty; } } private void SetPromptState ( bool state ) { SetPromptState (state, this.lblLocation, this.tbLocation); SetPromptState (state, this.lblName, this.tbName); SetPromptState (state, this.lblUsername, this.tbUsername); SetPromptState (state, this.lblPassword, this.tbPassword); SetPromptState (state, this.lblFilter, this.tbFilter); this.btnTestConnection.Enabled = state; this.tbConnectionString.Enabled = state; this.lblConnection.Enabled = state; } private void SetPromptLabels(DbConnectionType connectionType) { if (connectionType.SupportsFile) { this.lblLocation.Text = connectionType.PromptFile; this.btnOpenFile.Visible = true; this.btnOpenFile.Enabled = true; } else { this.lblLocation.Text = connectionType.PromptServer; this.btnOpenFile.Visible = false; this.btnOpenFile.Enabled = false; } this.lblName.Text = connectionType.PromptName; this.lblUsername.Text = connectionType.PromptUserID; this.lblPassword.Text = connectionType.PromptPassword; } private void SetPromptState ( bool state, System.Windows.Forms.Label label, System.Windows.Forms.TextBox text ) { text.Enabled = state; label.Enabled = state; } #endregion } } --- NEW FILE: SystemType.cs --- using System; namespace Adapdev.Windows.Forms { /// <summary> /// The type of system resource /// </summary> public enum SystemType { File, Directory } } --- NEW FILE: DatabaseSetting.cs --- namespace Adapdev.Windows.Forms { using System; using Adapdev.Data; using Adapdev.Data.Schema; [Serializable] public class DatabaseSetting { private string connectionName; private strin... [truncated message content] |