歡迎進入MyKTV前后臺點歌系統展示

vn714072 8年前發布 | 108K 次閱讀 SQL .NET開發

來自: http://www.cnblogs.com/bdpsc/p/5172908.html

一個項目,一分收獲;一個項目,一些資源。Ktv項目也是一樣的,所以我想分享我的收獲,讓你們獲得你需要的資源。

一. 那MyKTV點歌系統具體的功能有哪些呢?我們就來看看吧!

1.MyKTV前臺功能:

01.歌星點歌 、拼音點歌 、數字點歌 、類型選擇 、金榜排行

02.切歌 、點歌 、重唱和退出

2.MyKTV后臺功能:

01.歌手管理 、歌曲管理 、設置資源路徑

02.新增歌手、歌曲 ,查詢歌手、歌曲信息,設置歌曲路徑和退出

二. 功能已經概括的差不多了,就讓我們一起來看看MyKTV的項目吧

1.首先就是展現KTV的主界面,讓我們先了解一下那些功能

01.實現各個共功能的主代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyKTVClient { public partial class frmMain : Form { public frmMain() { InitializeComponent(); } //當前播放的歌曲 private Song song; // 退出系統 SqlConnection con = new SqlConnection(DBHelper.str); private void tsbtnExit_Click(object sender, EventArgs e) { Application.Exit(); } private void MainForm_Load(object sender, EventArgs e) { DBHelper.frm = this; // 加載時,運行播放窗體
// 啟動計時器 this.tim.Start();

        // 歌手照片路徑   
        string sql = "select resource_path from resource_path where resource_id=1";
        SqlCommand cmd = new SqlCommand(sql, con);
        // 歌手照片路徑
        con.Open();
        KTVUtil.singerPhotoPath = cmd.ExecuteScalar().ToString();
        // 歌曲路徑
        sql = "select resource_path from resource_path where resource_id=2";
        cmd.CommandText = sql;
        KTVUtil.songPath = cmd.ExecuteScalar().ToString();
        con.Close();
    }
       //已點歌曲窗體
    private void tsbtnOrdered_Click(object sender, EventArgs e)
    {
        frmOrderedSongList frm = new frmOrderedSongList();
        frm.Show();
    }

    // 重新播放當前歌曲
    private void tsbtnAgain_Click(object sender, EventArgs e)
    {
        PlayList.PlayAgain();
        PlaySong();
    }

    // 切歌
    private void tsbtnCut_Click(object sender, EventArgs e)
    {
        if (txtnextsong.Text=="")
        {
            MessageBox.Show("暫無已點歌曲");
        }
        else
        {
            PlayList.CutSong(-1);
        }

    }
    // 服務
    private void toolStripButton1_Click(object sender, EventArgs e)
    {
        MessageBox.Show("當前無服務!");
    }
    //播放歌曲
    private void PlaySong()
    {
        this.song = PlayList.GetPlayingSong(); // 獲取當前要播放的歌曲
        if (song != null)
        {
            this.song.SetSongPlayed();             // 將當前歌曲播放狀態設為已播放
            this.Winplaymedia.URL = KTVUtil.songPath + "\\" + this.song.SongURL;  // 得到當前播放歌曲的路徑
            string urlls = KTVUtil.singerPhotoPath +"\\"+ this.song.Singerurl;//歌手圖片
            lblsongname.Text = this.song.Singername;//歌手名字
            try
            {
                this.pblist.Image = Image.FromFile(urlls);
            }
            catch (Exception)
            {

                MessageBox.Show("暫無歌手圖片"); ;
            }

        }
    }
    // 定時掃描歌曲列表,顯示當前播放歌曲的名稱
    private void timer1_Tick(object sender, EventArgs e)
    {
        // 在文本框中顯示當前播放的歌曲名字
        this.txtplay.Text = PlayList.PlayingSongName();
        this.txtnextsong.Text = PlayList.NextSongName();
        if (this.song == null)
        {
            this.PlaySong();
        }
        if (this.Winplaymedia.playState == WMPLib.WMPPlayState.wmppsStopped)
        {
            this.song = null; // 將歌曲設為空
            PlayList.MoveOn();
        }
        // 切歌
        if (this.song != null && this.song.PlayState == SongPlayState.cut)
        {
            this.Winplaymedia.URL = "";
            this.song = null;
        }       
    }
    // 按歌手點歌
    private void picSinger_Click(object sender, EventArgs e)
    {
        frmOrderBySinger frm = new frmOrderBySinger();
        frm.Show();
    }

    // 拼音點歌
    private void picSongName_Click(object sender, EventArgs e)
    {
        frmOrderBySongName frm = new frmOrderBySongName();
        frm.Show();
    }

    // 分類點歌
    private void picSongType_Click(object sender, EventArgs e)
    {
        frmOrderBySongType frm = new frmOrderBySongType();
        frm.Show();
    }

    // 排行榜點歌
    private void picSongList_Click(object sender, EventArgs e)
    {
        frmSongList frm = new frmSongList();
        string sql = "select song_id,song_name,singer_info.singer_name,song_url,singer_info.singer_photo_url from song_info inner join singer_info on song_info.singer_id=singer_info.singer_id order by song_play_count desc";
        frm.Sql = sql;
        frm.Onform = FanhuiForm.Main;
        frm.Show();
    }

    // 字數點歌
    private void picWordCount_Click(object sender, EventArgs e)
    {
        frmOrderByWordCount frm = new frmOrderByWordCount();
        frm.Show();
    }

    private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
    {
        //關閉應用
        Application.Exit();
    }

    //點擊窗體移動
    private Point mouseOffset;        //記錄鼠標指針的坐標        
    private bool isMouseDown = false; //記錄鼠標按鍵是否按下 
    private void pnlTop_MouseDown(object sender, MouseEventArgs e)
    {
        int xOffset;
        int yOffset;
        if (e.Button == MouseButtons.Left)
        {
            xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
            yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
            mouseOffset = new Point(xOffset, yOffset);
            isMouseDown = true;
        }
    }

    private void pnlTop_MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
            Location = mousePos;
        }
    }

    private void pnlTop_MouseUp(object sender, MouseEventArgs e)
    {

        // 修改鼠標狀態isMouseDown的值      
        // 確保只有鼠標左鍵按下并移動時,才移動窗體       
        if (e.Button == MouseButtons.Left)
        {
            isMouseDown = false;
        }
    }

    private void pnlTop_Paint(object sender, PaintEventArgs e)
    {

    }

}

}</pre>

2.歌星點歌(三個listview的集成窗體)

01.歌手類別

02.歌手地區

03.歌手姓名

04.代碼

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient; // ADO.NET

namespace MyKTVClient { public partial class frmOrderBySinger : Form { // 當前選擇的歌手性別 private string singergender = "男"; // 當前選擇的歌手類型的編號 private int singerTypeId = 0;

    public frmOrderBySinger()
    {
        InitializeComponent();
    }


    // 關閉當前窗體,顯示主界面
    private void tsbtnHome_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    // 重新播放當前歌曲
    private void tsbtnAgain_Click(object sender, EventArgs e)
    {
        PlayList.PlayAgain();
    }

    // 切歌
    private void tsbtnCut_Click(object sender, EventArgs e)
    {           
            PlayList.CutSong(-1);

    }

    // 打開已點歌曲窗體
    private void tsbtnOrdered_Click(object sender, EventArgs e)
    {
        frmOrderedSongList frm= new frmOrderedSongList();
        frm.Show();
    }

    // 呼叫服務
    private void tsbtnService_Click(object sender, EventArgs e)
    {
        MessageBox.Show("服務!");
    }

    // 處理返回按鈕的事件
    private void tsbtnExit_Click(object sender, EventArgs e)
    {
        if (this.pnlSingerList.Visible)
        {

            this.pnlSingerType.Visible = true;
            this.pnlSingerList.Visible = false;
        }
        else if (this.pnlSingerType.Visible)
        {
            this.pnlSingerSex.Visible = true;
            this.pnlSingerType.Visible = false;
        }
        else if (this.pnlSingerSex.Visible)
        {
            this.Close();
        }
    }
    //點擊歌手的信息窗體時,彈出歌曲列表
    private void lvlistthree_Click(object sender, EventArgs e)
    {

        // 讀取數據庫,讀出該歌手的所有歌曲
        SqlConnection con = new SqlConnection(DBHelper.str);
        StringBuilder sb = new StringBuilder();
        sb.AppendFormat("select song_id,song_name,singer_info.singer_name,song_url,singer_info.singer_photo_url from song_info,singer_info where song_info.singer_id=singer_info.singer_id and singer_name='{0}' and song_info.singer_id={1}",
            lvlistthree.SelectedItems[0].Text, Convert.ToInt32(lvlistthree.SelectedItems[0].Tag));

        frmSongList frm = new frmSongList();
        frm.Sql = sb.ToString();


        frm.Onform = FanhuiForm.Singergender; // 指定返回的窗體是按歌手點歌
        frm.Show();
    }
    //當點擊歌手類別的窗體時,彈出某歌手的信息的船體
    private void lvlisttwo_Click(object sender, EventArgs e)
    {
        // 隱藏歌手類別,顯示歌手列表
        pnlSingerType.Visible = false;
        pnlSingerList.Location = pnlSingerSex.Location;
        pnlSingerList.Dock = DockStyle.Fill;
        pnlSingerList.Visible = true;
        this.singerTypeId = Convert.ToInt32(lvlisttwo.SelectedItems[0].Tag); // 保存選中的類別編號

        // 讀取數據庫,讀出歌手信息
        SqlConnection con = new SqlConnection(DBHelper.str);
        StringBuilder sql = new StringBuilder();
        sql.AppendFormat("select singer_id,singer_name,singer_photo_url from singer_info where singertype_id={0} and singer_gender='{1}'",
            this.singerTypeId, this.singergender);

        try
        {
            SqlCommand cmd = new SqlCommand(sql.ToString(), con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();
            int imageIndex = 0; // 代表歌手頭像的索引
            imglistthree.Images.Clear();

            // 循環讀出歌手信息添加到窗體中顯示
            lvlistthree.Items.Clear();
            while (dr.Read())
            {
                // 將歌手頭像放在ImageList控件中
                string photoURL = KTVUtil.singerPhotoPath + "\\" + Convert.ToString(dr["singer_photo_url"]);
                imglistthree.Images.Add(Image.FromFile(photoURL));

                // 將歌手添加到ListView中
                ListViewItem item = new ListViewItem();
                item.Text = Convert.ToString(dr["singer_name"]);
                item.Tag = Convert.ToString(dr["singer_id"]);
                item.ImageIndex = imageIndex;
                lvlistthree.Items.Add(item);

                imageIndex++;
            }
            dr.Close();
        }
        catch (Exception)
        {

            MessageBox.Show("錯誤!");
        }
        finally
        {
            con.Close();
        } 
    }
    //當點擊歌手的性別窗體時,彈出歌手的類別窗體的第一個listview
    private void lvlistone_Click(object sender, EventArgs e)
    {

        if (lvlistone.SelectedItems[0] != null)
        {
            // 隱藏歌手性別,顯示歌手類別
            pnlSingerSex.Visible = false;
            pnlSingerType.Location = pnlSingerSex.Location;
            pnlSingerType.Dock = DockStyle.Fill;
            pnlSingerType.Visible = true;
            // 記錄選擇的性別
            this.singergender = Convert.ToString(lvlistone.SelectedItems[0].Tag); 
        }

        // 讀取歌手類別
        SqlConnection con = new SqlConnection(DBHelper.str);
        string sql = "select * from singer_type";
        try
        {
            // 查詢數據庫
            SqlCommand command = new SqlCommand(sql, con);

            con.Open();
            SqlDataReader dr = command.ExecuteReader();

            // 循環將類別讀取出來添加到ListView中
            lvlisttwo.Items.Clear();
            int i = 0;
            while (dr.Read())
            {
                ListViewItem item = new ListViewItem();
                item.Text = Convert.ToString(dr["singertype_name"]);
                item.Tag = Convert.ToInt32(dr["singertype_id"]);
                item.ImageIndex = i;
                lvlisttwo.Items.Add(item);
                i++;
            }
            dr.Close();
        }
        catch (Exception)
        {

            MessageBox.Show("錯誤!");

        }
        finally
        {
            con.Close();
        }
    }
    private Point mouseOffset;        //記錄鼠標指針的坐標        
    private bool isMouseDown = false; //記錄鼠標按鍵是否按下  
    private void pnlon_MouseDown(object sender, MouseEventArgs e)
    {
        int xOffset;
        int yOffset;
        if (e.Button == MouseButtons.Left)
        {
            xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
            yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
            mouseOffset = new Point(xOffset, yOffset);
            isMouseDown = true;
        }
    }

    private void pnlon_MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
            Location = mousePos;
        }
    }

