Browse Source

PRS MOBILE - implement colour change renderer

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
0a78f72c1c
1 changed files with 95 additions and 44 deletions
  1. 95 44
      prs.mobile/comal.timesheets/DigitalForms/Renderer/QAFormViewer.cs

+ 95 - 44
prs.mobile/comal.timesheets/DigitalForms/Renderer/QAFormViewer.cs

@@ -119,7 +119,7 @@ namespace comal.timesheets.QAForms
                 LoadElements();
             }
         }
-        private async void LoadRowsAndColumns()
+        private void LoadRowsAndColumns()
         {
             LoadRows();
             LoadColumns();
@@ -158,7 +158,7 @@ namespace comal.timesheets.QAForms
                 Device.BeginInvokeOnMainThread(() => { ColumnDefinitions.Add(def); });
             }
         }
-        private async void LoadElements()
+        private void LoadElements()
         {
             rbGroup = 0; //used for customboolean - has to be outside of foreach loop
             foreach (DFLayoutControl element in dfLayout.Elements)
@@ -289,12 +289,19 @@ namespace comal.timesheets.QAForms
 
         private void AdjustHeaderSection(DigitalFormsHeader header, bool collapsed)
         {
-            var thisHeaderRow = GetRow(header);
-            var headerRows = GetOtherHeaders(thisHeaderRow);
-            if (headerRows.Any())
-                AdjustHeightsToNextHeader(headerRows, thisHeaderRow, collapsed);
-            else
-                AdjustHeightsBelowHeader(headerRows, thisHeaderRow, collapsed);
+            try
+            {
+                var thisHeaderRow = GetRow(header);
+                var headerRows = GetOtherHeaders(thisHeaderRow);
+                if (headerRows.Any())
+                    AdjustHeightsToNextHeader(headerRows, thisHeaderRow, collapsed);
+                else
+                    AdjustHeightsBelowHeader(headerRows, thisHeaderRow, collapsed);
+            }
+            catch
+            {
+
+            }
         }
 
         private List<int> GetOtherHeaders(int thisHeaderRow)
@@ -333,7 +340,7 @@ namespace comal.timesheets.QAForms
             }
         }
 
