using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
using System.IO;

namespace Tutor04
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private C1.Data.Express.C1ExpressConnection c1ExpressConnection1;
        private C1.Data.Express.C1ExpressTable c1ExpressTable1;
        private C1.Data.Express.C1ExpressTable c1ExpressTable2;
        private C1.Win.C1TrueDBGrid.C1TrueDBGrid c1TrueDBGrid1;
        private C1.Win.C1TrueDBGrid.C1TrueDBGrid c1TrueDBGrid2;
        private System.Windows.Forms.Button button1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after 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 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()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.c1ExpressConnection1 = new C1.Data.Express.C1ExpressConnection();
            this.c1ExpressTable1 = new C1.Data.Express.C1ExpressTable();
            this.c1ExpressTable2 = new C1.Data.Express.C1ExpressTable();
            this.c1TrueDBGrid1 = new C1.Win.C1TrueDBGrid.C1TrueDBGrid();
            this.c1TrueDBGrid2 = new C1.Win.C1TrueDBGrid.C1TrueDBGrid();
            this.button1 = new System.Windows.Forms.Button();
            ((System.ComponentModel.ISupportInitialize)(this.c1ExpressConnection1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.c1ExpressTable1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.c1ExpressTable2)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.c1TrueDBGrid1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.c1TrueDBGrid2)).BeginInit();
            this.SuspendLayout();
            // 
            // c1ExpressConnection1
            // 
            this.c1ExpressConnection1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Program Files\\ComponentOne Studio" +
                ".NET 2.0\\common\\Nwind.mdb;Persist Security Info=False";
            this.c1ExpressConnection1.DummyImage = ((System.Drawing.Bitmap)(resources.GetObject("c1ExpressConnection1.DummyImage")));
            this.c1ExpressConnection1.Locale = new System.Globalization.CultureInfo("en-US");
            this.c1ExpressConnection1.SerializedRelations = resources.GetString("c1ExpressConnection1.SerializedRelations");
            this.c1ExpressConnection1.BeforeFill += new C1.Data.FillEventHandler(this.c1ExpressConnection1_BeforeFill);
            this.c1ExpressConnection1.SerializedSchemaXML = this.c1ExpressConnection1.GetSchemaFromResources(resources, "c1ExpressConnection1", this);
            // 
            // c1ExpressTable1
            // 
            this.c1ExpressTable1.BindingContextCtrl = this;
            this.c1ExpressTable1.ConnectionComponent = this.c1ExpressConnection1;
            this.c1ExpressTable1.ConnectionString = "";
            this.c1ExpressTable1.DummyImage = ((System.Drawing.Bitmap)(resources.GetObject("c1ExpressTable1.DummyImage")));
            this.c1ExpressTable1.FullComponentName = "Form1.c1ExpressTable1";
            this.c1ExpressTable1.SchemaTableName = "Customers";
            this.c1ExpressTable1.TableViewName = "Customers";
            this.c1ExpressTable1.SerializedSchemaXML = this.c1ExpressTable1.GetSchemaFromResources(resources, "c1ExpressTable1", this);
            // 
            // c1ExpressTable2
            // 
            this.c1ExpressTable2.BindingContextCtrl = this;
            this.c1ExpressTable2.ConnectionComponent = this.c1ExpressConnection1;
            this.c1ExpressTable2.ConnectionString = "";
            this.c1ExpressTable2.DummyImage = ((System.Drawing.Bitmap)(resources.GetObject("c1ExpressTable2.DummyImage")));
            this.c1ExpressTable2.FullComponentName = "Form1.c1ExpressTable2";
            this.c1ExpressTable2.SchemaTableName = "Orders";
            this.c1ExpressTable2.TableViewName = "Orders";
            this.c1ExpressTable2.SerializedSchemaXML = this.c1ExpressTable2.GetSchemaFromResources(resources, "c1ExpressTable2", this);
            // 
            // c1TrueDBGrid1
            // 
            this.c1TrueDBGrid1.DataMember = "_Customers";
            this.c1TrueDBGrid1.DataSource = this.c1ExpressConnection1;
            this.c1TrueDBGrid1.GroupByCaption = "Drag a column header here to group by that column";
            this.c1TrueDBGrid1.Images.Add(((System.Drawing.Image)(resources.GetObject("c1TrueDBGrid1.Images"))));
            this.c1TrueDBGrid1.Location = new System.Drawing.Point(16, 16);
            this.c1TrueDBGrid1.Name = "c1TrueDBGrid1";
            this.c1TrueDBGrid1.PreviewInfo.Location = new System.Drawing.Point(0, 0);
            this.c1TrueDBGrid1.PreviewInfo.Size = new System.Drawing.Size(0, 0);
            this.c1TrueDBGrid1.PreviewInfo.ZoomFactor = 75;
            this.c1TrueDBGrid1.PrintInfo.PageSettings = ((System.Drawing.Printing.PageSettings)(resources.GetObject("c1TrueDBGrid1.PrintInfo.PageSettings")));
            this.c1TrueDBGrid1.Size = new System.Drawing.Size(616, 160);
            this.c1TrueDBGrid1.TabIndex = 0;
            this.c1TrueDBGrid1.Text = "c1TrueDBGrid1";
            this.c1TrueDBGrid1.PropBag = resources.GetString("c1TrueDBGrid1.PropBag");
            // 
            // c1TrueDBGrid2
            // 
            this.c1TrueDBGrid2.DataMember = "_Customers.Customers - Orders";
            this.c1TrueDBGrid2.DataSource = this.c1ExpressConnection1;
            this.c1TrueDBGrid2.GroupByCaption = "Drag a column header here to group by that column";
            this.c1TrueDBGrid2.Images.Add(((System.Drawing.Image)(resources.GetObject("c1TrueDBGrid2.Images"))));
            this.c1TrueDBGrid2.Location = new System.Drawing.Point(16, 192);
            this.c1TrueDBGrid2.Name = "c1TrueDBGrid2";
            this.c1TrueDBGrid2.PreviewInfo.Location = new System.Drawing.Point(0, 0);
            this.c1TrueDBGrid2.PreviewInfo.Size = new System.Drawing.Size(0, 0);
            this.c1TrueDBGrid2.PreviewInfo.ZoomFactor = 75;
            this.c1TrueDBGrid2.PrintInfo.PageSettings = ((System.Drawing.Printing.PageSettings)(resources.GetObject("c1TrueDBGrid2.PrintInfo.PageSettings")));
            this.c1TrueDBGrid2.Size = new System.Drawing.Size(616, 184);
            this.c1TrueDBGrid2.TabIndex = 1;
            this.c1TrueDBGrid2.Text = "c1TrueDBGrid2";
            this.c1TrueDBGrid2.PropBag = resources.GetString("c1TrueDBGrid2.PropBag");
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(248, 384);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(120, 32);
            this.button1.TabIndex = 2;
            this.button1.Text = "Show Form2";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // Form1
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(648, 428);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.c1TrueDBGrid2);
            this.Controls.Add(this.c1TrueDBGrid1);
            this.Name = "Form1";
            this.Text = "Form1";
            ((System.ComponentModel.ISupportInitialize)(this.c1ExpressConnection1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.c1ExpressTable1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.c1ExpressTable2)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.c1TrueDBGrid1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.c1TrueDBGrid2)).EndInit();
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            Form2 form = new Form2();
            form.ShowDialog();
        }

        #region Switch to C1NWind.mdb database

        private void c1ExpressConnection1_BeforeFill(object sender, C1.Data.FillEventArgs e)
        {
            if (!c1ExpressConnection1.DataSet.Filled)
            {
                UpdateDbPath();
            }
        }

        private void UpdateDbPath()
        {
            string dbPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) +
                "\\ComponentOne Samples\\Common\\C1NWind.mdb";
            if (File.Exists(dbPath))
            {
                OleDbConnectionStringBuilder csb = new OleDbConnectionStringBuilder(
                    c1ExpressConnection1.ConnectionString);
                csb.DataSource = dbPath;
                c1ExpressConnection1.ConnectionString = csb.ToString();
            }
        }

        #endregion

    }
}
