Example #1
0
        public static List <Employe> Employes()
        {
            List <Employe> AllEmployes = new List <Employe>();

            try
            {
                DbConnect db = new DbConnect();
                db.Command.CommandText = "GetAllEmploye";

                MySqlDataReader reader = db.Command.ExecuteReader();
                while (reader.Read())
                {
                    Employe employe = new Employe();
                    if (reader.IsDBNull(0))
                    {
                        employe.Matr = -1;
                    }
                    else
                    {
                        employe.Matr = (int)reader["Matr"];
                    }
                    if (reader.IsDBNull(1))
                    {
                        employe.NomE = null;
                    }
                    else
                    {
                        employe.NomE = (string)reader["NomE"];
                    }
                    if (reader.IsDBNull(2))
                    {
                        employe.Poste = null;
                    }
                    else
                    {
                        employe.Poste = (string)reader["Poste"];
                    }
                    if (reader.IsDBNull(3))
                    {
                        employe.DateEmb = null;
                    }
                    else
                    {
                        employe.DateEmb = (string)reader["DateEmb"];
                    }
                    if (reader.IsDBNull(4))
                    {
                        employe.Emp_Sup = new Employe();
                    }
                    else
                    {
                        employe.Emp_Sup = new Employe();
                        employe.Emp_Sup = GetEmploye((int)reader["Sup"]);
                    }
                    if (reader.IsDBNull(5))
                    {
                        employe.Salaire = 0;
                    }
                    else
                    {
                        employe.Salaire = (int)reader["Salaire"];
                    }
                    if (reader.IsDBNull(6))
                    {
                        employe.Comm = 0;
                    }
                    else
                    {
                        employe.Comm = (int)reader["Comm"];
                    }
                    if (reader.IsDBNull(7))
                    {
                        employe._Departement = null;
                    }
                    else
                    {
                        employe._Departement = new Departement();
                        employe._Departement = Departement.GetDepartement((int)reader["NumDept"]);
                    }

                    AllEmployes.Add(employe);
                }

                db.Connection.Close();
            }
            catch (MySqlException ex)
            {
                Console.WriteLine($"MyError :{ex.ToString()}");
            }


            return(AllEmployes);
        }
Example #2
0
        public static Employe GetEmploye(int id)
        {
            Employe employe = new Employe();

            try
            {
                DbConnect db = new DbConnect();
                db.Command.CommandText = "GetOneEmploye";
                db.Command.Parameters.AddWithValue("_Matr", id);
                MySqlDataReader reader = db.Command.ExecuteReader();
                reader.Read();
                if (reader.IsDBNull(0))
                {
                    employe.Matr = -1;
                }
                else
                {
                    employe.Matr = (int)reader["Matr"];
                }
                if (reader.IsDBNull(1))
                {
                    employe.NomE = null;
                }
                else
                {
                    employe.NomE = (string)reader["NomE"];
                }
                if (reader.IsDBNull(2))
                {
                    employe.Poste = null;
                }
                else
                {
                    employe.Poste = (string)reader["Poste"];
                }
                if (reader.IsDBNull(3))
                {
                    employe.DateEmb = null;
                }
                else
                {
                    employe.DateEmb = (string)reader["DateEmb"];
                }
                if (reader.IsDBNull(4))
                {
                    employe.Emp_Sup = new Employe();
                }
                else
                {
                    employe.Emp_Sup = new Employe();
                    employe.Emp_Sup = GetEmploye((int)reader["Sup"]);
                }
                if (reader.IsDBNull(5))
                {
                    employe.Salaire = 0;
                }
                else
                {
                    employe.Salaire = (int)reader["Salaire"];
                }
                if (reader.IsDBNull(6))
                {
                    employe.Comm = 0;
                }
                else
                {
                    employe.Comm = (int)reader["Comm"];
                }
                if (reader.IsDBNull(7))
                {
                    employe._Departement = null;
                }
                else
                {
                    employe._Departement = new Departement();
                    employe._Departement = Departement.GetDepartement((int)reader["NumDept"]);
                }

                db.Connection.Close();
            }
            catch
            {
            }
            return(employe);
        }