private async void Delete_Item(int i)
        {
            var res = await DisplayAlert(Lang.Resource.titleMessage, Lang.Resource.DetailsDeleting, Lang.Resource.btnOkMessage, Lang.Resource.btnCancelMessage);

            if (res && CheckNetwork.Check_Connectivity())
            {
                stackQuestions.Children.RemoveAt(i + 1);
                survey.Questions_Property.RemoveAt(i);

                folder = FileSystem.Current.LocalStorage;

                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);
                foreach (Survey S in ListSurveys)
                {
                    if (S.Id == survey.Id)
                    {
                        S.Questions_Property = survey.Questions_Property;

                        SurveysServices S_S = new SurveysServices();
                        S_S.Set_UrlApi("EditSurveys/" + username);
                        await S_S.PutSurveysAsync(survey);

                        DrowItems(S);
                    }
                }
                content = Serializable_Survey.serialize(ListSurveys.ToList());
                await file.WriteAllTextAsync(content);
            }
        }
Exemplo n.º 2
0
 private async void SignUp_clicked(object sender, EventArgs e)
 {
     if (!CheckNetwork.Check_Connectivity())
     {
         return;
     }
     await Navigation.PushAsync(new SignUp(null));
 }
Exemplo n.º 3
0
        private async void signin_toolbar_Clicked(object sender, EventArgs e)
        {
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }

            //folder = FileSystem.Current.LocalStorage;
            //ExistenceCheckResult Resultfolder = await folder.CheckExistsAsync("folderAccount");
            //if (Resultfolder != ExistenceCheckResult.FolderExists)
            //{
            //    DependencyService.Get<SnackBar>().ShowSnackBar("Don't Have Any Account");
            //    return;
            //}
            //folder = await folder.CreateFolderAsync("folderAccount", CreationCollisionOption.OpenIfExists);
            //file = await folder.CreateFileAsync("fileAccount", CreationCollisionOption.OpenIfExists);

            //string Accounts = await file.ReadAllTextAsync();
            //if (Accounts == "")
            //{
            //    DependencyService.Get<SnackBar>().ShowSnackBar("Don't Have Any Account");
            //    return;
            //}
            //await Navigation.PushAsync(new SignIn());


            RegistersServices R_S           = new RegistersServices();
            List <User>       listregisters = await R_S.GetRegistersAsync();

            if (listregisters == null)
            {
                DependencyService.Get <SnackBar>().ShowSnackBar(Lang.Resource.NotFoundAccounts);
                return;
            }

            //folder = FileSystem.Current.LocalStorage;
            //ExistenceCheckResult Resultfolder = await folder.CheckExistsAsync("folderAccount");
            //if (Resultfolder != ExistenceCheckResult.FolderExists)
            //{
            //    DependencyService.Get<SnackBar>().ShowSnackBar("Don't Have Any Account");
            //    return;
            //}
            //folder = await folder.CreateFolderAsync("folderAccount", CreationCollisionOption.OpenIfExists);
            //file = await folder.CreateFileAsync("fileAccount", CreationCollisionOption.OpenIfExists);


            await Navigation.PushAsync(new SignIn());
        }
Exemplo n.º 4
0
        private async void SignIn_clicked(object sender, EventArgs e)
        {
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }

            RegistersServices R_S           = new RegistersServices();
            List <User>       listregisters = await R_S.GetRegistersAsync();

            if (listregisters == null || listregisters.Count == 0)
            {
                DependencyService.Get <SnackBar>().ShowSnackBar("Don't Have Any Account");
                return;
            }
            await Navigation.PushAsync(new SignIn());
        }
        private async void Save(object sender, EventArgs e)
        {
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }

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

            folder = FileSystem.Current.LocalStorage;
            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);
            foreach (Survey S in ListSurveys)
            {
                if (S.Id == survey.Id)
                {
                    S.Title_Property       = Title.Text;
                    S.Description_Property = Description.Text;

                    survey = S;
                    SurveysServices S_S = new SurveysServices();
                    S_S.Set_UrlApi("EditSurveys/" + username);
                    await S_S.PutSurveysAsync(survey);

                    break;
                }
            }
            title.Text       = Title.Text;
            description.Text = Description.Text;
            content          = Serializable_Survey.serialize(ListSurveys.ToList());
            await file.WriteAllTextAsync(content);

            Cancel(sender, e);

            await Task.Delay(500);

            ActivityIndicator.IsRunning = false;
            stackQuestions.Opacity      = 1;
        }
