Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- statistics
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Statistics : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand timeSpent = new SqlCommand();
- SqlCommand songsPlayed = new SqlCommand();
- SqlCommand diffSongsPlayed = new SqlCommand();
- SqlCommand numOfPlaylists = new SqlCommand();
- SqlCommand biggestSong = new SqlCommand();
- SqlCommand biggestArtist = new SqlCommand();
- timeSpent.Connection = konekcija;
- songsPlayed.Connection = konekcija;
- diffSongsPlayed.Connection = konekcija;
- numOfPlaylists.Connection = konekcija;
- biggestArtist.Connection = konekcija;
- biggestSong.Connection = konekcija;
- timeSpent.CommandText = "select sum(Song_length) total from Statistic ST, Song S where ST.Song_ID=S.Song_ID";
- songsPlayed.CommandText = "select count(*) total from Statistic where username ='" + Session["username"] + "'"; //add username
- diffSongsPlayed.CommandText = "select count(distinct Song_ID) nmb from Statistic where username ='" + Session["username"] + "'";
- numOfPlaylists.CommandText = "select count(Playlist_ID) nmb from Playlist";
- biggestArtist.CommandText = "";
- biggestSong.CommandText = "select Song_Name, max(ST.Play_count) maks from Song S, Statistic ST where S.Song_ID=ST.Song_ID group by Song_Name order by maks desc";
- try
- {
- konekcija.Open();
- SqlDataReader citac = numOfPlaylists.ExecuteReader();
- if (citac.Read())
- playlistsnum.Text = citac["nmb"].ToString();
- citac.Close();
- citac = timeSpent.ExecuteReader();
- if (citac.Read())
- minutes.Text = (Int32.Parse(citac["total"].ToString())/60).ToString();
- hours.Text = String.Format("{0:0.##X}", (Double.Parse(minutes.Text.ToString()) / 60).ToString());
- days.Text = (Double.Parse(hours.Text.ToString())/24).ToString();
- citac.Close();
- citac = songsPlayed.ExecuteReader();
- if (citac.Read())
- songslistened.Text = citac["total"].ToString();
- citac.Close();
- citac = diffSongsPlayed.ExecuteReader();
- if (citac.Read())
- different.Text = citac["nmb"].ToString();
- citac.Close();
- citac = biggestSong.ExecuteReader();
- if (citac.Read())
- mpSong.Text = citac["Song_Name"].ToString();
- citac.Close();
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void logout (object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- }
- sing up
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class SignUp : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void register_Click(object sender, EventArgs e)
- {
- //proveri dali vnesenoto korisnichko ime go nema vo bazata
- Boolean unique = true;
- String names;
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- SqlCommand proverka = new SqlCommand();
- komanda.Connection = konekcija;
- proverka.Connection = konekcija;
- komanda.CommandText = "INSERT INTO Users values " +
- "('" + username.Text + "'," +
- "'" + password.Text + "'," +
- "'" + mail.Text + "')";
- proverka.CommandText = "SELECT * FROM Users";
- try
- {
- konekcija.Open();
- SqlDataReader citac = proverka.ExecuteReader();
- while (citac.Read())
- {
- names = citac["username"].ToString();
- if (names.Equals(username.Text))
- {
- unique = false;
- break;
- }
- }
- }
- finally
- {
- konekcija.Close();
- }
- if (unique)
- {
- try
- {
- konekcija.Open();
- komanda.ExecuteNonQuery();
- }
- finally
- {
- konekcija.Close();
- }
- Server.Transfer("LogIn.aspx", true);
- }
- else
- {
- messages.Text = "The username is in use. Please enter another one";
- }
- }
- }
- search
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Search : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- if (!IsPostBack)
- fillSearch();
- }
- protected void fillSearch()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- komanda.CommandText = "select Artist_Name, Song_Name, Album_Name, Release_year, url, Song_ID from Artist A, Album AL, Song S WHERE A.Artist_ID=AL.Artist_ID AND S.Album_ID=AL.Album_ID AND S.Artist_ID=A.Artist_ID";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "Search");
- gvSearch.DataSource = ds;
- gvSearch.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void keywordEvent(object sender, EventArgs e)
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- String tag = keyword.Text.ToString();
- komanda.CommandText = "select Artist_Name, Song_Name, Album_Name, Release_year, url, Song_ID from Artist A, Album AL, Song S WHERE A.Artist_ID=AL.Artist_ID AND S.Album_ID=AL.Album_ID AND S.Artist_ID=A.Artist_ID and (Artist_Name like '%" + tag + "%' or Song_Name like '%" + tag + "%' or Album_Name like '%" + tag + "%')";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "Search");
- gvSearch.DataSource = ds;
- gvSearch.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void gvSearchSelect(object sender, EventArgs e)
- {
- player.Src = gvSearch.SelectedRow.Cells[5].Text.ToString();
- //pri pritiskanje na PLAY, azhuriraj ja tabelata Statistic
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand maxIndex = new SqlCommand();
- SqlCommand playCount = new SqlCommand();
- SqlCommand play = new SqlCommand();
- maxIndex.Connection = konekcija;
- play.Connection = konekcija;
- playCount.Connection = konekcija;
- int max = 0, playcount = 0;
- maxIndex.CommandText = "select ISNULL(max(Stat_ID), 0) maks from Statistic";
- playCount.CommandText = "select ISNULL(max(Play_count),0) maks from Statistic where Song_ID=" + Int32.Parse(gvSearch.SelectedRow.Cells[6].Text);
- SqlDataReader citac = null;
- try
- {
- konekcija.Open();
- citac = maxIndex.ExecuteReader();
- if (citac.Read())
- {
- max = Int32.Parse(citac["maks"].ToString());
- }
- citac.Close();
- citac = playCount.ExecuteReader();
- if (citac.Read())
- {
- playcount = Int32.Parse(citac["maks"].ToString());
- }
- citac.Close();
- max++;
- playcount++;
- play.CommandText = "insert into Statistic values (" + max + "," + playcount + "," + "'2017-08-02', '" + Session["username"] + "'," + Int32.Parse(gvSearch.SelectedRow.Cells[6].Text) + ")";
- play.ExecuteNonQuery();
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void logout(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- }
- profile page
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class ProfilePage : System.Web.UI.Page
- {
- protected void home(object sender, EventArgs e)
- {
- //Server.Transfer("HomePage.aspx", true);
- }
- protected void search(object sender, EventArgs e)
- {
- Server.Transfer("Search.aspx", true);
- }
- protected void playlists(object sender, EventArgs e)
- {
- Server.Transfer("Playlists.aspx", true);
- }
- protected void logOut(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- protected void History(object sender, EventArgs e)
- {
- Server.Transfer("History.aspx", true);
- }
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- String mypassword = "", mymail = "";
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand getUser = new SqlCommand();
- getUser.Connection = konekcija;
- getUser.CommandText = "select * from Users where Username='" + Session["username"] + "'";
- username.Text = (String)Session["username"];
- try
- {
- konekcija.Open();
- SqlDataReader citac = getUser.ExecuteReader();
- if (citac.Read())
- {
- mymail = citac["mail"].ToString();
- for (int i = 0; i < citac["password"].ToString().Length; i++)
- {
- mypassword += "•";
- }
- password.Text = mypassword;
- email.Text = mymail;
- citac.Close();
- }
- }
- catch
- {
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void newPassB_Click(object sender, EventArgs e)
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- komanda.CommandText = "UPDATE Users SET password='"
- + newPass.Text + "' WHERE Username='" + username.Text + "'";
- try
- {
- konekcija.Open();
- komanda.ExecuteNonQuery();
- Response.Redirect("ProfilePage.aspx");
- }
- finally
- {
- konekcija.Close();
- }
- }
- }
- playlist
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Playlists : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- //thesongs.Text = (String)Session["theSongs"];
- usernameLink.Text = (String)Session["username"];
- fillPlaylists();
- }
- protected void fillPlaylists()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- komanda.CommandText = "select Playlist_name from Users U, Playlist P, Possession PO where U.Username=PO.Username AND PO.Playlist_ID=P.Playlist_ID"; //TO-DO: dodadi AND U.Username=" + Session["username"]
- try
- {
- konekcija.Open();
- SqlDataReader citac = komanda.ExecuteReader();
- while (citac.Read())
- {
- ImageButton pic = new ImageButton ();
- pic.ImageUrl = "http://goo.gl/CzIJEx";
- pic.CssClass = "pics";
- pic.Height = 125;
- pic.Width = 125;
- pic.AlternateText = citac["Playlist_name"].ToString();
- pic.Click += new ImageClickEventHandler(getPlaylist);
- LinkButton name = new LinkButton();
- name.Text = String.Format("{0, 200}", citac["Playlist_name"].ToString());
- Label blankSpace = new Label();
- blankSpace.Text = "\n";
- playlistPics.Controls.Add(pic);
- //playlistPics.Controls.Add(blankSpace);
- playlistPics.Controls.Add(name);
- // playlistNames.Controls.Add(name);
- }
- }
- catch
- {
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void ok(object sender, EventArgs e)
- {
- /* String getSongs = thesongs.Text.ToString();
- thesongs.Text = getSongs;
- Session["theSongs"] = getSongs;
- thesongs.Text = (String)Session["theSongs"];*/
- //String getSongs = listbox.InnerHtml;
- //Label1.Text += getSongs + "DONE!!!!!!!!!!!!!";
- /*SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand index = new SqlCommand();
- index.Connection = konekcija;
- SqlCommand playlist = new SqlCommand();
- playlist.Connection = konekcija;
- SqlCommand possession = new SqlCommand();
- possession.Connection = konekcija;
- index.CommandText = "select max(Playlist_ID) maks from Playlist";
- int indeks = 0;
- try
- {
- konekcija.Open();
- SqlDataReader citac = index.ExecuteReader();
- if (citac.Read())
- {
- indeks = Int32.Parse(citac["maks"].ToString()) + 1;
- }
- playlist.CommandText = "insert into Playlist values (" + indeks + "," + newPlaylistName.ToString() + ")";
- possession.CommandText = "insert into Possession values (" + Session["username"] + "," + indeks + ")";
- playlist.ExecuteNonQuery();
- possession.ExecuteNonQuery();
- Server.Transfer("Playlists.aspx");
- }
- finally
- {
- konekcija.Close();
- }*/
- }
- protected void logout(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- protected void getPlaylist (object sender, EventArgs e)
- {
- ImageButton clicked = (ImageButton)sender;
- Session["playlist"] = clicked.AlternateText.ToString();
- logOutButton.Text = (String)Session["playlist"];
- Response.Redirect("PlaylistPage.aspx");
- }
- protected void newPlaylist(object sender, EventArgs e)
- {
- Response.Redirect("NewPlaylist.aspx");
- }
- }
- playlistpage
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class PlaylistPage : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- if (!IsPostBack)
- fillPlaylist();
- }
- protected void fillPlaylist()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- komanda.CommandText = "select * from Playlist P, Appearance A, Song S, Artist AR, Album AL where P.Playlist_ID=A.Playlist_ID and S.Song_ID=A.Song_ID and S.Artist_ID=AR.Artist_ID and S.Album_ID=AL.Album_ID and P.Playlist_name = '" + Session["playlist"] + "'";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "Playlist");
- gvPlaylist.DataSource = ds;
- gvPlaylist.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void logout(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- }
- history
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class History : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- if (!IsPostBack)
- fillHistory();
- }
- protected void fillHistory()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- komanda.CommandText = "select A.Artist_Name, S.Song_Name, ST.Play_count, ST.Date, S.url, S.Song_ID from Song S, Statistic ST, Artist A where S.Song_ID=ST.Song_ID and S.Artist_ID=A.Artist_ID"; //and ST.Username ='" + Session["username"] + "'";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "History");
- gvHistory.DataSource = ds;
- gvHistory.DataBind();
- ViewState["dataset"] = ds;
- }
- catch
- {
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void dateEvent(object sender, EventArgs e)
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- String pickedDate = datepicker.Text.ToString().Replace('/', '-');
- String year = pickedDate.Substring(6, 4), month = pickedDate.Substring(3, 2), day = pickedDate.Substring(0, 2);
- komanda.CommandText = "select A.Artist_Name, S.Song_Name, ST.Play_count, ST.Date, S.url, S.Song_ID from Song S, Statistic ST, Artist A where S.Song_ID=ST.Song_ID and S.Artist_ID=A.Artist_ID and ST.Date LIKE '" + year + "%" + month + "%" + day + "'" + "and ST.Username ='" + Session["username"] + "'";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "History");
- gvHistory.DataSource = ds;
- gvHistory.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void gvHistorySelect(object sender, EventArgs e)
- {
- player.Src = gvHistory.SelectedRow.Cells[5].Text;
- //pri pritiskanje na PLAY, azhuriraj ja tabelata Statistic
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand maxIndex = new SqlCommand();
- SqlCommand playCount = new SqlCommand();
- SqlCommand play = new SqlCommand();
- maxIndex.Connection = konekcija;
- play.Connection = konekcija;
- playCount.Connection = konekcija;
- int max = 0, playcount = 0;
- maxIndex.CommandText = "select ISNULL(max(Stat_ID), 0) maks from Statistic";
- playCount.CommandText = "select ISNULL(max(Play_count),0) maks from Statistic where Song_ID=" + Int32.Parse(gvHistory.SelectedRow.Cells[6].Text);
- SqlDataReader citac = null;
- try
- {
- konekcija.Open();
- citac = maxIndex.ExecuteReader();
- if (citac.Read())
- {
- max = Int32.Parse(citac["maks"].ToString());
- }
- citac.Close();
- citac = playCount.ExecuteReader();
- if (citac.Read())
- {
- playcount = Int32.Parse(citac["maks"].ToString());
- }
- citac.Close();
- max++;
- playcount++;
- play.CommandText = "insert into Statistic values (" + max + "," + playcount + "," + "'2017-08-02', '" + Session["username"] + "'," + Int32.Parse(gvHistory.SelectedRow.Cells[6].Text) + ")";
- play.ExecuteNonQuery();
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void logout(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- }
- custom
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Custom : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- if (!IsPostBack)
- {
- fillGenre();
- fillPlaylistLength();
- fillMostPlayed();
- }
- }
- protected void fillGenre ()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- komanda.CommandText = "select genre.genre_name Genre, max(play_count) Plays, date Date from statistic, song, genre, is_genre where song.Song_ID=Statistic.Song_ID and song.song_id=is_genre.song_id and genre.genre_id=is_genre.genre_id group by genre.genre_name,Date";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "Genre");
- gvGenre.DataSource = ds;
- gvGenre.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void fillPlaylistLength()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- komanda.CommandText = "select playlist_name,sum(song.song_length) from song,playlist,appearance where song.song_id=appearance.song_id and playlist.playlist_id=appearance.playlist_id group by playlist.playlist_name having sum(song.song_length)>500";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "Genre");
- gvPlaylistLength.DataSource = ds;
- gvPlaylistLength.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void fillMostPlayed()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- komanda.CommandText = "select Album.Album_Name, MaxAlbumPlays.MaxPlays from Album inner join (select Album.Album_ID as AlbumID, max(Statistic.Play_count) as MaxPlays from Album, Song, Statistic where Album.Album_ID=Song.Album_ID and Song.Song_ID=Statistic.Song_ID group by Album.Album_ID) MaxAlbumPlays on Album.Album_ID = MaxAlbumPlays.AlbumID";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "Genre");
- gvMostPlayed.DataSource = ds;
- gvMostPlayed.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void logout(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- }
- charts
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Charts : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- if (!IsPostBack)
- fillChart();
- }
- protected void fillChart ()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- String tag = keyword.Text.ToString();
- komanda.CommandText = "select Artist_Name, S.Song_Name, Album_Name, C.times_listened from Artist A, Song S, Album AL, (select S.Song_ID as song_ID, count(S.Song_ID) times_listened from Artist A, Song S, Album AL, Statistic ST where A.Artist_ID=S.Artist_ID and AL.Album_ID=S.Album_ID and S.Song_ID=ST.Song_ID group by S.Song_ID) C where A.Artist_ID=S.Artist_ID and AL.Album_ID=S.Album_ID and C.song_ID=S.Song_ID order by times_listened desc";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "Search");
- gvYear.DataSource = ds;
- gvYear.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void keywordEvent(object sender, EventArgs e)
- {
- String year = keyword.Text.ToString();
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- String tag = keyword.Text.ToString();
- komanda.CommandText = "select Artist_Name, S.Song_Name, Album_Name, C.times_listened from Artist A, Song S, Album AL, (select S.Song_ID as song_ID, count(S.Song_ID) times_listened from Artist A, Song S, Album AL, Statistic ST where A.Artist_ID=S.Artist_ID and AL.Album_ID=S.Album_ID and S.Song_ID=ST.Song_ID and ST.Date like '" + year + "%' group by S.Song_ID) C where A.Artist_ID=S.Artist_ID and AL.Album_ID=S.Album_ID and C.song_ID=S.Song_ID";
- SqlDataAdapter adapter = new SqlDataAdapter(komanda);
- DataSet ds = new DataSet();
- try
- {
- konekcija.Open();
- adapter.Fill(ds, "Search");
- gvYear.DataSource = ds;
- gvYear.DataBind();
- ViewState["dataset"] = ds;
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void logout(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- }
- home page
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class HomePage : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- fillNewMusic();
- //fillRecentArtists();
- //fillRecentSongs();
- }
- protected void fillNewMusic()
- {
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand newmusic = new SqlCommand();
- SqlCommand recentartist = new SqlCommand();
- SqlCommand recentsong = new SqlCommand();
- newmusic.Connection = konekcija;
- recentartist.Connection = konekcija;
- recentsong.Connection = konekcija;
- newmusic.CommandText = "select top 5 Song_Name from Song S, Album A where S.Album_ID=A.Album_ID order by Release_year desc";
- recentartist.CommandText = "select distinct top 5 Artist_Name from Artist A, Song S, Statistic ST where ST.Song_ID=S.Song_ID and S.Artist_ID=A.Artist_ID";
- recentsong.CommandText = "select distinct top 5 Song_Name from Song S, Statistic ST where ST.Song_ID=S.Song_ID";
- try
- {
- konekcija.Open();
- SqlDataReader citac = newmusic.ExecuteReader();
- while (citac.Read())
- {
- ImageButton pic = new ImageButton();
- pic.ImageUrl = "http://goo.gl/CzIJEx";
- pic.CssClass = "pics";
- pic.Height = 125;
- pic.Width = 125;
- LinkButton name = new LinkButton();
- name.Text = String.Format("{0: 20}", citac["Song_Name"].ToString());
- Label blankSpace = new Label();
- blankSpace.Text = "\n";
- playlistPics.Controls.Add(pic);
- //playlistPics.Controls.Add(blankSpace);
- playlistPics.Controls.Add(name);
- // playlistNames.Controls.Add(name);
- }
- citac.Close();
- citac = recentartist.ExecuteReader();
- while (citac.Read())
- {
- ImageButton pic = new ImageButton();
- pic.ImageUrl = "http://goo.gl/CzIJEx";
- pic.CssClass = "pics";
- pic.Height = 125;
- pic.Width = 125;
- LinkButton name = new LinkButton();
- name.Text = String.Format("{0: 20}", citac["Artist_Name"].ToString());
- Label blankSpace = new Label();
- blankSpace.Text = "\n";
- playlistPics1.Controls.Add(pic);
- //playlistPics.Controls.Add(blankSpace);
- playlistPics1.Controls.Add(name);
- // playlistNames.Controls.Add(name);
- }
- citac.Close();
- citac = recentsong.ExecuteReader();
- while (citac.Read())
- {
- ImageButton pic = new ImageButton();
- pic.ImageUrl = "http://goo.gl/CzIJEx";
- pic.CssClass = "pics";
- pic.Height = 125;
- pic.Width = 125;
- LinkButton name = new LinkButton();
- name.Text = String.Format("{0: 20}", citac["Song_Name"].ToString());
- Label blankSpace = new Label();
- blankSpace.Text = "\n";
- playlistPics2.Controls.Add(pic);
- //playlistPics.Controls.Add(blankSpace);
- playlistPics2.Controls.Add(name);
- // playlistNames.Controls.Add(name);
- }
- citac.Close();
- }
- catch
- {
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void logout(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- }
- log in
- using System;
- using System.Collections.Generic;
- using System.Data.SqlClient;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class LogIn : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- }
- protected void logIn (object sender, EventArgs e)
- {
- String dbPassword = "";
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand komanda = new SqlCommand();
- komanda.Connection = konekcija;
- //username i password vneseni od korisnikot
- String theUsername = username.Text.ToString();
- String thePassword = password.Text.ToString();
- komanda.CommandText = "select * FROM Users WHERE username='"
- + theUsername.ToString() + "'";
- try
- {
- konekcija.Open();
- SqlDataReader citac = komanda.ExecuteReader();
- if (citac.Read())
- {
- dbPassword = citac["password"].ToString();
- citac.Close();
- }
- }
- catch
- {
- error.Text = "An error has occured. Please try again";
- }
- finally
- {
- konekcija.Close();
- }
- if (dbPassword.Equals(""))
- {
- error.Text = "Username does NOT exist";
- } else if (dbPassword.Equals(thePassword))
- {
- Session["username"] = (String)username.Text;
- Response.Redirect("HomePage.aspx");
- } else if (!dbPassword.Equals(thePassword))
- {
- error.Text = "Wrong Password! Try again";
- }
- }
- }
- new playlist
- using System;
- using System.Collections.Generic;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Data.SqlClient;
- using System.Configuration;
- public partial class NewPlaylist : System.Web.UI.Page
- {
- protected void Page_Load(object sender, EventArgs e)
- {
- usernameLink.Text = (String)Session["username"];
- }
- protected void createPlaylist (object sender, EventArgs e)
- {
- String playlistTitle = playlistName.Value;
- int index = 0;
- SqlConnection konekcija = new SqlConnection();
- konekcija.ConnectionString = "Data Source=localhost;"
- + "Initial Catalog=MusicPlayer; Integrated Security=True";
- SqlCommand playlistID = new SqlCommand();
- SqlCommand insertPlaylist = new SqlCommand();
- SqlCommand insertPossession = new SqlCommand();
- SqlCommand insertAppearance = new SqlCommand();
- playlistID.Connection = konekcija;
- insertPlaylist.Connection = konekcija;
- insertPossession.Connection = konekcija;
- insertAppearance.Connection = konekcija;
- playlistID.CommandText = "Select max(CAST(Playlist_ID AS Int)) maks from Playlist";
- try
- {
- konekcija.Open();
- SqlDataReader citac = playlistID.ExecuteReader();
- if (citac.Read())
- {
- index = Int32.Parse(citac["maks"].ToString());
- index++;
- }
- citac.Close();
- insertPlaylist.CommandText = "insert into Playlist values ('" + index + "','" + playlistTitle + "')";
- insertPlaylist.ExecuteNonQuery();
- insertPossession.CommandText = "insert into Possession values ('" + Session["username"] + "'," + index + ")";
- insertPossession.ExecuteNonQuery();
- for (int i=21; i<25; i++)
- {
- insertAppearance.CommandText = "insert into Appearance values (" + index + ", " + i + ")";
- insertAppearance.ExecuteNonQuery();
- }
- }
- finally
- {
- konekcija.Close();
- }
- }
- protected void logout(object sender, EventArgs e)
- {
- Session["username"] = null;
- Server.Transfer("LogIn.aspx", true);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement