首页 > 编程 > C# > 正文

c#实现KTV点歌系统

2019-10-29 21:39:41
字体:大 中 小
来源:转载
供稿:网友

这篇文章主要用C#语言编写的KTV点歌系统,需要的朋友可以参考下

下面通过图文并茂的方式给大家分享C#实现KTV点歌系统。

c#实现KTV点歌系统

c#实现KTV点歌系统

 

 
  1. public enum SongPlayState 
  2. { 
  3. //未播放,播放,重播,切歌 
  4. unplayed, played, again, cut 
  5. } 
  6. public class Song 
  7. { 
  8. public string SongName { get; set; }//歌曲名称 
  9. public string SongURL { get; set; }//歌曲路径 
  10. public SongPlayState playState = SongPlayState.unplayed;//默认未播放 
  11. internal SongPlayState PlayState { get; set; } 
  12. //状态为已播 
  13. public void SetSongPlayed() 
  14. { 
  15. this.PlayState = SongPlayState.played; 
  16. } 
  17. //重唱 
  18. public void SetPlayAgain() 
  19. { 
  20. this.playState = SongPlayState.again; 
  21. } 
  22. //切歌 
  23. public void SetSongCut() 
  24. { 
  25. this.playState = SongPlayState.cut; 
  26. } 

PlayList类中实现切歌 重唱 下一首 等.....

 

 
  1. public class PlayList 
  2. { 
  3. //定义一个长度为、 的歌曲数组,默认存储 首歌曲 
  4. public static Song[] SongList = new Song[ ]; 
  5. public static int SongIndex = ;//当前播放的歌曲在数组中的索引 
  6. //点播一首歌曲,其实是将歌曲对象添加到歌曲数组中 
  7. public static bool AddSong(Song song) 
  8. { 
  9. bool success = false;//记录添加歌曲是否成功 
  10. for (int i = ; i < SongList.Length; i++) 
  11. { 
  12. //找到数组中第一个为null的位置 
  13. if (SongList[i] == null) 
  14. { 
  15. SongList[i] = song; 
  16. success = true; 
  17. break; 
  18. } 
  19. } 
  20. return success; 
  21. } 
  22. //获取当前播放的歌曲::既然是获取当前播放的歌曲,返回值肯定是Song类型 
  23. public static Song GetPlaySong() 
  24. { 
  25. if (SongList[SongIndex] != null) 
  26. { 
  27. return SongList[SongIndex]; 
  28. } 
  29. else 
  30. { 
  31. return null; 
  32. } 
  33. } 
  34. /// <summary> 
  35. /// 播放下一首 
  36. /// </summary> 
  37. public static void MoveOn() 
  38. { 
  39. if (SongList[SongIndex] != null && SongList[SongIndex].PlayState == SongPlayState.again) 
  40. { 
  41. SongList[SongIndex].SetSongPlayed(); 
  42. } 
  43. else 
  44. { 
  45. SongIndex++; 
  46. } 
  47. } 
  48. /// <summary> 
  49. /// 当前播放的歌曲名称 
  50. /// </summary> 
  51. /// <returns>歌曲名称</returns> 
  52. public static string PlayingSongName() 
  53. { 
  54. string songName = ""; // 歌曲名称 
  55. if (SongList[SongIndex] != null) 
  56. { 
  57. songName = SongList[SongIndex].SongName; 
  58. } 
  59. return songName; 
  60. } 
  61. /// <summary> 
  62. /// 下一首要播放的歌曲名称 
  63. /// </summary> 
  64. /// <returns>歌曲名称</returns> 
  65. public static string NextSongName() 
  66. { 
  67. string songName = ""; // 歌曲名称 
  68. if (SongList[SongIndex + ] != null) 
  69. { 
  70. songName = SongList[SongIndex + ].SongName; 
  71. } 
  72. return songName; 
  73. } 
  74. //重放当前歌曲 
  75. public static void PlayAgain() 
  76. { 
  77. if (SongList[SongIndex] != null) 
  78. { 
  79. SongList[SongIndex].SetPlayAgain(); 
  80. } 
  81. } 
  82. //切歌 
  83. public static void CutSong(int index) 
  84. { 
  85. int i;//循环变量,代表切歌的位置 
  86. if (index == - )//循环变量,代表切割的位置 
  87. { 
  88. i = SongIndex; 
  89. } 
  90. else 
  91. { 
  92. i = index;//从切歌的位置开始,将歌曲逐个向前移一个位置 
  93. } 
  94. SongList[i].SetSongCut(); 
  95. while (SongList[i] != null) 
  96. { 
  97. SongList[i] = SongList[i + ]; 
  98. i++;  
  99. //如果达到数组最后一个元素,就将最后一个元素指向空 
  100. if (i == SongList.Length) 
  101. { 
  102. SongList[i] = null; 
  103. } 
  104. } 
  105. } 
  106. } 

c#实现KTV点歌系统

实现歌手点歌

 

 
  1. public FrmMain frmMain; 
  2. string connectionStr = "server=.;database=MyKTV;uid=sa"; 
  3. DBHelp db = new DBHelp(); 
  4. private SqlConnection con; 
  5. //首先要查出数据库中的图片路径和歌曲路径 
  6. private void FrmCountry_Load(object sender, EventArgs e) 
  7. { 
  8. con = new SqlConnection(connectionStr); 
  9. con.Open(); 
  10. string sql = "select resource_path from resource_path where resource_id= "; 
  11. string sqlsongpath = "select resource_path from resource_path where resource_id= "; 
  12. SqlCommand cmd = new SqlCommand(sql,con); 
  13. SqlCommand cmd = new SqlCommand(sqlsongpath, con); 
  14. KtvUnit.ImagePath = cmd.ExecuteScalar().ToString(); 
  15. KtvUnit.SongPath = cmd .ExecuteScalar().ToString(); 
  16. con.Close(); 
  17. } 
  18. //点击歌手男女或组合时 
  19. private void LvOne_Click(object sender, EventArgs e) 
  20. { 
  21. LoadSingerArea(); 
  22. } 
  23. public string singer_type { get; set; } 
  24. private void LoadSingerArea() 
  25. { 
  26. if (this.LvOne.SelectedItems[ ] != null) 
  27. { 
  28. LvOne.Visible = false; 
  29. LvTwo.Location = LvOne.Location; 
  30. LvTwo.Dock = DockStyle.Fill; 
  31. LvTwo.Visible = true; 
  32. this.singer_type=Convert.ToString(LvOne.SelectedItems[ ].Text); 
  33. } 
  34. con = new SqlConnection(connectionStr); 
  35. string sql = "select singertype_id,singertype_name from singer_type"; 
  36. SqlCommand cmd = new SqlCommand(sql, con); 
  37. SqlDataReader dr; 
  38. try 
  39. { 
  40. con.Open(); 
  41. LvTwo.Items.Clear(); 
  42. dr = cmd.ExecuteReader();  
  43. if (dr.HasRows) 
  44. { 
  45. int index = ; 
  46. while (dr.Read()) 
  47. { 
  48. ListViewItem lvItem = new ListViewItem(); 
  49. int typeid = Convert.ToInt (dr["singertype_id"]); 
  50. string typename = Convert.ToString(dr["singertype_name"]); 
  51. lvItem.Text = typename; 
  52. lvItem.Tag = typeid; 
  53. lvItem.ImageIndex = index; 
  54. LvTwo.Items.Add(lvItem); 
  55. index++; 
  56. } 
  57. } 
  58. dr.Close(); 
  59. } 
  60. catch (Exception ex) 
  61. { 
  62. MessageBox.Show("系统出现异常" + ex.Message); 
  63. } 
  64. finally  
  65. { 
  66. con.Close(); 
  67. } 
  68. } 
  69. public string singertype_id { get; set; } 
  70. /// <summary> 
  71. /// 点击地区类型时 
  72. /// </summary> 
  73. /// <param name="sender"></param> 
  74. /// <param name="e"></param> 
  75. private void LvTwo_Click(object sender, EventArgs e) 
  76. { 
  77. if (this.LvTwo.SelectedItems[ ] != null) 
  78. { 
  79. LvTwo.Visible = false; 
  80. Lvthree.Location = LvTwo.Location; 
  81. Lvthree.Dock = DockStyle.Fill; 
  82. Lvthree.Visible = true; 
  83. this.singertype_id = Convert.ToString(LvTwo.SelectedItems[ ].Tag); 
  84. } 
  85. string result = singer_type; 
  86. if (result != "组合") 
  87. { 
  88. result = singer_type == "女歌手" ? "女" : "男"; 
  89. } 
  90. con = new SqlConnection(connectionStr); 
  91. string sql =string.Format( "select singer_id,singer_name,singer_photo_url from singer_info where singertype_id={ } and singer_Sex='{ }'",singertype_id,result); 
  92. SqlCommand cmd = new SqlCommand(sql, con); 
  93. SqlDataReader dr; 
  94. try 
  95. { 
  96. con.Open(); 
  97. int index = ; 
  98. Lvthree.Items.Clear(); 
  99. imageList .Images.Clear(); 
  100. dr = cmd.ExecuteReader(); 
  101. if (dr.HasRows) 
  102. {  
  103. while (dr.Read()) 
  104. {  
  105. string photoURL =KtvUnit.ImagePath + Convert.ToString(dr["singer_photo_url"]); 
  106. //先给ImageList填充图片 
  107. imageList .Images.Add(Image.FromFile(photoURL)); 
  108. ListViewItem lvItem = new ListViewItem(); 
  109. lvItem.Text = Convert.ToString(dr["singer_name"]); 
  110. lvItem.Tag = Convert.ToString(dr["singer_id"]); 
  111. lvItem.ImageIndex = index; 
  112. Lvthree.Items.Add(lvItem); 
  113. index++; 
  114. } 
  115. } 
  116. dr.Close(); 
  117. } 
  118. catch (Exception ex) 
  119. { 
  120. MessageBox.Show("系统出现异常" + ex.Message); 
  121. } 
  122. finally 
  123. { 
  124. con.Close(); 
  125. } 
  126. } 
  127. public void SongList() 
  128. { 
  129. //读取数据库,读出该歌手的所有歌曲 
  130. StringBuilder sb = new StringBuilder(); 
  131. //拼接SQL语句 
  132. sb.AppendFormat("select song_id,song_name,song_url,singer_name from song_info,singer_info where singer_name='{ }' and song_info.singer_id={ }", Lvthree.SelectedItems[ ].Text, Convert.ToInt (Lvthree.SelectedItems[ ].Tag)); 
  133. FrmSongList songList = new FrmSongList(); 
  134. songList.Sql = sb.ToString(); 
  135. songList.Previous = KtvClient.PrevioisForm.Singer;//指定返回的窗体是按歌手点歌 
  136. songList.ShowDialog(); 
  137. this.Close(); 
  138. } 
  139. private void Lvthree_Click(object sender, EventArgs e) 
  140. { 
  141. SongList(); 
  142. } 
  143. private void tsSingerMain_Click(object sender, EventArgs e) 
  144. { 
  145. FrmMain main = new FrmMain(); 
  146. main.Show(); 
  147. this.Hide(); 
  148. } 
  149. private void tsSingerBack_Click(object sender, EventArgs e) 
  150. { 
  151. if (this.LvOne.Visible==true) 
  152. { 
  153. FrmMain man = new FrmMain(); 
  154. man.Show(); 
  155. this.Hide(); 
  156. } 
  157. else if (this.LvTwo.Visible==true) 
  158. { 
  159. this.LvTwo.Visible = false; 
  160. this.LvOne.Visible = true; 
  161. } 
  162. else if (this.Lvthree.Visible==true) 
  163. { 
  164. this.Lvthree.Visible = false; 
  165. this.LvTwo.Visible = true; 
  166. } 
  167. } 
  168. private void tsSingerCut_Click(object sender, EventArgs e) 
  169. { 
  170. PlayList.CutSong(- ); 
  171. } 
  172. private void tsSingerAgain_Click(object sender, EventArgs e) 
  173. { 
  174. PlayList.PlayAgain(); 
  175. } 
  176. private void tsSingerYidian_Click(object sender, EventArgs e) 
  177. { 
  178. FrmPlayList frm = new FrmPlayList(); 
  179. frm.Show(); 
  180. } 

拼音点歌

c#实现KTV点歌系统

 

 
  1. public FrmMain frmMain; 
  2. [DllImportAttribute("user .dll")] 
  3. private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags); 
  4. DBHelp db = new DBHelp(); 
  5. string connectionStr = "server=.;database=MyKTV;uid=sa"; 
  6. private void FrmPinYin_Load(object sender, EventArgs e) 
  7. { 
  8. AnimateWindow(this.Handle, , FrmMain.AW_SLIDE + FrmMain.AW_VER_POSITIVE); 
  9. SqlConnection con = new SqlConnection(connectionStr); 
  10. con.Open(); 
  11. db.connection();  
  12. string sqlsongpath = "select resource_path from resource_path where resource_id= "; 
  13. SqlCommand cmd = new SqlCommand(sqlsongpath, con); 
  14. KtvUnit.SongPath = cmd.ExecuteScalar().ToString(); 
  15. } 
  16. private void btnSearch_Click(object sender, EventArgs e) 
  17. { 
  18. string PinYin = this.txtPinYin.Text; 
  19. //判断是否是中文 还是拼音 
  20. if (!Regex.IsMatch(this.txtPinYin.Text, @"^[/u e -/u fa ]+$")) 
  21. { 
  22. StringBuilder PY = new StringBuilder(PinYin); 
  23. for (int i = ; i <= PY.Length; i++) 
  24. { 
  25. PY.Insert(i, "%"); 
  26. i++; 
  27. } 
  28. string sql = string.Format("SELECT song_name,singer_name FROM dbo.singer_info, dbo.song_info WHERE dbo.singer_info.singer_id=dbo.song_info.singer_id AND song_ab LIKE '{ }'", PY); 
  29. this.dgvPinYinInfo.DataSource = db.dataTable(sql,"PY"); 
  30. } 
  31. else 
  32. { 
  33. StringBuilder ZW = new StringBuilder(PinYin); 
  34. for (int i = ; i < ZW.Length; i++) 
  35. { 
  36. ZW.Insert(i,"%"); 
  37. i++; 
  38. } 
  39. string sql = string.Format("SELECT song_name,singer_name FROM dbo.singer_info, dbo.song_info WHERE dbo.singer_info.singer_id=dbo.song_info.singer_id AND song_name LIKE '{ }'", ZW); 
  40. this.dgvPinYinInfo.DataSource = db.dataTable(sql, "PY"); 
  41. } 
  42. } 
  43. private void dgvPinYinInfo_DoubleClick(object sender, EventArgs e) 
  44. { 
  45. string songname = this.dgvPinYinInfo.SelectedRows[ ].Cells["song_name"].Value.ToString(); 
  46. DBHelp db = new DBHelp(); 
  47. db.connection(); 
  48. string sql = string.Format("SELECT song_name,singer_name,song_url,song_photo_url FROM dbo.song_info,dbo.singer_info where dbo.singer_info.singer_id=dbo.song_info.singer_id and song_name='{ }'",songname); 
  49. SqlDataReader reader = db.ExecuteReaders(sql.ToString()); 
  50. Song song; 
  51. if (reader.Read()) 
  52. { 
  53. song = new Song(); 
  54. song.SongName = reader["song_name"].ToString(); 
  55. song.SongURL = KtvUnit.SongPath+reader["song_url"].ToString(); 
  56. PlayList.AddSong(song);  
  57. } 
  58. reader.Close(); 
  59. } 
  60. private void pictureBox _Click(object sender, EventArgs e) 
  61. { 
  62. textBox .Text = textBox .Text + "a"; 
  63. } 
  64. private void pictureBox _Click(object sender, EventArgs e) 
  65. { 
  66. textBox .Text = textBox .Text + "b"; 
  67. } 
  68. private void pictureBox _Click(object sender, EventArgs e) 
  69. { 
  70. textBox .Text = textBox .Text + "c"; 
  71. } 
  72. private void pictureBox _Click(object sender, EventArgs e) 
  73. { 
  74. textBox .Text = textBox .Text + "d"; 
  75. } 
  76. private void pictureBox _Click(object sender, EventArgs e) 
  77. { 
  78. textBox .Text = textBox .Text + "e"; 
  79. } 
  80. private void pictureBox _Click(object sender, EventArgs e) 
  81. { 
  82. textBox .Text = textBox .Text + "f"; 
  83. } 
  84. private void pictureBox _Click(object sender, EventArgs e) 
  85. { 
  86. textBox .Text = textBox .Text + "g"; 
  87. } 
  88. private void pictureBox _Click(object sender, EventArgs e) 
  89. { 
  90. textBox .Text = textBox .Text + "h"; 
  91. } 
  92. private void pictureBox _Click(object sender, EventArgs e) 
  93. { 
  94. textBox .Text = textBox .Text + "i"; 
  95. } 
  96. private void pictureBox _Click(object sender, EventArgs e) 
  97. { 
  98. textBox .Text = textBox .Text + "j"; 
  99. } 
  100. private void pictureBox _Click(object sender, EventArgs e) 
  101. { 
  102. textBox .Text = textBox .Text + "k"; 
  103. } 
  104. private void pictureBox _Click(object sender, EventArgs e) 
  105. { 
  106. textBox .Text = textBox .Text + "l"; 
  107. } 
  108. private void pictureBox _Click(object sender, EventArgs e) 
  109. { 
  110. textBox .Text = textBox .Text + "m"; 
  111. } 
  112. private void pictureBox _Click(object sender, EventArgs e) 
  113. { 
  114. textBox .Text = textBox .Text + "n"; 
  115. } 
  116. private void pictureBox _Click(object sender, EventArgs e) 
  117. { 
  118. textBox .Text = textBox .Text + "o"; 
  119. } 
  120. private void pictureBox _Click(object sender, EventArgs e) 
  121. { 
  122. textBox .Text = textBox .Text + "p"; 
  123. } 
  124. private void pictureBox _Click(object sender, EventArgs e) 
  125. { 
  126. textBox .Text = textBox .Text + "q"; 
  127. } 
  128. private void pictureBox _Click(object sender, EventArgs e) 
  129. { 
  130. textBox .Text = textBox .Text + "r"; 
  131. } 
  132. private void pictureBox _Click(object sender, EventArgs e) 
  133. { 
  134. textBox .Text = textBox .Text + "s"; 
  135. } 
  136. private void pictureBox _Click(object sender, EventArgs e) 
  137. { 
  138. textBox .Text = textBox .Text + "t"; 
  139. } 
  140. private void pictureBox _Click(object sender, EventArgs e) 
  141. { 
  142. textBox .Text = textBox .Text + "u"; 
  143. } 
  144. private void pictureBox _Click(object sender, EventArgs e) 
  145. { 
  146. textBox .Text = textBox .Text + "v"; 
  147. } 
  148. private void pictureBox _Click(object sender, EventArgs e) 
  149. { 
  150. textBox .Text = textBox .Text + "w"; 
  151. } 
  152. private void pictureBox _Click(object sender, EventArgs e) 
  153. { 
  154. textBox .Text = textBox .Text + "x"; 
  155. } 
  156. private void pictureBox _Click(object sender, EventArgs e) 
  157. { 
  158. textBox .Text = textBox .Text + "y"; 
  159. } 
  160. private void pictureBox _Click(object sender, EventArgs e) 
  161. { 
  162. textBox .Text = textBox .Text + "z"; 
  163. } 
  164. private void FrmPinYin_FormClosing(object sender, FormClosingEventArgs e) 
  165. { 
  166. AnimateWindow(this.Handle, , FrmMain.AW_SLIDE + FrmMain.AW_VER_POSITIVE); 
  167. } 
  168. public void Binder()  
  169. { 
  170. string PinYin = this.textBox .Text; 
  171. StringBuilder PY = new StringBuilder(PinYin); 
  172. for (int i = ; i <= PY.Length; i++) 
  173. { 
  174. PY.Insert(i, "%"); 
  175. i++; 
  176. } 
  177. string sql = string.Format("SELECT song_name,singer_name FROM dbo.singer_info, dbo.song_info WHERE dbo.singer_info.singer_id=dbo.song_info.singer_id AND song_ab LIKE '{ }'", PY); 
  178. DataSet ds = db.dataSet(sql, "PY"); 
  179. if (ds.Tables["PY"]!=null) 
  180. { 
  181. ds.Tables["PY"].Clear(); 
  182. } 
  183. this.dgvPinYinInfo.DataSource = db.dataTable(sql, "PY"); 
  184. } 
  185. private void pictureBox _Click(object sender, EventArgs e) 
  186. { 
  187. string text = textBox .Text; 
  188. int index = text.Length - ; 
  189. if (index >= ) 
  190. { 
  191. textBox .Text = text.Remove(index); 
  192. } 
  193. } 
  194. private void textBox _TextChanged(object sender, EventArgs e) 
  195. { 
  196. if (textBox .Text!=string.Empty) 
  197. { 
  198. Binder(); 
  199. this.dgvPinYinInfo.AutoGenerateColumns = false; 
  200. } 
  201. else 
  202. { 
  203. this.dgvPinYinInfo.DataSource=null; 
  204. } 
  205. } 
  206. private void tsPYMain_Click(object sender, EventArgs e) 
  207. { 
  208. FrmMain main = new FrmMain(); 
  209. main.Show(); 
  210. this.Hide(); 
  211. } 
  212. private void txPYAgain_Click(object sender, EventArgs e) 
  213. { 
  214. FrmMain main = new FrmMain(); 
  215. main.Playsong(); 
  216. } 
  217. Song song = new Song(); 
  218. private void tsPYCut_Click(object sender, EventArgs e) 
  219. { 
  220. song.playState = SongPlayState.cut; 
  221. } 
  222. private void tsPYYidian_Click(object sender, EventArgs e) 
  223. { 
  224. FrmPlayList list = new FrmPlayList(); 
  225. list.Show(); 
  226. } 
  227. private void tsPYBack_Click(object sender, EventArgs e) 
  228. { 
  229. Application.Exit(); 
  230. } 

类型点歌

 

 
  1. public FrmMain frmMain; 
  2. string connectionStr = "server=.;database=MyKTV;uid=sa"; 
  3. DBHelp db = new DBHelp(); 
  4. private SqlConnection con; 
  5. private void FrmSongType_Load(object sender, EventArgs e) 
  6. { 
  7. con = new SqlConnection(connectionStr); 
  8. con.Open(); 
  9. string sql = "select resource_path from resource_path where resource_id= "; 
  10. string sqlsongpath = "select resource_path from resource_path where resource_id= "; 
  11. SqlCommand cmd = new SqlCommand(sqlsongpath,con); 
  12. KtvUnit.SongPath = cmd .ExecuteScalar().ToString(); 
  13. SqlCommand cmd = new SqlCommand(sql, con); 
  14. KtvUnit.ImagePath = cmd.ExecuteScalar().ToString(); 
  15. con.Close(); 
  16. con = new SqlConnection(connectionStr); 
  17. string sql = string.Format("select songtype_id,songtype_name,songtype_URL from song_type"); 
  18. SqlCommand cmd = new SqlCommand(sql , con); 
  19. SqlDataReader dr; 
  20. try 
  21. { 
  22. con.Open(); 
  23. int index = ; 
  24. lvSongType.Items.Clear(); 
  25. imageList .Images.Clear(); 
  26. dr = cmd .ExecuteReader(); 
  27. if (dr.HasRows) 
  28. { 
  29. while (dr.Read()) 
  30. { 
  31. string photoURL = KtvUnit.ImagePath + Convert.ToString(dr["songtype_URL"]); 
  32. //先给ImageList填充图片 
  33. imageList .Images.Add(Image.FromFile(photoURL)); 
  34. ListViewItem lvItem = new ListViewItem(); 
  35. lvItem.Text = Convert.ToString(dr["songtype_name"]); 
  36. lvItem.Tag = Convert.ToString(dr["songtype_id"]); 
  37. lvItem.ImageIndex = index; 
  38. lvSongType.Items.Add(lvItem); 
  39. index++; 
  40. } 
  41. } 
  42. dr.Close(); 
  43. } 
  44. catch (Exception ex) 
  45. { 
  46. MessageBox.Show("系统出现异常" + ex.Message); 
  47. } 
  48. finally 
  49. { 
  50. con.Close(); 
  51. } 
  52. } 
  53. private void LoadSongType() 
  54. { 
  55. //读取数据库,读出该歌曲类型的所有歌曲 
  56. StringBuilder sb = new StringBuilder(); 
  57. //拼接SQL语句 
  58. sb.AppendFormat("select song_info.song_name,singer_info.singer_name,song_info.song_url from singer_info,song_info where song_info.singer_id=singer_info.singer_id and song_info.songtype_id={ }", Convert.ToInt (lvSongType.SelectedItems[ ].Tag)); 
  59. FrmSongList songList = new FrmSongList(); 
  60. songList.Sql = sb.ToString(); 
  61. songList.Previous = KtvClient.PrevioisForm.SongType;//指定返回的窗体是按歌曲类型点歌 
  62. songList.ShowDialog(); 
  63. this.Close(); 
  64. } 
  65. private void lvSongType_Click(object sender, EventArgs e) 
  66. { 
  67. LoadSongType(); 
  68. } 
  69. private void tsTYSingerMain_Click(object sender, EventArgs e) 
  70. { 
  71. FrmMain main = new FrmMain(); 
  72. main.Show(); 
  73. this.Hide(); 
  74. } 
  75. private void tsTYSingerAgain_Click(object sender, EventArgs e) 
  76. { 
  77. FrmMain main = new FrmMain(); 
  78. main.Playsong(); 
  79. } 
  80. Song song = new Song(); 
  81. private void tsTYSingerCut_Click(object sender, EventArgs e) 
  82. { 
  83. song.playState = SongPlayState.cut; 
  84. } 
  85. private void tsTYSingerYidian_Click(object sender, EventArgs e) 
  86. { 
  87. FrmPlayList list = new FrmPlayList(); 
  88. list.Show(); 
  89. } 
  90. private void tsTYSingerBack_Click(object sender, EventArgs e) 
  91. { 
  92. FrmMain main = new FrmMain(); 
  93. main.Show(); 
  94. this.Hide(); 
  95. } 