Exemplo n.º 6
0
        private async void Share_MenuItem_Clicked(object sender, EventArgs e)
        {
            var menuItem = sender as MenuItem;

            if (menuItem != null)
            {
                var survey = menuItem.BindingContext as Survey;
                var result = await DisplayAlert(Lang.Resource.sharing, Lang.Resource.detailsMessageShareSurvey + survey.Title_Property + Lang.Resource.survey, Lang.Resource.btnCancelMessage, Lang.Resource.btnOkMessage);

                if (result)
                {
                    return;
                }
                if (CheckNetwork.Check_Connectivity())
                {
                    await Navigation.PushModalAsync(new SharingPage(survey));
                }
            }
        }
Exemplo n.º 7
0
        private async void Sharing_Clicked(object sender, EventArgs e)
        {
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }
            if (countSelected == 0)
            {
                DependencyService.Get <SnackBar>().ShowSnackBar(Lang.Resource.NoAccountsSelected);
                return;
            }

            var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;

            player.Load("NotificationSend.mp3");
            player.Play();

            await((Image)sender).ScaleTo(0.8, 50, Easing.Linear);
            await Task.Delay(30);

            await((Image)sender).ScaleTo(1, 50, Easing.Linear);
            await((Image)sender).TranslateTo(-85, -200, 200, Easing.CubicIn);
            await((Image)sender).TranslateTo(0, -750, 100, Easing.CubicIn);

            _survey.Date_Property          = DateTime.Now.ToString();
            _survey.Number_of_Participants = SelectedUsers.Count;

            ActivityIndicator.IsRunning = true;
            contentpage.IsVisible       = false;


            for (int i = 0; i < SelectedUsers.Count; i++)
            {
                PostSurveysByNames(SelectedUsers.ElementAt(i).UserName_Property);
            }

            await Task.Delay(200);

            ActivityIndicator.IsRunning = false;
            contentpage.IsVisible       = true;
            await Navigation.PopModalAsync();
        }
Exemplo n.º 8
0
        private async void Delete_MenuItem_Clicked(object sender, EventArgs e)
        {
            var menuItem = sender as MenuItem;

            if (menuItem != null)
            {
                var survey = menuItem.BindingContext as Survey;
                var result = await DisplayAlert(Lang.Resource.deleting, Lang.Resource.detailsMessageDeleteSurvey + survey.Title_Property + Lang.Resource.survey, Lang.Resource.btnCancelMessage, Lang.Resource.btnOkMessage);

                if (result)
                {
                    return;
                }
                if (CheckNetwork.Check_Connectivity())
                {
                    SurveysServices S_S = new SurveysServices();
                    S_S.Set_UrlApi("DeleteSurvey/" + survey.Id + "/" + survey.User);
                    await S_S.DeleteSurveysAsync();

                    folder = FileSystem.Current.LocalStorage;
                    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).ToList();
                    for (int i = 0; i < ListSurveys.Count; i++)
                    {
                        if (ListSurveys[i].Id == survey.Id)
                        {
                            ListSurveys.RemoveAt(i);
                        }
                    }
                    content = Serializable_Survey.serialize(ListSurveys);
                    await file.WriteAllTextAsync(content);

                    Full_Lists_Surveys();
                }
            }
        }
        private async void GetSurveys()
        {
            string content;

            folder = FileSystem.Current.LocalStorage;
            if (CheckNetwork.Check_Connectivity())
            {
                ActivityIndicator.IsVisible    = true;
                ActivityIndicator.IsRunning    = true;
                contentpageEducation.IsVisible = false;

                SurveysServices S_S = new SurveysServices();
                S_S.Set_UrlApi("ReceiveSurveysShared/" + username);
                ReceivedSurveys = await S_S.GetSurveysAsync();

                ExistenceCheckResult result = await folder.CheckExistsAsync("Receivedsurveys");

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

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

                    content = await file.ReadAllTextAsync();

                    OldreceiveSurveys = Serializable_Survey.deserialize(content).ToList();
                    if (OldreceiveSurveys.Count < ReceivedSurveys.Count)
                    {
                        var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
                        player.Load("NotificationReceive.mp3");
                        player.Play();

                        Plugin.LocalNotifications.CrossLocalNotifications.Current.Show(Lang.Resource.receivesurveys, Lang.Resource.BodyreceiveSurvey, 0);
                    }
                }
                else if (result != ExistenceCheckResult.FolderExists && ReceivedSurveys.Count > 0)
                {
                    var player = Plugin.SimpleAudioPlayer.CrossSimpleAudioPlayer.Current;
                    player.Load("NotificationReceive.mp3");
                    player.Play();

                    Plugin.LocalNotifications.CrossLocalNotifications.Current.Show(Lang.Resource.receivesurveys, Lang.Resource.BodyreceiveSurvey, 0);
                }
            }
            else
            {
                ExistenceCheckResult Result = await folder.CheckExistsAsync("Receivedsurveys");

                if (Result == ExistenceCheckResult.FolderExists)
                {
                    ActivityIndicator.IsVisible    = true;
                    ActivityIndicator.IsRunning    = true;
                    contentpageEducation.IsVisible = false;

                    folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.OpenIfExists);

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

                    content = await file.ReadAllTextAsync();

                    ReceivedSurveys = Serializable_Survey.deserialize(content).ToList();

                    Full_Lists_Surveys();
                }
                else
                {
                    Full_Lists_Surveys();

                    ActivityIndicator.IsVisible = false;
                    ActivityIndicator.IsRunning = false;
                    await Task.Delay(200);

                    contentpageEducation.IsVisible = true;
                    return;
                }
            }
            if (ReceivedSurveys.Count == 0)
            {
                Full_Lists_Surveys();
                ActivityIndicator.IsVisible    = false;
                ActivityIndicator.IsRunning    = false;
                contentpageEducation.IsVisible = true;
                return;
            }
            else
            {
                folder = FileSystem.Current.LocalStorage;
                folder = await folder.CreateFolderAsync("Receivedsurveys", CreationCollisionOption.ReplaceExisting);

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

                content = Serializable_Survey.serialize(ReceivedSurveys);
                await file.WriteAllTextAsync(content);

                Full_Lists_Surveys();

                await Task.Delay(700);

                ActivityIndicator.IsVisible = false;
                ActivityIndicator.IsRunning = false;
                await Task.Delay(200);

                contentpageEducation.IsVisible = true;
            }
        }
