コード例 #1
0
ファイル: FitAppDatabase.cs プロジェクト: max2dn/fitApp
        public int WriteWorkout(WorkoutItem w)
        {
            /*return the ID of the workout after it's been added*/
            /*Write the WorkoutItem (which is in our ViewModel) to the WorkoutItemDB and SetDB models*/
            WorkoutItemDB wi = new WorkoutItemDB
            {
                Name = w.Name,
                Date = w.Date.ToString("yyyy-MM-dd"),
                Unit = w.Unit
            };
            int t = _connection.Insert(wi);

            System.Diagnostics.Debug.WriteLine("LINES WRITTEN: " + t);

            string sql = @"select last_insert_rowid()";
            int    key = _connection.ExecuteScalar <int>(sql);

            foreach (double d in w.Set)
            {
                SetDB s = new SetDB
                {
                    WorkoutItemID = key,
                    Amount        = d
                };
                t = _connection.Insert(s);
                System.Diagnostics.Debug.WriteLine("LINES WRITTEN: " + t);
            }
            return(key);
        }
コード例 #2
0
ファイル: FitAppDatabase.cs プロジェクト: max2dn/fitApp
        // Get the workouts based on the name of the exercise
        public ObservableCollection <WorkoutItem> GetWorkouts(string name)
        {
            ObservableCollection <WorkoutItem> coll = new ObservableCollection <WorkoutItem>();
            List <WorkoutItemDB> l = _connection.Query <WorkoutItemDB>("SELECT * FROM [WorkoutItemDB] WHERE [Name] = ? ORDER BY [Date]", name);

            System.Diagnostics.Debug.WriteLine("FETCHED: " + l.Count);

            // convert the DB items into WorkoutItems for the view
            foreach (WorkoutItemDB i in l)
            {
                System.Diagnostics.Debug.WriteLine("KEY: " + i.ID);

                WorkoutItem w = new WorkoutItem
                {
                    Name = i.Name,
                    Date = Convert.ToDateTime(i.Date),
                    Unit = i.Unit,
                    ID   = i.ID
                };

                // get the set
                List <SetDB> s = _connection.Query <SetDB>("SELECT [Amount] FROM [SetDB] WHERE [WorkoutItemID] = ?", i.ID);
                var          d = new ObservableCollection <double>();
                System.Diagnostics.Debug.WriteLine("SET ITEMS: " + s.Count);
                foreach (SetDB k in s)
                {
                    d.Add(k.Amount);
                }
                w.Set = d;
                coll.Add(w);
            }

            return(coll);
        }
コード例 #3
0
ファイル: FitAppDatabase.cs プロジェクト: max2dn/fitApp
        public void RemoveWorkout(WorkoutItem w)
        {
            // delete the workout
            WorkoutItemDB wi = new WorkoutItemDB
            {
                ID = w.ID
            };

            _connection.Delete(wi);

            // delete the sets that belong to that ID
            _connection.Execute("DELETE FROM [SetDB] WHERE [WorkoutItemID] = ?", w.ID);
        }
コード例 #4
0
ファイル: FitAppDatabase.cs プロジェクト: max2dn/fitApp
        public ObservableCollection <WorkoutItem> GetWorkouts(DateTime date)
        {
            // pull the workout items out of the database and convert them to the WorkoutItem class
            // the WorkoutItem class is more convienent for the view, but WorkoutItemDB is more convient for SQL
            // NOTE:
            //	we should eventually make those two objects the same.  It's redundant having both
            ObservableCollection <WorkoutItem> coll = new ObservableCollection <WorkoutItem>();
            string date_string     = date.ToString("yyyy-MM-dd");
            List <WorkoutItemDB> l = _connection.Query <WorkoutItemDB>("SELECT * FROM [WorkoutItemDB] WHERE [Date] = ?", date_string);

            System.Diagnostics.Debug.WriteLine("FETCHED: " + l.Count);

            // convert the DB items into WorkoutItems for the view
            foreach (WorkoutItemDB i in l)
            {
                System.Diagnostics.Debug.WriteLine("KEY: " + i.ID);

                WorkoutItem w = new WorkoutItem
                {
                    Name = i.Name,
                    Date = Convert.ToDateTime(i.Date),
                    Unit = i.Unit,
                    ID   = i.ID
                };

                // get the set
                List <SetDB> s = _connection.Query <SetDB>("SELECT [Amount] FROM [SetDB] WHERE [WorkoutItemID] = ?", i.ID);
                var          d = new ObservableCollection <double>();
                System.Diagnostics.Debug.WriteLine("SET ITEMS: " + s.Count);
                foreach (SetDB k in s)
                {
                    d.Add(k.Amount);
                }
                w.Set = d;
                coll.Add(w);
            }

            return(coll);
        }