1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- namespace PRS.Mobile
- {
- public abstract class DigitalFormLookupView : ContentView,
- IDigitalFormField<DFLayoutLookupField, DFLayoutLookupFieldProperties, Guid>
- {
- private DFLayoutLookupField _definition;
- public DFLayoutLookupField Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value ?? new DFLayoutLookupField());
- }
- }
- protected DigitalFormLookupValue _value;
- public Guid Value
- {
- get => _value.ID;
- set =>_value.ID = value;
- }
- public bool IsEmpty => Value == Guid.Empty;
- protected abstract void UpdateUI();
-
- private bool _readOnly;
- public bool ReadOnly
- {
- get => _readOnly;
- set
- {
- _readOnly = value;
- UpdateStatus();
- }
- }
-
- public void Load(string value)
- {
- _value = new DigitalFormLookupValue(value);
- UpdateUI();
- }
- public string Save()
- {
- return _value?.ToString() ?? "";
- }
- public event DigitalFormViewChangedHandler ValueChanged;
- protected DigitalFormLookupView()
- {
- _value = new DigitalFormLookupValue();
- }
-
- protected void DoLookup(object sender, MobileButtonClickEventArgs args)
- {
- var entityType = CoreUtils.GetEntity(Definition.Properties.LookupType);
- var modeltype = typeof(SelectionViewModel<>).MakeGenericType(entityType);
- var model = (ISelectionViewModel)Activator.CreateInstance(modeltype);
- foreach (var additionalcolumn in Definition.Properties.AdditionalPropertiesList)
- model.VisibleColumns.Add(additionalcolumn);
- GenericSelectionPage _selector = new GenericSelectionPage("Select Value", model);
- _selector.OnItemSelected += (o,e) =>
- {
- _value.ID = e.Row.Get<Guid>("ID");
- _value.Text = e.Formatted;
- _value.Values = e.Row.ToDictionary();
- UpdateUI();
- ValueChanged?.Invoke(this, new DigitalFormViewChangedArgs(Definition,Value));
- };
- Navigation.PushAsync(_selector);
- }
- private void Initialize(DFLayoutLookupField definition)
- {
- UpdateStatus();
- }
- protected abstract void UpdateStatus();
- }
- }
|