Exemplo n.º 10
0
        private async void SignIn_clicked(object sender, EventArgs e)
        {
            if (ActivityIndicator.IsRunning)
            {
                return;
            }
            List <User> register = new List <User>();
            var         Email    = email.Text;
            var         Password = password.Text;

            if (String.IsNullOrWhiteSpace(Email) || String.IsNullOrWhiteSpace(Password))
            {
                check_inputs.Text = Lang.Resource.check_inputsSignin1;
                return;
            }
            if (Password.Length > 8)
            {
                check_inputs.Text = Lang.Resource.check_inputsSignin2;
                return;
            }
            if (Password.Contains("~") || Email.Contains("~"))
            {
                check_inputs.Text = Lang.Resource.check_inputsSignin3;
                return;
            }
            var emailpattern = "^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$";

            if (!String.IsNullOrWhiteSpace(Email) && !(Regex.IsMatch(Email, emailpattern)))
            {
                check_inputs.Text = Lang.Resource.check_inputsSignin4;
                return;
            }
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }

            ActivityIndicator.IsVisible = true;
            ActivityIndicator.IsRunning = true;
            contentpage.Opacity         = 0.5;

            RegistersServices R_S       = new RegistersServices();
            List <User>       registers = await R_S.GetRegistersBykeywordAsync(Email.Substring(0, Email.IndexOf(".")));

            if (registers != null)
            {
                if (registers.Count > 0 && registers.ElementAt(0).Email_Property == Email)
                {
                    FileAndFolderUser(registers.ElementAt(0));
                    await Task.Delay(500);

                    await Navigation.PopToRootAsync();
                }
                else
                {
                    ActivityIndicator.IsVisible = false;
                    ActivityIndicator.IsRunning = false;
                    contentpage.Opacity         = 1;
                    check_inputs.Text           = Lang.Resource.check_inputsSignin5;
                    return;
                }
            }
            await Task.Delay(500);

            ActivityIndicator.IsVisible = false;
            ActivityIndicator.IsRunning = false;
            contentpage.Opacity         = 1;
        }
