示例#1
0
        public DiscountDetailPage(DiscountDetailData discountDetailData)
            : base(typeof(DiscountDetailViewModel), typeof(DiscountDetailContentUI))
        {
            BackgroundColor         = MainStyles.StatusBarColor.FromResources <Color>();
            Content.BackgroundColor = MainStyles.MainLightBackgroundColor.FromResources <Color>();

            viewModel.SetDiscount(discountDetailData);

            var mainLayout = new AbsoluteLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            var appBar = new TitleBar(this, TitleBar.BarBtnEnum.bbBack)
            {
                BarColor   = Color.Transparent,
                BoxPadding =
                {
                    BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>()
                },
                BtnBack =
                {
                    BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>(),
                    Source          = contentUI.IconBack
                }
            };

            #region Photo

            var imageLayout = new RelativeLayout
            {
                HeightRequest = Device.Idiom == TargetIdiom.Phone ? 200 : 400
            };

            var fileNameConverter = new FileNameToImageConverter();
            var imgPhoto          = new Image
            {
                Aspect = Aspect.AspectFill
            };
            imgPhoto.SetBinding(Image.SourceProperty,
                                new Binding("ImageFileName", BindingMode.Default, fileNameConverter, true));

            imageLayout.Children.Add(imgPhoto,
                                     Constraint.Constant(0),
                                     Constraint.Constant(0),
                                     Constraint.RelativeToParent(parent => parent.Width),
                                     Constraint.RelativeToParent(parent => parent.Height));

            #endregion

            #region Label percent

            const int sizeImgLabel = 60;

            var imgLabel = new Image
            {
                HeightRequest = sizeImgLabel,
                WidthRequest  = sizeImgLabel,
                Source        = contentUI.ImgPercentLabel
            };

            var labelLayout = new AbsoluteLayout();
            AbsoluteLayout.SetLayoutFlags(imgLabel, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(imgLabel, new Rectangle(0f, 0f, 1f, 1f));
            labelLayout.Children.Add(imgLabel);

            imageLayout.Children.Add(labelLayout,
                                     Constraint.RelativeToParent(parent => parent.Width - sizeImgLabel - 5),
                                     Constraint.RelativeToView(imgPhoto,
                                                               (parent, sibling) => sibling.Y + sibling.Height - sizeImgLabel - 5));

            var spanDiscountPercent = new Span
            {
                Style = LabelStyles.LabelPercentStyle.FromResources <Style>()
            };
            spanDiscountPercent.SetBinding(Span.TextProperty, "DiscountPercent", BindingMode.OneWay);

            var spanDiscountType = new Span
            {
                Style = LabelStyles.LabelPercentSymbolStyle.FromResources <Style>()
            };
            spanDiscountType.SetBinding(Span.TextProperty, "DiscountType", BindingMode.OneWay);

            var txtPercent = new Label
            {
                Rotation      = -15,
                TranslationY  = -1,
                FormattedText = new FormattedString
                {
                    Spans =
                    {
                        spanDiscountPercent,
                        spanDiscountType
                    }
                }
            };

            AbsoluteLayout.SetLayoutFlags(txtPercent, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(txtPercent,
                                           new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            labelLayout.Children.Add(txtPercent);

            #endregion

            #region WebAddress & Category list

            var flexCategories = new FlexLayout
            {
                Direction      = FlexDirection.Row,
                Wrap           = FlexWrap.Wrap,
                JustifyContent = FlexJustify.Start,
                AlignItems     = FlexAlignItems.Center,
                AlignContent   = FlexAlignContent.Start,
                Margin         = new Thickness(20, 15, 15, 0)
            };

            foreach (var webAddress in viewModel.WebAddresses)
            {
                var imgWebAddress = new Image
                {
                    Source = webAddress.Type.GetWebAddressIcon()
                };

                var viewGesturesWebAddress = new ViewGestures
                {
                    Content         = imgWebAddress,
                    AnimationEffect = ViewGestures.AnimationType.atScaling,
                    AnimationScale  = -5,
                    Tag             = webAddress.Url,
                    Margin          = new Thickness(0, 0, 5, 5)
                };
                viewGesturesWebAddress.Tap += viewModel.TxtUrlAddress_Click;

                flexCategories.Children.Add(viewGesturesWebAddress);
            }

            var flexSeparator = new ContentView();
            FlexLayout.SetGrow(flexSeparator, 1);
            flexCategories.Children.Add(flexSeparator);

            foreach (var category in viewModel.Categories)
            {
                var categoryLayout = new CategoryItemTemplate
                {
                    Margin         = new Thickness(0, 0, 5, 5),
                    BindingContext = category
                };

                flexCategories.Children.Add(categoryLayout);
            }

            #endregion

            #region Name company

            var txtPartnerName = new Label
            {
                Style = LabelStyles.DetailTitleStyle.FromResources <Style>()
            };
            txtPartnerName.SetBinding(Label.TextProperty, "NameCompany");

            #endregion

            #region Description

            var txtDescription = new Label
            {
                Style         = LabelStyles.DescriptionStyle.FromResources <Style>(),
                LineBreakMode = LineBreakMode.WordWrap
            };
            txtDescription.SetBinding(Label.TextProperty, "Description");

            #endregion

            var stackDetails = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                Padding     = new Thickness(20, 0),
                Children    =
                {
                    txtPartnerName,
                    txtDescription
                }
            };

            var discountLayout = new StackLayout
            {
                Spacing     = 0,
                Orientation = StackOrientation.Vertical,
                Children    =
                {
                    imageLayout,
                    flexCategories,
                    stackDetails
                }
            };

            foreach (var brachItem in viewModel.BranchItems)
            {
                var view = new BranchInfoViewTemplate(contentUI, viewModel).View;
                view.BindingContext = brachItem;

                discountLayout.Children.Add(view);
            }

            var scrollDiscount = new ScrollView
            {
                Content = discountLayout
            };

            AbsoluteLayout.SetLayoutFlags(scrollDiscount, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(scrollDiscount, new Rectangle(0f, 0f, 1f, 1f));
            mainLayout.Children.Add(scrollDiscount);

            AbsoluteLayout.SetLayoutFlags(appBar,
                                          AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);
            AbsoluteLayout.SetLayoutBounds(appBar, new Rectangle(0f, 0f, 1f, AbsoluteLayout.AutoSize));
            mainLayout.Children.Add(appBar);

            var safeAreaHelper = new SafeAreaHelper();
            safeAreaHelper.UseSafeArea(this, SafeAreaHelper.CustomSafeAreaFlags.Top);
            safeAreaHelper.UseSafeArea(appBar.BtnBack, SafeAreaHelper.CustomSafeAreaFlags.Left);
            safeAreaHelper.UseSafeArea(scrollDiscount, SafeAreaHelper.CustomSafeAreaFlags.Horizontal);

            ContentLayout.Children.Add(mainLayout);
        }
        public DiscountDetailPage(DiscountDetailData discountDetailData)
            : base(typeof(DiscountDetailViewModel), typeof(DiscountDetailContentUI))
        {
            BackgroundColor         = MainStyles.StatusBarColor.FromResources <Color>();
            Content.BackgroundColor = MainStyles.MainLightBackgroundColor.FromResources <Color>();

            var loadingColor = MainStyles.LoadingColor.FromResources <Color>();

            LoadingActivityIndicator.Color = loadingColor;
            LoadingActivityText.TextColor  = loadingColor;

            viewModel.SetDiscount(discountDetailData);

            var mainLayout = new AbsoluteLayout
            {
                VerticalOptions = LayoutOptions.FillAndExpand
            };

            var appBar = new TitleBar(this, TitleBar.BarBtnEnum.bbBack)
            {
                BarColor   = Color.Transparent,
                BoxPadding =
                {
                    BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>()
                },
                BtnBack =
                {
                    BackgroundColor = MainStyles.StatusBarColor.FromResources <Color>(),
                    Source          = contentUI.IconBack
                }
            };

            #region Label percent

            const int sizeImgLabel = 60;

            var imgLabel = new Image
            {
                HeightRequest = sizeImgLabel,
                WidthRequest  = sizeImgLabel,
                Source        = contentUI.ImgPercentLabel
            };

            var labelLayout = new AbsoluteLayout
            {
                InputTransparent = true
            };
            AbsoluteLayout.SetLayoutFlags(imgLabel, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(imgLabel, new Rectangle(0f, 0f, 1f, 1f));
            labelLayout.Children.Add(imgLabel);

            var spanDiscountPercent = new Span
            {
                Style = LabelStyles.LabelPercentStyle.FromResources <Style>()
            };
            spanDiscountPercent.SetBinding(Span.TextProperty, nameof(DiscountDetailViewModel.DiscountPercent));

            var spanDiscountType = new Span
            {
                Style = LabelStyles.LabelPercentSymbolStyle.FromResources <Style>()
            };
            spanDiscountType.SetBinding(Span.TextProperty, nameof(DiscountDetailViewModel.DiscountType));

            var txtPercent = new Label
            {
                Rotation      = -15,
                TranslationY  = -1,
                FormattedText = new FormattedString
                {
                    Spans =
                    {
                        spanDiscountPercent,
                        spanDiscountType
                    }
                }
            };

            AbsoluteLayout.SetLayoutFlags(txtPercent, AbsoluteLayoutFlags.PositionProportional);
            AbsoluteLayout.SetLayoutBounds(txtPercent,
                                           new Rectangle(0.5, 0.5, AbsoluteLayout.AutoSize, AbsoluteLayout.AutoSize));
            labelLayout.Children.Add(txtPercent);

            #endregion

            #region WebAddress & Category list

            var flexCategories = new FlexLayout
            {
                Direction      = FlexDirection.Row,
                Wrap           = FlexWrap.Wrap,
                JustifyContent = FlexJustify.Start,
                AlignItems     = FlexAlignItems.Center,
                AlignContent   = FlexAlignContent.Start,
                Margin         = new Thickness(20, 15, 15, 0)
            };

            const int sizeWebAddress = 40;

            foreach (var webAddress in viewModel.WebAddresses)
            {
                var imgWebAddress = new Image
                {
                    Source        = webAddress.Type.GetWebAddressIcon(),
                    Margin        = new Thickness(0, 0, 5, 5),
                    WidthRequest  = sizeWebAddress,
                    HeightRequest = sizeWebAddress
                };

                var tapWebAddress = new TapGestureRecognizer
                {
                    CommandParameter = webAddress.Url
                };
                tapWebAddress.Tapped += viewModel.TxtUrlAddress_Click;

                imgWebAddress.GestureRecognizers.Add(tapWebAddress);

                flexCategories.Children.Add(imgWebAddress);
            }

            var flexSeparator = new ContentView();
            FlexLayout.SetGrow(flexSeparator, 1);
            flexCategories.Children.Add(flexSeparator);

            foreach (var category in viewModel.Categories)
            {
                var categoryLayout = new CategoryItemTemplate
                {
                    Margin         = new Thickness(0, 0, 5, 5),
                    BindingContext = category
                };

                flexCategories.Children.Add(categoryLayout);
            }

            #endregion

            #region Carousel images

            var carouselView = new CarouselViewControl
            {
                Orientation  = CarouselViewOrientation.Horizontal,
                ItemTemplate = new DataTemplate(typeof(GalleryImageItemTemplate)),
                CurrentPageIndicatorTintColor = MainStyles.MainBackgroundColor.FromResources <Color>()
            };
            carouselView.SetBinding(CarouselViewControl.ItemsSourceProperty,
                                    nameof(DiscountDetailViewModel.GalleryImages));
            carouselView.SetBinding(CarouselViewControl.ShowIndicatorsProperty,
                                    nameof(DiscountDetailViewModel.HasGalleryImages));
            carouselView.SetBinding(CarouselViewControl.IsSwipeEnabledProperty,
                                    nameof(DiscountDetailViewModel.HasGalleryImages));

            var carouselLayout = new RelativeLayout
            {
                VerticalOptions = LayoutOptions.Start
            };

            carouselLayout.Children.Add(carouselView,
                                        Constraint.Constant(0),
                                        Constraint.Constant(0),
                                        Constraint.RelativeToParent(parent => parent.Width),
                                        Constraint.RelativeToParent(parent =>
                                                                    Device.Info.CurrentOrientation.IsPortrait() ? parent.Width * 0.5625 :
                                                                    Device.Idiom == TargetIdiom.Phone ? 200 : 400));

            carouselLayout.Children.Add(labelLayout,
                                        Constraint.RelativeToView(carouselView, (parent, view) => view.Width - sizeImgLabel - 5),
                                        Constraint.RelativeToView(carouselView, (parent, view) => view.Height - sizeImgLabel - 5));

            #endregion

            #region Name company

            var txtPartnerName = new Label
            {
                Style  = LabelStyles.DetailTitleStyle.FromResources <Style>(),
                Margin = new Thickness(20, 0)
            };
            txtPartnerName.SetBinding(Label.TextProperty, nameof(DiscountDetailViewModel.NameCompany));

            #endregion

            #region Description

            var txtDescription = new Label
            {
                Style         = LabelStyles.DescriptionStyle.FromResources <Style>(),
                Margin        = new Thickness(20, 10, 20, 0),
                LineBreakMode = LineBreakMode.WordWrap
            };
            txtDescription.SetBinding(Label.TextProperty, nameof(DiscountDetailViewModel.Description));

            #endregion

            #region Rating view

            var ratingView = new RatingView
            {
                Style = LabelStyles.RatingStyle.FromResources <Style>()
            };
            ratingView.SetBinding(RatingView.ValueProperty, nameof(DiscountDetailViewModel.UserRating));

            var ratingLabel = new Label
            {
                Style           = LabelStyles.DescriptionStyle.FromResources <Style>(),
                VerticalOptions = LayoutOptions.End
            };
            ratingLabel.SetBinding(Label.TextProperty, nameof(DiscountDetailViewModel.RatingString));
            ratingLabel.SetBinding(IsVisibleProperty, nameof(DiscountDetailViewModel.IsDiscountRatingAvailable));

            var activityIndicator = new ActivityIndicator
            {
                Color             = Color.FromHex("444"),
                HorizontalOptions = LayoutOptions.Center,
                VerticalOptions   = LayoutOptions.End,
                WidthRequest      = 20,
                HeightRequest     = 20
            };
            activityIndicator.SetBinding(ActivityIndicator.IsRunningProperty, nameof(DiscountDetailViewModel.IsLoadingRating));
            activityIndicator.SetBinding(IsVisibleProperty, nameof(DiscountDetailViewModel.IsLoadingRating));

            var stackRating = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                Margin      = new Thickness(20, 0),
                Spacing     = 10,
                Children    =
                {
                    ratingView,
                    ratingLabel,
                    activityIndicator
                }
            };

            #endregion

            var discountLayout = new StackLayout
            {
                Spacing     = 0,
                Orientation = StackOrientation.Vertical,
                Children    =
                {
                    carouselLayout,
                    flexCategories,
                    txtPartnerName,
                    stackRating,
                    txtDescription
                }
            };

            foreach (var brachItem in viewModel.BranchItems)
            {
                var view = new BranchInfoViewTemplate(contentUI, viewModel)
                {
                    BindingContext = brachItem
                };

                discountLayout.Children.Add(view);
            }

            var scrollDiscount = new ScrollView
            {
                Content = discountLayout
            };

            AbsoluteLayout.SetLayoutFlags(scrollDiscount, AbsoluteLayoutFlags.All);
            AbsoluteLayout.SetLayoutBounds(scrollDiscount, new Rectangle(0f, 0f, 1f, 1f));
            mainLayout.Children.Add(scrollDiscount);

            AbsoluteLayout.SetLayoutFlags(appBar,
                                          AbsoluteLayoutFlags.PositionProportional | AbsoluteLayoutFlags.WidthProportional);
            AbsoluteLayout.SetLayoutBounds(appBar, new Rectangle(0f, 0f, 1f, AbsoluteLayout.AutoSize));
            mainLayout.Children.Add(appBar);

            var safeAreaHelper = new SafeAreaHelper();
            safeAreaHelper.UseSafeArea(this, SafeAreaHelper.CustomSafeAreaFlags.Top);
            safeAreaHelper.UseSafeArea(appBar.BtnBack, SafeAreaHelper.CustomSafeAreaFlags.Left);
            safeAreaHelper.UseSafeArea(scrollDiscount, SafeAreaHelper.CustomSafeAreaFlags.Horizontal);

            ContentLayout.Children.Add(mainLayout);
        }
示例#3
0
        public DiscountDetailData LoadDiscountDetail(string ID)
        {
            DiscountDetailData discountDetail = new DiscountDetailData();

            var discountRec = (from d in database.Table <Discount>()
                               where d.DocumentId == ID
                               select d).FirstOrDefault();

            if (discountRec == null)
            {
                return(null);
            }

            discountDetail.Persent       = discountRec.PercentValue;
            discountDetail.UrlAddress    = discountRec.UrlAddress;
            discountDetail.LogoFileName  = discountRec.LogoFileName;
            discountDetail.ImageFileName = discountRec.ImageFileName;

            var titleRec = (from ds in database.Table <DiscountsStrings>()
                            from ls in database.Table <LangString>()
                            where ds.LangStringId == ls.Id
                            where ds.OwnerId == discountRec.Id
                            where ds.Appointment == StrAppointmentTitle
                            where ls.LanguageCode == LanguageHelper.LangEnumToCode(AppParameters.Config.SystemLang)
                            select new { ls.Text }).FirstOrDefault();

            if (titleRec != null)
            {
                discountDetail.Title = titleRec.Text;
            }

            var descriptionRec = (from ds in database.Table <DiscountsStrings>()
                                  from ls in database.Table <LangString>()
                                  where ds.LangStringId == ls.Id
                                  where ds.OwnerId == discountRec.Id
                                  where ds.Appointment == StrAppointmentDescription
                                  where ls.LanguageCode == LanguageHelper.LangEnumToCode(AppParameters.Config.SystemLang)
                                  select new { ls.Text }).FirstOrDefault();

            if (descriptionRec != null)
            {
                discountDetail.Description = descriptionRec.Text;
            }

            var categoryList = from c in database.Table <Categorie>()
                               where c.DiscountId == discountRec.Id
                               select c;

            foreach (var categoryrec in categoryList)
            {
                discountDetail.CategorieList.Add(new CategorieData {
                    TypeCode = categoryrec.TypeCode
                });
            }

            var contactList = from c in database.Table <Contact>()
                              where c.DiscountId == discountRec.Id
                              select c;

            foreach (var contactRec in contactList)
            {
                DiscountDetailBranchData discountDetailBranchData = new DiscountDetailBranchData();
                discountDetailBranchData.DocumentId = contactRec.DocumentId;
                discountDetailBranchData.Latitude   = contactRec.Latitude;
                discountDetailBranchData.Longitude  = contactRec.Longitude;

                var addressRec = (from ds in database.Table <DiscountsStrings>()
                                  from ls in database.Table <LangString>()
                                  where ds.LangStringId == ls.Id
                                  where ds.OwnerId == contactRec.Id
                                  where ds.Appointment == StrAppointmentAddress
                                  where ls.LanguageCode == LanguageHelper.LangEnumToCode(AppParameters.Config.SystemLang)
                                  select new { ls.Text }).FirstOrDefault();
                if (addressRec != null)
                {
                    discountDetailBranchData.Address = addressRec.Text;
                }

                discountDetailBranchData.PhoneList.Add(contactRec.Phone1);
                discountDetailBranchData.PhoneList.Add(contactRec.Phone2);
                discountDetail.BranchList.Add(discountDetailBranchData);
            }
            return(discountDetail);
        }
        public void SetDiscount(DiscountDetailData discountDetailData)
        {
            DiscountDetailData = discountDetailData;

            CalculateDistance();
        }