Ejemplo n.º 1
0
    protected void Button1_Click1(object sender, EventArgs e)
    {
        String searchName = TextBox1.Text;

        try

        {
            String         URL     = "http://localhost:55923/CDRestService.svc/GetSearchResults/" + searchName;
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.KeepAlive = false;
            WebResponse  response = request.GetResponse();
            StreamReader reader   = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string       json     = reader.ReadToEnd();


            DataTable table = JsonConvert.DeserializeObject <DataTable>(json);
            //Console.WriteLine(json);
            RepeaterAlbums.DataSource = table;
            RepeaterAlbums.DataBind();

            System.Diagnostics.Debug.WriteLine(json);
            if (table != null)
            {
                if (table.Rows.Count <= 0)
                {
                    System.Diagnostics.Debug.WriteLine("empty");
                    PanelWarning.Visible = true;
                }
            }
        }
        catch (Exception)
        {
        }
    }
    protected void LinkButton_OrderBy_Newest_Click(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        SqlCommand    cmd  = new SqlCommand("SELECT TOP (5) Albums.Album_id, Genre.Genre_name, Albums.Album_artist, Albums.Album_img, Albums.Album_price, Albums.Album_name, Genre.Genre_id, Albums.Album_postdate FROM Albums INNER JOIN Genre ON Albums.fk_genre_id = Genre.Genre_id ORDER BY Album_postdate DESC", conn);

        conn.Open();
        RepeaterAlbums.DataSource = cmd.ExecuteReader();
        RepeaterAlbums.DataBind();
        conn.Close();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        SqlCommand    cmd  = new SqlCommand("SELECT Albums.Album_id, Genre.Genre_name, Albums.Album_artist, Albums.Album_img, Albums.Album_price, Albums.Album_name, Genre.Genre_id, Albums.Album_postdate FROM Albums INNER JOIN Genre ON Albums.fk_genre_id = Genre.Genre_id", conn);

        conn.Open();
        RepeaterAlbums.DataSource = cmd.ExecuteReader();
        RepeaterAlbums.DataBind();
        conn.Close();

        GetAlbums();
    }
    private void GetAlbums()
    {
        int news_pr_side = 5;
        int current_page = 1;

        if (Request.QueryString["pagenr"] != null)
        {
            if (!int.TryParse(Request.QueryString["pagenr"].ToString(), out current_page))
            {
                current_page = 1;
            }
        }

        int total_pages = (int)Math.Ceiling(AntalAlbums() / (double)news_pr_side);

        string links = "<ul class='pagination'>";

        for (int i = 1; i <= total_pages; i++)
        {
            links += "<li " + (current_page == i ? "class='active'" : "") + ">";
            links += "<a href='MusicShop.aspx?pagenr=" + i + "'>" + i + "</a>";
            links += "</li>";
        }
        links += "</ul>";
        Literal_Pager.Text = links;

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        SqlCommand    cmd  = new SqlCommand();

        cmd.Connection  = conn;
        cmd.CommandText = @"SELECT * FROM Albums INNER JOIN Genre ON Genre_id = Albums.fk_genre_id ORDER BY Album_postdate DESC OFFSET @offset ROWS FETCH NEXT @news_per_page ROWS ONLY";
        cmd.Parameters.Add("@news_per_page", SqlDbType.Int).Value = news_pr_side;
        int offset = (current_page - 1) * news_pr_side;

        cmd.Parameters.Add("@offset", SqlDbType.Int).Value = offset;

        conn.Open();
        RepeaterAlbums.DataSource = cmd.ExecuteReader();
        RepeaterAlbums.DataBind();
        conn.Close();
    }
Ejemplo n.º 5
0
    private void getResults()
    {
        try

        {
            String         URL     = "http://localhost:55923/CDRestService.svc/GetData";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
            request.KeepAlive = false;
            WebResponse  response = request.GetResponse();
            StreamReader reader   = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            string       json     = reader.ReadToEnd();

            DataTable table = JsonConvert.DeserializeObject <DataTable>(json);
            //Console.WriteLine(json);
            RepeaterAlbums.DataSource = table;
            RepeaterAlbums.DataBind();
        }
        catch (Exception)
        {
        }
    }