コード例 #1
0
        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();
            }
        }
コード例 #2
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
     }
 }
コード例 #3
0
        public void PullDataFromDataBase()
        {
            DataBase.Connection = new MySqlConnection(DataBase.ConnectionString);
            DataBase.Command    = new MySqlCommand(CommandString, DataBase.Connection);

            using (DataBase.Connection)
            {
                using (DataBase.Command)
                {
                    try{ DataBase.Connection.Open(); }
                    catch (InvalidOperationException ex) { MessageBox.Show(ex.Message); }
                    catch (Exception ex) { MessageBox.Show(ex.Message); }

                    dataReader = DataBase.Command.ExecuteReader();
                    while (dataReader.Read())
                    {
                        try
                        {
                            {
                                fridge.AddIngredient(FactoryPicker.Instance.Pick(dataReader.GetString(0)).Create(dataReader.GetDouble(1), dataReader.GetDateTime(2)));
                            }
                        }
                        catch (Exception ex) { MessageBox.Show(ex.Message); }
                    }
                }

                DataBase.Connection.Close();
            }
        }