首页 > php教程 > php手册 > MyKTV项目总结

MyKTV项目总结

WBOY
发布: 2016-07-06 13:30:36
原创
2242 人浏览过

项目名称: KTV 点歌系统 -- 指导老师原玉明 经过一周多的时间,终于完成的我的这个 KTV 项目,说实话,做这个项目我收获了不少,难点也非常多,不过经过重重磨难,总算是过来了。不简单呀! 这个项目主要分为前后台。 前台主要实现的功能是:歌星点歌,拼音

                                                        项目名称:KTV点歌系统

                                                                                                                                                           --指导老师原玉明

经过一周多的时间,终于完成的我的这个KTV项目,说实话,做这个项目我收获了不少,难点也非常多,不过经过重重磨难,总算是过来了。不简单呀!

这个项目主要分为前后台。

前台主要实现的功能是:歌星点歌,拼音点歌,字数点歌,

类型选择,金曲排行,一些切歌,重唱,已点歌曲列表,主要是这些功能。

后台主要实现的功能是:增加歌手,增加歌曲,修改歌曲路径,修改歌手图片路径。

首先先看前台:

前台核心类:

SqlHelper类(负责连接数据库):

 

 <span style="color: #008000;">//</span><span style="color: #008000;">连接字符串</span>
       <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> str = <span style="color: #800000;">"</span><span style="color: #800000;">Data Source=HYJ-PC;Initial Catalog=MyKTV;User ID=sa;pwd=123</span><span style="color: #800000;">"</span>;
登录后复制

 

KtvHelper类(保存歌曲的目录;保存歌手图片的目录)

 <span style="color: #008000;">//</span><span style="color: #008000;">保存歌曲的目录</span>
       <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> songURL = <span style="color: #800000;">""</span><span style="color: #000000;">;
       </span><span style="color: #008000;">//</span><span style="color: #008000;">保存歌手图片的目录</span>
 <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span> singer_photoURL = <span style="color: #800000;">""</span><span style="color: #000000;">;
FrmByValue类(窗体对象之间的传值)
  </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span><span style="color: #000000;"> frmsonglist frmsl;

       </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span><span style="color: #000000;"> FrmMain frM;

       </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> SelectedSong ss;
登录后复制

