Beispiel #1
0
        internal static WeatherResponse GetWeather()
        {
            string         city_name      = GeolocationInformation.GetCity();
            string         url            = $"http://api.openweathermap.org/data/2.5/forecast?q={city_name}&appid={myToken}";
            WebRequest     request        = WebRequest.Create(url);
            var            response       = (HttpWebResponse)request.GetResponse();
            var            responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
            JsonTextReader reader         = new JsonTextReader(new StringReader(responseString));

            return(new JsonSerializer().Deserialize <WeatherResponse>(reader));
        }
Beispiel #2
0
        public void RefreshData()
        {
            //Control Panel
            query   = "SELECT * FROM Energy";
            command = new SQLiteCommand(query, conn);
            try
            {
                conn.Open();
                SQLiteDataReader reader = command.ExecuteReader();
                while (reader.Read())
                {
                    string typeId             = string.Empty;
                    double capacityFull       = double.Parse(reader["CapacityFull"].ToString());
                    double capacityCurrent    = double.Parse(reader["CapacityCurrent"].ToString());
                    int    capacityPercentage = Convert.ToInt32((capacityCurrent * 100) / capacityFull);
                    switch (reader["TypeId"].ToString())
                    {
                    case "1":
                        sp_prb.Value     = capacityPercentage;
                        sp_tbx.Text      = capacityPercentage.ToString();
                        sp_prb.ForeColor = SetColor(sp_prb.Value);
                        sp_chb.Checked   = int.Parse(reader["Enabled"].ToString()) == 1 ? true : false;
                        sp_chb.Text      = sp_chb.Checked ? "Turned on" : "Turned off";
                        break;

                    case "2":
                        wm_prb.Value     = capacityPercentage;
                        wm_tbx.Text      = capacityPercentage.ToString();
                        wm_prb.ForeColor = SetColor(wm_prb.Value);
                        wm_chb.Checked   = int.Parse(reader["Enabled"].ToString()) == 1 ? true : false;
                        wm_chb.Text      = wm_chb.Checked ? "Turned on" : "Turned off";
                        break;

                    case "3":
                        gr_prb.Value     = capacityPercentage;
                        gr_tbx.Text      = capacityPercentage.ToString();
                        gr_prb.ForeColor = SetColor(gr_prb.Value);
                        gr_chb.Checked   = int.Parse(reader["Enabled"].ToString()) == 1 ? true : false;
                        gr_chb.Text      = gr_chb.Checked ? "Turned on" : "Turned off";
                        break;
                    }
                }
                reader.Close();

                //Consumed Energy Display
                command.CommandText = "SELECT SUM(Amount) FROM EnergyConsumedLog";
                string consumedValue = command.ExecuteScalar().ToString();
                energyConsumed_lbl.Text = $"Energy Consumed:\n{consumedValue} kWt";

                //Produced Energy Display
                command.CommandText = "SELECT SUM(Amount) FROM EnergyProducedLog";
                string producedValue = command.ExecuteScalar().ToString();
                energyProduced_lbl.Text = $"Energy Produced:\n{producedValue} kWt";

                //Geolocation
                currentCity_lbl.Text = $"Current city: {GeolocationInformation.GetCity()}";

                //Weather
                weatherInformation_tbx.Text = WeatherInformation.PrintWeather();
                setCurrentWeather();

                conn.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }