private void AddQuestion(List <Question> listQuestions, int i)
 {
     if (listQuestions.ElementAt(i) is Text_Question)
     {
         Text_Question question = (Text_Question)listQuestions.ElementAt(i);
         stackQuestions.Children.Add(GetElements.GetTextQuestion(i + 1 + "- " + question.questionProperty + " ?", false, false));
         AddAnalyzeButton(i, TypeQuestion.Text);
     }
     else if (listQuestions.ElementAt(i) is Multible)
     {
         Multible question = (Multible)listQuestions.ElementAt(i);
         if (question.typeQuestion_properties.ToString().Contains("Multible"))
         {
             stackQuestions.Children.Add(GetElements.GetMultiChoices(false, i + 1 + "- " + question.title_property + " ?", question.answer, false, false));
         }
         else if (question.Type.Equals(TypeQuestion.MultiChoice))
         {
             stackQuestions.Children.Add(GetElements.GetMultiChoices(true, i + 1 + "- " + question.title_property + " ?", question.answer, false, false));
         }
         else if (question.Type.Equals(TypeQuestion.DropDown))
         {
             stackQuestions.Children.Add(GetElements.GetDropDownQuestion(i + 1 + "- " + question.title_properties + " ?", question.answer.ToList(), false, false));
         }
         AddAnalyzeButton(i, TypeQuestion.Multible);
     }
     else if (listQuestions.ElementAt(i) is Slider_Question)
     {
         Slider_Question question = (Slider_Question)listQuestions.ElementAt(i);
         stackQuestions.Children.Add(
             GetElements.GetSlider(question.Min_Value_Property, question.Max_Value_Property, i + 1 + "- " + question.title_property + " ?", false, false)
             );
         AddAnalyzeButton(i, TypeQuestion.Slider);
     }
 }
 public DropDownQuestion(ItemTappedEventArgs itemtapped, Question questionSelected, int index)
 {
     InitializeComponent();
     survey            = itemtapped.Item as Survey;
     _questionSelected = questionSelected as Multible;
     BindingContext    = _questionSelected;
     entries           = new List <Entry>();
     _index            = index;
 }
Ejemplo n.º 3
0
 public MultiChoiceQuestion(ItemTappedEventArgs itemtapped, Question questionSelected, int index)
 {
     InitializeComponent();
     pickerSelectionType.Items.Add(Lang.Resource.typePickerMulti_1);
     pickerSelectionType.Items.Add(Lang.Resource.typePickerMulti_2);
     survey            = itemtapped.Item as Survey;
     _questionSelected = questionSelected as Multible;
     BindingContext    = _questionSelected;
     entries           = new List <Entry>();
     _index            = index;
 }
        private async void SaveData_Activated(object sender, EventArgs e)
        {
            int count = stackAnswerChoice.Children.Count;

            for (int i = 0; i < count; i++)
            {
                Grid  G = stackAnswerChoice.Children.ElementAt(i) as Grid;
                Entry E = G.Children.ElementAt(0) as Entry;
                if (String.IsNullOrWhiteSpace(E.Text))
                {
                    E.IsVisible = false;
                    continue;
                }
                if (E.IsVisible && E.Text.Contains("~"))
                {
                    checkinputs.Text = Lang.Resource.check_inputsSignin3;
                    return;
                }
                if (!String.IsNullOrWhiteSpace(E.Text) && G.IsVisible)
                {
                    entries.Add(E);
                }
            }
            List <string> choices = new List <string>();

            for (int i = 0; i < entries.Count; i++)
            {
                if (entries[i].IsVisible)
                {
                    choices.Add(entries[i].Text);
                }
            }
            if (switchOtherAnswer.IsToggled)
            {
                choices.Add("Other");
            }
            string[] answers = new string[choices.Count];
            for (int i = 0; i < choices.Count; i++)
            {
                answers[i] = choices[i];
            }
            Multible question = new Multible(TypeQuestion.DropDown, questionEntry.Text, answers.Length);

            question.require_Ans = switchRequireAnswer.IsToggled;
            question.Create_question(questionEntry.Text, answers);

            //// Store Data in File Of Survey
            folder   = FileSystem.Current.LocalStorage;
            username = await controlFile.GetUserName();

            folder = await folder.CreateFolderAsync("foldersurveys" + username, CreationCollisionOption.OpenIfExists);

            file = await folder.CreateFileAsync("filesurveys" + username, CreationCollisionOption.OpenIfExists);

            string content = await file.ReadAllTextAsync();

            ListSurveys = Serializable_Survey.deserialize(content);

            if (_questionSelected != null)
            {
                foreach (Survey S in ListSurveys)
                {
                    if (S.Id == survey.Id)
                    {
                        (S.Questions_Property.ElementAt(_index) as Multible).Type        = TypeQuestion.DropDown;
                        (S.Questions_Property.ElementAt(_index) as Multible).require_Ans = switchRequireAnswer.IsToggled;
                        (S.Questions_Property.ElementAt(_index) as Multible).bound       = answers.Length;
                        (S.Questions_Property.ElementAt(_index) as Multible).Create_question(questionEntry.Text, answers);
                        survey = S;
                        break;
                    }
                }
            }
            else
            {
                foreach (Survey S in ListSurveys)
                {
                    if (S.Id == survey.Id)
                    {
                        S.Questions_Property.Add(question);

                        survey = S;
                        break;
                    }
                }
            }
            if (CheckNetwork.Check_Connectivity())
            {
                SurveysServices S_S = new SurveysServices();
                S_S.Set_UrlApi("EditSurveys/" + username);
                await S_S.PutSurveysAsync(survey);
            }

            content = Serializable_Survey.serialize(ListSurveys.ToList());
            await file.WriteAllTextAsync(content);

            await Navigation.PopModalAsync();
        }
