protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         if (Request["ApiKey"] != null)
         {
             System.Guid guid = new Guid(Request["ApiKey"]);
             ThermostatMonitorLib.Location location = ThermostatMonitorLib.Location.LoadLocation(guid);
             if (location != null)
             {
                 ThermostatMonitorLib.User user = ThermostatMonitorLib.User.LoadUser(location.UserId);
                 if (user != null)
                 {
                     AppUser.Current.Login(user);
                     Response.Redirect("/cp/");
                 }
             }
         }
         else if (Request["action"] == "logout")
         {
             AppUser.Current.Logout();
             Response.Redirect("/");
         }
     }
 }
    protected void Page_Load(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request["id"]);

        if (id > 0)
        {
            thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(id);
            if (thermostat.KeyName != null && thermostat.KeyName != "")
            {
                key = thermostat.KeyName;
            }
            ThermostatMonitorLib.Location location = ThermostatMonitorLib.Location.LoadLocation(thermostat.LocationId);
            if (location.UserId != AppUser.Current.UserData.Id)
            {
                Response.Redirect("/cp/login.aspx");
            }
        }
        else
        {
            thermostat              = new ThermostatMonitorLib.Thermostat();
            thermostat.ACSeer       = 16;
            thermostat.ACTons       = 3.5;
            thermostat.ACKilowatts  = 2.625;
            thermostat.DisplayName  = "New Thermostat";
            thermostat.FanKilowatts = 0.5;
            thermostat.IpAddress    = "192.168.1.106";
        }
        if (!IsPostBack)
        {
            Populate();
        }
    }
Exemple #3
0
    private void OutputSummary(ThermostatMonitorLib.Thermostat thermostat, ThermostatMonitorLib.Location location)
    {
        DataTable dt       = ThermostatMonitorLib.Cycles.LoadFullSummary(thermostat.LocationId, thermostat.Id, new DateTime(2000, 1, 1), DateTime.Today, AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings));
        DataTable resultDt = new DataTable();

        foreach (DataColumn dc in dt.Columns)
        {
            resultDt.Columns.Add(dc.ColumnName.Replace("Seconds", "Minutes"), dc.DataType);
        }
        foreach (DataRow row in dt.Rows)
        {
            DataRow newRow = resultDt.NewRow();
            foreach (DataColumn dc in dt.Columns)
            {
                if (dc.ColumnName.Contains("Seconds"))
                {
                    double minutes = 0;
                    try { minutes = System.Math.Round(Convert.ToDouble(row[dc.ColumnName]) / 60, 2); }
                    catch { }
                    newRow[dc.ColumnName.Replace("Seconds", "Minutes")] = minutes;
                }
                else
                {
                    newRow[dc.ColumnName] = row[dc.ColumnName];
                }
            }
            resultDt.Rows.Add(newRow);
        }

        OutputCSV(ThermostatMonitorLib.Utils.DataTableToCSV(resultDt), "summary.csv");
    }
Exemple #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request["id"]);

        if (id > 0)
        {
            location = ThermostatMonitorLib.Location.LoadLocation(id);
            if (location.UserId != AppUser.Current.UserData.Id)
            {
                Response.Redirect("/cp/login.aspx");
            }
        }
        else
        {
            location                  = new ThermostatMonitorLib.Location();
            location.UserId           = AppUser.Current.UserData.Id;
            location.ElectricityPrice = 10;
            location.Name             = "Home";
        }

        if (!IsPostBack)
        {
            Populate();
        }
    }
Exemple #5
0
    protected void Page_Load(object sender, EventArgs e)
    {
        ThermostatMonitorLib.Location location = null;
        try
        {
            string      apiKey     = Request["apikey"];
            System.Guid apiKeyGuid = new Guid(apiKey);
            location = ThermostatMonitorLib.Location.LoadLocation(apiKeyGuid);
        }
        catch { }
        if (location == null)
        {
            return;
        }

        string action = Request["action"];

        switch (action.ToLower())
        {
        case "cyclestart":
            LogCycle(true, location.Id);
            break;

        case "cycleend":
            LogCycle(false, location.Id);
            break;

        case "loadsettings":
            LoadSettings(location);
            break;

        case "temperaturechanged":
            LogTemperature(location.Id);
            break;

        case "weatherchanged":
            LogWeather(location.Id);
            break;

        case "commands":
            LoadCommands(location.Id);
            break;

        case "settemperature":
            SetTemperature(location.Id);
            break;
        }
    }
