Browse Source

PRS DESKTOP - emailing from report now adds more intelligent title for certain entities

Nick-PRSDigital@bitbucket.org 2 years ago
parent
commit
e6eac25bfa
1 changed files with 30 additions and 1 deletions
  1. 30 1
      prs.desktop/MainWindow.xaml.cs

+ 30 - 1
prs.desktop/MainWindow.xaml.cs

@@ -1792,7 +1792,36 @@ namespace PRSDesktop
 
         private void DoEmailReport(DataModel model, byte[] data)
         {
-            EmailUtils.CreateEMLFile(model.Name, data, App.EmployeeEmail, "Emailing report for " + model.Name);
+            string attachmentName = DetermineName(model);
+
+            EmailUtils.CreateEMLFile(attachmentName, data, App.EmployeeEmail, "Emailing report for " + attachmentName);
+        }
+
+        private string DetermineName(DataModel model)
+        {
+            string title = model.Name;
+            if (model.AsDictionary.ContainsKey(typeof(Requisition)))
+            {
+                CoreTable table = model.AsDictionary[typeof(Requisition)];
+                title = title + " - " + table.Rows.FirstOrDefault().Get<Requisition, string>(x => x.Title);
+            }
+            else if (model.AsDictionary.ContainsKey(typeof(PurchaseOrder)))
+            {
+                title = "Purchase Order";
+                CoreTable table = model.AsDictionary[typeof(PurchaseOrder)];
+                if (table.Rows.Count == 1)
+                    title = title + table.Rows.FirstOrDefault().Get<PurchaseOrder, string>(x => x.PONumber);
+                else if (table.Rows.Count > 1)
+                {
+                    foreach (CoreRow row in table.Rows)
+                    {                     
+                        title = title + row.Get<PurchaseOrder, string>(x => x.PONumber) + ", ";
+                    }
+                    title = title.Substring(0, title.Length - 2);
+                }                
+            }
+
+            return title;
         }
         #endregion