Bladeren bron

PRS DESKTOP - email template system

Nick-PRSDigital@bitbucket.org 2 jaren geleden
bovenliggende
commit
6dc6573a0d

+ 1 - 1
prs.classes/Entities/Job/Requisitions/JobRequisition.cs

@@ -8,7 +8,7 @@ namespace Comal.Classes
     public class JobRequisition : Entity, IRemotable, IPersistent, INumericAutoIncrement<JobRequisition>, IJobMaterialRequisition,
         ILicense<ProjectManagementLicense>
     {
-        [IntegerEditor(Visible = Visible.Default, Editable = Editable.Disabled)]
+        [NullEditor]
         [EntityRelationship(DeleteAction.Cascade)]
         public JobLink Job { get; set; }
         

+ 5 - 2
prs.classes/Entities/Job/Requisitions/JobRequisitionItem.cs

@@ -30,7 +30,7 @@ namespace Comal.Classes
     [Caption("Items")]
     [UserTracking(typeof(Job))]
     public class JobRequisitionItem : StockEntity, IRemotable, IPersistent, IOneToMany<JobRequisition>, 
-        ILicense<ProjectManagementLicense>, IJobMaterial
+        ILicense<ProjectManagementLicense>, IJobMaterial, ISequenceable
     {        
         [EntityRelationship(DeleteAction.Cascade)]
         public JobLink Job { get; set; }
@@ -72,9 +72,12 @@ namespace Comal.Classes
         [EnumLookupEditor(typeof(JobRequisitionItemStatus))]      
         public JobRequisitionItemStatus Status { get; set; }
 
-        [IntegerEditor(Visible = Visible.Default, Editable = Editable.Disabled)] //currently no way to disable editor but we need the columns
+        [NullEditor(Visible = Visible.Optional)] //currently no way to disable editor but we need the columns
         public PurchaseOrderItemLink PurchaseOrderItem { get; set; }
 
+        [NullEditor]
+        public long Sequence { get; set; }
+
         protected override void Init()
         {
             base.Init();

+ 12 - 9
prs.desktop/Grids/DataModelTemplateGrid.cs

@@ -14,6 +14,7 @@ namespace PRSDesktop
     public class DataModelTemplateGrid : DynamicDataGrid<DataModelTemplate>
     {
         private readonly BitmapImage _edit = PRSDesktop.Resources.pencil.AsBitmapImage();
+        private DataModelTemplate[] Items;
 
         public DataModelTemplateGrid()
         {
@@ -27,24 +28,25 @@ namespace PRSDesktop
             if (editor == null)
                 return;
 
-            if (column.ColumnName.Equals("To") || 
+            if (column.ColumnName.Equals("To") ||
                 column.ColumnName.Equals("CC") ||
                 column.ColumnName.Equals("BCC") ||
                 column.ColumnName.Equals("Subject") ||
                 column.ColumnName.Equals("AttachmentName")
                 )
                 (editor as ExpressionEditor).OnGetVariables += EmailTemplateManagerWindow_OnGetVariables;
-
-            //else if (column.ColumnName.Equals("Template") && items.Count() == 1)
-            //    (editor as ScriptEditor).OnScriptEditorCalled += () =>
-            //    {
-            //        EditTemplate(items);
-            //    };
+            else if (column.ColumnName.Equals("Template") && items.Count() == 1)
+            {
+                var edt = editor as ScriptEditor;
+                edt.Type = ScriptEditorType.TemplateEditor;
+                Items = items;
+                edt.OnEditorClicked += Edt_OnEditorClicked;
+            }               
         }
 
-        private void EditTemplate(DataModelTemplate[] items)
+        private void Edt_OnEditorClicked()
         {
-            var template = items[0];
+            var template = Items[0];
             var editor = new ScriptEditorWindow(template.Template, SyntaxLanguage.HTML);
 
             var snippets = new Dictionary<string, string[]>();
@@ -87,6 +89,7 @@ namespace PRSDesktop
         protected override DataModelTemplate CreateItem()
         {
             var result = base.CreateItem();
+            result.Visible = true;
             result.Model = Model.Name;
             return result;
         }

+ 42 - 36
prs.desktop/MainWindow.xaml.cs

@@ -1810,43 +1810,49 @@ namespace PRSDesktop
         {
             string attachmentName = DetermineName(model);
 
-            //this section is meant to be for parsing templates into emails - not working yet!
-
-            //var templates = new Client<DataModelTemplate>().Query(new Filter<DataModelTemplate>(x => x.Model).IsEqualTo(model.Name));
-            //if (templates.Rows.Any())
-            //{
-            //    var context = new ContextMenu();
-            //    foreach (var row in templates.Rows)
-            //    {
-            //        var menu = new MenuItem
-            //        {
-            //            Header = row.Get<DataModelTemplate, string>(x => x.Name),
-            //            Tag = row
-            //        };
-            //        menu.Click += (o, args) =>
-            //        {
-            //            var chosenrow = ((MenuItem)o).Tag as CoreRow;                       
-            //            try
-            //            {
-            //                var data = chosenrow.Get<DataModelTemplate, string>(x => x.Template);
-            //                var to = chosenrow.Get<DataModelTemplate, string>(x => x.To);
-
-            //                var body = DataModelUtils.ParseTemplate(model, data);
-
-            //            }
-            //            catch (Exception err)
-            //            {
-            //                MessageBox.Show("Unable to Parse Template!\n\n" + err.Message);
-            //            }
-            //        };
-            //        context.Items.Add(menu);
-            //    }
-            //    context.IsOpen = true;
-            //}
-            //else
-            //{              
+            var templates = new Client<DataModelTemplate>().Query(new Filter<DataModelTemplate>(x => x.Model).IsEqualTo(model.Name)
+                .And(x => x.Visible).IsEqualTo(true));
+            if (templates.Rows.Any())
+            {
+                var context = new ContextMenu();
+                foreach (var row in templates.Rows)
+                {
+                    var menu = new MenuItem
+                    {
+                        Header = row.Get<DataModelTemplate, string>(x => x.Name),
+                        Tag = row
+                    };
+                    menu.Click += (o, args) =>
+                    {
+                        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);
+                        }
+                        catch (Exception err)
+                        {
+                            MessageBox.Show("Unable to Parse Template!\n\n" + err.Message);
+                        }
+                    };
+                    context.Items.Add(menu);
+                }
+                context.IsOpen = true;
+            }
+            else
+            {
                 EmailUtils.CreateEMLFile(attachmentName, data, App.EmployeeEmail, "Emailing report for " + attachmentName);
-            //}                
+            }                
         }
 
         private string DetermineName(DataModel model)

+ 1 - 1
prs.server/Forms/DatabaseScripts/DatabaseScriptGrid.cs

@@ -5,7 +5,7 @@ using InABox.Clients;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.WPF;
-using ScriptEditor = InABox.DynamicGrid.ScriptEditor;
+using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
 
 namespace PRSServer.Formd.DatabaseScripts
 {

+ 1 - 1
prs.server/Forms/ScheduledScripts/ScheduledScriptsGrid.cs

@@ -14,7 +14,7 @@ using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Media.Imaging;
 using static System.Windows.Forms.VisualStyles.VisualStyleElement.TrackBar;
-using ScriptEditor = InABox.DynamicGrid.ScriptEditor;
+using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
 
 namespace PRSServer
 {

+ 1 - 1
prs.server/Forms/WebStyles/WebStyleGrid.cs

@@ -4,7 +4,7 @@ using Comal.Classes;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.WPF;
-using ScriptEditor = InABox.DynamicGrid.ScriptEditor;
+using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
 
 namespace PRSServer.Forms.WebStyles
 {

+ 6 - 6
prs.server/Forms/WebTemplates/WebTemplateGrid.cs

@@ -1,12 +1,12 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Threading.Tasks;
-using Comal.Classes;
+using Comal.Classes;
 using InABox.Core;
 using InABox.DynamicGrid;
 using InABox.WPF;
-using ScriptEditor = InABox.DynamicGrid.ScriptEditor;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Threading.Tasks;
+using ScriptEditor = InABox.DynamicGrid.ScriptEditorWindow;
 
 namespace PRSServer.Forms.WebTemplates
 {

+ 11 - 7
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 = "")
+        public static void CreateEMLFile(string attachmentname, byte[] attachmentdata, string from = "", string subject = "", string body = "", string to = "", string CC = "", string BCC = "")
         {
-            var message = CreateMessage(from, subject, body);
+            var message = CreateMessage(from, subject, body, to, CC, BCC);
 
             message = AddAttachment(message, attachmentname, attachmentdata);
 
@@ -83,15 +83,19 @@ namespace PRS.Shared
             Process.Start(new ProcessStartInfo(filename) { UseShellExecute = true });
         }
 
-        private static MailMessage CreateMessage(string from, string subject, string body)
+        private static MailMessage CreateMessage(string from, string subject, string body, string to = "", string CC = "", string BCC = "")
         {
-            var message = new MailMessage();
+            if (string.IsNullOrWhiteSpace(to))
+                to = "example@outlook.com.au";
             if (string.IsNullOrWhiteSpace(from))
                 from = GetAddressFromUser();
-            message.From = new MailAddress(from);
-            message.Subject = subject;
+            if (string.IsNullOrWhiteSpace(subject))
+                subject = "Enter subject";
+            if (string.IsNullOrWhiteSpace(body))
+                body = "Enter message";
+            var message = new MailMessage(from, to, subject, body);                  
             message.IsBodyHtml = true;
-            message.Body = body;
+
             return message;
         }