示例#1
0
        private void CreateSurveyItems(List <SurveysInfo> surveys)
        {
            foreach (SurveysInfo survey in surveys)
            {
                List <SurveyOptionsInfo> surveyOptions = SurveyOptionsController.GetAll(survey.SurveyID);
                switch (survey.OptionType)
                {
                case QuestionType.RadioButtons:
                    SurveyRadioButtons surveyRadioButtons = (SurveyRadioButtons)LoadControl(string.Format("{0}Controls/SurveyRadioButtons.ascx", ControlPath));
                    surveyRadioButtons.ID              = string.Format("SurveyRadiobutton_{0}", survey.SurveyID);
                    surveyRadioButtons.Label           = survey.Question;
                    surveyRadioButtons.RepeatDirection = survey.RepeatDirection;
                    surveyRadioButtons.RepeatColumns   = (((survey.RepeatColumns == null) || (survey.RepeatColumns <= 1)) ? 1 : survey.RepeatColumns.Value);
                    surveyRadioButtons.EditUrl         = EditUrl("SurveyID", survey.SurveyID.ToString());
                    surveyRadioButtons.IsEditable      = IsEditable;
                    surveyRadioButtons.ErrorMessage    = string.Format(Localization.GetString("RadioButtonRequired.ErrorMessage", LocalResourceFile), survey.Question);
                    surveyRadioButtons.ValidationGroup = string.Format("Survey_{0}_ValidationGroup", ModuleId);
                    surveyRadioButtons.DataSource      = surveyOptions;
                    surveyRadioButtons.DataTextField   = "OptionName";
                    surveyRadioButtons.DataValueField  = "SurveyOptionID";
                    surveyRadioButtons.DataBind();
                    SurveyPlaceHolder.Controls.Add(surveyRadioButtons);
                    break;

                case QuestionType.CheckBoxes:
                    SurveyCheckBoxes surveyCheckBoxes = (SurveyCheckBoxes)LoadControl(string.Format("{0}Controls/SurveyCheckBoxes.ascx", ControlPath));
                    surveyCheckBoxes.ID              = string.Format("SurveyCheckbox_{0}", survey.SurveyID);
                    surveyCheckBoxes.Label           = survey.Question;
                    surveyCheckBoxes.RepeatDirection = survey.RepeatDirection;
                    surveyCheckBoxes.RepeatColumns   = (((survey.RepeatColumns == null) || (survey.RepeatColumns <= 1)) ? 1 : survey.RepeatColumns.Value);
                    surveyCheckBoxes.EditUrl         = EditUrl("SurveyID", survey.SurveyID.ToString());
                    surveyCheckBoxes.IsEditable      = IsEditable;
                    surveyCheckBoxes.ErrorMessage    = string.Format(Localization.GetString("CheckBoxRequired.ErrorMessage", LocalResourceFile), survey.Question);
                    surveyCheckBoxes.ValidationGroup = string.Format("Survey_{0}_ValidationGroup", ModuleId);
                    surveyCheckBoxes.DataSource      = surveyOptions;
                    surveyCheckBoxes.DataTextField   = "OptionName";
                    surveyCheckBoxes.DataValueField  = "SurveyOptionID";
                    surveyCheckBoxes.DataBind();
                    SurveyPlaceHolder.Controls.Add(surveyCheckBoxes);
                    break;

                case QuestionType.Text:
                    SurveyText surveyTextBox = (SurveyText)LoadControl(string.Format("{0}Controls/SurveyText.ascx", ControlPath));
                    surveyTextBox.ID              = string.Format("SurveyTextBox_{0}", survey.SurveyID);
                    surveyTextBox.Label           = survey.Question;
                    surveyTextBox.NumberOfRows    = (((survey.NumberOfRows.HasValue) && (survey.NumberOfRows.Value > 1)) ? survey.NumberOfRows.Value : 1);
                    surveyTextBox.EditUrl         = EditUrl("SurveyID", survey.SurveyID.ToString());
                    surveyTextBox.IsEditable      = IsEditable;
                    surveyTextBox.ErrorMessage    = string.Format(Localization.GetString("TextBoxRequired.ErrorMessage", LocalResourceFile), survey.Question);
                    surveyTextBox.ValidationGroup = string.Format("Survey_{0}_ValidationGroup", ModuleId);
                    surveyTextBox.SurveyOptionID  = surveyOptions[0].SurveyOptionID;
                    SurveyPlaceHolder.Controls.Add(surveyTextBox);
                    break;

                default:
                    break;
                }
            }

            if (PrivacyConfirmation)
            {
                // This is DNN 9.2.2 code...
                string privacyUrl = Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Privacy");
                string termsUrl   = Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Terms");
                // For DNN 9.3.0 use this code then...
                //string privacyUrl = (PortalSettings.PrivacyTabId == Null.NullInteger ? Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Privacy") : Globals.NavigateURL(PortalSettings.PrivacyTabId));
                //string termsUrl = (PortalSettings.TermsTabId == Null.NullInteger ? Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "Terms") : Globals.NavigateURL(PortalSettings.TermsTabId));

                PrivacyConfirmationCheckBox privacyConfirmation = (PrivacyConfirmationCheckBox)LoadControl(string.Format("{0}Controls/PrivacyConfirmationCheckBox.ascx", ControlPath));
                privacyConfirmation.ID              = string.Format("PrivacyConfirmationCheckBox_{0}", ModuleId);
                privacyConfirmation.Label           = string.Format(Localization.GetString("PrivacyConfirmation.Text", LocalResourceFile), privacyUrl, termsUrl);
                privacyConfirmation.ErrorMessage    = Localization.GetString("PrivacyConfirmation.ErrorMessage", LocalResourceFile);
                privacyConfirmation.ValidationGroup = string.Format("Survey_{0}_ValidationGroup", ModuleId);
                SurveyPlaceHolder.Controls.Add(privacyConfirmation);
            }

            if ((UseCaptcha == UseCaptcha.Always) || ((UseCaptcha == UseCaptcha.UnauthorizedUsersOnly) && (UserId < 1)))
            {
                CaptchaControl captcha = new CaptchaControl();
                captcha.ID                  = string.Format("Captcha_{0}", ModuleId);
                captcha.Text                = Localization.GetString("Captcha.Text", LocalResourceFile);
                captcha.CaptchaLength       = 8;
                captcha.ErrorMessage        = Localization.GetString("Captcha.ErrorMessage", LocalResourceFile);
                captcha.CaptchaChars        = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghjkmnpqrstuvwxyz23456789";
                captcha.ErrorStyle.CssClass = "dnnFormMessage dnnFormError";
                SurveyPlaceHolder.Controls.Add(captcha);
            }
        }