Exemplo n.º 1
0
        public Appartement Get_AppartementFromName(string ApptName)
        {
            Appartement appt = new Appartement();

            appt.AppartementName = ApptName;

            using (var conn = new SqlConnection(this.connectionString))
            {
                conn.Open();
                using (var cmd = new SqlCommand("SELECT AppartementId, UserName, Batiment, Escalier, Etage, Porte, Type, IsDoubleVitrage, IsRobinetsThermo, Orientation, Partager FROM Appartement WHERE Appartement=@paramApptId", conn))
                {
                    cmd.Parameters.AddWithValue("paramApptId", ApptName);
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            appt.AppartementId    = reader.GetInt32(0);
                            appt.UserName         = reader.GetString(1);
                            appt.Batiment         = reader.GetString(2);
                            appt.Escalier         = reader.GetString(3);
                            appt.Etage            = reader.GetInt32(4);
                            appt.Porte            = reader.GetString(5);
                            appt.Type             = reader.GetString(6);
                            appt.IsDoubleVitrage  = reader.GetBoolean(7);
                            appt.IsRobinetsThermo = reader.GetBoolean(8);
                            appt.Orientation      = reader.GetString(9);
                            appt.Partager         = reader.GetBoolean(10);
                        }
                    }
                }
                conn.Close();
            }
            return(appt);
        }
Exemplo n.º 2
0
        public List <Appartement> Get_AllAppartements()
        {
            List <Appartement> listAppt = new List <Appartement>();

            using (var conn = new SqlConnection(this.connectionString))
            {
                conn.Open();
                using (var cmd = new SqlCommand("SELECT AppartementId, UserName, Appartement, Batiment, Escalier, Etage, Porte, Type, IsDoubleVitrage, IsRobinetsThermo, Orientation, Partager FROM Appartement", conn))
                {
                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Appartement appt = new Appartement();
                            appt.AppartementId    = reader.GetInt32(0);
                            appt.UserName         = reader.GetString(1);
                            appt.AppartementName  = reader.GetString(2);
                            appt.Batiment         = reader.GetString(3);
                            appt.Escalier         = reader.GetString(4);
                            appt.Etage            = reader.GetInt32(5);
                            appt.Porte            = reader.GetString(6);
                            appt.Type             = reader.GetString(7);
                            appt.IsDoubleVitrage  = reader.GetBoolean(8);
                            appt.IsRobinetsThermo = reader.GetBoolean(9);
                            appt.Orientation      = reader.GetString(10);
                            appt.Partager         = reader.GetBoolean(11);
                            listAppt.Add(appt);
                        }
                    }
                }
                conn.Close();
            }

            return(listAppt);
        }
