| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- 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 DFLayoutLookupValue _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 object OtherValue(String property)
- {
- if ((_value?.Values != null) && _value.Values.TryGetValue(property, out object result))
- return result;
- return null;
- }
-
- public void Deserialize(string serialized)
- {
- _value = new DFLayoutLookupValue(serialized);
- UpdateUI();
- }
- public string Serialize()
- {
- return _value?.ToString() ?? "";
- }
- public event DigitalFormViewChangedHandler ValueChanged;
- protected DigitalFormLookupView()
- {
- _value = new DFLayoutLookupValue();
- }
-
- 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();
- }
- }
|