public CompletedChore(Chore c, DateTime? completionDate = null, string completedBy = "") { ChoreName = c.ChoreName; CompletionDate = completionDate.GetValueOrDefault (DateTime.Now); CompletedBy = completedBy; ParentChoreId = c.ID; }
protected override void OnCreate(Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.EditChore); var choreId = Intent.GetIntExtra("ChoreId", 0); var dueDate = FindViewById<EditText>(Resource.Id.DueDateInput); dueDate.Click += (sender, e) => { ShowDialog ((int)DialogIds.DUE_DATE_DIALOG); }; dueDate.Touch += (sender, e) => { ShowDialog ((int)DialogIds.DUE_DATE_DIALOG); }; var endDate = FindViewById<EditText>(Resource.Id.EndDateInput); endDate.Click += (sender, e) => { ShowDialog ((int)DialogIds.END_DATE_DIALOG); }; endDate.Touch += (sender, e) => { ShowDialog ((int)DialogIds.END_DATE_DIALOG); }; endDate.Enabled = false; var recurrence = FindViewById<Spinner>(Resource.Id.RecurrencePicker); recurrence.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected); var array = Enum.GetValues(typeof(RecurrencePattern)).Cast<RecurrencePattern>(); var adapter = new ArrayAdapter<RecurrencePattern>(this, Android.Resource.Layout.SimpleSpinnerItem, array.ToList<RecurrencePattern>()); adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem); recurrence.Adapter = adapter; Button cancelButton = FindViewById<Button> (Resource.Id.CancelButton); cancelButton.Click += (sender, e) => { StartActivity(typeof(MainActivity)); }; Button deleteButton = FindViewById<Button> (Resource.Id.DeleteButton); deleteButton.Click += (sender, e) => { ChoreManager.DeleteChore(choreId); StartActivity(typeof(MainActivity)); }; Button editButton = FindViewById<Button> (Resource.Id.EditButton); editButton.Click += EditButtonClicked; _chore = ChoreManager.GetChore(choreId); _recurrence = RecurrenceManager.GetRecurrence(_chore.RecurrenceID); PopulatePage(); }
private static DateTime? CalculateNextDueDate(Chore c, Recurrence r) { DateTime? nextDate = null; DateTime today = DateTime.Now.Date; DateTime baseNextDate = (c.DueDate.Date < today) ? today : c.DueDate.Date; if (r != null) { switch (r.Pattern) { case RecurrencePattern.Daily: nextDate = c.DueDate; while (nextDate.Value.Date <= baseNextDate) { nextDate = nextDate.Value.AddDays(1); } break; case RecurrencePattern.Weekly: nextDate = c.DueDate; while (nextDate.Value.Date <= baseNextDate) { nextDate = nextDate.Value.AddDays(7); } break; case RecurrencePattern.BiWeekly: nextDate = c.DueDate; while (nextDate.Value.Date <= baseNextDate) { nextDate = nextDate.Value.AddDays(14); } break; case RecurrencePattern.Monthly: nextDate = c.DueDate; while (nextDate.Value.Date <= baseNextDate) { nextDate = nextDate.Value.AddMonths(1); } break; case RecurrencePattern.Yearly: nextDate = c.DueDate; while (nextDate.Value.Date <= baseNextDate) { nextDate = nextDate.Value.AddYears(1); } break; } } return nextDate; }
public static int SaveChore(Chore item) { return ChoreRepository.SaveChore(item); }
private void CreateButtonClicked(Object sender, EventArgs e) { FindViewById<Button> (Resource.Id.CreateButton).Enabled = false; var choreName = FindViewById<EditText>(Resource.Id.ChoreNameInput); var dueDate = FindViewById<EditText>(Resource.Id.DueDateInput); var endDate = FindViewById<EditText>(Resource.Id.EndDateInput); var recurrencePicker = FindViewById<Spinner>(Resource.Id.RecurrencePicker); var c = new Chore() { ChoreName = choreName.Text, DueDate = DateTime.Parse(dueDate.Text) }; ChoreManager.SaveChore(c); DateTime endRecurrence; var recurrence = new Recurrence() { ChoreID = c.ID, EndDate = DateTime.TryParse(endDate.Text, out endRecurrence) ? endRecurrence : (DateTime?)null, Pattern = (RecurrencePattern)recurrencePicker.SelectedItemId, StartDate = DateTime.Parse(dueDate.Text) }; RecurrenceManager.SaveRecurrence(recurrence); c.RecurrenceID = recurrence.ID; ChoreManager.SaveChore(c); StartActivity(typeof(MainActivity)); }
public static int SaveChore(Chore item) { return db.SaveItem<Chore>(item); }