Ejemplo n.º 1
0
        private void LinkConsultantandManager(String filename)
        {
            File linkfile = new File(filename);

            // Extract each line of the file
            foreach (string l in linkfile.Load)
            {
                Regex rg = new Regex(@"^(?<manager>[a-zA-Z]+)/(?<consultantslist>[a-zA-Z\-]+)$");
                Match m  = rg.Match(l);
                if (m.Success)
                {
                    Console.WriteLine("[TEST] Link");
                    String managername = m.Groups["manager"].Value;
                    try
                    {
                        // find the Consultant and putt it in his Manager
                        Manager  manager     = this.Entreprise.GetManagers()[managername];
                        string[] consultants = m.Groups["consultantslist"].Value.Split('-');
                        foreach (String consultantname in consultants)
                        {
                            Consultant consultant = this.Entreprise.GetConsultants()[consultantname];
                            manager.AddConsultant(consultant);
                        }
                    }
                    catch
                    {
                        String msgERROR = "The manager :" + managername + "in the file LinkFile.txt is not find in the Entreprise";
                        Console.WriteLine(msgERROR);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void Init()
 {
     m = new Manager("Seb", "CBF", "MA01");
     s = new Client("Sam", "CL00");
     c = new Consultant("Martin", "D", m, 2017, "CO1701", s);
     l.Add(c);
 }
Ejemplo n.º 3
0
 public void Init()
 {
     d = new DateTime(2017, 05, 17);
     e = new DateTime(2017, 12, 31);
     m = new Manager("Seb", "CBF", "MA01");
     s = new Client("Sam", "CL00");
     c = new Consultant("Martin", "D", m, 2017, "CO1701", s);
     p = new Mission(s, c, d, e);
 }
Ejemplo n.º 4
0
        private void GenerateMission(String filename)
        {
            Dictionary <String, List <Mission> > consultantagenda = new Dictionary <String, List <Mission> >();
            File missionfile = new File(filename);

            // Extract each line of the file
            foreach (string c in missionfile.Load)
            {
                // Use the lines that match the pattern of the regex
                Regex rg = new Regex(@"^(?<consultant>[a-zA-Z]+)/(?<datein>[0-9]{4}\-[0-9]{2}\-[0-9]{2})/(?<dateout>[0-9]{4}\-[0-9]{2}\-[0-9]{2})/(?<client>\w+)");
                Match m  = rg.Match(c);
                if (m.Success)
                {
                    // take the consultant and the client in the lists of the entreprise
                    Consultant consultant = this.Entreprise.GetConsultants()[m.Groups["consultant"].Value];
                    Client     client     = this.Entreprise.GetClients()[m.Groups["client"].Value];

                    // Generate time in
                    string[] datein = m.Groups["datein"].Value.Split('-'); // format date year-month-day
                    DateTime In     = new DateTime();
                    In.AddYears(Int32.Parse(datein[0]));
                    In.AddMonths(Int32.Parse(datein[1]));
                    In.AddDays(Int32.Parse(datein[2]));

                    // Generate time out
                    string[] dateout = m.Groups["datein"].Value.Split('-'); // format date year-month-day
                    DateTime Out     = new DateTime();
                    Out.AddYears(Int32.Parse(dateout[0]));
                    Out.AddMonths(Int32.Parse(dateout[1]));
                    Out.AddDays(Int32.Parse(dateout[2]));

                    // Generate Mission
                    Mission mission = new Mission(In, Out, client);

                    if (consultantagenda.ContainsKey(m.Groups["consultant"].Value)) // if key in dictionary
                    {
                        consultantagenda[m.Groups["consultant"].Value].Add(mission);
                    }
                    else
                    {
                        List <Mission> listmission = new List <Mission>();
                        listmission.Add(mission);
                        consultantagenda[m.Groups["consultant"].Value] = listmission;
                    }

                    // Put Mission in the database
                    foreach (String consultantname in this.Entreprise.GetConsultants().Keys)
                    {
                        foreach (string consu in consultantagenda.Keys)
                        {
                            this.Entreprise.GetConsultants()[consultantname].SetMissionHistory(consultantagenda[consu]);
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        // Method to generate the instances of the entreprise

        //generate all the employees
        private void GenerateEmploye(String filename)
        {
            File employefile = new File(filename);

            // Extract each line of the file
            foreach (string c in employefile.Load)
            {
                // Use the lines who match the pattern of the regex
                Regex rg = new Regex(@"^(?<job>[a-zA-Z]+)/(?<firstname>[a-zA-Z]+)/(?<lastname>[a-zA-Z]+)/(?<personalaccount>[0-9]+)$");
                Match m  = rg.Match(c);
                if (m.Success)
                {
                    // Generate the consultants
                    if (m.Groups["job"].Value == "consultant")
                    {
                        int        pa         = Int32.Parse(m.Groups["personalaccount"].Value);
                        Consultant consultant = new Consultant(m.Groups["firstname"].Value, m.Groups["lastname"].Value, pa);
                        this.Entreprise.AddConsultant(consultant);
                    }

                    // Generate the directors
                    if (m.Groups["job"].Value == "director")
                    {
                        int      pa       = Int32.Parse(m.Groups["personalaccount"].Value);
                        Director director = new Director(m.Groups["firstname"].Value, m.Groups["lastname"].Value, pa);
                        this.Entreprise.AddDirector(director);
                    }
                    if (m.Groups["job"].Value == "financialdirector")
                    {
                        int pa = Int32.Parse(m.Groups["personalaccount"].Value);
                        FinancialDirector director = new FinancialDirector(m.Groups["firstname"].Value, m.Groups["lastname"].Value, pa);
                        this.Entreprise.AddDirector(director);
                    }
                    if (m.Groups["job"].Value == "humanresourcedirector")
                    {
                        int pa = Int32.Parse(m.Groups["personalaccount"].Value);
                        HumanResourcesDirector director = new HumanResourcesDirector(m.Groups["firstname"].Value, m.Groups["lastname"].Value, pa);
                        this.Entreprise.AddDirector(director);
                    }

                    // Generate the managers
                    if (m.Groups["job"].Value == "manager")
                    {
                        int     pa      = Int32.Parse(m.Groups["personalaccount"].Value);
                        Manager manager = new Manager(m.Groups["firstname"].Value, m.Groups["lastname"].Value, pa);
                        this.Entreprise.AddManager(manager);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public Mission(Client client, Consultant consultant,
                DateTime startDate, DateTime endDate)
 {
     this.startDate  = startDate;
     this.endDate    = endDate;
     this.client     = client;
     this.consultant = consultant;
     startYear       = startDate.Year;
     endYear         = endDate.Year;
     try
     {
         consultant.AddMission(this);
         client.AddMission(this);
     }
     catch
     {
         Console.WriteLine("Error when loading the mission {0}, {1}, from {2} to {3}",
                           Client.Name, Consultant, startDate.ToString("dd/MM/yyyy"), endDate.ToString("dd/MM/yyyy"));
         Console.WriteLine(" ");
     }
 }
Ejemplo n.º 7
0
 public void AddConsultant(Consultant consultant)
 {
     this.Consultants.Add(consultant.ToString(), consultant);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// internal method used to add consultant to the managers list
 /// </summary>
 /// <param name="consultant"></param>
 public void AddConsultant(Consultant consultant)
 {
     bossOf.Add(consultant);
 }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            /**
             * Load from the input files
             */
            //READ DIRCTOR
            List <Directeur> di = new List <Directeur>();
            List <Manager>   ma = new List <Manager>();
            List <Client>    ci = new List <Client> {
                new Client("Entreprise", "CL00")
            };
            DF  difin  = null;
            DRH direhu = null;

            string[] lines = null;
            try
            {
                lines = System.IO.File.ReadAllLines(@"../../../inputDir.txt");
            }
            catch
            {
                Console.WriteLine("Error of loading directors");
            }
            string patternDI = @"^D[IFH] \w+ \w+$";
            Regex  rgxDI     = new Regex(patternDI);

            foreach (string line in lines)
            {
                if (rgxDI.IsMatch(line))
                {
                    string[] words = line.Split(' ');

                    if (words[0] == "DI")
                    {
                        Directeur directeur = new Directeur(words[1], words[2]);
                        di.Add(directeur);
                    }

                    if (words[0] == "DF")
                    {
                        difin = new DF(words[1], words[2]);
                        di.Add(difin);
                    }

                    if (words[0] == "DH")
                    {
                        direhu = new DRH(words[1], words[2]);
                        di.Add(direhu);
                    }
                }
            }

            //READ MANAGERS

            try
            {
                lines = System.IO.File.ReadAllLines(@"../../../inputMan.txt");
            }
            catch
            {
                Console.WriteLine("Error of loading managers");
            }

            string patternMA = @"^\w+ \w+ MA\d+$";
            Regex  rgxMA     = new Regex(patternMA);

            foreach (string line in lines)
            {
                if (rgxMA.IsMatch(line))
                {
                    string[] words   = line.Split(' ');
                    Manager  manager = new Manager(words[0], words[1], words[2]);
                    ma.Add(manager);
                }
            }

            //READ CLIENTS
            try
            {
                lines = System.IO.File.ReadAllLines(@"../../../inputCli.txt");
            }
            catch
            {
                Console.WriteLine("Error of loading clients");
            }

            string patternCI = @"^\w+ CL\d+$";
            Regex  rgxCI     = new Regex(patternCI);

            foreach (string line in lines)
            {
                if (rgxCI.IsMatch(line))
                {
                    string[] words  = line.Split(' ');
                    Client   client = new Client(words[0], words[1]);
                    ci.Add(client);
                }
                else
                {
                    Console.WriteLine("merde");
                }
            }

            //READ CONSULTANTS
            try
            {
                lines = System.IO.File.ReadAllLines(@"../../../inputCon.txt");
            }
            catch
            {
                Console.WriteLine("Error of loading consultants");
            }

            string patternCO = @"^\w+ \w+ MA\d+ \d{2}(?:\d{2}) CO($1)\d+$";
            Regex  rgxCO     = new Regex(patternCO);

            foreach (string line in lines)
            {
                string[] words   = line.Split(' ');
                Manager  manager = null;
                //if (rgxCO.IsMatch(line))
                //{
                foreach (Manager man in ma)
                {
                    if (man.Matricule == words[2])
                    {
                        manager = man;
                    }
                }
                //}
                Consultant consultant = new Consultant(words[0], words[1], manager, Int32.Parse(words[3]), words[4], ci[0]);
            }


            //READ MISSION
            try
            {
                lines = System.IO.File.ReadAllLines(@"../../../inputMis.txt");
            }

            catch
            {
                Console.WriteLine("Error of loading missions");
            }

            //string patternMI = @"^CL\d+ CO\d{2}\d+ (((31-((0[13578])|(1[02])))|([012]\d)-((0\d)|(1[012]))|(30-((0[13456789])|1[012])))-\d{4}) (((31-((0[13578])|(1[02])))|([012]\d)-((0\d)|(1[012]))|(30-((0[13456789])|1[012])))-\d{4})$";
            //Regex rgxMI = new Regex(patternMI);

            foreach (string line in lines)
            {
                string[] words   = line.Split(' ');
                string[] datein  = words[2].Split('-');
                string[] dateout = words[3].Split('-');
                DateTime DateIn  = new DateTime(Int32.Parse(datein[2]), Int32.Parse(datein[1]), Int32.Parse(datein[0]));
                DateTime DateOut = new DateTime(Int32.Parse(dateout[2]), Int32.Parse(dateout[1]), Int32.Parse(dateout[0]));

                Client     client     = null;
                Consultant consultant = null;

                foreach (Client cli in ci)
                {
                    if (cli.Matricule == words[0])
                    {
                        client = cli;
                    }
                }

                foreach (Manager man in ma)
                {
                    foreach (Consultant con in man.GetSubs)
                    {
                        if (con.Matricule == words[1])
                        {
                            consultant = con;
                        }
                    }
                }
                try
                {
                    new Mission(ci[0], consultant, consultant.GetMissions(DateIn.Year).Last().EndDate.AddDays(1), DateIn.AddDays(-1));
                }
                catch (KeyNotFoundException)
                {
                    //no mission in the consultant yet
                }
                if (DateIn.Year == DateOut.Year)
                {
                    new Mission(client, consultant, DateIn, DateOut);
                }
                else
                {
                    DateTime DateOutbis = new DateTime(DateIn.Year, 12, 31);
                    new Mission(client, consultant, DateIn, DateOutbis);
                    DateTime DateInbis = new DateTime(DateOutbis.AddYears(1).Year, 01, 01);
                    int      c         = 0;
                    while (DateInbis.AddYears(c).Year < DateOut.Year)
                    {
                        c++;
                        new Mission(client, consultant, DateInbis.AddYears((c - 1)), DateOutbis.AddYears(c));
                    }
                    new Mission(client, consultant, DateInbis.AddYears(c), DateOut);
                }
            }

            // ##Display the elements of the variables created (tree)

            /*
             * Console.ReadKey();
             * Console.Clear();
             * foreach(Directeur dir in di)
             * {
             *   Console.WriteLine(dir);
             * }
             * Console.WriteLine(direhu);
             * Console.WriteLine(difin);
             * foreach (Manager man in ma)
             * {
             *   Console.WriteLine(man);
             *   foreach (Consultant con in man.GetSubs)
             *   {
             *       Console.Write("----|");
             *       Console.WriteLine(con);
             *   }
             * }
             * foreach(Client cli in ci)
             * {
             *   Console.WriteLine(cli.Name);
             *   foreach (List<Mission> miss in cli.Missions.Values)
             *   {
             *       foreach(Mission mis in miss)
             *       {
             *           Console.Write(mis.EndDate.Year + "----|");
             *           Console.WriteLine(mis.Consultant);
             *       }
             *   }
             * }
             *
             * Console.ReadKey();
             */

            //UI
            bool S = true;

            while (S)
            {
                Console.Clear();
                Console.WriteLine("Select a mod (enter the number of your selection)");
                Console.WriteLine(" ");
                Console.WriteLine("1. Get report of a manager");
                Console.WriteLine("2. Get report of the Human Resources Director");
                Console.WriteLine("3. Get report of the financial director");
                Console.WriteLine(" ");
                Console.WriteLine("enter q to quit");
                Console.WriteLine(" ");
                string sel = Console.ReadLine();

                if (sel == "1")
                {
                    Console.Clear();
                    Console.WriteLine("Select a manager");
                    Console.WriteLine(" ");

                    int count = 0;
                    foreach (Manager man in ma)
                    {
                        count++;
                        Console.WriteLine(count.ToString() + ". " + man.ToString());
                    }
                    bool M = true;
                    while (M)
                    {
                        try
                        {
                            Console.WriteLine(" ");
                            sel = Console.ReadLine();
                            ma[Int32.Parse(sel) - 1].GenerateReport();
                            Console.WriteLine(" ");
                            Console.WriteLine("Report generated");
                            Console.ReadKey();
                            M = false;
                        }
                        catch
                        {
                            Console.WriteLine(" ");
                            Console.WriteLine("Please select a manager");
                        }
                    }
                    sel = null;
                }

                if (sel == "2")
                {
                    Console.Clear();
                    Console.WriteLine("Select a client");
                    Console.WriteLine(" ");

                    int count = 0;
                    foreach (Client cli in ci)
                    {
                        count++;
                        Console.WriteLine(count.ToString() + ". " + cli.Name);
                    }
                    bool F = true;
                    while (F)
                    {
                        try
                        {
                            Console.WriteLine(" ");
                            sel = Console.ReadLine();
                            direhu.GenerateReport(ci[Int32.Parse(sel) - 1]);
                            Console.WriteLine(" ");
                            Console.WriteLine("Report generated");
                            Console.ReadKey();
                            F = false;
                        }
                        catch
                        {
                            Console.WriteLine(" ");
                            Console.WriteLine("Please select a client");
                        }
                    }
                    sel = null;
                }

                if (sel == "3")
                {
                    Console.Clear();
                    Console.WriteLine("Enter a year completed");
                    Console.WriteLine(" ");
                    bool H = true;
                    while (H)
                    {
                        try
                        {
                            sel = Console.ReadLine();
                            if (Int32.Parse(sel) != DateTime.Now.Year)
                            {
                                difin.GenerateReport(di, ma, Int32.Parse(sel));
                                Console.WriteLine(" ");
                                Console.WriteLine("Report generated");
                                Console.ReadKey();
                                H = false;
                            }
                            else
                            {
                                Console.WriteLine(" ");
                                Console.WriteLine("Please enter a year completed");
                                Console.WriteLine(" ");
                            }
                        }
                        catch
                        {
                            Console.WriteLine(" ");
                            Console.WriteLine("Please enter a year completed");
                            Console.WriteLine(" ");
                        }
                    }
                    sel = null;
                }

                if (sel == "q" || sel == "Q")
                {
                    S = false;
                }
            }
        }
Ejemplo n.º 10
0
        // Method

        public void AddConsultant(Consultant consultant)
        {
            //Assert that consultant is not already contained in Consultants Dictionary
            //BEWARE: Currently Shallow copy of consultant object=> can create problems!!!
            this.Consultants.Add(consultant.GetFirstname() + consultant.GetLastname(), consultant);
        }