public void UpdateAds()
        {
            for (int i = 0; i < Ads.Children.Count; i++)
            {
                if (Ads.Children[i].GetType() == typeof(AdvertisementPreview))
                {
                    Ads.Children.RemoveAt(i);
                    i--;
                }
            }

            len   = adIds.Count;
            pages = len / 3 + Convert.ToInt32(len % 3 != 0);

            if (len == 0)
            {
                currentPage            = 0;
                txtPage.Text           = "Nu am gasit niciun anunt publicat!";
                btnNextPage.Visibility = btnPrevPage.Visibility = Visibility.Hidden;
            }
            else
            {
                for (int c = 3, i = (currentPage - 1) * 3; i <= Math.Min(len - 1, currentPage * 3 - 1); i++, c += 2)
                {
                    string text = searchBar.Text;

                    if (hasText == false)
                    {
                        text = watermark;
                    }

                    AdvertisementPreview newAd = new AdvertisementPreview(adIds[i], text, currentPage, (int)ControlTypes.AdvertisementsPage);

                    Ads.Children.Add(newAd);
                    Grid.SetRow(newAd, c);
                    Grid.SetColumn(newAd, 1);
                }

                txtPage.Text = "Pagina " + currentPage.ToString() + " / " + pages.ToString();
            }

            btnPrevPage.Visibility = Visibility.Visible;
            btnNextPage.Visibility = Visibility.Visible;
            Logo.Visibility        = Visibility.Hidden;

            if (currentPage == 1)
            {
                btnPrevPage.Visibility = Visibility.Hidden;
            }
            if (currentPage == pages && pages > 0)
            {
                btnNextPage.Visibility = Visibility.Hidden;
            }
            if (currentPage == 0)
            {
                btnPrevPage.Visibility = Visibility.Hidden;
                btnNextPage.Visibility = Visibility.Hidden;
                Logo.Visibility        = Visibility.Visible;
            }
        }
Exemple #2
0
        public void UpdateAds()
        {
            for (int i = 0; i < gridAds.Children.Count; i++)
            {
                if (gridAds.Children[i].GetType() == typeof(AdvertisementPreview))
                {
                    gridAds.Children.RemoveAt(i);
                    i--;
                }
            }

            len   = ads.Count;
            pages = len / 3 + Convert.ToInt32(len % 3 != 0);

            if (len == 0)
            {
                currentPage         = 0;
                txtPage.Text        = "Nu am gasit niciun anunt reclamat!";
                gridLogo.Visibility = Visibility.Visible;
            }
            else
            {
                for (int c = 1, i = (currentPage - 1) * 3; i <= Math.Min(len - 1, currentPage * 3 - 1); i++, c += 2)
                {
                    AdvertisementPreview newAd = new AdvertisementPreview(ads[i], "", currentPage, (int)ControlTypes.AdminPanel);;

                    gridAds.Children.Add(newAd);
                    Grid.SetRow(newAd, c);
                    Grid.SetColumn(newAd, 1);
                }

                txtPage.Text = "Pagina " + currentPage.ToString() + " / " + pages.ToString();
            }

            btnPrevPage.Visibility = Visibility.Visible;
            btnNextPage.Visibility = Visibility.Visible;

            if (currentPage == 1)
            {
                btnPrevPage.Visibility = Visibility.Hidden;
            }
            if (currentPage == pages && pages > 0)
            {
                btnNextPage.Visibility = Visibility.Hidden;
            }
            if (currentPage == 0)
            {
                btnPrevPage.Visibility = Visibility.Hidden;
                btnNextPage.Visibility = Visibility.Hidden;
            }
        }