Пример #1
0
        public void AddExercise(LogRow Exercise)
        {
            try
            {
                NpgsqlConnection connection = new NpgsqlConnection(DbConnection);
                connection.Open();

                string query = "INSERT INTO fitnesslogger.exercise_log VALUES(@Id, @Date, @Exercise, @Weight, @Repetitions, @Sets, @Rest_time, @Notes)";

                int NextId = GetNextId();

                NpgsqlCommand command = new NpgsqlCommand(query, connection);

                command.Parameters.Add(new NpgsqlParameter("Id", NextId));
                command.Parameters.Add(new NpgsqlParameter("Date", Exercise.Date));
                command.Parameters.Add(new NpgsqlParameter("Exercise", Exercise.Exercise));
                command.Parameters.Add(new NpgsqlParameter("Weight", Exercise.Weight));
                command.Parameters.Add(new NpgsqlParameter("Repetitions", Exercise.Repetitions));
                command.Parameters.Add(new NpgsqlParameter("Sets", Exercise.Sets));
                command.Parameters.Add(new NpgsqlParameter("Rest_time", Exercise.Rest_time));
                command.Parameters.Add(new NpgsqlParameter("Notes", Exercise.Notes));

                command.ExecuteNonQuery();

                connection.Close();
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
        private List <LogRow> ExerciseList()
        {
            List <LogRow> exercises = new List <LogRow>();

            try
            {
                NpgsqlConnection connection = new NpgsqlConnection(DbConnection);
                connection.Open();

                NpgsqlCommand command = new NpgsqlCommand("SELECT * FROM fitnesslogger.exercise_log", connection);

                NpgsqlDataReader dataReader = command.ExecuteReader();

                while (dataReader.Read())
                {
                    LogRow logrow = new LogRow();

                    logrow.Id          = Convert.ToInt32(dataReader["id"]);
                    logrow.Date        = Convert.ToDateTime(dataReader["date"]);
                    logrow.Exercise    = dataReader["exercise"].ToString();
                    logrow.Weight      = Convert.ToInt32(dataReader["weight"]);
                    logrow.Repetitions = Convert.ToInt32(dataReader["repetitions"]);
                    logrow.Sets        = Convert.ToInt32(dataReader["sets"]);
                    logrow.Rest_time   = Convert.ToInt32(dataReader["rest_time"]);
                    logrow.Notes       = dataReader["notes"].ToString();

                    exercises.Add(logrow);
                }

                connection.Close();

                return(exercises);
            }
            catch (Exception msg)
            {
                throw;
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            database db = new database();

            LogRow logrow = new LogRow()
            {
                Date        = DateTime.Now,
                Exercise    = "Benchpress",
                Weight      = 210,
                Repetitions = 10,
                Sets        = 5,
                Rest_time   = 90,
                Notes       = "BEASTMODE"
            };

            //db.AddExercise(logrow);

            foreach (LogRow _logrow in db.Exercises)
            {
                Console.WriteLine(_logrow.Id + ", " + _logrow.Date.ToString("dd-MM-yy") + ", " + _logrow.Exercise + ", " + _logrow.Weight + ", " + _logrow.Repetitions + ", " + _logrow.Sets + ", " + _logrow.Rest_time + ", " + _logrow.Notes);
            }

            Console.ReadLine();
        }