123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760 |
- using System;
- using System.Collections.Generic;
- using System.Threading.Tasks;
- using System.Linq;
- using Xamarin.Forms;
- using InABox.Core;
- using InABox.Clients;
- using System.IO;
- using InABox.Mobile;
- using Syncfusion.XForms.SignaturePad;
- using Comal.Classes;
- using PRSClasses;
- namespace PRS.Mobile
- {
- public class QAFormViewer : Grid, IDFRenderer
- {
- #region Fields
-
- // This connects the DFLayout elements to the respective UI elements
- public readonly Dictionary<DFLayoutField, IDigitalFormField> Bindings = new();
-
- // These get saved into FormData
- public readonly Dictionary<String, String> Data = new();
- // These are used to pre-populate the next instance of this form
- public readonly Dictionary<String, String> RetainedData = new();
-
- public readonly Dictionary<DFLayoutLookupField, Dictionary<Guid, string>> dfLayoutLookupFieldLookupOptions = new();
- private DFLayout _layout = new();
- private IDigitalFormDataModel _model;
-
- const string nullOrInvalidType = "Null or Invalid Type";
-
- private readonly List<string> useSavedSignatures = new();
-
- public readonly List<string> errors = new();
- public bool isRequiredEmpty { get; set; }
- public string isRequiredMessage { get; set; }
- private readonly Location location = new();
-
- private readonly Color isRequiredColor = Color.DarkOrange;
- private readonly Color isRequiredFrame = Color.Firebrick;
- private DateTime timeStarted = DateTime.MinValue;
- readonly List<DigitalFormHeader> headersToCollapse = new();
- #endregion
- #region Constructor
- public QAFormViewer()
- {
-
- }
-
- public QAFormViewer(IDigitalFormDataModel model, DFLayout layout,
- Guid job = default) : this()
- {
- Load(model, layout, job);
- }
-
- public void Load(IDigitalFormDataModel model, DFLayout layout, Guid job = default)
- {
- GetLocation();
- timeStarted = DateTime.Now;
-
- _model = model;
-
- _layout = layout;
- _layout.Renderer = this;
-
- isRequiredEmpty = false;
- isRequiredMessage = "";
- LoadFormLayout();
-
- Data.Clear();
- Dictionary<String, Object> data = DigitalForm.DeserializeFormData(this._model.Instance);
- if (data != null)
- {
- foreach (KeyValuePair<string, object> keyValuePair in data)
- Data.Add(keyValuePair.Key, keyValuePair.Value.ToString());
- }
-
- LoadData();
- }
- #endregion
- #region Location
-
- private async void GetLocation()
- {
- await Task.Run(() =>
- {
- LocationServices locationServices = new LocationServices();
- locationServices.OnLocationFound += LocationFound;
- locationServices.OnLocationError += LocationError;
- locationServices.GetLocation();
- });
- }
- private async void LocationFound(LocationServices sender)
- {
- location.Latitude = sender.Latitude;
- location.Longitude = sender.Longitude;
- }
-
- private async void LocationError(LocationServices sender, Exception error)
- {
- errors.Add("Location error: " + error.Message);
- }
-
- #endregion Location
-
- #region Load and Save Data
-
- public void LoadData()
- {
- foreach (DFLayoutField field in Bindings.Keys)
- {
- try
- {
- if (RetainedData.TryGetValue(field.Name, out var retained))
- Bindings[field].Deserialize(retained);
- else if (Data.TryGetValue(field.Name, out var data))
- Bindings[field].Deserialize(data);
- else
- Bindings[field].Deserialize("");
- _layout.ChangeField(field.Name);
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex,$"LoadData({field.Name})");
- }
- }
- }
-
- public void SaveData(bool saveForLater)
- {
- try
- {
- Data.Clear();
- RetainedData.Clear();
- foreach (DFLayoutField field in Bindings.Keys)
- {
- var value = Bindings[field].Serialize();
- Data[field.Name] = value;
- if (field.GetProperties().Retain)
- RetainedData[field.Name] = value;
- }
- UpdateModel(saveForLater);
- }
- catch (Exception ex)
- {
- InABox.Mobile.MobileLogging.Log(ex,"SaveData");
- }
- }
-
- #endregion
- #region Load Form Layout
-
- private void LoadFormLayout()
- {
-
- RowDefinitions.Clear();
- foreach (var row in _layout.RowHeights)
- {
- RowDefinition def = new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) };
- SetRowHeight(row, def);
- RowDefinitions.Add(def);
- }
- ColumnDefinitions.Clear();
- foreach (var col in _layout.ColumnWidths)
- {
- ColumnDefinition def = new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) };
- def = SetColumnWidth(col, def);
- ColumnDefinitions.Add(def);
- }
- Children.Clear();
- foreach (DFLayoutControl element in _layout.Elements)
- LoadViewAccordingToElement(element);
-
- foreach (var header in headersToCollapse)
- AdjustHeaderSection(header, false);
- }
-
- private static void SetRowHeight(string row, RowDefinition def)
- {
- if (int.TryParse(row, out int rowHeight))
- def.Height = new GridLength(Math.Max(60, rowHeight), GridUnitType.Absolute);
- else if (row.Contains("*"))
- {
- def.Height = int.TryParse(row.Substring(0, row.IndexOf("*")), out int result)
- ? new GridLength(result, GridUnitType.Star)
- : new GridLength(1, GridUnitType.Star);
- }
- else
- def.Height = new GridLength(1, GridUnitType.Auto);
- }
-
- private static ColumnDefinition SetColumnWidth(string col, ColumnDefinition def)
- {
- if (int.TryParse(col, out int colWidth))
- def = new ColumnDefinition { Width = new GridLength(colWidth, GridUnitType.Absolute) };
- else if (col.Contains("*"))
- {
- def = int.TryParse(col.Substring(0, col.IndexOf("*")), out int result)
- ? new ColumnDefinition { Width = new GridLength(result, GridUnitType.Star) }
- : new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) };
- }
- return def;
- }
-
- private void LoadViewAccordingToElement(DFLayoutControl element)
- {
- // Not sure why this is here - perhaps to ry and handle malformed element definitions?
- if (string.IsNullOrEmpty(element.Description))
- return;
-
- if (element is DFLayoutLabel l)
- {
- var result = new DigitalFormLabel() { Definition = l };
- AddViewToGrid(result, element);
- }
-
- else if (element is DFLayoutImage img )
- {
- var result = new DigitalFormImage() { Definition = img };
- AddViewToGrid(result, element);
- }
-
- else if (element is DFLayoutHeader hdr)
- {
- var result = new DigitalFormHeader() { Definition = hdr };
- result.CollapsedChanged += (sender, args) => AdjustHeaderSection(result, result.Collapsed);
- if (hdr.Collapsed)
- headersToCollapse.Add(result);
- AddViewToGrid(result, element);
- }
-
- else if (element is DFLayoutBooleanField b)
- CreateView<DigitalFormBoolean, DFLayoutBooleanField, DFLayoutBooleanFieldProperties, bool>(b);
-
- else if (element is DFLayoutStringField s)
- {
- if (s.Properties.PopupEditor)
- CreateView<DigitalFormStringPopup, DFLayoutStringField, DFLayoutStringFieldProperties, string>(s);
- else if (s.Properties.TextWrapping)
- CreateView<DigitalFormStringEditor, DFLayoutStringField, DFLayoutStringFieldProperties, string>(s);
- else
- CreateView<DigitalFormStringEntry, DFLayoutStringField, DFLayoutStringFieldProperties, string>(s);
- }
-
- else if (element is DFLayoutIntegerField i)
- CreateView<DigitalFormIntegerEntry, DFLayoutIntegerField, DFLayoutIntegerFieldProperties, int>(i);
-
- else if (element is DFLayoutDoubleField d)
- CreateView<DigitalFormDoubleEntry, DFLayoutDoubleField, DFLayoutDoubleFieldProperties, double>(d);
- else if (element is DFLayoutDateField df)
- CreateView<DigitalFormDateEntry, DFLayoutDateField, DFLayoutDateFieldProperties, DateTime>(df);
-
- else if (element is DFLayoutTimeField tf)
- CreateView<DigitalFormTimeEntry, DFLayoutTimeField, DFLayoutTimeFieldProperties, TimeSpan>(tf);
-
- else if (element is DFLayoutOptionField of)
- {
- if (of.Properties.OptionType == DFLayoutOptionType.Radio)
- CreateView<DigitalFormOptionRadioList, DFLayoutOptionField, DFLayoutOptionFieldProperties, string>(of);
- else if (of.Properties.OptionType == DFLayoutOptionType.Buttons)
- CreateView<DigitalFormOptionButtonList, DFLayoutOptionField, DFLayoutOptionFieldProperties, string>(of);
- else
- CreateView<DigitalFormOptionComboBox, DFLayoutOptionField, DFLayoutOptionFieldProperties, string>(of);
- }
-
- else if (element is DFLayoutLookupField lf)
- {
- if (lf.Properties.DisplayType == DFLayoutLookupDisplayType.Combo)
- CreateView<DigitalFormLookupComboBox, DFLayoutLookupField, DFLayoutLookupFieldProperties, Guid>(lf);
- else
- CreateView<DigitalFormLookupButton, DFLayoutLookupField, DFLayoutLookupFieldProperties, Guid>(lf);
- }
-
- else if (element is DFLayoutSignaturePad sp)
- CreateView<DigitalFormSignature, DFLayoutSignaturePad, DFLayoutSignaturePadProperties, byte[]>(sp);
- else if (element is DFLayoutEmbeddedImage ei)
- CreateView<DigitalFormEmbeddedImage, DFLayoutEmbeddedImage, DFLayoutEmbeddedImageProperties, DFLayoutEmbeddedMediaValue>(ei);
-
- else if (element is DFLayoutVideoField ev)
- CreateView<DigitalFormEmbeddedVideo, DFLayoutVideoField, DFLayoutVideoFieldProperties, DFLayoutEmbeddedMediaValue>(ev);
-
- else if (element is DFLayoutMultiImage mi)
- CreateView<DigitalFormMultiImage, DFLayoutMultiImage, DFLayoutMultiImageProperties, DFLayoutEmbeddedMediaValues>(mi);
-
- else if (element is DFLayoutMultiSignaturePad)
- {
- var tuple = LoadMultiSignaturePad(element);
- AddViewToGrid(tuple.Item1, element);
- }
- else if (element is DFLayoutAddTaskField)
- {
- var tuple = LoadAddTaskField(element);
- AddViewToGrid(tuple.Item1, element);
- }
-
- }
-
- private TField CreateView<TField, TDefinition, TProperties, TValue>(TDefinition definition)
- where TField : View, IDigitalFormField<TDefinition, TProperties, TValue>, new()
- where TDefinition : DFLayoutField<TProperties>
- where TProperties : DFLayoutFieldProperties<TValue>, new()
- {
- TField item = new TField()
- {
- Definition = definition,
- IsEnabled = !definition.GetProperties().Secure
- && _model.Instance.FormCompleted.IsEmpty()
- && string.IsNullOrWhiteSpace(definition.GetPropertyValue<string>("Expression")),
- };
- item.ValueChanged += (sender, args) =>
- {
- // Update Object?
- var property = args.Definition.GetProperties().Property;
- if (!String.IsNullOrWhiteSpace(property))
- CoreUtils.SetPropertyValue(_model.Entity,property,args.Value);
- foreach (var other in Bindings.Keys.Where(x=>x.Name != args.Definition.Name))
- {
- var linked = other.GetProperties().Property;
- if (!String.IsNullOrWhiteSpace(linked))
- {
- var linkedvalue = CoreUtils.GetPropertyValue(_model.Entity, linked);
- // Problem - linkedvalue might not be the same as the
- //CoreUtils.SetPropertyValue(pairs[other],"Value",linkedvalue);
- }
- }
- // Update ChangedLinkedProperties?
- // Run Expressions and Scripts?
- // Update Dictionary?
- };
-
- Bindings[definition] = item;
-
- AddViewToGrid(item, definition);
-
- return item;
- }
-
- private void AddViewToGrid(View view, DFLayoutControl element)
- {
- //rows and columns coming in from the desktop designer start from 1, not 0 (most of the time??)
- SetRow(view, Math.Max(0,element.Row - 1));
- SetRowSpan(view, Math.Max(1,element.RowSpan));
- SetColumn(view, Math.Max(0,element.Column - 1));
- SetColumnSpan(view, Math.Max(1,element.ColumnSpan));
- Children.Add(view);
- }
-
- private void AdjustHeaderSection(DigitalFormHeader header, bool collapsed)
- {
- try
- {
- var thisHeaderRow = GetRow(header);
- var headerRows = Children.OfType<DigitalFormHeader>().Select(x => GetRow(x)).OrderBy(x=>x).ToArray();
- if (headerRows.Any())
- AdjustHeightsToNextHeader(headerRows, thisHeaderRow, collapsed);
- else
- AdjustHeightsBelowHeader(headerRows, thisHeaderRow, collapsed);
- }
- catch (Exception ex)
- {
- MobileLogging.Log(ex, "AdjustHeaderSection()");
- }
- }
-
- private void AdjustHeightsToNextHeader(int[] headerRows, int thisHeaderRow, bool collapsed)
- {
- int nextHeaderRow = headerRows[0];
- for (int i = thisHeaderRow + 1; i < nextHeaderRow; i++)
- AdjustHeight(i, collapsed);
- }
- private void AdjustHeightsBelowHeader(int[] headerRows, int thisHeaderRow, bool collapsed)
- {
- for (int i = thisHeaderRow + 1; i < RowDefinitions.Count; i++)
- AdjustHeight(i, collapsed);
- }
- private void AdjustHeight(int i, bool collapsed)
- {
- var rowdef = RowDefinitions[i];
-
- if (collapsed)
- SetRowHeight(_layout.RowHeights[i], rowdef);
- else
- rowdef.Height = 0;
- }
- private Tuple<View, bool> LoadMultiSignaturePad(DFLayoutControl element)
- {
- string value = "";
- DFLayoutMultiSignaturePad dfLayoutMultiSignaturePad = element as DFLayoutMultiSignaturePad;
- DataButtonControl button = new DataButtonControl
- {
- Text = "Add Signatures",
- };
- if (Data.TryGetValue(dfLayoutMultiSignaturePad.Name, out value))
- {
- button.Data = value;
- }
- MultiSignaturePad multiSignaturePad = new MultiSignaturePad(button.Data);
- multiSignaturePad.OnMultiSignatureSaved += (result) =>
- {
- button.Data = result;
- };
- button.Clicked += (object sender, MobileButtonClickEventArgs e) =>
- {
- Navigation.PushAsync(multiSignaturePad);
- };
-
- if (dfLayoutMultiSignaturePad.Properties.Required)
- {
- button.BackgroundColor = isRequiredColor;
- button.BorderColor = isRequiredFrame;
- }
- else if (!_model.Instance.FormCompleted.IsEmpty())
- {
- button.BackgroundColor = Color.Silver;
- button.BorderColor = Color.Gray;
- }
- return new Tuple<View, bool>(button, dfLayoutMultiSignaturePad.Properties.Required);
- }
- private Tuple<View, bool> LoadAddTaskField(DFLayoutControl element)
- {
- string value = "";
- DFLayoutAddTaskField field = element as DFLayoutAddTaskField;
- DFCreateTaskView taskView = new DFCreateTaskView();
- taskView.OnAddTaskButtonClicked += () =>
- {
- AddEditTask addEditTask = new AddEditTask(Guid.Empty, "New task from Digital Form");
- if (field.Properties.TaskType != null)
- {
- addEditTask.kanban.Type.ID = field.Properties.TaskType.ID;
- try
- {
- addEditTask.kanban.Type.Description = new Client<KanbanType>().Query(
- new Filter<KanbanType>(x => x.ID).IsEqualTo(field.Properties.TaskType.ID),
- new Columns<KanbanType>(x => x.Description)
- ).Rows.FirstOrDefault()?.Get<KanbanType,String>(c=>c.Description) ?? "";
- }
- catch (Exception ex)
- {
- MobileLogging.Log(ex,"LoadAddTaskField");
- }
- addEditTask.UpdateScreen(true);
- }
- addEditTask.OnTaskSaved += (taskNumber) =>
- {
- taskView.DisableButton();
- taskView.TaskNumber = taskNumber.ToString();
- };
- Navigation.PushAsync(addEditTask);
- };
- if (Data.TryGetValue(field.Name, out value))
- {
- taskView.TaskNumber = value;
- taskView.DisableButton();
- }
- return new Tuple<View, bool>(taskView, field.Properties.Required);
- }
-
- #endregion
- #region Checks / Custom methods
- private void CheckRequired(DFLayoutField field)
- {
- if (field is DFLayoutStringField)
- {
- if ((field as DFLayoutStringField).Properties.Required)
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutStringField).Description;
- }
- }
- else if (field is DFLayoutIntegerField)
- {
- if ((field as DFLayoutIntegerField).Properties.Required)
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutIntegerField).Description;
- }
- }
- else if (field is DFLayoutDoubleField)
- {
- if ((field as DFLayoutDoubleField).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutIntegerField).Description;
- }
- }
- }
- else if (field is DFLayoutBooleanField)
- {
- if ((field as DFLayoutBooleanField).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutBooleanField).Description;
- }
- }
- }
- else if (field is DFLayoutDateField)
- {
- if ((field as DFLayoutDateField).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutDateField).Description;
- }
- }
- }
- else if (field is DFLayoutTimeField)
- {
- if ((field as DFLayoutTimeField).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutTimeField).Description;
- }
- }
- }
- else if (field is DFLayoutOptionField)
- {
- if ((field as DFLayoutOptionField).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutOptionField).Description;
- }
- }
- }
- else if (field is DFLayoutLookupField)
- {
- if ((field as DFLayoutLookupField).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutLookupField).Description;
- }
- }
- }
- else if (field is DFLayoutSignaturePad)
- {
- if ((field as DFLayoutSignaturePad).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutSignaturePad).Description;
- }
- }
- }
- else if (field is DFLayoutEmbeddedImage)
- {
- if ((field as DFLayoutEmbeddedImage).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutEmbeddedImage).Description;
- }
- }
- }
- else if (field is DFLayoutMultiImage)
- {
- if ((field as DFLayoutMultiImage).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutMultiImage).Description;
- }
- }
- }
- else if (field is DFLayoutMultiSignaturePad)
- {
- if ((field as DFLayoutMultiSignaturePad).Properties.Required)
- {
- {
- isRequiredEmpty = true;
- isRequiredMessage = (field as DFLayoutMultiSignaturePad).Description;
- }
- }
- }
- }
-
- private string ImageSourceToBase64(ImageSource source)
- {
- StreamImageSource streamImageSource = (StreamImageSource)source;
- System.Threading.CancellationToken cancellationToken = System.Threading.CancellationToken.None;
- Task<Stream> task = streamImageSource.Stream(cancellationToken);
- Stream stream = task.Result;
- byte[] bytes = new byte[stream.Length];
- stream.Read(bytes, 0, bytes.Length);
- string s = Convert.ToBase64String(bytes, Base64FormattingOptions.InsertLineBreaks);
- return s;
- }
-
- private string FindIDForDesignLookupField(DataButtonControl button)
- {
- try
- {
- string userInputValue = button.Data;
- string guidString = "";
- if (userInputValue != nullOrInvalidType)
- {
- foreach (KeyValuePair<DFLayoutLookupField, Dictionary<Guid, string>> pair in dfLayoutLookupFieldLookupOptions)
- {
- foreach (KeyValuePair<Guid, string> innerPair in pair.Value)
- {
- if (innerPair.Value == userInputValue)
- {
- guidString = innerPair.Key.ToString();
- }
- }
- }
- }
- return guidString;
- }
- catch (Exception e)
- {
- MobileLogging.Log(e,"FindIDForDesignLookupField");
- return "";
- }
- }
- #endregion
- #region Save Completion
-
- //point of determination for whether or not QA form gets completed or saved for later
- private void UpdateModel(bool saveForLater)
- {
- if (Data.Count != 0)
- {
-
- // Blobs are uploaded in the background by DigitalFormDocumentHandler class,
- // so the blob breakup doesn't have to happen anymore :-)
- DigitalForm.SerializeFormData(_model.Instance, _model.Variables, Data.ToDictionary(x => x.Key, x => x.Value as object));
- //DigitalForm.SerializeFormData(model.Instance, QueryVariables(model.Instance), results.ToDictionary(x => x.Key, x => x.Value as object));
- if (_model.Instance.FormStarted == DateTime.MinValue)
- _model.Instance.FormStarted = timeStarted;
- _model.Instance.FormOpen += (DateTime.Now - timeStarted);
-
- if (!saveForLater)
- {
- _model.Instance.FormCompleted = DateTime.Now;
- _model.Instance.FormCompletedBy.ID = App.Data.Me.UserID;
- _model.Instance.Location.Longitude = location.Longitude;
- _model.Instance.Location.Latitude = location.Latitude;
- _model.Instance.Location.Timestamp = _model.Instance.FormCompleted;
- }
-
- _model.Update(null);
- }
- }
-
- #endregion
- #region Expressions
-
- public object GetFieldValue(string name)
- {
- try
- {
- var definition = Bindings.Keys.FirstOrDefault(x => String.Equals(x.Name, name));
- if (definition != null)
- return CoreUtils.GetPropertyValue(Bindings[definition],"Value");
- }
- catch (Exception e)
- {
- MobileLogging.Log(e,"SetFieldValue");
- }
- return null;
- }
- public void SetFieldValue(string name, object value)
- {
- try
- {
- var definition = Bindings.Keys.FirstOrDefault(x => String.Equals(x.Name, name));
- if (definition != null)
- CoreUtils.SetPropertyValue(Bindings[definition],"Value",value);
- }
- catch (Exception e)
- {
- MobileLogging.Log(e,"SetFieldValue");
- }
- }
-
- public object GetFieldData(string fieldName, string dataField)
- {
- var definition = Bindings.Keys.FirstOrDefault(x => String.Equals(x.Name, fieldName));
- if ((definition != null) && (Bindings[definition] is DigitalFormLookupView lookup))
- return lookup.OtherValue(dataField);
- return null;
- }
- public void SetFieldColour(string field, System.Drawing.Color? colour = null)
- {
- if (colour != null)
- {
- try
- {
- System.Drawing.Color color = (System.Drawing.Color)colour;
- var definition = Bindings.Keys.FirstOrDefault(x => String.Equals(x.Name, field));
- if (definition != null)
- {
- Bindings[definition].BackgroundColor = Color.FromRgba(
- Convert.ToDouble(color.R),
- Convert.ToDouble(color.G),
- Convert.ToDouble(color.B),
- Convert.ToDouble(color.A)
- );
- }
- }
- catch (Exception e)
- {
- MobileLogging.Log(e,"SetFieldColor");
- }
- }
- }
- #endregion
- }
- }
|