    private void pnlon_MouseUp(object sender, MouseEventArgs e)
    {
        // 修改鼠標狀態isMouseDown的值      
        // 確保只有鼠標左鍵按下并移動時,才移動窗體       
        if (e.Button == MouseButtons.Left)
        {
            isMouseDown = false;
        }
    }


}

}</pre>

05.歌曲列表

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyKTVClient {

// 定義枚舉,代表當前應該返回到的上一個窗體
public enum FanhuiForm
{
    Main, Singergender, SongType, WordCount, SongName, SongList
}

public partial class frmSongList : Form
{
    private string sql = "";
    private FanhuiForm onform;  // 上一個窗體


    // 該窗體應該返回到的上一個窗體

    public FanhuiForm Onform
    {
        get { return onform; }
        set { onform = value; }
    }


    // 歌曲列表查詢語句

    public string Sql
    {
        get { return sql; }
        set { sql = value; }
    }


    public frmSongList()
    {
        InitializeComponent();
    }

    // 返回
    SqlConnection con = new SqlConnection(DBHelper.str);
    private void tsbtnExit_Click(object sender, EventArgs e)
    {
        switch (this.Onform)
        {
            // 返回到歌手點歌
            case FanhuiForm.Singergender:
                frmOrderBySinger frm = new frmOrderBySinger();
                frm.Show();
                break;
            // 返回到歌曲類型點歌
            case FanhuiForm.SongType:
                frmOrderBySongType frm1 = new frmOrderBySongType();
                frm1.Show();
                break;
            // 返回到字數點歌
            case FanhuiForm.WordCount:
                frmOrderByWordCount frm2 = new frmOrderByWordCount();
                frm2.Show();
                break;
        }
        this.Close();
    }

    // 窗體加載時查詢歌曲列表
    private void SongListForm_Load(object sender, EventArgs e)
    {

        DataSet dataSet = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(this.Sql, con);
        da.Fill(dataSet, "info");
        dgvlist.DataSource = dataSet.Tables["info"];
    }        






    private void tsbtnService_Click(object sender, EventArgs e)
    {
        MessageBox.Show("服務中");
    }
    // 點播一首歌曲
    private void dgvlist_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        // 創建一個歌曲對象,并將選中的歌曲名和路徑賦給該對象
        Song song = new Song();
        song.SongName = dgvlist.SelectedRows[0].Cells["songName"].Value.ToString();
        song.SongURL = dgvlist.SelectedRows[0].Cells["songURL"].Value.ToString();
        song.Singerurl = dgvlist.SelectedRows[0].Cells["singerUrl"].Value.ToString();
        song.Singername = dgvlist.SelectedRows[0].Cells["singer"].Value.ToString();
        PlayList.AddSong(song);

        // 更新數據庫,將選中的歌曲點播次數加1
        int sId = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["songId"].Value);
  //string sql = "update song_info set song_play_count=song_play_count+1 where song_id="+sId+"";
        string sql = string.Format("update song_info set song_play_count=song_play_count+1 where song_id={0}", sId);
        try
        {
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();
            cmd.ExecuteNonQuery();
        }
        catch (Exception)
        {

            MessageBox.Show("出錯!");
        }
        finally
        {
            con.Close();
        }
    }
    //返回
    private void tsbtnExit_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }
    // 切歌
    private void tsbtnCut_Click(object sender, EventArgs e)
    {
        PlayList.CutSong(-1);
    }
    // 打開已點歌曲窗體
    private void tsbtnOrdered_Click(object sender, EventArgs e)
    {
        frmOrderedSongList frm = new frmOrderedSongList();
        frm.Show();
    }
    // 重新播放當前歌曲
    private void tsbtnAgain_Click(object sender, EventArgs e)
    {
        PlayList.PlayAgain();
    }
    //主界面
    private void tsbtnHome_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void frmSongList_MouseDown(object sender, MouseEventArgs e)
    {

    }

    private void frmSongList_MouseMove(object sender, MouseEventArgs e)
    {

    }

    private void frmSongList_MouseUp(object sender, MouseEventArgs e)
    {

    }

    private void pnlTop_MouseUp(object sender, MouseEventArgs e)
    {
        // 修改鼠標狀態isMouseDown的值      
        // 確保只有鼠標左鍵按下并移動時,才移動窗體       
        if (e.Button == MouseButtons.Left)
        {
            isMouseDown = false;
        }
    }
    private Point mouseOffset;        //記錄鼠標指針的坐標        
    private bool isMouseDown = false; //記錄鼠標按鍵是否按下 
    private void pnlTop_MouseDown(object sender, MouseEventArgs e)
    {
        int xOffset;
        int yOffset;
        if (e.Button == MouseButtons.Left)
        {
            xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
            yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
            mouseOffset = new Point(xOffset, yOffset);
            isMouseDown = true;
        }
    }

    private void pnlTop_MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
            Location = mousePos;
        }
    }



}

}</pre>

