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

using VW = Howest.SchemaDiscovery.DbObjects.View;
using System.Diagnostics;

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

		private void Form2_Load(object sender, EventArgs e)
		{
			System.Threading.ThreadPool.QueueUserWorkItem(new System.Threading.WaitCallback(FillTree));
		}

		void FillTree(object state)
		{
			if (this.InvokeRequired)
			{
				Invoke(new System.Threading.WaitCallback(FillTree), new object[] { null });
				return;
			}
			ConnectionStringSettings settings = ConfigurationManager.ConnectionStrings["demo"];
			objectTree1.Settings = settings;
		}

		private void btnGetSelection_Click(object sender, EventArgs e)
		{
			Debug.WriteLine("[Tables]");
			List<Table> tables = objectTree1.SelectedTables;

			foreach (Table tab in tables)
			{
				WriteTableToDebug(tab);
			}

			Debug.WriteLine("[Views]");
			List<VW> views = objectTree1.SelectedViews;

			foreach (VW vw in views)
			{
				WriteTableToDebug(vw);
			}
		}

		void WriteTableToDebug(Table tab)
		{
			Debug.WriteLine("Object Name: " + tab.Name);
			foreach (Column col in tab.Columns)
			{
				Debug.WriteLine("  Column name: " + col.Name);
			}
		}
	}
}