예제 #1
0
        private void ClearDatabase()
        {
            var sqldb_connection = ConnectionStringBuilder.ConnectionString();

            using (SqlConnection con = new SqlConnection(sqldb_connection))
                try
                {
                    con.Open();

                    SqlCommand GetRunIDCommand = new SqlCommand("[dbo].[ClearDownDatabase]", con)
                    {
                        CommandType = CommandType.StoredProcedure
                    };

                    GetRunIDCommand.ExecuteNonQuery();
                }

                catch (Exception ex)
                {
                    _ = ex.Message.ToString();
                }
        }
예제 #2
0
        private void SaveCurrentlyData(int runID, DateTime sunrise, DateTime sunset, Guid runGuid, Decimal?snow, Decimal?rain, Decimal?temperature, Decimal?apparentTemperature, Decimal?windSpeed, Decimal?windGust, Decimal?windBearing, Decimal?dewPoint, Decimal?humidity, Decimal?pressure, Decimal?cloudCover, Decimal?uvIndex, Decimal?visibility, Decimal?ozone)
        {
            var sqldb_connection = ConnectionStringBuilder.ConnectionString();

            using (SqlConnection con = new SqlConnection(sqldb_connection))
                try
                {
                    con.Open();

                    SqlCommand SaveWeatherData = new SqlCommand("[dbo].[SaveWeatherData]", con)
                    {
                        CommandType = CommandType.StoredProcedure
                    };

                    SaveWeatherData.Parameters.Add("@runID", SqlDbType.Int);
                    SaveWeatherData.Parameters["@runID"].Value = runID;

                    SaveWeatherData.Parameters.Add("@runGuid", SqlDbType.UniqueIdentifier);
                    SaveWeatherData.Parameters["@runGuid"].Value = runGuid;

                    SaveWeatherData.Parameters.Add("@sunrise", SqlDbType.DateTime);

                    if (sunrise != null)
                    {
                        SaveWeatherData.Parameters["@sunrise"].Value = sunrise;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@sunrise"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@sunset", SqlDbType.DateTime);

                    if (sunset != null)
                    {
                        SaveWeatherData.Parameters["@sunset"].Value = sunset;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@sunset"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@rain", SqlDbType.Decimal);

                    if (rain != null)
                    {
                        SaveWeatherData.Parameters["@rain"].Value = rain;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@rain"].Value = DBNull.Value;
                    }

                    if (temperature != null)
                    {
                        SaveWeatherData.Parameters.Add("@temperature", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@temperature"].Value = temperature;
                    }
                    else
                    {
                        SaveWeatherData.Parameters.Add("@temperature", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@temperature"].Value = DBNull.Value;
                    }

                    if (apparentTemperature != null)
                    {
                        SaveWeatherData.Parameters.Add("@apparentTemperature", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@apparentTemperature"].Value = apparentTemperature;
                    }
                    else
                    {
                        SaveWeatherData.Parameters.Add("@apparentTemperature", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@apparentTemperature"].Value = DBNull.Value;
                    }

                    if (windSpeed != null)

                    {
                        SaveWeatherData.Parameters.Add("@windSpeed", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@windSpeed"].Value = windSpeed;
                    }
                    else

                    {
                        SaveWeatherData.Parameters.Add("@windSpeed", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@windSpeed"].Value = DBNull.Value;
                    }

                    if (windGust != null)
                    {
                        SaveWeatherData.Parameters.Add("@windGust", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@windGust"].Value = windGust;
                    }
                    else
                    {
                        SaveWeatherData.Parameters.Add("@windGust", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@windGust"].Value = DBNull.Value;
                    }

                    if (windBearing != null)
                    {
                        SaveWeatherData.Parameters.Add("@windBearing", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@windBearing"].Value = windBearing;
                    }
                    else
                    {
                        SaveWeatherData.Parameters.Add("@windBearing", SqlDbType.Decimal);
                        SaveWeatherData.Parameters["@windBearing"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@dewPoint", SqlDbType.Decimal);
                    if (dewPoint != null)
                    {
                        SaveWeatherData.Parameters["@dewPoint"].Value = dewPoint;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@dewPoint"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@humidity", SqlDbType.Decimal);
                    if (humidity != null)
                    {
                        SaveWeatherData.Parameters["@humidity"].Value = humidity;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@humidity"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@pressure", SqlDbType.Decimal);
                    if (pressure != null)
                    {
                        SaveWeatherData.Parameters["@pressure"].Value = pressure;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@pressure"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@cloudCover", SqlDbType.Decimal);
                    if (cloudCover != null)
                    {
                        SaveWeatherData.Parameters["@cloudCover"].Value = cloudCover + 'M';
                        //SaveWeatherData.Parameters["@cloudCover"].Value = DBNull.Value;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@cloudCover"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@uvIndex", SqlDbType.Decimal);
                    if (uvIndex != null)
                    {
                        SaveWeatherData.Parameters["@uvIndex"].Value = uvIndex;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@uvIndex"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@visibility", SqlDbType.Decimal);
                    if (visibility != null)
                    {
                        SaveWeatherData.Parameters["@visibility"].Value = visibility;
                        //SaveWeatherData.Parameters["@visibility"].Value = DBNull.Value;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@visibility"].Value = DBNull.Value;
                    }

                    SaveWeatherData.Parameters.Add("@ozone", SqlDbType.Decimal);
                    if (ozone != null)
                    {
                        SaveWeatherData.Parameters["@ozone"].Value = ozone;
                    }
                    else
                    {
                        SaveWeatherData.Parameters["@ozone"].Value = DBNull.Value;
                    }

                    txtLogging.AppendText(DateTime.Now.ToLongTimeString() + " Attempting to save data to the database" + Environment.NewLine);
                    SaveWeatherData.ExecuteNonQuery();
                    txtLogging.AppendText(DateTime.Now.ToLongTimeString() + " Saving to the database was sucessful" + Environment.NewLine);
                }

                catch (Exception ex)
                {
                    txtLogging.AppendText(DateTime.Now.ToShortTimeString() + " " + ex.Message.ToString() + Environment.NewLine);
                }
        }