/// <summary>
        /// Va retourner les infos d'une tâche sous forme de tableau,
        /// cela est utilisé pour l'affichage dans différents écrans.
        /// </summary>
        /// <param name="task">Task : Tâche dont on souhaite obtenir les informations</param>
        /// <returns>un tableau contenant le jour de la tâche, et les informations sur cette dernière</returns>
        public string[] TaskInfo(Task task)
        {
            string[] arr = new string[5];

            arr[0] = "";
            arr[1] = this.ToString();
            arr[2] = task.FormatHour(task.StartHour);
            int EndTask = task.StartHour + task.DurationMinute;
            arr[3] = task.FormatHour(EndTask);
            arr[4] = task.Name;
            return arr;
        }
        public void TaskInfoTest()
        {
            int NumberDay = 0; // TODO: initialisez à une valeur appropriée
            Day target = new Day(NumberDay); // TODO: initialisez à une valeur appropriée
            List<Astronaut> a = new List<Astronaut>();
            Activity act = new Activity("Test");
            Task task = new Task(act,a,50,50,10,10); // TODO: initialisez à une valeur appropriée

            string[] expected = { "", target.ToString(), "0H50", "1H40", task.Name }; // TODO: initialisez à une valeur appropriée
            string[] actual;
            actual = target.TaskInfo(task);
            CollectionAssert.AreEqual(expected, actual);
        }
 public void getInfoTest()
 {
     Activity Tactivity = new Activity("Test");
     List<Astronaut> Tastronauts = new List<Astronaut>();
     int DureeMinute = 120; // TODO: initialisez à une valeur appropriée
     int StartHour = 130; // TODO: initialisez à une valeur appropriée
     int X = 0; // TODO: initialisez à une valeur appropriée
     int Y = 0; // TODO: initialisez à une valeur appropriée
     Task target = new Task(Tactivity, Tastronauts, DureeMinute, StartHour, X, Y);
     string[] expected = { "", target.FormatHour(StartHour), target.FormatHour(DureeMinute + StartHour), target.Name };
     string[] actual;
     actual = target.getInfo();
     CollectionAssert.AreEqual(expected, actual);
 }
 public void FormatHourTest()
 {
     Activity Tactivity = new Activity("Test"); // TODO: initialisez à une valeur appropriée
     List<Astronaut> Tastronauts = new List<Astronaut>(); // TODO: initialisez à une valeur appropriée
     int DureeMinute = 130; // TODO: initialisez à une valeur appropriée
     int StartHour = 150; // TODO: initialisez à une valeur appropriée
     int X = 0; // TODO: initialisez à une valeur appropriée
     int Y = 0; // TODO: initialisez à une valeur appropriée
     Task target = new Task(Tactivity, Tastronauts, DureeMinute, StartHour, X, Y); // TODO: initialisez à une valeur appropriée
     int Time = DureeMinute+StartHour ; // TODO: initialisez à une valeur appropriée
     string expected = "4H40"; // TODO: initialisez à une valeur appropriée
     string actual;
     actual = target.FormatHour(Time);
     Assert.AreEqual(expected, actual);
 }
        /// <summary>
        /// Constructeur de taskView va renseigner l'ensemble des champs en fonction de la tâche entré en paramètre
        /// </summary>
        /// <param name="task">Task : Tâche dont on veut connaitre les informations</param>
        public TaskView(Task task)
        {
            InitializeComponent();
            this.task = task;

            this.ActivityName.Text =  task.Name;
            this.richTextBoxDescription.Text = task.Description;

            int StartHour = task.StartHour / 60;
            int StartMinutes = task.StartHour % 60;

            if (StartHour == 0)
                this.StartHour.Text = "00";
            else
                this.StartHour.Text = StartHour.ToString();

            if (StartMinutes == 0)
                this.StartMinutes.Text = "00";
            else
                this.StartMinutes.Text = StartMinutes.ToString();

            int EndHour = (task.StartHour + task.DurationMinute) / 60;
            int EndMinutes = (task.StartHour + task.DurationMinute) % 60;

            if (EndHour == 0)
                this.EndHour.Text = "00";
            else
                this.EndHour.Text = EndHour.ToString();

            if (EndMinutes == 0)
                this.EndMinutes.Text = "00";
            else
                this.EndMinutes.Text = EndMinutes.ToString();

            foreach (Astronaut A in task.Astronauts)
            {
                AstronautView.Items.Add(A.Name);
            }
        }
        /// <summary>
        /// Se déclenche après le clic sur le bouton Addtask
        /// Va lancer le processus pour ajouter une tâche à une journée
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonAddTask_Click_1(object sender, EventArgs e)
        {
            int jour = listCalendar.SelectedNode.Index;
            TaskForm AddTask = new TaskForm(Astronauts, Categories, "adding", PlanningMission.Calendar[jour],Map, this.xOrigin, this.yOrigin);

            if(AddTask.ShowDialog() == DialogResult.OK)
            {
                Activity newAct = AddTask.ActivitySend;
                List<Astronaut> AstronautNew = AddTask.SelectedAstronaut;
                int Duration = AddTask.MinuteDurationSend;
                int startHour = AddTask.MinuteStartSend;
                string DescriptionTask = AddTask.Description;
                int XPosition = AddTask.xMap;
                int YPosition = AddTask.yMap;

                Task newTask = new Task(newAct, AstronautNew, Duration, startHour,DescriptionTask,XPosition,YPosition);
                int numDay = listCalendar.SelectedNode.Index;
                PlanningMission.Calendar[numDay].AddTask(newTask);
                this.majDayPlanning();

            }
        }
        /// <summary>
        /// Action qui se lance après avoir cliqué sur New dans la barre de menu en haut
        /// Va lancer le processus nécessaire à une nouvelle mission
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void newPlanningToolStripMenuItem_Click(object sender, EventArgs e)
        {
            PlanningMission = new Planning();

            if(NewMission())
            {
                foreach (Astronaut a in Astronauts)
                {
                    AstronautList.Items.Add(a.Name);
                    AstronautList.SelectedIndex = 0;
                }

                CurrentDay = MajTime();
                foreach (Day day in PlanningMission.Calendar)
                {
                    TreeNode MyNode;
                    if (day.NumberDay < CurrentDay)
                    {
                        MyNode = listCalendar.Nodes.Add(day.ToString());

                        MyNode.BackColor = Color.LightGray;
                    }
                    else if (day.NumberDay == CurrentDay + 1)
                    {
                        MyNode = listCalendar.Nodes.Add(day.ToString());

                        MyNode.BackColor = Color.Green;
                    }
                    else
                    {
                        MyNode = listCalendar.Nodes.Add(day.ToString());

                        MyNode.BackColor = Color.LightBlue;
                    }

                    List<Activity> Activities = Categories.Find(x => x.Name == "Living").Activities;

                    Activity sleep = Activities.Find(x => x.Name == "Sleeping");
                    Activity eat = Activities.Find(x => x.Name == "Eating");
                    Activity privateActivity = Activities.Find(x => x.Name == "Private");

                    List<Astronaut> astroSleep1 = Astronauts.ToList();
                    Task sleep1 = new Task(sleep, astroSleep1, 420, 0, this.xOrigin, this.yOrigin);

                    List<Astronaut> astroEat = Astronauts.ToList();
                    Task eat1 = new Task(eat, astroEat, 60, 420, this.xOrigin, this.yOrigin);

                    List<Astronaut> astroPV1 = Astronauts.ToList();
                    Task private1 = new Task(privateActivity, astroPV1, 240, 480, this.xOrigin, this.yOrigin);

                    List<Astronaut> astroEat2 = Astronauts.ToList();
                    Task eat2 = new Task(eat, astroEat2, 120, 720, this.xOrigin, this.yOrigin);

                    List<Astronaut> astroPV2 = Astronauts.ToList();
                    Task private2 = new Task(privateActivity, astroPV2, 300, 840, this.xOrigin, this.yOrigin);

                    List<Astronaut> astroEat3 = Astronauts.ToList();
                    Task eat3 = new Task(eat, astroEat3, 120, 1140, this.xOrigin, this.yOrigin);

                    List<Astronaut> astroPV3 = Astronauts.ToList();
                    Task private3 = new Task(privateActivity, astroPV3, 120, 1260, this.xOrigin, this.yOrigin);

                    List<Astronaut> astroSleep2 = Astronauts.ToList();
                    Task sleep2 = new Task(sleep, astroSleep2, 100, 1380, this.xOrigin, this.yOrigin);

                    day.AddTask(sleep1);
                    day.AddTask(eat1);
                    day.AddTask(private1);
                    day.AddTask(eat2);
                    day.AddTask(private2);
                    day.AddTask(eat3);
                    day.AddTask(private3);
                    day.AddTask(sleep2);
                }

                listCalendar.SelectedNode = listCalendar.Nodes[0];
            }
        }
        /// <summary>
        /// Va lire un fichier Xml contenant un planning de mission enregistré
        /// </summary>
        /// <param name="Path">Le chemin vers le fichier Xml</param>
        private void LoadMission(string Path)
        {
            XmlDocument file = new XmlDocument();
            this.PlanningMission = new Planning();
            PlanningMission.Calendar.Clear();

            try
            {
                file.Load(Path);

                XmlNode root = file.DocumentElement;

                XmlNode Start = root.SelectSingleNode("StartMission");
                XmlNode Year = Start.SelectSingleNode("Year");
                XmlNode Month = Start.SelectSingleNode("Month");
                XmlNode Day = Start.SelectSingleNode("Day");

                this.StartMission = new DateTime(int.Parse(Year.InnerText), int.Parse(Month.InnerText), int.Parse(Day.InnerText));

                XmlNodeList Days = root.SelectNodes("Day");

                foreach (XmlNode d in Days)
                {
                    XmlNode Number = d.SelectSingleNode("Number");
                    XmlNode ReportDay = d.SelectSingleNode("Report");
                    String Report = ReportDay.InnerText;

                    Day newDay = new Day(int.Parse(Number.InnerText),Report);

                    XmlNodeList Tasks = d.SelectNodes("Task");

                    foreach (XmlNode n in Tasks)
                    {
                        XmlNode LoadActivity = n.SelectSingleNode("TaskName");
                        String ActivityName = LoadActivity.InnerText;
                        Activity newActivity = null;

                        XmlNode StartHourLoad = n.SelectSingleNode("StartHour");
                        int StartHour = int.Parse(StartHourLoad.InnerText);

                        XmlNode DurationLoad = n.SelectSingleNode("Duration");
                        int Duration = int.Parse(DurationLoad.InnerText);

                        XmlNode PositionXLoad = n.SelectSingleNode("PositionX");
                        int PositionX = int.Parse(PositionXLoad.InnerText);

                        XmlNode PositionYLoad = n.SelectSingleNode("PositionY");
                        int PositionY = int.Parse(PositionYLoad.InnerText);

                        foreach (Activity c in this.Categories)
                        {
                            if(newActivity == null)
                                newActivity = c.Activities.Find(x => x.Name == ActivityName);

                        }

                        XmlNode AstronautsXml = n.SelectSingleNode("Astronauts");
                        XmlNodeList AstronautsListXml = AstronautsXml.SelectNodes("Astronaut");

                        List<Astronaut> newAstronaut = new List<Astronaut>();
                        foreach (XmlNode astro in AstronautsListXml)
                        {
                            Astronaut a = this.Astronauts.Find(x => x.Name == astro.InnerText);
                            if(a != null)
                            {
                                newAstronaut.Add(a);
                            }
                        }

                        XmlNode DescriptionTask = n.SelectSingleNode("Description");
                        String Description = DescriptionTask.InnerText;

                        if(newActivity == null)
                        {
                            MessageBox.Show("No Activity Found");
                        }

                        Task newTask = new Task(newActivity, newAstronaut, Duration, StartHour, Description, PositionX, PositionY);
                        newDay.AddTask(newTask);
                    }
                    PlanningMission.Calendar.Add(newDay);
                }

                foreach (Astronaut a in Astronauts)
                {
                    AstronautList.Items.Add(a.Name);
                    AstronautList.SelectedIndex = 0;
                }
                CurrentDay = MajTime();
                foreach (Day day in PlanningMission.Calendar)
                {
                    TreeNode MyNode;
                    if (day.NumberDay < CurrentDay)
                    {
                        MyNode = listCalendar.Nodes.Add(day.ToString());

                        MyNode.BackColor = Color.LightGray;
                    }
                    else if (day.NumberDay == CurrentDay)
                    {
                        MyNode = listCalendar.Nodes.Add(day.ToString());

                        MyNode.BackColor = Color.Green;
                    }
                    else
                    {
                        MyNode = listCalendar.Nodes.Add(day.ToString());

                        MyNode.BackColor = Color.LightBlue;
                    }

                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message);
            }
            listCalendar.SelectedNode = listCalendar.Nodes[CurrentDay-1];
        }
 /// <summary>
 /// Va retirer les Astronaute d'une tâche
 /// </summary>
 /// <param name="t">Tâche dont on souhaite enlever des astronautes</param>
 /// <param name="Astronauts">Astronautes à retirer</param>
 private void Delete(Task t, List<Astronaut> Astronauts)
 {
     foreach (Astronaut A in Astronauts)
     {
         t.Astronauts.Remove(A);
     }
 }
 /// <summary>
 /// Ajoute une tâche à la journée sélectionnée
 /// </summary>
 /// <param name="t">Task : La tâche que l'on souhaite ajouter</param>
 public void AddTask(Task t)
 {
     Tasks.Add(t);
     OrderTask();
 }