protected void LinkButtonSave_Click(object sender,
     EventArgs e)
 {
     string nextFarm = TextBoxNextFarm.Text;
     if (!CheckInputData())
     {
         return;
     }
     DataBase dataBase = new DataBase();
     WebGuiSettings webGuiSettings = new WebGuiSettings
                                     {
                                         CoordinatesX = Int32.Parse(TextBoxCoordinateX.Text),
                                         CoordinatesY = Int32.Parse(TextBoxCoordinateY.Text),
                                         NextFarm = nextFarm.Length < 1 ? "-" : nextFarm,
                                         DistanceX = Int32.Parse(TextBoxDistanceX.Text),
                                         DistanceY = Int32.Parse(TextBoxDistanceY.Text)
                                     };
     if (!dataBase.SaveSettings(webGuiSettings))
     {
         LabelStatus.Text = "Can't save settings to DataBase!";
     }
 }
Exemple #2
0
 /// <summary>
 /// Saves the settings.
 /// </summary>
 /// <param name="webGuiSettings">The web GUI settings.</param>
 /// <returns><c>false</c> on fail.</returns>
 public bool SaveSettings(WebGuiSettings webGuiSettings)
 {
     try
     {
         using (sqlConnection = new SqlConnection(connectionString))
         {
             sqlConnection.Open();
             SqlCommand sqlCommand = sqlConnection.CreateCommand();
             sqlCommand.CommandType = CommandType.StoredProcedure;
             sqlCommand.CommandText = "UpdateSettings";
             sqlCommand.Parameters.Add(new SqlParameter("@CoordinatesX", SqlDbType.Int)).Value =
                 webGuiSettings.CoordinatesX;
             sqlCommand.Parameters.Add(new SqlParameter("@CoordinatesY", SqlDbType.Int)).Value =
                 webGuiSettings.CoordinatesY;
             sqlCommand.Parameters.Add(new SqlParameter("@NextFarm", SqlDbType.NVarChar)).Value =
                 webGuiSettings.NextFarm;
             sqlCommand.Parameters.Add(new SqlParameter("@DistanceX", SqlDbType.Int)).Value =
                 webGuiSettings.DistanceX;
             sqlCommand.Parameters.Add(new SqlParameter("@DistanceY", SqlDbType.Int)).Value =
                 webGuiSettings.DistanceY;
             sqlCommand.ExecuteNonQuery();
         }
     }
     catch (SqlException exception)
     {
         Log.Error(exception.Message);
         Log.Error(exception);
         return false;
     }
     finally
     {
         sqlConnection.Close();
     }
     return true;
 }
 protected Task RefreshData()
 {
     return(Task.WhenAll(WebGuiSettings.GetSettings(), PowerManagementSettings.GetSettings(),
                         NetworkSettings.GetSettings(),
                         DateAndTimeSettings.GetSettings(), AptSettings.GetSettings()));
 }
Exemple #4
0
 /// <summary>
 /// Gets the saved settings (Coordinates, distance and NextFarm).
 /// </summary>
 /// <returns>
 ///     <c>null</c> if failed.
 /// </returns>
 public WebGuiSettings GetSettings()
 {
     WebGuiSettings webGuiSettings = new WebGuiSettings();
     try
     {
         using (sqlConnection = new SqlConnection(connectionString))
         {
             sqlConnection.Open();
             SqlCommand sqlCommand = sqlConnection.CreateCommand();
             sqlCommand.CommandType = CommandType.StoredProcedure;
             sqlCommand.CommandText = "SelectSettings";
             SqlDataReader reader = sqlCommand.ExecuteReader();
             if (reader != null)
             {
                 while (reader.Read())
                 {
                     webGuiSettings.CoordinatesX = Int32.Parse(reader["CoordinatesX"].ToString());
                     webGuiSettings.CoordinatesY = Int32.Parse(reader["CoordinatesY"].ToString());
                     webGuiSettings.NextFarm = (reader["NextFarm"].ToString());
                     webGuiSettings.DistanceX = Int32.Parse(reader["DistanceX"].ToString());
                     webGuiSettings.DistanceY = Int32.Parse(reader["DistanceY"].ToString());
                 }
                 reader.Close();
             }
         }
     }
     catch (SqlException exception)
     {
         Log.Error(exception.Message);
         Log.Error(exception);
         return null;
     }
     finally
     {
         sqlConnection.Close();
     }
     return webGuiSettings;
 }