Exemplo n.º 1
0
        public SamplesRadio()
        {
            Padding = new Thickness(20);
            RadioGroupDemoViewModel rr = new RadioGroupDemoViewModel();


            BindableRadioGroup dd = new BindableRadioGroup {
                ItemsSource = rr.MyList.Values,

//					SelectedIndex="{Binding SelectedIndex}" VerticalOptions="Start" />
            };


            Content = new StackLayout {
                Children =
                {
                    dd
                }
            };
        }
Exemplo n.º 2
0
        public DeliveryView(List <Basket> basketList, double total)
        {
            Total           = total;
            _basketList     = basketList;
            VerticalOptions = LayoutOptions.FillAndExpand;

            Label lblSort = new Label {
                Text            = "Способ доставки:",
                VerticalOptions = LayoutOptions.CenterAndExpand
            };
            StackLayout titleSortLayout = new StackLayout {
                BackgroundColor = ApplicationStyle.LineColor,
                HeightRequest   = Utils.GetSize(22),
                Padding         = new Thickness(8, 0),
                Children        =
                {
                    lblSort
                }
            };

            radioList = new BindableRadioGroup {
                Spacing         = 1,
                BackgroundColor = Color.White,
                TextColor       = ApplicationStyle.TextColor,
                Padding         = new Thickness(8, 0, 0, 0)
            };
            radioList.CheckedChanged += (sender, e) => {
                var radio = sender as CustomRadioButton;
                if (radio == null || radio.Id == -1)
                {
                    return;
                }
                selectDelivery = radio.Text;
            };

            StackLayout bottomLayout = new StackLayout {
                BackgroundColor = ApplicationStyle.LineColor,
                HeightRequest   = Utils.GetSize(22),
                Padding         = new Thickness(8, 0),
                Children        =
                {
                }
            };

            Switch elSwitch = new Switch {
                VerticalOptions   = LayoutOptions.CenterAndExpand,
                HorizontalOptions = LayoutOptions.EndAndExpand
            };

            elSwitch.Toggled += OnClickDataTrue;

            StackLayout layoutSwitch = new StackLayout {
                Padding       = new Thickness(8, 0),
                Orientation   = StackOrientation.Horizontal,
                HeightRequest = Utils.GetSize(43),
                Children      =
                {
                    new Label {
                        Text            = "Данные указаны верно",
                        VerticalOptions = LayoutOptions.CenterAndExpand,
                        TextColor       = ApplicationStyle.TextColor,
                    },
                    elSwitch
                }
            };

            editorComment = new MyEditor {
                //VerticalOptions = LayoutOptions.FillAndExpand,
                TextColor        = ApplicationStyle.TextColor,
                Placeholder      = "Оставить комментарий к заказу",
                PlaceholderColor = ApplicationStyle.LabelColor,
                FontSize         = Utils.GetSize(14),
                HeightRequest    = 100
            };
            editorComment.Focused   += OnTextFocused;
            editorComment.Unfocused += OnTextUnFocused;

            entCoupon = new MyEntry {
                PlaceholderColor  = ApplicationStyle.LabelColor,
                Placeholder       = "Введите код на скидку",
                HorizontalOptions = LayoutOptions.FillAndExpand,
                VerticalOptions   = LayoutOptions.FillAndExpand,
                Margin            = new Thickness(0),
                Padding           = new Thickness(0),
            };

            MyButton btnCoupon = new MyButton {
                BackgroundColor = ApplicationStyle.LineColor,
                TextColor       = ApplicationStyle.LabelColor,
                UseWithTextBox  = true,
                FontSize        = 14,
                Text            = "Применить",
                WidthRequest    = 114,
            };

            btnCoupon.Clicked += CouponClick;;

            StackLayout layoutBtnCoupon = new StackLayout {
                BackgroundColor = ApplicationStyle.LineColor,
                WidthRequest    = 114,
                Margin          = new Thickness(1)
            };

            StackLayout layoutCoupon = new StackLayout {
                HeightRequest = 30,
                Orientation   = StackOrientation.Horizontal,
                Children      =
                {
                    entCoupon,
                    btnCoupon
                }
            };
            CustomFrame frameCoupon = new CustomFrame {
                OutlineColor      = ApplicationStyle.LineColor,
                OutlineWidth      = 2,
                HeightRequest     = 31,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HasShadow         = false,
                Content           = layoutCoupon,
                Padding           = new Thickness(0),
                Margin            = new Thickness(8, 18)
            };


            Label lblTitleMessageOrder = new Label {
                VerticalOptions = LayoutOptions.Center,
                TextColor       = ApplicationStyle.TextColor,
                Text            = "Сумма заказа"
            };
            Label lblMessageOrder = new Label {
                TextColor         = ApplicationStyle.TextColor,
                VerticalOptions   = LayoutOptions.Center,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                Text = Total + " р."
            };
            StackLayout layoutSumOrder = new StackLayout {
                VerticalOptions = LayoutOptions.Center,
                Orientation     = StackOrientation.Horizontal,
                HeightRequest   = Constants.HeightRowListView,
                Padding         = new Thickness(8, 0),
                Children        =
                {
                    lblTitleMessageOrder,
                    lblMessageOrder
                }
            };

            Label lblTitleMessageCoupon = new Label {
                VerticalOptions = LayoutOptions.Center,
                TextColor       = ApplicationStyle.TextColor,
                Text            = "Скидка по купону"
            };

            lblMessageCoupon = new Label {
                TextColor         = ApplicationStyle.TextColor,
                HorizontalOptions = LayoutOptions.EndAndExpand,
                VerticalOptions   = LayoutOptions.Center,
            };
            StackLayout layoutSumCoupon = new StackLayout {
                Orientation   = StackOrientation.Horizontal,
                HeightRequest = Constants.HeightRowListView,
                Padding       = new Thickness(8, 0),
                Children      =
                {
                    lblTitleMessageCoupon,
                    lblMessageCoupon
                }
            };

            lblCouponMeassage = new Label {
                TextColor = ApplicationStyle.RedColor,
                IsVisible = false
            };
            layoutCouponInfo = new StackLayout {
                Spacing   = 0,
                IsVisible = false,
                Children  =
                {
                    new BoxView(),
                    layoutSumOrder,
                    new BoxView(),
                    layoutSumCoupon,
                    new BoxView(),
                }
            };
            indicatorCoupon = new ActivityIndicator {
                Color           = Device.OnPlatform(Color.Black, Color.Gray, Color.Default),
                IsRunning       = true,
                IsVisible       = false,
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };

            StackLayout layoutCouponMain = new StackLayout {
                Padding  = new Thickness(8, 0),
                Children =
                {
                    lblCouponMeassage,
                    layoutCouponInfo,
                    indicatorCoupon
                }
            };

            layoutBody = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Spacing         = 0,
                Children        =
                {
                    titleSortLayout,
                    radioList,
                    bottomLayout,
                    editorComment,
                    new StackLayout {
                        BackgroundColor = ApplicationStyle.LineColor,
                        HeightRequest   = Utils.GetSize(22),
                        Padding         = new Thickness(8,  0),
                        Children        =
                        {
                        }
                    },
                    frameCoupon,
                    layoutCouponMain,
                    layoutSwitch,
                }
            };
            double heightBot  = Utils.GetSize(49);
            Grid   gridBottom = new Grid {
                Padding         = new Thickness(0),
                HeightRequest   = heightBot,
                VerticalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions  =
                {
                    new RowDefinition {
                        Height = heightBot,
                    }
                },
                RowSpacing        = 0,
                ColumnDefinitions =
                {
                    new ColumnDefinition {
                        Width = new GridLength(50, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(50, GridUnitType.Star)
                    },
                },
                BackgroundColor = Color.White,
            };

            lblTotal = new Label {
                FontSize                = 24,
                TextColor               = ApplicationStyle.GreenColor,
                VerticalOptions         = LayoutOptions.CenterAndExpand,
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                HorizontalTextAlignment = TextAlignment.Center,
                FontAttributes          = FontAttributes.Bold,
                Text = Total + "р."
            };
            btnOrder = new Button {
                Text              = "Оформить",
                FontSize          = Utils.GetSize(18),
                TextColor         = Color.White,
                BackgroundColor   = ApplicationStyle.LabelColor,
                HorizontalOptions = LayoutOptions.FillAndExpand,
                HeightRequest     = heightBot,
                BorderRadius      = 0,
            };
            btnOrder.Clicked += ClickCheckOut;

            gridBottom.Children.Add(lblTotal, 0, 0);
            gridBottom.Children.Add(btnOrder, 1, 0);

            StackLayout layoutBottom = new StackLayout {
                Spacing  = 0,
                Children =
                {
                    new BoxView {
                        VerticalOptions = LayoutOptions.EndAndExpand
                    },
                    gridBottom
                }
            };

            scrollBody = new ScrollView {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Content         = layoutBody
            };
            mainGrid = new Grid {
                VerticalOptions = LayoutOptions.FillAndExpand,
                RowDefinitions  =
                {
                    new RowDefinition {
                        Height = new GridLength(100, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = Utils.GetSize(50),
                    },
                },
                BackgroundColor = Color.Green
            };
            mainGrid.Children.Add(scrollBody, 0, 0);
            mainGrid.Children.Add(layoutBottom, 0, 1);

            layoutMain = new StackLayout {
                VerticalOptions = LayoutOptions.FillAndExpand,
                Spacing         = 0,
                Children        =
                {
                    scrollBody,
                    layoutBottom,
                }
            };
            indicator = new ActivityIndicator {
                Color           = Device.OnPlatform(Color.Black, Color.Gray, Color.Default),
                IsRunning       = true,
                IsVisible       = true,
                VerticalOptions = LayoutOptions.CenterAndExpand,
            };

            Content = indicator;
            SetDeliveryAsync();
        }
        /// <summary>
        /// Todays Timetable
        /// </summary>
        public void TodaysTimetableLayout()
        {
            try
            {
                TitleBar lblPageName = new TitleBar("Today's TimeTable");
                StackLayout slTitle = new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    Padding = new Thickness(0, 5, 0, 0),
                    BackgroundColor = Color.White,
                    Children = { lblPageName }
                };

                Seperator spTitle = new Seperator();

                BindableRadioGroup radByTeacherOrClass = new BindableRadioGroup();

                radByTeacherOrClass.ItemsSource = new[] { "By Teacher", "By Class" };
                radByTeacherOrClass.HorizontalOptions = LayoutOptions.FillAndExpand;
                radByTeacherOrClass.Orientation = StackOrientation.Horizontal;
                radByTeacherOrClass.TextColor = Color.Black;

                StackLayout slRadio = new StackLayout
                {
                    Children = { radByTeacherOrClass },
                    HorizontalOptions = LayoutOptions.FillAndExpand
                };

                #region By Teacher

                Image imgTeacherDropDown = new Image { Source = Constants.ImagePath.DropDownArrow, HorizontalOptions = LayoutOptions.EndAndExpand };
                Label lblTeacher = new Label { TextColor = Color.Black, Text = "Teacher" };
                Picker pcrTeacher = new Picker { IsVisible = false, Title = "Teacher" };

                StackLayout slTeacherDisplay = new StackLayout { Children = { lblTeacher, pcrTeacher, imgTeacherDropDown }, Orientation = StackOrientation.Horizontal, Padding = new Thickness(Device.OnPlatform(0, 5, 0), Device.OnPlatform(0, 5, 0), Device.OnPlatform(0, 10, 0), Device.OnPlatform(0, 5, 0)) };

                Frame frmTeacher = new Frame
                {
                    Content = slTeacherDisplay,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    OutlineColor = Color.Black,
                    Padding = new Thickness(10)
                };

                var teacherTap = new TapGestureRecognizer();

                teacherTap.NumberOfTapsRequired = 1; // single-tap
                teacherTap.Tapped += (s, e) =>
                {
                    pcrTeacher.Focus();
                };
                frmTeacher.GestureRecognizers.Add(teacherTap);
                slTeacherDisplay.GestureRecognizers.Add(teacherTap);

                StackLayout slTeacherFrameLayout = new StackLayout
                {
                    Children = { frmTeacher }
                };

                StackLayout slTeacherLayout = new StackLayout
                {
                    Children = { slTeacherFrameLayout },
                    Orientation = StackOrientation.Vertical,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    IsVisible = false
                };

                Label lblStandardName = new Label
                {
                    Text = "Standard Name",
                    TextColor = Color.Black
                };

                StackLayout slStandardName = new StackLayout
                {
                    Children = { lblStandardName },
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                };

                Label lblClassTypeName = new Label
                {
                    Text = "Class Type Name",
                    TextColor = Color.Black
                };

                StackLayout slClassTypeName = new StackLayout
                {
                    Children = { lblClassTypeName },
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand
                };

                Label lblStubjectName = new Label
                {
                    Text = "Subject Name",
                    TextColor = Color.Black
                };

                StackLayout slSubjectName = new StackLayout
                {
                    Children = { lblStubjectName },
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.EndAndExpand
                };
                #endregion

                #region By Class

                Image imgStandardDropDown = new Image { Source = Constants.ImagePath.DropDownArrow, HorizontalOptions = LayoutOptions.EndAndExpand };
                Label lblStandard = new Label { TextColor = Color.Black, Text = "Standard" };
                Picker pcrStandard = new Picker { IsVisible = false, Title = "Standard" };

                StackLayout slStandardDisplay = new StackLayout { Children = { lblStandard, pcrStandard, imgStandardDropDown }, Orientation = StackOrientation.Horizontal, Padding = new Thickness(Device.OnPlatform(0, 5, 0), Device.OnPlatform(0, 5, 0), Device.OnPlatform(0, 10, 0), Device.OnPlatform(0, 5, 0)) };

                Frame frmStandard = new Frame
                {
                    Content = slStandardDisplay,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    OutlineColor = Color.Black,
                    Padding = new Thickness(10)
                };

                var standardTap = new TapGestureRecognizer();

                standardTap.NumberOfTapsRequired = 1; // single-tap
                standardTap.Tapped += (s, e) =>
                {
                    pcrStandard.Focus();
                };
                frmStandard.GestureRecognizers.Add(standardTap);
                slStandardDisplay.GestureRecognizers.Add(standardTap);

                StackLayout slStandardFrameLayout = new StackLayout
                {
                    Children = { frmStandard }
                };

                StackLayout slStandardLayout = new StackLayout
                {
                    Children = { slStandardFrameLayout },
                    Orientation = StackOrientation.Vertical,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                };

                Image imgClassDropDown = new Image { Source = Constants.ImagePath.DropDownArrow, HorizontalOptions = LayoutOptions.EndAndExpand };
                Label lblClass = new Label { TextColor = Color.Black, Text = "Class" };
                Picker pcrClass = new Picker { IsVisible = false, Title = "Class" };

                StackLayout slClassDisplay = new StackLayout { Children = { lblClass, pcrClass, imgClassDropDown }, Orientation = StackOrientation.Horizontal, Padding = new Thickness(Device.OnPlatform(0, 5, 0), Device.OnPlatform(0, 5, 0), Device.OnPlatform(0, 10, 0), Device.OnPlatform(0, 5, 0)) };

                Frame frmClass = new Frame
                {
                    Content = slClassDisplay,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    OutlineColor = Color.Black,
                    Padding = new Thickness(10)
                };

                var classTap = new TapGestureRecognizer();

                classTap.NumberOfTapsRequired = 1; // single-tap
                classTap.Tapped += (s, e) =>
                {
                    pcrClass.Focus();
                };
                frmClass.GestureRecognizers.Add(classTap);
                slClassDisplay.GestureRecognizers.Add(classTap);

                StackLayout slClassFrameLayout = new StackLayout
                {
                    Children = { frmClass }
                };

                StackLayout slClassLayout = new StackLayout
                {
                    Children = { slClassFrameLayout },
                    Orientation = StackOrientation.Vertical,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    IsVisible = false
                };

                //Grid Header
                Label lblTeachername = new Label
                {
                    Text = "Teacher Name",
                    TextColor = Color.Black
                };

                StackLayout slTeacherName = new StackLayout
                {
                    Children = { lblTeachername },
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.CenterAndExpand
                };

                Label lblStubject = new Label
                {
                    Text = "Subject Name",
                    TextColor = Color.Black
                };

                StackLayout slSubject = new StackLayout
                {
                    Children = { lblStubject },
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.EndAndExpand
                };

                #endregion

                Label lblSequensNo = new Label
                {
                    Text = "No",
                    TextColor = Color.Black
                };

                StackLayout slSequensNo = new StackLayout
                {
                    Children = { lblSequensNo },
                    VerticalOptions = LayoutOptions.CenterAndExpand,
                    HorizontalOptions = LayoutOptions.StartAndExpand
                };

                StackLayout grid = new StackLayout
                {
                    //Children = { slTeacherName, slSequensNo, slSubjectName },
                    Orientation = StackOrientation.Horizontal,
                    IsVisible = false
                };

                Seperator spDisplayHeader = new Seperator { IsVisible = false };

                StackLayout slSearchinOneCol = new StackLayout
                {
                    Children = { slStandardLayout, slClassLayout },
                    Orientation = StackOrientation.Horizontal,
                    IsVisible = false
                };

                _NotAvailData = new Label { Text = "No data availalble for this search data.", TextColor = Color.Red, IsVisible = false };

                _Loader = new LoadingIndicator();

                radByTeacherOrClass.CheckedChanged += (sender, e) =>
                    {
                        Device.BeginInvokeOnMainThread(async () =>
                       {
                           var radio = sender as CustomRadioButton;

                           if (radio == null || radio.Id == -1)
                           {
                               return;
                           }

                           if (radio.Text == "By Teacher")
                           {
                               slTeacherLayout.IsVisible = true;
                               slSearchinOneCol.IsVisible = false;

                               foreach (TeacherModel item in _TeacherList)
                               {
                                   pcrTeacher.Items.Add(item.Name);
                               }

                               grid.Children.Add(slSequensNo);
                               grid.Children.Add(slStandardDisplay);
                               grid.Children.Add(slClassTypeName);
                               grid.Children.Add(slSubjectName);

                           }
                           else
                           {
                               slSearchinOneCol.IsVisible = true;
                               slTeacherLayout.IsVisible = false;

                               grid.Children.Add(slSequensNo);
                               grid.Children.Add(slTeacherName);
                               grid.Children.Add(slSubject);

                               _StatndardList = await StandardModel.GetStandard();

                               foreach (StandardModel item in _StatndardList)
                               {
                                   pcrStandard.Items.Add(item.Name);
                               }
                           }
                       });
                    };

                //List view
                ListView TimeTableListView = new ListView
                {
                    RowHeight = 50,
                    SeparatorColor = Color.Gray
                };

                TimeTableListView.ItemTemplate = new DataTemplate(() => new FillUpAttendanceCell());

                pcrStandard.SelectedIndexChanged += (sender, e) =>
                {
                    Device.BeginInvokeOnMainThread(async () =>
                    {
                        try
                        {
                            _Loader.IsShowLoading = true;
                            pcrClass.Items.Clear();

                            string standardName = lblStandard.Text = pcrStandard.Items[pcrStandard.SelectedIndex];

                            _SelectedStandardID = _StatndardList.Where(x => x.Name == standardName).FirstOrDefault().Id;

                            _ClassTypeList = await ClassTypeModel.GetClassType(_SelectedStandardID);

                            if (_ClassTypeList.Count > 0 && _ClassTypeList != null)
                            {
                                slClassLayout.IsVisible = true;
                                _NotAvailData.IsVisible = false;
                            }
                            else
                            {
                                slClassLayout.IsVisible = false;
                                _NotAvailData.IsVisible = true;
                            }

                            foreach (ClassTypeModel item in _ClassTypeList)
                            {
                                pcrClass.Items.Add(item.Name);
                            }

                            _Loader.IsShowLoading = false;
                        }
                        catch (Exception ex)
                        {

                        }
                    });
                };

                //Class Picker Selected

                pcrClass.SelectedIndexChanged += (sender, e) =>
                {
                    Device.BeginInvokeOnMainThread(async () =>
                    {
                        _Loader.IsShowLoading = true;
                        _NotAvailData.IsVisible = false;

                        string className = lblClass.Text = pcrClass.Items[pcrClass.SelectedIndex];

                        _SelectedClassTypeID = _ClassTypeList.FirstOrDefault(x => x.Name == className).Id;

                        //Get time table list
                        _TimeTableList = await TimeTableModel.ShowTimeTable(_SelectedStandardID, _SelectedClassTypeID);

                        if (_TimeTableList != null && _TimeTableList.Count > 0)
                        {
                            grid.IsVisible = true;
                            spDisplayHeader.IsVisible = true;
                            Items = new ObservableCollection<TimeTableModel>(_TimeTableList);
                            TimeTableListView.ItemsSource = Items;
                        }
                        else
                        {
                            grid.IsVisible = false;
                            spDisplayHeader.IsVisible = false;
                            _NotAvailData.Text = "There is no data for selected standard and class.";
                            _NotAvailData.IsVisible = true;
                        }
                        _Loader.IsShowLoading = false;
                    });
                };

                //Class Picker Selected

                pcrTeacher.SelectedIndexChanged += (sender, e) =>
                {
                    Device.BeginInvokeOnMainThread(async () =>
                    {
                        _Loader.IsShowLoading = true;
                        _NotAvailData.IsVisible = false;

                        string teacherName = lblTeacher.Text = pcrTeacher.Items[pcrTeacher.SelectedIndex];

                        _SelectedTeacherID = _TeacherList.FirstOrDefault(x => x.Name == teacherName).ID;

                        //Get time table list
                        _TimeTableList = await TimeTableModel.ShowTimeTable(_SelectedTeacherID);

                        if (_TimeTableList != null && _TimeTableList.Count > 0)
                        {
                            grid.IsVisible = true;
                            spDisplayHeader.IsVisible = true;
                            Items = new ObservableCollection<TimeTableModel>(_TimeTableList);
                            TimeTableListView.ItemsSource = Items;
                        }
                        else
                        {
                            grid.IsVisible = false;
                            spDisplayHeader.IsVisible = false;
                            _NotAvailData.Text = "There is no data for selected standard and class.";
                            _NotAvailData.IsVisible = true;
                        }
                        _Loader.IsShowLoading = false;
                    });
                };

                StackLayout slTimeTable = new StackLayout
                {
                    Children = { 
                        new StackLayout{
                            Padding = new Thickness(20, Device.OnPlatform(40,20,0), 20, 20),
						    Children = {slTitle, spTitle.LineSeperatorView,slRadio,slTeacherLayout, slSearchinOneCol,grid,spDisplayHeader.LineSeperatorView, _Loader, _NotAvailData,TimeTableListView},
                            VerticalOptions = LayoutOptions.FillAndExpand,
                        },
                    },
                    BackgroundColor = LayoutHelper.PageBackgroundColor
                };

                Content = new ScrollView
                {
                    Content = slTimeTable,
                };
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 4
0
        public QuizView()
        {
            BackgroundColor = backgroundColor;

            var logo = new Label()
            {
                Text                    = "MemoBicho",
                TextColor               = textColor,
                FontSize                = 40,
                FontAttributes          = FontAttributes.Bold,
                HorizontalTextAlignment = TextAlignment.Center
            };

            var questionsLayout = new StackLayout()
            {
                Padding = 10
            };

            questionsLayout.Children.Add(logo);
            questionsLayout.Children.Add(new Label()
            {
                Text      = "Quiz",
                FontSize  = 25,
                TextColor = textColor,
                HorizontalTextAlignment = TextAlignment.Center
            });

            foreach (var question in questionsAndAnswers)
            {
                var questionLayout = new StackLayout()
                {
                    Padding = 10
                };
                questionLayout.Children.Add(new Label()
                {
                    Text           = question.Key, FontSize = 27,
                    TextColor      = textColor,
                    FontAttributes = FontAttributes.Bold
                });

                var answersButtons = new BindableRadioGroup();
                foreach (var questionAnswers in possibleAnswers.Where(a => a.Key == question.Key).Select(a => a.Value))
                {
                    answersButtons.ItemsSource = questionAnswers.ToArray();
                    foreach (var answerButton in answersButtons.Items) // The button belongs to a question
                    {
                        answerButton.ClassId   = question.Key;
                        answerButton.FontSize  = 22;
                        answerButton.TextColor = textColor;
                    }
                }

                questionLayout.Children.Add(answersButtons);
                questionsLayout.Children.Add(questionLayout);
            }

            var submitButton = new Button
            {
                Text            = "Submeter respostas!", FontSize = 25,
                BackgroundColor = buttonBackgroundColor,
                FontAttributes  = FontAttributes.Bold
            };

            submitButton.Clicked += async delegate
            {
                int score = 0;
                foreach (StackLayout questionLayout in questionsLayout.Children
                         .Where(q => q.GetType() == new StackLayout().GetType()))
                {
                    foreach (BindableRadioGroup answersButtons in questionLayout.Children
                             .Where(q => q.GetType() == new BindableRadioGroup().GetType()))
                    {
                        foreach (CustomRadioButton answerButton in answersButtons.Items)
                        {
                            if (answerButton.Checked)
                            {
                                if (questionsAndAnswers.Where(q => q.Key == answerButton.ClassId)
                                    .FirstOrDefault().Value == answerButton.Text) // If correct answer
                                {
                                    score++;
                                    answerButton.TextColor = Color.Lime;
                                }
                                else
                                {
                                    answerButton.TextColor = Color.Red;
                                }
                            }
                        }
                    }
                }
                var result = await DisplayAlert("Legal, você completou o seu primeiro questionário!", "Você pontuou "
                                                + score + " em " + ((questionsLayout.Children.Count - 2) - 1) + " questões.", "Resultado", "Próximo nível");

                if (!result.Equals(true))
                {
                    await Task.Run(() =>
                    {
                        this.Navigation.PopModalAsync();
                        Device.BeginInvokeOnMainThread(() => this.Navigation.PushModalAsync(new GridLayoutPage2()));
                    });
                }
            };

            questionsLayout.Children.Add(submitButton);

            var scrollView = new ScrollView();

            scrollView.Content = questionsLayout;

            Content = scrollView;
        }
Exemplo n.º 5
0
        public void TestExamLayout(SubjectTakensModel subjectTakenModel)
        {
            if (ACTContext.isLogin == true)
            {
                #region header text
                Label lblTestScreenHeaderText = new Label {
                    Text = "Mock Test", HorizontalOptions = LayoutOptions.CenterAndExpand, TextColor = Color.White, FontSize = 20, FontAttributes = FontAttributes.Bold
                };
                StackLayout sLblTestScreenHeaderText = new StackLayout
                {
                    Children    = { lblTestScreenHeaderText },
                    Orientation = StackOrientation.Horizontal,
                    Padding     = new Thickness(0, 50, 0, 0)
                };
                #endregion

                #region start button
                StackLayout sbtnStartTest = new StackLayout
                {
                    Children    = { btnStartTest },
                    Orientation = StackOrientation.Horizontal,
                    Padding     = new Thickness(20, 10, 2, 8)
                };
                btnStartTest.Clicked += (object sender, EventArgs e) =>
                {
                    btnStartTest.IsVisible        = false;
                    slblQuestion.IsVisible        = true;
                    bRadioAnswerOptions.IsVisible = true;
                    sbtnSubmitAnswer.IsVisible    = true;
                    sbtnSubmitAnswer2.IsVisible   = true;
                };
                #endregion

                #region time remaining
                if (countQuestion == 0)
                {
                    Device.StartTimer(new TimeSpan(0, 0, 1), () =>
                    {
                        if (btnStartTest.IsVisible == false)
                        {
                            if (examRemainingSecond <= 0 && examReamainingMinute <= 0 && examRemainigHour <= 0)
                            {
                                return(false);
                            }
                            if (examRemainingSecond <= 0 && examReamainingMinute <= 0)
                            {
                                examRemainingSecond              = 61;
                                examReamainingMinute             = 61;
                                lblTestScreenTimeReamaining.Text = "Time remaining : " + --examRemainigHour + " Hours " + --examReamainingMinute + " Minutes " + --examRemainingSecond + " Seconds";
                                return(true);
                            }
                            if (examRemainingSecond <= 0)
                            {
                                examRemainingSecond = 61;
                                lblTestScreenTimeReamaining.Text = "Time remaining : " + examRemainigHour + " Hours " + --examReamainingMinute + " Minutes " + --examRemainingSecond + " Seconds";
                                return(true);
                            }


                            lblTestScreenTimeReamaining.Text = "Time remaining : " + examRemainigHour + " Hours " + examReamainingMinute + " Minutes " + --examRemainingSecond + " Seconds";
                        }
                        return(true);
                    });
                    sLblTestScreenTimeRemaining = new StackLayout
                    {
                        Children    = { lblTestScreenTimeReamaining },
                        Orientation = StackOrientation.Horizontal,
                        Padding     = new Thickness(0, 30, 0, 10)
                    };
                }
                #endregion

                #region Question

                List <QuestionsModel> setOfQuestions = new List <QuestionsModel>();
                setOfQuestions = subjectTakenModel.QuestionsList;

                Label lblQuestion = new Label {
                    HorizontalOptions = LayoutOptions.StartAndExpand, TextColor = Color.White, FontSize = 15, FontAttributes = FontAttributes.None
                };
                if (setOfQuestions.Count >= countQuestion + 1)
                {
                    lblQuestion.Text = setOfQuestions[countQuestion].QuestionText;
                }
                else
                {
                    lblQuestion.Text = "";
                }
                slblQuestion = new StackLayout
                {
                    Children    = { lblQuestion },
                    Orientation = StackOrientation.Horizontal,
                    Padding     = new Thickness(20, 10, 20, 0)
                };

                #endregion

                #region answers
                CustomRadioButton radioAnswerOption1 = new CustomRadioButton();
                CustomRadioButton radioAnswerOption2 = new CustomRadioButton();
                CustomRadioButton radioAnswerOption3 = new CustomRadioButton();
                CustomRadioButton radioAnswerOption4 = new CustomRadioButton();
                if (setOfQuestions.Count >= countQuestion + 1)
                {
                    radioAnswerOption1.Text = setOfQuestions[countQuestion].OptionsList[0].OptionText;
                    radioAnswerOption2.Text = setOfQuestions[countQuestion].OptionsList[1].OptionText;
                    radioAnswerOption3.Text = setOfQuestions[countQuestion].OptionsList[2].OptionText;
                    radioAnswerOption4.Text = setOfQuestions[countQuestion].OptionsList[3].OptionText;

                    bRadioAnswerOptions = new BindableRadioGroup()
                    {
                        Orientation = StackOrientation.Vertical,
                        Padding     = new Thickness(20, 10, 20, 5)
                    };
                    bRadioAnswerOptions.ItemsSource = new[]
                    {
                        radioAnswerOption1.Text,
                        radioAnswerOption2.Text,
                        radioAnswerOption3.Text,
                        radioAnswerOption4.Text
                    };
                    bRadioAnswerOptions.CheckedChanged += BRadioAnswerOptions_CheckedChanged;
                }
                else
                {
                    radioAnswerOption1.Text = "";
                    radioAnswerOption2.Text = "";
                    radioAnswerOption3.Text = "";
                    radioAnswerOption4.Text = "";

                    slblQuestion.IsVisible        = false;
                    bRadioAnswerOptions.IsVisible = false;
                    sbtnSubmitAnswer.IsVisible    = false;
                    sbtnSubmitAnswer2.IsVisible   = false;
                }


                #endregion

                #region submit button
                Button btnSubmitAnswer = new Button {
                    Text = "Next", HorizontalOptions = LayoutOptions.StartAndExpand, BackgroundColor = Color.FromHex("4690FB"), TextColor = Color.White, BorderRadius = 10, WidthRequest = 100, FontAttributes = FontAttributes.Bold
                };
                Button btnCancelExam = new Button {
                    Text = "End test", HorizontalOptions = LayoutOptions.CenterAndExpand, BackgroundColor = Color.FromHex("4690FB"), TextColor = Color.White, BorderRadius = 10, WidthRequest = 100, FontAttributes = FontAttributes.Bold
                };
                Button btnBackToPreviousQuestion = new Button {
                    Text = "Previous", HorizontalOptions = LayoutOptions.EndAndExpand, BackgroundColor = Color.FromHex("4690FB"), TextColor = Color.White, BorderRadius = 10, WidthRequest = 100, FontAttributes = FontAttributes.Bold
                };
                sbtnSubmitAnswer = new StackLayout
                {
                    Children    = { btnSubmitAnswer, btnBackToPreviousQuestion },
                    Orientation = StackOrientation.Horizontal,
                    Padding     = new Thickness(20, 10, 2, 8)
                };
                sbtnSubmitAnswer2 = new StackLayout
                {
                    Children    = { btnCancelExam },
                    Orientation = StackOrientation.Horizontal,
                    Padding     = new Thickness(0, 5, 0, 5)
                };
                if (countQuestion == 0)
                {
                    btnBackToPreviousQuestion.IsEnabled = false;
                }
                btnBackToPreviousQuestion.Clicked += (object sender, EventArgs e) =>
                {
                    if (countQuestion > 1)
                    {
                        countQuestion--;
                        TestExamLayout(subjectTakenModel);
                    }
                };
                btnSubmitAnswer.Clicked += (object sender, EventArgs e) =>
                {
                    subjectTakenModel.CandidateId = 1;
                    subjectTakenModel.BatchId     = 6;
                    subjectTakenModel.QuestionId  = setOfQuestions[countQuestion].QuestionId;
                    if (_selectedRadio == "first")
                    {
                        subjectTakenModel.SelectedAnswerId = setOfQuestions[countQuestion].OptionsList[0].OptionId;
                    }
                    else if (_selectedRadio == "second")
                    {
                        subjectTakenModel.SelectedAnswerId = setOfQuestions[countQuestion].OptionsList[1].OptionId;
                    }
                    else if (_selectedRadio == "third")
                    {
                        subjectTakenModel.SelectedAnswerId = setOfQuestions[countQuestion].OptionsList[2].OptionId;
                    }
                    else if (_selectedRadio == "fourth")
                    {
                        subjectTakenModel.SelectedAnswerId = setOfQuestions[countQuestion].OptionsList[3].OptionId;
                    }
                    else
                    {
                        subjectTakenModel.SelectedAnswerId = 0;
                        unAnswered++;
                    }
                    _selectedRadio = "";

                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        var result = await Service.SaveAnswer(subjectTakenModel);
                    });
                    countQuestion++;
                    TestExamLayout(subjectTakenModel);
                };
                #endregion

                #region stack and content layouts

                Label lblAfterExamResponse = new Label {
                    HorizontalOptions = LayoutOptions.CenterAndExpand, TextColor = Color.FromHex("7AD169"), FontSize = 17, FontAttributes = FontAttributes.None
                };

                lblAfterExamResponse.IsVisible = false;

                if (btnStartTest.IsVisible == true)
                {
                    slblQuestion.IsVisible        = false;
                    bRadioAnswerOptions.IsVisible = false;
                    sbtnSubmitAnswer.IsVisible    = false;
                    sbtnSubmitAnswer2.IsVisible   = false;
                }

                if (slblQuestion.IsVisible == false && bRadioAnswerOptions.IsVisible == false && btnStartTest.IsVisible == false)
                {
                    sbtnSubmitAnswer.IsVisible     = false;
                    sbtnSubmitAnswer2.IsVisible    = false;
                    lblAfterExamResponse.IsVisible = true;
                    string result = "";
                    Device.BeginInvokeOnMainThread(async() =>
                    {
                        result = await Service.CalculateCandidateTestResult(subjectTakenModel);

                        lblTestScreenTimeReamaining.IsVisible = false;
                        TimeSpan finishedTime     = new TimeSpan(examRemainigHour, examReamainingMinute, examRemainingSecond);
                        TimeSpan startedTime      = new TimeSpan(subjectTakenModel.ExamDuration / 60, subjectTakenModel.ExamDuration / 60, 0);
                        lblAfterExamResponse.Text =
                            "Test finished. Thank you\n\nRight answers : "
                            + result.ToString()
                            + "\n\nWrong answers : " + (subjectTakenModel.QuestionsList.Count - int.Parse(result)) + "\n\nUnattended : " + (unAnswered++) + "\n\nPercentage : "
                            + ((int.Parse(result) * 100) / subjectTakenModel.QuestionsList.Count) +
                            "%\n\nTime taken : " + startedTime.Subtract(finishedTime);
                    });
                }

                StackLayout slTestScreen = new StackLayout
                {
                    Children = { sLblTestScreenHeaderText,    sbtnStartTest,
                                 sLblTestScreenTimeRemaining, slblQuestion,     bRadioAnswerOptions,
                                 sbtnSubmitAnswer,            sbtnSubmitAnswer2,lblAfterExamResponse },
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand,
                    Padding           = new Thickness(20, 0, 20, 0),
                    BackgroundColor   = Color.Gray
                };

                ScrollView svTestScreenDetails = new ScrollView {
                    Content = slTestScreen
                };

                Content = svTestScreenDetails;
                #endregion
            }
            else
            {
                Navigation.PushModalAsync(new Login());
            }
        }
