Quellcode durchsuchen

PRS DESKTOP - email template changes

Nick-PRSDigital@bitbucket.org vor 2 Jahren
Ursprung
Commit
92a054dfde
3 geänderte Dateien mit 45 neuen und 38 gelöschten Zeilen
  1. 25 23
      prs.desktop/Grids/DataModelTemplateGrid.cs
  2. 17 12
      prs.desktop/MainWindow.xaml.cs
  3. 3 3
      prs.shared/EmailUtils.cs

+ 25 - 23
prs.desktop/Grids/DataModelTemplateGrid.cs

@@ -2,6 +2,7 @@
 using System.Collections.Generic;
 using System.Linq;
 using System.Windows.Media.Imaging;
+using FastReport.Dialog;
 using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
@@ -28,26 +29,32 @@ namespace PRSDesktop
             if (editor == null)
                 return;
 
-            if (column.ColumnName.Equals("To") ||
-                column.ColumnName.Equals("CC") ||
-                column.ColumnName.Equals("BCC") ||
-                column.ColumnName.Equals("Subject") ||
-                column.ColumnName.Equals("AttachmentName")
+            if (column.ColumnName.Equals("Template")
+                || column.ColumnName.Equals("To")
+                || column.ColumnName.Equals("Subject")
+                || column.ColumnName.Equals("AttachmentName")
                 )
-                (editor as ExpressionEditor).OnGetVariables += EmailTemplateManagerWindow_OnGetVariables;
-            else if (column.ColumnName.Equals("Template") && items.Count() == 1)
             {
-                var edt = editor as ScriptEditor;
-                edt.Type = ScriptEditorType.TemplateEditor;
-                Items = items;
-                edt.OnEditorClicked += Edt_OnEditorClicked;
-            }               
+                var edt = editor as TextBoxEditor;
+                edt.Buttons = new EditorButton[]
+                {
+                    new EditorButton(items.FirstOrDefault(), "Edit", 60, TemplateEditorClicked, true)
+                };
+            }
+
+
         }
 
-        private void Edt_OnEditorClicked()
+        private void TemplateEditorClicked(object editor, object? item)
         {
-            var template = Items[0];
-            var editor = new ScriptEditorWindow(template.Template, SyntaxLanguage.HTML);
+            var template = item as DataModelTemplate;
+
+            var edtControl = editor as TextBoxEditorControl;
+            var col = edtControl.ColumnName;
+
+            var toEdit = CoreUtils.GetPropertyValue(template, col);
+
+            var edt = new ScriptEditorWindow(toEdit as string, SyntaxLanguage.HTML);
 
             var snippets = new Dictionary<string, string[]>();
             var tables = Model.AsDictionary;
@@ -65,18 +72,13 @@ namespace PRSDesktop
                     cursnippets.Add("{{ " + variable + "." + prop.Name + " }}");
                 snippets[name] = cursnippets.ToArray();
             }
-            editor.Snippets = snippets;
-            if (editor.ShowDialog() == true)
+            edt.Snippets = snippets;
+            if (edt.ShowDialog() == true)
             {
-                template.Template = editor.Script;
+                CoreUtils.SetPropertyValue(template, col, edt.Script);
             }
         }
 
-        private DataModel EmailTemplateManagerWindow_OnGetVariables()
-        {
-            return Model;
-        }
-
         public DataModel Model { get; set; }
 
         protected override void Reload(Filters<DataModelTemplate> criteria, Columns<DataModelTemplate> columns, ref SortOrder<DataModelTemplate> sort,

+ 17 - 12
prs.desktop/MainWindow.xaml.cs

@@ -70,6 +70,7 @@ using System.Diagnostics.CodeAnalysis;
 using System.Runtime.InteropServices;
 using FastReport.Export.Email;
 using InABox.Wpf;
+using javax.xml.crypto;
 
 namespace PRSDesktop
 {
@@ -1827,18 +1828,7 @@ namespace PRSDesktop
                         var chosenrow = ((MenuItem)o).Tag as CoreRow;
                         try
                         {
-                            var to = chosenrow.Get<DataModelTemplate, string>(x => x.To);
-                            var CC = chosenrow.Get<DataModelTemplate, string>(x => x.CC);
-                            var BCC = chosenrow.Get<DataModelTemplate, string>(x => x.BCC);
-                            var Subject = chosenrow.Get<DataModelTemplate, string>(x => x.Subject);
-                            attachmentName = chosenrow.Get<DataModelTemplate, string>(x => x.AttachmentName);
-                            var template = chosenrow.Get<DataModelTemplate, string>(x => x.Template);
-
-                            var body = DataModelUtils.ParseTemplate(model, template);
-
-                            if (string.IsNullOrWhiteSpace(attachmentName))
-                                attachmentName = DetermineName(model);
-                            EmailUtils.CreateEMLFile(attachmentName, data, App.EmployeeEmail, Subject, body, to, CC, BCC);
+                            ParseTemplateAndCreateEmail(chosenrow, model, data);
                         }
                         catch (Exception err)
                         {
@@ -1855,6 +1845,21 @@ namespace PRSDesktop
             }                
         }
 
+        private void ParseTemplateAndCreateEmail(CoreRow chosenrow, DataModel model, byte[] data)
+        {
+            var to = chosenrow.Get<DataModelTemplate, string>(x => x.To);
+            var Subject = chosenrow.Get<DataModelTemplate, string>(x => x.Subject);
+            
+            var attachmentName = chosenrow.Get<DataModelTemplate, string>(x => x.AttachmentName);
+            var template = chosenrow.Get<DataModelTemplate, string>(x => x.Template);
+
+            var body = DataModelUtils.ParseTemplate(model, template);
+
+            if (string.IsNullOrWhiteSpace(attachmentName))
+                attachmentName = model.Name;
+            EmailUtils.CreateEMLFile(attachmentName, data, App.EmployeeEmail, Subject, body, to);
+        }
+
         private string DetermineName(DataModel model)
         {
             string title = model.Name;

+ 3 - 3
prs.shared/EmailUtils.cs

@@ -22,9 +22,9 @@ namespace PRS.Shared
         /// <param name="from"></param>
         /// <param name="subject"></param>
         /// <param name="body"></param>
-        public static void CreateEMLFile(string attachmentname, byte[] attachmentdata, string from = "", string subject = "", string body = "", string to = "", string CC = "", string BCC = "")
+        public static void CreateEMLFile(string attachmentname, byte[] attachmentdata, string from = "", string subject = "", string body = "", string to = "")
         {
-            var message = CreateMessage(from, subject, body, to, CC, BCC);
+            var message = CreateMessage(from, subject, body, to);
 
             message = AddAttachment(message, attachmentname, attachmentdata);
 
@@ -83,7 +83,7 @@ namespace PRS.Shared
             Process.Start(new ProcessStartInfo(filename) { UseShellExecute = true });
         }
 
-        private static MailMessage CreateMessage(string from, string subject, string body, string to = "", string CC = "", string BCC = "")
+        private static MailMessage CreateMessage(string from, string subject, string body, string to = "")
         {
             if (string.IsNullOrWhiteSpace(to))
                 to = "example@outlook.com.au";