Esempio n. 1
0
        /// <summary>
        /// Retrieve the Salarie by its code
        /// </summary>
        /// <param name="cSalarie"></param>
        /// <returns>Salarie</returns>
        public static Salarie Get(string codeSalarie)
        {
            Salarie salarie = new Salarie();

            using (SqlConnection db = DbConnexion.connect())
            {

                string sql = "SELECT * FROM Salarie s WHERE s.CodeSalarie = @CodeSalarie";

                using (SqlCommand req = new SqlCommand(sql, db))
                {
                    req.Parameters.Add(new SqlParameter("CodeSalarie", codeSalarie));

                    SqlDataReader row = req.ExecuteReader();

                    if (row.Read())
                    {
                        salarie.Code = row["CodeSalarie"].ToString();
                        salarie.Nom = row["NomSalarie"].ToString();
                        salarie.Prenom = row["PrenomSalarie"].ToString();
                        salarie.DateRecrutement = row.GetDateTime(row.GetOrdinal("DateRecrutement"));
                        salarie.CaissesOuvertures = CaisseOuvertureDAO.GetBySalarie(salarie);
                        salarie.IsAdmin = row.GetBoolean(row.GetOrdinal("isAdmin"));
                    }
                }
            }

            return salarie;
        }
Esempio n. 2
0
        /// <summary>
        /// Delete the Salarie
        /// </summary>
        /// <param name="salarie"></param>
        /// <returns>bool</returns>
        public static bool Delete(Salarie salarie)
        {
            int res = 0;

            using (SqlConnection db = DbConnexion.connect())
            {

                string sql = "DELETE FROM salarie WHERE CodeSalarie = @CodeSalarie"; ;

                    using (SqlCommand req = new SqlCommand(sql, db))
                    {
                        req.Parameters.Add(new SqlParameter("CodeSalarie", salarie.Code));

                        res = req.ExecuteNonQuery();

                    }
            }

            return res != 0 ? true : false;
        }
Esempio n. 3
0
        /// <summary>
        /// Update the entry corresponding to the Caisse's state
        /// </summary>
        /// <param name="caisse"></param>
        /// <param name="salarie"></param>
        /// <returns></returns>
        public static bool Fermer(Caisse caisse, Salarie salarie)
        {
            int res = 0;

            using (SqlConnection db = DbConnexion.connect())
            {

                string sql = "UPDATE Caisse_Ouverture SET NumCaisse = @NumCaisse, CodeSalarie = @CodeSalarie";

                using (SqlCommand req = new SqlCommand(sql, db))
                {
                    req.Parameters.Add(new SqlParameter("NumCaisse", caisse.Num));
                    req.Parameters.Add(new SqlParameter("CodeSalarie", salarie.Code));

                    res = req.ExecuteNonQuery();

                }
            }

            return res != 0 ? true : false;
        }
Esempio n. 4
0
        /// <summary>
        /// Retrieve all Caisses opened by the Salarie
        /// </summary>
        /// <param name="salarie"></param>
        /// <returns>List of CaisseOuverture</returns>
        public static List<CaisseOuverture> GetBySalarie(Salarie salarie)
        {
            List<CaisseOuverture> listCaisseOuverture = new List<CaisseOuverture>();

            using (SqlConnection db = DbConnexion.connect())
            {

                string sql = "SELECT NumCaisse,DateHeureOuverture,DateHeureFermeture FROM Caisse_Ouverture co WHERE co.CodeSalarie = @CodeSalarie ORDER BY DateHeureOuverture DESC";

                using (SqlCommand req = new SqlCommand(sql, db))
                {
                    req.Parameters.Add(new SqlParameter("CodeSalarie", salarie.Code));

                    SqlDataReader row = req.ExecuteReader();

                    while (row.Read())
                    {
                        CaisseOuverture co = new CaisseOuverture();

                        co.Salarie = salarie;

                        co.Caisse = CaisseDAO.Get(int.Parse(row["NumCaisse"].ToString()));

                        if (!String.IsNullOrEmpty(row["DateHeureOuverture"].ToString())) co.DateHeureOuverture = row.GetDateTime(row.GetOrdinal("DateHeureOuverture"));

                        if (!String.IsNullOrEmpty(row["DateHeureFermeture"].ToString())) co.DateHeureFermeture = row.GetDateTime(row.GetOrdinal("DateHeureFermeture"));

                        listCaisseOuverture.Add(co);
                    }
                }

            }

            return listCaisseOuverture;
        }
