Exemple #1
0
            public VoteQuestion(VoteQuestionTable VQ_)
            {
                VQ       = VQ_;
                Question = VQ.Question;



                Box = new BoxView
                {
                    BackgroundColor   = Color.White,
                    WidthRequest      = 200,
                    HeightRequest     = 30 + Label.HeightRequest,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    ClassId           = VQ.ID.ToString(),
                    Margin            = 0,
                };
                Label = new Label
                {
                    Text = Question,
                    HorizontalTextAlignment = TextAlignment.Center,
                    VerticalTextAlignment   = TextAlignment.Start,
                    FontSize        = 25,
                    FontAttributes  = FontAttributes.Bold,
                    WidthRequest    = 200,
                    VerticalOptions = LayoutOptions.StartAndExpand,
                    HeightRequest   = ((Question.Length / 30)) * 50 + 70,
                    TextColor       = Color.Black,
                    ClassId         = JsonConvert.SerializeObject(VQ),
                    Margin          = 6,
                };
                Label.GestureRecognizers.Add(TGR);
            }
Exemple #2
0
        public async void SubmitQ(object sender, EventArgs e)
        {
            if (Question.Text != "" && Op1.Text != "" && Op2.Text != "" && Question.Text != null && Op1.Text != null && Op2.Text != null && Op3.Text != null && Op4.Text != null)
            {
                var VQ = new VoteQuestionTable();

                VQ.Question    = Question.Text;
                VQ.Option1     = Op1.Text;
                VQ.Option2     = Op2.Text;
                VQ.Option3     = Op3.Text;
                VQ.Option4     = Op4.Text;
                VQ.Posted      = DateTime.Now;
                VQ.Stage       = 1;
                VQ.TotalVotes1 = 0;
                VQ.TotalVotes2 = 0;
                VQ.TotalVotes3 = 0;
                VQ.TotalVotes4 = 0;
                VQ.Winner      = 0;
                App.database.InsertVoteQuestion(VQ);
                await DisplayAlert("Snyggt!", "Din fråga har skickats in.", "Okej");
            }
            else
            {
                await DisplayAlert("Något gick fel", "Kolla om någon textruta är tom!", "Okej");
            }
        }
        public VoteDisplayPage(VoteQuestionTable VQ, int argc)
        {
            InitializeComponent();
            Question.ClassId = VQ.ID.ToString();
            Question.Text    = VQ.Question;
            Op1.Text         = VQ.Option1;
            Op2.Text         = VQ.Option2;
            Op3.Text         = VQ.Option3;
            Op4.Text         = VQ.Option4;

            Op1.BackgroundColor = App.MC;
            Op2.BackgroundColor = App.MC;
            Op3.BackgroundColor = App.MC;
            Op4.BackgroundColor = App.MC;
            Op1.TextColor       = Color.White;
            Op2.TextColor       = Color.White;
            Op3.TextColor       = Color.White;
            Op4.TextColor       = Color.White;

            Question.TextColor = App.MC;

            int TV1 = 0;
            int TV2 = 0;
            int TV3 = 0;
            int TV4 = 0;

            if (argc == 1)
            {
                VoteCheck(VQ.ID);
            }
            else if (argc == 2)
            {
                VoteCheck(VQ.ID);
                Op1.IsEnabled = false;
                Op2.IsEnabled = false;
                Op3.IsEnabled = false;
                Op4.IsEnabled = false;


                var Votelist = App.database.GetVotes(VQ.ID);

                foreach (VoteTable Vote in Votelist)
                {
                    switch (Vote.ChoosenOption)
                    {
                    case 1:
                        TV1++;
                        break;

                    case 2:
                        TV2++;
                        break;

                    case 3:
                        TV3++;
                        break;

                    case 4:
                        TV4++;
                        break;
                    }
                }
                var TVMax = Math.Max(TV1, Math.Max(TV2, Math.Max(TV3, TV4)));
                if (TVMax == TV1)
                {
                    Question.Text = "Val '" + VQ.Option1 + "' leder röstningen";
                }
                else if (TVMax == TV2)
                {
                    Question.Text = "Val '" + VQ.Option2 + "' leder röstningen";
                }
                else if (TVMax == TV3)
                {
                    Question.Text = "Val '" + VQ.Option3 + "' leder röstningen";
                }
                else if (TVMax == TV4)
                {
                    Question.Text = "Val '" + VQ.Option4 + "' leder röstningen";
                }



                Op1.Text = TV1.ToString();
                Op2.Text = TV2.ToString();
                Op3.Text = TV3.ToString();
                Op4.Text = TV4.ToString();
            }
            else if (argc == 3)
            {
                Op1.IsEnabled = false;
                Op2.IsEnabled = false;
                Op3.IsEnabled = false;
                Op4.IsEnabled = false;
            }
        }