Exemplo n.º 11
0
        private async void SaveData_Activated(object sender, EventArgs e)
        {
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }
            string inputs = questionEntry.Text + minvalue.Text + maxvalue.Text;

            if (String.IsNullOrWhiteSpace(inputs) || inputs.Contains("~"))
            {
                checkinputs.Text = Lang.Resource.check_inputsSignin3;
                return;
            }
            Slider_Question question = new Slider_Question(TypeQuestion.Slider, questionEntry.Text);

            question.Create_question(Int32.Parse(minvalue.Text), Int32.Parse(maxvalue.Text), switchRequireAnswer.IsToggled);

            // 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)
                    {
                        Slider_Question slider = new Slider_Question(TypeQuestion.Slider, questionEntry.Text);

                        slider.title      = questionEntry.Text;
                        slider.requireAns = switchRequireAnswer.IsToggled;
                        slider.min_value  = Int32.Parse(minvalue.Text);
                        slider.max_value  = Int32.Parse(maxvalue.Text);
                        (S.Questions_Property.ElementAt(_index) as Slider_Question).Edit_question(slider);
                        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();
        }
Exemplo n.º 12
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);
        }
Exemplo n.º 13
0
        private async void Get_Surveys()
        {
            try
            {
                ActivityIndicator.IsRunning    = true;
                contentpageEducation.IsVisible = false;

                folder = FileSystem.Current.LocalStorage;
                ExistenceCheckResult Resultfolder = await folder.CheckExistsAsync("folderUser");

                if (Resultfolder != ExistenceCheckResult.FolderExists)
                {
                    await Navigation.PushAsync(new Login());

                    return;
                }

                username = await controlFile.GetUserName();

                Resultfolder = await folder.CheckExistsAsync("foldersurveys" + username);

                if (Resultfolder != ExistenceCheckResult.FolderExists)
                {
                    if (!CheckNetwork.Check_Connectivity())
                    {
                        await Task.Delay(700);

                        ActivityIndicator.IsRunning    = false;
                        contentpageEducation.IsVisible = true;
                        return;
                    }
                    SurveysServices S_S1 = new SurveysServices();
                    S_S1.Set_UrlApi("ReceiveMySurveysSaved/" + username);
                    ListSurveys = await S_S1.GetSurveysAsync();

                    if (ListSurveys == null || ListSurveys.Count == 0)
                    {
                        await Task.Delay(700);

                        ActivityIndicator.IsRunning    = false;
                        contentpageEducation.IsVisible = true;
                        return;
                    }

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

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

                    string Content = Serializable_Survey.serialize(ListSurveys);
                    await file.WriteAllTextAsync(Content);

                    stackEducation.IsVisible = false;

                    Full_Lists_Surveys();

                    await Task.Delay(700);

                    ActivityIndicator.IsRunning    = false;
                    contentpageEducation.IsVisible = true;
                    return;
                }
                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).ToList();

                if (ListSurveys == null || ListSurveys.Count == 0)
                {
                    await Task.Delay(700);

                    ActivityIndicator.IsRunning    = false;
                    contentpageEducation.IsVisible = true;
                    return;
                }
                stackEducation.IsVisible = false;

                Full_Lists_Surveys();

                await Task.Delay(700);

                ActivityIndicator.IsRunning    = false;
                contentpageEducation.IsVisible = true;
            }
            catch (Exception ex)
            {
                ActivityIndicator.IsVisible = false;
                ActivityIndicator.IsRunning = false;
                DependencyService.Get <SnackBar>().ShowSnackBar("Error ... cann't access to device storage");
            }
        }
        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();
        }
