#region Copyright and GPL
/*************************************************************************
 * dataMagus - The open source database learning software
 * Copyright (C) 2007 by all authors
 * Authors: Monika Schwitter (monsy@gmx.ch)
 *          Jürg Zgraggen (j.zgraggen@ejaz.net)
 *          HSLU (Hochschule Luzern - Technik+Architektur)
 * 
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 * 
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU General Public License for more details.
 * 
 *     You should have received a copy of the GNU General Public License
 *     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *************************************************************************/
#endregion
#region Using
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using dataMagus.Common.PlugIn;
using dataMagus.Common.PlugIn.Generator;
#endregion

namespace dataMagus.PlugIns.Generators.SqlServer2000
{
	/// <summary>
	/// This control handels the generator options.
	/// </summary>
	public partial class OptionsControl : GeneratorControl
	{
		#region Constructors / Destructors
		/// <summary>
		/// Default constructor.
		/// </summary>
		public OptionsControl()
		{
			InitializeComponent();
		}
		#endregion

		#region Methodes
        /// <summary>
        /// Event handler.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">EventArgs</param>
		private void OptionsControlLoad(object sender, EventArgs e)
		{
            this.ForceCCForPKCheckBox.Checked = GeneratorData.Instance.ForceColumnConstraintForPrimaryKey;
            this.FKCreateRadioButton.Checked = GeneratorData.Instance.ForceForeignKeyWithCreateTable;
            this.FKAlterRadioButton.Checked = !GeneratorData.Instance.ForceForeignKeyWithCreateTable;
            this.ForceFKCCCheckBox.Enabled = GeneratorData.Instance.ForceForeignKeyWithCreateTable;
            this.ForceFKCCCheckBox.Checked = GeneratorData.Instance.ForceColumnConstraintForForeignKey;
            this.UniqueCreateTableRadioButton.Checked = GeneratorData.Instance.ForceUniqueIndexWithCreateTable;
            this.UniqueIndexRadioButton.Checked = !GeneratorData.Instance.ForceUniqueIndexWithCreateTable;
            this.ForceUniqueCCCheckBox.Enabled = GeneratorData.Instance.ForceUniqueIndexWithCreateTable;
            this.ForceUniqueCCCheckBox.Checked = GeneratorData.Instance.ForceColumnConstraintForUnique;
		}
		
        /// <summary>
        /// Event handler.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">EventArgs</param>
		private void OptionsControlLeave(object sender, EventArgs e)
		{
            GeneratorData.Instance.ForceColumnConstraintForPrimaryKey = this.ForceCCForPKCheckBox.Checked;
            GeneratorData.Instance.ForceForeignKeyWithCreateTable = this.FKCreateRadioButton.Checked;
            GeneratorData.Instance.ForceUniqueIndexWithCreateTable = this.UniqueCreateTableRadioButton.Checked;
            GeneratorData.Instance.ForceColumnConstraintForForeignKey = this.ForceFKCCCheckBox.Checked;
            GeneratorData.Instance.ForceColumnConstraintForUnique = this.ForceUniqueCCCheckBox.Checked;
		}

        /// <summary>
        /// Event handler.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">EventArgs</param>
        private void FKAlterRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.HandleForeignKeyOptions();
        }

        /// <summary>
        /// Event handler.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">EventArgs</param>
        private void FKCreateRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.HandleForeignKeyOptions();
        }

        /// <summary>
        /// Event handler.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">EventArgs</param>
        private void UniqueCreateTableRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.HandleUniqueOptions();
        }

        /// <summary>
        /// Event handler.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="e">EventArgs</param>
        private void UniqueIndexRadioButton_CheckedChanged(object sender, EventArgs e)
        {
            this.HandleUniqueOptions();
        }

        /// <summary>
        /// Handle foreign key options.
        /// </summary>
        private void HandleForeignKeyOptions()
        {
            this.ForceFKCCCheckBox.Enabled = this.FKCreateRadioButton.Checked;
        }

        /// <summary>
        /// Handle unique options.
        /// </summary>
        private void HandleUniqueOptions()
        {
            this.ForceUniqueCCCheckBox.Enabled = this.UniqueCreateTableRadioButton.Checked;
        }
		#endregion		
	}
}
