Selaa lähdekoodia

Merge commit '0a78f72c1cef6526724c15ce00348292fa66fc8a' into frank

Frank van den Bos 2 vuotta sitten
vanhempi
commit
70da5c402b

+ 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);
@@ -1820,6 +1828,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)
@@ -1994,14 +2011,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;
+            }
+            catch
+            {
+                return null;
             }
-            else return null;
+
+        }
+
+        public void SetFieldColour(string field, System.Drawing.Color? colour = null)
+        {
+            
         }
 
 

+ 57 - 21
prs.stores/PurchaseOrderItemStore.cs

@@ -9,7 +9,7 @@ namespace Comal.Stores
 {
     internal class PurchaseOrderItemStore : BaseStore<PurchaseOrderItem>
     {
-        
+
         private void UpdateStockMovements(PurchaseOrderItem entity)
         {
             if (!entity.Product.IsValid())
@@ -43,7 +43,16 @@ namespace Comal.Stores
                         x => x.Dimensions.Height,
                         x => x.Dimensions.Weight,
                         x => x.Notes,
-                        x => x.Cost
+                        x => x.Cost,
+                        x => x.Dimensions.Unit.HasHeight,
+                        x => x.Dimensions.Unit.HasLength,
+                        x => x.Dimensions.Unit.HasWidth,
+                        x => x.Dimensions.Unit.HasWeight,
+                        x => x.Dimensions.Unit.HasQuantity,
+                        x => x.Dimensions.Unit.Formula,
+                        x => x.Dimensions.Unit.Format,
+                        x => x.Dimensions.Unit.Code,
+                        x => x.Dimensions.Unit.Description
                     )
                 ).Rows.Select(x => x.ToObject<StockMovement>()).ToList();
                 if (!result.Any())
@@ -57,6 +66,7 @@ namespace Comal.Stores
                 return Provider.Query(
                     new Filter<Product>(x => x.ID).IsEqualTo(entity.Product.ID),
                     new Columns<Product>(
+                        x => x.ID,
                         x => x.DefaultLocation.ID,
                         x => x.Warehouse.ID,
                         x => x.Dimensions.Unit.ID,
@@ -67,7 +77,16 @@ namespace Comal.Stores
                         x => x.Dimensions.Width,
                         x => x.Dimensions.Height,
                         x => x.Dimensions.Weight,
-                        x => x.NonStock
+                        x => x.NonStock,
+                        x => x.Dimensions.Unit.HasHeight,
+                        x => x.Dimensions.Unit.HasLength,
+                        x => x.Dimensions.Unit.HasWidth,
+                        x => x.Dimensions.Unit.HasWeight,
+                        x => x.Dimensions.Unit.HasQuantity,
+                        x => x.Dimensions.Unit.Formula,
+                        x => x.Dimensions.Unit.Format,
+                        x => x.Dimensions.Unit.Code,
+                        x => x.Dimensions.Unit.Description
                     )
                 ).Rows.FirstOrDefault();
             });
@@ -85,16 +104,16 @@ namespace Comal.Stores
             Task.WaitAll(movementtask, producttask, locationtask);
 
             var movements = movementtask.Result;
-            var product = producttask.Result;
+            var productrow = producttask.Result;
             var defaultlocations = locationtask.Result;
 
-            if (product == null)
+            if (productrow == null)
             {
                 Logger.Send(LogType.Information, UserID, "Cannot Find PurchaseOrderItem.Product.ID!");
                 return;
             }
 
