一個項目,一分收獲;一個項目,一些資源。Ktv項目也是一樣的,所以我想分享我的收獲,讓你們獲得你需要的資源。
一. 那MyKTV點歌系統具體的功能有哪些呢?我們就來看看吧!
1.MyKTV前台功能:
01.歌星點歌 、拼音點歌 、數字點歌 、類型選擇 、金榜排行
02.切歌 、點歌 、重唱和退出
2.MyKTV后台功能:
01.歌手管理 、歌曲管理 、設置資源路徑
02.新增歌手、歌曲 ,查詢歌手、歌曲信息,設置歌曲路徑和退出
二. 功能已經概括的差不多了,就讓我們一起來看看MyKTV的項目吧
四個輔助類
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyKTV { class KTVUtil { public static string picturePath = ""; public static string songPath = ""; } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyKTV { class PlayList { public static Song[] SongList=new Song[1000]; //當前播放的歌曲在數組中的索引(已點列表) public static int SongIndex = 0; //點一首歌,相當於將歌曲放在數組中 public static bool AddSong(Song song) { bool result = false;//記錄添加歌曲是否成功 for (int i = 0; i < SongList.Length; i++) { if (SongList [i]==null) { SongList[i] = song; result = true; break; } } return result; } //獲取當前播放的歌曲 既然是獲取當前播放的歌曲,返回值肯定是Song類型 public static Song GetPlaySong() { if (SongList [SongIndex]!=null) { return SongList[SongIndex]; } else { return null; } } //播放下一首 public static void Next() { if (SongList[SongIndex] != null && SongList[SongIndex].PlayStar== SongPlayState.again) { SongList[SongIndex].SongPlayed(); } else { SongIndex++; if (SongList[SongIndex]!=null) { SongList[SongIndex].SongPlayed(); } } } //當前播放的歌曲名稱 public static string PlaySongName() { string songname = ""; if (SongList[SongIndex]!=null) { songname=SongList[SongIndex].SongName; } return songname; } //下一首要播放的歌曲名稱 public static string NextSongName() { string songname = ""; //if (SongList[SongIndex+1] != null&&SongList[0]!=null) //{ // songname = SongList[SongIndex+1].SongName; //} //return songname; if (SongList[0] != null && SongList[SongIndex + 1] == null) { songname = "待添加...."; return songname; } else { if (SongList[0] != null) { songname = SongList[SongIndex + 1].SongName; return songname; } else { return string.Empty; } } } //重唱 public static void PalyAgain() { if (SongList[SongIndex]!=null) { SongList[SongIndex].SongAgain(); } } //切歌 public static void Cutsong() { //獲取到當前播放的歌曲改變播放狀態 if (SongList [SongIndex] != null) { SongList [SongIndex].PlayStar = SongPlayState.cut; SongIndex++; //改變歌曲索引,播放下一首 } } ////切歌 // public static void CutSong(int index) // { // //迭代變量,代表切歌位置 // int i; // if (index==-1)//循環變量,代表切歌位置 // { // i=SongIndex; // }else // { // //從切歌的位置開始,將歌曲逐個向前移動一個位置 // i=index; // } // SongList[i].SongCut(); // while (SongList[i]!=null) // { // SongList[i]=SongList[i+1]; // i++; // } // } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyKTV { enum SongPlayState { //未播放,播放,重播,切歌 unplayer, played, again, cut } public class Song { private string songName; public string SongName { get { return songName; } set { songName = value; } } private string songUrl; public string SongUrl { get { return songUrl; } set { songUrl = value; } } //歌曲播放狀態默認為未播放 private SongPlayState playStar = SongPlayState.unplayer; internal SongPlayState PlayStar { get { return playStar; } set { playStar = value; } } //將歌曲狀態改為播放 public void SongPlayed() { this.PlayStar = SongPlayState.played; } //歌曲狀態重播 public void SongAgain() { this.PlayStar = SongPlayState.again; } //歌曲狀態切歌 public void SongCut() { this.PlayStar = SongPlayState.cut; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyKTV { class SqlUtil { public static string str = "data source=.;initial catalog=KTV;user id=sa;pwd=718191"; } }
1.首先就是展現KTV的主界面,讓我們先了解一下那些功能

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.Data.SqlClient;
namespace MyKTV
{
public partial class frmMain : Form
{
public frmMain()
{
//InitializeComponent();
}
private void btnGX_Click(object sender, EventArgs e)
{
frmGXDG1 fg = new frmGXDG1();
fg.form1 = this;
fg.Show();
this.Hide();
}
//獲取歌曲路徑
public void SongPath()
{
string sql = "select resourcepath from resourcepath where resourceid=1";
SqlConnection con = new SqlConnection(SqlUtil.str);
SqlCommand com = new SqlCommand(sql, con);
try
{
con.Open();
KTVUtil.songPath= com.ExecuteScalar().ToString();
}
catch (Exception)
{
throw;
}
finally
{
con.Close();
}
}
private void frmMain_Load(object sender, EventArgs e)
{
//讀取歌曲路徑
SongPath();
//讀取resourcepath表中的歌手圖片
string sql = "select resourcepath from resourcepath where resourceid=2";
SqlConnection con = new SqlConnection(SqlUtil.str);
SqlCommand com = new SqlCommand(sql,con);
try
{
con.Open();
KTVUtil.picturePath=com.ExecuteScalar().ToString();
}
catch (Exception)
{
throw;
}
finally
{
con.Close();
}
}
private Song song;//當前播放的歌曲
//播放歌曲
public void PlaySong()
{
//調用播放當前歌曲方法
this.song = PlayList.GetPlaySong();
if (song!=null)
{
//改變播放狀態為播放
this.song.SongPlayed();
Player2.URL = KTVUtil.songPath + "\\" + this.song.SongUrl;
txtIng.Text = PlayList.PlaySongName();
}
}
private void btnPY_Click(object sender, EventArgs e)
{
frmPY fp = new frmPY();
fp.Show();
}
private void btnSZ_Click(object sender, EventArgs e)
{
frmNum fn = new frmNum();
fn.Show();
}
private void btnLX_Click(object sender, EventArgs e)
{
frmType ft = new frmType();
ft.getSong(song);
ft.Show();
}
private void btnJB_Click(object sender, EventArgs e)
{
frmPaiHang fp = new frmPaiHang();
fp.Show();
}
private void toolStripButton3_Click(object sender, EventArgs e)
{
frmYiDian fy = frmYiDian.getFrm();
fy.Show();
}
private void panel2_Paint(object sender, PaintEventArgs e)
{
}
public static int cutSong = 0;
private void timer1_Tick(object sender, EventArgs e)
{
String nextSongName = PlayList.NextSongName();
txtNext.Text = nextSongName;
if (song == null)
{
PlaySong();
}
if (Player2.playState == WMPLib.WMPPlayState.wmppsStopped)
{
song = null;
PlayList.Next();
}
if (song != null && this.song.PlayStar == SongPlayState.cut)
{
this.song = null;
}
if (song != null)
{
if (this.song.PlayStar == SongPlayState.again)
{
this.song = null;
}
}
}
private void toolStripButton5_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Player2_Enter(object sender, EventArgs e)
{
}
private void timNow_Tick(object sender, EventArgs e)
{
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
DialogResult result = MessageBox.Show("確定要切歌嗎?", "", MessageBoxButtons.YesNo);
if (result==DialogResult.Yes)
{
PlayList.Cutsong();
}
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
PlayList.PalyAgain();
}
private void txtIng_TextChanged(object sender, EventArgs e)
{
//txtIng.Text = PlayList.PlaySongName();
}
private void txtNext_TextChanged(object sender, EventArgs e)
{
// txtNext.Text = PlayList.NextSongName();
}
private void timer2_Tick(object sender, EventArgs e)
{
}
//原唱伴唱(可惜沒實現)
private void button1_Click(object sender, EventArgs e)
{
if (Player2.settings.balance==100)
{
Player2.settings.balance = -100;
}
else
{
Player2.settings.balance = 100;
}
}
}
}
2.歌星點歌(三個listview的集成窗體)
01.歌手類別

02.歌手地區

03.歌手姓名

04.代碼
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.Data.SqlClient; namespace MyKTV { public partial class frmGXDG1 : Form { public frmGXDG1() { InitializeComponent(); } public int a = 1;//三個listview標示 public int typeid = 0; public string sex = "組合"; public frmMain form1 = null; private void frmGXDG1_Load(object sender, EventArgs e) { this.listView2.Visible = false; this.listView3.Visible = false; } //動態加載第二個listView五個圖片 private void listView1_Click(object sender, EventArgs e) { a = 2; if (listView1.SelectedItems[0]!=null) { listView2.Visible = true; listView2.Location = listView1.Location; //記錄第一個listview所選類型 sex = listView1.SelectedItems[0].Tag.ToString(); } string sql = "select singercountryid,singercountryname from singercountry"; SqlConnection con = new SqlConnection(SqlUtil.str); SqlCommand com = new SqlCommand(sql, con); try { con.Open(); SqlDataReader reader = com.ExecuteReader(); listView2.Items.Clear(); if (reader.HasRows) { int num = 0; while (reader.Read()) { ListViewItem lv = new ListViewItem(); lv.Text = reader["singercountryname"].ToString(); lv.Tag = Convert.ToInt32(reader["singercountryid"]); lv.ImageIndex = num; listView2.Items.Add(lv); num++; } reader.Close(); } } catch (Exception) { throw; } finally { con.Close(); } } private void listView2_Click(object sender, EventArgs e) { a = 3; if (listView2.SelectedItems[0]!=null) { listView2.Visible = false; listView3.Visible = true; listView3.Location = listView2.Location; //保存所選擇的地區編號 typeid = Convert.ToInt32(listView2.SelectedItems[0].Tag); string result=sex; if (sex!="組合") { result=sex ; } string sql = "select singername,singerphotourl,singerid from singerinfo where singercountryid='"+typeid+"' and singersex='"+result+"'"; SqlConnection con = new SqlConnection(SqlUtil.str); SqlCommand com = new SqlCommand(sql,con); try { con.Open(); SqlDataReader reader = com.ExecuteReader(); listView3.Items.Clear();//清空listview列表集合 if (reader.HasRows) { int num = 0;//添加的圖片下標 imageList3.Images.Clear();//情況圖片集合 while (reader.Read()) { //讀取圖片地址 string path = KTVUtil.picturePath + "\\" + reader["singerphotourl"].ToString(); //把讀取出來的圖片添加到imagelist3上 imageList3.Images.Add(Image.FromFile(path)); ListViewItem lv = new ListViewItem(); lv.Text=reader["singername"].ToString(); lv.Tag = Convert.ToInt32(reader["singerid"]); lv.ImageIndex = num; listView3.Items.Add(lv); num++; } } } catch (Exception) { throw; } finally { con.Close(); } } } private void listView3_Click(object sender, EventArgs e) { string sql = @"select singername,songname,songurl,songid from singerinfo as s,songinfo as f where s.singerid=f.singerid and singername='"+listView3.SelectedItems[0].Text+"'"; frmSongList fs = new frmSongList(); fs.sql = sql; fs.Show(); } private void tsbYD_Click(object sender, EventArgs e) { frmYiDian fy = frmYiDian.getFrm(); fy.Show(); } private void listView1_SelectedIndexChanged(object sender, EventArgs e) { } private void tsbFH_Click(object sender, EventArgs e) { if (a==2) { a = 1; this.listView1.Visible = true; this.listView2.Visible = false; this.listView3.Visible = false; }else if (a==3) { a = 2; listView2.Visible = true; listView1.Visible = false; listView3.Visible = false; }else if (a==1) { form1.Show(); } } private void tsbTC_Click(object sender, EventArgs e) { form1.Show(); this.Close(); } private void listView3_SelectedIndexChanged(object sender, EventArgs e) { } private void tsbCC_Click(object sender, EventArgs e) { PlayList.PalyAgain(); } private void tsbQG_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("確定要切歌嗎?", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { PlayList.Cutsong(); } } } }
05.歌曲列表

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.Data.SqlClient; namespace MyKTV { public partial class frmSongList : Form { public string sql = ""; public int count = 0; public frmSongList() { InitializeComponent(); } private void frmSongList_Load(object sender, EventArgs e) { if (count != 0) { string numsql = "select singername,songname,songurl,songid from singerinfo as s,songinfo as f where s.singerid=f.singerid and songcount=" + count + ""; NewMethod(numsql); } else { NewMethod(sql); } } //加載frmSongList控件里dgvList數據 private void NewMethod(string sql) { dgvList.AutoGenerateColumns = false; SqlConnection con = new SqlConnection(SqlUtil.str); SqlDataAdapter da = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); da.Fill(ds); dgvList.DataSource = ds.Tables[0]; } private void dgvList_CellClick(object sender, DataGridViewCellEventArgs e) { //點擊某首歌曲,並將選中的歌曲名和路徑賦給該對象() Song song = new Song(); song.SongName = dgvList.SelectedRows[0].Cells[0].Value.ToString(); string a = dgvList.SelectedRows[0].Cells[2].Value.ToString(); song.SongUrl=a; PlayList.AddSong(song); string name = dgvList.SelectedRows[0].Cells[0].Value.ToString(); addCount(name); } public void addCount(string name) { SqlConnection con = new SqlConnection(SqlUtil.str); string sql = "update songinfo set songplaycount+=1 where songname='"+name+"'"; SqlCommand com = new SqlCommand(sql,con); try { con.Open(); int num = com.ExecuteNonQuery(); } catch (Exception) { throw; } finally { con.Close(); } } private void dgvList_CellContentClick(object sender, DataGridViewCellEventArgs e) { } } }
字數點歌

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 MyKTV { public partial class frmNum : Form { public frmNum() { InitializeComponent(); } int count = 0; private void btn1_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn1.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void btn2_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn2.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void btn3_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn3.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void btn4_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn4.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void btn5_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn5.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void btn6_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn6.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void btn7_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn7.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void btn8_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn8.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void btn9_Click(object sender, EventArgs e) { count = Convert.ToInt32(btn9.Text); frmSongList fs = new frmSongList(); fs.count = count; fs.Show(); } private void toolStripButton2_Click(object sender, EventArgs e) { PlayList.PalyAgain(); } private void toolStripButton1_Click(object sender, EventArgs e) { } private void toolStripButton3_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("確定要切歌嗎?", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { PlayList.Cutsong(); } } private void toolStripButton4_Click(object sender, EventArgs e) { frmYiDian fy = frmYiDian.getFrm(); fy.Show(); } private void frmNum_Load(object sender, EventArgs e) { } } }
金榜排行

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.Data.SqlClient; namespace MyKTV { public partial class frmPaiHang : Form { public frmPaiHang() { InitializeComponent(); } private void frmPaiHang_Load(object sender, EventArgs e) { Initial(); } public void Initial() { SqlConnection con = new SqlConnection(SqlUtil.str); string sql = "select singername,songname,songplaycount,songurl from singerinfo as s,songinfo as f where s.singerid=f.singerid order by songplaycount desc"; SqlCommand com = new SqlCommand(sql, con); try { con.Open(); SqlDataReader reader = com.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string songname = Convert.ToString(reader["songname"]); string singername = Convert.ToString(reader["singername"]); int count = Convert.ToInt32(reader["songplaycount"]); string songurl = Convert.ToString(reader["songurl"]); ListViewItem lv = new ListViewItem(songname); lv.SubItems.Add(singername); lv.SubItems.Add(count.ToString()); lv.SubItems.Add(songurl); lvPH1.Items.Add(lv); } } } catch (Exception) { throw; } finally { con.Close(); } } private void toolStripButton4_Click(object sender, EventArgs e) { frmYiDian fy = frmYiDian.getFrm(); fy.Show(); } private void lvPH_SelectedIndexChanged(object sender, EventArgs e) { } private void lvPH_Click(object sender, EventArgs e) { } private void listView1_SelectedIndexChanged(object sender, EventArgs e) { } private void listView1_Click(object sender, EventArgs e) { Song song = new Song(); song.SongName = lvPH1.SelectedItems[0].SubItems[0].Text; song.SongUrl = lvPH1.SelectedItems[0].SubItems[3].Text; PlayList.AddSong(song); frmSongList fs = new frmSongList(); string name = lvPH1.SelectedItems[0].SubItems[0].Text; fs.addCount(name); this.lvPH1.Items.Clear(); Initial(); } private void toolStripButton2_Click(object sender, EventArgs e) { PlayList.PalyAgain(); } private void toolStripButton3_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("確定要切歌嗎?", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { PlayList.Cutsong(); } } private void timer1_Tick(object sender, EventArgs e) { this.lvPH1.Items.Clear(); ; Initial(); } } }
類型點歌

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 MyKTV { public partial class frmType : Form { public frmType() { InitializeComponent(); } private Song song;//當前播放的歌曲 public void getSong(Song so){ this.song=so; } private void lvType_SelectedIndexChanged(object sender, EventArgs e) { } //類型點歌 private void lvType_Click(object sender, EventArgs e) { string sql = "select singername,songname,songurl,songid from singerinfo as s,songinfo as f where s.singerid=f.singerid and songtype='" +lvType.SelectedItems[0].Text+ "'"; frmSongList fs = new frmSongList(); fs.sql = sql; fs.Show(); } private void toolStripButton4_Click(object sender, EventArgs e) { frmYiDian fy = frmYiDian.getFrm(); fy.Show(); } private void frmType_Load(object sender, EventArgs e) { } private void toolStripButton2_Click(object sender, EventArgs e) { PlayList.PalyAgain(); } private void toolStripButton3_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("確定要切歌嗎?", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { PlayList.Cutsong(); } } } }
拼音點歌

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.Data.SqlClient; namespace MyKTV { public partial class frmPY : Form { public frmPY() { InitializeComponent(); } public string py = ""; private void butA_Click(object sender, EventArgs e) { py += btnA.Text; txtPY.Text = py; select(); } private void butB_Click(object sender, EventArgs e) { py += btnB.Text; txtPY.Text = py; select(); } private void butC_Click(object sender, EventArgs e) { py += btnC.Text; txtPY.Text = py; select(); } private void btnD_Click(object sender, EventArgs e) { py += btnD.Text; txtPY.Text = py; select(); } private void btnE_Click(object sender, EventArgs e) { py += btnE.Text; txtPY.Text = py; select(); } private void btnF_Click(object sender, EventArgs e) { py += btnF.Text; txtPY.Text = py; select(); } private void btnG_Click(object sender, EventArgs e) { py += btnG.Text; txtPY.Text = py; select(); } private void btnH_Click(object sender, EventArgs e) { } private void btnI_Click(object sender, EventArgs e) { py += btnI.Text; txtPY.Text = py; select(); } private void btnK_Click(object sender, EventArgs e) { py += btnK.Text; txtPY.Text = py; select(); } private void btnL_Click(object sender, EventArgs e) { py += btnL.Text; txtPY.Text = py; select(); } private void btnM_Click(object sender, EventArgs e) { py += btnM.Text; txtPY.Text = py; select(); } private void btnN_Click(object sender, EventArgs e) { py += btnN.Text; txtPY.Text = py; select(); } private void btnO_Click(object sender, EventArgs e) { py += btnO.Text; txtPY.Text = py; select(); } private void btnP_Click(object sender, EventArgs e) { py += btnP.Text; txtPY.Text = py; select(); } private void btnQ_Click(object sender, EventArgs e) { py += btnQ.Text; txtPY.Text = py; select(); } private void btnR_Click(object sender, EventArgs e) { py += btnR.Text; txtPY.Text = py; select(); } private void btnS_Click(object sender, EventArgs e) { py += btnS.Text; txtPY.Text = py; select(); } private void btnT_Click(object sender, EventArgs e) { py += btnT.Text; txtPY.Text = py; select(); } private void btnU_Click(object sender, EventArgs e) { py += btnU.Text; txtPY.Text = py; select(); } private void btnV_Click(object sender, EventArgs e) { py += btnV.Text; txtPY.Text = py; select(); } private void btnW_Click(object sender, EventArgs e) { py += btnW.Text; txtPY.Text = py; select(); } private void btnX_Click(object sender, EventArgs e) { py += btnX.Text; txtPY.Text = py; select(); } private void btnY_Click(object sender, EventArgs e) { py += btnY.Text; txtPY.Text = py; select(); } private void btnZ_Click(object sender, EventArgs e) { py += btnZ.Text; txtPY.Text = py; select(); } private void btnJ_Click(object sender, EventArgs e) { py += btnJ.Text; txtPY.Text = py; select(); } private void btnPY_Click(object sender, EventArgs e) { int length = py.Length; if (length>0) { py = py.Substring(0,length-1); txtPY.Text = py; select(); } } //拼音模糊查詢 public void select() { dgvPY.AutoGenerateColumns = false; string sql = @"select singername,songname,songurl,songid from singerinfo as s,songinfo as f where s.singerid=f.singerid and songab like '" + txtPY.Text + "%'"; SqlConnection con = new SqlConnection(SqlUtil.str); SqlDataAdapter da = new SqlDataAdapter(sql, con); DataSet ds = new DataSet(); da.Fill(ds); dgvPY.DataSource = ds.Tables[0]; } private void txtPY_TextChanged(object sender, EventArgs e) { select(); } private void btnH_Click_1(object sender, EventArgs e) { py += btnH.Text; txtPY.Text = py; select(); } private void toolStripButton4_Click(object sender, EventArgs e) { frmYiDian fy = frmYiDian.getFrm(); fy.Show(); } private void dgvPY_CellClick(object sender, DataGridViewCellEventArgs e) { Song song = new Song(); song.SongName = dgvPY.SelectedRows[0].Cells[0].Value.ToString(); string a = dgvPY.SelectedRows[0].Cells[2].Value.ToString(); song.SongUrl = a; PlayList.AddSong(song); } private void frmPY_Load(object sender, EventArgs e) { } private void panel1_Paint(object sender, PaintEventArgs e) { } private void toolStripButton2_Click(object sender, EventArgs e) { PlayList.PalyAgain(); } private void toolStripButton3_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("確定要切歌嗎?", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { PlayList.Cutsong(); } } } }
已點列表

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 MyKTV { public partial class frmYiDian : Form { private frmYiDian() { InitializeComponent(); } public static frmYiDian frm; public static frmYiDian getFrm() { if (frm==null) { frm = new frmYiDian(); } return frm; } public static int style = 1; private void lvYiDian_SelectedIndexChanged(object sender, EventArgs e) { } public void RefreshSongList() { lvYiDian.Items.Clear();//清空原列表 for (int i = 0; i < PlayList.SongList.Length; i++) { if (PlayList.SongList[i]!=null) { ListViewItem item = new ListViewItem(PlayList.SongList[i].SongName); item.Tag = i; //獲取播放狀態 string bofang = PlayList.SongList[i].PlayStar == SongPlayState.unplayer ? "未播放" : "已播放"; item.SubItems.Add(bofang); lvYiDian.Items.Add(item); } } } private void frmYiDian_Load(object sender, EventArgs e) { style = 0; RefreshSongList(); } private void timer1_Tick(object sender, EventArgs e) { RefreshSongList(); } private void frmYiDian_FormClosing(object sender, FormClosingEventArgs e) { style = 1; } private void 切歌ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("確定要切歌嗎?", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { PlayList.Cutsong(); } } private void 重唱ToolStripMenuItem_Click(object sender, EventArgs e) { PlayList.PalyAgain(); } } }
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.Data.SqlClient;namespace MyKTV{ public partial class frmMain : Form { public frmMain() { //InitializeComponent(); }
private void btnGX_Click(object sender, EventArgs e) { frmGXDG1 fg = new frmGXDG1(); fg.form1 = this; fg.Show(); this.Hide(); } //獲取歌曲路徑 public void SongPath() { string sql = "select resourcepath from resourcepath where resourceid=1"; SqlConnection con = new SqlConnection(SqlUtil.str); SqlCommand com = new SqlCommand(sql, con); try { con.Open(); KTVUtil.songPath= com.ExecuteScalar().ToString(); } catch (Exception) {
throw; } finally { con.Close(); } } private void frmMain_Load(object sender, EventArgs e) { //讀取歌曲路徑 SongPath(); //讀取resourcepath表中的歌手圖片 string sql = "select resourcepath from resourcepath where resourceid=2"; SqlConnection con = new SqlConnection(SqlUtil.str); SqlCommand com = new SqlCommand(sql,con); try { con.Open(); KTVUtil.picturePath=com.ExecuteScalar().ToString(); } catch (Exception) {
throw; } finally { con.Close(); } } private Song song;//當前播放的歌曲 //播放歌曲 public void PlaySong() { //調用播放當前歌曲方法 this.song = PlayList.GetPlaySong(); if (song!=null) { //改變播放狀態為播放 this.song.SongPlayed(); Player2.URL = KTVUtil.songPath + "\\" + this.song.SongUrl; txtIng.Text = PlayList.PlaySongName(); } }
private void btnPY_Click(object sender, EventArgs e) { frmPY fp = new frmPY(); fp.Show(); }
private void btnSZ_Click(object sender, EventArgs e) { frmNum fn = new frmNum(); fn.Show(); }
private void btnLX_Click(object sender, EventArgs e) { frmType ft = new frmType(); ft.getSong(song); ft.Show(); }
private void btnJB_Click(object sender, EventArgs e) { frmPaiHang fp = new frmPaiHang(); fp.Show(); } private void toolStripButton3_Click(object sender, EventArgs e) {
frmYiDian fy = frmYiDian.getFrm(); fy.Show(); }
private void panel2_Paint(object sender, PaintEventArgs e) {
} public static int cutSong = 0; private void timer1_Tick(object sender, EventArgs e) { String nextSongName = PlayList.NextSongName(); txtNext.Text = nextSongName; if (song == null) { PlaySong(); } if (Player2.playState == WMPLib.WMPPlayState.wmppsStopped) { song = null; PlayList.Next(); } if (song != null && this.song.PlayStar == SongPlayState.cut) { this.song = null; } if (song != null) { if (this.song.PlayStar == SongPlayState.again) { this.song = null; } } } private void toolStripButton5_Click(object sender, EventArgs e) { Application.Exit(); }
private void Player2_Enter(object sender, EventArgs e) {
}
private void timNow_Tick(object sender, EventArgs e) { }
private void toolStripButton2_Click(object sender, EventArgs e) {
DialogResult result = MessageBox.Show("確定要切歌嗎?", "", MessageBoxButtons.YesNo); if (result==DialogResult.Yes) { PlayList.Cutsong(); } }
private void toolStripButton1_Click(object sender, EventArgs e) { PlayList.PalyAgain(); }
private void txtIng_TextChanged(object sender, EventArgs e) { //txtIng.Text = PlayList.PlaySongName(); }
private void txtNext_TextChanged(object sender, EventArgs e) { // txtNext.Text = PlayList.NextSongName(); } private void timer2_Tick(object sender, EventArgs e) { } //原唱伴唱(可惜沒實現) private void button1_Click(object sender, EventArgs e) { if (Player2.settings.balance==100) { Player2.settings.balance = -100; } else { Player2.settings.balance = 100; } } }}