01. 播放界面

02. 已點歌曲

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MyKTVClient { public partial class frmOrderedSongList : Form { private FanhuiForm onform; // 上一個窗體

    /// <summary>
    /// 該窗體應該返回到的上一個窗體
    /// </summary>
    public string name;
    public FanhuiForm Onform
    {
        get { return onform; }
        set { onform = value; }
    }

    public frmOrderedSongList()
    {
        InitializeComponent();
    }

    private void OrderedSongListForm_Load(object sender, EventArgs e)
    {
        this.newSonglist();
        tim.Start();
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        //this.newSonglist();
    }


    //刷新歌曲列表
    private void newSonglist()
    {
        // 清空原列表
        lvlist.Items.Clear();
        int index = 0;
        while (PlayList.SongList[index] != null)
        {
            ListViewItem item = new ListViewItem();
            //獲取歌曲的名稱
            item.Text = PlayList.SongList[index].SongName;
            item.Tag = index;
            //歌曲的播放狀態
            string playState = PlayList.SongList[index].PlayState == SongPlayState.unplayed ? "未播放" : "已播放";
            item.SubItems.Add(playState);
            lvlist.Items.Add(item);
            index++;
        }
    }

    // 返回到上一個窗體
    private void tsbtnExit_Click(object sender, EventArgs e)
    {
        switch (this.Onform)
        {
            case FanhuiForm.Singergender:
                frmOrderBySinger frm = new frmOrderBySinger();
                frm.Show();
                break;
            case FanhuiForm.SongList:
                frmSongList frm1 = new frmSongList();
                frm1.Show();
                break;
            case FanhuiForm.SongName:
                frmOrderBySongName frm2 = new frmOrderBySongName();
                frm2.Show();
                break;
            case FanhuiForm.SongType:
                frmOrderBySongType frm3 = new frmOrderBySongType();
                frm3.Show();
                break;
            case FanhuiForm.WordCount:
                frmOrderByWordCount frm4 = new frmOrderByWordCount();
                frm4.Show();
                break;
        }

        this.Close();
    }      
    // 呼叫服務     
    private void tsbtnService_Click(object sender, EventArgs e)
    {
        MessageBox.Show("服務中");
    }
    //返回
    private void tsbtnExit_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }
    //已點
    private void tsbtnOrdered_Click(object sender, EventArgs e)
    {
        frmOrderedSongList frm = new frmOrderedSongList();
        frm.Show();
    }
    //切割
    private void tsbtnCut_Click_1(object sender, EventArgs e)
    {

            PlayList.CutSong(songId);
            this.newSonglist();

    }
    //重唱
    private void tsbtnAgain_Click_1(object sender, EventArgs e)
    {
        PlayList.PlayAgain();
    }
    //
    private void tsbtnHome_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }
    //刪除選中歌曲
    int songId = -1;  // 切歌的編號
    private void lvlist_Click(object sender, EventArgs e)
    {


        if (this.lvlist.SelectedItems.Count > 0)
        {
            songId = Convert.ToInt32(this.lvlist.SelectedItems[0].Tag);
        }
    }

    private void lvlist_MouseDown(object sender, MouseEventArgs e)
    {

    }
    private Point mouseOffset;        //記錄鼠標指針的坐標        
    private bool isMouseDown = false; //記錄鼠標按鍵是否按下
    private void frmOrderedSongList_MouseDown(object sender, MouseEventArgs e)
    {

    }

    private void frmOrderedSongList_MouseMove(object sender, MouseEventArgs e)
    {

    }

    private void frmOrderedSongList_Move(object sender, EventArgs e)
    {

    }

    private void frmOrderedSongList_MouseUp(object sender, MouseEventArgs e)
    {

    }

    private void pnlTop_MouseDown(object sender, MouseEventArgs e)
    {
        int xOffset;
        int yOffset;
        if (e.Button == MouseButtons.Left)
        {
            xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
            yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
            mouseOffset = new Point(xOffset, yOffset);
            isMouseDown = true;
        }
    }

    private void pnlTop_MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
            Location = mousePos;
        }
    }

    private void pnlTop_MouseUp(object sender, MouseEventArgs e)
    {
        // 修改鼠標狀態isMouseDown的值      
        // 確保只有鼠標左鍵按下并移動時,才移動窗體       
        if (e.Button == MouseButtons.Left)
        {
            isMouseDown = false;
        }
    }      

}</pre> 

3.拼音點歌

