示例#1
0
        public List <LearningUnit> loadLearningUnitsFromDB(int userId)
        {
            MySqlConnection connection = getConnection("root", "");

            string commandstring = "SELECT stat_ID, user_ID, stat_average, stat_time, stat_cardboxname " +
                                   "FROM `statistic` WHERE user_ID = " + userId + ";";

            if (connection.State.ToString() == "Open")
            {
                MySqlCommand command = new MySqlCommand(commandstring, connection);
                try
                {
                    MySqlDataReader reader = command.ExecuteReader();


                    if (reader.HasRows)
                    {
                        List <LearningUnit> learnings = new List <LearningUnit>();
                        while (reader.Read())
                        {
                            LearningUnit learning = new LearningUnit(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetString(3), reader.GetString(4));
                            learnings.Add(learning);
                        }

                        connection.Close();
                        return(learnings);
                    }

                    else
                    {
                        connection.Close();
                    }
                    return(null);
                }

                catch (Exception ex)
                {
                    throw ex;
                }
            }
            connection.Close();
            return(null);
        }
示例#2
0
        public void updateLearningUnit(LearningUnit learningUnit, int newAverage, String newTime)
        {
            MySqlConnection connection = getConnection("root", "");
            //Erstellen einer LearningUnit mit veränderten Werten, aber gleicher ID
            LearningUnit clone         = new LearningUnit(learningUnit.LearningUnitId, learningUnit.UserId, newAverage, newTime, learningUnit.CarddBoxName);
            string       commandstring = "UPDATE `statistic` SET `stat_average` = '" + clone.AverageSuccessCB + "',`stat_time`= '" + clone.Time + "' " +
                                         "WHERE `statistic`.`stat_ID` = " + clone.LearningUnitId + ";";

            MySqlCommand command = new MySqlCommand(commandstring, connection);

            try
            {
                command.ExecuteNonQuery();
            }

            catch (Exception)
            {
                throw;
            }
            connection.Close();
        }
示例#3
0
        //==============================================Learning Unit========================================================
        public void saveLearningUnitInDB(LearningUnit learningUnit, int userId)
        {
            MySqlConnection connection = getConnection("root", "");

            string commandstring = "INSERT INTO `statistic` (`stat_ID`, `user_ID`, `stat_average`, `stat_time`, `stat_cardboxname`) " +
                                   "VALUES(NULL, '" + userId + "', '" + learningUnit.AverageSuccessCB + "','" + learningUnit.Time + "', '" + learningUnit.CarddBoxName + "' );";

            if (connection.State.ToString() == "Open")
            {
                MySqlCommand command = new MySqlCommand(commandstring, connection);
                try
                {
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            connection.Close();
        }