public StepEntry GetItem(DateTime date)
        {
            var t = new StepEntry();

            lock (locker) {
                using (connection = new SqliteConnection("Data Source=" + path)) {
                    connection.Open();
                    using (var command = connection.CreateCommand()) {
                        command.CommandText = "SELECT [_id], [Steps], [Date] from [Items] WHERE [Date] = ?";
                        var culture = CultureInfo.CreateSpecificCulture("en-US");
                        command.Parameters.Add(new SqliteParameter(DbType.String)
                        {
                            Value = date.ToString("MM/dd/yyyy", culture)
                        });
                        var r = command.ExecuteReader();
                        while (r.Read())
                        {
                            t = FromReader(r);
                            break;
                        }
                        r.Close();
                    }
                    connection.Close();
                }
            }
            return(t);
        }
        public int SaveItem(StepEntry item)
        {
            int r;

            lock (locker) {
                if (item.ID != 0)
                {
                    using (connection = new SqliteConnection("Data Source=" + path)) {
                        connection.Open();
                        using (var command = connection.CreateCommand()) {
                            command.CommandText = "UPDATE [Items] SET [Steps] = ?, [Date] = ? WHERE [_id] = ?;";
                            command.Parameters.Add(new SqliteParameter(DbType.Int64)
                            {
                                Value = item.Steps
                            });
                            var culture = CultureInfo.CreateSpecificCulture("en-US");
                            command.Parameters.Add(new SqliteParameter(DbType.String)
                            {
                                Value = item.Date.ToString("MM/dd/yyyy", culture)
                            });
                            command.Parameters.Add(new SqliteParameter(DbType.Int32)
                            {
                                Value = item.ID
                            });
                            r = command.ExecuteNonQuery();
                        }
                        connection.Close();
                    }
                    return(r);
                }
                else
                {
                    using (connection = new SqliteConnection("Data Source=" + path)) {
                        connection.Open();
                        using (var command = connection.CreateCommand()) {
                            command.CommandText = "INSERT INTO [Items] ([Steps], [Date]) VALUES (? ,?)";
                            command.Parameters.Add(new SqliteParameter(DbType.Int64)
                            {
                                Value = item.Steps
                            });
                            var culture = CultureInfo.CreateSpecificCulture("en-US");
                            command.Parameters.Add(new SqliteParameter(DbType.String)
                            {
                                Value = item.Date.ToString("MM/dd/yyyy", culture)
                            });
                            r = command.ExecuteNonQuery();
                        }
                        connection.Close();
                    }
                    return(r);
                }
            }
        }
		/// <summary>Convert from DataReader to Task object</summary>
		StepEntry FromReader (SqliteDataReader r) {
			var t = new StepEntry ();
			t.ID = Convert.ToInt32 (r ["_id"]);
			t.Steps = Convert.ToInt64(r ["Steps"]);
			var date = r ["Date"].ToString ();
			var culture = CultureInfo.CreateSpecificCulture("en-US");
			var styles = DateTimeStyles.None;
			DateTime dateOut;
			if (!DateTime.TryParse (date, culture, styles, out dateOut)) {
				//back compat, but will never come in here really.
				DateTime.TryParse (date, out dateOut);
			}
			t.Date = dateOut;
			return t;
		}
        /// <summary>Convert from DataReader to Task object</summary>
        StepEntry FromReader(SqliteDataReader r)
        {
            var t = new StepEntry();

            t.ID    = Convert.ToInt32(r ["_id"]);
            t.Steps = Convert.ToInt64(r ["Steps"]);
            var      date    = r ["Date"].ToString();
            var      culture = CultureInfo.CreateSpecificCulture("en-US");
            var      styles  = DateTimeStyles.None;
            DateTime dateOut;

            if (!DateTime.TryParse(date, culture, styles, out dateOut))
            {
                //back compat, but will never come in here really.
                DateTime.TryParse(date, out dateOut);
            }
            t.Date = dateOut;
            return(t);
        }
		public static int SaveStepEntry(StepEntry item)
		{
			return StepEntryRepositoryADO.SaveStepEntry(item);
		}
