using System; using System.Collections.Generic; using InABox.Core; using Xamarin.Forms; using InABox.Clients; using Comal.Classes; using System.Threading.Tasks; using System.Linq; namespace comal.timesheets { public partial class TimeSheetNotePage { TimeSheet timeSheet = new TimeSheet(); protected void SaveTimeSheetCallback(TimeSheet entity, Exception e) { if (e != null) Device.BeginInvokeOnMainThread(() => { DisplayAlert("Error Adding Note", "Unable to Save Note\n\n" + e.Message, "OK"); }); } public TimeSheetNotePage(TimeSheet _timeSheet) { InitializeComponent(); timeSheet = _timeSheet; NavigationPage.SetBackButtonTitle(this, "Cancel"); ToolbarItems.Clear(); ToolbarItems.Add(new ToolbarItem("Save", "", () => { SaveNewNotes(); Navigation.PopAsync(); })); LoadNewNotes(); } private void LoadNewNotes() { Task.Run(() => { try { CoreTable table = new Client().Query ( new Filter(x => x.ID).IsEqualTo(timeSheet.ID), new Columns( x => x.Notes )); if (table.Rows.Any()) { CoreRow row = table.Rows.FirstOrDefault(); List list = row.Values; if (list[0] == null) { list[0] = ""; } Device.BeginInvokeOnMainThread(() => { notesLbl.Text = list[0].ToString(); }); } } catch { } }); } private void SaveNewNotes() { try { string notesLableText = notesLbl.Text + "\n"; if (string.IsNullOrWhiteSpace(notesLbl.Text)) { notesLableText = ""; } if (!string.IsNullOrWhiteSpace(notesEdt.Text)) { timeSheet.Notes = notesLableText + notesEdt.Text + " (Added by " + App.Data.Me.Name + " at " + DateTime.Now + ")"; new Client().Save(timeSheet, "Updated Note from Mobile"); DisplayAlert("Success", "Note Saved", "OK"); } } catch { } } } }