123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- 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<Log> logs = new List<Log>();
- 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<AssignmentForm>()
- .Query(new Filter<AssignmentForm>(x => x.ID).IsEqualTo(instance.ID))
- .Rows
- .Select(x => x.ToObject<AssignmentForm>())
- .FirstOrDefault();
-
- var model = new DigitalFormHostModel<Assignment, AssignmentLink, AssignmentForm>();
- 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<EmployeeDigitalForm>
- (
- new Filter<EmployeeDigitalForm>(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<Func<EmployeeDigitalForm, object>>[] { x => x.Form.Code, x => x.Form.Description },
- new Expression<Func<EmployeeDigitalForm, object>>[] { x => x.Form.ID },
- new SortOrder<EmployeeDigitalForm>(x => x.Form.Code)
- ));
- page.OnItemSelected += (row) =>
- {
- var form = new AssignmentForm();
- form.Parent.ID = DataModel.Item.ID;
- form.Form.ID = row.Get<EmployeeDigitalForm, Guid>(x => x.Form.ID);
- form.Form.Code = row.Get<EmployeeDigitalForm, String>(x => x.Form.Code);
- form.Form.Description = row.Get<EmployeeDigitalForm, String>(x => x.Form.Description);
-
- new Client<AssignmentForm>().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);
- }
- }
- }
|