Exemple #1
0
 /// <summary>
 /// Pulls all the data from specified table and puts it in the selected fridge.
 /// </summary>
 /// <param name="commandString"></param>
 /// <param name="fridge"></param>
 public void PullIngredientsFromDataBase(string commandString, AbstractFridge fridge)             //metoda pobierająca dane dotyczące
 {                                                                                                //składników w bazie danych i umieszcza
                                                                                                  //w odpowiedniej lodówce
     DataBase.Connection = new MySqlConnection(DataBase.ConnectionString);                        //umożliwia otwarcie połączenia
     DataBase.Command    = new MySqlCommand(commandString, (MySqlConnection)DataBase.Connection); //umożliwia przekazanie polecenia
     //do bazy danych w MySql
     using (DataBase.Connection)
     {
         using (DataBase.Command)
         {
             try
             {
                 DataBase.Connection.Open();                        //otwarcie połączenia
                 {
                     dataReader = DataBase.Command.ExecuteReader(); //umożliwia odczyt danych z bazy
                     while (dataReader.Read())
                     {
                         fridge.AddIngredient                                      //dodaje do lodówki wszystkie składniki dostępne w bazie danych
                             (FactoryPicker.Instance.Pick(dataReader.GetString(0)) //wybiera fabryki na podstawie nazwy składnika
                             .Create(Convert.ToDouble(CommaFormat(dataReader.GetString(1))), dataReader.GetDateTime(2)));
                         //tworzy składniki o parametrach z bazy danych
                     }
                 }
             }
             catch (Exception)
             { MessageBox.Show("There has been a problem with connecting to the Database", "DBPuller.PullIngredients"); }
         }
         DataBase.Connection.Close();//zamyka połączenie
     }
 }
        public void PullIngredientsFromDataBase(string commandString, AbstractFridge fridge)
        {
            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())
                            {
                                fridge.AddIngredient
                                (FactoryPicker.Instance.Pick(dataReader.GetString(0))
                                .Create(Convert.ToDouble(CommaFormat(dataReader.GetString(1))), dataReader.GetDateTime(2)));
                            }
                        }
                    }
                    catch (Exception)
                    { MessageBox.Show("There has been a problem with connecting to the Database", "DBPuller.PullIngredients"); }
                }
                DataBase.MYSQLConnection.Close();
            }
        }
            public MySqlDataBasePuller dataBasePull; //potrzebny do pobierania danych z bazy

            #region constructors
            public MainWindowFridgeFiller(AbstractFridge fridge, MainWindow mainWindow, OnlineDataBase odb, string commandString)
            {
                Fridge          = fridge;
                this.mainWindow = mainWindow;

                dataBasePull = new MySqlDataBasePuller(odb);                     //konstruktor inicjalizuje pullera wykorzystując podaną klasę typu OnlineDB
                dataBasePull.PullIngredientsFromDataBase(commandString, Fridge); //automatycznie przekazuje polecenie
            }
            public FridgeFiller(AbstractFridge fridge, MainWindow mainWindow)
            {
                Fridge          = fridge;
                this.mainWindow = mainWindow;

                dataBasePull = new DataBasePull(new FreeSqlDataBase(), @"SELECT * FROM FridgeContent", fridge);
                dataBasePull.PullDataFromDataBase();
            }
            public MainWindowFridgeFiller(AbstractFridge fridge, MainWindow mainWindow)
            {
                Fridge          = fridge;
                this.mainWindow = mainWindow;

                dataBasePull = new MySqlDataBasePuller(mainWindow.DataBase);                      //konstruktor inicjalizuje pullera inicjalizując
                                                                                                  //przy okazji nową bazę danych
                dataBasePull.PullIngredientsFromDataBase(@"SELECT * FROM FridgeContent", Fridge); //konstruktor zawiera
                //domyślne polecenie wypełnienia listy składników wszystkimi składnikami obecnymi w bazie
            }
        MySqlDataBasePuller DataPuller; //umożliwia usuwanie z bazy danych wybranych składników

        public FoodPuller(AbstractFridge fridge, MySqlDataBasePuller dataPuller)
        {
            Fridge     = fridge;
            DataPuller = dataPuller;
        }
        }                                                    //umożliwia dostęp do lodówki

        public StateChecker(AbstractFridge fridge)
        {
            Fridge = fridge;
        }
        // IngredientFactory ingredientFactory;

        public DataBasePull(OnlineDataBase dataBase, string commandString, AbstractFridge fridge)
        {
            DataBase      = dataBase;
            CommandString = commandString;
            this.fridge   = fridge;
        }