Esempio n. 5
0
        /// <summary>
        /// Create a new entry of CaisseOuverture meaning the Caisse is opened by the Salarie
        /// </summary>
        /// <param name="caisse"></param>
        /// <param name="salarie"></param>
        /// <returns>bool</returns>
        public static bool Ouvrir(Caisse caisse, Salarie salarie)
        {
            int res = 0;

            using (SqlConnection db = DbConnexion.connect())
            {

                string sql = "INSERT INTO Caisse_Ouverture  (NumCaisse, CodeSalarie) VALUES(@NumCaisse, @CodeSalarie)";

                using (SqlCommand req = new SqlCommand(sql, db))
                {
                    req.Parameters.Add(new SqlParameter("NumCaisse", caisse.Num));
                    req.Parameters.Add(new SqlParameter("CodeSalarie", salarie.Code));

                    res = req.ExecuteNonQuery();

                }
            }

            return res != 0 ? true : false;
        }
Esempio n. 6
0
        /// <summary>
        /// Retrieve all Salaries
        /// </summary>
        /// <returns>List of Salarie</returns>
        public static List<Salarie> GetAll()
        {
            List<Salarie> listSalaries = new List<Salarie>();

            using (SqlConnection db = DbConnexion.connect())
            {

                string sql = "SELECT * FROM Salarie s ORDER BY s.NomSalarie";

                using (SqlCommand req = new SqlCommand(sql, db))
                {
                    SqlDataReader row = req.ExecuteReader();

                    while (row.Read())
                    {
                        Salarie salarie = new Salarie();
                        salarie.Code = row.GetValue(0).ToString();
                        salarie.Nom = row.GetValue(1).ToString();
                        salarie.Prenom = row.GetValue(2).ToString();
                        salarie.DateRecrutement = DateTime.Parse(row.GetValue(3).ToString());
                        salarie.CaissesOuvertures = CaisseOuvertureDAO.GetBySalarie(salarie);
                        salarie.IsAdmin = row.GetBoolean(row.GetOrdinal("isAdmin"));

                        listSalaries.Add(salarie);
                    }
                }
            }

            return listSalaries;
        }
Esempio n. 7
0
        /// <summary>
        /// Update the Salarie
        /// </summary>
        /// <param name="salarie"></param>
        /// <returns>bool</returns>
        public static bool Update(Salarie salarie)
        {
            int res = 0;

            using (SqlConnection db = DbConnexion.connect())
            {

                string sql = "UPDATE salarie SET NomSalarie = @NomSalarie, PrenomSalarie = @PrenomSalarie, DateRecrutement = @DateRecrutement, IsAdmin = @IsAdmin WHERE CodeSalarie = @CodeSalarie"; ;

                using (SqlCommand req = new SqlCommand(sql, db))
                {
                    req.Parameters.Add(new SqlParameter("CodeSalarie", salarie.Code));
                    req.Parameters.Add(new SqlParameter("NomSalarie", salarie.Nom));
                    req.Parameters.Add(new SqlParameter("PrenomSalarie", salarie.Prenom));
                    req.Parameters.Add(new SqlParameter("DateRecrutement", salarie.DateRecrutement));
                    req.Parameters.Add(new SqlParameter("IsAdmin", salarie.IsAdmin));

                    res = req.ExecuteNonQuery();

                }
            }

            return res != 0 ? true : false;
        }
Esempio n. 8
0
        /// <summary>
        /// Create a new Salarie
        /// </summary>
        /// <param name="salarie"></param>
        /// <returns>bool</returns>
        public static bool Insert(Salarie salarie)
        {
            int res = 0;

            using (SqlConnection db = DbConnexion.connect())
            {

                string sql = "INSERT INTO salarie (CodeSalarie,NomSalarie, PrenomSalarie, DateRecrutement, isAdmin) VALUES(@CodeSalarie, @NomSalarie, @PrenomSalarie, @DateRecrutement, @IsAdmin)"; ;

                using (SqlCommand req = new SqlCommand(sql, db))
                {
                    req.Parameters.Add(new SqlParameter("CodeSalarie", salarie.Code));
                    req.Parameters.Add(new SqlParameter("NomSalarie", salarie.Nom));
                    req.Parameters.Add(new SqlParameter("PrenomSalarie", salarie.Prenom));
                    req.Parameters.Add(new SqlParameter("DateRecrutement", salarie.DateRecrutement));
                    req.Parameters.Add(new SqlParameter("IsAdmin", salarie.IsAdmin));

                    res = req.ExecuteNonQuery();

                }
            }

            return res != 0 ? true : false;
        }