Exemplo n.º 15
0
        private async void SignUp_clicked(object sender, EventArgs e)
        {
            string userName = username.Text;
            string Email    = email.Text;
            string Password = password.Text;
            string Age      = age.Text;

            if (String.IsNullOrWhiteSpace(Age) || String.IsNullOrWhiteSpace(Email) || String.IsNullOrWhiteSpace(userName) || String.IsNullOrWhiteSpace(Password))
            {
                check_inputs.Text = Lang.Resource.check_inputsSignin1;
                return;
            }
            if (Password.Length > 8)
            {
                check_inputs.Text = Lang.Resource.check_inputsSignin2;
                return;
            }
            string Check = userName + Email + Password + Age;

            if (Check.Contains("~"))
            {
                check_inputs.Text = Lang.Resource.check_inputsSignin3;
                return;
            }
            var emailpattern = "^([\\w\\.\\-]+)@([\\w\\-]+)((\\.(\\w){2,3})+)$";

            if (!String.IsNullOrWhiteSpace(Email) && !(Regex.IsMatch(Email, emailpattern)))
            {
                check_inputs.Text = Lang.Resource.check_inputsSignin4;
                return;
            }
            var confirmpassword = verifypassword.Text;

            if (confirmpassword != Password)
            {
                check_inputs.Text = Lang.Resource.confirmPassword;
                return;
            }
            if (!CheckNetwork.Check_Connectivity())
            {
                return;
            }

            ActivityIndicator.IsVisible = true;
            ActivityIndicator.IsRunning = true;
            contentpage.Opacity         = 0.5;

            // Folder Accounts
            folder = FileSystem.Current.LocalStorage;
            ExistenceCheckResult Result = await folder.CheckExistsAsync("folderAccount");

            if (Result != ExistenceCheckResult.FolderExists)
            {
                folder = await folder.CreateFolderAsync("folderAccount", CreationCollisionOption.ReplaceExisting);
            }
            else
            {
                folder = await folder.CreateFolderAsync("folderAccount", CreationCollisionOption.OpenIfExists);
            }

            //file = await folder.GetFileAsync("fileAccount");
            //await file.DeleteAsync();
            //return;

            //string serialize; Register r;
            //Result = await folder.CheckExistsAsync("fileAccount");
            //if (Result != ExistenceCheckResult.FileExists)
            //{
            //    //  File Accounts
            //    file = await folder.CreateFileAsync("fileAccount", CreationCollisionOption.ReplaceExisting);
            //    r = new Register(userName, Password, "khalil", Email, DateTime.Now.ToString());
            //    register.Add(r);
            //    serialize = Serializable_Account.serialize(register);
            //    await file.WriteAllTextAsync(serialize);

            //    // Folder And File  User
            //    FileAndFolderUser(serialize);

            //    await Navigation.PopToRootAsync();
            //    return;
            //}
            //file = await folder.CreateFileAsync("fileAccount", CreationCollisionOption.OpenIfExists);
            //string Accounts = await file.ReadAllTextAsync();
            //if (Accounts == "")
            //{
            //    r = new Register(userName, Password, "khalil", Email, DateTime.Now.ToString());
            //    register.Add(r);
            //    serialize = Serializable_Account.serialize(register);
            //    await file.WriteAllTextAsync(serialize);
            //    // Folder And File  User
            //    FileAndFolderUser(serialize);

            //    await Navigation.PopToRootAsync();
            //    return;
            //}
            //register = Serializable_Account.deserialize(Accounts);
            //foreach (Register R in register)
            //{
            //    if (userName.Equals(R.UserName_Property) || Email.Equals(R.Email_Property))
            //    {
            //        check_inputs.Text = "there are same UserName or Email ...";
            //        return;
            //    }
            //}
            //r = new Register(userName, Password, "khalil", Email, DateTime.Now.ToString());
            //register.Add(r);
            //serialize = Serializable_Account.serialize(register);
            //await file.WriteAllTextAsync(serialize);
            //// Folder And File  User
            //register.Clear();
            //register.Add(r);
            //serialize = Serializable_Account.serialize(register);
            //FileAndFolderUser(serialize);

            RegistersServices R_S = new RegistersServices();

            string      _email        = Email.Substring(0, Email.IndexOf("."));
            User        user          = null;
            List <User> listregisters = new List <User>();

            if (register == null)
            {
                listregisters = await R_S.GetRegistersBykeywordAsync(_email);

                if (listregisters.Count == 0)
                {
                    user = new User(userName, Password, Email, Int32.Parse(Age), country, DateTime.Now.ToString().Substring(0, 10));
                    await R_S.PostRegistersAsync(user);

                    listregisters.Add(user);
                    string serialize = Serializable_Account.serialize(listregisters);
                    FileAndFolderUser(serialize);
                    await Task.Delay(500);

                    await Navigation.PopToRootAsync();
                }
                else
                {
                    check_inputs.Text           = Lang.Resource.username_same_email;
                    ActivityIndicator.IsVisible = false;
                    ActivityIndicator.IsRunning = false;
                    contentpage.Opacity         = 1;
                    return;
                }
            }
            else
            {
                user = new User(userName, Password, Email, Int32.Parse(Age), country, register.Date);
                R_S.Set_UrlApi("Edit/");
                await R_S.PutRegistersAsync(user);

                listregisters.Add(user);
                string serialize = Serializable_Account.serialize(listregisters);
                FileAndFolderUser(serialize);
                await Task.Delay(500);

                await Navigation.PopModalAsync();
            }
        }
Exemplo n.º 16
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();
        }