コード例 #1
0
ファイル: Program.cs プロジェクト: jrezuke/posttestsservice
        internal static void SendCoordinatorsEmail(SiteInfo si, string path)
        {
            var coordinators = GetStaffForEvent(8, si.Id);

            if (coordinators.Count == 0)
                return;

            //Logger.Info("after GetStaffForEvent");
            var sbBody = new StringBuilder("");
            const string newLine = "<br/>";

            sbBody.Append(newLine);
            sbBody.Append("<h2> Total Staff: " + si.PostTestNextDues.Count + "</h2>");
            sbBody.Append("<h2> Total Staff Post Tests Completed:" + si.StaffCompleted + "</h2>");
            int percent = 0;

            if (si.PostTestNextDues.Count > 0)
                percent = si.StaffCompleted * 100 / si.PostTestNextDues.Count;

            sbBody.Append("<h2> Total % Staff Post Tests Completed:" + percent + "%</h2>");

            if (si.SiteEmailLists.CompetencyMissingList.Count == 0)
                sbBody.Append("<h3>All staff members have completed threir competency tests.</h3>");
            else
            {
                var competencyMissingSortedList = si.SiteEmailLists.CompetencyMissingList.OrderBy(x => x.Name).ToList();
                sbBody.Append("<h3>The following staff members have not completed a competency test.</h3>");

                sbBody.Append("<table style='border-collapse:collapse;' cellpadding='5' border='1'><tr style='background-color:87CEEB'><th>Name</th><th>Role</th><th>Tests Not Completed</th><th>Email</th></tr>");
                foreach (var ptnd in competencyMissingSortedList)
                {
                    var email = "not entered";
                    if (ptnd.Email != null)
                        email = ptnd.Email;

                    var test = "";

                    switch (si.SiteId)
                    {
                        case "01":
                        case "02":
                        case "09":
                        case "13":
                        case "31":
                            if (ptnd.Role == "Nurse")
                            {
                                if (!ptnd.IsVampTested)
                                {
                                    if (test.Length > 0)
                                        test += " and ";
                                    test += "Vamp Jr";
                                }
                            }
                            break;
                        case "14":
                        case "20":
                        case "27":
                            break;
                        case "15":
                        case "18":
                        case "21":
                        case "30":
                        case "33":
                        case "36":
                        case "40":
                        case "43":
                            if (!ptnd.IsNovaStatStripTested)
                                test = "NovaStatStrip ";
                            break;
                        default:
                            if (!ptnd.IsNovaStatStripTested)
                                test = "NovaStatStrip ";
                            if (ptnd.Role == "Nurse")
                            {
                                if (!ptnd.IsVampTested)
                                {
                                    if (test.Length > 0)
                                        test += " and ";
                                    test += "Vamp Jr";
                                }
                            }
                            break;
                    }

                    sbBody.Append("<tr><td>" + ptnd.Name + "</td><td>" + ptnd.Role + "</td><td>" + test +
                                      "</td><td>" + email + "</td></tr>");

                }
                sbBody.Append("</table>");
            }

            //Logger.Info("after si.SiteEmailLists.CompetencyMissingList.Count");

            if (si.SiteEmailLists.EmailMissingList.Count > 0)
            {
                var emailMissingSortedList = si.SiteEmailLists.EmailMissingList.OrderBy(x => x.Name).ToList();
                sbBody.Append("<h3>The following staff members need to have their email address entered into the staff table.</h3>");

                sbBody.Append("<div><table style='border-collapse:collapse;' cellpadding='5' border='1'><tr style='background-color:87CEEB'><th>Name</th><th>Role</th></tr>");
                foreach (var ptnd in emailMissingSortedList)
                {
                    sbBody.Append("<tr><td>" + ptnd.Name + "</td><td>" + ptnd.Role + "</td></tr>");
                }
                sbBody.Append("</table></div>");
            }

            if (si.SiteEmailLists.EmployeeIdMissingList.Count > 0)
            {
                var employeeIdMissingSortedList = si.SiteEmailLists.EmployeeIdMissingList.OrderBy(x => x.Name).ToList();
                sbBody.Append("<h3>The following staff members need to have their employee ID entered into the staff table.</h3>");

                sbBody.Append("<div><table style='border-collapse:collapse;' cellpadding='5' border='1'><tr style='background-color:87CEEB'><th>Name</th><th>Role</th><th>Email</th></tr>");
                foreach (var ptnd in employeeIdMissingSortedList)
                {
                    var email = "not entered";
                    if (ptnd.Email != null)
                        email = ptnd.Email;
                    sbBody.Append("<tr><td>" + ptnd.Name + "</td><td>" + ptnd.Role + "</td><td>" + email + "</td></tr>");
                }
                sbBody.Append("</table></div>");
            }
            //Logger.Info("after si.SiteEmailLists.EmployeeIdMissingList.Count");

            if (si.SiteEmailLists.NewStaffList.Count == 0)
            { }
            else
            {
                var newSortedList = si.SiteEmailLists.NewStaffList.OrderBy(x => x.Name).ToList();
                sbBody.Append("<h3>The following new staff members have not completed their annual post tests.</h3>");

                sbBody.Append("<table style='border-collapse:collapse;' cellpadding='5' border='1'><tr style='background-color:87CEEB'><th>Name</th><th>Role</th><th>Email</th></tr>");
                foreach (var ptnd in newSortedList)
                {
                    sbBody.Append("<tr><td>" + ptnd.Name + "</td><td>" + ptnd.Role + "</td><td>" + ptnd.Email +
                                  "</td></tr>");
                }
                sbBody.Append("</table>");
            }
            //Logger.Info("after (si.SiteEmailLists.NewStaffList.Count");

            if (si.SiteEmailLists.ExpiredList.Count == 0)
            { }
            else
            {
                var expiredSortedList = si.SiteEmailLists.ExpiredList.OrderBy(x => x.Name).ToList();
                //Logger.Info("after var expiredSortedList");

                sbBody.Append("<h3>The following expired staff members have not completed their annual post tests.</h3>");

                sbBody.Append("<table style='border-collapse:collapse;' cellpadding='5' border='1'><tr style='background-color:87CEEB'><th>Name</th><th>Role</th><th>Due Date</th><th>Email</th></tr>");

                try
                {
                    foreach (var ptnd in expiredSortedList)
                    {
                        //Logger.Info("in foreach (var ptnd in expiredSortedList)");
                        //Debug.Assert(ptnd.NextDueDate != null, "ptnd.NextDueDate != null");
                        if (ptnd.NextDueDate != null)
                            sbBody.Append("<tr><td>" + ptnd.Name + "</td><td>" + ptnd.Role + "</td><td>" +
                                          ptnd.NextDueDate.Value.ToShortDateString() + "</td><td>" + ptnd.Email +
                                          "</td></tr>");
                    }
                }
                catch (Exception ex)
                {
                    Console.Write(ex.Message);
                }
                //Logger.Info("after foreach (var ptnd in expiredSortedList)");
                sbBody.Append("</table>");
            }
            //Logger.Info("after si.SiteEmailLists.ExpiredList.Count");

            if (si.SiteEmailLists.DueList.Count == 0)
                sbBody.Append("<h3>There are no staff members due to take their annual post tests.</h3>");
            else
            {
                var dueSortedList = si.SiteEmailLists.DueList.OrderBy(x => x.Name).ToList();
                sbBody.Append("<h3>The following staff members are due to take their annual post tests.</h3>");

                sbBody.Append("<table style='border-collapse:collapse;' cellpadding='5' border='1'><tr style='background-color:87CEEB'><th>Name</th><th>Role</th><th>Due Date</th><th>Email</th></tr>");
                foreach (var ptnd in dueSortedList)
                {
                    Debug.Assert(ptnd.NextDueDate != null, "ptnd.NextDueDate != null");
                    if (ptnd.NextDueDate != null)
                        sbBody.Append("<tr><td>" + ptnd.Name + "</td><td>" + ptnd.Role + "</td><td>" + ptnd.NextDueDate.Value.ToShortDateString() + "</td><td>" + ptnd.Email +
                                      "</td></tr>");
                }
                sbBody.Append("</table>");
            }
            //Logger.Info("after si.SiteEmailLists.DueList.Count");

            if (si.SiteEmailLists.StaffTestsNotCompletedList.Count > 0)
            {
                var notCompletedSortedList = si.SiteEmailLists.StaffTestsNotCompletedList.OrderBy(x => x.StaffName).ToList();
                sbBody.Append("<h3>The following staff members have not completed all post tests.</h3>");

                //sbBody.Append("<div><table style='border-collapse:collapse;' cellpadding='5' border='1';><tr style='background-color:87CEEB'><th>Name</th><th>Role</th><th>Email</th><th>Tests Not Completed</th><th>Tests Completed</th></tr>");
                sbBody.Append("<div><table style='border-collapse:collapse;' cellpadding='5' border='1';><tr style='background-color:87CEEB'><th>Name</th><th>Role</th><th>Email</th><th>Tests Not Completed</th></tr>");
                foreach (var tncl in notCompletedSortedList)
                {
                    if (tncl.TestsNotCompleted.Count == 0)
                        continue;

                    //sbBody.Append("<div>");
                    var email = "not entered";
                    if (tncl.Email != null)
                        email = tncl.Email;

                    sbBody.Append("<tr><td>" + tncl.StaffName + "</td><td>" + tncl.Role + "</td><td>" + email + "</td><td>");

                    foreach (var test in tncl.TestsNotCompleted)
                    {
                        sbBody.Append(test + newLine);
                    }
                    sbBody.Append("</td></tr>");

                }
                sbBody.Append("</table></div>");
                //Logger.Info("after si.SiteEmailLists.StaffTestsNotCompletedList.Count");
            }

            SendHtmlEmail("Post Tests Notifications - " + si.Name, coordinators.ToArray(), null, sbBody.ToString(), path, @"<a href='http://halfpintstudy.org/hpProd/'>Halfpint Study Website</a>");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: jrezuke/posttestsservice
        static List<SiteInfo> GetSites()
        {
            var sil = new List<SiteInfo>();

            String strConn = ConfigurationManager.ConnectionStrings["Halfpint"].ToString();
            SqlDataReader rdr = null;
            using (var conn = new SqlConnection(strConn))
            {
                try
                {
                    var cmd = new SqlCommand("", conn) { CommandType = CommandType.StoredProcedure, CommandText = "GetSitesActive" };

                    conn.Open();
                    rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        var si = new SiteInfo();
                        var pos = rdr.GetOrdinal("ID");
                        si.Id = rdr.GetInt32(pos);
                        pos = rdr.GetOrdinal("Name");
                        si.Name = rdr.GetString(pos);
                        pos = rdr.GetOrdinal("SiteID");
                        si.SiteId = rdr.GetString(pos);
                        pos = rdr.GetOrdinal("EmpIDRequired");
                        si.EmpIdRequired = rdr.GetBoolean(pos);
                        sil.Add(si);
                    }
                    rdr.Close();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                }
                finally
                {
                    if (rdr != null)
                        rdr.Close();
                }
            }
            return sil;
        }