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

namespace Support_pedagogique_numerique
{
	/// <summary>
	/// Description résumée de Form_index_htm.
	/// </summary>
	public class Form_index_htm : 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_pct_progression;
		private System.Windows.Forms.Label lbl_texte_progression;
		private System.Windows.Forms.ProgressBar barre_progression;
		private System.Windows.Forms.Button btn_termine;
		/// <summary>
		/// Variable nécessaire au concepteur.
		/// </summary>
		private System.ComponentModel.Container components = null;

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

			//
			// TODO : ajoutez le code du constructeur après l'appel à 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_termine = 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 = 3;
			// 
			// 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 index page";
			// 
			// 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(15, 65);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(712, 367);
			this.groupBox1.TabIndex = 4;
			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(216, 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_termine
			// 
			this.btn_termine.Enabled = false;
			this.btn_termine.Location = new System.Drawing.Point(624, 440);
			this.btn_termine.Name = "btn_termine";
			this.btn_termine.Size = new System.Drawing.Size(80, 24);
			this.btn_termine.TabIndex = 8;
			this.btn_termine.Text = "Done";
			this.btn_termine.Click += new System.EventHandler(this.btn_termine_Click);
			// 
			// Form_index_htm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(742, 478);
			this.Controls.Add(this.btn_termine);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.panel1);
			this.Name = "Form_index_htm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Documentation index generation tool";
			this.panel1.ResumeLayout(false);
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		public void demarrerGeneration() 
		{
			// Début de la génération du fichier d'index
			// 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 index.htm...";
			this.Refresh();
			gen2.regenerer();
			barre_progression.PerformStep();
			lbl_pct_progression.Text="50%";
			this.Refresh();
			// Purge des fichiers DC et DocBook
			lbl_texte_progression.Text="Deleting .dc files...";
			this.Refresh();
			Purge.DirPurge("..\\documents", ".dc");
			barre_progression.PerformStep();
			lbl_pct_progression.Text="75%";
			this.Refresh();
			lbl_texte_progression.Text="Deleting .docbook files...";
			this.Refresh();
			Purge.DirPurge("..\\documents", ".docbook");
			barre_progression.PerformStep();
			lbl_pct_progression.Text="100%";
			this.Refresh();
			lbl_texte_progression.Text="Generation complete";
			btn_termine.Enabled=true;
		}

		private void btn_termine_Click(object sender, System.EventArgs e)
		{
			// Instance de la classe Process
			System.Diagnostics.Process proc = new System.Diagnostics.Process();
			// Nom du fichier dont l'extension est connue du shell à ouvrir
			proc.StartInfo.FileName = Config.index_htm;
			// Démarrage du processus. 
			// Notepad, si il est associé aux fichiers .txt,
			// sera lancé et ouvrira le fichier monfichier.txt
			proc.Start() ;
			// On libère les ressources dont on a plus besoin.
			proc.Close(); // Attention Close ne met pas fin au processus.
			Application.Exit();
		}
	}
}