Exemplo n.º 3
0
        //------------------------------------------------------------------------------------------------------------
        // INSERT
        //------------------------------------------------------------------------------------------------------------
        public bool Add_Appartement(Appartement appt)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(this.connectionString))
                {
                    conn.Open();
                    string sql = "INSERT INTO Appartement VALUES(@UserName,@Appartement,@Batiment,@Etage,@Porte,@Type,@IsDoubleVitrage, @IsRobinetsThermo, @Orientation, @Partager,@Escalier)";

                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.Add("@UserName", SqlDbType.VarChar).Value     = appt.UserName;
                    cmd.Parameters.Add("@Appartement", SqlDbType.VarChar).Value  = appt.AppartementName;
                    cmd.Parameters.Add("@Batiment", SqlDbType.VarChar).Value     = appt.Batiment;
                    cmd.Parameters.Add("@Escalier", SqlDbType.VarChar).Value     = appt.Escalier;
                    cmd.Parameters.Add("@Etage", SqlDbType.Int).Value            = appt.Etage;
                    cmd.Parameters.Add("@Porte", SqlDbType.VarChar).Value        = appt.Porte;
                    cmd.Parameters.Add("@Type", SqlDbType.VarChar).Value         = appt.Type;
                    cmd.Parameters.Add("@IsDoubleVitrage", SqlDbType.Bit).Value  = appt.IsDoubleVitrage;
                    cmd.Parameters.Add("@IsRobinetsThermo", SqlDbType.Bit).Value = appt.IsRobinetsThermo;
                    cmd.Parameters.Add("@Orientation", SqlDbType.VarChar).Value  = appt.Orientation;
                    cmd.Parameters.Add("@Partager", SqlDbType.Bit).Value         = appt.Partager;

                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        //------------------------------------------------------------------------------------------------------------
        // UPDATE
        //------------------------------------------------------------------------------------------------------------

        public bool Update_Appartement(Appartement appt)
        {
            try
            {
                using (SqlConnection conn = new SqlConnection(this.connectionString))
                {
                    conn.Open();
                    string sql = "UPDATE Appartement SET Appartement=@paramAppartement, UserName=@paramUsername, Type=@paramType, IsDoubleVitrage=@paramIsDoubleVitrage, IsRobinetsThermo = @paramIsRobinetsThermo, Orientation = @paramOrientation, Partager=@paramPartager WHERE AppartementId=@paramApptId";

                    SqlCommand cmd = new SqlCommand(sql, conn);
                    cmd.Parameters.Add("@paramApptId", SqlDbType.VarChar).Value       = appt.AppartementId;
                    cmd.Parameters.Add("@paramAppartement", SqlDbType.VarChar).Value  = appt.AppartementName;
                    cmd.Parameters.Add("@paramUsername", SqlDbType.VarChar).Value     = appt.UserName;
                    cmd.Parameters.Add("@paramType", SqlDbType.VarChar).Value         = appt.Type;
                    cmd.Parameters.Add("@paramIsDoubleVitrage", SqlDbType.Bit).Value  = appt.IsDoubleVitrage;
                    cmd.Parameters.Add("@paramIsRobinetsThermo", SqlDbType.Bit).Value = appt.IsRobinetsThermo;
                    cmd.Parameters.Add("@paramOrientation", SqlDbType.VarChar).Value  = appt.Orientation;
                    cmd.Parameters.Add("@paramPartager", SqlDbType.Bit).Value         = appt.Partager;

                    cmd.CommandType = CommandType.Text;
                    cmd.ExecuteNonQuery();
                    conn.Close();
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 5
0
        // GET: Appartement
        public ActionResult MonAppartement()
        {
            Appartement             user = bdd_appartement.Get_AppartementFromName(User.Identity.Name);
            MonAppartementViewModel vm   = new MonAppartementViewModel(user);

            return(View(vm));
        }
Exemplo n.º 6
0
        public void CreerCompteAjax(string paramUserName, string paramAppartement, string paramBatiment, string paramEscalier, int paramEtage, string paramPorte, string paramType, bool paramIsDoubleVitrage, bool paramIsRobinetsThermo, string paramOrientation)
        {
            try
            {
                bdd_appartement = new Bdd_Appartement();


                Appartement appt = new Appartement();
                appt.AppartementName  = paramAppartement;
                appt.Batiment         = paramBatiment;
                appt.Escalier         = paramEscalier;
                appt.Etage            = paramEtage;
                appt.IsDoubleVitrage  = paramIsDoubleVitrage;
                appt.IsRobinetsThermo = paramIsRobinetsThermo;
                appt.Orientation      = paramOrientation;
                appt.Porte            = paramPorte;
                appt.Type             = paramType;
                appt.UserName         = paramUserName;

                if (!bdd_appartement.IsAppartementNamePresent(paramAppartement))
                {
                    bdd_appartement.Add_Appartement(appt);
                    TempData["message"] = "Compte créé";
                }
                else
                {
                    TempData["message"] = "NOKCet appartement a déjà été créé";
                }
            }
            catch (Exception ex)
            {
                TempData["message"] = "NOKErreur lors de le création: " + ex.Message;
            }
        }
        private void ProcessPersonnalChallenge(Appartement p_appartement, string p_challengeName, string p_subChallenge)
        {
            Challenge l_challengeEnCours = m_tousLesChallenges.FirstOrDefault(c => c.Nom == p_challengeName);

            // On restreint les données avec lesquelles on joue à celle de l'appart/type
            IEnumerable<DataSuite> l_personnalChallengeSuites = m_dataSuites.Where(ds => ds.Appartement == p_appartement && ds.Type == p_subChallenge); ;

            DateTime l_processedDate = m_minDate.AddDays(7); // on démarre à la seconde semaine, forcément...

            // Dump de la semaine d'avant
            DataSuite l_previousDataSuite = l_personnalChallengeSuites.FirstOrDefault(ds => ds.Date == m_minDate);
            double l_previousIndice = l_previousDataSuite.ConsommationTotale();

            // On traite date par date
            while (DateTime.Compare(l_processedDate, m_maxDate) <= 0)
            {
                DataSuite l_candidat = m_dataSuites.FirstOrDefault(ds => ds.Date == l_processedDate);
                double l_indice = l_candidat.ConsommationTotale();

                if (l_indice < l_previousIndice)
                {
                    p_appartement.GagneEnergyCoin(l_challengeEnCours, 4, l_processedDate, string.Format("{0:0.00}%", (((l_indice - l_previousIndice) * 100) / l_previousIndice)));
                }

                // dump des valeurs courantes pour l'itération suivante
                l_previousDataSuite = l_candidat;
                l_previousIndice = l_indice;

                // Date suivante
                l_processedDate = l_processedDate.AddDays(7);

            }
        }
Exemplo n.º 8
0
        public ActionResult Index()
        {
            Appartement user = bdd_appartement.Get_AppartementFromName(User.Identity.Name);

            ViewBag.ApptId = user.AppartementId;
            ViewBag.Type   = user.Type;

            return(View());
        }
Exemplo n.º 9
0
        // GET: Appartement
        public ActionResult Appartements()
        {
            Appartement           user = bdd_appartement.Get_AppartementFromName(User.Identity.Name);
            AppartementsViewModel vm   = new AppartementsViewModel();

            vm.JePartage    = user.Partager;
            vm.list_appts   = bdd_appartement.Get_AllAppartements().OrderBy(a => a.AppartementName).ToList();
            vm.nbAppts      = vm.list_appts.Count();
            vm.nbApptsTotal = 212;
            vm.nbPartage    = vm.list_appts.Where(a => a.Partager == true).ToList().Count();

            return(View(vm));
        }
Exemplo n.º 10
0
        public MonAppartementViewModel(Appartement appt)
        {
            this.AppartementId    = appt.AppartementId;
            this.UserName         = appt.UserName;
            this.Appartement      = appt.AppartementName;
            this.Batiment         = appt.Batiment;
            this.Escalier         = appt.Escalier;
            this.Etage            = appt.Etage;
            this.Porte            = appt.Porte;
            this.Type             = appt.Type;
            this.IsDoubleVitrage  = appt.IsDoubleVitrage;
            this.IsRobinetsThermo = appt.IsRobinetsThermo;
            this.Partager         = appt.Partager;

            if (appt.Orientation.Contains("Nord"))
            {
                this.OrientationNS = "Nord";
            }
            if (appt.Orientation.Contains("Sud"))
            {
                this.OrientationNS = "Sud";
            }
            if (appt.Orientation.Contains("Est"))
            {
                this.OrientationEO = "Est";
            }
            if (appt.Orientation.Contains("Ouest"))
            {
                this.OrientationEO = "Ouest";
            }

            if (this.Batiment.Equals("A"))
            {
                this.IsBatA = true;
            }
            else
            {
                this.IsBatA = false;
            }

            if (this.Escalier.Equals("A"))
            {
                this.IsEscalierA = true;
            }
            else
            {
                this.IsEscalierA = false;
            }
        }
Exemplo n.º 11
0
        // GET (AJAX) - Récupére les informations de l'appartement
        public JsonResult GetInformationsAppartement(int paramApptId)
        {
            Appartement appt = bdd_appartement.Get_AppartementFromId(paramApptId);


            var result = new List <object>();

            result.Add(
                new
            {
                appt.Type,
                appt.IsDoubleVitrage,
                appt.IsRobinetsThermo,
                appt.Orientation
            });

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 12
0
        public ActionResult Index(LoginViewModel vm)
        {
            bdd_appartement = new Bdd_Appartement();
            Appartement appt = new Appartement();

            appt.AppartementName = vm.Appart;
            appt.UserName        = vm.Utilisateur;

            if (bdd_appartement.IsAppartementNamePresent(appt.AppartementName))
            {
                Appartement bddUser = bdd_appartement.Get_AppartementFromName(appt.AppartementName);
                TempData["messageConnexion"] = null;
                if (bddUser.UserName.Equals(appt.UserName))
                {
                    FormsAuthentication.SetAuthCookie(vm.Appart, false);
                }
            }
            else
            {
                TempData["messageConnexion"] = "Impossible de vous authentifier avec ce couplke Appartement / Nom";
            }

            return(Redirect(@Url.Content("~/")));
        }
Exemplo n.º 13
0
        public ActionResult MonAppartement(MonAppartementViewModel vm)
        {
            Appartement user     = bdd_appartement.Get_AppartementFromName(User.Identity.Name);
            bool        isModify = false;

            if (user.AppartementName != vm.Appartement)
            {
                isModify             = true;
                user.AppartementName = vm.Appartement;
            }

            if (user.UserName != vm.UserName)
            {
                isModify      = true;
                user.UserName = vm.UserName;
            }

            if (user.Type != vm.Type)
            {
                isModify  = true;
                user.Type = vm.Type;
            }

            if (user.Orientation != (vm.OrientationNS + " " + vm.OrientationEO))
            {
                isModify         = true;
                user.Orientation = "";
                if (vm.OrientationNS.Contains("Sud"))
                {
                    user.Orientation += "Sud ";
                }
                if (vm.OrientationNS.Contains("Nord"))
                {
                    user.Orientation += "Nord ";
                }
                if (vm.OrientationEO.Contains("Est"))
                {
                    user.Orientation += "Est";
                }
                if (vm.OrientationEO.Contains("Ouest"))
                {
                    user.Orientation += "Ouest";
                }
            }

            if (user.IsDoubleVitrage != vm.IsDoubleVitrage)
            {
                isModify             = true;
                user.IsDoubleVitrage = vm.IsDoubleVitrage;
            }

            if (user.IsRobinetsThermo != vm.IsRobinetsThermo)
            {
                isModify = true;
                user.IsRobinetsThermo = vm.IsRobinetsThermo;
            }

            if (user.Partager != vm.Partager)
            {
                isModify      = true;
                user.Partager = vm.Partager;
            }

            if (isModify)
            {
                bdd_appartement.Update_Appartement(user);
            }


            return(RedirectToAction("MonAppartement"));
        }