代碼:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyKTVClient { public partial class frmOrderBySongName : Form { public frmOrderBySongName() { InitializeComponent(); }

    // 查詢歌曲顯示在窗體中
    SqlConnection con = new SqlConnection(DBHelper.str);
    private void btnSearch_Click(object sender, EventArgs e)
    {

        DataSet ds = new DataSet();
        StringBuilder sb = new StringBuilder();
        sb.Append("select song_id,song_name,singer_info.singer_name,song_url,singer_info.singer_photo_url from song_info inner join singer_info on singer_info.singer_id=song_info.singer_id ");
        sb.AppendFormat("where song_name like '%{0}%' or song_ab like '{0}'", this.txtname.Text);

        Console.WriteLine(sb.ToString());

        SqlDataAdapter da = new SqlDataAdapter(sb.ToString(), con);

        // 在填充之前先清空當前列表
        if (ds.Tables["info"] != null)
        {
            ds.Tables["info"].Clear();
        }
        da.Fill(ds, "info");
        this.dgvlist.DataSource = ds.Tables["info"];
    }
    private void tsbtnExit_Click(object sender, EventArgs e)
    {

        this.Close();
    }

    // 服務      
    private void tsbtnService_Click(object sender, EventArgs e)
    {
        MessageBox.Show("服務中!");
    }
    private void dgvlist_CellClick(object sender, DataGridViewCellEventArgs e)
    {

        if (dgvlist.SelectedRows[0].Cells["songName"] != null)
        {
            // 創建一個歌曲對象,并將當權選中的歌曲名和路徑賦給該對象
            Song song = new Song();
            song.SongName = dgvlist.SelectedRows[0].Cells["songName"].Value.ToString();
            song.SongURL = dgvlist.SelectedRows[0].Cells["songURL"].Value.ToString();
            song.Singerurl = dgvlist.SelectedRows[0].Cells["singerUrl"].Value.ToString();
            PlayList.AddSong(song);

            //將選中的歌曲點播次數加1
            int songId = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["songId"].Value);
            string sql = string.Format("update song_info set song_play_count=song_play_count+1 where song_id={0}", songId);
            DBHelper dbHelper = new DBHelper();
            try
            {
                SqlCommand cmd = new SqlCommand(sql,con);
                con.Open();
                cmd.ExecuteNonQuery();
            }
            catch (Exception )
            {

                MessageBox.Show("異常");
            }
            finally
            {
                con.Close();
            }
        }
    }

    private void tsbtnExit_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }

    private void tsbtnCut_Click(object sender, EventArgs e)
    {
          if (MessageBox.Show("確定要切歌嗎?", "操作提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
        {
            PlayList.CutSong(-1);
        }

    }

    private void tsbtnOrdered_Click_1(object sender, EventArgs e)
    {
        frmOrderedSongList frm = new frmOrderedSongList();
        frm.Show();
    }

    private void tsbtnAgain_Click_1(object sender, EventArgs e)
    {
        PlayList.PlayAgain();
    }

    private void tsbtnHome_Click(object sender, EventArgs e)
    {
        this.Close();
    }
    private Point mouseOffset;        //記錄鼠標指針的坐標        
    private bool isMouseDown = false; //記錄鼠標按鍵是否按下  
    private void pnlon_MouseDown(object sender, MouseEventArgs e)
    {
        int xOffset;
        int yOffset;
        if (e.Button == MouseButtons.Left)
        {
            xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
            yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
            mouseOffset = new Point(xOffset, yOffset);
            isMouseDown = true;
        }
    }

    private void pnlon_MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
            Location = mousePos;
        }
    }

    private void pnlon_MouseUp(object sender, MouseEventArgs e)
    {
        // 修改鼠標狀態isMouseDown的值      
        // 確保只有鼠標左鍵按下并移動時,才移動窗體       
        if (e.Button == MouseButtons.Left)
        {
            isMouseDown = false;
        }
    }
}

}</pre>

01.點歌后的效果

4.已點歌曲里的切歌效果

代碼:

  //刪除選中歌曲
        int songId = -1;  // 切歌的編號
        private void lvlist_Click(object sender, EventArgs e)
        {

        if (this.lvlist.SelectedItems.Count > 0)
        {
            songId = Convert.ToInt32(this.lvlist.SelectedItems[0].Tag);
        }
    }


 //切歌
    private void tsbtnCut_Click_1(object sender, EventArgs e)
    {

            PlayList.CutSong(songId);
            this.newSonglist();

    }</pre> 

5.類型選擇

通過代碼把圖片動態加載進來

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyKTVClient { public partial class frmOrderBySongType : Form { public frmOrderBySongType() { InitializeComponent(); }

    private void tsbtnExit_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    // 窗體加載時,顯示歌曲類別
    SqlConnection con = new SqlConnection(DBHelper.str);
    private void OrderBySongTypeForm_Load(object sender, EventArgs e)
    {
        // 讀取歌曲類別         
        string sql = "select * from song_type";
        try
        {
            // 查詢數據庫
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            // 循環將類別讀取出來添加到ListView中
            this.lvlist.Items.Clear();
            int index = 0;
            while (dr.Read())
            {
                ListViewItem item = new ListViewItem();
                item.Text = Convert.ToString(dr["songtype_name"]);
                item.Tag = Convert.ToInt32(dr["songtype_id"]);
                item.ImageIndex = index;
                this.lvlist.Items.Add(item);
                index++;
            }
            dr.Close();
        }
        catch (Exception)
        {

            MessageBox.Show("錯誤!");

        }
        finally
        {
            con.Close();
        }
    }

    // 呼叫服務   
    private void tsbtnService_Click(object sender, EventArgs e)
    {
        MessageBox.Show("您呼叫服務中!");
    }

    private void lvlist_Click(object sender, EventArgs e)
    {
        // 讀取數據庫,讀出該歌手的所有歌曲

        StringBuilder sb = new StringBuilder();
        sb.Append("select song_id,song_name,singer_info.singer_name,song_url,singer_info.singer_photo_url from song_info inner join singer_info on song_info.singer_id=singer_info.singer_id ");
        sb.AppendFormat("where songtype_id={0}", Convert.ToInt32(lvlist.SelectedItems[0].Tag));
        Console.WriteLine(sb.ToString());
        frmSongList frm = new frmSongList();
        frm.Sql = sb.ToString();
        frm.Onform = FanhuiForm.SongType;
        frm.Show();

    }
    //
    private void tsbtnExit_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }
    //
    private void tsbtnOrdered_Click_1(object sender, EventArgs e)
    {
        frmOrderedSongList frm = new frmOrderedSongList();
        frm.Show();
    }
    //
    private void tsbtnCut_Click_1(object sender, EventArgs e)
    {
        PlayList.CutSong(-1);
    }
    //
    private void tsbtnAgain_Click(object sender, EventArgs e)
    {
        PlayList.PlayAgain();
    }

    private void tsbtnHome_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void pnlon_MouseUp(object sender, MouseEventArgs e)
    {
        // 修改鼠標狀態isMouseDown的值      
        // 確保只有鼠標左鍵按下并移動時,才移動窗體       
        if (e.Button == MouseButtons.Left)
        {
            isMouseDown = false;
        }
    }

    private void pnlon_MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
            Location = mousePos;
        }
    }
    private Point mouseOffset;        //記錄鼠標指針的坐標        
    private bool isMouseDown = false; //記錄鼠標按鍵是否按下  
    private void lvlist_MouseDown(object sender, MouseEventArgs e)
    {

    }

    private void pnlon_MouseDown(object sender, MouseEventArgs e)
    {
        int xOffset;
        int yOffset;
        if (e.Button == MouseButtons.Left)
        {
            xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
            yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
            mouseOffset = new Point(xOffset, yOffset);
            isMouseDown = true;
        }
    }
}

}</pre>

01.歌曲列表

6.金榜點歌

01.代碼同為一個歌曲列表窗體

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyKTVClient {

// 定義枚舉,代表當前應該返回到的上一個窗體
public enum FanhuiForm
{
    Main, Singergender, SongType, WordCount, SongName, SongList
}

public partial class frmSongList : Form
{
    private string sql = "";
    private FanhuiForm onform;  // 上一個窗體


    // 該窗體應該返回到的上一個窗體

    public FanhuiForm Onform
    {
        get { return onform; }
        set { onform = value; }
    }


    // 歌曲列表查詢語句

    public string Sql
    {
        get { return sql; }
        set { sql = value; }
    }


    public frmSongList()
    {
        InitializeComponent();
    }

    // 返回
    SqlConnection con = new SqlConnection(DBHelper.str);
    private void tsbtnExit_Click(object sender, EventArgs e)
    {
        switch (this.Onform)
        {
            // 返回到歌手點歌
            case FanhuiForm.Singergender:
                frmOrderBySinger frm = new frmOrderBySinger();
                frm.Show();
                break;
            // 返回到歌曲類型點歌
            case FanhuiForm.SongType:
                frmOrderBySongType frm1 = new frmOrderBySongType();
                frm1.Show();
                break;
            // 返回到字數點歌
            case FanhuiForm.WordCount:
                frmOrderByWordCount frm2 = new frmOrderByWordCount();
                frm2.Show();
                break;
        }
        this.Close();
    }

    // 窗體加載時查詢歌曲列表
    private void SongListForm_Load(object sender, EventArgs e)
    {

        DataSet dataSet = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(this.Sql, con);
        da.Fill(dataSet, "info");
        dgvlist.DataSource = dataSet.Tables["info"];
    }        






    private void tsbtnService_Click(object sender, EventArgs e)
    {
        MessageBox.Show("服務中");
    }
    // 點播一首歌曲
    private void dgvlist_CellClick(object sender, DataGridViewCellEventArgs e)
    {
        // 創建一個歌曲對象,并將選中的歌曲名和路徑賦給該對象
        Song song = new Song();
        song.SongName = dgvlist.SelectedRows[0].Cells["songName"].Value.ToString();
        song.SongURL = dgvlist.SelectedRows[0].Cells["songURL"].Value.ToString();
        song.Singerurl = dgvlist.SelectedRows[0].Cells["singerUrl"].Value.ToString();
        song.Singername = dgvlist.SelectedRows[0].Cells["singer"].Value.ToString();
        PlayList.AddSong(song);

        // 更新數據庫,將選中的歌曲點播次數加1
        int sId = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["songId"].Value);
  //string sql = "update song_info set song_play_count=song_play_count+1 where song_id="+sId+"";
        string sql = string.Format("update song_info set song_play_count=song_play_count+1 where song_id={0}", sId);
        try
        {
            SqlCommand cmd = new SqlCommand(sql, con);
            con.Open();
            cmd.ExecuteNonQuery();
        }
        catch (Exception)
        {

            MessageBox.Show("出錯!");
        }
        finally
        {
            con.Close();
        }
    }
    //返回
    private void tsbtnExit_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }
    // 切歌
    private void tsbtnCut_Click(object sender, EventArgs e)
    {
        PlayList.CutSong(-1);
    }
    // 打開已點歌曲窗體
    private void tsbtnOrdered_Click(object sender, EventArgs e)
    {
        frmOrderedSongList frm = new frmOrderedSongList();
        frm.Show();
    }
    // 重新播放當前歌曲
    private void tsbtnAgain_Click(object sender, EventArgs e)
    {
        PlayList.PlayAgain();
    }
    //主界面
    private void tsbtnHome_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void frmSongList_MouseDown(object sender, MouseEventArgs e)
    {

    }

    private void frmSongList_MouseMove(object sender, MouseEventArgs e)
    {

    }

    private void frmSongList_MouseUp(object sender, MouseEventArgs e)
    {

    }

    private void pnlTop_MouseUp(object sender, MouseEventArgs e)
    {
        // 修改鼠標狀態isMouseDown的值      
        // 確保只有鼠標左鍵按下并移動時,才移動窗體       
        if (e.Button == MouseButtons.Left)
        {
            isMouseDown = false;
        }
    }
    private Point mouseOffset;        //記錄鼠標指針的坐標        
    private bool isMouseDown = false; //記錄鼠標按鍵是否按下 
    private void pnlTop_MouseDown(object sender, MouseEventArgs e)
    {
        int xOffset;
        int yOffset;
        if (e.Button == MouseButtons.Left)
        {
            xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
            yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
            mouseOffset = new Point(xOffset, yOffset);
            isMouseDown = true;
        }
    }

    private void pnlTop_MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
            Location = mousePos;
        }
    }



}

}</pre>

7.字數點歌

