コード例 #1
0
        public async Task UploadResponsedSurveys()
        {
            folder = FileSystem.Current.LocalStorage;
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }
            List <Survey>        surveys = new List <Survey>();
            ExistenceCheckResult result  = await folder.CheckExistsAsync("ShareResponsedSurveys");

            if (result == ExistenceCheckResult.FolderExists)
            {
                folder = await folder.CreateFolderAsync("ShareResponsedSurveys", CreationCollisionOption.OpenIfExists);

                file = await folder.CreateFileAsync("ShareResponsedSurveys", CreationCollisionOption.OpenIfExists);

                string Content = await file.ReadAllTextAsync();

                if (String.IsNullOrEmpty(Content) || String.IsNullOrWhiteSpace(Content))
                {
                    return;
                }
                surveys = Serializable_Survey.deserialize(Content).ToList();
                foreach (Survey S in surveys)
                {
                    SurveysServices S_S = new SurveysServices();
                    S_S.Set_UrlApi("ShareResponsedSurveys/");
                    await S_S.PostSurveysAsync(S);
                }
                file = await folder.GetFileAsync("ShareResponsedSurveys");

                await file.DeleteAsync();
            }
        }
コード例 #2
0
        private async void PostSurveysByNames(string UserName)
        {
            SurveysServices S_S = new SurveysServices();

            S_S.Set_UrlApi("ShareSurveys/" + UserName);
            await S_S.PostSurveysAsync(_survey);
        }
コード例 #3
0
        private async void HandleConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
        {
            if (e.IsConnected)
            {
                string Content;
                // Post Responsed Surveys
                folder = FileSystem.Current.LocalStorage;
                List <Survey>        surveys = new List <Survey>();
                ExistenceCheckResult result  = await folder.CheckExistsAsync("ShareResponsedSurveys");

                if (result == ExistenceCheckResult.FolderExists)
                {
                    folder = await folder.CreateFolderAsync("ShareResponsedSurveys", CreationCollisionOption.OpenIfExists);

                    file = await folder.CreateFileAsync("ShareResponsedSurveys", CreationCollisionOption.OpenIfExists);

                    Content = await file.ReadAllTextAsync();

                    if (String.IsNullOrEmpty(Content) || String.IsNullOrWhiteSpace(Content))
                    {
                        return;
                    }
                    surveys = Serializable_Survey.deserialize(Content).ToList();
                    foreach (Survey S in surveys)
                    {
                        SurveysServices S_S = new SurveysServices();
                        S_S.Set_UrlApi("ShareResponsedSurveys/");
                        await S_S.PostSurveysAsync(S);
                    }
                    folder = FileSystem.Current.LocalStorage;
                    folder = await folder.GetFolderAsync("ShareResponsedSurveys");

                    await folder.DeleteAsync();
                }

                // Receive Surveys
                ReceiveSurveys();
                // Receive Responsed Surveys
                ReceiveResponsedSurveys();
            }
        }