Exemplo n.º 6
0
        private void Setup()
        {
            SizeChanged += OnSizeChanged;
            StackLayout layout = new StackLayout
            {
                Padding = new Thickness(20, 28),
                Spacing = 0
                          //VerticalOptions = LayoutOptions.Center,
            };

            layout.Children.Add(
                new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Children    =
                {
                    // Section
                    new Label {
                        Text              = "Section " + question.section.Label + ": " + question.section.Title,
                        FontAttributes    = FontAttributes.Bold,
                        HorizontalOptions = LayoutOptions.StartAndExpand
                    },
                    // Question Number
                    new Label {
                        Text = "Question " + question.numberString,
                        HorizontalOptions = LayoutOptions.EndAndExpand,
                        XAlign            = TextAlignment.End,
                        FontAttributes    = FontAttributes.Bold
                    }
                }
            }
                );

            // Part
            if (question.SectionPartId != null)
            {
                layout.Children.Add(
                    new StackLayout
                {
                    Orientation = StackOrientation.Horizontal,
                    Children    =
                    {
                        new Label {
                            Text = "Part " + question.part.Label + ": " + question.part.Description
                        }
                    }
                });
            }

            layout.Children.Add(LayoutHelper.GetVerticalSpacing(20));
            layout.Children.Add(LayoutHelper.GetHorizontalLine());

            // Question text
            layout.Children.Add(
                new StackLayout
            {
                BackgroundColor = Color.FromHex("#ffd758"),
                Padding         = new Thickness(10, 20, 10, 20),
                Children        =
                {
                    new Label {
                        Text           = (textOverride == null) ? question.Text.Trim() : textOverride,
                        FontAttributes = FontAttributes.Italic
                    }
                }
            });
            layout.Children.Add(LayoutHelper.GetHorizontalLine());

            //Add Edit Comment Button
            Button commentButton = new Button();

            commentButton.Text              = "Add/Edit Comment For Question";
            commentButton.FontAttributes    = FontAttributes.Italic;
            commentButton.Clicked          += openCommentPage;
            commentButton.HorizontalOptions = LayoutOptions.End;
            layout.Children.Add(commentButton);

            layout.Children.Add(LayoutHelper.GetVerticalSpacing(5));

            //Answer
            score = inspection.GetScoreForQuestion(question);
            if (score != null)
            {
                HasScore = true;
                var answer = EnumDescriptionAttribute.GetDescriptionFromEnumValue(score.answer);
            }
            else
            {
                HasScore = false;
            }

            // Answers - Radio Group
            var answers          = Enum.GetValues(typeof(Answer)).Cast <Answer>().ToList();
            var answerRadioGroup = new BindableRadioGroup
            {
                ItemsSource   = answers.Select(x => EnumDescriptionAttribute.GetDescriptionFromEnumValue(x)),
                SelectedIndex = HasScore == true?answers.FindIndex(x => x.Equals(score.answer)) : -1
            };

            answerRadioGroup.Spacing         = 12;
            answerRadioGroup.CheckedChanged += answerRadioGroup_CheckedChanged;
            answerRadioGroup.ItemUnchecked  += answerRadioGroup_Unchecked;

            layout.Children.Add(new StackLayout
            {
                Children = { answerRadioGroup }
            });

            layout.Children.Add(LayoutHelper.GetVerticalSpacing(25));

            // References label
            layout.Children.Add(new Label
            {
                Text           = "References:",
                FontAttributes = FontAttributes.Bold
            });
            layout.Children.Add(LayoutHelper.GetVerticalSpacing(5));
            layout.Children.Add(LayoutHelper.GetHorizontalLine());

            //References buttons
            List <Reference> references = question.References;

            if (extraReferences != null)
            {                           //Creates a copy of the list so we aren't adding to the original.
                references = references.ToList();
                references.AddRange(extraReferences);
            }

            foreach (Reference reference in references)
            {
                var referenceButton = new ReferenceButton(reference)
                {
                    folderName = inspection.ChecklistId, FontAttributes = FontAttributes.Italic, HorizontalOptions = LayoutOptions.StartAndExpand
                };
                layout.Children.Add(
                    new StackLayout
                {
                    Orientation   = StackOrientation.Horizontal,
                    Padding       = new Thickness(24, 0),
                    HeightRequest = 30,
                    Children      =
                    {
                        new Label {
                            TextColor = Color.FromHex("#2b90ff"), FontSize = 40, XAlign = TextAlignment.Center, Text = "\u2022"
                        },
                        LayoutHelper.GetHorizontalSpacing(8),
                        referenceButton
                    }
                });
            }
            layout.Children.Add(LayoutHelper.GetVerticalSpacing(25));


            //Remarks label
            layout.Children.Add(new Label
            {
                Text           = "Remarks:",
                FontAttributes = FontAttributes.Bold
            });

            //Remarks box
            remarksBox = new Editor();
            remark     = inspection.GetRemarkForQuestion(question);
            if (App.IsPortrait(this))
            {
                remarksBox.HeightRequest = 300;
            }
            else
            {
                remarksBox.HeightRequest = 100;
            }
            if (remark == null)
            {
                remarksBox.Text     = string.Empty;
                question.OldRemarks = string.Empty;
            }
            else
            {
                remarksBox.Text     = remark.remark;
                question.OldRemarks = remark.remark;
            }
            remarksBox.TextChanged += SaveRemarksText;
            layout.Children.Add(remarksBox);

            ScrollView scroll = new ScrollView();

            scroll.Content = layout;

            Device.BeginInvokeOnMainThread(() =>
            {
                Content = scroll;
            });
        }