Ejemplo n.º 1
0
        void SendSurveyAsEmail()
        {
            Log.Information("==============================================");
            Log.Information("=== SURVEY RESPONSE ===");

            var errorMessage = string.Empty;

            try
            {
                var surveyCSV = CurrentSurvey.AsEmail();
                Log.Information($"Attach log file request {AppSettings.LastLogFile}");
                Log.Information($"Attach survey response {surveyCSV}");
                //Log.CloseAndFlush();

                var emailMessenger = CrossMessaging.Current.EmailMessenger;
                if (emailMessenger.CanSendEmailAttachments)
                {
                    // Construct email with attachment on Android.
                    Log.Information("Building message");

                    var email = new EmailMessageBuilder()
                                .To("*****@*****.**")
                                .Subject($"SHOWmndME Survey Response for {AppSettings.ParticipantName}").Body($"{surveyCSV}\n\n\n")
                                //.WithAttachment(AppSettings.LastLogFile, "text/*")
                                .Build();

                    InvokeOnMainThread(() =>
                    {
                        Log.Information("Sending email");
                        emailMessenger.SendEmail(email);
                    });
                }
                else
                {
                    errorMessage = "Your device can't send email attachments.";
                }
            }
            catch (Exception ex)
            {
                errorMessage = ex.Message;
            }


            if (!string.IsNullOrEmpty(errorMessage))
            {
                App.Navigation.ShowError(errorMessage);
            }
            //App.Navigation.ShowAlert(surveyCSV);
        }
Ejemplo n.º 2
0
        private string GenerateChangeSummaryHtml(out bool hasChanges)
        {
            hasChanges = false;

            using (var writer = new StringWriter())
            {
                writer.WriteLine("<html>");
                writer.WriteLine(" <head>");
                writer.WriteLine("  <style>");
                writer.WriteLine("    body, table, p, a, h3 { font-family: Arial, Verdana; font-size: 12px; }");
                writer.WriteLine("    table td { padding: 3px; }");
                writer.WriteLine("    .page { background-color: #666; color: #fff; font-size: 16px; }");
                writer.WriteLine("    .question { background-color: #ededed; font-size: 14px; }");
                writer.WriteLine("  </style>");
                writer.WriteLine(" </head>");

                writer.WriteLine("<body>");

                writer.WriteLine("<table>");
                writer.WriteLine(" <tr><td>Advisor:</td><td>{0}</td></tr>", CurrentUser.DisplayName);
                writer.WriteLine(" <tr><td>Completed:</td><td>{0}</td></tr>", CurrentSurvey.CurrentResponse.CompleteDate.Value.ToString("MMM dd, yyyy @ hh:mm tt"));
                writer.WriteLine(" <tr><td>Last Modified:</td><td>{0}</td></tr>", CurrentSurvey.ModifyDate.ToString("MMM dd, yyyy @ hh:mm tt"));
                writer.WriteLine("</table>");

                if (!string.IsNullOrEmpty(SummaryUrl))
                {
                    writer.WriteLine("<p><a href='{0}'>Click here to view full survey</a></p>", SummaryUrl);
                }

                writer.WriteLine("<h2>Change Summary</h2>");

                writer.WriteLine("<table>");

                if (PreviousSurvey != null)
                {
                    foreach (var page in PreviousSurvey.Pages.Where(p => p.IsVisible && !p.IsSummary))
                    {
                        var sb = new StringBuilder();

                        foreach (var previousQuestion in page.Questions.Where(q => q.IsVisible && q.InputType != InputType.None))
                        {
                            var currentQuestion = CurrentSurvey.GetQuestion(page.PageName, previousQuestion.QuestionName);

                            if (currentQuestion != null)
                            {
                                if (currentQuestion.Answers.Except(previousQuestion.Answers).Any() || previousQuestion.Answers.Except(currentQuestion.Answers).Any())
                                {
                                    sb.AppendFormat("<tr><td colspan='2' class='question'>{0}</td></tr>", currentQuestion.QuestionText);
                                    sb.AppendFormat("<tr><td>Previous Answer(s):</td><td>{0}</td></tr>", previousQuestion.Answers.ToCsv());
                                    sb.AppendFormat("<tr><td>Current Answer(s):</td><td>{0}</td></tr>", currentQuestion.Answers.ToCsv());
                                }
                            }
                        }

                        if (sb.Length > 0)
                        {
                            writer.WriteLine("<tr><td colspan='2' class='page'>{0}</td></tr>", page.PageName);
                            writer.WriteLine(sb.ToString());
                            hasChanges = true;
                        }
                    }
                }
                else
                {
                    writer.WriteLine("<tr><td>Initial completion, no changes to report.</td></tr>");
                }

                writer.WriteLine("  </table>");
                writer.WriteLine(" </body>");
                writer.WriteLine("</html>");

                return(writer.ToString());
            }
        }