using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using comal.timesheets.QAForms; using Comal.Classes; using InABox.Clients; using InABox.Core; using Xamarin.Forms; using Xamarin.Forms.Xaml; using XF.Material.Forms.UI; using XF.Material.Forms.UI.Dialogs; namespace comal.timesheets { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class AssignmentForms : ContentView, IAssignmentPage { public AssignmentDetailModel DataModel => BindingContext as AssignmentDetailModel; public AssignmentForms() { InitializeComponent(); } public void Load() { NoForms.IsVisible = !DataModel.Forms.Any(); Forms.IsVisible = DataModel.Forms.Any(); Forms.ItemsSource = DataModel.Forms.ToArray(); } private async void MaterialCard_OnClicked(object sender, EventArgs e) { using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading")) { var instance = (sender as MaterialCard).BindingContext as AssignmentFormShell; var form = new Client() .Query(new Filter(x => x.ID).IsEqualTo(instance.ID)) .Rows .Select(x => x.ToObject()) .FirstOrDefault(); var model = new DigitalFormHostModel(); model.LoadItems(DataModel.Item.Entity, form, null); var host = new DigitalFormHost(model); host.OnClosing += (o, args) => { if (args.Changed) { //instance.Completed = !model.DigitalFormDataModel.Instance.FormCompleted.IsEmpty(); } }; Navigation.PushAsync(host); } } private void AddForm_OnClicked(object sender, EventArgs e) { GenericSelectionPage page = new GenericSelectionPage ( "Select Type", new SelectionViewModel ( new Filter(x => x.Form.AppliesTo).IsEqualTo(typeof(Assignment).EntityName().Split('.').Last()) .And(x=>x.Employee.ID).IsEqualTo(DataModel.Item.EmployeeID) .And(x=>x.Form.Active).IsEqualTo(true) .And(x=>x.Form.Secure).IsEqualTo(false), new Expression>[] { x => x.Form.Code, x => x.Form.Description }, new Expression>[] { x => x.Form.ID }, new SortOrder(x => x.Form.Code) )); page.OnItemSelected += (row) => { var form = new AssignmentForm(); form.Parent.ID = DataModel.Item.ID; form.Form.ID = row.Get(x => x.Form.ID); form.Form.Code = row.Get(x => x.Form.Code); form.Form.Description = row.Get(x => x.Form.Description); new Client().Save(form,"Created on Mobile Device", (o, e) => { Dispatcher.BeginInvokeOnMainThread( () => { // DataModel.Forms.Add( // new AssignmentFormShell() // { // ID = o.ID, // Description = o.Form.Description, // Completed = false // } // ); Forms.ItemsSource = DataModel.Forms.ToArray(); } ); } ); }; Navigation.PushAsync(page); } } }