コード例 #1
0
        public CreatePage()
        {
            //SQL local database connection
            _notesDB = new NotesDB();
            _notesQuery = new NotesQuery();

            var noteEditor = new Editor
            {
                BackgroundColor = Color.White,
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand
            };

            var saveButton = new Button { Text = "SAVE", HorizontalOptions = LayoutOptions.FillAndExpand };
            var cancelButton = new Button { Text = "CANCEL", HorizontalOptions = LayoutOptions.FillAndExpand };

            
            saveButton.Clicked += (object sender, EventArgs e) =>
            {
                _DateTime = DateTime.Now;
                try
                {
                    InsertData(noteEditor.Text.ToString(), _DateTime.ToString());
                    DisplayAlert("Alert", "Saved Succesfully.", "OK");
                    Navigation.PushAsync(new HomePage());
                }
                catch (Exception ex)
                {
                    string error = ex.ToString();
                    DisplayAlert("Sorry...", "Something went wrong. Try after sometime.", "OK");
                    // Navigation.PushAsync(new HomePage());
                }
            };


            var btnStack = new StackLayout {
                Orientation = StackOrientation.Horizontal,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children = {
                    saveButton,cancelButton
				}
            };


            cancelButton.Clicked += (sender, e) =>
            {
                var NoteItem = (NotesDB)BindingContext;
                this.Navigation.PopAsync();
            };

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Children = {
                    noteEditor,btnStack
				}
            };

        }
コード例 #2
0
        public HomePage()
        {
            //SQL local database connection
            _notesDB = new NotesDB();
            _notesQuery = new NotesQuery();

            var createBtn = new Button { Text = "Create note" };
            lstView = new ListView { };
            lstView.ItemTemplate = new DataTemplate(typeof(NoteItemCell));
            
            lstView.ItemSelected += async (sender, e) =>
            {
                if (e.SelectedItem == null)
                {
                    return; // ensures we ignore this handler when the selection is just being cleared 
                }
                var detail_Item = (NotesDB)e.SelectedItem;
                var detailPage = new EditPage();
                detailPage.BindingContext = detail_Item;
                await Navigation.PushAsync(detailPage);
                ((ListView)sender).SelectedItem = null;   // clears the 'selected' background
            };

            createBtn.Clicked += (object sender, EventArgs e) =>
            {
                Navigation.PushAsync(new CreatePage());
            };

            var mainlayout = new StackLayout { };
            mainlayout.Children.Add(createBtn);
            mainlayout.Children.Add(lstView);


            Content = mainlayout;
        }
コード例 #3
0
        public EditPage()
        {
            //SQL local database connection
            _notesDB = new NotesDB();
            _notesQuery = new NotesQuery();

            var idEntry = new Entry { };
            idEntry.SetBinding(Entry.TextProperty, "Id");
            idEntry.IsVisible = false;

            var noteEntry = new Entry { };
            noteEntry.SetBinding(Entry.TextProperty, "Note");


            var updateButton = new Button { Text = "UPDATE" };
            var deleteButton = new Button { Text = "DELETE" };
            var cancelButton = new Button { Text = "CANCEL" };

            //Update the selected data
            updateButton.Clicked += (object sender, EventArgs e) =>
            {
                try
                {
                    _DateTime = DateTime.Now;
                    UpdateData(idEntry.Text.ToString(), noteEntry.Text.ToString(), _DateTime.ToString());
                    DisplayAlert("Alert", "Updated Succesfully.", "OK");
                    Navigation.PushAsync(new HomePage());
                }
                catch (Exception ex)
                {
                    string error = ex.ToString();
                    DisplayAlert("Sorry...", "Something went wrong. Try after sometime.", "OK");
                }
            };

            //Delete selected data
            deleteButton.Clicked += (object sender, EventArgs e) =>
            {
                try
                {
                    int Id = Convert.ToInt32(idEntry.Text.ToString());
                    _notesQuery.DeleteNote(Id);
                    DisplayAlert("Alert", "Deleted Succesfully.", "OK");
                    Navigation.PushAsync(new HomePage());
                }
                catch (Exception ex)
                {
                    string error = ex.ToString();
                    DisplayAlert("Sorry...", "Something went wrong. Try after sometime.", "OK");
                }
            };


            cancelButton.Clicked += (sender, e) =>
            {
                var NoteItem = (NotesDB)BindingContext;
                this.Navigation.PopAsync();
            };
            
            var btnStack = new StackLayout
            {
                HorizontalOptions = LayoutOptions.FillAndExpand,
                Orientation = StackOrientation.Horizontal,
                Children ={
                    updateButton,deleteButton,cancelButton
                }
            };

            Content = new StackLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand,
                HorizontalOptions=LayoutOptions.FillAndExpand,
                Padding = new Thickness(20),
                Children = {
                    idEntry,noteEntry,btnStack

				}
            };

        }