using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;

namespace Support_pedagogique_numerique
{
	/// <summary>
	/// Description résumée de Form1.
	/// </summary>
	public class Form_docbook : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Label lbl_texte_progression;
		private System.Windows.Forms.Label lbl_pct_progression;
		private System.Windows.Forms.Button btn_annuler;
		private System.Windows.Forms.Button btn_suivant;
		private System.Windows.Forms.ProgressBar barre_progression;
		/// <summary>
		/// Variable nécessaire au concepteur.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form_docbook()
		{
			//
			// Requis pour la prise en charge du Concepteur Windows Forms
			//
			InitializeComponent();
		}

		/// <summary>
		/// Nettoyage des ressources utilisées.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Code généré par le Concepteur Windows Form
		/// <summary>
		/// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
		/// le contenu de cette méthode avec l'éditeur de code.
		/// </summary>
		private void InitializeComponent()
		{
			this.panel1 = new System.Windows.Forms.Panel();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.lbl_pct_progression = new System.Windows.Forms.Label();
			this.lbl_texte_progression = new System.Windows.Forms.Label();
			this.barre_progression = new System.Windows.Forms.ProgressBar();
			this.btn_annuler = new System.Windows.Forms.Button();
			this.btn_suivant = new System.Windows.Forms.Button();
			this.panel1.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.BackColor = System.Drawing.Color.White;
			this.panel1.Controls.Add(this.label1);
			this.panel1.Location = new System.Drawing.Point(0, 0);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(744, 48);
			this.panel1.TabIndex = 0;
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(8, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(312, 24);
			this.label1.TabIndex = 0;
			this.label1.Text = "Generating DocBook files";
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.lbl_pct_progression);
			this.groupBox1.Controls.Add(this.lbl_texte_progression);
			this.groupBox1.Controls.Add(this.barre_progression);
			this.groupBox1.Location = new System.Drawing.Point(16, 72);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(712, 360);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Status";
			// 
			// lbl_pct_progression
			// 
			this.lbl_pct_progression.Location = new System.Drawing.Point(656, 200);
			this.lbl_pct_progression.Name = "lbl_pct_progression";
			this.lbl_pct_progression.Size = new System.Drawing.Size(40, 16);
			this.lbl_pct_progression.TabIndex = 2;
			this.lbl_pct_progression.Text = "0 %";
			// 
			// lbl_texte_progression
			// 
			this.lbl_texte_progression.Location = new System.Drawing.Point(72, 160);
			this.lbl_texte_progression.Name = "lbl_texte_progression";
			this.lbl_texte_progression.Size = new System.Drawing.Size(320, 24);
			this.lbl_texte_progression.TabIndex = 1;
			// 
			// barre_progression
			// 
			this.barre_progression.Location = new System.Drawing.Point(64, 192);
			this.barre_progression.Name = "barre_progression";
			this.barre_progression.Size = new System.Drawing.Size(576, 24);
			this.barre_progression.TabIndex = 0;
			// 
			// btn_annuler
			// 
			this.btn_annuler.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btn_annuler.Location = new System.Drawing.Point(624, 440);
			this.btn_annuler.Name = "btn_annuler";
			this.btn_annuler.Size = new System.Drawing.Size(80, 24);
			this.btn_annuler.TabIndex = 3;
			this.btn_annuler.Text = "Cancel";
			this.btn_annuler.Click += new System.EventHandler(this.btn_annuler_Click);
			// 
			// btn_suivant
			// 
			this.btn_suivant.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btn_suivant.Location = new System.Drawing.Point(528, 440);
			this.btn_suivant.Name = "btn_suivant";
			this.btn_suivant.Size = new System.Drawing.Size(80, 24);
			this.btn_suivant.TabIndex = 4;
			this.btn_suivant.Text = "Next >";
			this.btn_suivant.Click += new System.EventHandler(this.btn_suivant_Click);
			// 
			// Form_docbook
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(742, 478);
			this.Controls.Add(this.btn_suivant);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.panel1);
			this.Controls.Add(this.btn_annuler);
			this.Font = new System.Drawing.Font("Arial", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.Name = "Form_docbook";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Documentation index generation tool";
			this.Closed += new System.EventHandler(this.Form_docbook_Closed);
			this.panel1.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		// Cas où le fichier d'index existe déjà => on le reprend
		public void docbookExistant() 
		{
			// On cache le bouton Suivant
			btn_suivant.Enabled=false;
			// Initialisation des paramètres de la barre de progression
			barre_progression.Minimum=0;
			barre_progression.Maximum=1;
			barre_progression.Step=1;
			barre_progression.PerformStep();
			lbl_texte_progression.Text="Found existing index file. Existing parameters will be used.";
			lbl_pct_progression.Text="100 %";
			this.Refresh();
			btn_suivant.Enabled=true;	
			btn_suivant.Focus();
		}
		
		// Génération à partir de zéro
		public void demarrerGeneration()
		{
			// Début de la génération des fichiers
			// On cache le bouton Suivant
			btn_suivant.Enabled=false;
			// Initialisation des paramètres de la barre de progression
			barre_progression.Minimum=0;
			barre_progression.Maximum=3;
			barre_progression.Step=1;
			lbl_texte_progression.Text="Generating .dc files...";
			this.Refresh();
			gen.genererDc();
			//Thread.Sleep(1500);
			barre_progression.PerformStep();
			lbl_pct_progression.Text="30 %";
			lbl_texte_progression.Text="Generating .DocBook files...";
			this.Refresh();
			gen.genererDocBook();
			//Thread.Sleep(1500);
			barre_progression.PerformStep();
			lbl_pct_progression.Text="60 %";
			lbl_texte_progression.Text="Generating index.docbook...";
			this.Refresh();
			gen.genererIndexDocBook();
			barre_progression.PerformStep();
			lbl_pct_progression.Text="100 %";
			//Thread.Sleep(1500);
			// génération terminée
			lbl_texte_progression.Text="Done";
			btn_suivant.Enabled=true;	
			btn_suivant.Focus();
		}

		private void btn_annuler_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void Form_docbook_Closed(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void btn_suivant_Click(object sender, System.EventArgs e)
		{
			Form_intro.frm_params = new Form_params();
			this.Hide();
			Form_intro.frm_params.Show();
			Form_intro.frm_params.Activate();
		}
	}
}