Exemple #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int      thermostatId = Convert.ToInt32(Request["ThermostatId"]);
        DateTime date         = Convert.ToDateTime(Request["date"]);

        ThermostatMonitorLib.Thermostat thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(thermostatId);
        ThermostatMonitorLib.Location   location   = ThermostatMonitorLib.Location.LoadLocation(thermostat.LocationId);
        if (location.UserId != AppUser.Current.UserData.Id)
        {
            Response.Redirect("/login.aspx");
        }

        TimezoneDifference = AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings);

        ThermostatName.Text = thermostat.DisplayName;
        DateLit.Text        = date.ToString("ddd, MMMM d, yyyy");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request["id"]);
        if (id > 0)
        {
            location = ThermostatMonitorLib.Location.LoadLocation(id);
            if (location.UserId != AppUser.Current.UserData.Id) Response.Redirect("/cp/login.aspx");
        }
        else
        {
            location = new ThermostatMonitorLib.Location();
            location.UserId = AppUser.Current.UserData.Id;
            location.ElectricityPrice = 10;
            location.Name = "Home";
        }

        if (!IsPostBack) Populate();
    }
Exemple #8
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Request["Id"]);

        ThermostatMonitorLib.Thermostat thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(id);
        ThermostatMonitorLib.Location   location   = ThermostatMonitorLib.Location.LoadLocation(thermostat.LocationId);
        if (location.UserId != AppUser.Current.UserData.Id)
        {
            Response.Redirect("/login.aspx");
        }


        TimezoneDifference = AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings);



        ThermostatName.Text = thermostat.DisplayName + " (" + thermostat.IpAddress + ")";
        //ThermostatMonitorLib.Cycle currentCycle=ThermostatMonitorLib.Cycle.LoadOpenCycle(thermostat.Id);

        ThermostatMonitorLib.OutsideCondition currentCondition   = ThermostatMonitorLib.OutsideCondition.LoadCurrentCondition(location.Id);
        ThermostatMonitorLib.Temperature      currentTemperature = ThermostatMonitorLib.Temperature.LoadCurrentTemperature(thermostat.Id);
        CurrentConditionsLit.Text = "Currently: ";
        //if (currentCycle == null) CurrentConditionsLit.Text += "Off"; else CurrentConditionsLit.Text += currentCycle.CycleType;
        if (currentTemperature != null && currentCondition != null)
        {
            CurrentConditionsLit.Text += " - Inside: " + currentTemperature.Degrees.ToString() + "°";
            CurrentConditionsLit.Text += " - Outside: " + currentCondition.Degrees.ToString() + "°";
        }
        else
        {
            CurrentConditionsLit.Text = "No data has been gathered for this thermostat.";
        }



        ThermostatMonitorLib.Cycles cycles = ThermostatMonitorLib.Cycles.LoadRange(id, DateTime.Now.AddDays(-1).AddHours(AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings)), DateTime.Now.AddHours(AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings)));


        DataTable dt = ThermostatMonitorLib.Cycles.LoadFullSummary(thermostat.LocationId, thermostat.Id, DateTime.Today.AddDays(-7), DateTime.Today, AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings));

        HistorySummary1.Populate(dt, thermostat);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        int thermostatId = Convert.ToInt32(Request["thermostatId"]);

        thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(thermostatId);
        ThermostatMonitorLib.Location location = ThermostatMonitorLib.Location.LoadLocation(thermostat.LocationId);

        timezoneDifference = AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings);


        if (!IsPostBack)
        {
            ThermostatName.Text     = thermostat.DisplayName;
            StartDateText.Text      = startDate.ToString("MM/dd/yyyy");
            EndDateText.Text        = endDate.ToString("MM/dd/yyyy");
            PrevStartDateText.Text  = prevStartDate.ToString("MM/dd/yyyy");
            PrevEndDateText.Text    = prevEndDate.ToString("MM/dd/yyyy");
            IncludePrevious.Checked = true;
        }
    }
    protected void RegisterButton_Click(object sender, EventArgs e)
    {
        if (Validate())
        {
            ThermostatMonitorLib.User user = new ThermostatMonitorLib.User();
            user.EmailAddress = EmailText.Text;
            user.Password     = ThermostatMonitorLib.Utils.HashPassword(PasswordText.Text);
            user.AuthCode     = Guid.NewGuid().ToString();
            ThermostatMonitorLib.User.SaveUser(user);

            ThermostatMonitorLib.Location location = new ThermostatMonitorLib.Location();
            location.ApiKey           = Guid.NewGuid().ToString();
            location.ElectricityPrice = Convert.ToDouble(PriceText.Text);
            location.HeatFuelPrice    = Convert.ToDouble(HeatPriceText.Text.Replace("$", "").Replace(",", ""));
            location.Name             = "Home";
            location.UserId           = user.Id;
            location.ZipCode          = ZipCodeText.Text;
            location.ShareData        = ShareCheck.Checked;
            location.Timezone         = Convert.ToInt32(TimezoneList.SelectedValue);
            location.DaylightSavings  = DaylightSavings.Checked;
            //location.DaylightSavings = DaylightSavings.Checked;


            location.OpenWeatherCityId = ThermostatMonitorLib.Weather.GetCityId(location.ZipCode);

            ThermostatMonitorLib.Location.SaveLocation(location);

            //ThermostatMonitorLib.UserSetting setting = new ThermostatMonitorLib.UserSetting();
            //setting.ZipCode = ZipCodeText.Text;
            //setting.UserId = user.Id;
            //setting.FilterChangeDate = DateTime.Today.AddDays(90);
            //ThermostatMonitorLib.UserSetting.SaveUserSetting(setting);


            AppUser.Current.Login(user);
            Response.Redirect("/cp/");
        }
    }