示例#6
0
		private void CrunchDates(bool startup = false)
		{
			if (!Utils.IsSameDay) {
				//save our day from yesterday, we dont' do datetime.adddays(-1) because phone might have been off
				//for more then 1 day and it would not be correct!
				var yesterday = Helpers.Settings.CurrentDay;
				var dayEntry = StepEntryManager.GetStepEntry (yesterday);
				if (dayEntry == null || dayEntry.Date.DayOfYear != yesterday.DayOfYear) {
					dayEntry = new StepEntry ();
				}

				dayEntry.Date = yesterday;
				dayEntry.Steps = Helpers.Settings.CurrentDaySteps;

				Helpers.Settings.CurrentDay = DateTime.Today;
				Helpers.Settings.CurrentDaySteps = 0;
				Helpers.Settings.StepsBeforeToday = Helpers.Settings.TotalSteps;
				StepsToday = 0;
				try{
					StepEntryManager.SaveStepEntry (dayEntry);
				}catch(Exception ex){
					Console.WriteLine ("Something horrible has gone wrong attempting to save database entry, it is lost forever :(");
				}

			} else if (startup) {
				StepsToday = Helpers.Settings.TotalSteps - Helpers.Settings.StepsBeforeToday;
			}
		}
 public static int SaveStepEntry(StepEntry item)
 {
     return(me.db.SaveItem(item));
 }
 public StepEntry GetItem(DateTime date)
 {
     var t = new StepEntry ();
     lock (locker) {
         connection = new SqliteConnection ("Data Source=" + path);
         connection.Open ();
         using (var command = connection.CreateCommand ()) {
             command.CommandText = "SELECT [_id], [Steps], [Date] from [Items] WHERE [Date] = ?";
             var culture = CultureInfo.CreateSpecificCulture("en-US");
             command.Parameters.Add (new SqliteParameter (DbType.String) { Value = date.ToString("MM/dd/yyyy", culture) });
             var r = command.ExecuteReader ();
             while (r.Read ()) {
                 t = FromReader (r);
                 break;
             }
         }
         connection.Close ();
     }
     return t;
 }
        public int SaveItem(StepEntry item)
        {
            int r;
            lock (locker) {
                if (item.ID != 0) {
                    connection = new SqliteConnection ("Data Source=" + path);
                    connection.Open ();
                    using (var command = connection.CreateCommand ()) {
                        command.CommandText = "UPDATE [Items] SET [Steps] = ?, [Date] = ? WHERE [_id] = ?;";
                        command.Parameters.Add (new SqliteParameter (DbType.Int64) { Value = item.Steps });
                        var culture = CultureInfo.CreateSpecificCulture("en-US");
                        command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Date.ToString("MM/dd/yyyy", culture) });
                        command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.ID });
                        r = command.ExecuteNonQuery ();
                    }
                    connection.Close ();
                    return r;
                } else {
                    connection = new SqliteConnection ("Data Source=" + path);
                    connection.Open ();
                    using (var command = connection.CreateCommand ()) {
                        command.CommandText = "INSERT INTO [Items] ([Steps], [Date]) VALUES (? ,?)";
                        command.Parameters.Add (new SqliteParameter (DbType.Int64) { Value = item.Steps });
                        var culture = CultureInfo.CreateSpecificCulture("en-US");
                        command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Date.ToString("MM/dd/yyyy", culture) });
                        r = command.ExecuteNonQuery ();
                    }
                    connection.Close ();
                    return r;
                }

            }
        }
 public static int SaveStepEntry(StepEntry item)
 {
     return me.db.SaveItem(item);
 }
示例#11
0
 public static int SaveStepEntry(StepEntry item)
 {
     return(StepEntryRepositoryADO.SaveStepEntry(item));
 }