Esempio n. 1
0
        private static Todo CreateTodo(string[] fields)
        {
            if (fields.Length != 4) throw new ImportDataException();
            var q =
                from x in fields
                where x == null
                select x;

            if (q.Any()) throw new ImportDataException();
            //TODO 全体的に、変数定義をvarで行うべき
            Todo todo = new Todo();

            todo.Title = fields[0].TrimEnd();
            if (todo.Title.Length == 0 || todo.Title.Length > 32)
                throw new ImportDataException();

            todo.Contents = fields[1].TrimEnd();
            if(todo.Contents.Length > 32)
                throw new ImportDataException();

            DateTime d;
            if(!DateTime.TryParse(fields[2], out d ))
                throw new ImportDataException();
            todo.Limit = d;

            bool b;
            if (!bool.TryParse(fields[3], out b))
                throw new ImportDataException();
            todo.IsFinished = b;

            return todo;
        }
Esempio n. 2
0
        public async Task<ObservableCollection<Todo>> GetTodos()
        {
            using (var conn = new SQLiteConnection("Data Source=TodoList.s3db"))
            {
                using (var cmd = new SQLiteCommand("SELECT * FROM TODOs", conn))
                {
                    await conn.OpenAsync();
                    using (var reader = await cmd.ExecuteReaderAsync())
                    {
                        if (!reader.HasRows)
                        {
                            return new ObservableCollection<Todo>();
                        }

                        var todos = new ObservableCollection<Todo>();
                        Todo todo = null;
                        while (reader.Read())
                        {
                            todo = new Todo();
                            todo.Id = Convert.ToInt32(reader["Id"].ToString());
                            todo.CreateDate = Convert.ToDateTime(reader["CreateDate"].ToString());
                            todo.Task = reader["Task"].ToString();
                            todo.Done = Convert.ToBoolean(reader["Done"].ToString());
                            todo.DueDate = reader["DueDate"] == DBNull.Value ?
                                null as DateTime? : Convert.ToDateTime(reader["DueDate"].ToString());
                            todos.Add(todo);
                        }
                        return todos;
                    }
                }
            }
        }
Esempio n. 3
0
 private void btnAdd_Click(object sender, RoutedEventArgs e)
 {
     Todo newTodo = new Todo();
     var add = new AddTodo(newTodo);
     if (add.ShowDialog().Value)
     {
         _todos.Add(newTodo);
         lstTodos.InvalidateVisual();
     }
 }
Esempio n. 4
0
 public async void SetComplete(Todo todo)
 {
     using (var conn = new SQLiteConnection("Data Source=TodoList.s3db"))
     {
         using (var cmd = new SQLiteCommand("UPDATE TODOs SET Done = 1 WHERE Id = " + todo.Id, conn))
         {
             await conn.OpenAsync();
             await cmd.ExecuteNonQueryAsync();
         }
     }
 }
Esempio n. 5
0
        public async void AddTodo(Todo todo)
        {
            using (var conn = new SQLiteConnection("Data Source=TodoList.s3db"))
            {
                var sb = new StringBuilder();
                sb.Append("INSERT INTO TODOs (Task, DueDate, CreateDate, Done) VALUES ('");
                sb.Append(todo.Task);
                sb.Append("', '");
                sb.Append(todo.DueDate.Value.ToString("yyyy-MM-dd HH:mm"));
                sb.Append("', '");
                sb.Append(todo.CreateDate.ToString("yyyy-MM-dd HH:mm"));
                sb.Append("', ");
                sb.Append(todo.Done ? 1 : 0);
                sb.Append(");");

                Debug.WriteLine("Executing: " + sb.ToString());

                using (var cmd = new SQLiteCommand(sb.ToString(), conn))
                {
                    await conn.OpenAsync();
                    await cmd.ExecuteNonQueryAsync();
                }
            }
        }
Esempio n. 6
0
 private void GetDataPropertyValues(Todo todo)
 {
     todo.Id = Id;
     todo.Title = Title;
     todo.Contents = Contents;
     todo.Limit = Limit;
     todo.IsFinished = IsFinished;
 }
Esempio n. 7
0
 private void InsertRecord()
 {
     Todo todo = new Todo();
     GetDataPropertyValues(todo);
     _dataContext.Todo.InsertOnSubmit(todo);
     _dataContext.SubmitChanges();
     Items.Add(todo);
     Item = todo;
 }
Esempio n. 8
0
        //メソッド
        private void FillItems(String keyword = null)
        {
            string k = (keyword ?? string.Empty).Trim();
            var q =
                from p in _dataContext.Todo
                where p.Title.Contains(k)
                orderby p.Id descending
                select p;

            Items.Clear();
            Todo newTodo = new Todo { Title = "(新規)" };
            Items.Add(newTodo);
            foreach (var x in q)
            {
                Items.Add(x);
            }
            Item = Items[0];
        }
 partial void DeleteTodo(Todo instance);
 partial void UpdateTodo(Todo instance);
 partial void InsertTodo(Todo instance);
Esempio n. 12
0
 public AddTodo(Todo newTodo)
 {
     InitializeComponent();
     _todo = newTodo;
 }