internal static UserSetting GetUserSetting(DataRow row) { UserSetting result = new UserSetting(); 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("ZipCode")) { if (Convert.IsDBNull(row["ZipCode"])) { result._isZipCodeNull = true; } else { result._zipCode = Convert.ToString(row["ZipCode"]); result._isZipCodeNull = false; } } if (row.Table.Columns.Contains("FilterChangeDate")) { if (Convert.IsDBNull(row["FilterChangeDate"])) { result._isFilterChangeDateNull = true; } else { result._filterChangeDate = Convert.ToDateTime(row["FilterChangeDate"]); result._isFilterChangeDateNull = 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; } } return result; }
public static int SaveUserSetting(UserSetting userSetting) { int result = 0; SqlCommand cmd = new SqlCommand("SaveUserSetting", ThermostatMonitorLib.Global.Connection); cmd.CommandType = CommandType.StoredProcedure; if (userSetting._isIdNull) { cmd.Parameters.AddWithValue("@Id", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@Id", userSetting._id); } if (userSetting._isZipCodeNull) { cmd.Parameters.AddWithValue("@ZipCode", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@ZipCode", userSetting._zipCode); } if (userSetting._isFilterChangeDateNull) { cmd.Parameters.AddWithValue("@FilterChangeDate", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@FilterChangeDate", userSetting._filterChangeDate); } if (userSetting._isUserIdNull) { cmd.Parameters.AddWithValue("@UserId", System.DBNull.Value); } else { cmd.Parameters.AddWithValue("@UserId", userSetting._userId); } cmd.Connection.Open(); try { result = Convert.ToInt32(cmd.ExecuteScalar()); } finally { cmd.Connection.Close(); } userSetting.Id = result; return result; }