private void SendNotifications()
 {
     //Send thank you letter
     if (Master.EmailPINRow != null)
     {
         SurveyTools.SendNotifications(
             Server,
             Master.PropertyShortCode,
             SharedClasses.SurveyType.GEI,
             NotificationReason.ThankYou,
             string.Empty,
             new
         {
             CasinoName       = PropertyTools.GetCasinoName((int)Master.PropertyShortCode),
             FeedbackNoteHTML = String.Empty,
             FeedbackNoteTXT  = String.Empty,
             Attachments      = new SurveyTools.SurveyAttachmentDetails[] {
                 new SurveyTools.SurveyAttachmentDetails()
                 {
                     Path = "~/Images/headers/" + PropertyTools.GetCasinoHeaderImage(Master.PropertyShortCode), ContentID = "HeaderImage"
                 }
             }
         },
             Master.EmailPINRow["EmailAddress"].ToString());
     }
 }
        private void SendNotifications(int surveyID)
        {
            //Add the feedback
            SQLDatabase  sql = new SQLDatabase();    sql.CommandTimeout = 120;
            SqlParameter feedbackUIDParam = new SqlParameter("@UID", System.Data.SqlDbType.UniqueIdentifier);

            feedbackUIDParam.Direction = System.Data.ParameterDirection.Output;

            sql.ExecStoredProcedureDataSet("spFeedback_Create",
                                           new SQLParamList()
                                           .Add("@PropertyID", (int)Master.PropertyShortCode)
                                           .Add("@SurveyTypeID", (int)SurveyType.Donation)
                                           .Add("@RecordID", surveyID)
                                           .Add("@ReasonID", (int)NotificationReason.SponsorshipRequest)
                                           .Add(feedbackUIDParam)
                                           );

            //Notify the location
            SurveyTools.SendNotifications(
                Server,
                Master.PropertyShortCode,
                SharedClasses.SurveyType.Donation,
                NotificationReason.SponsorshipRequest,
                string.Empty,
                new
            {
                Date         = DateTime.Now.ToString("yyyy-MM-dd"),
                CasinoName   = Master.CasinoName,
                FeedbackLink = GCCPortalUrl + "Admin/Feedback/" + feedbackUIDParam.Value.ToString(),
                Link         = GCCPortalUrl + "Display/Donation/" + surveyID
            });
        }
        private void MessageTimeline_OnReply(TextBox textBox, MessageManager mm)
        {
            //Prevent refresh from re-submitting form data
            if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
            {
                Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
            }
            else
            {
                //Catch refresh and wipe the value again
                Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
                textBox.Text            = String.Empty;
                return;
            }
            MessageTimeline.NoteTabActive = false;
            if (!String.IsNullOrWhiteSpace(textBox.Text.Trim()))
            {
                SQLDatabase sql  = new SQLDatabase();    sql.CommandTimeout = 120;
                int         rows = sql.NonQuery(@"	INSERT INTO [tblFeedbackEvents]  ( [FeedbackID], [FeedbackEventTypeID], [IsFromPlayer], [DateCreated], [Message], [NewStatusValue], [StaffMemberID] )
											VALUES ( ( SELECT FeedbackID FROM [tblFeedbackRequests] WHERE [UID] = @UID ), 2, 0, GETDATE(), @Message, NULL, @UserID);"                                            ,
                                                new SQLParamList()
                                                .Add("@Message", textBox.Text.Trim())
                                                .Add("@UID", GUID)
                                                .Add("@UserID", User.UserID));
                if (!sql.HasError && rows == 1)
                {
                    SurveyTools.SendFeedbackNotifications(Server, GUID, true);
                    mm.SuccessMessage = "Reply sent!";
                    textBox.Text      = String.Empty;
                    int feedbackStatus = sql.QueryScalarValue <int>("SELECT [FeedbackStatusID] FROM [tblFeedbackRequests] WHERE [UID] = @UID", new SQLParamList().Add("@UID", GUID));
                    if (feedbackStatus == (int)FeedbackStatus.Open)
                    {
                        sql.ExecStoredProcedureDataTable("spFeedback_ChangeStatus",
                                                         new SQLParamList()
                                                         .Add("@UID", GUID)
                                                         .Add("@FeedbackStatusID", (int)FeedbackStatus.AwaitingGuestResponse)
                                                         .Add("@IsFromPlayer", false)
                                                         .Add("@UserID", User.UserID));
                    }
                }
                else
                {
                    mm.ErrorMessage = "Oops! It looks like something went wrong. Please check the timeline and verify that the message was added.";
                }
            }
            else
            {
                mm.ErrorMessage = "Please enter something into the message box.";
            }
        }
        protected bool SaveData(out int rowID)
        {
            StringBuilder columnList = new StringBuilder();
            SQLParamList  sqlParams  = new SQLParamList();

            fbkEmail.PrepareQuestionForDB(columnList, sqlParams);
            fbkProperty.PrepareQuestionForDB(columnList, sqlParams);
            radGAG_Everett.PrepareQuestionForDB(columnList, sqlParams);
            radGAG_Lakewood.PrepareQuestionForDB(columnList, sqlParams);
            radGAG_Tukwila.PrepareQuestionForDB(columnList, sqlParams);
            radGAG_DeMoines.PrepareQuestionForDB(columnList, sqlParams);
            fbkQ1.PrepareQuestionForDB(columnList, sqlParams);
            fbkQ2.PrepareQuestionForDB(columnList, sqlParams);
            fbkQ3.PrepareQuestionForDB(columnList, sqlParams);
            fbkQ4.PrepareQuestionForDB(columnList, sqlParams);
            fbkQ5.PrepareQuestionForDB(columnList, sqlParams);
            txtName.PrepareQuestionForDB(columnList, sqlParams);
            txtTelephoneNumber.PrepareQuestionForDB(columnList, sqlParams);
            txtEmailContact.PrepareQuestionForDB(columnList, sqlParams);
            // fbkDirectQuestion.PrepareQuestionForDB(columnList, sqlParams);

            columnList.Append(",[PropertyID],[DateEntered]");
            sqlParams.Add("@PropertyID", Master.PropertyID)
            .Add("@DateEntered", DateTime.Now);

            if (IsStaffSurvey)
            {
                columnList.Append(",[StaffMemberID]");
                sqlParams.Add("@StaffMemberID", User.UserID);
                ddlStaffContact.PrepareQuestionForDB(columnList, sqlParams);
            }

            columnList.Remove(0, 1);
            SQLDatabase sql = new SQLDatabase();    sql.CommandTimeout = 120;

            rowID = sql.QueryAndReturnIdentity(String.Format("INSERT INTO [tblSurveyFeedback] ({0}) VALUES ({1});", columnList, columnList.ToString().Replace("[", "@").Replace("]", String.Empty)), sqlParams);
            if (!sql.HasError && rowID != -1)
            {
                Dictionary <string, int> wordCounts = SurveyTools.GetWordCount(fbkQ3.Text);
                SurveyTools.SaveWordCounts(SharedClasses.SurveyType.Feedback, rowID, wordCounts);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public GCCPropertyShortCode PropertyShortCodeOverride()
        {
            switch (SurveyType)
            {
            case GSEISurveyType.HP:
                if (SurveyTools.GetValue(radLocation_EC, false, false))
                {
                    return(GCCPropertyShortCode.ECS);
                }
                else if (SurveyTools.GetValue(radLocation_HA, false, false))
                {
                    return(GCCPropertyShortCode.HA);
                }
                else
                {
                    return(Master.OriginalPropertyShortCode);
                }

            case GSEISurveyType.TM:
                if (SurveyTools.GetValue(radLocation_RR, false, false))
                {
                    return(GCCPropertyShortCode.RR);
                }
                else if (SurveyTools.GetValue(radLocation_HRCV, false, false))
                {
                    return(GCCPropertyShortCode.HRCV);
                }
                else
                {
                    return(Master.OriginalPropertyShortCode);
                }

            case GSEISurveyType.GA:
                return(GCCPropertyShortCode.GAG);

            default:
                return(Master.OriginalPropertyShortCode);
            }
        }
        /// <summary>
        /// Validates and saves a page's values. Returns true if the page is valid.
        /// </summary>
        /// <param name="page">The page ID to check.</param>
        /// <param name="currentPage">Whether this is the current page. If true, the values in the controls will be checked, otherwise the session will be checked.</param>
        /// <param name="saveOnly">If save only is true, the validation will be ignored and values will be saved so that they can be returned to. This is for use with the "Back" button.</param>
        protected bool ValidateAndSave(int page, bool currentPage, bool saveOnly)
        {
            bool retVal = true;

            switch (page)
            {
            case 1:

                #region Page 1

                if (!saveOnly)
                {
                    bool accept  = SurveyTools.GetValue(radAccept, currentPage, false);
                    bool decline = SurveyTools.GetValue(radDecline, currentPage, false);
                    if (!accept && !decline)
                    {
                        mmAcceptGroup.ErrorMessage = "Please select one of the following options.";
                        return(false);
                    }
                }
                if (currentPage)
                {
                    SurveyTools.SaveRadioButtons(radAccept, radDecline);
                }
                break;

                #endregion Page 1

            case 2:

                #region Page 2

                if (!saveOnly)
                {
                    if (SurveyType == GSEISurveyType.HP)
                    {
                        if (!SurveyTools.GetValue(radLocation_EC, currentPage, false) &&
                            !SurveyTools.GetValue(radLocation_HA, currentPage, false) &&
                            !SurveyTools.GetValue(radLocation_None, currentPage, false))
                        {
                            radLocation_EC.MessageManager.ErrorMessage = "Please select one of the following options.";
                            retVal = false;
                        }
                    }
                    else if (SurveyType == GSEISurveyType.TM)
                    {
                        if (!SurveyTools.GetValue(radLocation_RR, currentPage, false) &&
                            !SurveyTools.GetValue(radLocation_HRCV, currentPage, false) &&
                            !SurveyTools.GetValue(radLocation_None2, currentPage, false))
                        {
                            radLocation_RR.MessageManager.ErrorMessage = "Please select one of the following options.";
                            retVal = false;
                        }
                    }
                    else if (SurveyType == GSEISurveyType.GA)
                    {
                        if (!SurveyTools.GetValue(radLocation_Lakewood, currentPage, false) &&
                            !SurveyTools.GetValue(radLocation_Tukwila, currentPage, false) &&
                            !SurveyTools.GetValue(radLocation_Everett, currentPage, false) &&
                            !SurveyTools.GetValue(radLocation_DeMoines, currentPage, false) &&
                            !SurveyTools.GetValue(radLocation_None3, currentPage, false))
                        {
                            radLocation_Lakewood.MessageManager.ErrorMessage = "Please select one of the following options.";
                            retVal = false;
                        }
                    }
                }
                if (currentPage)
                {
                    if (SurveyType == GSEISurveyType.HP)
                    {
                        SurveyTools.SaveRadioButtons(radLocation_EC, radLocation_HA, radLocation_None);
                    }
                    else if (SurveyType == GSEISurveyType.TM)
                    {
                        SurveyTools.SaveRadioButtons(radLocation_RR, radLocation_HRCV, radLocation_None2);
                    }
                    else if (SurveyType == GSEISurveyType.GA)
                    {
                        SurveyTools.SaveRadioButtons(radLocation_Lakewood, radLocation_Tukwila, radLocation_Everett, radLocation_DeMoines, radLocation_None3);
                    }
                }
                break;

                #endregion Page 2

            case 3:                     // Staff

                #region Page 3

                if (!saveOnly)
                {
                    if (!SurveyTools.CheckForAnswer(Q7A, true)
                        | !SurveyTools.CheckForAnswer(Q7B, true)
                        | !SurveyTools.CheckForAnswer(Q7C, true)
                        | !SurveyTools.CheckForAnswer(Q7D, true)
                        | !SurveyTools.CheckForAnswer(Q7E, true)
                        | !SurveyTools.CheckForAnswer(Q7F, true)
                        | !SurveyTools.CheckForAnswer(Q8, true)
                        )
                    {
                        retVal = false;
                    }
                }
                if (currentPage)
                {
                    SurveyTools.SaveValue(Q7A);
                    SurveyTools.SaveValue(Q7B);
                    SurveyTools.SaveValue(Q7C);
                    SurveyTools.SaveValue(Q7D);
                    SurveyTools.SaveValue(Q7E);
                    SurveyTools.SaveValue(Q7F);
                    SurveyTools.SaveValue(Q8);
                }
                break;

                #endregion Page 3

            case 4:                     // Demographics

                #region Page 4

                if (!saveOnly)
                {
                    bool ageGroupNotSelected = !SurveyTools.GetValue(Q37_1, currentPage, false) &&
                                               !SurveyTools.GetValue(Q37_2, currentPage, false) &&
                                               !SurveyTools.GetValue(Q37_3, currentPage, false) &&
                                               !SurveyTools.GetValue(Q37_4, currentPage, false) &&
                                               !SurveyTools.GetValue(Q37_5, currentPage, false) &&
                                               !SurveyTools.GetValue(Q37_6, currentPage, false);
                    //if ( ageGroupNotSelected ) {
                    //    Q37Message.ErrorMessage = "Please answer the following question.";
                    //    retVal = false;
                    //}

                    bool genderNotSelected = !SurveyTools.GetValue(Q36Male, currentPage, false) &&
                                             !SurveyTools.GetValue(Q36Female, currentPage, false);
                    //if ( genderNotSelected ) {
                    //    Q36Message.ErrorMessage = "Please answer the following question.";
                    //    retVal = false;
                    //}

                    if (SurveyType != GSEISurveyType.GA)
                    {
                        bool noneSelected = !SurveyTools.GetValue(radQ1_Slots, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_Tables, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_Poker, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_Food, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_Entertainment, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_Hotel, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_LiveRacing, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_Racebook, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_Bingo, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_Lottery, currentPage, false) &&
                                            !SurveyTools.GetValue(radQ1_None, currentPage, false);

                        if (!saveOnly && noneSelected)
                        {
                            mmQ1.ErrorMessage = "Please select one of the following options.";
                            return(false);
                        }
                    }
                }
                if (currentPage)
                {
                    SurveyTools.SaveRadioButtons(Q37_1, Q37_2, Q37_3, Q37_4, Q37_5, Q37_6);
                    SurveyTools.SaveRadioButtons(Q36Male, Q36Female);
                    if (SurveyType != GSEISurveyType.GA)
                    {
                        SurveyTools.SaveRadioButtons(radQ1_Slots, radQ1_Tables, radQ1_Poker, radQ1_Food, radQ1_Entertainment, radQ1_Hotel, radQ1_LiveRacing, radQ1_Racebook, radQ1_Bingo, radQ1_Lottery, radQ1_None);
                        SurveyTools.SaveValue(chkQ2_Slots);
                        SurveyTools.SaveValue(chkQ2_Tables);
                        SurveyTools.SaveValue(chkQ2_Poker);
                        SurveyTools.SaveValue(chkQ2_Food);
                        SurveyTools.SaveValue(chkQ2_Entertainment);
                        SurveyTools.SaveValue(chkQ2_Hotel);
                        SurveyTools.SaveValue(chkQ2_LiveRacing);
                        SurveyTools.SaveValue(chkQ2_Racebook);
                        SurveyTools.SaveValue(chkQ2_Bingo);
                        SurveyTools.SaveValue(chkQ2_Lottery);
                    }
                }

                break;

                #endregion Page 4
            }
            return(retVal);
        }
 protected bool CheckForAnswer(ISurveyControl <string> control)
 {
     return(SurveyTools.CheckForAnswer(control, QuestionsAreMandatory));
 }
 protected void SaveValue <T>(ISurveyControl <T> control)
 {
     SurveyTools.SaveValue(control);
 }
 protected T GetValue <T>(ISurveyControl <T> control, bool getCurrentValue, T defaultValue)
 {
     return(SurveyTools.GetValue(control, getCurrentValue, defaultValue));
 }
        private void SendNotifications(int surveyID, string feedbackUID)
        {
            string gagLocation = String.Empty;

            if (AlignedPropertyShortCode == GCCPropertyShortCode.GAG)
            {
                if (radGAG_Everett.Checked)
                {
                    gagLocation = "Everett";
                }
                else if (radGAG_Lakewood.Checked)
                {
                    gagLocation = "Lakewood";
                }
                else if (radGAG_Tukwila.Checked)
                {
                    gagLocation = "Tukwila";
                }
                else if (radGAG_DeMoines.Checked)
                {
                    gagLocation = "DeMoines";
                }
                if (gagLocation.Length > 0)
                {
                    gagLocation = " - " + gagLocation;
                }
            }



            // 2018 04 18 Adding notification users for no specific property
            // Adding proper PropertyID for No Specific Property Region Operations

            //if (AlignedPropertyShortCode == GCCPropertyShortCode.GCC && fbkProperty.SelectedIndex == 24)   // No specific Property
            //{


            //    if (Master.PropertyShortCode == GCCPropertyShortCode.GCC)
            //    {
            //        int selectedProp = Conversion.StringToInt(fbkDirectQuestion.SelectedValue, 0);
            //        if (selectedProp != 0)
            //        {
            //            try
            //            {
            //                GCCPropertyShortCode sc = (GCCPropertyShortCode)selectedProp;
            //                NoSpecificPropertyShortCode = sc;
            //            }
            //            catch
            //            {
            //                NoSpecificPropertyShortCode = GCCPropertyShortCode.GCC;
            //            }
            //        }
            //        else
            //        {
            //            NoSpecificPropertyShortCode = GCCPropertyShortCode.GCC;
            //        }
            //    }
            //    else
            //    {
            //        NoSpecificPropertyShortCode = Master.PropertyShortCode;
            //    }



            //  //  AlignedPropertyShortCode = (GCCPropertyShortCode)Convert.ToInt32(fbkDirectQuestion.SelectedValue.ToString());

            //}


            NotificationReason nr = (NotificationReason)fbkQ2.SelectedValue.StringToInt();

            //Send the notification
            SurveyTools.SendNotifications(
                Server,
                AlignedPropertyShortCode,
                SharedClasses.SurveyType.Feedback,
                nr,
                fbkQ3.Text.ToString(),
                new
            {
                Date             = DateTime.Now.ToString("yyyy-MM-dd"),
                CasinoName       = Master.CasinoName + gagLocation,
                FeedbackNoteHTML = String.IsNullOrEmpty(feedbackUID) ? String.Empty : "<p><b>This guest has requested a response.</b> You can view and respond to the feedback request by clicking on (or copying and pasting) the following link:</p>\n<p>" + GCCPortalUrl + "Admin/Feedback/" + feedbackUID + "</p>",
                FeedbackNoteTXT  = String.IsNullOrEmpty(feedbackUID) ? String.Empty : "The guest requested feedback. You can view and respond to the feedback request by clicking on (or copying and pasting) the following link:\n" + GCCPortalUrl + "Admin/Feedback/" + feedbackUID + "\n\n",
                SurveyLink       = GCCPortalUrl + "Display/Feedback/" + surveyID
            },
                String.Empty,
                String.Empty,
                fbkDirectQuestion.SelectedValue.StringToInt(-1)
                );
            //Determine triggers for feedback request
            if (!IsStaffSurvey &&
                !fbkQ5.SelectedValue.Equals("I do not want to be contacted") &&
                !String.IsNullOrEmpty(txtEmailContact.Text))
            {
                //Send thank you letter
                SurveyTools.SendNotifications(
                    Server,
                    AlignedPropertyShortCode,
                    SharedClasses.SurveyType.Feedback,
                    NotificationReason.ThankYou,
                    string.Empty,
                    new
                {
                    CasinoName = PropertyTools.GetCasinoName(Master.PropertyID),

                    Attachments = new SurveyTools.SurveyAttachmentDetails[]
                    {
                        new SurveyTools.SurveyAttachmentDetails()
                        {
                            Path = "~/Images/headers/" + PropertyTools.GetCasinoHeaderImage(AlignedPropertyShortCode), ContentID = "HeaderImage"
                        }
                    }
                },
                    txtEmailContact.Text,
                    String.Empty,
                    fbkDirectQuestion.SelectedValue.StringToInt(-1));
            }
        }
        /// <summary>
        /// Validates and saves a page's values. Returns true if the page is valid.
        /// </summary>
        /// <param name="page">The page ID to check.</param>
        /// <param name="currentPage">Whether this is the current page. If true, the values in the controls will be checked, otherwise the session will be checked.</param>
        /// <param name="saveOnly">If save only is true, the validation will be ignored and values will be saved so that they can be returned to. This is for use with the "Back" button.</param>
        protected bool ValidateAndSave(int page, bool currentPage, bool saveOnly)
        {
            bool retVal = true;

            switch (page)
            {
            case 1:

                #region Page 1

                if (currentPage)
                {
                    SurveyTools.SaveValue <string>(Q1);
                    SurveyTools.SaveValue <string>(Q1);

                    if (Session["CurrentUI"].ToString() == "fr-CA")
                    {
                        SurveyTools.SaveValue <int>(Q2_F);
                    }
                    else
                    {
                        SurveyTools.SaveValue <int>(Q2);
                    }


                    SurveyTools.SaveValue <string>(Q3);
                    SurveyTools.SaveValue <string>(Q4);
                    SurveyTools.SaveValue <string>(Q5Name);
                    SurveyTools.SaveValue <string>(Q5Title);
                    SurveyTools.SaveValue <string>(Q5Telephone);
                    SurveyTools.SaveValue <string>(Q5Email);
                    SurveyTools.SaveValue <string>(Q6Street);
                    SurveyTools.SaveValue <string>(Q6City);
                    SurveyTools.SaveValue <string>(Q6Province);
                    SurveyTools.SaveValue <string>(Q6PostalCode);
                    SurveyTools.SaveValue <string>(Q7);
                    SurveyTools.SaveValue <string>(Q8);
                    SurveyTools.SaveRadioButtons(Q9A, Q9B, Q9C);
                    SurveyTools.SaveValue <string>(Q9C_Explanation);
                    SurveyTools.SaveValue <string>(Q10);
                    SurveyTools.SaveValue <bool>(Q11A_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11A_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11B_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11B_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11C_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11C_CurrentRequest);
                    //SurveyTools.SaveValue<bool>( Q11D_PastSupport );
                    //SurveyTools.SaveValue<bool>( Q11D_CurrentRequest );
                    SurveyTools.SaveValue <bool>(Q11E_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11E_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11F_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11F_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11G_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11G_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11H_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11H_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11I_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11I_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11J_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11J_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11K_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11K_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11L_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11L_CurrentRequest);
                    SurveyTools.SaveValue <bool>(Q11M_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11M_CurrentRequest);

                    //2017-11-14 aDDING 3 NEW LOCATIONS
                    SurveyTools.SaveValue <bool>(Q11N_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11N_CurrentRequest);


                    SurveyTools.SaveValue <bool>(Q11O_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11O_CurrentRequest);


                    SurveyTools.SaveValue <bool>(Q11P_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11P_CurrentRequest);


                    SurveyTools.SaveValue <bool>(Q11Q_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11Q_CurrentRequest);


                    SurveyTools.SaveValue <bool>(Q11R_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11R_CurrentRequest);


                    SurveyTools.SaveValue <bool>(Q11S_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11S_CurrentRequest);


                    SurveyTools.SaveValue <bool>(Q11T_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11T_CurrentRequest);


                    SurveyTools.SaveValue <bool>(Q11U_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11U_CurrentRequest);



                    SurveyTools.SaveValue <bool>(Q11V_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11V_CurrentRequest);

                    SurveyTools.SaveValue <bool>(Q11W_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11W_CurrentRequest);

                    SurveyTools.SaveValue <bool>(Q11X_PastSupport);
                    SurveyTools.SaveValue <bool>(Q11X_CurrentRequest);


                    SurveyTools.SaveValue <string>(Q12);
                    SurveyTools.SaveValue <string>(Q13);
                    SurveyTools.SaveValue <string>(Q14);
                }

                if (!saveOnly)
                {
                    if (!SurveyTools.CheckForAnswer(Q1, true)
                        | !SurveyTools.CheckForAnswer(Q2, true)
                        | !SurveyTools.CheckForAnswer(Q5Name, true)
                        | !SurveyTools.CheckForAnswer(Q5Title, true)
                        | !SurveyTools.CheckForAnswer(Q5Telephone, true)
                        | !SurveyTools.CheckForAnswer(Q5Email, true)
                        | !SurveyTools.CheckForAnswer(Q6Street, true)
                        | !SurveyTools.CheckForAnswer(Q6City, true)
                        | !SurveyTools.CheckForAnswer(Q6Province, true)
                        | !SurveyTools.CheckForAnswer(Q6PostalCode, true)
                        | !SurveyTools.CheckForAnswer(Q7, true)
                        | !SurveyTools.CheckForAnswer(Q10, true)
                        | !SurveyTools.CheckForAnswer(Q13, true)
                        | !SurveyTools.CheckForAnswer(Q14, true)
                        )
                    {
                        retVal = false;
                    }

                    bool noneSelected = !SurveyTools.GetValue(Q9A, currentPage, false) &&
                                        !SurveyTools.GetValue(Q9B, currentPage, false) &&
                                        !SurveyTools.GetValue(Q9C, currentPage, false);
                    if (noneSelected)
                    {
                        mmQ9.ErrorMessage = "Please select one of the following values.";
                        retVal            = false;
                    }

                    string email = SurveyTools.GetValue(Q5Email, currentPage, String.Empty);
                    if (!Validation.RegExCheck(email, ValidationType.Email))
                    {
                        Q5Email.MessageManager.ErrorMessage = "Please enter a valid email address.";
                        return(false);
                    }

                    string postcode = SurveyTools.GetValue(Q6PostalCode, currentPage, String.Empty);
                    if (!Validation.RegExCheck(postcode, ValidationType.Postal))
                    {
                        Q6PostalCode.MessageManager.ErrorMessage = "Please enter a valid postal code in the format 'A1A 1A1'.";
                        return(false);
                    }


                    if (Session["CurrentUI"].ToString() == "fr-CA")
                    {
                        if ((Q2_F.SelectedValue_F == 1 && !SurveyTools.CheckForAnswer(Q3, true)) ||
                            (Q2_F.SelectedValue_F == 0 && !SurveyTools.CheckForAnswer(Q4, true)))
                        {
                            retVal = false;
                        }
                    }
                    else
                    {
                        if ((Q2.SelectedValue == 1 && !SurveyTools.CheckForAnswer(Q3, true)) ||
                            (Q2.SelectedValue == 0 && !SurveyTools.CheckForAnswer(Q4, true)))
                        {
                            retVal = false;
                        }
                    }
                    if (Q9C.Checked && !SurveyTools.CheckForAnswer(Q9C_Explanation, true))
                    {
                        retVal = false;
                    }
                }
                break;

                #endregion Page 1

            case 2:     // Final confirm

                #region Page 2

                break;

                #endregion Page 2
            }
            return(retVal);
        }
        protected void btnSaveTier_Click(object sender, EventArgs e)
        {
            //Prevent refresh from re-submitting form data
            if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
            {
                Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
            }
            else
            {
                //Catch refresh and wipe the value again
                Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
                return;
            }
            //Don't do anything if the tier hasn't changed
            if (ddlTier.SelectedValue.Equals(hdnOldTier.Value))
            {
                return;
            }
            //Update the tier
            SQLDatabase sql = new SQLDatabase();    sql.CommandTimeout = 120;

            sql.ExecStoredProcedureDataTable("spFeedback_ChangeTier",
                                             new SQLParamList()
                                             .Add("@UID", GUID)
                                             .Add("@Tier", Conversion.StringToInt(ddlTier.SelectedValue, 1))
                                             .Add("@UserID", User.UserID));
            //Send tier 3 notifications
            if (ddlTier.SelectedValue.Equals("3"))
            {
                SQLParamList sqlParams = new SQLParamList();
                sqlParams.Add("@GUID", GUID);
                DataSet ds = sql.ExecStoredProcedureDataSet("[spFeedback_GetItem]", sqlParams);
                if (sql.HasError)
                {
                    TopMessage.ErrorMessage = "Unable to load the feedback item.";
                    return;
                }
                DataRow fr = ds.Tables[0].Rows[0];                 //Feedback row
                DataRow sr = ds.Tables[2].Rows[0];                 //Survey row
                GCCPropertyShortCode sc = (GCCPropertyShortCode)fr["PropertyID"].ToString().StringToInt(1);
                SurveyType           st = (SurveyType)fr["SurveyTypeID"].ToString().StringToInt(1);

                //Get the GAG location
                string gagLocation = String.Empty;
                switch (st)
                {
                case SurveyType.GEI:
                    gagLocation = sr["Q3"].ToString();
                    break;

                case SurveyType.Feedback:
                    gagLocation = sr["GAGProperty"].ToString();
                    break;
                }
                if (gagLocation.Length > 0)
                {
                    gagLocation = " - " + gagLocation;
                }

                //Send the notification
                SurveyTools.SendNotifications(Server, sc, SurveyType.Feedback, NotificationReason.Tier3Alert, string.Empty, new {
                    Date         = DateTime.Now.ToString("MMMM dd, yyyy"),
                    CasinoName   = fr["CasinoName"].ToString() + gagLocation,
                    FeedbackLink = GCCPortalUrl + "Admin/Feedback/" + fr["UID"].ToString(),
                    SurveyLink   = String.Format(GCCPortalUrl + "Display/{0}/{1}", st.ToString(), fr["RecordID"])
                });
            }
            if (sql.HasError)
            {
                TopMessage.ErrorMessage = "Oops! It looks like something went wrong trying to change the tier. Please try again. (EFB120)";
            }
        }
        /// <summary>
        /// Validates and saves a page's values. Returns true if the page is valid.
        /// </summary>
        /// <param name="page">The page ID to check.</param>
        /// <param name="currentPage">Whether this is the current page. If true, the values in the controls will be checked, otherwise the session will be checked.</param>
        /// <param name="saveOnly">If save only is true, the validation will be ignored and values will be saved so that they can be returned to. This is for use with the "Back" button.</param>
        protected bool ValidateAndSave(int page, bool currentPage, bool saveOnly)
        {
            bool retVal = true;

            switch (page)
            {
            case 1:

                #region Page 1

                if (currentPage)
                {
                    SurveyTools.SaveValue <string>(fbkEmail);
                    SurveyTools.SaveValue <string>(fbkProperty);
                    SurveyTools.SaveValue <string>(fbkDirectQuestion);
                    if (IsStaffSurvey)
                    {
                        SurveyTools.SaveValue <string>(ddlStaffContact);
                    }
                }
                string email = SurveyTools.GetValue(fbkEmail, currentPage, String.Empty);


                // 20180406 - OLD wants to make this email address optional


                //if (!Validation.RegExCheck(email, ValidationType.Email)
                //    && !(String.IsNullOrWhiteSpace(email) && IsStaffSurvey))
                //{ //Allow blanks on staff survey
                //    mmTrackingEmail.ErrorMessage = "Please enter a valid email address.";
                //    retVal = false;
                //}
                if (Master.PropertyShortCode == GCCPropertyShortCode.GCC && fbkProperty.SelectedIndex == 0)
                {
                    fbkProperty.MessageManager.ErrorMessage = "Please indicate which property you are providing feedback for or select \"No Specific Property\".";
                    retVal = false;
                }

                if (fbkProperty.GetValue() == "1" && fbkDirectQuestion.SelectedIndex == 0)
                {
                    fbkDirectQuestion.MessageManager.ErrorMessage = "Please select which area of operations you are providing feedback for.";
                    retVal = false;
                }
                if (IsStaffSurvey && ddlStaffContact.SelectedIndex == 0)
                {
                    ddlStaffContact.MessageManager.ErrorMessage = "Please indicate how the guest was contacted.";
                    retVal = false;
                }
                break;

                #endregion Page 1

            case 2:                     // Initial question

                #region Page 2

                if (currentPage)
                {
                    SurveyTools.SaveValue <string>(fbkQ1);
                    if (AlignedPropertyShortCode == GCCPropertyShortCode.GAG)
                    {
                        SurveyTools.SaveRadioButtons(radGAG_Everett, radGAG_Lakewood, radGAG_Tukwila, radGAG_DeMoines);
                    }
                }
                if (!saveOnly)
                {
                    bool q3Check = (AlignedPropertyShortCode != GCCPropertyShortCode.GAG) ||
                                   SurveyTools.GetValue(radGAG_Everett, currentPage, false) ||
                                   SurveyTools.GetValue(radGAG_Lakewood, currentPage, false) ||
                                   SurveyTools.GetValue(radGAG_Tukwila, currentPage, false) ||
                                   SurveyTools.GetValue(radGAG_DeMoines, currentPage, false);
                    if (!q3Check)
                    {
                        mmGAG.ErrorMessage = "Please select one of the following options.";
                        retVal             = false;
                    }
                    if (fbkQ1.SelectedIndex == 0)
                    {
                        fbkQ1.MessageManager.ErrorMessage = "Please select an answer.";
                        retVal = false;
                    }
                }
                break;

                #endregion Page 2

            case 3:                     // Basic Form

                #region Page 3

                if (currentPage)
                {
                    SurveyTools.SaveValue <string>(fbkQ2);
                    SurveyTools.SaveValue <string>(fbkQ3);
                    SurveyTools.SaveValue <string>(fbkQ4);
                    SurveyTools.SaveValue <string>(fbkQ5);
                }

                if (!saveOnly)
                {
                    if (fbkQ2.SelectedIndex == 0)
                    {
                        fbkQ2.MessageManager.ErrorMessage = "Please select an answer.";
                        retVal = false;
                    }

                    if (!SurveyTools.CheckForAnswer(fbkQ3, true))
                    {
                        retVal = false;
                    }

                    if (!SurveyTools.CheckForAnswer(fbkQ4, false))
                    {
                        retVal = false;
                    }

                    if (fbkQ5.SelectedIndex == 0)
                    {
                        fbkQ5.MessageManager.ErrorMessage = "Please select an answer.";
                        retVal = false;
                    }
                }

                break;

                #endregion Page 3

            case 4:                     // Contact Info

                #region Page 4

                if (!saveOnly && !fbkQ5.GetValue().Equals("I do not want to be contacted"))
                {
                    //Check for phone or email validation depending on Q5
                    email = SurveyTools.GetValue(txtEmailContact, currentPage, String.Empty);
                    if (fbkQ5.GetValue().Equals("By e-mail") &&
                        (String.IsNullOrEmpty(email) ||
                         !Validation.RegExCheck(email, ValidationType.Email)))
                    {
                        txtEmailContact.MessageManager.ErrorMessage = "Please enter a valid email address.";
                        retVal = false;
                    }
                    if (fbkQ5.GetValue().Equals("By telephone") &&
                        !SurveyTools.CheckForAnswer(txtTelephoneNumber, true))
                    {
                        retVal = false;
                    }

                    if (!SurveyTools.CheckForAnswer(txtName, true))
                    {
                        retVal = false;
                    }
                }
                if (currentPage)
                {
                    SurveyTools.SaveValue <string>(txtName);
                    SurveyTools.SaveValue <string>(txtTelephoneNumber);
                    SurveyTools.SaveValue <string>(txtEmailContact);
                }
                break;

                #endregion Page 4

            case 5:                     // Confirmation

                #region Page 5

                break;

                #endregion Page 5
            }
            return(retVal);
        }
        /// <summary>
        /// Validates and saves a page's values. Returns true if the page is valid.
        /// </summary>
        /// <param name="page">The page ID to check.</param>
        /// <param name="currentPage">Whether this is the current page. If true, the values in the controls will be checked, otherwise the session will be checked.</param>
        /// <param name="saveOnly">If save only is true, the validation will be ignored and values will be saved so that they can be returned to. This is for use with the "Back" button.</param>
        protected bool ValidateAndSave(int page, bool currentPage, bool saveOnly)
        {
            bool retVal = true;

            switch (page)
            {
            case 1:

                #region Page 1

                break;

                #endregion Page 1

            case 2:

                #region Page 2

                if (QueryPropertyShortCode == GCCPropertyShortCode.GCC || (QueryPropertyShortCode == GCCPropertyShortCode.GAG && QueryGAGLocation == GLocation.None))
                {
                    if (currentPage)
                    {
                        SurveyTools.SaveValue(fbkProperty);
                    }
                    if (!saveOnly)
                    {
                        if (fbkProperty.SelectedIndex == 0)
                        {
                            fbkProperty.MessageManager.ErrorMessage = "Please select an answer.";
                            retVal = false;
                        }
                    }
                }
                break;

                #endregion Page 2

            case 3:     // Department

                #region Page 3

                if (currentPage)
                {
                    SurveyTools.SaveValue(ddlDepartment);
                }
                if (!saveOnly)
                {
                    if (ddlDepartment.SelectedIndex == 0)
                    {
                        ddlDepartment.MessageManager.ErrorMessage = "Please select your department.";
                        retVal = false;
                    }
                }
                break;

                #endregion Page 3

            case 4:     // Main survey

                #region Page 4

                if (currentPage)
                {
                    SurveyTools.SaveValue(Q1);
                    SurveyTools.SaveValue(Q2);
                    SurveyTools.SaveValue(Q3);
                    SurveyTools.SaveValue(Q4);
                    SurveyTools.SaveValue(Q5);
                    SurveyTools.SaveValue(Q6);
                    SurveyTools.SaveValue(Q7);
                }
                if (!saveOnly)
                {
                    if (!SurveyTools.CheckForAnswer(Q1, true)
                        | !SurveyTools.CheckForAnswer(Q2, true)
                        | !SurveyTools.CheckForAnswer(Q3, true)
                        | !SurveyTools.CheckForAnswer(Q4, true)
                        | !SurveyTools.CheckForAnswer(Q5, true)
                        | !SurveyTools.CheckForAnswer(Q6, true)
                        | !SurveyTools.CheckForAnswer(Q7, true))
                    {
                        retVal = false;
                    }
                }
                break;

                #endregion Page 4

            case 5:     // Main survey

                #region Page 5

                if (currentPage)
                {
                    SurveyTools.SaveValue(Q8);
                    SurveyTools.SaveValue(Q9);
                    SurveyTools.SaveValue(Q10);
                    SurveyTools.SaveValue(Q11);
                    SurveyTools.SaveValue(Q12);
                    SurveyTools.SaveValue(Q13);
                    SurveyTools.SaveValue(Q14);
                    SurveyTools.SaveValue(Q15);
                    SurveyTools.SaveValue(Q16);
                    SurveyTools.SaveValue(Q17);
                }
                if (!saveOnly)
                {
                    if (!SurveyTools.CheckForAnswer(Q8, true)
                        | !SurveyTools.CheckForAnswer(Q9, true)
                        | !SurveyTools.CheckForAnswer(Q10, true)
                        | !SurveyTools.CheckForAnswer(Q11, true)
                        | !SurveyTools.CheckForAnswer(Q12, true)
                        | !SurveyTools.CheckForAnswer(Q13, true)
                        | !SurveyTools.CheckForAnswer(Q14, true)
                        | !SurveyTools.CheckForAnswer(Q15, true)
                        | !SurveyTools.CheckForAnswer(Q16, true)
                        | !SurveyTools.CheckForAnswer(Q17, true))
                    {
                        retVal = false;
                    }
                }
                break;

                #endregion Page 5

            case 6:     // Main survey

                #region Page 6

                if (currentPage)
                {
                    SurveyTools.SaveValue(Q18);
                    SurveyTools.SaveValue(Q19);
                    SurveyTools.SaveValue(Q20);
                    SurveyTools.SaveValue(Q21);
                    SurveyTools.SaveValue(Q22);
                    SurveyTools.SaveValue(Q23);
                }
                if (!saveOnly)
                {
                    if (!SurveyTools.CheckForAnswer(Q18, true)
                        | !SurveyTools.CheckForAnswer(Q19, true)
                        | !SurveyTools.CheckForAnswer(Q20, true)
                        | !SurveyTools.CheckForAnswer(Q21, true)
                        | !SurveyTools.CheckForAnswer(Q22, true)
                        | !SurveyTools.CheckForAnswer(Q23, true))
                    {
                        retVal = false;
                    }
                }
                break;

                #endregion Page 6

            case 7:     // Main survey

                #region Page 7

                if (currentPage)
                {
                    SurveyTools.SaveValue(Q24);
                    SurveyTools.SaveValue(Q25);
                    SurveyTools.SaveValue(Q26);
                    SurveyTools.SaveValue(Q27);
                    SurveyTools.SaveValue(Q28);
                    SurveyTools.SaveValue(Q29A);
                    SurveyTools.SaveValue(Q29B);
                    SurveyTools.SaveValue(Q29C);
                    SurveyTools.SaveValue(Q30);
                }
                if (!saveOnly)
                {
                    if (!SurveyTools.CheckForAnswer(Q24, true)
                        | !SurveyTools.CheckForAnswer(Q25, true)
                        | !SurveyTools.CheckForAnswer(Q26, true)
                        | !SurveyTools.CheckForAnswer(Q27, true)
                        | !SurveyTools.CheckForAnswer(Q28, true)
                        | !SurveyTools.CheckForAnswer(Q29A, true)
                        | !SurveyTools.CheckForAnswer(Q29B, true)
                        | !SurveyTools.CheckForAnswer(Q29C, true)
                        | !SurveyTools.CheckForAnswer(Q30, true))
                    {
                        retVal = false;
                    }
                }
                break;

                #endregion Page 7

            case 8:     // Demographics

                #region Page 8

                if (currentPage)
                {
                    SurveyTools.SaveRadioButtons(radQ31_Hourly, radQ31_Salary);
                    SurveyTools.SaveRadioButtons(radQ32_1, radQ32_2, radQ32_3, radQ32_4, radQ32_5);
                    SurveyTools.SaveValue(Q33);
                    SurveyTools.SaveValue(chkQ34_1);
                    SurveyTools.SaveValue(chkQ34_2);
                    SurveyTools.SaveValue(chkQ34_3);
                    SurveyTools.SaveValue(chkQ34_4);
                    SurveyTools.SaveValue(chkQ34_5);
                    SurveyTools.SaveValue(chkQ34_6);
                    SurveyTools.SaveValue(chkQ34_7);
                    SurveyTools.SaveValue(chkQ34_8);
                    SurveyTools.SaveValue(chkQ34_9);
                    SurveyTools.SaveValue(chkQ34_10);
                    SurveyTools.SaveValue(chkQ34_11);
                    SurveyTools.SaveValue(chkQ34_12);
                }
                if (!saveOnly)
                {
                    bool payTypeNotSelected = !SurveyTools.GetValue(radQ31_Hourly, currentPage, false) &&
                                              !SurveyTools.GetValue(radQ31_Salary, currentPage, false);

                    if (payTypeNotSelected)
                    {
                        radQ31_Hourly.MessageManager.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }

                    bool tenureNotSelected = !SurveyTools.GetValue(radQ32_1, currentPage, false) &&
                                             !SurveyTools.GetValue(radQ32_2, currentPage, false) &&
                                             !SurveyTools.GetValue(radQ32_3, currentPage, false) &&
                                             !SurveyTools.GetValue(radQ32_4, currentPage, false) &&
                                             !SurveyTools.GetValue(radQ32_5, currentPage, false);
                    if (tenureNotSelected)
                    {
                        radQ32_1.MessageManager.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }
                }
                break;

                #endregion Page 8

            case 9:     // First Final Confirmation

                #region Page 9

                if (currentPage)
                {
                    SurveyTools.SaveRadioButtons(radFFNoThanks, radFFContinue);
                }
                if (!saveOnly)
                {
                    bool continueNotSelected = !SurveyTools.GetValue(radFFNoThanks, currentPage, false) &&
                                               !SurveyTools.GetValue(radFFContinue, currentPage, false);

                    if (continueNotSelected)
                    {
                        radFFNoThanks.MessageManager.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }
                }
                break;

                #endregion Page 9

            case 10:     // CSR

                #region Page 10

                if (radFFContinue.Checked)
                {
                    if (currentPage)
                    {
                        SurveyTools.SaveValue(CSR_Q1);
                        SurveyTools.SaveValue(CSR_Q2);
                        SurveyTools.SaveValue(CSR_Q3);
                        SurveyTools.SaveValue(CSR_Q4);
                        SurveyTools.SaveValue(CSR_Q5_1);
                        SurveyTools.SaveValue(CSR_Q5_2);
                        SurveyTools.SaveValue(CSR_Q5_3);
                        SurveyTools.SaveValue(CSR_Q5_4);
                        SurveyTools.SaveValue(CSR_Q6);
                        SurveyTools.SaveValue(CSR_Q7);
                        SurveyTools.SaveValue(CSR_Q8_1);
                        SurveyTools.SaveValue(CSR_Q8_2);
                        SurveyTools.SaveValue(CSR_Q8_3);
                        SurveyTools.SaveValue(CSR_Q8_4);
                        SurveyTools.SaveValue(CSR_Q8_5);
                        SurveyTools.SaveValue(CSR_Q8_6);
                        SurveyTools.SaveValue(CSR_Q8_7);
                        SurveyTools.SaveValue(CSR_Q8_8);
                        SurveyTools.SaveValue(CSR_Q8_9);
                        SurveyTools.SaveValue(CSR_Q8_OtherExplanation);
                        SurveyTools.SaveValue(CSR_Q9A);
                        SurveyTools.SaveValue(CSR_Q9B);
                        SurveyTools.SaveValue(CSR_Q9C);
                        SurveyTools.SaveValue(CSR_Q9D);
                        SurveyTools.SaveValue(CSR_Q9E);
                        SurveyTools.SaveValue(CSR_Q9F);
                        SurveyTools.SaveValue(CSR_Q9G);
                        SurveyTools.SaveValue(CSR_Q9H);
                        SurveyTools.SaveValue(CSR_Q10A);
                        SurveyTools.SaveValue(CSR_Q10B);
                        SurveyTools.SaveValue(CSR_Q10C);
                        SurveyTools.SaveValue(CSR_Q10D);
                        SurveyTools.SaveValue(CSR_Q10E);
                        SurveyTools.SaveRadioButtons(radCSR_Q11_1, radCSR_Q11_2, radCSR_Q11_3, radCSR_Q11_4);
                        SurveyTools.SaveValue(CSR_Q12);
                        SurveyTools.SaveValue(CSR_Q13);
                    }
                    if (!saveOnly)
                    {
                        if (!SurveyTools.CheckForAnswer(CSR_Q1, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q2, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q3, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q4, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q6, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q7, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q9A, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q9B, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q9C, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q9D, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q9E, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q9F, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q9G, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q9H, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q10A, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q10B, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q10C, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q10D, true)
                            | !SurveyTools.CheckForAnswer(CSR_Q10E, true)
                            | (!(new GCCPropertyShortCode[] { GCCPropertyShortCode.GAG, GCCPropertyShortCode.FL, GCCPropertyShortCode.GD, GCCPropertyShortCode.CNB }).Contains(Master.PropertyShortCode) && !SurveyTools.CheckForAnswer(CSR_Q12, true))
                            )
                        {
                            retVal = false;
                        }
                        bool informedNotSelected = !SurveyTools.GetValue(radCSR_Q11_1, currentPage, false) &&
                                                   !SurveyTools.GetValue(radCSR_Q11_2, currentPage, false) &&
                                                   !SurveyTools.GetValue(radCSR_Q11_3, currentPage, false) &&
                                                   !SurveyTools.GetValue(radCSR_Q11_4, currentPage, false);
                        if (informedNotSelected)
                        {
                            radCSR_Q11_4.MessageManager.ErrorMessage = "Please select one of the following options.";
                            retVal = false;
                        }

                        if (CSR_Q8_9.Checked && String.IsNullOrEmpty(CSR_Q8_OtherExplanation.Text))
                        {
                            CSR_Q8_9.MessageManager.ErrorMessage = "Please explain why you chose \"Other\".";
                            retVal = false;
                        }
                    }
                }
                break;

                #endregion Page 10
            }
            return(retVal);
        }
        /// <summary>
        /// Validates and saves a page's values. Returns true if the page is valid.
        /// </summary>
        /// <param name="page">The page ID to check.</param>
        /// <param name="currentPage">Whether this is the current page. If true, the values in the controls will be checked, otherwise the session will be checked.</param>
        /// <param name="saveOnly">If save only is true, the validation will be ignored and values will be saved so that they can be returned to. This is for use with the "Back" button.</param>
        protected bool ValidateAndSave(int page, bool currentPage, bool saveOnly)
        {
            bool retVal = true;

            switch (page)
            {
            case 1:

                #region Page 1
                string email = GetValue(txtEmail, currentPage, String.Empty);
                if (!Validation.RegExCheck(email, ValidationType.Email))
                {
                    mmTxtEmail.ErrorMessage = "Please enter a valid email address.";
                    return(false);
                }
                else if (currentPage)
                {
                    SaveValue <string>(txtEmail);
                }
                break;

                #endregion Page 1

            case 2:

                #region Page 2
                if (!saveOnly)
                {
                    bool accept  = GetValue(radAccept, currentPage, false);
                    bool decline = GetValue(radDecline, currentPage, false);
                    if (!accept && !decline)
                    {
                        mmAcceptGroup.ErrorMessage = "Please select one of the following options.";
                        return(false);
                    }
                }
                if (currentPage)
                {
                    SurveyTools.SaveRadioButtons(radAccept, radDecline);
                }
                break;

                #endregion Page 2

            case 3:

                #region Page 3
                if (!saveOnly)
                {
                    bool Q1notselected = !GetValue(Q1_1, currentPage, false) &&
                                         !GetValue(Q1_2to4, currentPage, false) &&
                                         !GetValue(Q1_5to9, currentPage, false) &&
                                         !GetValue(Q1_10, currentPage, false);
                    if (Q1notselected)
                    {
                        Q1Message.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }

                    bool Q2notselected = !GetValue(Q2_Yes, currentPage, false) &&
                                         !GetValue(Q2_No, currentPage, false);
                    if (Q2notselected)
                    {
                        Q2Message.ErrorMessage = "Please select one of the following options.";
                    }

                    bool Q3notselected = !GetValue(Q3_No, currentPage, false) &&
                                         !GetValue(Q3_Yes, currentPage, false);
                    if (Q3notselected)
                    {
                        Q3Message.ErrorMessage = "Please select one of the following options.";
                    }

                    bool Q4notselected = !GetValue(Q4_Yes, currentPage, false) &&
                                         !GetValue(Q4_No, currentPage, false);

                    if (Q4notselected)
                    {
                        Q4Message.ErrorMessage = "Please select Yes or No.";
                        retVal = false;
                    }
                }
                if (currentPage)
                {
                    SaveValue(Q1_1);
                    SaveValue(Q1_2to4);
                    SaveValue(Q1_5to9);
                    SaveValue(Q1_10);
                    SaveValue(Q2_No);
                    SaveValue(Q2_Yes);
                    SaveValue(Q3_No);
                    SaveValue(Q3_Yes);
                    SaveValue(Q4_Yes);
                    SaveValue(Q4_No);
                    SaveValue(Q4_EncoreNumber);
                }
                break;

                #endregion Page 3

            case 4:

                #region Page 4
                if (!saveOnly)
                {
                    bool Q5notselected = !GetValue(Q5_Tarmac, currentPage, false) &&
                                         !GetValue(Q5_BoxSeats, currentPage, false) &&
                                         !GetValue(Q5_GroupPatio, currentPage, false) &&
                                         !GetValue(Q5_MarqueeTent, currentPage, false) &&
                                         !GetValue(Q5_SilksBuffet, currentPage, false) &&
                                         !GetValue(Q5_DiamondClub, currentPage, false);
                    if (Q5notselected)
                    {
                        Q5Message.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }

                    bool Q6notselected = !GetValue(Q6_Excellent, currentPage, false) &&
                                         !GetValue(Q6_VeryGood, currentPage, false) &&
                                         !GetValue(Q6_Good, currentPage, false) &&
                                         !GetValue(Q6_Fair, currentPage, false) &&
                                         !GetValue(Q6_Poor, currentPage, false);
                    if (Q6notselected)
                    {
                        Q6Message.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }

                    bool Q7notselected = !GetValue(Q7_Excellent, currentPage, false) &&
                                         !GetValue(Q7_VeryGood, currentPage, false) &&
                                         !GetValue(Q7_Good, currentPage, false) &&
                                         !GetValue(Q7_Fair, currentPage, false) &&
                                         !GetValue(Q7_Poor, currentPage, false);
                    if (Q7notselected)
                    {
                        Q7Message.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }

                    bool Q8notselected = !GetValue(Q8_DefinitelyWould, currentPage, false) &&
                                         !GetValue(Q8_ProbablyWould, currentPage, false) &&
                                         !GetValue(Q8_MightMightNot, currentPage, false) &&
                                         !GetValue(Q8_ProbablyWouldNot, currentPage, false) &&
                                         !GetValue(Q8_DefinitelyWouldNot, currentPage, false);
                    if (Q8notselected)
                    {
                        Q8Message.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }
                }
                if (currentPage)
                {
                    SaveValue(Q5_Tarmac);
                    SaveValue(Q5_BoxSeats);
                    SaveValue(Q5_GroupPatio);
                    SaveValue(Q5_MarqueeTent);
                    SaveValue(Q5_SilksBuffet);
                    SaveValue(Q5_DiamondClub);
                    SaveValue(Q6_Excellent);
                    SaveValue(Q6_VeryGood);
                    SaveValue(Q6_Good);
                    SaveValue(Q6_Fair);
                    SaveValue(Q6_Poor);
                    SaveValue(Q7_Excellent);
                    SaveValue(Q7_VeryGood);
                    SaveValue(Q7_Good);
                    SaveValue(Q7_Fair);
                    SaveValue(Q7_Poor);
                    SaveValue(Q8_DefinitelyWould);
                    SaveValue(Q8_ProbablyWould);
                    SaveValue(Q8_MightMightNot);
                    SaveValue(Q8_ProbablyWouldNot);
                    SaveValue(Q8_DefinitelyWouldNot);
                }
                break;

                #endregion Page 4

            case 5:

                #region Page 5
                if (!saveOnly)
                {
                    bool Q9notselected = !GetValue(Q9_Male, currentPage, false) &&
                                         !GetValue(Q9_Female, currentPage, false);
                    if (Q9notselected)
                    {
                        Q9Message.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }

                    bool Q10notselected = !GetValue(Q10_19to24, currentPage, false) &&
                                          !GetValue(Q10_25to34, currentPage, false) &&
                                          !GetValue(Q10_35to44, currentPage, false) &&
                                          !GetValue(Q10_45to54, currentPage, false) &&
                                          !GetValue(Q10_55to64, currentPage, false) &&
                                          !GetValue(Q10_65orOlder, currentPage, false);
                    if (Q10notselected)
                    {
                        Q10Message.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }

                    bool Q11notselected = !GetValue(Q11_35000, currentPage, false) &&
                                          !GetValue(Q11_35000to59999, currentPage, false) &&
                                          !GetValue(Q11_60000to89999, currentPage, false) &&
                                          !GetValue(Q11_90000, currentPage, false) &&
                                          !GetValue(Q11_NoSay, currentPage, false);
                    if (Q11notselected)
                    {
                        Q10Message.ErrorMessage = "Please select one of the following options.";
                        retVal = false;
                    }

                    bool Q12check = !String.IsNullOrEmpty(GetValue(Q12_PostalCode, currentPage, String.Empty));

                    if (!Q12check)
                    {
                        Q12_PostalCode.MessageManager.ErrorMessage = "Please enter the first 3 digits of your Postal Code.";
                        retVal = false;
                    }

                    bool Q13FirstNameCheck = !String.IsNullOrEmpty(GetValue(Q13_FirstName, currentPage, String.Empty));

                    if (!Q13FirstNameCheck)
                    {
                        Q13_FirstName.MessageManager.ErrorMessage = "Please enter your First Name.";
                        retVal = false;
                    }

                    bool Q13LastNameCheck = !String.IsNullOrEmpty(GetValue(Q13_LastName, currentPage, String.Empty));

                    if (!Q13LastNameCheck)
                    {
                        Q13_LastName.MessageManager.ErrorMessage = "Please enter your Last Name.";
                        retVal = false;
                    }

                    bool Q13EmailCheck = !String.IsNullOrEmpty(GetValue(Q13_Email, currentPage, String.Empty));

                    if (!Q13EmailCheck)
                    {
                        Q13_Email.MessageManager.ErrorMessage = "Please enter your Email Address.";
                        retVal = false;
                    }
                }
                if (currentPage)
                {
                    SaveValue(Q9_Male);
                    SaveValue(Q9_Female);
                    SaveValue(Q10_19to24);
                    SaveValue(Q10_25to34);
                    SaveValue(Q10_35to44);
                    SaveValue(Q10_45to54);
                    SaveValue(Q10_55to64);
                    SaveValue(Q10_65orOlder);
                    SaveValue(Q11_35000);
                    SaveValue(Q11_35000to59999);
                    SaveValue(Q11_60000to89999);
                    SaveValue(Q11_90000);
                    SaveValue(Q11_NoSay);
                    SaveValue(Q12_PostalCode);
                    SaveValue(Q13_FirstName);
                    SaveValue(Q13_LastName);
                    SaveValue(Q13_Email);
                }
                break;

                #endregion Page 5
            }
            return(retVal);
        }
        protected bool SaveData()
        {
            StringBuilder columnList = new StringBuilder();
            SQLParamList  sqlParams  = new SQLParamList();

            if (QueryPropertyShortCode == GCCPropertyShortCode.GCC || (QueryPropertyShortCode == GCCPropertyShortCode.GAG && QueryGAGLocation == GLocation.None))
            {
                //User had to select location
                string propSel = fbkProperty.SelectedValue;
                if (propSel.Length > 3)
                {
                    //GAG
                    if (propSel.Substring(0, 2).Equals("13"))
                    {
                        columnList.AppendFormat(",[{0}]", fbkProperty.DBColumn);
                        sqlParams.Add("@" + fbkProperty.DBColumn, 13);
                    }
                }
                else
                {
                    fbkProperty.PrepareQuestionForDB(columnList, sqlParams);
                }
            }

            ddlDepartment.PrepareQuestionForDB(columnList, sqlParams);
            Q1.PrepareQuestionForDB(columnList, sqlParams);
            Q2.PrepareQuestionForDB(columnList, sqlParams);
            Q3.PrepareQuestionForDB(columnList, sqlParams);
            Q4.PrepareQuestionForDB(columnList, sqlParams);
            Q5.PrepareQuestionForDB(columnList, sqlParams);
            Q6.PrepareQuestionForDB(columnList, sqlParams);
            Q7.PrepareQuestionForDB(columnList, sqlParams);
            Q8.PrepareQuestionForDB(columnList, sqlParams);
            Q9.PrepareQuestionForDB(columnList, sqlParams);
            Q10.PrepareQuestionForDB(columnList, sqlParams);
            Q11.PrepareQuestionForDB(columnList, sqlParams);
            Q12.PrepareQuestionForDB(columnList, sqlParams);
            Q13.PrepareQuestionForDB(columnList, sqlParams);
            Q14.PrepareQuestionForDB(columnList, sqlParams);
            Q15.PrepareQuestionForDB(columnList, sqlParams);
            Q16.PrepareQuestionForDB(columnList, sqlParams);
            Q17.PrepareQuestionForDB(columnList, sqlParams);
            Q18.PrepareQuestionForDB(columnList, sqlParams);
            Q19.PrepareQuestionForDB(columnList, sqlParams);
            Q20.PrepareQuestionForDB(columnList, sqlParams);
            Q21.PrepareQuestionForDB(columnList, sqlParams);
            Q22.PrepareQuestionForDB(columnList, sqlParams);
            Q23.PrepareQuestionForDB(columnList, sqlParams);
            Q24.PrepareQuestionForDB(columnList, sqlParams);
            Q25.PrepareQuestionForDB(columnList, sqlParams);
            Q26.PrepareQuestionForDB(columnList, sqlParams);
            Q27.PrepareQuestionForDB(columnList, sqlParams);
            Q28.PrepareQuestionForDB(columnList, sqlParams);
            Q29A.PrepareQuestionForDB(columnList, sqlParams);
            Q29B.PrepareQuestionForDB(columnList, sqlParams);
            Q29C.PrepareQuestionForDB(columnList, sqlParams);
            Q30.PrepareQuestionForDB(columnList, sqlParams);
            radQ31_Hourly.PrepareQuestionForDB(columnList, sqlParams);
            radQ31_Salary.PrepareQuestionForDB(columnList, sqlParams);
            radQ32_1.PrepareQuestionForDB(columnList, sqlParams);
            radQ32_2.PrepareQuestionForDB(columnList, sqlParams);
            radQ32_3.PrepareQuestionForDB(columnList, sqlParams);
            radQ32_4.PrepareQuestionForDB(columnList, sqlParams);
            radQ32_5.PrepareQuestionForDB(columnList, sqlParams);
            Q33.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_1.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_2.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_3.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_4.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_5.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_6.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_7.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_8.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_9.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_10.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_11.PrepareQuestionForDB(columnList, sqlParams);
            chkQ34_12.PrepareQuestionForDB(columnList, sqlParams);

            if (radFFContinue.Checked)
            {
                CSR_Q1.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q2.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q3.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q4.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q5_1.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q5_2.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q5_3.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q5_4.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q6.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q7.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_1.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_2.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_3.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_4.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_5.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_6.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_7.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_8.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_9.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q8_OtherExplanation.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q9A.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q9B.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q9C.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q9D.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q9E.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q9F.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q9G.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q9H.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q10A.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q10B.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q10C.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q10D.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q10E.PrepareQuestionForDB(columnList, sqlParams);
                radCSR_Q11_1.PrepareQuestionForDB(columnList, sqlParams);
                radCSR_Q11_2.PrepareQuestionForDB(columnList, sqlParams);
                radCSR_Q11_3.PrepareQuestionForDB(columnList, sqlParams);
                radCSR_Q11_4.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q12.PrepareQuestionForDB(columnList, sqlParams);
                CSR_Q13.PrepareQuestionForDB(columnList, sqlParams);
            }

            columnList.Append(",[PropertyID],[DateEntered],[SurveyType]");
            sqlParams.Add("@PropertyID", Master.PropertyID)
            .Add("@DateEntered", DateTime.Now)
            .Add("@SurveyType", IsKioskSurvey ? "K" : "D");
            if (GAGLocation != GLocation.None)
            {
                columnList.Append(",[GAGLocation]");
                sqlParams.Add("@GAGLocation", GAGLocation.ToString());
            }

            columnList.Remove(0, 1);
            SQLDatabase sql   = new SQLDatabase();    sql.CommandTimeout = 120;
            int         rowID = sql.QueryAndReturnIdentity(String.Format("INSERT INTO [tblSurveySnapshot2017] ({0}) VALUES ({1});", columnList, columnList.ToString().Replace("[", "@").Replace("]", String.Empty)), sqlParams);

            if (!sql.HasError && rowID != -1)
            {
                Dictionary <string, int> wordCounts = SurveyTools.GetWordCount(Q33.Text, CSR_Q8_OtherExplanation.Text, CSR_Q13.Text);
                SurveyTools.SaveWordCounts(SharedClasses.SurveyType.Employee, rowID, wordCounts);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 17
0
        public void ProcessRequest(HttpContext context)
        {
            //Only run locally or in the network
            string ip = RequestVars.GetRequestIPv4Address();

            if (!ip.Equals("127.0.0.1") && !ip.StartsWith("172.16.") && !ip.StartsWith("192.168.0."))
            {
                ErrorHandler.WriteLog("GCC_Web_Portal.Jobs", "Job attempted to be run by invalid IP: " + ip, ErrorHandler.ErrorEventID.General);
                return;
            }
            //Get the job ID
            string jobID = RequestVars.Get("jobid", String.Empty);

            switch (jobID)
            {
            case "e07db58b-d3a6-4e01-a5ed-ff9875773b3c":

                #region Send weekly notification email

                DateTime startDate = DateTime.Now.Date.AddDays(-7);
                DateTime endDate   = DateTime.Now.Date.AddMilliseconds(-1);
                //DateTime startDate = new DateTime( 2015, 7, 1 ).Date;
                //DateTime endDate = new DateTime( 2015, 8, 1 ).Date.AddMilliseconds( -1 );
                SQLDatabase sql = new SQLDatabase();    sql.CommandTimeout = 120;
                DataTable   dt  = sql.ExecStoredProcedureDataTable("spJobs_StatusEmail",
                                                                   new SQLParamList()
                                                                   .Add("@DateCreated_Begin", startDate)
                                                                   .Add("@DateCreated_End", endDate));
                StringBuilder sbCurrent = new StringBuilder();
                sbCurrent.AppendFormat(@"<h3 style='margin:20px 0'>GEI / GSEI Dashboard for {0} to {1}</h3><table style='border-collapse:collapse;border:1px solid #444;width:100%' cellspacing='0' cellpadding='0'>", startDate.ToString("MMM d, yyyy"), endDate.ToString("MMM d, yyyy"));
                sbCurrent.AppendFormat("<thead><tr><th{0}></th><th{0}># Surveys</th><th{0}>GEI</th><th{0}>NPS</th><th{0}>PRS</th><th{0}>GSEI</th><th{0}># Followup</th><th{0}>% Followup</th><th{0}># <24h</th><th{0}>#24-48h</th><th{0}># > 48h</th><th{0}>Avg. Response</th></tr></thead>",
                                       " style='padding:5px;border:1px solid #BBB'");
                StringBuilder sbComparison = new StringBuilder("<h3 style='margin:20px 0'>Change from Previous Week</h3><table style='border-collapse:collapse;border:1px solid #444;width:100%' cellspacing='0' cellpadding='0'>");
                sbComparison.AppendFormat("<thead><tr><th{0}></th><th{0}># Surveys</th><th{0}>GEI</th><th{0}>NPS</th><th{0}>PRS</th><th{0}>GSEI</th><th{0}># Followup</th><th{0}>% Followup</th><th{0}># <24h</th><th{0}>#24-48h</th><th{0}># > 48h</th><th{0}>Avg. Response</th></tr></thead>",
                                          " style='padding:5px;border:1px solid #BBB'");
                Dictionary <string, List <string> > redFlagDetails = new Dictionary <string, List <string> >();
                foreach (DataRow dr in dt.Rows)
                {
                    sbCurrent.AppendFormat("<tr><th style='padding:5px;text-align:left;border:1px solid #BBB;'>{0}</th><td{12}>{1:#,###}</td><td{12}>{2}</td><td{12}>{3}</td><td{12}>{4}</td><td{12}>{5}</td><td{12}>{6:#,###}</td><td{12}>{7:#,###}</td><td{12}>{8:#,###}</td><td{12}>{9:#,###}</td><td{12}>{10:#,###}</td><td{12}>{11}</td></tr>",
                                           dr["ShortCode"],
                                           dr["TotalRecords"],
                                           ReportingTools.FormatIndex(dr["GEI"].ToString()),
                                           ReportingTools.FormatPercent(dr["NPS"].ToString()),
                                           ReportingTools.FormatPercent(dr["PRS"].ToString()),
                                           ReportingTools.FormatPercent(dr["GSEI"].ToString()),
                                           dr["FeedbackCount"], //6
                                           ReportingTools.FormatPercent(dr["FeedbackCompletePercent"].ToString()),
                                           dr["FeedbackLessThan24Hrs"],
                                           dr["Feedback24HrsTo48Hrs"],
                                           dr["FeedbackGreaterThan48Hrs"],
                                           ReportingTools.MinutesToNiceTime(dr["AverageFeedbackResponse"].ToString()),
                                           " style='padding:5px;border:1px solid #BBB;text-align:center'"
                                           );
                    sbComparison.AppendFormat("<tr><th style='padding:5px;text-align:left;border:1px solid #BBB;'>{0}</th>{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}</tr>",
                                              dr["ShortCode"],
                                              GetChangeCell(dr, "TotalRecords_Diff", String.Format("{0:#,###}", dr["TotalRecords"]), redFlagDetails, null),
                                              GetChangeCell(dr, "GEI_Diff", ReportingTools.FormatIndex(dr["GEI_Diff"].ToString()), redFlagDetails, r => { return(r != -1000 && r <= -10); }),
                                              GetChangeCell(dr, "NPS_Diff", ReportingTools.FormatPercent(dr["NPS_Diff"].ToString()), redFlagDetails, r => { return(r != -1000 && r <= -0.1); }),
                                              GetChangeCell(dr, "PRS_Diff", ReportingTools.FormatPercent(dr["PRS_Diff"].ToString()), redFlagDetails, r => { return(r != -1000 && r <= -0.1); }),
                                              GetChangeCell(dr, "GSEI_Diff", ReportingTools.FormatPercent(dr["GSEI_Diff"].ToString()), redFlagDetails, r => { return(r != -1000 && r <= -0.1); }),
                                              GetChangeCell(dr, "FeedbackCount_Diff", String.Format("{0:#,###}", dr["FeedbackCount_Diff"]), redFlagDetails, null), //6
                                              GetChangeCell(dr, "FeedbackCompletePercent_Diff", ReportingTools.FormatPercent(dr["FeedbackCompletePercent_Diff"].ToString()), redFlagDetails, r => { return(r != -1000 && r <= -0.1); }),
                                              GetChangeCell(dr, "FeedbackLessThan24Hrs_Diff", String.Format("{0:#,###}", dr["FeedbackLessThan24Hrs_Diff"]), redFlagDetails, null),
                                              GetChangeCell(dr, "Feedback24HrsTo48Hrs_Diff", String.Format("{0:#,###}", dr["Feedback24HrsTo48Hrs_Diff"]), redFlagDetails, null),
                                              GetChangeCell(dr, "FeedbackGreaterThan48Hrs_Diff", String.Format("{0:#,###}", dr["FeedbackGreaterThan48Hrs_Diff"]), redFlagDetails, null),
                                              GetChangeCell(dr, "AverageFeedbackResponse_Diff", ReportingTools.MinutesToNiceTime(dr["AverageFeedbackResponse_Diff"].ToString()), redFlagDetails, r => { return(r != -1000 && r >= 120); })
                                              );
                }
                sbCurrent.Append("</table><br /><br /><br />");
                sbComparison.Append("</table>");

                StringBuilder sbRedFlags = new StringBuilder();
                foreach (var kvp in redFlagDetails)
                {
                    if (sbRedFlags.Length == 0)
                    {
                        sbRedFlags.Append("<h3 style='margin:20px 0'>Red Flag Summary</h3><ul>");
                    }
                    if (kvp.Key.Length <= 4)
                    {
                        //Score
                        sbRedFlags.AppendFormat("<li><b>{0} score</b> has decreased by at least 10% for the following site(s): ", kvp.Key);
                    }
                    else if (kvp.Key.Equals("FeedbackCompletePercent"))
                    {
                        //Completion percentage
                        sbRedFlags.Append("<li><b>Feedback Completion</b> has decreased by at least 10% for the following site(s): ");
                    }
                    else if (kvp.Key.Equals("AverageFeedbackResponse"))
                    {
                        //Feedback response
                        sbRedFlags.Append("<li><b>Average Feedback Response</b> has increased by at least 2 hours for the following site(s): ");
                    }
                    foreach (string shortCode in kvp.Value)
                    {
                        sbRedFlags.AppendFormat("{0}, ", shortCode);
                    }
                    sbRedFlags.Remove(sbRedFlags.Length - 2, 2)
                    .Append("</li>");
                }
                if (sbRedFlags.Length > 0)
                {
                    sbRedFlags.Append("</ul><br />");
                    sbCurrent.Insert(0, sbRedFlags.ToString());
                }

                MailMessage msg = null;
                try
                {
                    var replacementModel = new
                    {
                        DataTables = sbCurrent.ToString() + sbComparison.ToString()
                    };
                    string path = context.Server.MapPath("~/Content/notifications/");
                    msg = EmailManager.CreateEmailFromTemplate(
                        Path.Combine(path, "WeeklyNotification.htm"),
                        replacementModel);
                    msg.IsBodyHtml   = true;
                    msg.BodyEncoding = System.Text.Encoding.UTF8;
                    msg.From         = new MailAddress("*****@*****.**");
                    msg.Subject      = "GCGC Weekly Status Notification - Week Ending " + endDate.ToString("MMM d, yyyy");
                    bool hasAddress = false;

                    dt = sql.QueryDataTable(@"
SELECT [SendType], u.[FirstName], u.[LastName],  u.[Email]
FROM [tblNotificationUsers] ne
	INNER JOIN [tblNotificationPropertySurveyReason] psr
		ON ne.[PropertySurveyReasonID] = psr.[PropertySurveyReasonID]
	INNER JOIN [tblCOM_Users] u
		ON ne.UserID = u.UserID
WHERE psr.PropertyID = @PropertyID
    AND psr.SurveyTypeID = @SurveyID
    AND psr.ReasonID = @ReasonID
;",
                                            new SQLParamList()
                                            .Add("@PropertyID", (int)GCCPropertyShortCode.GCC)
                                            .Add("@SurveyID", (int)SurveyType.GEI)
                                            .Add("@ReasonID", (int)NotificationReason.WeeklyStatusNotification)
                                            );
                    if (!sql.HasError && dt.Rows.Count > 0)
                    {
                        StringBuilder addrs = new StringBuilder();
                        foreach (DataRow dr in dt.Rows)
                        {
                            switch (dr["SendType"].ToString())
                            {
                            case "1":
                                msg.To.Add(dr["Email"].ToString());
                                addrs.Append(dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " <" + dr["Email"].ToString() + ">" + "\n");
                                hasAddress = true;
                                break;

                            case "2":
                                msg.CC.Add(dr["Email"].ToString());
                                //Colin requested that CC addresses not show on the call Aug 10,2015
                                //addrs.Append( dr["FirstName"].ToString() + " " + dr["LastName"].ToString() + " <" + dr["Email"].ToString() + ">" + "\n" );
                                hasAddress = true;
                                break;

                            case "3":
                                msg.Bcc.Add(dr["Email"].ToString());
                                hasAddress = true;
                                break;
                            }
                        }
                        //using ( StreamReader sr = new StreamReader( msg.AlternateViews[0].ContentStream ) ) {
                        //    msg.AlternateViews[0] = AlternateView.CreateAlternateViewFromString( sr.ReadToEnd().Replace( "{Recipients}", context.Server.HtmlEncode( addrs.ToString() ).Replace( "\n", "<br />" ) ), null, MediaTypeNames.Text.Html );
                        //}
                    }

                    if (hasAddress)
                    {
                        msg.Send();
                    }
                }
                catch (Exception ex)
                {
                    ErrorHandler.WriteLog("GCC_Web_Portal.Jobs", "Error running job.", ErrorHandler.ErrorEventID.General, ex);
                }
                finally
                {
                    if (msg != null)
                    {
                        msg.Dispose();
                        msg = null;
                    }
                }
                return;

                #endregion Send weekly notification email

            case "506aebb3-dfa2-4b34-94bc-51e81f5f31d3":

                #region Send Feedback Reminder Email

                sql = new SQLDatabase();
                dt  = sql.ExecStoredProcedureDataTable("[spJobs_48HrReminder]");
                foreach (DataRow dr in dt.Rows)
                {
                    GCCPropertyShortCode sc;
                    SurveyType           st;
                    NotificationReason   nr;
                    DateTime             created = Conversion.XMLDateToDateTime(dr["DateCreated"].ToString());
                    string feedbackUID           = dr["UID"].ToString();
                    if (Enum.TryParse(dr["PropertyID"].ToString(), out sc) &&
                        Enum.TryParse(dr["SurveyTypeID"].ToString(), out st) &&
                        Enum.TryParse(dr["ReasonID"].ToString(), out nr))
                    {
                        switch (st)
                        {
                        case SurveyType.GEI:
                            string gagLocation = dr["GEIGAGLocation"].ToString();
                            if (gagLocation.Length > 0)
                            {
                                gagLocation = " - " + gagLocation;
                            }
                            string fbLink = GCCPortalUrl + "Admin/Feedback/" + feedbackUID;
                            SurveyTools.SendNotifications(HttpContext.Current.Server, sc, st, nr, string.Empty,
                                                          new
                            {
                                Date               = created.ToString("yyyy-MM-dd"),
                                CasinoName         = PropertyTools.GetCasinoName((int)sc) + gagLocation,
                                Problems           = (dr["Q27"].Equals(1) ? "Yes" : "No"),
                                Response           = (dr["Q40"].Equals(1) ? "Yes" : "No"),
                                ProblemDescription = dr["Q27B"].ToString(),
                                StaffComment       = dr["Q11"].ToString(),
                                GeneralComments    = dr["Q34"].ToString(),
                                MemorableEmployee  = dr["Q35"].ToString(),
                                FeedbackLinkTXT    = (String.IsNullOrWhiteSpace(feedbackUID) ? String.Empty : "\n\nRespond to this feedback:\n" + fbLink + "\n"),
                                FeedbackLinkHTML   = (String.IsNullOrWhiteSpace(feedbackUID) ? String.Empty : @"<br /><br />
	<p><b>Respond to this feedback:</b></p>
	<p>"     + fbLink + "</p>"),
                                SurveyLink = GCCPortalUrl + "Display/GEI/" + dr["RecordID"].ToString()
                            },
                                                          String.Empty,
                                                          "Overdue: ");
                            break;

                        case SurveyType.Hotel:
                            SurveyTools.SendNotifications(HttpContext.Current.Server, sc, st, nr, string.Empty,
                                                          new
                            {
                                CasinoName       = PropertyTools.GetCasinoName((int)sc),
                                FeedbackNoteHTML = "<p><b>This guest has requested a response.</b> You can view and respond to the feedback request by clicking on (or copying and pasting) the following link:</p>\n<p>" + GCCPortalUrl + "Admin/Feedback/" + feedbackUID + "</p>",
                                FeedbackNoteTXT  = "The guest requested feedback. You can view and respond to the feedback request by clicking on (or copying and pasting) the following link:\n" + GCCPortalUrl + "Admin/Feedback/" + feedbackUID + "\n\n",
                                SurveyLink       = GCCPortalUrl + "Display/Hotel/" + dr["RecordID"].ToString()
                            },
                                                          String.Empty,
                                                          "Overdue: ");
                            break;

                        case SurveyType.Feedback:
                            gagLocation = dr["FBKGAGLocation"].ToString();
                            if (gagLocation.Length > 0)
                            {
                                gagLocation = " - " + gagLocation;
                            }
                            SurveyTools.SendNotifications(HttpContext.Current.Server, sc, st, nr, string.Empty,
                                                          new
                            {
                                Date             = created.ToString("yyyy-MM-dd"),
                                CasinoName       = PropertyTools.GetCasinoName((int)sc) + gagLocation,
                                FeedbackNoteHTML = "<p><b>This guest has requested a response.</b> You can view and respond to the feedback request by clicking on (or copying and pasting) the following link:</p>\n<p>" + GCCPortalUrl + "Admin/Feedback/" + feedbackUID + "</p>",
                                FeedbackNoteTXT  = "The guest requested feedback. You can view and respond to the feedback request by clicking on (or copying and pasting) the following link:\n" + GCCPortalUrl + "Admin/Feedback/" + feedbackUID + "\n\n",
                                SurveyLink       = GCCPortalUrl + "Display/Feedback/" + dr["RecordID"].ToString()
                            },
                                                          String.Empty,
                                                          "Overdue: ");
                            break;

                        case SurveyType.Donation:
                            SurveyTools.SendNotifications(HttpContext.Current.Server, sc, st, nr, string.Empty,
                                                          new
                            {
                                Date         = created.ToString("yyyy-MM-dd"),
                                CasinoName   = PropertyTools.GetCasinoName((int)sc),
                                FeedbackLink = GCCPortalUrl + "Admin/Feedback/" + feedbackUID,
                                Link         = GCCPortalUrl + "Display/Donation/" + dr["RecordID"].ToString()
                            },
                                                          String.Empty,
                                                          "Overdue: ");
                            break;
                        }
                    }
                }
                return;

                #endregion Send Feedback Reminder Email
            }

            context.Response.ContentType = "text/plain";
            context.Response.Write("Invalid Job ID.");
        }