| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- 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<TimeSheet>().Query
- (
- new Filter<TimeSheet>(x => x.ID).IsEqualTo(timeSheet.ID),
- new Columns<TimeSheet>(
- x => x.Notes
- ));
- if (table.Rows.Any())
- {
- CoreRow row = table.Rows.FirstOrDefault();
- List<object> 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<TimeSheet>().Save(timeSheet, "Updated Note from Mobile");
- DisplayAlert("Success", "Note Saved", "OK");
- }
- }
- catch { }
- }
- }
- }
|