Exemple #11
0
    private void LoadSettings(ThermostatMonitorLib.Location location)
    {
        //Build array list of thermostats
        ThermostatMonitorLib.Thermostats thermostats = ThermostatMonitorLib.Thermostats.LoadThermostatsByLocationId(location.Id);
        ArrayList al = new ArrayList();

        foreach (ThermostatMonitorLib.Thermostat thermostat in thermostats)
        {
            System.Collections.Hashtable hash = new System.Collections.Hashtable();
            hash.Add("name", thermostat.DisplayName);
            hash.Add("ipAddress", thermostat.IpAddress);
            hash.Add("brand", thermostat.Brand);
            al.Add(hash);
        }

        Hashtable result = new Hashtable();

        result.Add("thermostats", al);
        result.Add("zipCode", location.ZipCode);

        Response.Write(ThermostatMonitorLib.JSON.JsonEncode(result));
        Response.End();
    }
Exemple #12
0
    protected void Page_Load(object sender, EventArgs e)
    {
        int thermostatId = Convert.ToInt32(Request["ThermostatId"]);

        ThermostatMonitorLib.Thermostat thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(thermostatId);
        ThermostatMonitorLib.Location   location   = ThermostatMonitorLib.Location.LoadLocation(thermostat.LocationId);
        if (location.UserId != AppUser.Current.UserData.Id)
        {
            Response.Redirect("/cp/");
        }

        string reportType = Convert.ToString(Request["ReportType"]);

        switch (reportType)
        {
        case "summary":
            OutputSummary(thermostat, location);
            break;

        case "cycles":
            OutputCycles(thermostat, location);
            break;
        }
    }
    protected void RegisterButton_Click(object sender, EventArgs e)
    {
        if (Validate())
        {
            ThermostatMonitorLib.User user = new ThermostatMonitorLib.User();
            user.EmailAddress = EmailText.Text;
            user.Password = ThermostatMonitorLib.Utils.HashPassword(PasswordText.Text);
            user.AuthCode = Guid.NewGuid().ToString();
            ThermostatMonitorLib.User.SaveUser(user);

            ThermostatMonitorLib.Location location = new ThermostatMonitorLib.Location();
            location.ApiKey = Guid.NewGuid();
            location.ElectricityPrice = Convert.ToDouble(PriceText.Text);
            location.HeatFuelPrice = Convert.ToDouble(HeatPriceText.Text.Replace("$", "").Replace(",", ""));
            location.Name = "Home";
            location.UserId = user.Id;
            location.ZipCode = ZipCodeText.Text;
            location.ShareData = ShareCheck.Checked;
            location.Timezone = Convert.ToInt32(TimezoneList.SelectedValue);
            location.DaylightSavings = DaylightSavings.Checked;
            //location.DaylightSavings = DaylightSavings.Checked;

            location.OpenWeatherCityId = ThermostatMonitorLib.Weather.GetCityId(location.ZipCode);

            ThermostatMonitorLib.Location.SaveLocation(location);

            //ThermostatMonitorLib.UserSetting setting = new ThermostatMonitorLib.UserSetting();
            //setting.ZipCode = ZipCodeText.Text;
            //setting.UserId = user.Id;
            //setting.FilterChangeDate = DateTime.Today.AddDays(90);
            //ThermostatMonitorLib.UserSetting.SaveUserSetting(setting);

            AppUser.Current.Login(user);
            Response.Redirect("/cp/");
        }
    }
    public void Populate(DataTable dt, ThermostatMonitorLib.Thermostat thermostat)
    {
        ThermostatMonitorLib.Location location = ThermostatMonitorLib.Location.LoadLocation(thermostat.LocationId);

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        bool cool = false;
        bool heat = false;
        bool fan  = false;

        foreach (DataRow row in dt.Rows)
        {
            if (dt.Columns.Contains("Cool_CycleCount"))
            {
                cool = true;
            }
            if (dt.Columns.Contains("Heat_CycleCount"))
            {
                heat = true;
            }
            if (dt.Columns.Contains("Fan_CycleCount"))
            {
                fan = true;
            }
        }

        sb.Append("<table cellpadding=\"4\" cellspacing=\"0\" style=\"border:1px solid black;\"><tr><td></td>");
        if (cool)
        {
            sb.Append("<td colspan=\"4\" class=\"cool\"><b>Cool</b></td>");
        }
        if (heat)
        {
            sb.Append("<td colspan=\"4\" class=\"heat\"><b>Heat</b></td>");
        }
        if (fan)
        {
            sb.Append("<td colspan=\"4\" class=\"fan\"><b>Fan</b></td>");
        }
        sb.Append("<td colspan=\"2\" class=\"outside\"><b>Outside</b></td></tr>");

        sb.Append("<tr><td><b>Day</b></td>");
        if (cool)
        {
            sb.Append("<td class=\"cool\"><b>Cycles</b></td><td class=\"cool\"><b>Average</b></td><td class=\"cool\"><b>Total</b></td><td class=\"cool\"><b>Cost</b></td>");
        }
        if (heat)
        {
            sb.Append("<td class=\"heat\"><b>Cycles</b></td><td class=\"heat\"><b>Average</b></td><td class=\"heat\"><b>Total</b></td><td class=\"heat\"><b>Cost</b></td>");
        }
        if (fan)
        {
            sb.Append("<td class=\"fan\"><b>Cycles</b></td><td class=\"fan\"><b>Average</b></td><td class=\"fan\"><b>Total</b></td><td class=\"fan\"><b>Cost</b></td>");
        }
        sb.Append("<td class=\"outside\"><b>Min</b></td><td class=\"outside\"><b>Max</b></td></tr>");


        dt.DefaultView.Sort = "LogDate desc";
        //foreach (DataRowView row in dt.DefaultView)
        for (int i = 0; i < 7; i++)
        {
            DateTime logDate = DateTime.Today.AddDays(-i);
            DataRow  row     = GetRow(dt, logDate);

            DataRow[] rows = dt.Select("logdate='" + logDate.ToString("MM/dd/yyyy") + "'");
            if (rows.Length > 0)
            {
                row = rows[0];
            }


            sb.Append("<tr><td><a href=\"/cp/day.aspx?thermostatId=" + thermostat.Id + "&date=" + Convert.ToDateTime(row["LogDate"]).ToString("MM/dd/yyyy") + "\">" + Convert.ToDateTime(row["LogDate"]).ToString("dddd") + "</a></td>");
            if (cool)
            {
                if (Convert.IsDBNull(row["Cool_CycleCount"]))
                {
                    sb.Append("<td class=\"cool\" colspan=\"4\">&nbsp;</td>");
                }
                else
                {
                    double coolCost = (thermostat.ACKilowatts + thermostat.FanKilowatts) * Convert.ToDouble(row["Cool_TotalSeconds"]) / 60.0 / 60.0 * location.ElectricityPrice / 100;
                    sb.Append("<td class=\"cool\">" + row["Cool_CycleCount"].ToString() + "</td><td class=\"cool\">" + (Convert.ToDouble(row["Cool_AverageSeconds"]) / 60).ToString("#,##0.#") + " min</td><td class=\"cool\">" + (Convert.ToDouble(row["Cool_TotalSeconds"]) / 60).ToString("###,##0") + " min</td><td class=\"cool\">" + coolCost.ToString("C") + "</td>");
                }
            }
            if (heat)
            {
                if (Convert.IsDBNull(row["Heat_CycleCount"]))
                {
                    sb.Append("<td class=\"heat\" colspan=\"4\">&nbsp;</td>");
                }
                else
                {
                    double heatCost = thermostat.HeatBtuPerHour * Convert.ToDouble(row["Heat_TotalSeconds"]) / 60.0 / 60.0 * location.HeatFuelPrice / 1000000;
                    double fanCost  = (thermostat.FanKilowatts) * Convert.ToDouble(row["Heat_TotalSeconds"]) / 60.0 / 60.0 * location.ElectricityPrice / 100;
                    heatCost += fanCost;

                    sb.Append("<td class=\"heat\">" + row["Heat_CycleCount"].ToString() + "</td><td class=\"heat\">" + (Convert.ToDouble(row["Heat_AverageSeconds"]) / 60).ToString("#,##0.#") + " min</td><td class=\"heat\">" + (Convert.ToDouble(row["Heat_TotalSeconds"]) / 60).ToString("###,##0") + " min</td><td class=\"heat\">" + heatCost.ToString("C") + "</td>");
                }
            }
            if (fan)
            {
                if (Convert.IsDBNull(row["Fan_CycleCount"]))
                {
                    sb.Append("<td class=\"fan\" colspan=\"4\">&nbsp;</td>");
                }
                else
                {
                    sb.Append("<td class=\"fan\">" + row["Fan_CycleCount"].ToString() + "</td><td class=\"fan\">" + (Convert.ToDouble(row["Fan_AverageSeconds"]) / 60).ToString("#,##0.#") + " min</td><td class=\"fan\">" + (Convert.ToDouble(row["Fan_TotalSeconds"]) / 60).ToString("###,##0") + " min</td><td class=\"fan\"></td>");
                }
            }
            sb.Append("<td class=\"outside\">" + row["OutsideMin"].ToString() + "</td><td class=\"outside\">" + row["OutsideMax"].ToString() + "</td></tr>");
        }
        sb.Append("</table>");
        OutputLit.Text = sb.ToString();
    }
        internal static Location GetLocation(DataRow row)
        {
            Location result = new Location();
            if (row.Table.Columns.Contains("id"))
            {
                if (Convert.IsDBNull(row["id"]))
                {
                    result._isIdNull = true;
                }
                else
                {
                    result._id = Convert.ToInt32(row["id"]);
                    result._isIdNull = false;
                }
            }

            if (row.Table.Columns.Contains("user_id"))
            {
                if (Convert.IsDBNull(row["user_id"]))
                {
                    result._isUserIdNull = true;
                }
                else
                {
                    result._userId = Convert.ToInt32(row["user_id"]);
                    result._isUserIdNull = false;
                }
            }

            if (row.Table.Columns.Contains("name"))
            {
                if (Convert.IsDBNull(row["name"]))
                {
                    result._isNameNull = true;
                }
                else
                {
                    result._name = Convert.ToString(row["name"]);
                    result._isNameNull = false;
                }
            }

            if (row.Table.Columns.Contains("api_key"))
            {
                if (Convert.IsDBNull(row["api_key"]))
                {
                    result._isApiKeyNull = true;
                }
                else
                {
                    result._apiKey = Convert.ToString(row["api_key"]);
                    result._isApiKeyNull = false;
                }
            }

            if (row.Table.Columns.Contains("zip_code"))
            {
                if (Convert.IsDBNull(row["zip_code"]))
                {
                    result._isZipCodeNull = true;
                }
                else
                {
                    result._zipCode = Convert.ToString(row["zip_code"]);
                    result._isZipCodeNull = false;
                }
            }

            if (row.Table.Columns.Contains("electricity_price"))
            {
                if (Convert.IsDBNull(row["electricity_price"]))
                {
                    result._isElectricityPriceNull = true;
                }
                else
                {
                    result._electricityPrice = Convert.ToDouble(row["electricity_price"]);
                    result._isElectricityPriceNull = false;
                }
            }

            if (row.Table.Columns.Contains("share_data"))
            {
                if (Convert.IsDBNull(row["share_data"]))
                {
                    result._isShareDataNull = true;
                }
                else
                {
                    result._shareData = Convert.ToBoolean(row["share_data"]);
                    result._isShareDataNull = false;
                }
            }

            if (row.Table.Columns.Contains("timezone"))
            {
                if (Convert.IsDBNull(row["timezone"]))
                {
                    result._isTimezoneNull = true;
                }
                else
                {
                    result._timezone = Convert.ToInt32(row["timezone"]);
                    result._isTimezoneNull = false;
                }
            }

            if (row.Table.Columns.Contains("daylight_savings"))
            {
                if (Convert.IsDBNull(row["daylight_savings"]))
                {
                    result._isDaylightSavingsNull = true;
                }
                else
                {
                    result._daylightSavings = Convert.ToBoolean(row["daylight_savings"]);
                    result._isDaylightSavingsNull = false;
                }
            }

            if (row.Table.Columns.Contains("heat_fuel_price"))
            {
                if (Convert.IsDBNull(row["heat_fuel_price"]))
                {
                    result._isHeatFuelPriceNull = true;
                }
                else
                {
                    result._heatFuelPrice = Convert.ToDouble(row["heat_fuel_price"]);
                    result._isHeatFuelPriceNull = false;
                }
            }

            if (row.Table.Columns.Contains("open_weather_city_id"))
            {
                if (Convert.IsDBNull(row["open_weather_city_id"]))
                {
                    result._isOpenWeatherCityIdNull = true;
                }
                else
                {
                    result._openWeatherCityId = Convert.ToInt32(row["open_weather_city_id"]);
                    result._isOpenWeatherCityIdNull = false;
                }
            }

            return result;
        }
        public static int SaveLocation(Location location)
        {
            int result = 0;
            MySqlCommand cmd = new MySqlCommand("locations_save", ThermostatMonitorLib.Global.MySqlConnection);
            cmd.CommandType = CommandType.StoredProcedure;
            if (location._isIdNull)
            {
                cmd.Parameters.AddWithValue("@id", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@id", location._id);
            }

            if (location._isUserIdNull)
            {
                cmd.Parameters.AddWithValue("@user_id", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@user_id", location._userId);
            }

            if (location._isNameNull)
            {
                cmd.Parameters.AddWithValue("@name", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@name", location._name);
            }

            if (location._isApiKeyNull)
            {
                cmd.Parameters.AddWithValue("@api_key", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@api_key", location._apiKey);
            }

            if (location._isZipCodeNull)
            {
                cmd.Parameters.AddWithValue("@zip_code", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@zip_code", location._zipCode);
            }

            if (location._isElectricityPriceNull)
            {
                cmd.Parameters.AddWithValue("@electricity_price", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@electricity_price", location._electricityPrice);
            }

            if (location._isShareDataNull)
            {
                cmd.Parameters.AddWithValue("@share_data", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@share_data", location._shareData);
            }

            if (location._isTimezoneNull)
            {
                cmd.Parameters.AddWithValue("@timezone", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@timezone", location._timezone);
            }

            if (location._isDaylightSavingsNull)
            {
                cmd.Parameters.AddWithValue("@daylight_savings", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@daylight_savings", location._daylightSavings);
            }

            if (location._isHeatFuelPriceNull)
            {
                cmd.Parameters.AddWithValue("@heat_fuel_price", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@heat_fuel_price", location._heatFuelPrice);
            }

            if (location._isOpenWeatherCityIdNull)
            {
                cmd.Parameters.AddWithValue("@open_weather_city_id", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@open_weather_city_id", location._openWeatherCityId);
            }

            cmd.Connection.Open();
            try
            {
                result = Convert.ToInt32(cmd.ExecuteScalar());
            }
            finally
            {
                cmd.Connection.Close();
            }
            location.Id = result;
            return result;
        }
Exemple #17
0
 private void OutputCycles(ThermostatMonitorLib.Thermostat thermostat, ThermostatMonitorLib.Location location)
 {
     ThermostatMonitorLib.Cycles cycles = ThermostatMonitorLib.Cycles.LoadRange(thermostat.Id, new DateTime(2000, 1, 1), DateTime.Now);
     OutputCSV(cycles.GetCSV(thermostat.ACKilowatts, thermostat.FanKilowatts, thermostat.HeatBtuPerHour, AppUser.TimezoneDifference(location.Timezone, location.DaylightSavings)), "cycles.csv");
 }
        internal static Location GetLocation(DataRow row)
        {
            Location result = new Location();
            if (row.Table.Columns.Contains("Id"))
            {
                if (Convert.IsDBNull(row["Id"]))
                {
                    result._isIdNull = true;
                }
                else
                {
                    result._id = Convert.ToInt32(row["Id"]);
                    result._isIdNull = false;
                }
            }

            if (row.Table.Columns.Contains("UserId"))
            {
                if (Convert.IsDBNull(row["UserId"]))
                {
                    result._isUserIdNull = true;
                }
                else
                {
                    result._userId = Convert.ToInt32(row["UserId"]);
                    result._isUserIdNull = false;
                }
            }

            if (row.Table.Columns.Contains("Name"))
            {
                if (Convert.IsDBNull(row["Name"]))
                {
                    result._isNameNull = true;
                }
                else
                {
                    result._name = Convert.ToString(row["Name"]);
                    result._isNameNull = false;
                }
            }

            if (row.Table.Columns.Contains("ApiKey"))
            {
                if (Convert.IsDBNull(row["ApiKey"]))
                {
                    result._isApiKeyNull = true;
                }
                else
                {
                    result._apiKey = (System.Guid)(row["ApiKey"]);
                    result._isApiKeyNull = false;
                }
            }

            if (row.Table.Columns.Contains("ZipCode"))
            {
                if (Convert.IsDBNull(row["ZipCode"]))
                {
                    result._isZipCodeNull = true;
                }
                else
                {
                    result._zipCode = Convert.ToString(row["ZipCode"]);
                    result._isZipCodeNull = false;
                }
            }

            if (row.Table.Columns.Contains("ElectricityPrice"))
            {
                if (Convert.IsDBNull(row["ElectricityPrice"]))
                {
                    result._isElectricityPriceNull = true;
                }
                else
                {
                    result._electricityPrice = Convert.ToDouble(row["ElectricityPrice"]);
                    result._isElectricityPriceNull = false;
                }
            }

            if (row.Table.Columns.Contains("ShareData"))
            {
                if (Convert.IsDBNull(row["ShareData"]))
                {
                    result._isShareDataNull = true;
                }
                else
                {
                    result._shareData = Convert.ToBoolean(row["ShareData"]);
                    result._isShareDataNull = false;
                }
            }

            if (row.Table.Columns.Contains("Timezone"))
            {
                if (Convert.IsDBNull(row["Timezone"]))
                {
                    result._isTimezoneNull = true;
                }
                else
                {
                    result._timezone = Convert.ToInt32(row["Timezone"]);
                    result._isTimezoneNull = false;
                }
            }

            if (row.Table.Columns.Contains("DaylightSavings"))
            {
                if (Convert.IsDBNull(row["DaylightSavings"]))
                {
                    result._isDaylightSavingsNull = true;
                }
                else
                {
                    result._daylightSavings = Convert.ToBoolean(row["DaylightSavings"]);
                    result._isDaylightSavingsNull = false;
                }
            }

            if (row.Table.Columns.Contains("HeatFuelPrice"))
            {
                if (Convert.IsDBNull(row["HeatFuelPrice"]))
                {
                    result._isHeatFuelPriceNull = true;
                }
                else
                {
                    result._heatFuelPrice = Convert.ToDouble(row["HeatFuelPrice"]);
                    result._isHeatFuelPriceNull = false;
                }
            }

            if (row.Table.Columns.Contains("OpenWeatherCityId"))
            {
                if (Convert.IsDBNull(row["OpenWeatherCityId"]))
                {
                    result._isOpenWeatherCityIdNull = true;
                }
                else
                {
                    result._openWeatherCityId = Convert.ToInt32(row["OpenWeatherCityId"]);
                    result._isOpenWeatherCityIdNull = false;
                }
            }

            return result;
        }