public async Task SaveTodoItemAsync(TodoItem todoItem)
		{
			if (todoItem.ID == null)
				await todoTable.InsertAsync(todoItem);
			else
				await todoTable.UpdateAsync(todoItem);
		}
		public async Task SaveTodoItemAsync(TodoItem todoItem)
		{
			if (String.IsNullOrEmpty(todoItem.ID))
				await todoTable.InsertAsync(todoItem);
			else
				await todoTable.UpdateAsync(todoItem);
		}
		public int SaveTask (TodoItem item)
		{
			if (item.ID <= 0) {
				item.ID = ++max;
				items.Add (item);
			}
			return 1;
		}
		/// <summary>Convert from DataReader to Task object</summary>
		TodoItem FromReader (SqliteDataReader r) {
            var t = new TodoItem();
			t.ID = Convert.ToInt32 (r ["_id"]);
			t.Name = r ["Name"].ToString ();
			t.Notes = r ["Notes"].ToString ();
			t.Done = Convert.ToInt32 (r ["Done"]) == 1 ? true : false;
			return t;
		}
        public void Update(TodoItem item)
        {
            internalItem = item;

            ID = item.ID;
            Name = item.Name;
            Notes = item.Notes;
            Done = item.Done;
        }
		public void CreateTask () {
			// first, add the task to the underlying data
			var newTodo = new TodoItem();

			// then open the detail view to edit it
			var detail = Storyboard.InstantiateViewController("detail") as TaskDetailViewController;
			detail.SetTask (newTodo);
			NavigationController.PushViewController (detail, true);

			// Could to this instead of the above, but need to create 'new Task()' in PrepareForSegue()
			//this.PerformSegue ("TaskSegue", this);
		}
		/// <summary>
		/// Insert or update a task
		/// </summary>
		public int SaveTask (TodoItem item)
		{ 
			var max = 0;
			if (tasks.Count > 0) 
				max = tasks.Max(x => x.ID);

			if (item.ID == 0 || tasks.Count == 0) {
				item.ID = ++max;
				tasks.Add (item);
			} else {
				//HACK: why isn't Find available in PCL ?
				//var i = tasks.Find (x => x.ID == item.ID); 
				var j = tasks.Where (x => x.ID == item.ID).First();
				j = item; // replaces item in collection with updated value
			}

			storage.WriteXml (tasks, storeLocation);
			return max;
		}
        public TodoItem GetItem(int id) 
		{
            var t = new TodoItem();
			lock (locker) {
				connection = new SqliteConnection ("Data Source=" + path);
				connection.Open ();
				using (var command = connection.CreateCommand ()) {
					command.CommandText = "SELECT [_id], [Name], [Notes], [Done] from [Items] WHERE [_id] = ?";
					command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = id });
					var r = command.ExecuteReader ();
					while (r.Read ()) {
						t = FromReader (r);
						break;
					}
				}
				connection.Close ();
			}
			return t;
		}
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);
			
			View titleView = Window.FindViewById(Android.Resource.Id.Title);
			if (titleView != null) {
			  IViewParent parent = titleView.Parent;
			  if (parent != null && (parent is View)) {
			    View parentView = (View)parent;
			    parentView.SetBackgroundColor(Color.Rgb(0x26, 0x75 ,0xFF)); //38, 117 ,255
			  }
			}

			int taskID = Intent.GetIntExtra("TaskID", 0);
			if(taskID > 0) {
				task = AppDelegate.Current.TaskMgr.GetTask(taskID);
			}
			
			// set our layout to be the home screen
			SetContentView(Resource.Layout.TaskDetails);
			nameTextEdit = FindViewById<EditText>(Resource.Id.txtName);
			notesTextEdit = FindViewById<EditText>(Resource.Id.txtNotes);
			saveButton = FindViewById<Button>(Resource.Id.btnSave);
			doneCheckbox = FindViewById<CheckBox>(Resource.Id.chkDone);
			
			// find all our controls
			cancelDeleteButton = FindViewById<Button>(Resource.Id.btnCancelDelete);
			
			
			// set the cancel delete based on whether or not it's an existing task
			cancelDeleteButton.Text = (task.ID == 0 ? "Cancel" : "Delete");
			
			nameTextEdit.Text = task.Name;
			notesTextEdit.Text = task.Notes;
			doneCheckbox.Checked = task.Done;

			// button clicks 
			cancelDeleteButton.Click += (sender, e) => { CancelDelete(); };
			saveButton.Click += (sender, e) => { Save(); };
		}
		// this will be called before the view is displayed 
		public void SetTask (TodoItem todo) {
			currentTodoItem = todo;
		}
Пример #11
0
 public int SaveTask(TodoItem item)
 {
     return(repository.SaveTask(item));
 }
        public int SaveItem(TodoItem 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 [Name] = ?, [Notes] = ?, [Done] = ? WHERE [_id] = ?;";
						command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Name });
						command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Notes });
						command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.Done });
						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] ([Name], [Notes], [Done]) VALUES (? ,?, ?)";
						command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Name });
						command.Parameters.Add (new SqliteParameter (DbType.String) { Value = item.Notes });
						command.Parameters.Add (new SqliteParameter (DbType.Int32) { Value = item.Done });
						r = command.ExecuteNonQuery ();
					}
					connection.Close ();
					return r;
				}

			}
		}
Пример #13
0
 public int DeleteTask(TodoItem item)
 {
     return(repository.DeleteTask(item.ID));
 }
		public int SaveTask (TodoItem item)
		{
			return db.SaveItem<TodoItem>(item);
		}
 public TodoItemViewModel (TodoItem item)
 {
     internalItem = item;
     Update (item);
 }
 public TodoItemViewModel ()
 {
     internalItem = new TodoItem();
 }
Пример #17
0
 public int DeleteTask(TodoItem item)
 {
     return(database.DeleteItem(item.ID));
 }
		public int DeleteTask(TodoItem item)
		{
            return database.DeleteItem(item.ID);
		}
		public RootTableSource (TodoItem[] items)
		{
			tableItems = items; 
		}
		public Task SaveTaskAsync (TodoItem item)
		{
			return storage.SaveTodoItemAsync(item);
		}
		public int DeleteTask(TodoItem item)
		{
			return items.Remove (item)?1:0;
		}
		public int SaveTask (TodoItem item)
		{
			return repository.SaveTask(item);
		}
		public int DeleteTask(TodoItem item)
		{
			return repository.DeleteTask(item.ID);
		}
		public Task DeleteTaskAsync (TodoItem item)
		{
			return storage.DeleteTodoItemAsync(item);
		}
		public int SaveTask (TodoItem item)
		{
            return database.SaveItem(item);
		}
		public async Task DeleteTodoItemAsync(TodoItem item)
		{
			try 
			{
				await todoTable.DeleteAsync(item);
			} 
			catch (MobileServiceInvalidOperationException msioe)
			{
				Console.Error.WriteLine(@"INVALID {0}", msioe.Message);
			}
			catch (Exception e) 
			{
				Console.Error.WriteLine(@"ERROR {0}", e.Message);
			}
		}
Пример #27
0
 public int SaveTask(TodoItem item)
 {
     return(database.SaveItem(item));
 }