Exemple #1
0
        public void GetPageFromDB(int pageNum)
        {
            string connectionString = Global.WaifString;

            _connection = new SqlConnection(connectionString);
            _connection.Open();

            object Count = new SqlCommand("SELECT COUNT(*) FROM Waifu", _connection).ExecuteScalar();

            PageCount      = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(Count) / Convert.ToDouble(ItemsOnPage)));
            MainPagination = new Pagination(PageCount, pageNum);

            SqlCommand GetPageCommand = new SqlCommand("EXEC GetWaifuPage @offset, @page_size", _connection);

            GetPageCommand.Parameters.AddWithValue("offset", ItemsOnPage * (PageNumber - 1));
            GetPageCommand.Parameters.AddWithValue("page_size", ItemsOnPage);

            SqlDataReader rd = GetPageCommand.ExecuteReader();

            while (rd.Read())
            {
                WaifuLight item = new WaifuLight(rd);
                PageContent.Add(item);
            }
            rd.Close();

            ContentRepeater.DataSource = PageContent;
            ContentRepeater.DataBind();
            PaginationRepeater.DataSource = MainPagination.PaginationElements;
            PaginationRepeater.DataBind();
        }
        public void DataBaseWork(int id)
        {
            PageWaif = new Waifu();
            bool res = PageWaif.ReadFromBase(id);

            if (res)
            {
                using (_connection = new SqlConnection(Global.WaifString))
                {
                    _connection.Open();
                    using (var cmd = new SqlCommand("SELECT TOP 3 Id, Name, Image, Popularity FROM Waifu ORDER BY Popularity DESC",
                                                    _connection))
                    {
                        using (var rd = cmd.ExecuteReader())
                        {
                            while (rd.Read())
                            {
                                TopPopWaif.Add(new WaifuLight(rd) as LightElement);
                            }
                        }
                    }
                    using (var cmd = new SqlCommand("SELECT TOP 3 w.Id, w.Name, w.Image, " +
                                                    "(SELECT COUNT(f.Id) FROM Favorites as f WHERE f.WaifuId = w.Id) " +
                                                    "as Favority FROM Waifu as w ORDER BY Favority DESC", _connection))
                    {
                        using (var rd = cmd.ExecuteReader())
                        {
                            while (rd.Read())
                            {
                                var temp = new WaifuLight(rd);
                                temp.Popularity = temp.Favority;
                                TopFavWaif.Add(temp as LightElement);
                            }
                        }
                    }
                }
                var redacted = PageWaif.Chapters.Select(x =>
                {
                    x.Elements = x.Elements.Select(y =>
                    {
                        if (!String.IsNullOrWhiteSpace(y.Title))
                        {
                            y.Title += " : ";
                        }
                        return(y);
                    }).ToList();
                    return(x);
                }).ToList();

                ChapterRepeater.DataSource = redacted;
                TagRepeater.DataSource     = PageWaif.OurTags;
                TagRepeater.DataBind();
                ChapterRepeater.DataBind();
                FavListControl.Data = TopFavWaif;
                PopListControl.Data = TopPopWaif;
            }
            else
            {
                Response.Redirect("/error/404");
            }
        }