Song类(歌曲的信息及实现歌曲状态的一个切换(已播放;未播放;重播;切歌)):

 <span style="color: #008000;">//</span><span style="color: #008000;">定义一个枚举:歌曲播放状态</span>
   <span style="color: #0000ff;">public</span>  <span style="color: #0000ff;">enum</span><span style="color: #000000;"> SongPlayState
    {
        unplayed, played, newplayed, cut

    }
  </span><span style="color: #0000ff;">public</span>  <span style="color: #0000ff;">class</span><span style="color: #000000;"> Song
  {

      </span><span style="color: #0000ff;">public</span>  <span style="color: #0000ff;">string</span><span style="color: #000000;"> SongName
      {
          </span><span style="color: #0000ff;">get</span> { <span style="color: #0000ff;">return</span><span style="color: #000000;"> songName; }
          </span><span style="color: #0000ff;">set</span> { songName =<span style="color: #000000;"> value; }
      }
      </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">string</span><span style="color: #000000;"> SongURL
      {
          </span><span style="color: #0000ff;">get</span> { <span style="color: #0000ff;">return</span><span style="color: #000000;"> songURL; }
          </span><span style="color: #0000ff;">set</span> { songURL =<span style="color: #000000;"> value; }
      }

      </span><span style="color: #0000ff;">internal</span><span style="color: #000000;"> SongPlayState Playseat
      {
          </span><span style="color: #0000ff;">get</span> { <span style="color: #0000ff;">return</span><span style="color: #000000;"> playseat; }
          </span><span style="color: #0000ff;">set</span> { playseat =<span style="color: #000000;"> value; }
      }

      </span><span style="color: #0000ff;">PRivate</span> <span style="color: #0000ff;">string</span> songName;<span style="color: #008000;">//</span><span style="color: #008000;">歌曲名称字段</span>
      <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">string</span> songURL;<span style="color: #008000;">//</span><span style="color: #008000;">歌曲存放路径字段
      </span><span style="color: #008000;">//</span><span style="color: #008000;">让歌曲的播放状态默认为未播放;</span>
      <span style="color: #0000ff;">private</span> SongPlayState playseat =<span style="color: #000000;"> SongPlayState.unplayed;

      </span><span style="color: #008000;">//</span><span style="color: #008000;">把歌曲状态改为已播放</span>
      <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> SetSongPlayed()
      {
          </span><span style="color: #0000ff;">this</span>.playseat =<span style="color: #000000;"> SongPlayState.played;
      }
      </span><span style="color: #008000;">//</span><span style="color: #008000;">把歌曲状态改为重唱</span>
      <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> SetnewSong()
      {
          </span><span style="color: #0000ff;">this</span>.playseat =<span style="color: #000000;"> SongPlayState.newplayed;
      }
      </span><span style="color: #008000;">//</span><span style="color: #008000;">把歌曲状态改为一切歌</span>
      <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> Setcut()
      {
          </span><span style="color: #0000ff;">this</span>.playseat =<span style="color: #000000;"> SongPlayState.cut;
      }</span>
登录后复制

PlayList类(播放歌曲的核心内容,功能(实现播放,切歌,重唱)):

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">class</span><span style="color: #000000;"> PlayList
    {
       </span><span style="color: #008000;">//</span><span style="color: #008000;">定义一个数组,默认可以储存50首歌</span>
       <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> Song[] songList=<span style="color: #0000ff;">new</span> Song[<span style="color: #800080;">50</span>];<span style="color: #008000;">//</span><span style="color: #008000;">歌曲播放列表数组</span>
       <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">int</span> songIndex;<span style="color: #008000;">//</span><span style="color: #008000;">当前播放的歌曲在数组的索引</span>



       <span style="color: #0000ff;">#region</span> 添加播放歌曲
       <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">bool</span><span style="color: #000000;"> AddSong(Song song)
       {
           </span><span style="color: #0000ff;">bool</span> happy = <span style="color: #0000ff;">false</span><span style="color: #000000;">;
           </span><span style="color: #0000ff;">for</span> (<span style="color: #0000ff;">int</span> i = <span style="color: #800080;">0</span>; i )
           {
               <span style="color: #0000ff;">if</span> (songList[i] == <span style="color: #0000ff;">null</span><span style="color: #000000;">)
               {
                   songList[i] </span>=<span style="color: #000000;"> song;

                   happy </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
                   </span><span style="color: #0000ff;">break</span><span style="color: #000000;">;
               }
           }
           </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> happy;

       } 
       </span><span style="color: #0000ff;">#endregion</span>
    
       <span style="color: #0000ff;">#region</span> 当前播放的歌曲名称
         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span><span style="color: #000000;"> PlayingSongName()
        { 
            </span><span style="color: #0000ff;">string</span> songName = <span style="color: #800000;">""</span>; <span style="color: #008000;">//</span><span style="color: #008000;"> 歌曲名称</span>
             <span style="color: #0000ff;">if</span>(songList.Length><span style="color: #000000;">songIndex)
             {
                 </span><span style="color: #0000ff;">if</span> (songList[songIndex] != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
                 {
                     songName </span>=<span style="color: #000000;"> songList[songIndex].SongName;
                 }
             }
           

            </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> songName;
        } 
       </span><span style="color: #0000ff;">#endregion</span>

       <span style="color: #0000ff;">#region</span> 获取当前播放的歌曲
         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span><span style="color: #000000;"> Song GetPlayingSong()
         {
             </span><span style="color: #0000ff;">if</span>(songIndexsongList.Length)
             {
                 <span style="color: #0000ff;">if</span> (songList[songIndex] != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
                 {
                     </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> songList[songIndex];
                 }
                 </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
                 {
                     </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span><span style="color: #000000;">;
                 }
             }
             </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">null</span><span style="color: #000000;">;
         } 
         </span><span style="color: #0000ff;">#endregion</span>

       <span style="color: #0000ff;">#region</span> 下一首要播放的歌曲名称
         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">string</span><span style="color: #000000;"> NextSongName()
         {
             </span><span style="color: #0000ff;">string</span> songName = <span style="color: #800000;">""</span>; <span style="color: #008000;">//</span><span style="color: #008000;"> 歌曲名称</span>
             <span style="color: #0000ff;">if</span>(songIndexsongList.Length)
             {
                 <span style="color: #0000ff;">if</span> (songList.Length > songIndex + <span style="color: #800080;">1</span><span style="color: #000000;">)
                 {
                     </span><span style="color: #0000ff;">if</span> (songList[songIndex + <span style="color: #800080;">1</span>] != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
                     {
                         songName </span>= songList[songIndex + <span style="color: #800080;">1</span><span style="color: #000000;">].SongName;
                     }
                   
              
             }
           
           }
             </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> songName;
         } 
         </span><span style="color: #0000ff;">#endregion</span>

       <span style="color: #0000ff;">#region</span> 切歌:
         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> CutSong()
         {
             </span><span style="color: #008000;">//</span><span style="color: #008000;">代表切歌的位置</span>
             <span style="color: #0000ff;">int</span> i =<span style="color: #000000;"> songIndex;  
            
             </span><span style="color: #0000ff;">if</span> (songList[i]!=<span style="color: #0000ff;">null</span><span style="color: #000000;">)
             {
                 songList[i].Setcut();
             }
             </span><span style="color: #0000ff;">while</span> (songList[i] != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
             {
                 songList[i] </span>= songList[i + <span style="color: #800080;">1</span><span style="color: #000000;">];
                 i</span>++<span style="color: #000000;">;

                 </span><span style="color: #008000;">//</span><span style="color: #008000;"> 如果到达数组最后一个元素,就将最后一个元素指向空</span>
                 <span style="color: #0000ff;">if</span> (i ==<span style="color: #000000;"> songList.Length)
                 {
                     songList[i] </span>= <span style="color: #0000ff;">null</span><span style="color: #000000;">;
                 }
             }
             </span><span style="color: #0000ff;">if</span> (songList[<span style="color: #800080;">0</span>] != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
             {
                 songList[</span><span style="color: #800080;">0</span>].Playseat =<span style="color: #000000;"> SongPlayState.played;
             }
         }
 
    </span><span style="color: #0000ff;">#endregion</span>

       <span style="color: #0000ff;">#region</span> 重放当前歌曲
         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> PlayAgain()
         {
             </span><span style="color: #0000ff;">if</span> (songList[songIndex] != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
             {
                 songList[songIndex].SetnewSong();
             }
         } 
         </span><span style="color: #0000ff;">#endregion</span>

       <span style="color: #0000ff;">#region</span> 播放下一首
         <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> MoveOn()
         {
             </span><span style="color: #0000ff;">if</span>(songIndexsongList.Length)
             {
                 <span style="color: #0000ff;">if</span> (songList[songIndex] != <span style="color: #0000ff;">null</span> && songList[songIndex].Playseat ==<span style="color: #000000;"> SongPlayState.newplayed)
                 {
                     songList[songIndex].SetSongPlayed();
                 }
                 </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
                 {
                     songIndex</span>++<span style="color: #000000;">;
                 }
             }
            
         }        
         </span><span style="color: #0000ff;">#endregion</span><span style="color: #000000;">
  
   }</span>
登录后复制

实现窗体拖动的代码(找到对应事件双击):

<span style="color: #0000ff;">#region</span> 让窗体实现拖动
        <span style="color: #0000ff;">public</span> Point mouSEOffset;        <span style="color: #008000;">//</span><span style="color: #008000;">记录鼠标指针的坐标        </span>
        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> isMouseDown = <span style="color: #0000ff;">false</span>; <span style="color: #008000;">//</span><span style="color: #008000;">记录鼠标按键是否按下   </span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> FrmMain_MouseDown(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, MouseEventArgs e)
        {
            </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> xOffset;
            </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> yOffset;
            </span><span style="color: #0000ff;">if</span> (e.Button ==<span style="color: #000000;"> MouseButtons.Left)
            {
                xOffset </span>= -e.X -<span style="color: #000000;"> SystemInformation.FrameBorderSize.Width;
                yOffset </span>= -e.Y - SystemInformation.CaptionHeight -<span style="color: #000000;"> SystemInformation.FrameBorderSize.Height;
                mouseOffset </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> Point(xOffset, yOffset);
                isMouseDown </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            }
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> FrmMain_MouseMove(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, MouseEventArgs e)
        {
            </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (isMouseDown)
            {
                Point mousePos </span>=<span style="color: #000000;"> Control.MousePosition;
                mousePos.Offset(mouseOffset.X </span>+ <span style="color: #800080;">5</span>, mouseOffset.Y + <span style="color: #800080;">30</span><span style="color: #000000;">);
                Location </span>=<span style="color: #000000;"> mousePos;
            }
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> FrmMain_MouseUp(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, MouseEventArgs e)
        {
            </span><span style="color: #008000;">//</span><span style="color: #008000;"> 修改鼠标状态isMouseDown的值      
            </span><span style="color: #008000;">//</span><span style="color: #008000;"> 确保只有鼠标左键按下并移动时,才移动窗体       </span>
            <span style="color: #0000ff;">if</span> (e.Button ==<span style="color: #000000;"> MouseButtons.Left)
            {
                isMouseDown </span>= <span style="color: #0000ff;">false</span><span style="color: #000000;">;
            }
        } 
        </span><span style="color: #0000ff;">#endregion</span>
登录后复制

主界面:(FrmMain

 

 <span style="color: #008000;">//</span><span style="color: #008000;">当前播放的歌曲</span>
        <span style="color: #0000ff;">public</span><span style="color: #000000;"> Song songname;

        </span><span style="color: #0000ff;">#region</span> 让窗体实现拖动
        <span style="color: #0000ff;">public</span> Point mouseOffset;        <span style="color: #008000;">//</span><span style="color: #008000;">记录鼠标指针的坐标        </span>
        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">bool</span> isMouseDown = <span style="color: #0000ff;">false</span>; <span style="color: #008000;">//</span><span style="color: #008000;">记录鼠标按键是否按下   </span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> FrmMain_MouseDown(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, MouseEventArgs e)
        {
            </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> xOffset;
            </span><span style="color: #0000ff;">int</span><span style="color: #000000;"> yOffset;
            </span><span style="color: #0000ff;">if</span> (e.Button ==<span style="color: #000000;"> MouseButtons.Left)
            {
                xOffset </span>= -e.X -<span style="color: #000000;"> SystemInformation.FrameBorderSize.Width;
                yOffset </span>= -e.Y - SystemInformation.CaptionHeight -<span style="color: #000000;"> SystemInformation.FrameBorderSize.Height;
                mouseOffset </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> Point(xOffset, yOffset);
                isMouseDown </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            }
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> FrmMain_MouseMove(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, MouseEventArgs e)
        {
            </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (isMouseDown)
            {
                Point mousePos </span>=<span style="color: #000000;"> Control.MousePosition;
                mousePos.Offset(mouseOffset.X </span>+ <span style="color: #800080;">5</span>, mouseOffset.Y + <span style="color: #800080;">30</span><span style="color: #000000;">);
                Location </span>=<span style="color: #000000;"> mousePos;
            }
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> FrmMain_MouseUp(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, MouseEventArgs e)
        {
            </span><span style="color: #008000;">//</span><span style="color: #008000;"> 修改鼠标状态isMouseDown的值      
            </span><span style="color: #008000;">//</span><span style="color: #008000;"> 确保只有鼠标左键按下并移动时,才移动窗体       </span>
            <span style="color: #0000ff;">if</span> (e.Button ==<span style="color: #000000;"> MouseButtons.Left)
            {
                isMouseDown </span>= <span style="color: #0000ff;">false</span><span style="color: #000000;">;
            }
        } 
        </span><span style="color: #0000ff;">#endregion</span>

       <span style="color: #008000;">//</span><span style="color: #008000;"> 点击退出按钮触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnexit_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            application.Exit();  
        } 

       </span><span style="color: #008000;">//</span><span style="color: #008000;"> Login事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> FrmMain_Load(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            
           
            </span><span style="color: #008000;">//</span><span style="color: #008000;">把整个窗体对象赋给FrmByValue的静态frM对象</span>
            FrmByValue.frM = <span style="color: #0000ff;">this</span><span style="color: #000000;">;
            </span><span style="color: #008000;">//</span><span style="color: #008000;">运行窗体时启动定时器</span>
            <span style="color: #0000ff;">this</span><span style="color: #000000;">.tilist_played.Start();

            </span><span style="color: #008000;">//</span><span style="color: #008000;">调用查询返回路径的方法,传入SQL语句
            </span><span style="color: #008000;">//</span><span style="color: #008000;"> 歌曲路径</span>
            <span style="color: #0000ff;">string</span> sql = <span style="color: #800000;">"</span><span style="color: #800000;">select resource_path from Resource_path where resource_id=1</span><span style="color: #800000;">"</span><span style="color: #000000;">;
            KtvHelper.songURL </span>=<span style="color: #000000;"> song_path(sql);
            </span><span style="color: #008000;">//</span><span style="color: #008000;"> 歌手图片路径</span>
            <span style="color: #0000ff;">string</span> sql1 = <span style="color: #800000;">"</span><span style="color: #800000;">select resource_path from Resource_path where resource_id=2</span><span style="color: #800000;">"</span><span style="color: #000000;">;
            KtvHelper.singer_photoURL </span>=<span style="color: #000000;"> song_path(sql1);


        } 
        
        </span><span style="color: #808080;">///</span> <span style="color: #808080;"><summary></summary></span>
        <span style="color: #808080;">///</span><span style="color: #008000;"> 查询返回路径的方法
        </span><span style="color: #808080;">///</span> <span style="color: #808080;"></span>
        <span style="color: #808080;">///</span> <span style="color: #808080;"><param name="sql"></span><span style="color: #008000;">传入sql语句</span><span style="color: #808080;"></span>
        <span style="color: #808080;">///</span> <span style="color: #808080;"><returns></returns></span><span style="color: #008000;">根据传入的sql语句返回不同的路径(1.resource_id=1歌曲路径:resource_id=2歌手图片路径)</span><span style="color: #808080;"></span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">string</span> song_path(<span style="color: #0000ff;">string</span><span style="color: #000000;"> sql)
        {
            SqlConnection con </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlConnection(SqlHelper.str);
            SqlCommand cmd </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlCommand(sql, con);
            </span><span style="color: #0000ff;">string</span> path = <span style="color: #800000;">""</span><span style="color: #000000;">;
            </span><span style="color: #0000ff;">try</span><span style="color: #000000;">
            {
                con.Open();
                SqlDataReader dr </span>=<span style="color: #000000;"> cmd.ExecuteReader();

                </span><span style="color: #0000ff;">if</span> (dr != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
                {
                    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (dr.HasRows)
                    {
                        </span><span style="color: #0000ff;">while</span><span style="color: #000000;"> (dr.Read())
                        {
                            path </span>= dr[<span style="color: #800000;">"</span><span style="color: #800000;">resource_path</span><span style="color: #800000;">"</span><span style="color: #000000;">].ToString();
                        }

                    }
                }
            }
            </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (Exception)
            {


                MessageBox.Show(</span><span style="color: #800000;">"</span><span style="color: #800000;">网络异常!</span><span style="color: #800000;">"</span><span style="color: #000000;">);
            }
            </span><span style="color: #0000ff;">finally</span><span style="color: #000000;">
            {
                con.Close();
            }
            </span><span style="color: #0000ff;">return</span><span style="color: #000000;"> path;
        }  
    
      </span><span style="color: #008000;">//</span><span style="color: #008000;">点击显示播放触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnshow_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
        
      
         </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.Width == <span style="color: #800080;">567</span><span style="color: #000000;">)
         {
             </span><span style="color: #0000ff;">this</span>.Width = <span style="color: #0000ff;">this</span>.Width + <span style="color: #800080;">208</span><span style="color: #000000;">;
             btnshow.Text </span>= <span style="color: #800000;">"</span><span style="color: #800000;">隐 藏 播 放</span><span style="color: #800000;">"</span><span style="color: #000000;">;
         }
         </span><span style="color: #0000ff;">else</span> <span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.Width > <span style="color: #800080;">567</span><span style="color: #000000;">)
         {
             </span><span style="color: #0000ff;">this</span>.Width = <span style="color: #800080;">567</span><span style="color: #000000;">;
             btnshow.Text </span>= <span style="color: #800000;">"</span><span style="color: #800000;">显 示 播 放</span><span style="color: #800000;">"</span><span style="color: #000000;">;
         }
          
        } 

       </span><span style="color: #008000;">//</span><span style="color: #008000;">已点歌曲窗体</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnopen_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            SelectedSong frm </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SelectedSong();
            </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.Hide();
            frm.Show();
        }

 
  
        </span><span style="color: #008000;">//</span><span style="color: #008000;"> 点击拼音点歌触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnspell_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            frmbySongname frm </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> frmbySongname();
            </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.Hide();
            frm.Show();
            
        } 
     
      </span><span style="color: #008000;">//</span><span style="color: #008000;">点击字数点歌触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnnum_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            frmbyziSong frm </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> frmbyziSong();
            </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.Hide();
            frm.Show();
        } 

        </span><span style="color: #008000;">//</span><span style="color: #008000;">点击类型点歌触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btntype_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            frmbyTypesong frm </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> frmbyTypesong();
            </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.Hide();
            frm.Show();
        }

        </span><span style="color: #008000;">//</span><span style="color: #008000;">定时扫描歌曲列表,显示当前播放歌曲的名称</span>
        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> ShowPlayingSongName()
        {
            txtopen.Text </span>=<span style="color: #000000;"> PlayList.PlayingSongName();
            txtnext.Text </span>=<span style="color: #000000;"> PlayList.NextSongName();
        }

       </span><span style="color: #008000;">//</span><span style="color: #008000;">播放歌曲的方法</span>
        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> PlaySong()
        {
            </span><span style="color: #008000;">//</span><span style="color: #008000;"> 获取当前要播放的歌曲</span>
            <span style="color: #0000ff;">this</span>.songname =<span style="color: #000000;"> PlayList.GetPlayingSong();
          
          
            </span><span style="color: #0000ff;">if</span> (songname != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">#region</span> 播放时显示歌曲图片
                <span style="color: #0000ff;">string</span> name =<span style="color: #000000;"> songname.SongName;
                </span><span style="color: #0000ff;">string</span> sql = <span style="color: #800000;">"</span><span style="color: #800000;">select singer_id from song_info where song_name ='</span><span style="color: #800000;">"</span> + name + <span style="color: #800000;">"</span><span style="color: #800000;">' </span><span style="color: #800000;">"</span><span style="color: #000000;">;
                SqlConnection con </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlConnection(SqlHelper.str);
                con.Open();
                SqlCommand cmd </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlCommand(sql, con);
                </span><span style="color: #0000ff;">int</span> singerid =<span style="color: #000000;"> Convert.ToInt32(cmd.ExecuteScalar());
                con.Close();
                </span><span style="color: #0000ff;">string</span> sql1 = <span style="color: #800000;">"</span><span style="color: #800000;">select singer_photo from singer_info where singer_id=</span><span style="color: #800000;">"</span> + singerid + <span style="color: #800000;">""</span><span style="color: #000000;">;
                SqlConnection con1 </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlConnection(SqlHelper.str);
                con1.Open();
                SqlCommand cmd1 </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlCommand(sql1, con1);
                </span><span style="color: #0000ff;">string</span> singer_photo =<span style="color: #000000;"> cmd1.ExecuteScalar().ToString();
                con1.Close();
                plist.Image </span>= Image.FromFile(KtvHelper.singer_photoURL +<span style="color: #000000;"> singer_photo); 
                </span><span style="color: #0000ff;">#endregion</span>
                <span style="color: #008000;">//</span><span style="color: #008000;"> 将当前歌曲播放状态设为已播放</span>
                <span style="color: #0000ff;">this</span><span style="color: #000000;">.songname.SetSongPlayed();
                
                </span><span style="color: #008000;">//</span><span style="color: #008000;"> 得到当前播放歌曲的路径</span>
                Playerlist.URL = KtvHelper.songURL +<span style="color: #000000;"> songname.SongURL;
               
            }
        } 
     
        </span><span style="color: #008000;">//</span><span style="color: #008000;">计时器控件的Tick事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> tilist_played_Tick(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
             ShowPlayingSongName();
            </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">this</span>.songname==<span style="color: #0000ff;">null</span><span style="color: #000000;">)
            {
                </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.PlaySong();
            }
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.Playerlist.playState ==<span style="color: #000000;"> WMPLib.WMPPlayState.wmppsStopped)
            {
                </span><span style="color: #0000ff;">this</span>.songname = <span style="color: #0000ff;">null</span><span style="color: #000000;">;
                PlayList.MoveOn();
            }
            </span><span style="color: #0000ff;">if</span>(<span style="color: #0000ff;">this</span>.songname!=<span style="color: #0000ff;">null</span>&&<span style="color: #0000ff;">this</span>.songname.Playseat==<span style="color: #000000;">SongPlayState.cut)
            {
                </span><span style="color: #0000ff;">this</span>.Playerlist.URL = <span style="color: #800000;">""</span><span style="color: #000000;">;
                </span><span style="color: #0000ff;">this</span>.songname = <span style="color: #0000ff;">null</span><span style="color: #000000;">;
            
            }
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.songname != <span style="color: #0000ff;">null</span> && <span style="color: #0000ff;">this</span>.songname.Playseat ==<span style="color: #000000;"> SongPlayState.newplayed)
            {
                </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.PlaySong();
            
            }
   
        }

        </span><span style="color: #008000;">//</span><span style="color: #008000;">点击切歌触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnnextsong_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.songname != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
            {
                PlayList.CutSong();
                
            }
            </span><span style="color: #0000ff;">else</span><span style="color: #000000;"> 
            {
                MessageBox.Show(</span><span style="color: #800000;">"</span><span style="color: #800000;">亲!你还没有添加歌曲</span><span style="color: #800000;">"</span><span style="color: #000000;">);
                
            }
           
        }

        </span><span style="color: #008000;">//</span><span style="color: #008000;">点击重唱触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnnew_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            </span><span style="color: #0000ff;">if</span> (<span style="color: #0000ff;">this</span>.songname != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
            {
                PlayList.PlayAgain();
            }
            </span><span style="color: #0000ff;">else</span><span style="color: #000000;">
            {
                MessageBox.Show(</span><span style="color: #800000;">"</span><span style="color: #800000;">亲!你还没有添加歌曲</span><span style="color: #800000;">"</span><span style="color: #000000;">);

            }
           
        }

        </span><span style="color: #008000;">//</span><span style="color: #008000;">点击金曲排行触发的时间</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnorderby_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            frmsonglist frm </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> frmsonglist();
            frm.ph </span>= <span style="color: #800080;">1</span><span style="color: #000000;">;
            </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.Hide();
            frm.Show();

        }
        </span><span style="color: #008000;">//</span><span style="color: #008000;">歌星点歌</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnswan_Click_1(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            Frmbyswangetsong frm </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> Frmbyswangetsong();
            frm.Show();
            </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.Hide();
        }

        </span><span style="color: #008000;">//</span><span style="color: #008000;">当鼠标进入控件可见状态是触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnswan_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnswan,</span><span style="color: #800000;">"</span><span style="color: #800000;">歌星点歌</span><span style="color: #800000;">"</span><span style="color: #000000;">);

        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnspell_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnspell, </span><span style="color: #800000;">"</span><span style="color: #800000;">拼音点歌</span><span style="color: #800000;">"</span><span style="color: #000000;">);
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnnum_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnnum, </span><span style="color: #800000;">"</span><span style="color: #800000;">字数点歌</span><span style="color: #800000;">"</span><span style="color: #000000;">);
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btntype_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
             ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btntype, </span><span style="color: #800000;">"</span><span style="color: #800000;">类型选择</span><span style="color: #800000;">"</span><span style="color: #000000;">);
            
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnorderby_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnorderby, </span><span style="color: #800000;">"</span><span style="color: #800000;">金曲排行</span><span style="color: #800000;">"</span><span style="color: #000000;">);
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnnew_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnnew, </span><span style="color: #800000;">"</span><span style="color: #800000;">重唱</span><span style="color: #800000;">"</span><span style="color: #000000;">); 
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnnextsong_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnnextsong, </span><span style="color: #800000;">"</span><span style="color: #800000;">切歌</span><span style="color: #800000;">"</span><span style="color: #000000;">); 
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnopen_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnopen, </span><span style="color: #800000;">"</span><span style="color: #800000;">已点</span><span style="color: #800000;">"</span><span style="color: #000000;">); 
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnfw_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnfw, </span><span style="color: #800000;">"</span><span style="color: #800000;">服务</span><span style="color: #800000;">"</span><span style="color: #000000;">); 
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnexit_MouseEnter(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {

            ToolTip tp </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ToolTip();
            tp.ShowAlways </span>= <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            tp.SetToolTip(btnexit, </span><span style="color: #800000;">"</span><span style="color: #800000;">退出</span><span style="color: #800000;">"</span><span style="color: #000000;">); 
        }

        </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnfw_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            MessageBox.Show(</span><span style="color: #800000;">"</span><span style="color: #800000;">正在呼叫服务...</span><span style="color: #800000;">"</span><span style="color: #000000;">);
        }</span>
登录后复制

歌星点歌(Frmbyswangetsong):

 <span style="color: #008000;">//</span><span style="color: #008000;">图片索引</span>
        <span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> index=<span style="color: #800080;">0</span><span style="color: #000000;">;
        </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">int</span> index_singer = <span style="color: #800080;">0</span><span style="color: #000000;">;

       </span><span style="color: #008000;">//</span><span style="color: #008000;">Load事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> Frmbyswangetsong_Load(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            </span><span style="color: #008000;">//</span><span style="color: #008000;">在显示当前窗体时,让第二个lvlisttwo和第三个lvlistthere控件不显示</span>
            lvlisttwo.Visible = <span style="color: #0000ff;">false</span><span style="color: #000000;">;
            lvlistthere.Visible </span>= <span style="color: #0000ff;">false</span><span style="color: #000000;">;


            </span><span style="color: #0000ff;">#region</span> 给第一个listview绑定数据
            <span style="color: #008000;">//</span><span style="color: #008000;">给listview1绑定数据和图片</span>
            ListViewItem lv = <span style="color: #0000ff;">new</span> ListViewItem(<span style="color: #800000;">"</span><span style="color: #800000;">组合</span><span style="color: #800000;">"</span>, <span style="color: #800080;">0</span><span style="color: #000000;">);
            lv.Tag </span>= <span style="color: #800000;">"</span><span style="color: #800000;">组合</span><span style="color: #800000;">"</span><span style="color: #000000;">;
            ListViewItem lv1 </span>= <span style="color: #0000ff;">new</span> ListViewItem(<span style="color: #800000;">"</span><span style="color: #800000;">女歌手</span><span style="color: #800000;">"</span>, <span style="color: #800080;">1</span><span style="color: #000000;">);
            lv1.Tag </span>= <span style="color: #800000;">"</span><span style="color: #800000;">女</span><span style="color: #800000;">"</span><span style="color: #000000;">;
            ListViewItem lv2 </span>= <span style="color: #0000ff;">new</span> ListViewItem(<span style="color: #800000;">"</span><span style="color: #800000;">男歌手</span><span style="color: #800000;">"</span>, <span style="color: #800080;">2</span><span style="color: #000000;">);
            lv2.Tag </span>= <span style="color: #800000;">"</span><span style="color: #800000;">男</span><span style="color: #800000;">"</span><span style="color: #000000;">;
            lvlistone.Items.Add(lv);
            lvlistone.Items.Add(lv1);
            lvlistone.Items.Add(lv2); 
            </span><span style="color: #0000ff;">#endregion</span><span style="color: #000000;">

        } 



       </span><span style="color: #008000;">//</span><span style="color: #008000;">点击lvlistone中项时触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> lvlistone_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            </span><span style="color: #008000;">//</span><span style="color: #008000;">如果没有选中lvlistone控件中的任何一项是不会显示第二个窗体
            </span><span style="color: #008000;">//</span><span style="color: #008000;">让第二个出现的lvlisttwo和lvlistone显示在同一个位置</span>
            lvlisttwo.Location =<span style="color: #000000;"> lvlistone.Location;
            </span><span style="color: #008000;">//</span><span style="color: #008000;">如果选中一项,就把第二个llvlisttwo显示出来
            </span><span style="color: #008000;">//</span><span style="color: #008000;">让第二个lvlisttwo显示</span>
            lvlisttwo.Visible = <span style="color: #0000ff;">true</span><span style="color: #000000;">;
            </span><span style="color: #0000ff;">if</span> (lvlistone.SelectedItems[<span style="color: #800080;">0</span>] != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
            {
                </span><span style="color: #008000;">//</span><span style="color: #008000;">给第二个listview控件动态绑定数据的方法</span>
<span style="color: #000000;">                lvlisttwoadd();
               
            }
           
        }

       </span><span style="color: #008000;">//</span><span style="color: #008000;">给第二个listview控件动态绑定数据的方法lvlisttwoadd();</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span><span style="color: #000000;"> lvlisttwoadd()
        {
            SqlConnection con </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlConnection(SqlHelper.str);
            </span><span style="color: #0000ff;">string</span> sql = <span style="color: #800000;">"</span><span style="color: #800000;">select * from singer_type</span><span style="color: #800000;">"</span><span style="color: #000000;">;
            SqlCommand cmd </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlCommand(sql, con);
            </span><span style="color: #0000ff;">try</span><span style="color: #000000;">
            {
                con.Open();
                SqlDataReader dr </span>=<span style="color: #000000;"> cmd.ExecuteReader();
                </span><span style="color: #0000ff;">if</span> (dr != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
                {
                    </span><span style="color: #0000ff;">if</span><span style="color: #000000;"> (dr.HasRows)
                    {
                        </span><span style="color: #0000ff;">while</span><span style="color: #000000;"> (dr.Read())
                        {
                            </span><span style="color: #0000ff;">string</span> singertype_group = dr[<span style="color: #800000;">"</span><span style="color: #800000;">singertype_name</span><span style="color: #800000;">"</span><span style="color: #000000;">].ToString();
                            </span><span style="color: #0000ff;">int</span> id = Convert.ToInt32(dr[<span style="color: #800000;">"</span><span style="color: #800000;">singertype_id</span><span style="color: #800000;">"</span><span style="color: #000000;">]);
                            ListViewItem lv </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ListViewItem();
                            lv.ImageIndex </span>= index++<span style="color: #000000;">;
                            lv.Text </span>=<span style="color: #000000;"> singertype_group;
                            lv.Tag</span>=<span style="color: #000000;"> id;
                           </span><span style="color: #008000;">//</span><span style="color: #008000;"> MessageBox.Show(lvlisttwo.Tag.ToString());</span>
<span style="color: #000000;">                            lvlisttwo.Items.Add(lv);
                        }
                    }
                }
            }
            </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (Exception)
            {

                MessageBox.Show(</span><span style="color: #800000;">"</span><span style="color: #800000;">网络异常!</span><span style="color: #800000;">"</span><span style="color: #000000;">);
            }
            </span><span style="color: #0000ff;">finally</span><span style="color: #000000;">
            {
                con.Close();
            }
        }  
   
     </span><span style="color: #008000;">//</span><span style="color: #008000;"> 03点击lvlisttwo中项时触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> lvlisttwo_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {

            lvlistthere.Items.Clear();
            </span><span style="color: #008000;">//</span><span style="color: #008000;">如果没有选中lvlisttwo控件中的任何一项是不会显示第三个窗体
            </span><span style="color: #008000;">//</span><span style="color: #008000;">如果选中一项,就把第二个llvlistthere显示出来</span>
            <span style="color: #0000ff;">if</span> (lvlisttwo.SelectedItems[<span style="color: #800080;">0</span>] != <span style="color: #0000ff;">null</span><span style="color: #000000;">)
            {
                lvlisttwo.Visible </span>= <span style="color: #0000ff;">false</span><span style="color: #000000;">;
                </span><span style="color: #008000;">//</span><span style="color: #008000;">让第三个出现的lvlistthere和lvlistone显示在同一个位置</span>
                lvlistthere.Location =<span style="color: #000000;"> lvlistone.Location;
                </span><span style="color: #008000;">//</span><span style="color: #008000;">让第三个lvlistthere显示</span>
                lvlistthere.Visible = <span style="color: #0000ff;">true</span><span style="color: #000000;">;
                </span><span style="color: #008000;">//</span><span style="color: #008000;">获取用户点击第一个listview是男歌手还是女歌手或者是组合</span>
                <span style="color: #0000ff;">string</span> singer_group = lvlistone.SelectedItems[<span style="color: #800080;">0</span><span style="color: #000000;">].Tag.ToString();
                </span><span style="color: #008000;">//</span><span style="color: #008000;">获取用户点击点击第二个listview是哪个地区的id</span>
                <span style="color: #0000ff;">int</span> cityid = Convert.ToInt32(lvlisttwo.SelectedItems[<span style="color: #800080;">0</span><span style="color: #000000;">].Tag);        
                SqlConnection con </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlConnection(SqlHelper.str);
                </span><span style="color: #0000ff;">string</span> sql = <span style="color: #800000;">"</span><span style="color: #800000;">select singer_name,singer_photo from singer_info where singer_sex ='</span><span style="color: #800000;">"</span> + singer_group + <span style="color: #800000;">"</span><span style="color: #800000;">' and singertype_id=</span><span style="color: #800000;">"</span>+cityid+<span style="color: #800000;">"</span> <span style="color: #800000;">"</span><span style="color: #000000;">;
                SqlCommand cmd </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> SqlCommand(sql,con);
                </span><span style="color: #0000ff;">try</span><span style="color: #000000;">
                {
                    con.Open();
                  SqlDataReader dr</span>=<span style="color: #000000;">  cmd.ExecuteReader();
                    </span><span style="color: #0000ff;">if</span>(dr!=<span style="color: #0000ff;">null</span><span style="color: #000000;">)
                    {
                    </span><span style="color: #0000ff;">if</span><span style="color: #000000;">(dr.HasRows)
                    {
                        </span><span style="color: #0000ff;">while</span><span style="color: #000000;"> (dr.Read())
                        {
                            </span><span style="color: #008000;">//</span><span style="color: #008000;">获取到歌手姓名和歌手图片路径</span>
                            <span style="color: #0000ff;">string</span> singer_name = dr[<span style="color: #800000;">"</span><span style="color: #800000;">singer_name</span><span style="color: #800000;">"</span><span style="color: #000000;">].ToString();
                            </span><span style="color: #0000ff;">string</span> singer_photo_url = dr[<span style="color: #800000;">"</span><span style="color: #800000;">singer_photo</span><span style="color: #800000;">"</span><span style="color: #000000;">].ToString();
                            </span><span style="color: #008000;">//</span><span style="color: #008000;">并接路径</span>
                            <span style="color: #0000ff;">string</span> URL = KtvHelper.singer_photoURL +<span style="color: #000000;"> singer_photo_url;
                            imgsingerinfo .Images.Add(Image.FromFile(URL));
                            ListViewItem lv </span>= <span style="color: #0000ff;">new</span><span style="color: #000000;"> ListViewItem();
                            lv.Text </span>=<span style="color: #000000;"> singer_name;
                            lv.ImageIndex </span>=index_singer++<span style="color: #000000;">;
                            lvlistthere.Items.Add(lv);

                        }
                    }
                    }

                }
                </span><span style="color: #0000ff;">catch</span><span style="color: #000000;"> (Exception)
                {

                    MessageBox.Show(</span><span style="color: #800000;">"</span><span style="color: #800000;">网络异常!</span><span style="color: #800000;">"</span><span style="color: #000000;">);
                }
                </span><span style="color: #0000ff;">finally</span><span style="color: #000000;"> 
                {
                    con.Close();
                }
                
           
              }

        }
           
       </span><span style="color: #008000;">//</span><span style="color: #008000;">点击按钮主界面触发的事件</span>
        <span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> btnmain_Click(<span style="color: #0000ff;">object</span><span style="color: #000000;"> sender, EventArgs e)
        {
            FrmByValue.frM.Show();
            </span><span style="color: #0000ff;">this</span><span style="color: #000000;">.Close();
            
        } 

       </span>
登录后复制
相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板