Ajax online music website (4) Part of the function implementation

Source: Internet
Author: User

The previous blog has nearly summed up the specific implementation of three features, today, the rest of the specific implementation of the function to supplement the summary, if you want to have a clear understanding of the whole small project, suggest to see the previous several blog.

1.AJAX Online music website (1) Requirements and functional structure

2.AJAX Online music website (2) database and development environment

3.AJAX Online music website (3) Part one feature implementation

D. Implementation of song add function

Administrators or administrator-authorized users can add their favorite songs to the home leaderboard of online music sites. As shown in 7.5.

Figure 7.5 Song Additions

Implementation process:

By defining the error attribute in the tab in the ASP. NET page, the following code:

display="Dynamic" errormessage="requiredfieldvalidator" > Singer information is not empty

Singer information is not empty after you click Add, the program will check the contents of each text box to meet the requirements, and display the corresponding prompt, in the case of the information is correct, the program will be inserted in the SQL language into the data table, the key code is as follows:

1 Try2         {3Upload. SaveAs (path +musicname);4 Conn. Open ();5SqlTransaction Mytrans =Conn. BeginTransaction ();6             Try7             {8SqlCommand cmd =NewSqlCommand ();9Cmd. Transaction =Mytrans;Ten Insert_music (conn, musicname, cmd); One                 if(!isexisted ("album","album", Conn, cmd)) A                 { - insert_album (conn, cmd); -                 } the                 if(!isexisted ("singer","singer", Conn, cmd)) -                 { - Insert_singer (conn, cmd); -                 } + mytrans.commit (); -Msg. Text ="Music added successfully! "; +Singer. Text =""; ABirthday. Text =""; atHobby. Text =""; -Album. Text =""; -Profile. Text =""; -             } -}

E. Implementation of different types of playlists

Users can choose how to play the list of songs according to their preferences (random play, sequential play, single repeat), as shown in the following 7.6 figure.

Figure 7.6 Playlist different types of playback

Implementation process:

First, in the foreground page, the index value in DropDownList corresponds to the content, the following code:

<asp:dropdownlist><asp:dropdownlistID= "Ddlplaytype"runat= "Server"><Asp:listitemValue= "0">Sequential playback</Asp:listitem><Asp:listitemValue= "1">Random Play</Asp:listitem><Asp:listitemValue= "2">Single cycle</Asp:listitem></asp:dropdownlist>

When the user plays the next song, the program determines the ID of the music file that is passed in to the player by comparing the DropDownList current index value. The key code is as follows:

//Sequential Playback        if(Ddlplaytype.selectedvalue = ="0")        {            intListCount =Select1.Items.Count; //This is the last song.            if((Selectix +1) ==ListCount) {                //set the last header as not selectableSelect1.items[selectix]. Selected =false; //Select the first songselect1.items[0]. Selected =true; //ID is the ID of the first songid = select1.items[0].            Value; }            Else            {                //remove a song IDid = select1.items[select1.selectedindex +1].                Value; Select1.items[selectix]. Selected=false; Select1.items[selectix+1]. Selected =true; }        }        //Random Play        Else if(Ddlplaytype.selectedvalue = ="1")        {            //take a random numberRandom rad =NewRandom (); //take a random number in the number of songs            intRadIx = rad. Next (0, Select1.Items.Count); //Select the ID of the selected random songID =Select1.items[radix].            Value; Select1.items[selectix]. Selected=false; Select1.items[radix]. Selected=true; }        //Single Cycle        Else{ID=Select1.items[selectix].        Value; }

F. Administrator-maintained songs

After the administrator logs in to the backstage, can make the music, the album, the singer Information modification, as follows 7.7, 7.8 diagram.

Figure 7.7 Music Information Modification

Figure 7.8 Music Details modification

Implementation process:

By adding a button to the Btn_click event using the updated and deleted SQL language, synchronize the page changes to the database, the key code is as follows:

Cmd.commandtext ="Update [music] set [email protected],[email protected],[email protected],[email protected] where [email protected]
    "; cmd. Parameters.Add ("@musicName", SqlDbType.NChar). Value =MusicName.Text.Trim (). ToString (); cmd. Parameters.Add ("@singer", SqlDbType.NChar). Value =singer. Selectedvalue.trim (). ToString (); cmd. Parameters.Add ("@album", SqlDbType.NChar). Value =album. Selectedvalue.trim (). ToString (); cmd. Parameters.Add ("@type", SqlDbType.NChar). Value = Typelist. Selectedvalue.trim (). ToString ();

G. User authorization and registration

Administrators can authorize users to be administrators for the maintenance of site tracks, 7.9. Visitors can register to become online music users, 7.10.

Figure 7.9 Admin Authorization page

Figure 7.10 User Registration

1) Authorization implementation process:

When the administrator login backstage, click the authorization button, trigger the Dg_itemcommand event, the website according to the authorized user ID, execute the SQL UPDATE statement, the key code is as follows:

if(E.commandname = ="Allowuser") {msg. Text=""; SqlConnection Conn=NewSqlConnection (configurationmanager.connectionstrings["LocalSqlServer"].            ToString ()); stringUserId =DG. Datakeys[e.item.itemindex].            ToString (); Conn.            Open (); Try{SqlCommand cmd=NewSqlCommand (); Cmd.commandtext="Update [user] set type = ' admin ' where [email protected]"; Cmd. Connection=Conn; Cmd. Parameters.Add ("@userId", SqlDbType.NChar). Value =Userid.trim (); Cmd.         ExecuteNonQuery ();            DataBind (); }

2) Registration Implementation process:
The user enters the registration page the information, can determine the user name and the e_mail format is correct, after clicking the Add button, triggers the Addbtn_click event, and inserts the information into the User Information data table, the key code is as follows:

Try{Conn.        Open (); SqlCommand cmd=NewSqlCommand (); Cmd. Connection=Conn; Cmd. Parameters.Add ("@userId", SqlDbType.NChar). Value =UserId.Text.Trim (); Cmd. Parameters.Add ("@passwd", SqlDbType.NChar). Value =password.        Text.trim (); Cmd. Parameters.Add ("@name", SqlDbType.NChar). Value =name.        Text.trim (); Cmd. Parameters.Add ("@sex", SqlDbType.NChar). Value =sex.        Selectedvalue.tostring (); Cmd. Parameters.Add ("@mail", SqlDbType.NChar). Value =Mail.          Text.trim (); Cmd. Parameters.Add ("@type", SqlDbType.NChar). Value ="User"; if(!isexisted (CMD)) {Cmd.commandtext="INSERT into [user] VALUES (@userId, @passwd, @name, @sex, @mail, @type)"; Cmd.            ExecuteNonQuery (); Msg. Text="Registration Successful! "; Userid.text=""; Name. Text=""; Mail. Text=""; Response.Redirect ("Default.aspx"); }            ElseMsg. Text="user name already exists! ";

Ajax online music website (4) Part of the function implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.