Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Surveys.SurveyViewPage"/> class.
        /// </summary>
        /// <param name="vg">View generator.</param>
        /// <param name="tflp">Page which called this one (for callbacks)</param>
        public SurveyViewPage(ViewGenerator vg, ToFillListPage tflp)
        {
            this.vg    = vg;
            this._tflp = tflp;

            #region creating navigationContent with two buttons
            goToPreviousButton = new Button {
                Text              = "Previous",
                IsEnabled         = false,
                HorizontalOptions = LayoutOptions.StartAndExpand
            };
            goToPreviousButton.Clicked += OnPreviousClicked;


            goToNextButton = new Button {
                Text              = "Next",
                IsEnabled         = false,
                HorizontalOptions = LayoutOptions.EndAndExpand
            };
            goToNextButton.Clicked += OnNextClicked;

            navigationContent = new StackLayout {
                Orientation   = StackOrientation.Horizontal,
                HeightRequest = 50
            };
            navigationContent.Children.Add(goToPreviousButton);
            navigationContent.Children.Add(goToNextButton);
            #endregion

            surveyContent = new StackLayout();
            surveyContent.Children.Add(navigationContent);

            this.Padding = new Thickness(10, Device.OnPlatform(20, 0, 0), 10, 0);

            this.Content = surveyContent;

            LoadSurvey();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Surveys.ToFillListPage"/> class.
        /// </summary>
        public ToFillListPage()
        {
            this.Title = "To be answered";

            // Read schemas, instances and check for new
            List <Survey>       allSchemas    = IOController.ReadAllSchemas();
            List <SurveyAnswer> filledAnswers = new List <SurveyAnswer> ();

            List <string> filledAnswersSerialized = IOController.ReadFiles(Constants.filledFolder);

            foreach (string s in filledAnswersSerialized)
            {
                filledAnswers.Add(JSonTranslator.Deserialize <SurveyAnswer> (s));
            }


            List <Survey> newSchemas = StartupController.checkForNewSchemas(allSchemas, filledAnswers);

            // If new, generate unfilled instances
            List <SurveyAnswer> surveyUnfilledInstances = new List <SurveyAnswer> ();

            if (newSchemas.Count != 0)
            {
                UserData user = new UserData();
                user.Username           = "******";
                user.ID                 = "test_ID";
                surveyUnfilledInstances = StartupController.generateInstances(newSchemas, user);
            }

            // Read previously stored unfilled instances
            List <string> previouslyUnfilledSerialized = IOController.ReadFiles(Constants.toFillFolder);

            foreach (string s in previouslyUnfilledSerialized)
            {
                SurveyAnswer sa = JSonTranslator.Deserialize <SurveyAnswer> (s);
                surveyUnfilledInstances.Add(sa);
            }


            // set active parts and preapre a display dictionary
            Dictionary <string, SurveyAnswer> toAnswerNamed = new Dictionary <string, SurveyAnswer> ();

            foreach (SurveyAnswer sa in surveyUnfilledInstances)
            {
                if (ScheduleController.setActive(sa))
                {
                    toAnswerNamed.Add(sa.Survey.SurveyName + "_" + sa.SurveyId.ToString().Substring(0, 4) + "_" + DateTime.Now.DayOfYear,
                                      sa);
                }
            }

            // Create and initialize ListView.

            ListView listView = new ListView();

            listView.ItemsSource = toAnswerNamed.Keys;

            listView.ItemSelected += (object sender, SelectedItemChangedEventArgs e) => {
                if (e.SelectedItem != null)
                {
                    listView.SelectedItem = null;
                    chosenSurvey          = toAnswerNamed [(string)e.SelectedItem];
                    ViewGenerator vg         = new ViewGenerator(chosenSurvey.Survey);
                    ContentPage   surveyPage = new SurveyViewPage(vg, this);
                    this.Navigation.PushAsync(surveyPage);
                }
            };

            this.Content = new ScrollView {
                Content = listView
            };
        }