Beispiel #1
0
        internal void Insert(Task task)
        {
            string tags;

            if (task.Tags.Count == 0)
            {
                tags = "";
            }
            else
            {
                tags = task.Tags[0].ID;
                for (var i = 1; i < task.Tags.Count; i++)
                {
                    tags += "," + task.Tags[i].ID;
                }
            }
            string cmd = String.Format(@"INSERT INTO tasks(Title, ID, Repeater, ActivatedTime, ExpiryTime, Time, Tags, WebAddress) VALUES 
                                        ('{0}', '{1}', '{2}', Date('{3}'), Date('{4}'), '{5}', '{6}', '{7}');",
                                       task.Title, task.ID, RepeaterStorageConverter.ToString(task.Repeater), task.ActivatedTime.ToString("yyyy-MM-dd HH:mm"),
                                       task.ExpiryTime.ToString("yyyy-MM-dd HH:mm"), TimeInfosStorageConverter.ToString(task.Time), tags, task.WebAddress);

            ExecuteQuery(cmd).ContinueWith(t => { if (t.IsFaulted)
                                                  {
                                                      throw t.Exception;
                                                  }
                                           });
        }
Beispiel #2
0
        GetTaskList(Predicate <Task> predicate, bool isGarbage, ObservableCollection <Tag> tagList)
        {
            ObservableCollection <Task> tasks = new ObservableCollection <Task>();
            await _sQLite.OpenAsync();

            SQLiteCommand sQLiteCommand = _sQLite.CreateCommand();

            if (isGarbage)
            {
                sQLiteCommand.CommandText = "SELECT * FROM TasksGarbage;";
            }
            else
            {
                sQLiteCommand.CommandText = "SELECT * FROM Tasks;";
            }
            DbDataReader reader = await sQLiteCommand.ExecuteReaderAsync();

            if (predicate == null)
            {
                predicate = AlwaysTrue;
            }
            while (await reader.ReadAsync())
            {
                string   title         = reader[0].ToString();
                string   ID            = reader[1].ToString();
                Repeater repeater      = RepeaterStorageConverter.Parse(reader[2].ToString());
                DateTime activatedTime = reader.GetDateTime(3);
                DateTime expiryTime    = reader.GetDateTime(4);
                ObservableCollection <TimeInfo> time = TimeInfosStorageConverter.Parse(reader[5].ToString());
                Tag[]  tags       = Array.ConvertAll <string, Tag>(reader[6].ToString().Split(','), x => tagList.First(y => y.ID == x));
                string webAddress = reader[7].ToString();
                Task   task       = new Task(title, ID, repeater, activatedTime, expiryTime, time, new ObservableCollection <Tag>(tags), webAddress);
                if (predicate(task))
                {
                    tasks.Add(task);
                }
            }
            _sQLite.Close();
            return(tasks);
        }