public override void ViewDidLoad() { base.ViewDidLoad(); #if STDVERSION NoteItems = DBMgrNotes.Instance.NoteItems; barbtnLeft.Clicked += (s, e) => { if (TableView.Editing) { TableView.SetEditing(false, true); // if we've half-swiped a row } // TableView.WillBeginEditing(TableView); TableView.SetEditing(true, true); this.NavigationItem.SetLeftBarButtonItem(done, true); }; done = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, args) => { TableView.SetEditing(false, true); this.NavigationItem.SetLeftBarButtonItem(barbtnLeft, true); }); barbtnRight.Clicked += (s, e) => { var storyB = UIStoryboard.FromName("Main", null); NotesDetailsViewController detailscontroller = storyB.InstantiateViewController("NotesDetails") as NotesDetailsViewController; detailscontroller.bEditMode = false; detailscontroller.refParent = this; this.NavigationController.PushViewController(detailscontroller, false); //UINavigationController nav = this.NavigationController; //detailscontroller = new NotesDetailsViewController(); //nav.PushViewController(detailscontroller,false); }; #else for (int i = 0; i < 2; i++) { MMNote sample = new MMNote(); sample.Id = Convert.ToString(i + 1); sample.Name = "Sample Note" + sample.Id; sample.Observations = "samples"; NoteItems.Add(sample); } MMNote sample2 = new MMNote(); sample2.Id = "3"; sample2.Name = "Use paid version for all features"; sample2.Observations = "samples"; NoteItems.Add(sample2); #endif //TableView.SetEditing(true, true); TableView.Source = new NotesDataSource(NoteItems); View.BackgroundColor = Utils.getThemeColor(); this.Title = "Notes"; }
/// <summary> /// Views the did load. /// </summary> public override void ViewDidLoad() { base.ViewDidLoad(); View.BackgroundColor = Utils.getThemeColor(); if (bEditMode) { MMNote noteEditing = DBMgrNotes.Instance.NoteItems[nCurrentNoteIndex]; txtNoteName.Text = noteEditing.Name; txtNoteObservations.Text = noteEditing.Observations; } UIBarButtonItem done = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, args) => { if (Utils.Empty(txtNoteName.Text))// no matter if edit or add mode { Utils.ShowAlertOK("Please provide a name for this note", this); } else if (Utils.Empty(txtNoteObservations.Text))// no matter if edit or add mode { Utils.ShowAlertOK("Please provide notes. This cannot be empty", this); } else if (!bEditMode)// add mode { // validate for existing name MMNote newNote = new MMNote(); newNote.Id = ""; newNote.Name = txtNoteName.Text; newNote.Observations = txtNoteObservations.Text; //Notes.Add(newNote); string dbExistingId = DBMgrNotes.Instance.IfFoundNoteName(newNote); if (!Utils.Empty(dbExistingId)) { Utils.ShowAlertOK("Duplicate found, Please provide another name", this); } else { DBMgrNotes.Instance.InsertNote(newNote); refParent.ReloadNotes(); this.NavigationController.PopToRootViewController(true); } } else // edit mode { //Update record; MMNote noteEditing = DBMgrNotes.Instance.NoteItems[nCurrentNoteIndex]; noteEditing.Name = txtNoteName.Text; noteEditing.Observations = txtNoteObservations.Text; string dbExistingId = DBMgrNotes.Instance.IfFoundNoteName(noteEditing); if (!Utils.Empty(dbExistingId) && !noteEditing.Id.Equals(dbExistingId)) { Utils.ShowAlertOK("Duplicate found, Please provide another name", this); } else { DBMgrNotes.Instance.UpdateNote(noteEditing); refParent.ReloadNotes(); this.NavigationController.PopToRootViewController(true); } } }); this.NavigationItem.SetRightBarButtonItem(done, true); }