Ejemplo n.º 1
0
 /// <summary>
 /// Checks a control with an int value for an answer.
 /// </summary>
 /// <param name="control">The control to check.</param>
 /// <param name="questionsAreMandatory">Whether questions are mandatory or not.</param>
 public static bool CheckForAnswer(ISurveyControl <int> control, bool questionsAreMandatory)
 {
     if (control.GetValue() == -1 && questionsAreMandatory)
     {
         control.MessageManager.ErrorMessage = "Please select a value for the following question.";
         return(false);
     }
     return(true);
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Saves the value of a control into the session.
 /// </summary>
 /// <param name="control">The control to save the value of session.</param>
 public static void SaveValue <T>(ISurveyControl <T> control)
 {
     if (control is SurveyCheckBox)
     {
         SaveValue(control as SurveyCheckBox);
     }
     else
     {
         SessionWrapper.Add(control.SessionKey, new SurveySessionControl <T>(control.GetValue()));
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Gets a value from a control or from the session depending on the value of the getCurrentValue parameter.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="control"></param>
 /// <param name="getCurrentValue"></param>
 /// <param name="defaultValue"></param>
 /// <returns></returns>
 public static T GetValue <T>(ISurveyControl <T> control, bool getCurrentValue, T defaultValue)
 {
     if (getCurrentValue)
     {
         return(control.GetValue());
     }
     else
     {
         var sval = SessionWrapper.Get <SurveySessionControl <T> >(control.SessionKey);
         if (sval != null)
         {
             return(sval.Value);
         }
         else
         {
             return(defaultValue);
         }
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Checks a control with a string value for an answer.
        /// </summary>
        /// <param name="control">The control to check.</param>
        /// <param name="questionsAreMandatory">Whether questions are mandatory or not.</param>
        public static bool CheckForAnswer(ISurveyControl <string> control, bool questionsAreMandatory)
        {
            if ((String.IsNullOrEmpty(control.GetValue()) ||
                 control.GetValue().Trim().Length == 0) &&
                questionsAreMandatory)
            {
                control.MessageManager.ErrorMessage = "Please enter a value for the following question.";
                return(false);
            }
            SurveyTextBox stb = control as SurveyTextBox;

            if (stb != null)
            {
                if (stb.MaxLength > 0 &&
                    stb.GetValue().Length > stb.MaxLength)
                {
                    stb.MessageManager.ErrorMessage = String.Format("The following answer cannot be longer than {0} character(s). You have entered {1} character(s).", stb.MaxLength, stb.GetValue().Length);
                    return(false);
                }
            }
            return(true);
        }
 private void WipeSurveyControls(ControlCollection controls)
 {
     foreach (Control ctl in controls)
     {
         //Wipe this control
         if (ctl is ISurveyControl <string> )
         {
             ISurveyControl <string> sc = ctl as ISurveyControl <string>;
             if (sc != null)
             {
                 SessionWrapper.Remove(sc.SessionKey);
             }
         }
         if (ctl is ISurveyControl <int> )
         {
             ISurveyControl <int> sc = ctl as ISurveyControl <int>;
             if (sc != null)
             {
                 SessionWrapper.Remove(sc.SessionKey);
             }
         }
         if (ctl is ISurveyControl <bool> )
         {
             ISurveyControl <bool> sc = ctl as ISurveyControl <bool>;
             if (sc != null)
             {
                 SessionWrapper.Remove(sc.SessionKey);
             }
         }
         //Recursively check child controls
         if (ctl.Controls != null && ctl.Controls.Count > 0)
         {
             WipeSurveyControls(ctl.Controls);
         }
     }
 }
 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));
 }