金榜排行

c#实现KTV点歌系统

 

 
  1. public FrmMain frmMain; 
  2. DBHelp db = new DBHelp(); 
  3. string connectionStr = "server=.;database=MyKTV;uid=sa"; 
  4. private void FrmJB_Load(object sender, EventArgs e) 
  5. { 
  6. SqlConnection con = new SqlConnection(connectionStr); 
  7. con.Open(); 
  8. db.connection(); 
  9. string sql = "SELECT song_name,song_play_count FROM dbo.song_info ORDER BY song_play_count DESC"; 
  10. string sqlsongpath = "select resource_path from resource_path where resource_id= "; 
  11. SqlCommand cmd = new SqlCommand(sqlsongpath, con); 
  12. KtvUnit.SongPath = cmd.ExecuteScalar().ToString(); 
  13. DataSet ds = db.dataSet(sql,"Count"); 
  14. this.dgvSongList.DataSource = ds.Tables["Count"].DefaultView; 
  15. } 
  16. private void dgvSongList_Click(object sender, EventArgs e) 
  17. { 
  18. DBHelp db = new DBHelp(); 
  19. if (dgvSongList.SelectedRows[ ]!=null) 
  20. { 
  21. string songname = this.dgvSongList.SelectedRows[ ].Cells["SongName"].Value.ToString(); 
  22. db.connection(); 
  23. string sql = string.Format("SELECT song_name,singer_name,song_url,song_photo_url FROM dbo.song_info,dbo.singer_info where dbo.singer_info.singer_id=dbo.song_info.singer_id and song_name='{ }'", songname); 
  24. SqlDataReader reader = db.ExecuteReaders(sql.ToString()); 
  25. Song song; 
  26. if (reader.Read()) 
  27. { 
  28. song = new Song(); 
  29. song.SongName = reader["song_name"].ToString(); 
  30. song.SongURL = KtvUnit.SongPath + reader["song_url"].ToString(); 
  31. PlayList.AddSong(song); 
  32. } 
  33. reader.Close(); 
  34. } 
  35. else 
  36. { 
  37. MessageBox.Show("空"); 
  38. } 
  39. } 

