Kaynağa Gözat

Fix to reports crash

Kenric Nugteren 1 yıl önce
ebeveyn
işleme
c317fdbbbd

+ 1 - 80
InABox.Core/CoreExpression.cs

@@ -11,43 +11,6 @@ using System.Text.RegularExpressions;
 
 namespace InABox.Core
 {
-    //using FncType = Func<IExpression[], IDictionary<string, object>, object?>;
-
-    // public class CoreExpressionFunction
-    // {
-    //     public string Group { get; set; }
-    //
-    //     public string Name { get; set; }
-    //
-    //     public string? Description { get; set; }
-    //     
-    //     public List<Parameter> Parameters { get; set; }
-    //
-    //     public FncType Function { get; set; }
-    //
-    //     public class Parameter
-    //     {
-    //         public string Name { get; set; }
-    //
-    //         public string Type { get; set; }
-    //
-    //         public Parameter(string name, string type)
-    //         {
-    //             Name = name;
-    //             Type = type;
-    //         }
-    //     }
-    //
-    //     public CoreExpressionFunction(string group, string name, FncType function, List<Parameter> parameters, string? description = null)
-    //     {
-    //         Group = group;
-    //         Name = name;
-    //         Parameters = parameters;
-    //         Function = function;
-    //         Description = description;
-    //     }
-    // }
-
     public interface IExpressionModel { }
     public interface IExpressionModel<TReturn> : IExpressionModel { }
 
@@ -118,7 +81,7 @@ namespace InABox.Core
                 {
                     return Expression.ReferencedVariables != null;
                 }
-                catch (Exception e)
+                catch
                 {
                     return false;
                 }   
@@ -141,11 +104,6 @@ namespace InABox.Core
                 expr = expr.Replace("+\"\"", "");
                 Expression = new Expression(expr);
             }
-            
-            // foreach (var function in Functions)
-            // {
-            //     Expression.RegisterFunction(function.Name, function.Function);
-            // }
         }
 
         public object? Evaluate(Dictionary<string, object?>? variables)
@@ -180,47 +138,10 @@ namespace InABox.Core
         
         static CoreExpression()
         {
-            
             RegisterFunction<FormatFunction>();
             RegisterFunction<Client_LoadDocumentFunction>();
-            
-            // RegisterFunction("String", "Format", (p, v) =>
-            // {
-            //     if (!(p[0].Evaluate(v) is string format)) throw new Exception("No format string given for Format()");
-            //     return string.Format(format, p.Skip(1).Select(x => x.Evaluate(v)).ToArray());
-            // }, "string fmt", "...");
-
-            //RegisterFunction("Other", "Client_LoadDocument", "Loads a byte array from the database Document table, with the ID {docID}.", Fnc_LoadDocument, "Guid docID");
         }
 
-        // private static object? Fnc_LoadDocument(IExpression[] p, IDictionary<string, object> v)
-        // {
-        //     var id = p[0].Evaluate(v);
-        //     if (id is null)
-        //         return null;
-        //     if (!(id is Guid docID))
-        //         return null;
-        //
-        //     return new Client<Document>()
-        //         .Query(
-        //             new Filter<Document>(x => x.ID).IsEqualTo(docID),
-        //             new Columns<Document>(x => x.Data))
-        //         .Rows.FirstOrDefault()
-        //         ?.Get<Document, byte[]>(x => x.Data);
-        // }
-
-        // public static void RegisterFunction(string group, string name, FncType function, params string[] parameters)
-        //     => RegisterFunction(group, name, null, function, parameters);
-
-        // public static void RegisterFunction(string group, string name, string? description, FncType function, params string[] parameters) =>
-        //     Functions.Add(new CoreExpressionFunction(group, name, function, parameters.Select(x =>
-        //     {
-        //         var parts = x.Split(' ');
-        //         if (parts.Length == 1)
-        //             return new CoreExpressionFunction.Parameter(parts[0], "");
-        //         return new CoreExpressionFunction.Parameter(parts[1], parts[0]);
-        //     }).ToList(), description));
-
         #endregion
     }
 

+ 11 - 2
InABox.Core/DigitalForms/DataModel/DigitalFormDataModel.cs

@@ -57,7 +57,16 @@ namespace InABox.Core
             }
         }
 
-        public IDigitalFormInstance Instance { get; set; }
+        IDigitalFormInstance IDigitalFormDataModel.Instance
+        {
+            get => Instance;
+            set
+            {
+                Instance = (TInstance)value;
+            }
+        }
+
+        public TInstance Instance { get; set; }
         
         public DigitalFormVariable[] Variables { get; set; }
 
@@ -209,7 +218,7 @@ namespace InABox.Core
                 foreach (var item in formData.Items())
                     variables[$"Data.{item.Key}"] = item.Value;
                 
-                var instancedata = Entity.GetValues(true);
+                var instancedata = Instance.GetValues(true);
                 foreach (var item in instancedata)
                     variables[$"Form.{item.Key}"] = item.Value;
                 

+ 0 - 36
inabox.wpf/Reports/PreviewWindow.xaml.cs

@@ -216,42 +216,6 @@ namespace InABox.Wpf.Reports
             Title = string.Format("Report Preview - {0}", _template.Name);
 
             SetupReport(() => Refresh());
-            /*Task.Run(() =>
-            {
-                try
-                {
-                    if(_report == null)
-                    {
-                        _report = ReportUtils.SetupReport(_template, _model, !modelIsPopulated);
-                    }
-                    return null;
-                }
-                catch (Exception e)
-                {
-                    return e.Message;
-                }
-            }).ContinueWith((s) =>
-            {
-                try
-                {
-                    if (s.Result == null)
-                    {
-                        if(Designer.Report == null)
-                        {
-                            Designer.Report = _report;
-                        }
-                        Refresh();
-                    }
-                    else
-                    {
-                        ShowEditor(s.Result);
-                    }
-                }
-                catch (Exception e)
-                {
-                    ShowEditor(e.Message);
-                }
-            }, TaskScheduler.FromCurrentSynchronizationContext());*/
         }
 
         private void ShowDesigner()

+ 7 - 5
inabox.wpf/Reports/ReportUtils.cs

@@ -79,12 +79,14 @@ namespace InABox.Wpf.Reports
             CoreUtils.RegisterClasses(typeof(ReportTemplate).Assembly, typeof(ReportUtils).Assembly);
             foreach (string printer in PrinterSettings.InstalledPrinters)
                 ReportPrinters.Register(printer);
-            
-            RegisteredObjects.Add(typeof(MultiImageObject), "ReportPage",Wpf.Resources.multi_image, "Multi-Image");
-            RegisteredObjects.Add(typeof(MultiSignatureObject), "ReportPage",Wpf.Resources.signature, "Multi-Signature");
-            RegisteredObjects.Add(typeof(HTMLView), "ReportPage",Wpf.Resources.view, "HTML");
 
-         }
+            Application.Current.Dispatcher.BeginInvoke(() =>
+            {
+                RegisteredObjects.Add(typeof(MultiImageObject), "ReportPage", Wpf.Resources.multi_image, "Multi-Image");
+                RegisteredObjects.Add(typeof(MultiSignatureObject), "ReportPage",Wpf.Resources.signature, "Multi-Signature");
+                RegisteredObjects.Add(typeof(HTMLView), "ReportPage",Wpf.Resources.view, "HTML");
+            });
+        }
 
         public static void PreviewReport(ReportTemplate template, DataModel data, bool printandclose = false, bool allowdesigner = false)
         {