Ejemplo n.º 5
0
 private void AddQuestion(List <Question> listQuestions, int i)
 {
     if (listQuestions.ElementAt(i) is Text_Question)
     {
         Text_Question question = (Text_Question)listQuestions.ElementAt(i);
         stackQuestions.Children.Add(GetElements.GetTextQuestion(i + 1 + "- " + question.questionProperty + " ?", false, true));
         (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[0] as Button).Clicked += (sender, e) => {
             question_selected = survey.Questions_Property.ElementAt(i);
             Navigation.PushModalAsync(new TextQuestion(_survey, question_selected, i));
         };
         (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[1] as Button).Clicked += (sender, e) => {
             Delete_Item(i);
         };
     }
     else if (listQuestions.ElementAt(i) is Multible)
     {
         Multible question = (Multible)listQuestions.ElementAt(i);
         if (question.Type.Equals(TypeQuestion.Multible))
         {
             stackQuestions.Children.Add(GetElements.GetMultiChoices(false, i + 1 + "- " + question.title_property + " ?", question.answer, false, true));
             (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[0] as Button).Clicked += (sender, e) =>
             {
                 question_selected = survey.Questions_Property.ElementAt(i);
                 Navigation.PushModalAsync(new MultiChoiceQuestion(_survey, question_selected, i));
             };
             (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[1] as Button).Clicked += (sender, e) => {
                 Delete_Item(i);
             };
         }
         else if (question.Type.Equals(TypeQuestion.MultiChoice))
         {
             stackQuestions.Children.Add(GetElements.GetMultiChoices(true, i + 1 + "- " + question.title_property + " ?", question.answer, false, true));
             (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[0] as Button).Clicked += (sender, e) =>
             {
                 question_selected = survey.Questions_Property.ElementAt(i);
                 Navigation.PushModalAsync(new MultiChoiceQuestion(_survey, question_selected, i));
             };
             (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[1] as Button).Clicked += (sender, e) => {
                 Delete_Item(i);
             };
         }
         else if (question.Type.Equals(TypeQuestion.DropDown))
         {
             stackQuestions.Children.Add(GetElements.GetDropDownQuestion(i + 1 + "- " + question.title_properties + " ?", question.answer.ToList(), false, true));
             (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[0] as Button).Clicked += (sender, e) => {
                 question_selected = survey.Questions_Property.ElementAt(i);
                 Navigation.PushModalAsync(new DropDownQuestion(_survey, question_selected, i));
             };
             (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[1] as Button).Clicked += (sender, e) => {
                 Delete_Item(i);
             };
         }
     }
     else if (listQuestions.ElementAt(i) is Slider_Question)
     {
         Slider_Question question = (Slider_Question)listQuestions.ElementAt(i);
         stackQuestions.Children.Add(
             GetElements.GetSlider(question.Min_Value_Property, question.Max_Value_Property, i + 1 + "- " + question.title_property + " ?", false, true)
             );
         (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[0] as Button).Clicked += (sender, e) => {
             question_selected = survey.Questions_Property.ElementAt(i);
             Navigation.PushModalAsync(new SliderQuestion(_survey, question_selected, i));
         };
         (((stackQuestions.Children[i + 1] as StackLayout).Children[(stackQuestions.Children[i + 1] as StackLayout).Children.Count - 1] as StackLayout).Children[1] as Button).Clicked += (sender, e) => {
             Delete_Item(i);
         };
     }
 }