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"); }
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(); } }
private void LogCycle(bool start, int locationId) { string thermostatIp = Request["thermostatIP"]; System.Int16 precision = Convert.ToInt16(Request["Precision"]); if (Request["Precision"] == null) { precision = -1; } ThermostatMonitorLib.Thermostat thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(locationId, thermostatIp); if (thermostat == null) { return; } string mode = ""; bool running = false; ThermostatMonitorLib.Cycle.EndOpenCycle(thermostat.Id, precision); //whether start or end, always close any open cycles if (start) { string cycleType = Request["cycleType"]; ThermostatMonitorLib.Cycle.StartCycle(thermostat.Id, cycleType, precision); } }
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 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; } }
public static void Generate(int thermostatId) { DateTime startDate = new DateTime(2000, 1, 1); Snapshot lastSnapshot = Snapshot.LoadLastSnapshot(thermostatId); if (lastSnapshot != null) { startDate = lastSnapshot.StartTime.AddSeconds(lastSnapshot.Seconds); } Thermostat thermostat = Thermostat.LoadThermostat(thermostatId); Cycles cycles = Cycles.LoadRange(thermostatId, startDate, DateTime.Now); Temperatures temperatures = Temperatures.LoadRange(thermostatId, startDate.AddDays(-1), DateTime.Now); //we need the previous temperature and conditions OutsideConditions conditions = OutsideConditions.LoadRange(thermostat.LocationId, startDate.AddDays(-1), DateTime.Now); cycles.RemoveIncomplete(); if (cycles.Count == 0) { return; } DateTime lastCycleEndDate = cycles[0].StartDate; if (lastSnapshot != null) { lastCycleEndDate = startDate; } foreach (Cycle cycle in cycles) { try { LogOffCycle(thermostat.Id, cycle, lastCycleEndDate, temperatures, conditions); } catch { } try { LogOnCycle(thermostat.Id, cycle, temperatures, conditions); } catch { } lastCycleEndDate = cycle.EndDate; } }
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); }
private void LogTemperature(int locationId) { string thermostatIp = Request["thermostatIP"]; System.Int16 precision = Convert.ToInt16(Request["Precision"]); if (Request["Precision"] == null) { precision = -1; } ThermostatMonitorLib.Thermostat thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(locationId, thermostatIp); if (thermostat == null) { return; } int temperature = Convert.ToInt32(Request["temperature"]); ThermostatMonitorLib.Temperature.CheckAndLogTemperature(thermostat.Id, temperature, precision); }
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(); }
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; } }
internal static Thermostat GetThermostat(DataRow row) { Thermostat result = new Thermostat(); 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("ip_address")) { if (Convert.IsDBNull(row["ip_address"])) { result._isIpAddressNull = true; } else { result._ipAddress = Convert.ToString(row["ip_address"]); result._isIpAddressNull = false; } } if (row.Table.Columns.Contains("display_name")) { if (Convert.IsDBNull(row["display_name"])) { result._isDisplayNameNull = true; } else { result._displayName = Convert.ToString(row["display_name"]); result._isDisplayNameNull = false; } } if (row.Table.Columns.Contains("ac_tons")) { if (Convert.IsDBNull(row["ac_tons"])) { result._isAcTonsNull = true; } else { result._acTons = Convert.ToDouble(row["ac_tons"]); result._isAcTonsNull = false; } } if (row.Table.Columns.Contains("ac_seer")) { if (Convert.IsDBNull(row["ac_seer"])) { result._isAcSeerNull = true; } else { result._acSeer = Convert.ToInt32(row["ac_seer"]); result._isAcSeerNull = false; } } if (row.Table.Columns.Contains("ac_kilowatts")) { if (Convert.IsDBNull(row["ac_kilowatts"])) { result._isAcKilowattsNull = true; } else { result._acKilowatts = Convert.ToDouble(row["ac_kilowatts"]); result._isAcKilowattsNull = false; } } if (row.Table.Columns.Contains("fan_kilowatts")) { if (Convert.IsDBNull(row["fan_kilowatts"])) { result._isFanKilowattsNull = true; } else { result._fanKilowatts = Convert.ToDouble(row["fan_kilowatts"]); result._isFanKilowattsNull = false; } } if (row.Table.Columns.Contains("brand")) { if (Convert.IsDBNull(row["brand"])) { result._isBrandNull = true; } else { result._brand = Convert.ToString(row["brand"]); result._isBrandNull = false; } } if (row.Table.Columns.Contains("location_id")) { if (Convert.IsDBNull(row["location_id"])) { result._isLocationIdNull = true; } else { result._locationId = Convert.ToInt32(row["location_id"]); result._isLocationIdNull = false; } } if (row.Table.Columns.Contains("heat_btu_per_hour")) { if (Convert.IsDBNull(row["heat_btu_per_hour"])) { result._isHeatBtuPerHourNull = true; } else { result._heatBtuPerHour = Convert.ToDouble(row["heat_btu_per_hour"]); result._isHeatBtuPerHourNull = false; } } if (row.Table.Columns.Contains("key_name")) { if (Convert.IsDBNull(row["key_name"])) { result._isKeyNameNull = true; } else { result._keyName = Convert.ToString(row["key_name"]); result._isKeyNameNull = false; } } return result; }
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\"> </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\"> </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\"> </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(); }
public static int SaveThermostat(Thermostat thermostat) { int result = 0; MySqlCommand cmd = new MySqlCommand("thermostats_save", ThermostatMonitorLib.Global.MySqlConnection); cmd.CommandType = CommandType.StoredProcedure; if (thermostat._isIdNull) { cmd.Parameters.AddWithValue("@id", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@id", thermostat._id); } if (thermostat._isIpAddressNull) { cmd.Parameters.AddWithValue("@ip_address", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ip_address", thermostat._ipAddress); } if (thermostat._isDisplayNameNull) { cmd.Parameters.AddWithValue("@display_name", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@display_name", thermostat._displayName); } if (thermostat._isAcTonsNull) { cmd.Parameters.AddWithValue("@ac_tons", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ac_tons", thermostat._acTons); } if (thermostat._isAcSeerNull) { cmd.Parameters.AddWithValue("@ac_seer", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ac_seer", thermostat._acSeer); } if (thermostat._isAcKilowattsNull) { cmd.Parameters.AddWithValue("@ac_kilowatts", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ac_kilowatts", thermostat._acKilowatts); } if (thermostat._isFanKilowattsNull) { cmd.Parameters.AddWithValue("@fan_kilowatts", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@fan_kilowatts", thermostat._fanKilowatts); } if (thermostat._isBrandNull) { cmd.Parameters.AddWithValue("@brand", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@brand", thermostat._brand); } if (thermostat._isLocationIdNull) { cmd.Parameters.AddWithValue("@location_id", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@location_id", thermostat._locationId); } if (thermostat._isHeatBtuPerHourNull) { cmd.Parameters.AddWithValue("@heat_btu_per_hour", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@heat_btu_per_hour", thermostat._heatBtuPerHour); } if (thermostat._isKeyNameNull) { cmd.Parameters.AddWithValue("@key_name", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@key_name", thermostat._keyName); } cmd.Connection.Open(); try { result = Convert.ToInt32(cmd.ExecuteScalar()); } finally { cmd.Connection.Close(); } thermostat.Id = result; return result; }
public void Populate(int thermostatId, DateTime startTime, DateTime endTime) { ThermostatMonitorLib.Thermostat thermostat = ThermostatMonitorLib.Thermostat.LoadThermostat(thermostatId); ThermostatMonitorLib.Temperatures temps = ThermostatMonitorLib.Temperatures.LoadRange(thermostatId, startTime, endTime); ThermostatMonitorLib.OutsideConditions conditions = ThermostatMonitorLib.OutsideConditions.LoadRange(thermostat.LocationId, startTime, endTime); DataTable dt = new DataTable(); dt.Columns.Add("LogDate", typeof(DateTime)); dt.Columns.Add("InsideTemperature", typeof(double)); //dt.Columns.Add("AC_On", typeof(double)); dt.Columns.Add("OutsideTemperature", typeof(double)); for (int i = 0; i < temps.Count; i++) { ThermostatMonitorLib.Temperature temp = temps[i]; if (temp.Degrees == Convert.ToInt32(temp.Degrees)) { if (i > 0) { DataRow pRow = dt.NewRow(); pRow[0] = temp.LogDate.AddSeconds(-1); pRow[1] = temps[i - 1].Degrees; dt.Rows.Add(pRow); } DataRow row = dt.NewRow(); row[0] = temp.LogDate; row[1] = temp.Degrees; dt.Rows.Add(row); } } foreach (ThermostatMonitorLib.OutsideCondition condition in conditions) { DataRow row = dt.NewRow(); row[0] = condition.LogDate; row[2] = condition.Degrees; dt.Rows.Add(row); } if (conditions.Count > 0 && temps.Count > 0) { DataRow row = dt.NewRow(); row[0] = startTime; row[1] = temps[0].Degrees; row[2] = conditions[0].Degrees; dt.Rows.Add(row); row = dt.NewRow(); row[0] = endTime; row[1] = temps[temps.Count - 1].Degrees; row[2] = conditions[conditions.Count - 1].Degrees; dt.Rows.Add(row); } OutputData(dt); return; }
public static int SaveThermostat(Thermostat thermostat) { int result = 0; SqlCommand cmd = new SqlCommand("SaveThermostat", ThermostatMonitorLib.Global.Connection); cmd.CommandType = CommandType.StoredProcedure; if (thermostat._isIdNull) { cmd.Parameters.AddWithValue("@Id", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@Id", thermostat._id); } if (thermostat._isIpAddressNull) { cmd.Parameters.AddWithValue("@IpAddress", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@IpAddress", thermostat._ipAddress); } if (thermostat._isDisplayNameNull) { cmd.Parameters.AddWithValue("@DisplayName", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@DisplayName", thermostat._displayName); } if (thermostat._isACTonsNull) { cmd.Parameters.AddWithValue("@ACTons", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ACTons", thermostat._aCTons); } if (thermostat._isACSeerNull) { cmd.Parameters.AddWithValue("@ACSeer", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ACSeer", thermostat._aCSeer); } if (thermostat._isACKilowattsNull) { cmd.Parameters.AddWithValue("@ACKilowatts", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ACKilowatts", thermostat._aCKilowatts); } if (thermostat._isFanKilowattsNull) { cmd.Parameters.AddWithValue("@FanKilowatts", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@FanKilowatts", thermostat._fanKilowatts); } if (thermostat._isBrandNull) { cmd.Parameters.AddWithValue("@Brand", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@Brand", thermostat._brand); } if (thermostat._isLocationIdNull) { cmd.Parameters.AddWithValue("@LocationId", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@LocationId", thermostat._locationId); } if (thermostat._isHeatBtuPerHourNull) { cmd.Parameters.AddWithValue("@HeatBtuPerHour", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@HeatBtuPerHour", thermostat._heatBtuPerHour); } if (thermostat._isKeyNameNull) { cmd.Parameters.AddWithValue("@KeyName", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@KeyName", thermostat._keyName); } cmd.Connection.Open(); try { result = Convert.ToInt32(cmd.ExecuteScalar()); } finally { cmd.Connection.Close(); } thermostat.Id = result; return(result); }
public static int SaveThermostat(Thermostat thermostat) { int result = 0; MySqlCommand cmd = new MySqlCommand("thermostats_save", ThermostatMonitorLib.Global.MySqlConnection); cmd.CommandType = CommandType.StoredProcedure; if (thermostat._isIdNull) { cmd.Parameters.AddWithValue("@id", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@id", thermostat._id); } if (thermostat._isIpAddressNull) { cmd.Parameters.AddWithValue("@ip_address", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ip_address", thermostat._ipAddress); } if (thermostat._isDisplayNameNull) { cmd.Parameters.AddWithValue("@display_name", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@display_name", thermostat._displayName); } if (thermostat._isAcTonsNull) { cmd.Parameters.AddWithValue("@ac_tons", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ac_tons", thermostat._acTons); } if (thermostat._isAcSeerNull) { cmd.Parameters.AddWithValue("@ac_seer", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ac_seer", thermostat._acSeer); } if (thermostat._isAcKilowattsNull) { cmd.Parameters.AddWithValue("@ac_kilowatts", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ac_kilowatts", thermostat._acKilowatts); } if (thermostat._isFanKilowattsNull) { cmd.Parameters.AddWithValue("@fan_kilowatts", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@fan_kilowatts", thermostat._fanKilowatts); } if (thermostat._isBrandNull) { cmd.Parameters.AddWithValue("@brand", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@brand", thermostat._brand); } if (thermostat._isLocationIdNull) { cmd.Parameters.AddWithValue("@location_id", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@location_id", thermostat._locationId); } if (thermostat._isHeatBtuPerHourNull) { cmd.Parameters.AddWithValue("@heat_btu_per_hour", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@heat_btu_per_hour", thermostat._heatBtuPerHour); } if (thermostat._isKeyNameNull) { cmd.Parameters.AddWithValue("@key_name", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@key_name", thermostat._keyName); } cmd.Connection.Open(); try { result = Convert.ToInt32(cmd.ExecuteScalar()); } finally { cmd.Connection.Close(); } thermostat.Id = result; return(result); }
internal static Thermostat GetThermostat(DataRow row) { Thermostat result = new Thermostat(); 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("ip_address")) { if (Convert.IsDBNull(row["ip_address"])) { result._isIpAddressNull = true; } else { result._ipAddress = Convert.ToString(row["ip_address"]); result._isIpAddressNull = false; } } if (row.Table.Columns.Contains("display_name")) { if (Convert.IsDBNull(row["display_name"])) { result._isDisplayNameNull = true; } else { result._displayName = Convert.ToString(row["display_name"]); result._isDisplayNameNull = false; } } if (row.Table.Columns.Contains("ac_tons")) { if (Convert.IsDBNull(row["ac_tons"])) { result._isAcTonsNull = true; } else { result._acTons = Convert.ToDouble(row["ac_tons"]); result._isAcTonsNull = false; } } if (row.Table.Columns.Contains("ac_seer")) { if (Convert.IsDBNull(row["ac_seer"])) { result._isAcSeerNull = true; } else { result._acSeer = Convert.ToInt32(row["ac_seer"]); result._isAcSeerNull = false; } } if (row.Table.Columns.Contains("ac_kilowatts")) { if (Convert.IsDBNull(row["ac_kilowatts"])) { result._isAcKilowattsNull = true; } else { result._acKilowatts = Convert.ToDouble(row["ac_kilowatts"]); result._isAcKilowattsNull = false; } } if (row.Table.Columns.Contains("fan_kilowatts")) { if (Convert.IsDBNull(row["fan_kilowatts"])) { result._isFanKilowattsNull = true; } else { result._fanKilowatts = Convert.ToDouble(row["fan_kilowatts"]); result._isFanKilowattsNull = false; } } if (row.Table.Columns.Contains("brand")) { if (Convert.IsDBNull(row["brand"])) { result._isBrandNull = true; } else { result._brand = Convert.ToString(row["brand"]); result._isBrandNull = false; } } if (row.Table.Columns.Contains("location_id")) { if (Convert.IsDBNull(row["location_id"])) { result._isLocationIdNull = true; } else { result._locationId = Convert.ToInt32(row["location_id"]); result._isLocationIdNull = false; } } if (row.Table.Columns.Contains("heat_btu_per_hour")) { if (Convert.IsDBNull(row["heat_btu_per_hour"])) { result._isHeatBtuPerHourNull = true; } else { result._heatBtuPerHour = Convert.ToDouble(row["heat_btu_per_hour"]); result._isHeatBtuPerHourNull = false; } } if (row.Table.Columns.Contains("key_name")) { if (Convert.IsDBNull(row["key_name"])) { result._isKeyNameNull = true; } else { result._keyName = Convert.ToString(row["key_name"]); result._isKeyNameNull = false; } } return(result); }
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 Thermostat GetThermostat(DataRow row) { Thermostat result = new Thermostat(); 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("IpAddress")) { if (Convert.IsDBNull(row["IpAddress"])) { result._isIpAddressNull = true; } else { result._ipAddress = Convert.ToString(row["IpAddress"]); result._isIpAddressNull = false; } } if (row.Table.Columns.Contains("DisplayName")) { if (Convert.IsDBNull(row["DisplayName"])) { result._isDisplayNameNull = true; } else { result._displayName = Convert.ToString(row["DisplayName"]); result._isDisplayNameNull = false; } } if (row.Table.Columns.Contains("ACTons")) { if (Convert.IsDBNull(row["ACTons"])) { result._isACTonsNull = true; } else { result._aCTons = Convert.ToDouble(row["ACTons"]); result._isACTonsNull = false; } } if (row.Table.Columns.Contains("ACSeer")) { if (Convert.IsDBNull(row["ACSeer"])) { result._isACSeerNull = true; } else { result._aCSeer = Convert.ToInt32(row["ACSeer"]); result._isACSeerNull = false; } } if (row.Table.Columns.Contains("ACKilowatts")) { if (Convert.IsDBNull(row["ACKilowatts"])) { result._isACKilowattsNull = true; } else { result._aCKilowatts = Convert.ToDouble(row["ACKilowatts"]); result._isACKilowattsNull = false; } } if (row.Table.Columns.Contains("FanKilowatts")) { if (Convert.IsDBNull(row["FanKilowatts"])) { result._isFanKilowattsNull = true; } else { result._fanKilowatts = Convert.ToDouble(row["FanKilowatts"]); result._isFanKilowattsNull = false; } } if (row.Table.Columns.Contains("Brand")) { if (Convert.IsDBNull(row["Brand"])) { result._isBrandNull = true; } else { result._brand = Convert.ToString(row["Brand"]); result._isBrandNull = false; } } if (row.Table.Columns.Contains("LocationId")) { if (Convert.IsDBNull(row["LocationId"])) { result._isLocationIdNull = true; } else { result._locationId = Convert.ToInt32(row["LocationId"]); result._isLocationIdNull = false; } } if (row.Table.Columns.Contains("HeatBtuPerHour")) { if (Convert.IsDBNull(row["HeatBtuPerHour"])) { result._isHeatBtuPerHourNull = true; } else { result._heatBtuPerHour = Convert.ToDouble(row["HeatBtuPerHour"]); result._isHeatBtuPerHourNull = false; } } if (row.Table.Columns.Contains("KeyName")) { if (Convert.IsDBNull(row["KeyName"])) { result._isKeyNameNull = true; } else { result._keyName = Convert.ToString(row["KeyName"]); result._isKeyNameNull = false; } } return(result); }