Пример #1
0
        /// <summary>
        /// Ajoute une spécificité en base
        /// </summary>
        public void AddSpecialite()
        {
            Specialite spec = new Specialite();

            bool res = false;

            _getSpec = new List <Specialite>();
            _getSpec = ListAllSpec();

            Console.WriteLine($"{Messages.TitreAjouterSpecialiteMedecin}");
            Console.Write($"{ Messages.TitreNouvelleSpecialiteMedecin}");
            spec.SpecialiteM = Console.ReadLine();

            do
            {
                res = _getSpec.Exists(x => x.SpecialiteM.ToLower().Contains(spec.SpecialiteM.ToLower()));
                if (res)
                {
                    Messages.AfficherMessageErreur("Cette spécialité existe déjà");
                    Console.WriteLine(" ");
                    Console.Write($"{ Messages.TitreNouvelleSpecialiteMedecin} :");
                    spec.SpecialiteM = Console.ReadLine();
                }
            }while (res);

            int max = _getSpec[0].CodeSpec;

            for (int i = 1; i < _getSpec.Count; i++)
            {
                if (max <= _getSpec[i].CodeSpec)
                {
                    max = _getSpec[i].CodeSpec;
                }
            }
            max = max + 1;

            SqlCommand command = new SqlCommand("INSERT INTO Spec (Specialite, CodeSpec) OUTPUT INSERTED.Id VALUES (@s, @c)", Connection.Instance);

            command.Parameters.Add(new SqlParameter("@s", spec.SpecialiteM[0].ToString().ToUpper() + spec.SpecialiteM.Substring(1).ToLower()));
            command.Parameters.Add(new SqlParameter("@c", max));
            Connection.Instance.Open();
            spec.Id = (int)command.ExecuteScalar();
            command.Dispose();
            Connection.Instance.Close();

            Messages.AfficherMessageInsertOk(Messages.InsertOk);
        }
Пример #2
0
        public List <Specialite> GetSpecialite()
        {
            SqlCommand command = new SqlCommand("SELECT * FROM Spec", Connection.Instance);

            Connection.Instance.Open();
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                Specialite s = new Specialite()
                {
                    Id          = reader.GetInt32(0),
                    SpecialiteM = reader.GetString(1),
                    CodeSpec    = reader.GetInt32(2)
                };
                listeSpecialites.Add(s);
            }
            reader.Close();
            command.Dispose();
            Connection.Instance.Close();
            return(listeSpecialites);
        }