/// <summary>
        /// Retrieve history of all Caisses
        /// </summary>
        /// <param name="salarie"></param>
        /// <returns>List of CaisseOuverture</returns>
        public static List<CaisseOuverture> GetByCaisse(Caisse caisse)
        {
            List<CaisseOuverture> listCaisseOuverture = new List<CaisseOuverture>();

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

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

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

                    SqlDataReader row = req.ExecuteReader();

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

                        co.Salarie = SalarieDAO.Get(row["CodeSalarie"].ToString());

                        co.Caisse = caisse;

                        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;
        }
Exemple #2
0
        /// <summary>
        /// Delete a Caisse
        /// </summary>
        /// <param name="caisse"></param>
        /// <returns>bool</returns>
        public static bool Delete(Caisse caisse)
        {
            int res = 0;

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

                string sql = "DELETE FROM Caisse WHERE NumCaisse = @NumCaisse";

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

                    res = req.ExecuteNonQuery();

                }
            }

            return res != 0 ? true : false;
        }
        /// <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;
        }
Exemple #4
0
        /// <summary>
        /// Retrieve the Caisse by its num
        /// </summary>
        /// <param name="numCaisse"></param>
        /// <returns>Caisse</returns>
        public static Caisse Get(int numCaisse)
        {
            Caisse caisse = new Caisse();

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

                string sql = "SELECT * FROM Caisse c WHERE c.NumCaisse = @NumCaisse";

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

                    SqlDataReader row = req.ExecuteReader();

                    if (row.Read())
                    {
                        caisse.Num = int.Parse(row["NumCaisse"].ToString());
                    }
                }
            }

            return caisse;
        }
        /// <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;
        }
Exemple #6
0
        /// <summary>
        /// Retrieve all Caisses existing
        /// </summary>
        /// <returns>List of Caisse</returns>
        public static List<Caisse> GetAll()
        {
            List<Caisse> listCaisses = new List<Caisse>();

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

                string sql = "SELECT NumCaisse FROM Caisse";

                using (SqlCommand req = new SqlCommand(sql, db))
                {

                    SqlDataReader row = req.ExecuteReader();

                    while (row.Read())
                    {
                        Caisse caisse = new Caisse();

                        caisse.Num = int.Parse(row["NumCaisse"].ToString());
                        caisse.CaissesOuvertures = CaisseOuvertureDAO.GetByCaisse(caisse);

                        listCaisses.Add(caisse);
                    }
                }

            }
            return listCaisses;
        }