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 { List logs = new List(); public AssignmentEditDataModel DataModel => BindingContext as AssignmentEditDataModel; 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) { logs.Add(new Log("Clicked", QAForms.MobileLogType.START)); using (await MaterialDialog.Instance.LoadingDialogAsync(message: "Loading")) { var instance = (sender as MaterialCard).BindingContext as AssignmentFormInstance; var form = new Client() .Query(new Filter(x => x.ID).IsEqualTo(instance.ID)) .Rows .Select(x => x.ToObject()) .FirstOrDefault(); var model = new DigitalFormHostModel(); logs.Add(new Log("Load Items", QAForms.MobileLogType.START)); model.LoadItems(DataModel.Item.Entity, form, null); logs.Add(new Log("Load Items", QAForms.MobileLogType.END)); var host = new DigitalFormHost(model); host.OnClosing += (o, args) => { if (args.Changed) { instance.Completed = !model.DigitalFormDataModel.Instance.FormCompleted.IsEmpty(); } }; Navigation.PushAsync(host); } logs.Add(new Log("Clicked", QAForms.MobileLogType.END)); var log = Log.ProduceLog(logs); } 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.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 AssignmentFormInstance() { ID = o.ID, Description = o.Form.Description, Completed = false } ); Forms.ItemsSource = DataModel.Forms.ToArray(); } ); } ); }; Navigation.PushAsync(page); } } }