public static List <Departement> Departements() { List <Departement> AllDep = new List <Departement>(); try { DbConnect db = new DbConnect(); db.Command.CommandText = "GetAllDepartements"; MySqlDataReader reader = db.Command.ExecuteReader(); while (reader.Read()) { Departement d = new Departement(); if (reader.IsDBNull(0)) { d.NumDept = 0; } else { d.NumDept = (int)reader["NumDept"]; } if (reader.IsDBNull(1)) { d.NomDept = null; } else { d.NomDept = (string)reader["NomDept"]; } if (reader.IsDBNull(2)) { d.Lieu = null; } else { d.Lieu = (string)reader["Lieu"]; } AllDep.Add(d); } db.Connection.Close(); } catch { } return(AllDep); }
public static void InsertDepartement(Departement departement) { try { DbConnect db = new DbConnect(); db.Command.CommandText = "InsertDepartement"; db.Command.Parameters.AddWithValue("_NumDept", departement.NumDept); db.Command.Parameters.AddWithValue("_NomDept", departement.NomDept); db.Command.Parameters.AddWithValue("_Lieu", departement.Lieu); db.Command.ExecuteNonQuery(); db.Connection.Close(); } catch { } }
public static Departement GetDepartement(int id) { Departement departement = new Departement(); try { DbConnect db = new DbConnect(); db.Command.CommandText = "GetOneDepartement"; db.Command.Parameters.AddWithValue("_NumDept", id); MySqlDataReader reader = db.Command.ExecuteReader(); reader.Read(); departement.NumDept = (int)reader[0]; departement.NomDept = (string)reader[1]; departement.Lieu = (string)reader[2]; db.Connection.Close(); } catch { } return(departement); }
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); }
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); }