/// <summary> /// Pulls all the recipes from the selected table in the database. /// </summary> /// <param name="commandString"></param> /// <param name="recipeBook"></param> public void PullRecipesFromDatabase(string commandString, IRecipeBook recipeBook) //metoda służąca pobieraniu danych //dotyczących przepisów i zapisywaniu { //ich w książce przepisów AbstractRecipeFactory recipeFactory = new StandardRecipeFactory(); //metoda korzysta z fabryki przepisów do konstruowania DataBase.Connection = new MySqlConnection(DataBase.ConnectionString); //umożliwia nawiązanie połączenia DataBase.Command = new MySqlCommand(commandString, (MySqlConnection)DataBase.Connection); //umożliwia przekazanie polecenia using (DataBase.Connection) { using (DataBase.Command) { try { DataBase.Connection.Open(); //otwiera połączenie dataReader = DataBase.Command.ExecuteReader(); //umożliwia odczyt danych z bazy while (dataReader.Read()) { { recipeBook.Recipebook.Add(recipeFactory.CreateRecipe //pobiera dane zapisane w bazie w postaci (dataReader.GetString(0), //stringów i zapisuje je jako obiekt klasy DataBase.Converter.FromStringToListOfIngredients //Recipe (dataReader.GetString(1)), dataReader.GetString(2))); } } } catch (MySqlException) { MessageBox.Show("Failed to connect with the database"); } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); } } DataBase.Connection.Close();//zamyka połączenie } }
public void PullRecipesFromDatabase(string commandString, IRecipeBook recipeBook) { AbstractRecipeFactory recipeFactory = new StandardRecipeFactory(); DataBase.MYSQLConnection = new MySqlConnection(DataBase.ConnectionString); DataBase.MYSQLCommand = new MySqlCommand(commandString, DataBase.MYSQLConnection); using (DataBase.MYSQLConnection) { using (DataBase.MYSQLCommand) { try { DataBase.MYSQLConnection.Open(); dataReader = DataBase.MYSQLCommand.ExecuteReader(); while (dataReader.Read()) { { recipeBook.Recipebook.Add(recipeFactory.CreateRecipe(dataReader.GetString(0), DataBase.Converter.FromStringToListOfIngredients(dataReader.GetString(1)), dataReader.GetString(2))); } } } catch (MySqlException) { MessageBox.Show("Failed to connect with the database"); } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); } } DataBase.MYSQLConnection.Close(); } }
private async void Start() { SetDragThreshold(); #if UNITY_IOS Destroy(GameObject.Find("ExitButton")); #endif _recipeBook = new RecipeBook(); _forge = new Forge(_recipeBook, new NetworkMixChecker()); _elementItemPrefab = (GameObject)Resources.Load("Prefabs/ElementItem", typeof(GameObject)); _newElementWindowPrefab = (GameObject)Resources.Load("Prefabs/NewElementWindow", typeof(GameObject)); _somethingWrongWindowPrefab = (GameObject)Resources.Load("Prefabs/SomethingWrongWindow", typeof(GameObject)); _confirmExitWindowPrefab = (GameObject)Resources.Load("Prefabs/ConfirmExitWindow", typeof(GameObject)); var loadInitialElements = await _recipeBook.LoadInitialElements(); if (loadInitialElements.IsSuccess) { var initialElements = loadInitialElements.Data.ToList(); InitializeElements(initialElements); InitializeScores(initialElements); } else { Instantiate(_somethingWrongWindowPrefab, UnderUpperLayerTransform); } }
public Forge(IRecipeBook book, IMixChecker mixChecker) { _book = book; _mixChecker = mixChecker; }
public static void SetCurrent(string savePath = null) { Current = RecipeBookImpl.Load(savePath); }
public static void Remove(this IRecipeBook recipeBook, BookObject domainObject) { recipeBook.Remove(domainObject.Id); }