01.通過for循環把1-12的數字循環打印出來

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MyKTVClient { public partial class frmOrderByWordCount : Form { public frmOrderByWordCount() { InitializeComponent(); }

    private void tsbtnExit_Click(object sender, EventArgs e)
    {
        this.Close();
    }
    SqlConnection con = new SqlConnection(DBHelper.str);
    private void OrderByWordCountForm_Load(object sender, EventArgs e)
    {         
        // 將字數列表添加到窗體中            
        for (int i = 0; i < 12; i++)
        {
            // 循環生成字數項添加到窗體中
            ListViewItem item = new ListViewItem();
            item.Text = (i + 1) + "個字";
            item.Tag = i + 1;
            lvlist.Items.Add(item);
        }                      
    }           
    // 呼叫服務     
    private void tsbtnService_Click(object sender, EventArgs e)
    {
        MessageBox.Show("服務中");
    }

    private void lvlist_Click(object sender, EventArgs e)
    {
        if (lvlist.SelectedItems[0] != null)
        {
            // 讀取數據庫,讀出該歌手的所有歌曲

            StringBuilder sb = new StringBuilder();
            sb.Append("select song_id,song_name,singer_info.singer_name,song_url,singer_info.singer_photo_url  from song_info inner join singer_info on song_info.singer_id=singer_info.singer_id ");
            sb.AppendFormat("where song_word_count={0}", Convert.ToInt32(lvlist.SelectedItems[0].Tag));
            Console.WriteLine(sb.ToString());
            frmSongList frm = new frmSongList();
            frm.Sql = sb.ToString();
            frm.Onform = FanhuiForm.WordCount;
            frm.Show();

        }
    }
    //
    private void tsbtnExit_Click_1(object sender, EventArgs e)
    {
        this.Close();
    }
    //
    private void tsbtnOrdered_Click_1(object sender, EventArgs e)
    {
        frmOrderedSongList frm = new frmOrderedSongList();
        frm.Show();
    }
    //
    private void tsbtnCut_Click_1(object sender, EventArgs e)
    {
           PlayList.CutSong(-1);

    }
    //     // 重新播放當前歌曲       
    private void tsbtnAgain_Click_1(object sender, EventArgs e)
    {
        PlayList.PlayAgain();
    }

    private void tsbtnHome_Click(object sender, EventArgs e)
    {
        this.Close();
    }
     private Point mouseOffset;        //記錄鼠標指針的坐標        
    private bool isMouseDown = false; //記錄鼠標按鍵是否按下   
    private void pnlon_MouseDown(object sender, MouseEventArgs e)
    {

        int xOffset;
        int yOffset;
        if (e.Button == MouseButtons.Left)
        {
            xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
            yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
            mouseOffset = new Point(xOffset, yOffset);
            isMouseDown = true;
        }
    }

    private void pnlon_MouseMove(object sender, MouseEventArgs e)
    {
        if (isMouseDown)
        {
            Point mousePos = Control.MousePosition;
            mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
            Location = mousePos;
        }
    }

    private void pnlon_MouseUp(object sender, MouseEventArgs e)
    {
        // 修改鼠標狀態isMouseDown的值      
        // 確保只有鼠標左鍵按下并移動時,才移動窗體       
        if (e.Button == MouseButtons.Left)
        {
            isMouseDown = false;
        }
    }
}

}</pre>

02.歌曲列表

03.已點列表

8.最后再看看重唱的功能展示以及代碼

01.重唱

 // 重新播放當前歌曲
        private void tsbtnAgain_Click(object sender, EventArgs e)
        {
            PlayList.PlayAgain();
            PlaySong();
        }

前臺算告一段落了,如果覺得對你有幫助的話,可以關注,如覺得還可以就個你的痕跡。

01.主窗體

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace KTV { public partial class FrmMain : Form { public FrmMain() { InitializeComponent(); } //新增 private void tsnewadd_Click(object sender, EventArgs e) { //新增 frmAddSinger frm = new frmAddSinger(); frm.MdiParent = this; frm.Show();//以本窗體為父窗體打開 } //查詢歌手 private void tssingerselect_Click(object sender, EventArgs e) { //查詢歌手信息 FrmSelectSinger frm = new FrmSelectSinger(); frm.MdiParent = this; frm.Show();//以本窗體為父窗體打開 } //退出 private void tsexit_Click(object sender, EventArgs e) { //退出應用程序 Application.Exit(); } //查詢歌曲 private void tssongselect_Click(object sender, EventArgs e) { }

    private void tslujing_Click(object sender, EventArgs e)
    {           
    }

    private void tssong_Click(object sender, EventArgs e)
    {

    }

    private void tshelping_Click(object sender, EventArgs e)
    {
        //幫助
        MessageBox.Show("幫助規則");
    }

    private void tsAddSong_Click(object sender, EventArgs e)
    {
        //保存歌曲
        FrmAdd frm = new FrmAdd();
        frm.MdiParent = this;
        frm.Show();
    }

    private void TsSeSong_Click(object sender, EventArgs e)
    {
        //查詢歌曲信息
        frmselectSong frm = new frmselectSong();
        frm.MdiParent = this;
        frm.Show();//以本窗體為父窗體打開
    }

    private void TSsonger_Click(object sender, EventArgs e)
    {
        //路徑
        frmAddSongURL frm = new frmAddSongURL();
        frm.Show();
    }


}

}</pre>

01.添加歌手

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;

