Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            //DateTime Date19eme= new DateTime(2010, 11, 10);
            //DateTime DateDeNaissance = new DateTime(1984, 11, 10);
            //int age = DateTime.Now.Year - DateDeNaissance.Year;
            //Console.WriteLine(Salarie.MatriculeVerif("12aer56") == true);
            //Console.WriteLine(Salarie.PrenomVerif("romain") == true);
            //Console.WriteLine(Salarie.TauxVerif(0.4) == true);
            //Console.WriteLine(Salarie.DateNaissanceVerif(DateDeNaissance) == true);
            //Console.WriteLine(Salarie.DateNaissanceVerif(Date19eme) == true);
            //Console.WriteLine(DateDeNaissance);
            // Console.WriteLine(age);
            //Console.WriteLine("nb de salariés: {0}", Salarie.Compteur);
            //Salarie Salarie1 = new Salarie("12aze56", "sire", "romain");
            //Salarie salarie2 = new Salarie("12zer98", "picard", "fernand");
            //Salarie Salarie3 = new Salarie("12aze56", "durand", "Gilles");
            //Console.WriteLine(Salarie1.Matricule);
            // Console.WriteLine("prenom du salarié 2: {0}, nom: {1}, matricule: {2}",salarie2.Prenom, salarie2.Nom, salarie2.Matricule);

            //  Console.WriteLine("nb de salariés: {0}",Salarie.Compteur);
            // Console.WriteLine(Salarie1.ToString());
            Commercial commercial1 = new Commercial(100000, 0.25, "12aze65", "dupont", "roger", 50000, 0.1);
            Commercial commercial2 = new Commercial(100000, 0.50, "96azf00", "dupont", "roger", 50000, 0.1);

            Console.WriteLine(commercial1.CalculerSalaireNet());
            string test1 = commercial2.ToString();

            Console.WriteLine(test1);
        }
Ejemplo n.º 2
0
        static void Polymorphe1()
        {
            Salarie sal1 = new Salarie("Bost", "Vincent", "96AAA11");

            Commercial com1 = new Commercial("Bost", "Vincent", "96AAA11", 10000, 0.10m)
            {
                SalaireBrut = 3500.00m,
                TauxCS      = 0.35m
            };

            Console.WriteLine("Salaire commercial attendu {0} obtenu {1} assertion {2} ", 3275, com1.SalaireNet, 3275 == com1.SalaireNet);
            Console.WriteLine("Détails : {0}", com1.ToString());
            Console.ReadLine();
        }
