using System;
using System.ComponentModel;
using System.Collections;
using System.Diagnostics;
using C1.Data;
using DataLibrary.DataObjects;

namespace DataLibrary
{
    /// <summary>
    /// C1SchemaDef container class: main class of the data library.
    /// Contains the C1SchemaDef component managing the data schema. 
    /// </summary>
    public class DataClass : System.ComponentModel.Component
    {
        public C1.Data.C1SchemaDef schemaDef1;

        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public DataClass(System.ComponentModel.IContainer container)
        {
            /// <summary>
            /// Required for Windows.Forms Class Composition Designer support
            /// </summary>
            container.Add(this);
            InitializeComponent();
        }

        public DataClass()
        {
            /// <summary>
            /// Required for Windows.Forms Class Composition Designer support
            /// </summary>
            InitializeComponent();
        }

        /// <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()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DataClass));
            this.schemaDef1 = new C1.Data.C1SchemaDef();
            ((System.ComponentModel.ISupportInitialize)(this.schemaDef1)).BeginInit();
            // 
            // schemaDef1
            // 
            this.schemaDef1.DummyImage = ((System.Drawing.Bitmap)(resources.GetObject("schemaDef1.DummyImage")));
            this.schemaDef1.CreateSchema += new System.EventHandler(this.schemaDef1_CreateSchema);
            this.schemaDef1.SerializedSchemaXML = this.schemaDef1.GetSchemaFromResources(resources, "schemaDef1", this);
            this.schemaDef1.SerializedDesignTimeOptionsXML = this.schemaDef1.GetDesignTimeOptionsFromResources(resources, "schemaDef1", this);
            ((System.ComponentModel.ISupportInitialize)(this.schemaDef1)).EndInit();

        }
        #endregion

        #region Switch to C1NWind.mdb database

        private void schemaDef1_CreateSchema(object sender, EventArgs e)
        {
            string dbPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
                "\\ComponentOne Samples\\Common\\C1NWind.mdb";
            if (System.IO.File.Exists(dbPath))
            {
                C1.Data.SchemaObjects.Connection conn = schemaDef1.Schema.Connections[0];
                conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + dbPath;
            }
        }

        #endregion
    }
}