-            if (product.Get<Product, bool>(x => x.NonStock))
+            if (productrow.Get<Product, bool>(x => x.NonStock))
             {
                 Logger.Send(LogType.Information, UserID, "PurchaseOrderItem.Product is marked as Non Stock!");
                 return;
@@ -103,9 +122,9 @@ namespace Comal.Stores
             if (!locationValid)
             {
                 Logger.Send(LogType.Information, UserID, "PurchaseOrderItem.Location.ID is blank!");
-                if (product != null)
+                if (productrow != null)
                 {
-                    var productlocationid = product.EntityLinkID<Product, StockLocationLink>(x => x.DefaultLocation) ?? Guid.Empty;
+                    var productlocationid = productrow.EntityLinkID<Product, StockLocationLink>(x => x.DefaultLocation) ?? Guid.Empty;
                     if (productlocationid != Guid.Empty)
                     {
                         Logger.Send(LogType.Information, UserID, "- Using Product.DefaultLocation.ID as location");
@@ -113,7 +132,7 @@ namespace Comal.Stores
                     }
                     else
                     {
-                        var productwarehouseid = product.Get<Product, Guid>(c => c.Warehouse.ID);
+                        var productwarehouseid = productrow.Get<Product, Guid>(c => c.Warehouse.ID);
                         var row = defaultlocations.Rows.FirstOrDefault(r => r.Get<StockLocation, Guid>(c => c.Warehouse.ID) == productwarehouseid);
                         if (row != null)
                         {
@@ -132,7 +151,7 @@ namespace Comal.Stores
                         locationid = row.Get<StockLocation, Guid>(x => x.ID);
                     }
                 }
-                
+
                 if (locationid == Guid.Empty)
                 {
                     Logger.Send(LogType.Information, UserID, "- Cannot find Location : Skipping Movement Creation");
@@ -140,19 +159,20 @@ namespace Comal.Stores
                 }
             }
 
-            
+
             if (
-                (entity.Dimensions.Unit.ID == Guid.Empty) 
-                && (entity.Dimensions.Height == 0) 
-                && (entity.Dimensions.Width == 0) 
-                && (entity.Dimensions.Length == 0) 
+                (entity.Dimensions.Unit.ID == Guid.Empty)
+                && (entity.Dimensions.Height == 0)
+                && (entity.Dimensions.Width == 0)
+                && (entity.Dimensions.Length == 0)
                 && (entity.Dimensions.Weight == 0)
                 )
             {
                 Logger.Send(LogType.Information, UserID, "PurchaseOrderItem.Unit Size is zero!");
-                entity.Dimensions.CopyFrom(product.ToObject<Product>().Dimensions);
+                entity.Dimensions.CopyFrom(productrow.ToObject<Product>().Dimensions);
             }
-            
+
+            var product = productrow.ToObject<Product>();
 
             foreach (var movement in movements)
             {
@@ -164,12 +184,27 @@ namespace Comal.Stores
                 movement.OrderItem.ID = entity.ID;
                 movement.Job.ID = entity.Job.ID;
                 movement.Location.ID = locationid;
-                movement.Dimensions.CopyFrom(entity.Dimensions);
                 movement.Style.ID = entity.Style.ID;
                 movement.Style.Code = entity.Style.Code;
                 movement.Style.Description = entity.Style.Description;
                 movement.Notes = string.Format("Received on PO {0}", entity.PurchaseOrderLink.PONumber);
                 movement.Cost = entity.Cost;
+                movement.Dimensions.UnitSize = product.Dimensions.UnitSize;
+                movement.Dimensions.Unit.ID = product.Dimensions.Unit.ID;
+                movement.Dimensions.Height = product.Dimensions.Height;
+                movement.Dimensions.Length = product.Dimensions.Length;
+                movement.Dimensions.Width = product.Dimensions.Width;
+                movement.Dimensions.Weight = product.Dimensions.Weight;
+                movement.Dimensions.Quantity = product.Dimensions.Quantity;
+                movement.Dimensions.Unit.HasHeight = product.Dimensions.Unit.HasHeight;
+                movement.Dimensions.Unit.HasWidth = product.Dimensions.Unit.HasWidth;
+                movement.Dimensions.Unit.HasLength = product.Dimensions.Unit.HasLength;
+                movement.Dimensions.Unit.HasWeight = product.Dimensions.Unit.HasWeight;
+                movement.Dimensions.Unit.HasQuantity = product.Dimensions.Unit.HasQuantity;
+                movement.Dimensions.Unit.Formula = product.Dimensions.Unit.Formula;
+                movement.Dimensions.Unit.Format = product.Dimensions.Unit.Format;
+                movement.Dimensions.Unit.Code = product.Dimensions.Unit.Code;
+                movement.Dimensions.Unit.Description = product.Dimensions.Unit.Description;
             }
 
             var updates = movements.Where(x => x.IsChanged());
@@ -177,6 +212,7 @@ namespace Comal.Stores
                 FindSubStore<StockMovement>().Save(updates, "Updated by Purchase Order Modification");
         }
 
+
         private void DeleteStockMovements(PurchaseOrderItem entity)
         {
             var movements = Provider.Query(
@@ -187,7 +223,7 @@ namespace Comal.Stores
             if (movements.Any())
                 FindSubStore<StockMovement>().Delete(movements, "Purchase Order Item marked as Unreceived");
         }
-        
+
         protected override void BeforeSave(PurchaseOrderItem entity)
         {
             base.BeforeSave(entity);
@@ -197,7 +233,7 @@ namespace Comal.Stores
         protected override void AfterSave(PurchaseOrderItem entity)
         {
             base.AfterSave(entity);
-            
+
             if (entity.ReceivedDate.IsEmpty())
                 DeleteStockMovements(entity);
             else
@@ -231,7 +267,7 @@ namespace Comal.Stores
         {
             base.BeforeDelete(entity);
             DeleteStockMovements(entity);
-            
+
             var delete = Provider.Query(
                 new Filter<PurchaseOrderItem>(x => x.ID).IsEqualTo(entity.ID),
                 new Columns<PurchaseOrderItem>(x => x.ID)