数字点歌

 

 
  1. public FrmMain frmMain; 
  2. string connectionStr = "server=.;database=MyKTV;uid=sa"; 
  3. DBHelp db = new DBHelp(); 
  4. private SqlConnection con; 
  5. private void FrmNumber_Load(object sender, EventArgs e) 
  6. { 
  7. con = new SqlConnection(connectionStr); 
  8. con.Open(); 
  9. string sqlsongpath = "select resource_path from resource_path where resource_id= "; 
  10. SqlCommand cmd = new SqlCommand(sqlsongpath, con); 
  11. KtvUnit.SongPath = cmd.ExecuteScalar().ToString(); 
  12. con.Close(); 
  13. for (int i = ; i <= ; i++) 
  14. { 
  15. for (int j = ; j <= ; j++) 
  16. { 
  17. Label label = new Label(); 
  18. label.ForeColor = Color.Red; 
  19. label.BackColor = Color.Pink; 
  20. label.Font=new System.Drawing.Font("华文彩云", ); 
  21. label.TextAlign = ContentAlignment.MiddleCenter; 
  22. label.Click += label_Click; 
  23. this.MouseMove += FrmNumber_MouseMove; 
  24. label.MouseHover += label_MouseHover; 
  25. label.Size = new System.Drawing.Size( , ); 
  26. label.Text = j.ToString(); 
  27. if (i > ) 
  28. { 
  29. label.Text = (j + i + ).ToString(); 
  30. } 
  31. if (i > ) 
  32. { 
  33. label.Text = (j + i + ).ToString(); 
  34. } 
  35. if (i > ) 
  36. { 
  37. label.Text = (j + i + ).ToString(); 
  38. }  
  39. label.Location = new Point( + * j, + * i); 
  40. this.Controls.Add(label); 
  41. } 
  42. } 
  43. } 

已点列表

c#实现KTV点歌系统

 

 
  1. private void FrmPlayList_Load(object sender, EventArgs e) 
  2. { 
  3. SongList(); 
  4. } 
  5. public void SongList()  
  6. { 
  7. lvSong.Items.Clear(); 
  8. for (int i = ; i < PlayList.SongList.Length; i++) 
  9. { 
  10. if (PlayList.SongList[i]!=null) 
  11. { 
  12. ListViewItem item = new ListViewItem(); 
  13. item.Text = PlayList.SongList[i].SongName; 
  14. item.Tag = i; 
  15. string playstate = PlayList.SongList[i].PlayState == SongPlayState.unplayed ? "未播放" : "已播"; 
  16. item.SubItems.Add(playstate); 
  17. lvSong.Items.Add(item); 
  18. } 
  19. } 
  20. } 
  21. private void btnClose_Click(object sender, EventArgs e) 
  22. { 
  23. this.Close(); 
  24. } 

以上就是C#实现KTV点歌系统的全部代码,希望大家喜欢。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表