コード例 #4
0
        private async void Save_Survey(object sender, EventArgs e, TypeSurvey type)
        {
            string          content;
            List <Question> list = new List <Question>();

            folder = FileSystem.Current.LocalStorage;

            Survey survey = new Survey(list, username, title, description, (DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss")).Substring(0, DateTime.Now.ToString("dddd, dd MMMM yyyy HH:mm:ss").Length - 8));

            survey.type_Property = type;
            ExistenceCheckResult Result = await folder.CheckExistsAsync("foldersurveys" + username);

            if (Result != ExistenceCheckResult.FolderExists)
            {
                folder = await folder.CreateFolderAsync("foldersurveys" + username, CreationCollisionOption.ReplaceExisting);
            }
            else
            {
                folder = await folder.CreateFolderAsync("foldersurveys" + username, CreationCollisionOption.OpenIfExists);
            }
            Result = await folder.CheckExistsAsync("filesurveys" + username);

            if (Result != ExistenceCheckResult.FileExists)
            {
                file = await folder.CreateFileAsync("filesurveys" + username, CreationCollisionOption.ReplaceExisting);

                survey.Id = 1;
                ListSurveys.Add(survey);
                content = Serializable_Survey.serialize(ListSurveys);
                await file.WriteAllTextAsync(content);

                Full_Lists_Surveys();

                if (CheckNetwork.Check_Connectivity())
                {
                    SurveysServices S_S1 = new SurveysServices();
                    S_S1.Set_UrlApi("SaveSurveys/");
                    await S_S1.PostSurveysAsync(survey);
                }
                stackEducation.IsVisible = false;
                Cancel(sender, e);
                return;
            }
            file = await folder.CreateFileAsync("filesurveys" + username, CreationCollisionOption.OpenIfExists);

            content = await file.ReadAllTextAsync();

            ListSurveys = Serializable_Survey.deserialize(content).ToList();
            if (ListSurveys.Count != 0)
            {
                survey.Id = ListSurveys[ListSurveys.Count - 1].Id + 1;
            }
            else
            {
                survey.Id = 1;
            }
            ListSurveys.Add(survey);
            content = Serializable_Survey.serialize(ListSurveys);
            await file.WriteAllTextAsync(content);

            Full_Lists_Surveys();

            if (CheckNetwork.Check_Connectivity())
            {
                SurveysServices S_S = new SurveysServices();
                S_S.Set_UrlApi("SaveSurveys/");
                await S_S.PostSurveysAsync(survey);
            }
            stackEducation.IsVisible = false;
            Cancel(sender, e);
        }
コード例 #5
0
        private async void Save_Activated(object sender, EventArgs e)
        {
            stackQuestions.BackgroundColor = Color.FromHex("e5e5e5");
            var res = await DisplayAlert(Lang.Resource.titleMessage, Lang.Resource.bodyMessageSave, Lang.Resource.btnCancelMessage, Lang.Resource.btnOkMessage);

            stackQuestions.BackgroundColor = Color.FromHex("ffffff");
            if (res)
            {
                return;
            }

            ActivityIndicator.IsRunning = true;
            stackQuestions.Opacity      = 0.4;

            folder = FileSystem.Current.LocalStorage;
            folder = await folder.CreateFolderAsync("folderUser", CreationCollisionOption.OpenIfExists);

            file = await folder.CreateFileAsync("fileUser", CreationCollisionOption.OpenIfExists);

            string AccountUser = await file.ReadAllTextAsync();

            User register = Serializable_Account.deserialize(AccountUser).ElementAt(0);

            for (int i = 1; i < stackQuestions.Children.Count; i++)
            {
                string date = "";
                // Get Answer From Text Question
                if (((stackQuestions.Children.ElementAt(i) as StackLayout).StyleId.Equals("text")))
                {
                    string answer = ((stackQuestions.Children.ElementAt(i) as StackLayout).Children[2] as Entry).Text;
                    if (String.IsNullOrWhiteSpace(answer) && (SelectedSurvey.Questions[i - 1] as Text_Question).requireAnswer)
                    {
                        DependencyService.Get <SnackBar>().ShowSnackBar(Lang.Resource.the_question + i + Lang.Resource.restTheQuestion);
                        return;
                    }
                    if (!String.IsNullOrWhiteSpace(answer))
                    {
                        if (answer.Contains("~"))
                        {
                            DependencyService.Get <SnackBar>().ShowSnackBar(Lang.Resource.the_question + i + Lang.Resource.rest_theTextQuestion);
                            return;
                        }
                    }
                    date += DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
                    (SelectedSurvey.Questions[i - 1] as Text_Question).Answer_question(answer, date, register);
                }
                else if (((stackQuestions.Children.ElementAt(i) as StackLayout).StyleId.Equals("dropdown")))
                {
                    string answer = ((stackQuestions.Children.ElementAt(i) as StackLayout).Children[2] as Picker).Title;
                    if ((String.IsNullOrWhiteSpace(answer) || answer.Equals("Choices")) && (SelectedSurvey.Questions[i - 1] as Multible).require_Ans)
                    {
                        DependencyService.Get <SnackBar>().ShowSnackBar(Lang.Resource.the_question + i + Lang.Resource.restTheQuestion);
                        return;
                    }
                    date += DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
                    (SelectedSurvey.Questions[i - 1] as Multible).Answer_question(answer, date, register);
                }
                else if (((stackQuestions.Children.ElementAt(i) as StackLayout).StyleId.Equals("multible")))
                {
                    bool answered = false;
                    if ((SelectedSurvey.Questions[i - 1] as Multible).Type.Equals(TypeQuestion.Multible))
                    {
                        string answer = "";
                        for (int j = 0; j < (((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[0] as StackLayout).Children.Count; j++)
                        {
                            var stack = (((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[0] as StackLayout).Children[j] as StackLayout;
                            var img   = stack.Children[0] as Image;
                            if (!img.StyleId.Contains("un"))
                            {
                                answer   = (((((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[0] as StackLayout).Children[j] as StackLayout).Children[1] as Label).Text;
                                answered = true;
                            }
                        }
                        if (!answered && (SelectedSurvey.Questions[i - 1] as Multible).require_Ans)
                        {
                            DependencyService.Get <SnackBar>().ShowSnackBar(Lang.Resource.the_question + i + Lang.Resource.restTheQuestion);
                            return;
                        }
                        Multiable_answer multiAnswer = new Multiable_answer((((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[0] as StackLayout).Children.Count);

                        date += DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
                        (SelectedSurvey.Questions[i - 1] as Multible).Answer_question(answer, date, register);
                    }
                    else if ((SelectedSurvey.Questions[i - 1] as Multible).Type.Equals(TypeQuestion.MultiChoice))
                    {
                        string[] multichoicesAnswers = new string[(((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[0] as StackLayout).Children.Count];
                        for (int j = 0; j < (((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[0] as StackLayout).Children.Count; j++)
                        {
                            var stack = (((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[0] as StackLayout).Children[j] as StackLayout;
                            var img   = stack.Children[0] as Image;
                            if (!img.StyleId.Contains("un"))
                            {
                                multichoicesAnswers[j] = (((((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[0] as StackLayout).Children[j] as StackLayout).Children[1] as Label).Text;
                                answered = true;
                            }
                        }
                        if (!answered && (SelectedSurvey.Questions[i - 1] as Multible).require_Ans)
                        {
                            DependencyService.Get <SnackBar>().ShowSnackBar(Lang.Resource.the_question + i + Lang.Resource.restTheQuestion);
                            return;
                        }
                        (SelectedSurvey.Questions[i - 1] as Multible).list_multichoice_answer = new LinkedList <MultiChoiceAnswercs>();
                        MultiChoiceAnswercs multichoices = new MultiChoiceAnswercs(multichoicesAnswers.Length);

                        date += DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
                        (SelectedSurvey.Questions[i - 1] as Multible).Answer_question(multichoicesAnswers, date, register);
                    }
                }
                else if (((stackQuestions.Children.ElementAt(i) as StackLayout).StyleId.Equals("slider")))
                {
                    int counter = (int)(((stackQuestions.Children[i] as StackLayout).Children[2] as StackLayout).Children[1] as Slider).Value;
                    date += DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString();
                    (SelectedSurvey.Questions[i - 1] as Slider_Question).Answer_question(counter, date, register);
                }
            }
            stackQuestions.Opacity = 0.5;
            if (CheckNetwork.Check_Connectivity())
            {
                SurveysServices S_S = new SurveysServices();
                S_S.Set_UrlApi("ShareResponsedSurveys/");
                await S_S.PostSurveysAsync(SelectedSurvey);
            }
            else
            {
                List <Survey> surveys = new List <Survey>();
                folder = FileSystem.Current.LocalStorage;
                ExistenceCheckResult result = await folder.CheckExistsAsync("ShareResponsedSurveys");

                if (result == ExistenceCheckResult.FolderExists)
                {
                    folder = await folder.CreateFolderAsync("ShareResponsedSurveys", CreationCollisionOption.OpenIfExists);

                    file = await folder.CreateFileAsync("ShareResponsedSurveys", CreationCollisionOption.OpenIfExists);

                    string Content = await file.ReadAllTextAsync();

                    if (String.IsNullOrEmpty(Content) || String.IsNullOrWhiteSpace(Content))
                    {
                        surveys.Add(SelectedSurvey);
                        Content = Serializable_Survey.serialize(surveys);
                        await file.WriteAllTextAsync(Content);

                        await Task.Delay(500);

                        await Navigation.PopAsync();

                        return;
                    }

                    surveys = Serializable_Survey.deserialize(Content).ToList();
                    if (surveys.Contains(SelectedSurvey))
                    {
                        foreach (Survey S in surveys)
                        {
                            if (S.Id == SelectedSurvey.Id_Property)
                            {
                                S.Questions = SelectedSurvey.Questions;
                            }
                        }
                    }
                    else
                    {
                        surveys.Add(SelectedSurvey);
                    }
                    Content = Serializable_Survey.serialize(surveys);
                    await file.WriteAllTextAsync(Content);
                }
                else
                {
                    folder = await folder.CreateFolderAsync("ShareResponsedSurveys", CreationCollisionOption.ReplaceExisting);

                    file = await folder.CreateFileAsync("ShareResponsedSurveys", CreationCollisionOption.ReplaceExisting);

                    surveys.Add(SelectedSurvey);
                    string content = Serializable_Survey.serialize(surveys);
                    await file.WriteAllTextAsync(content);
                }
            }
            await Task.Delay(500);

            await Navigation.PopAsync();
        }