using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using Howest.SchemaDiscovery.DbObjects;
using System.Globalization;
using System.Configuration;

namespace Howest.SchemaDiscovery.Presentation
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			//DbSchemaProvider provider = DbSchemaProviderFactory.CreateProvider("System.Data.SqlClient");

			//using (SqlConnection con = new SqlConnection("Data Source=localhost;Initial Catalog=SchemaTest;Integrated Security=true;"))
			//{
			//    con.Open();
			//    //List<Table> tables = provider.GetTables(con);
			//    string tableName = "DoublePKRefTable";
			//    string schema = "dbo";
			//    string[] restrictions = new string[4] { null, null, tableName, null };
			//    DataTable foreignKeys = con.GetSchema("ForeignKeys", restrictions);

			//    //string text1 = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE where table_schema = '{0}' and table_name = '{1}'", schema, tableName);
			//    string text1 = string.Format(CultureInfo.CurrentCulture, "SELECT * FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE where table_schema = '{0}' and table_name = '{1}'", schema, tableName);
			//    SqlDataAdapter da = new SqlDataAdapter(text1, con);

			//    DataTable schemaTable = new DataTable();
			//    da.Fill(schemaTable);

			//    dataGridView1.DataSource = foreignKeys;
			//    dataGridView2.DataSource = schemaTable;

			//}
			DbSchemaDiscoverer disc = new DbSchemaDiscoverer(ConfigurationManager.ConnectionStrings["demo"]);

			List<Parameter> pars = disc.DiscoverSqlResultSet("SELECT * FROM [tblAlbum] WHERE [albumID] = @albumid");

			foreach (Parameter par in pars)
			{
				MessageBox.Show(par.Name + " " + par.DbDataType.Type.ToString());
			}

			Form3 frm = new Form3();
			frm.ShowDialog(this);
		}
	}
}