Ejemplo n.º 3
0
        private static void Test()
        {
            Console.WriteLine("Test de la méthode vérification Matricule");
            Console.WriteLine
                ($"Test nom vide {Salarie.IsMatriculeValide("") == false})");
            Console.WriteLine
                ($"Test longueur > 7 {Salarie.IsMatriculeValide("12345678") == false})");
            Console.WriteLine
                ($"Test caractère spécial {Salarie.IsMatriculeValide("12&FT78") == false})");
            Console.WriteLine
                ($"Test non digit {Salarie.IsMatriculeValide("A2EFT78") == false})");
            Console.WriteLine
                ($"Test nom vide {Salarie.IsMatriculeValide("12EFT78") == true})");

            try
            {
                Salarie sal = new Salarie("Bost", "Vincent", "12aaa55");
                sal.DateNaissance = new DateTime(2000, 05, 29);
                sal.SalaireBrut   = 1980.25m;
                sal.TauxCS        = .30m;
                Salarie sal1 = new Salarie(sal);
                sal1.DateNaissance = new DateTime(2000, 05, 29);
                sal1.SalaireBrut   = 1980.25m;
                sal1.TauxCS        = .30m;
                Salarie sal2 = new Salarie("Bost", "Vincent", "12aaa55");
                sal2.DateNaissance = new DateTime(2000, 05, 29);
                sal2.SalaireBrut   = 1980.25m;
                sal2.TauxCS        = .30m;
                Salarie sal3 = new Salarie("Peyramard", "Florian", "25bbb55");
                Console.WriteLine(@"Le salarié {0} {1} a été créé et son salaire net est de {2:n} euros", sal.Prenom, sal.Nom, sal.SalaireNet);
                Console.WriteLine("Etape 1 Le nombre d'instances en mémoire de salariés est de {0}", Salarie.NombreInstances);
                Console.WriteLine("Appuyez sur la touche Entrée pour détruire la référence au salarié");
                // Console.ReadLine();
                bool verif    = sal.Equals(sal2);
                int  hashcode = sal3.GetHashCode();
                // Console.WriteLine($"equal,{hashcode}");
                // string str = sal.ToString();
                // Console.WriteLine(str);

                Commercial c1 = new Commercial("Dupond", "Michel", "56rrr99");
                Console.WriteLine(c1.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
        static void Main(string[] args)
        {
            #region Initialisation


            Salarie salarie1 = new Salarie();
            //Salarie salarie2 = salarie1;
            #endregion

            #region Test
            //test pour valeurs correctes
            salarie1.Matricule     = "12abc67";
            salarie1.Nom           = "vignot";
            salarie1.Prenom        = "guillaume";
            salarie1.SalaireBrut   = 1700;
            salarie1.TauxCS        = 0.21m;
            salarie1.DateNaissance = new DateTime(1985, 07, 13);


            //test pour valeurs incorrectes(premier test)
            //salarie1.Matricule = "12a6c67";
            //salarie1.Nom = "vignot1";
            //salarie1.Prenom = "0";
            //salarie1.SalaireBrut = 1700a;
            //salarie1.TauxCS = 0.7m;
            //salarie1.DateNaissance = new DateTime(1285, 07, 13);

            //test pour valeurs incorrectes(deuxieme test)
            //salarie1.Matricule = "0";
            //salarie1.Nom = "";
            //salarie1.Prenom = "ab";
            //salarie1.SalaireBrut = 0;
            //salarie1.TauxCS = 0.9m;
            //salarie1.DateNaissance = new DateTime(1285, 07, 13);


            //test pour valeurs incorrectes(deuxieme test)
            //salarie1.Matricule = "";
            //salarie1.Nom = "";
            //salarie1.Prenom = "ab";
            //salarie1.SalaireBrut = 0;
            //salarie1.TauxCS = 0.9m;
            //salarie1.DateNaissance = new DateTime(2010, 07, 13);
            #endregion

            #region Salarie 1
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" SALARIE 1 ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Info complete du salarié 1");
            Console.WriteLine(" Nom: {0}\n Prenom: {1}\n Date de naissance: {2}\n Age: {3} ans \n Matricule: {4}\n Salaire Brut: {5} euros \n Taux des charges: {6} % \n Salaire net: {7} euros ", salarie1.Nom, salarie1.Prenom, salarie1.DateNaissance, salarie1.Age, salarie1.Matricule, salarie1.SalaireBrut, (salarie1.TauxCS * 100), salarie1.SalaireNet);

            Console.WriteLine(salarie1.ToString());

            Console.WriteLine("HashCode = {0} ", salarie1.GetHashCode());


            #endregion

            #region Salarie 2
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" SALARIE 2 ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;


            Console.WriteLine("Info  du salarié 2 copié du 1");
            Salarie salarie2 = new Salarie(salarie1);
            Console.WriteLine(salarie2.Nom);

            Console.WriteLine(salarie2.ToString());



            #endregion

            #region Salarie 3

            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" SALARIE 3 ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Info  du salarie3 copié du 1 avec modif (nom, prenom ,matricule)");
            Salarie salarie3 = new Salarie(salarie1)
            {
                Nom = "salarie", Prenom = "quatre", Matricule = "11xxx22"
            };
            Console.WriteLine(salarie3.Nom);
            Console.WriteLine(salarie3.Prenom);
            Console.WriteLine(salarie3.Matricule);

            Console.WriteLine(salarie3.ToString());



            #endregion

            #region Salarie 4
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" SALARIE 4 ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Info  du salarié 4  (identique au 5 pour test hash) ");
            Salarie salarie4 = new Salarie("12abc67", "pierre");

            Console.WriteLine(salarie4.ToString());

            Console.WriteLine("HashCode du nom du salarie 4 = {0} ", salarie4.Nom.GetHashCode());
            Console.WriteLine("HashCode du matricule du salarie 4 = {0} ", salarie4.Matricule.GetHashCode());
            Console.WriteLine("HashCode du salarie 4 (complet) = {0} ", salarie4.GetHashCode());


            #endregion

            #region Salarie 5
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" SALARIE 5 ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Info  du salarié 5 (identique au 4 pour test hash) ");
            Salarie salarie5 = new Salarie("12abc67", "pierre");
            Console.WriteLine("nom {0}", salarie5.Nom);

            Console.WriteLine(salarie5.ToString());

            Console.WriteLine("HashCode du nom du salarie 5 = {0} ", salarie5.Nom.GetHashCode());
            Console.WriteLine("HashCode du matricule du salarie 5 = {0} ", salarie5.Matricule.GetHashCode());
            Console.WriteLine("HashCode du salarie 5 (complet) = {0} ", salarie5.GetHashCode());


            #endregion

            #region Test du equals sur salarie 4 et salarie 5
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" EQUALS ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("Test du equals");
            Console.WriteLine("salarie 4 equals  salarie 5 : {0} ", salarie4.Equals(salarie5));


            #endregion

            #region Affichage instance
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" INSTANCE  ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("Nombre d'instances:{0}", Salarie.CompteurInstances);


            #endregion

            #region Commercial1
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" COMMERCIAL 1  ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;


            Commercial commercial1 = new Commercial(100000, 0.5m);
            commercial1.SalaireBrut = 500;
            commercial1.TauxCS      = 0.5m;
            commercial1.Nom         = "vignot";
            commercial1.Prenom      = "guillaume";
            commercial1.Matricule   = "12abc67";


            Console.WriteLine(commercial1.ToString());

            Console.WriteLine("HashCode du nom du commercial1 = {0} ", commercial1.Nom.GetHashCode());
            Console.WriteLine("HashCode du matricule du commercial1 = {0} ", commercial1.Matricule.GetHashCode());
            Console.WriteLine("HashCode du commercial1 (complet) = {0} ", commercial1.GetHashCode());
            Console.WriteLine("COMMERCIAL 1: chiffre d'affaire: {0} puis commission: {1} puis (salaire net +commission) du commercial1:  {2} ", commercial1.ChiffreAffaire, commercial1.Commission, commercial1.SalaireNet);


            #endregion

            #region Commercial2
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" COMMERCIAL 2 ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;

            Commercial commercial2 = new Commercial(commercial1);
            Console.WriteLine(commercial2.ToString());
            Console.WriteLine("HashCode du nom du commercial1 = {0} ", commercial1.Nom.GetHashCode());
            Console.WriteLine("HashCode du matricule du commercial1 = {0} ", commercial1.Matricule.GetHashCode());
            Console.WriteLine("HashCode du commercial1 (complet) = {0} ", commercial1.GetHashCode());
            Console.WriteLine("COMMERCIAL 2: chiffre d'affaire: {0} puis commission: {1} puis (salaire net +commission) du commercial1:  {2} ", commercial1.ChiffreAffaire, commercial1.Commission, commercial1.SalaireNet);


            #endregion

            #region test du equals sur commercial 1 et commercial 2
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write("  EQUALS  ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("Test du equals");
            Console.WriteLine("commercial 1 equals  commercial 2 : {0} ", commercial1.Equals(commercial2));


            #endregion



            #region Affichage instance
            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" INSTANCE ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;


            Console.WriteLine("Nombre d'instances:{0}", Salarie.CompteurInstances);


            Console.ForegroundColor = ConsoleColor.Red;
            Console.Write(" --------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.Write(" FIN ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(" -------------------------------------------------------------- ");
            Console.ForegroundColor = ConsoleColor.White;
            #endregion

            Console.ReadLine();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            ServiceCommercial sc1 = PersisteServiceCommercial.charge("service.sr"); //le ServiceCommercial sc1 est désérialisé

            // 3.	Code de la classe Commercial
            Console.WriteLine("3.	Code de la classe Commercial ");
            Commercial c, c1;

            c = new Commercial("Jean", "Dupond", 8, 'A');
            Console.WriteLine(c.ToString());
            Console.WriteLine();

            // 4.	Code de la classe NoteFrais
            Console.WriteLine("4.	Code de la classe NoteFrais");
            NoteFrais f, f1, f2, f3, f4, f5;

            f = new NoteFrais(new DateTime(2013, 11, 12), c);
            Console.WriteLine(f.ToString());
            Console.WriteLine();

            // 6.1 La classe FraisTransport
            Console.WriteLine("6.1 La classe FraisTransport");
            f1 = new FraisTransport(new DateTime(2013, 11, 12), c, 250);
            Console.WriteLine(f1.ToString());
            Console.WriteLine();

            // 6.2 La classe RepasMidi
            Console.WriteLine("6.2 La classe RepasMidi");
            f2 = new RepasMidi(new DateTime(2013, 11, 12), c, 35);
            Console.WriteLine(f2.ToString());
            f3 = new RepasMidi(new DateTime(2013, 11, 12), c, 15);
            Console.WriteLine(f3.ToString());
            Console.WriteLine();

            // 6.3 La classe Nuitee
            Console.WriteLine("6.3 La classe Nuitee");
            f4 = new Nuitee(new DateTime(2013, 11, 12), c, 2, 46);
            Console.WriteLine(f4.ToString());
            f5 = new Nuitee(new DateTime(2013, 11, 12), c, 3, 80);
            Console.WriteLine(f5.ToString());
            Console.WriteLine();

            // 7.	Gestion des notes de frais d'un commercial
            Console.WriteLine("7.	Gestion des notes de frais d'un commercial");
            ServiceCommercial sc;

            sc = new ServiceCommercial();
            c1 = new Commercial("Dupond", "Jean", 7, 'B');
            sc.ajouterCommercial(c1);
            sc.ajouterNote(c1, new DateTime(2013, 11, 15), 100);    // ajoute un frais de transport
            sc.ajouterNote(c1, new DateTime(2013, 11, 21), 15.5);   // ajoute une note de repas
            sc.ajouterNote(c1, new DateTime(2013, 11, 25), 105, 2); // ajoute une nuitée
            Console.WriteLine("Les frais ajouté depuis la classe service commercial : {0}", sc.nbFraisNonRembourses());

            f.setFraisRembourser();
            f1.setFraisRembourser();
            f2.setFraisRembourser();
            Console.WriteLine("Test du cumul des notes de frais remboursées en 2013 : {0} euros.", c.cumulNoteFraisRemboursees(2013));

            PersisteServiceCommercial.sauve(sc, "service.sr"); // le ServiceCommercial sc est sérialisé et enregistré en mémoire

            Console.ReadLine();
        }