Esempio n. 1
0
        public static int SaveThermostatSetting(ThermostatSetting thermostatSetting)
        {
            int        result = 0;
            SqlCommand cmd    = new SqlCommand("SaveThermostatSetting", ThermostatMonitorLib.Global.Connection);

            cmd.CommandType = CommandType.StoredProcedure;
            if (thermostatSetting._isIdNull)
            {
                cmd.Parameters.AddWithValue("@Id", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Id", thermostatSetting._id);
            }

            if (thermostatSetting._isThermostatIdNull)
            {
                cmd.Parameters.AddWithValue("@ThermostatId", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@ThermostatId", thermostatSetting._thermostatId);
            }

            if (thermostatSetting._isLogDateNull)
            {
                cmd.Parameters.AddWithValue("@LogDate", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@LogDate", thermostatSetting._logDate);
            }

            if (thermostatSetting._isDegreesNull)
            {
                cmd.Parameters.AddWithValue("@Degrees", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Degrees", thermostatSetting._degrees);
            }

            if (thermostatSetting._isModeNull)
            {
                cmd.Parameters.AddWithValue("@Mode", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Mode", thermostatSetting._mode);
            }

            cmd.Connection.Open();
            try
            {
                result = Convert.ToInt32(cmd.ExecuteScalar());
            }
            finally
            {
                cmd.Connection.Close();
            }
            thermostatSetting.Id = result;
            return(result);
        }
        internal static ThermostatSetting GetThermostatSetting(DataRow row)
        {
            ThermostatSetting result = new ThermostatSetting();
            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("ThermostatId"))
            {
                if (Convert.IsDBNull(row["ThermostatId"]))
                {
                    result._isThermostatIdNull = true;
                }
                else
                {
                    result._thermostatId = Convert.ToInt32(row["ThermostatId"]);
                    result._isThermostatIdNull = false;
                }
            }

            if (row.Table.Columns.Contains("LogDate"))
            {
                if (Convert.IsDBNull(row["LogDate"]))
                {
                    result._isLogDateNull = true;
                }
                else
                {
                    result._logDate = Convert.ToDateTime(row["LogDate"]);
                    result._isLogDateNull = false;
                }
            }

            if (row.Table.Columns.Contains("Degrees"))
            {
                if (Convert.IsDBNull(row["Degrees"]))
                {
                    result._isDegreesNull = true;
                }
                else
                {
                    result._degrees = Convert.ToDouble(row["Degrees"]);
                    result._isDegreesNull = false;
                }
            }

            if (row.Table.Columns.Contains("Mode"))
            {
                if (Convert.IsDBNull(row["Mode"]))
                {
                    result._isModeNull = true;
                }
                else
                {
                    result._mode = Convert.ToString(row["Mode"]);
                    result._isModeNull = false;
                }
            }

            return result;
        }
Esempio n. 3
0
        internal static ThermostatSetting GetThermostatSetting(DataRow row)
        {
            ThermostatSetting result = new ThermostatSetting();

            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("ThermostatId"))
            {
                if (Convert.IsDBNull(row["ThermostatId"]))
                {
                    result._isThermostatIdNull = true;
                }
                else
                {
                    result._thermostatId       = Convert.ToInt32(row["ThermostatId"]);
                    result._isThermostatIdNull = false;
                }
            }

            if (row.Table.Columns.Contains("LogDate"))
            {
                if (Convert.IsDBNull(row["LogDate"]))
                {
                    result._isLogDateNull = true;
                }
                else
                {
                    result._logDate       = Convert.ToDateTime(row["LogDate"]);
                    result._isLogDateNull = false;
                }
            }

            if (row.Table.Columns.Contains("Degrees"))
            {
                if (Convert.IsDBNull(row["Degrees"]))
                {
                    result._isDegreesNull = true;
                }
                else
                {
                    result._degrees       = Convert.ToDouble(row["Degrees"]);
                    result._isDegreesNull = false;
                }
            }

            if (row.Table.Columns.Contains("Mode"))
            {
                if (Convert.IsDBNull(row["Mode"]))
                {
                    result._isModeNull = true;
                }
                else
                {
                    result._mode       = Convert.ToString(row["Mode"]);
                    result._isModeNull = false;
                }
            }

            return(result);
        }
        public static int SaveThermostatSetting(ThermostatSetting thermostatSetting)
        {
            int result = 0;
            SqlCommand cmd = new SqlCommand("SaveThermostatSetting", ThermostatMonitorLib.Global.Connection);
            cmd.CommandType = CommandType.StoredProcedure;
            if (thermostatSetting._isIdNull)
            {
                cmd.Parameters.AddWithValue("@Id", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Id", thermostatSetting._id);
            }

            if (thermostatSetting._isThermostatIdNull)
            {
                cmd.Parameters.AddWithValue("@ThermostatId", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@ThermostatId", thermostatSetting._thermostatId);
            }

            if (thermostatSetting._isLogDateNull)
            {
                cmd.Parameters.AddWithValue("@LogDate", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@LogDate", thermostatSetting._logDate);
            }

            if (thermostatSetting._isDegreesNull)
            {
                cmd.Parameters.AddWithValue("@Degrees", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Degrees", thermostatSetting._degrees);
            }

            if (thermostatSetting._isModeNull)
            {
                cmd.Parameters.AddWithValue("@Mode", System.DBNull.Value);
            }
            else
            {
                cmd.Parameters.AddWithValue("@Mode", thermostatSetting._mode);
            }

            cmd.Connection.Open();
            try
            {
                result = Convert.ToInt32(cmd.ExecuteScalar());
            }
            finally
            {
                cmd.Connection.Close();
            }
            thermostatSetting.Id = result;
            return result;
        }