namespace KTV { public partial class frmAddSinger : Form { public string uname; public frmAddSinger() { InitializeComponent(); } //默認給原路徑賦值 public string OldLoadWays() { //測試 SqlConnection con = new SqlConnection(DBHelp.str); string sql = "select resource_path from resource_path where resource_id=1"; SqlCommand cmd = new SqlCommand(sql, con); string songUrl = ""; try { con.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr != null) { if (dr.HasRows) { while (dr.Read()) { songUrl = dr["resource_path"].ToString(); } } } } catch (Exception) { MessageBox.Show("網絡異常!"); ; } finally { con.Close(); } return songUrl; } //下拉框 public void Singerselect() { string str = DBHelp.str; //連接數據庫 SqlConnection con = new SqlConnection(str); string sql = "select singertype_id,singertype_name from singer_type"; //數據集和數據庫連接 SqlDataAdapter da = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); try { da.Fill(ds); //綁定數據源 DataTable dt = ds.Tables[0]; DataRow dr = dt.NewRow(); //給該行賦值 dr[0] = -1; dr[1] = "請選擇"; dt.Rows.InsertAt(dr, 0); cbotype.DataSource = ds.Tables[0]; //下拉框顯示值 cbotype.DisplayMember = "singertype_name"; //下拉框隱藏值 cbotype.ValueMember = "singertype_id"; } catch (Exception) { MessageBox.Show("加載失敗!"); } finally { con.Close(); } } private void frmAddSinger_Load(object sender, EventArgs e) { Singerselect(); Commod.DBsongurl=OldLoadWays(); if (this.Text=="修改歌手信息") { btnadd.Text = "修改"; //MessageBox.Show(uname); Load_information(); } else { this.Text = "編輯歌手信息"; btnadd.Text = "保存"; } } string fileName = ""; string fullName = "";

    private void btnView_Click(object sender, EventArgs e)
    {

        //瀏覽
        if (this.ofdlist.ShowDialog() == DialogResult.OK)
        {

            fileName = this.ofdlist.SafeFileName; // 文件名
            fullName = this.ofdlist.FileName;
            picphoto.Image = Image.FromFile(fullName);
            txtdescrp.Text = fullName;
        }
    }
    //添加
    public void SongInfoAdd()
    { 
       string name = txtname.Text;//歌手姓名
        string type = "";//類別
        if (ramale.Checked)
        {
            type = "男";
        }
        else if (rafemale.Checked)
        {
            type = "女";
        }
        else if (raguoup.Checked)
        {
            type = "組合";
        }
        int id = Convert.ToInt32(cbotype.SelectedValue);//類型            
        string description = txtdescrp.Text;//描述
        SqlConnection con = new SqlConnection(DBHelp.str);
        string sql = "insert into singer_info values('" + name + "'," + id + ",'" + type + "','" + fileName + "','" + description + "')";
        SqlCommand cmd = new SqlCommand(sql,con);
        try
        {
            con.Open();
            int count = cmd.ExecuteNonQuery();
            if (count > 0)
            {
                File.Copy(fullName, Commod.DBsongurl + "\\" + fileName, true);
                MessageBox.Show("歌手添加成功");
            }
            else
            {
                MessageBox.Show("歌手添加失敗");
            }
        }
        catch (Exception)
        {

            MessageBox.Show("歌手加載失敗"); ;
        }
        finally
        {
            con.Close();//關閉
        }
    }
    //修改
    public void SongInfoUpdate()
    { 

    }
    //關閉
    private void btnclose_Click(object sender, EventArgs e)
    {
        this.Close();
    }

    private void btnadd_Click(object sender, EventArgs e)
    {
        if (this.Text=="修改歌手信息")
        {
            Update();//修改
        }
        else
        {
            SongInfoAdd();//保存功能
        }

    }
    //load修改
    string ch="";//單選按鈕值
    int type = 0;
    public void Load_information()
    {


        SqlConnection con = new SqlConnection(DBHelp.str);
        string sql = "select singer_name,singer_gender,singertype_id,singer_description from singer_info where singer_name ='" + uname + "'";
        con.Open();
        SqlCommand cmd = new SqlCommand(sql, con);
        SqlDataReader dr = cmd.ExecuteReader();
        try
        {
            if (dr != null)
            {
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        txtname.Text = dr["singer_name"].ToString();
                        ch = dr["singer_gender"].ToString();
                        #region MyRegion判斷男女,給單選按鈕賦值
                        if (ch == "男")
                        {
                            ramale.Checked = true;
                        }
                        else if (ch == "女")
                        {
                            rafemale.Checked = true;
                        }
                        else
                        {
                            raguoup.Checked = true;
                        }
                        #endregion

                        int type = Convert.ToInt32(dr["singertype_id"]);
                        #region MyRegion 給下拉框賦值
                        if (type == 1)
                        {
                            cbotype.Text = "大陸";
                        }
                        else if (type == 2)
                        {
                            cbotype.Text = "香港";
                        }
                        else if (type == 3)
                        {
                            cbotype.Text = "臺灣";
                        }
                        else if (type == 4)
                        {
                            cbotype.Text = "歐美";
                        }
                        else if (type == 5)
                        {
                            cbotype.Text = "日韓";
                        }
                        #endregion

                        txtdescrp.Text = dr["singer_description"].ToString();                            
                    }
                }
            }
        }
        catch (Exception)
        {
            MessageBox.Show("歌手個別信息不完善!!!");
        }
        finally
        {
            con.Close();
        }
    }
    //修改
    public void Update()
    {
        int songid = Convert.ToInt32(cbotype.SelectedValue);
        int num = txtname.Text.Length;
        SqlConnection con = new SqlConnection(DBHelp.str);
        //singer_id, singer_name, singertype_id, singer_gender, singer_photo_url, singer_description
        string sql = @"update singer_info set singer_name='" + txtname.Text + "',singer_gender='" + ch + "',singer_photo_url='" + fileName +
                     "',singertype_id=" + type + ",singer_description='"+txtdescrp.Text+"' where singer_name ='" + uname + "'";
        SqlCommand cmd = new SqlCommand(sql, con);
        try
        {
            con.Open();
            int count = cmd.ExecuteNonQuery();
            if (count > 0)
            {
                MessageBox.Show("修改成功");
            }
        }
        catch (Exception)
        {

            MessageBox.Show("加載失敗"); ;
        }
        finally
        {
            con.Close();
        }
    }
}

}</pre>

由于一些問題暫不能幫你們把KTV項目完全展示, 不過后臺會很快補回來的,如果想多了解點知識,就多多的來學習吧!博客園都在等你們啊。。。。。。

</div>

 本文由用戶 vn714072 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!