-        private async void AdjustHeight(int i, bool collapsed)
+        private void AdjustHeight(int i, bool collapsed)
         {
             var rowdef = RowDefinitions[i];
             if (collapsed)
@@ -419,7 +426,7 @@ namespace comal.timesheets.QAForms
         private Tuple<View, Boolean> LoadEditor(View view, DFLayoutControl element, string value)
         {
             Editor item = new Editor();
-
+            item.AutoSize = EditorAutoSizeOption.TextChanges;
             var isrequired = false;
             var issecure = false;
 
@@ -913,23 +920,24 @@ namespace comal.timesheets.QAForms
             {
                 framebutton.SetButtonText(value);
                 framebutton.Data = value + "," + (GlobalVariables.ProductShells.FirstOrDefault(x => x.Code == value)).ID.ToString();
-                CoreTable productTable = new Client<Product>().Query(new Filter<Product>(x => x.Code).IsEqualTo(value),
-                    new Columns<Product>(x => x.Image.ID));
-                if (productTable.Rows.Any())
-                {
-                    CoreTable imageTable1 = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(Guid.Parse(productTable.Rows.First().Values[0].ToString())),
-                            new Columns<Document>(x => x.Data));
-                    CoreRow docrow = imageTable1.Rows.FirstOrDefault();
-                    if (docrow != null)
-                    {
-                        byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
-                        ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
-                        if (src != null)
-                        {
-                            framebutton.SetImage(src);
-                        }
-                    }
-                }
+                //CoreTable productTable = new Client<Product>().Query(new Filter<Product>(x => x.Code).IsEqualTo(value),
+                //    new Columns<Product>(x => x.Image.ID));
+                //if (productTable.Rows.Any())
+                //{
+                //    CoreTable imageTable1 = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(Guid.Parse(productTable.Rows.First().Values[0].ToString())),
+                //            new Columns<Document>(x => x.Data));
+                //    CoreRow docrow = imageTable1.Rows.FirstOrDefault();
+                //    if (docrow != null)
+                //    {
+                //        byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
+                //        ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
+                //        if (src != null)
+                //        {
+                //            framebutton.SetImage(src);
+                //        }
+                //    }
+                //}
+
             }
             framebutton.OnFrameButtonClicked += (() =>
             {
@@ -938,18 +946,18 @@ namespace comal.timesheets.QAForms
                 {
                     framebutton.SetButtonText(productList.SelectedProduct.Code);
                     framebutton.Data = productList.SelectedProduct.Code + "," + productList.SelectedProduct.ID.ToString();
-                    CoreTable imageTable = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(productList.SelectedProduct.ImageID),
-                        new Columns<Document>(x => x.Data));
-                    CoreRow docrow = imageTable.Rows.FirstOrDefault();
-                    if (docrow != null)
-                    {
-                        byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
-                        ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
-                        if (src != null)
-                        {
-                            framebutton.SetImage(src);
-                        }
-                    }
+                    //CoreTable imageTable = new Client<Document>().Query(new Filter<Document>(x => x.ID).IsEqualTo(productList.SelectedProduct.ImageID),
+                    //    new Columns<Document>(x => x.Data));
+                    //CoreRow docrow = imageTable.Rows.FirstOrDefault();
+                    //if (docrow != null)
+                    //{
+                    //    byte[] data = docrow.Get<Document, byte[]>(x => x.Data);
+                    //    ImageSource src = ImageSource.FromStream(() => new MemoryStream(data));
+                    //    if (src != null)
+                    //    {
+                    //        framebutton.SetImage(src);
+                    //    }
+                    //}
                     dfLayout.ChangeField(dfLayoutLookupField.Name);
                 };
                 Navigation.PushAsync(productList);
@@ -1815,6 +1823,15 @@ namespace comal.timesheets.QAForms
 
             else if (field is DFLayoutLookupField)
                 AssignLookupOption(view, value as string);
+
+            else if (field is DFLayoutEmbeddedImage)
+                AssignImage(view, value as byte[]);
+        }
+
+        private void AssignImage(View view, byte[] bytes)
+        {
+            var imageCapture = view as EmbeddedImageCapture;
+            imageCapture.DataToImage(bytes);
         }
 
         private void AssignLookupOption(View view, string value)
@@ -1989,14 +2006,48 @@ namespace comal.timesheets.QAForms
         public object GetFieldData(string fieldName, string dataField)
         {
             Tuple<DFLayoutField, View> tuple = FindView(fieldName);
-            if (tuple.Item1 is DFLayoutLookupField)
+            try
             {
-                var button = tuple.Item2 as DataButtonControl;
-                Dictionary<string, object> dict = button.ExtraData[button.ChosenID];
-                return dict[dataField];
+                if (tuple.Item1 is DFLayoutLookupField)
+                {
+                    DFLayoutLookupField field = tuple.Item1 as DFLayoutLookupField;
+                    string type = field.Properties.LookupType;
+                    Type lookuptype = CoreUtils.GetEntityOrNull(type);
+                    if (lookuptype == typeof(Product))
+                    {
+                        var framebutton = tuple.Item2 as FrameButton;
+                        string[] buttonData = framebutton.Data.Split(',');
+                        string id = buttonData[1]; //[1] is product id as string
 
+                        CoreTable table = new Client<Product>().Query(new Filter<Product>(x => x.ID).IsEqualTo(Guid.Parse(id)), new Columns<Product>(x => x.Image.ID));
+                        if (table.Rows.Any())
+                        {
+                            Guid returnid = table.Rows.FirstOrDefault().Get<Product, Guid>(x => x.Image.ID);
+                            return returnid;
+                        }
+                        else
+                            return null;
+                    }
+                    else
+                    {
+                        var button = tuple.Item2 as DataButtonControl;
+                        Dictionary<string, object> dict = button.ExtraData[button.ChosenID];
+                        return dict[dataField];
+                    }
+                }
+                else
+                    return null;
             }
-            else return null;
+            catch
+            {
+                return null;
+            }
+
+        }
+
+        public void SetFieldColour(string field, System.Drawing.Color? colour = null)
+        {
+            
         }