zoukankan      html  css  js  c++  java
  • MyKTV项目总结

      今天和大伙分享一下我的KTV系统,我想大家都有自己独特的魅力,都有自己的风采,都有自己骄傲的一部分。

    在这里我就抛砖引玉,聊聊我的KTV项目,希望大家能给出自己的建议。。

      首先,我们先了解一下:当我们拿到这个KTV系统时,我们该怎么办?该如何下手?我们应该有自己的一些想法。

    我们先来看看我们必需要准备的数据库吧:

    从上向下作用分别为:

    1.用户登录

    2.歌曲歌手图片路径

    3.歌手信息

    4.歌手类型信息

    5.歌曲信息

    6.歌曲类型信息

    同时我们更应该把各个表之间的关系搞清楚

    数据库关系图:

    到这里我们的数据库就完成了

    下面就开始我们一系列的开发代码阶段了

    1.首先我们各种类已方便使用

     01.用于连接数据库的类(SqlServer)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace MyKTV
    {
        //用于连接数据库
       public class SqlServer
        {
           public static string str = "data source=.;initial catalog=MyKTV;uid=sa";
        }
    }

     02.歌曲类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace MyKTV
    {
        enum SongPlayState
        {
            //未播,在播,重播,切歌
            unplayed, played, again, cut
        }
       public class Song
        {
           public string gequ_name;//歌曲名
           public string geshou_name;//歌手名
           public string gequ_dizhi;//歌曲地址
           public string geshou_url;//歌手地址
    
           private SongPlayState playState = SongPlayState.unplayed;  // 歌曲播放状态,默认为未播
    
          
    
           // 歌曲播放状态
           internal SongPlayState PlayState
           {
               get { return playState; }
               set { playState = value; }
           }
    
    
    
          
           // 将歌曲状态改为已播放
           public void SetSongPlayed()
           {
               this.playState = SongPlayState.played;
           }
    
           
           // 将歌曲状态改为再拨放一次
         
           public void SetPlayAgain()
           {
               this.playState = SongPlayState.again;
           }
    
       
           // 将歌曲状态改为切歌
          
           public void SetSongCut()
           {
               this.playState = SongPlayState.cut;
           }
        }
    }

      03.用于操作歌曲的类

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace MyKTV
    {
       public class Playsong
        {
           public static Song[] gequ = new Song[50];//定义一个对象数组
           public static int shuzuindex=0;//定义数组下标原始为0
    
    
           //给对象数组赋值的方法
           public static bool Addsong(Song song){
               bool happy = false;
               for (int i = 0; i < gequ.Length; i++)
               {
                   if (gequ[i]==null)
                   {                  
                       gequ[i] =song;
                       happy = true;
                       break;
                   }
                   
               }
               return happy;          
           
           }
           //获取当前播放的歌曲的方法
           public static Song GetPlayingSong()
           {
    
                 if (shuzuindex<gequ.Length&&gequ[shuzuindex] != null)
                   {
                       return gequ[shuzuindex];
                   }
                   else
                   {
                       return null;
                   }
               
               
           }
    
    
           #region 当前播放的歌曲名称
           //歌曲名称
           public static string PlayingSongName()
           {
               string songName = ""; // 歌曲名称
               if (shuzuindex < gequ.Length)
               {
                   if (gequ[shuzuindex] != null)
                   {
                       songName = gequ[shuzuindex].gequ_name;
                   }
               }
    
    
               return songName;
           }
    
         
           #endregion
    
    
           #region 下一首要播放的歌曲名称
           //歌曲名称
           public static string NextSongName()
           {
               string songName = ""; // 歌曲名称
               if (shuzuindex + 1 < gequ.Length)
               {
                   if (gequ[shuzuindex + 1] != null)
                   {
                       songName = gequ[shuzuindex + 1].gequ_name;
                   }
    
    
               }
               return songName;
           }
    
           #endregion
    
    
           #region 点播一首歌曲,新点播的歌曲
           //新点播的歌曲
           public static bool AddSong(Song song)
           {
               bool success = false;
               for (int i = 0; i < gequ.Length; i++)
               {
                   if (gequ[i] == null)
                   {
                       gequ[i] = song;
                      // Console.WriteLine(song.gequ_name);
                       success = true;
                       break;
                   }
               }
    
               return success;
           }
    
           #endregion
    
    
           #region 切歌
           //  切歌  
           //要切歌曲的编号,如果是切当前播放的歌曲传入-1
           public static void CutSong(int index)
           {
               int i;  // 循环变量,代表切歌的位置
               if (index == -1)
               {
                   i = shuzuindex;
               }
               else
               {
                   i = index; // 从切歌的位置开始,将歌曲逐个向前移一个位置
               }
               if (gequ[i] != null)
               {
                   gequ[i].SetSongCut();
               }
    
               while (gequ[i] != null)
               {
                   gequ[i] = gequ[i + 1];
                   i++;
    
                   // 如果到达数组最后一个元素,就将最后一个元素指向空
                   if (i == gequ.Length)
                   {
                       gequ[i] = null;
    
                   }
               }
               if (gequ[0] != null)
               {
                   gequ[0].PlayState = SongPlayState.played;
               }
           }
           #endregion
    
    
           #region 重放当前歌曲
           // 重放当前歌曲       
           public static void PlayAgain()
           {
               if (shuzuindex<gequ.Length)
               {
                   if (gequ[shuzuindex] != null)
                   {
                       gequ[shuzuindex].SetPlayAgain();
                   }
               }
              
           }
           #endregion
    
    
           #region 播放下一首
           // 播放下一首
           public static void MoveOn()
           {
               if (shuzuindex < gequ.Length)
               {
    
    
                   if (gequ[shuzuindex] != null && gequ[shuzuindex].PlayState == SongPlayState.again)//用于判断是不是重播
                   {
                       gequ[shuzuindex].SetSongPlayed();
                       //gequ[shuzuindex].PlayState = SongPlayState.played;
                   }
                   else
                   {
                      // gequ[shuzuindex].SetSongPlayed();
                      // shuzuindex++;
                      
                       shuzuindex++;
    
                   }
                  
                 
               }
    
           }       
           #endregion
          
          
        }
    }

     04.用于或得歌曲和歌手图片路径

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace MyKTV
    {
        public class KTVUtil
        {
            //保存歌曲路径,这样就可以多次使用
            public static string songurl;
    
            //保存歌手图片路径,这样就可以多次使用
            public static string singer_photo;
    
        }
    }

      05.同时,我们还需要一个工具类,以方便使用(这里先展示一下)

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace MyKTV
    {
       public class Tool
        {
           public static string num1;//获得是(组合,男,女)的类行
    
           public static string num2;//获得歌手的地区
    
           public static string num3;//或得歌手的名字
    
           public static string num4;//找到歌曲的路径(地址)
    
           public static FormMain frM;//主窗体,播放器的共用
    
           public static int num5;//获得是(流行,儿歌..)的类行
    
           public static Form_liebiao frm;//调用Form_liebiao中的把歌添加到数组的方法
    
           public static int num6;//用于字数点歌
    
           public static bool num7=false;//用于区分的标识符
         
           public static int ph;//用于金曲排行
    
           public static Form_Yidian yidian;
    
        }
    }

    这样后,我们就可以开始我们的开发之路了

    1.前台

    1.欢迎界面

    代码如下:

    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 Form_Wlcome : Form
        {
            public Form_Wlcome()
            {
                InitializeComponent();
            }
    
            private void pictureBox1_Click(object sender, EventArgs e)
            {
               //单击进入主界面
                   FormMain fm = new FormMain();
                   fm.Show();
                   this.Hide();//隐藏欢迎界面
            }
    
           
        }
    }

    2.主页面

    这里我们就来说一说KTV项目的功能,上面的图一目了然

    我们就上图所看到的一系列控件进行一一展示

    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 FormMain : Form
        {
            public FormMain()
            {
                InitializeComponent();
            }
            //歌曲名称
            public Song songname;
    
          
            private void FormMain_Load(object sender, EventArgs e)
            {
               
                Form_liebiao frm = new Form_liebiao();//走一遍Form_liebiao窗体
                Tool.frm = frm;//这样就可以把Form_liebiao窗体赋给Tool类里的frm,这样就可以在其它窗体里用Form_liebiao窗体里的方法,..(eg:在fenleidiange窗体里用Form_            liebiao窗体中Add方法用于添加到已点列表)
                Tool.frM = this;//把主窗体赋值给Tool类里面的frM,这样就可以用主窗体的播放器空间
              
                string sql="select resource_path from dbo.Resource_Path where resource_id=1";
                KTVUtil.singer_photo= get( sql) ;//歌手地址
                string sql1 = "select resource_path from dbo.Resource_Path where resource_id=2";
                KTVUtil.songurl=  get(sql1);//歌曲地址
               // mp.URL = Tool.num4;
            }
    
            //用于获得 歌曲 或 歌手的地址(路径)
            public string get(string sql) 
            {
                SqlConnection con = new SqlConnection(SqlServer.str);
                SqlCommand cmd = new SqlCommand(sql,con);
                string url="";
                try
                {
                    con.Open();
                   SqlDataReader dr= cmd.ExecuteReader();
                    if(dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            url = dr["resource_path"].ToString();
                        }
                    }
                }
                catch (Exception)
                {
    
                    MessageBox.Show("网络出错哟!");
                }
                finally 
                {
    
                    con.Close();
                }
                return url;
            }
            //退出按钮
            private void but_tui_Click(object sender, EventArgs e)
            {
                //提示
                DialogResult result = MessageBox.Show("确定退出吗?","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
                if (result==DialogResult.OK)
                {
                    Application.Exit();
                }
                else
                {
                    //。。。
                }
               
            }
    
            //歌星点歌按钮
            private void but_one_Click(object sender, EventArgs e)
            {
                Form_GeXing fg = new Form_GeXing();
                Tool.num7 = false;
                this.Hide();
                fg.Show();
            }
    //显示播放歌曲,和下一首歌曲 public void showsongname() { txt_now.Text= Playsong.PlayingSongName(); txt_next.Text = Playsong.NextSongName(); }
    //播放歌曲的方法 public void playedsong() { //获取当前播放的歌曲 songname = Playsong.GetPlayingSong(); //如果当前歌曲不为空的话 if(songname!=null) { //把播放歌曲状态改为已播放 songname.PlayState = SongPlayState.played; mp.URL = KTVUtil.songurl + songname.gequ_dizhi; //显示歌手图片 string photoPath = KTVUtil.singer_photo + songname.geshou_url; this.picb.Image = Image.FromFile(photoPath); } } //应用timer控件实现对歌曲播放的状态进行一系列的操作 private void time_Tick(object sender, EventArgs e) { showsongname();//主页面展示 当前播放 , 下一首播放 内容 //顺序播放 if (this.songname==null)//未找到歌在播放 { playedsong();//获取一首歌 } if (this.mp.playState == WMPLib.WMPPlayState.wmppsStopped)//一首歌快播完了 { this.songname = null;//把歌曲名称改为null Playsong.MoveOn();//再重新获取下一首歌曲 // songname.PlayState = SongPlayState.played; } //切歌 if (this.songname != null && this.songname.PlayState == SongPlayState.cut) { this.mp.URL = "";//把播放地址设为null,则停止了播放 this.songname = null;//把歌曲也设为了null } //重播 if (this.songname != null && this.songname.PlayState == SongPlayState.again) { playedsong();//重新 } }
    //切歌 private void but_qie_Click(object sender, EventArgs e) { if (txt_now.Text=="") { MessageBox.Show("您未添加歌曲,没发切歌哟!亲", "提示", MessageBoxButtons.OKCancel,MessageBoxIcon.Information); } else if (txt_now.Text != "" && txt_next.Text!="") { DialogResult result = MessageBox.Show("确定切歌", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { Playsong.CutSong(-1); } } else { MessageBox.Show("现在播放的是最后一首歌,已经没歌可切喽!再去添加吧!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information); } }

    //重播 private void but_chong_Click(object sender, EventArgs e) { Playsong.PlayAgain(); } private void but_five_Click(object sender, EventArgs e) { zishudiange zs = new zishudiange(); this.Hide(); zs.Show(); } private void but_two_Click(object sender, EventArgs e) { pinyindiange py = new pinyindiange(); Tool.num7 = false; this.Hide(); py.Show(); } private void but_three_Click_1(object sender, EventArgs e) { fenleidiange fl = new fenleidiange(); Tool.num7 = false; fl.Show(); } private void but_four_Click(object sender, EventArgs e) { Tool.ph = 1; Form_liebiao frm = new Form_liebiao(); Tool.num7 = false; frm.Show(); Tool.ph = 0; } private void but_dian_Click(object sender, EventArgs e) { Form_Yidian yi = new Form_Yidian(); yi.Show(); } private void but_ke_Click(object sender, EventArgs e) { MessageBox.Show("已向客服中心联系!","提示",MessageBoxButtons.OKCancel,MessageBoxIcon.Information); } //播放器的隐藏与显示 private void lab_yin_Click(object sender, EventArgs e) { if (lab_yin.Text=="隐藏播放器") { this.Height = this.Height - 95; lab_yin.Text = "显示播放器"; } else { this.Height = this.Height + 95; lab_yin.Text = "隐藏播放器"; } } //实现窗体的拖动 #region 窗体的拖动 //一下是窗体的拖动 private Point mouseOffset; //记录鼠标指针的坐标 private bool isMouseDown = false; //记录鼠标按键是否按下 private void panel_top_MouseUp(object sender, MouseEventArgs e) { // 修改鼠标状态isMouseDown的值 // 确保只有鼠标左键按下并移动时,才移动窗体 if (e.Button == MouseButtons.Left) { isMouseDown = false; } } private void panel_top_MouseMove(object sender, MouseEventArgs e) { if (isMouseDown) { Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30); Location = mousePos; } } private void panel_top_MouseDown(object sender, MouseEventArgs e) { int xOffset; int yOffset; if (e.Button == MouseButtons.Left) { xOffset = -e.X - SystemInformation.FrameBorderSize.Width; yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height; mouseOffset = new Point(xOffset, yOffset); isMouseDown = true; } } private void FormMain_MouseUp(object sender, MouseEventArgs e) { // 修改鼠标状态isMouseDown的值 // 确保只有鼠标左键按下并移动时,才移动窗体 if (e.Button == MouseButtons.Left) { isMouseDown = false; } } private void FormMain_MouseMove(object sender, MouseEventArgs e) { if (isMouseDown) { Point mousePos = Control.MousePosition; mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30); Location = mousePos; } } private void FormMain_MouseDown(object sender, MouseEventArgs e) { int xOffset; int yOffset; if (e.Button == MouseButtons.Left) { xOffset = -e.X - SystemInformation.FrameBorderSize.Width; yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height; mouseOffset = new Point(xOffset, yOffset); isMouseDown = true; } } #endregion } }

     歌星点歌(主要是listview控件的使用)

    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 Form_GeXing : Form
        {
            public Form_GeXing()
            {
                InitializeComponent();
            }
    
            private void panel_foot_Paint(object sender, PaintEventArgs e)
            {
    
            }
    
         
            //从数据库加载歌曲类型的方法
            public void gequleixinf() {
    
                string str = SqlServer.str;
                string sql = "select singertype_name from singer_type ";
                SqlConnection con = new SqlConnection(str);
                SqlCommand com = new SqlCommand(sql, con);
                try
                {
                    lv_two.Items.Clear();//清除以前listview数据
                   // imglist_two.Images.Clear();//清除以前图片数据
                    con.Open();
                    SqlDataReader dr = com.ExecuteReader();
                    int index = 0;
                  
                   
                    if (dr != null)
                    {
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                string name = dr["singertype_name"].ToString();
    
                                ListViewItem item = new ListViewItem();
                                item.Text = name;
                                item.ImageIndex = index;
                                lv_two.Items.Add(item);//关联
                                index++;
                            }
    
                        }
    
                    }
    
                }
                catch (Exception)
                {
    
                    MessageBox.Show("网络出错哦!");
                }
                finally
                {
                    con.Close();
                }
            
            }
    
            //动态加载歌手信息方法
            public void dongtaijiazai()
            {
                string str = SqlServer.str;
                string sql = "select resource_path,singer_phone_url,singer_name from Resource_Path,singer_info,singer_type where singer_info.singertype_id=singer_type.singertype_id and resource_type='singer_photo' and singer_sex='" + Tool.num1 + "' and singertype_name='" + Tool.num2 + "' ";
                SqlConnection con = new SqlConnection(str);
                SqlCommand com = new SqlCommand(sql, con);
                try
                {
                    con.Open();
                    SqlDataReader dr = com.ExecuteReader();
                    int imgindex = 0;//图片下标
                     lv_three.Items.Clear();//清除以前listview数据
                     imglist_three.Images.Clear();//清除以前图片数据
                    if (dr != null)
                    {
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                string path = dr["resource_path"].ToString();
    
                                string singer_phone_url = dr["singer_phone_url"].ToString();
                                string singer_name = dr["singer_name"].ToString();
                               
                                string zong = path + singer_phone_url;//拼接歌手图片地址                       
                                imglist_three.Images.Add(Image.FromFile(zong));//显示图片
    
                                // imglist_three.ImageSize = Image.FromFile(zong).Size;
                                //"" + singer_name + "", imgindex
    
                                //ListViewItem绑定值
                                ListViewItem item = new ListViewItem();
                                item.Text = "" + singer_name + "";
                                item.ImageIndex =imgindex;
                                lv_three.Items.Add(item);
                                imgindex++;//增加图片下标
                            }
    
                        }
    
                    }
    
                }
                catch (Exception)
                {
    
                    MessageBox.Show("网络出错哦!");
                }
                finally
                {
                    con.Close();
                }
            }
    
            //返回按钮
            private void but_fan_Click(object sender, EventArgs e)
            {
                if (this.lv_two.Visible==true)
                {
                    lv_one.Visible = true;
                    lv_two.Visible = false;
                }
                else if (this.lv_one.Visible==true)
                {
                   
                    this.Hide();
                    Tool.frM.Show();
                }
                else if (this.lv_three.Visible==true)
                {
                    lv_three.Visible = false;
                    lv_two.Visible = true;
                }
            }
            //主页面
            private void but_home_Click(object sender, EventArgs e)
            {
    
                this.Close();
                Tool.frM.Show();
            }
    
          
            private void lv_one_Click(object sender, EventArgs e)
            {
                Tool.num1 = lv_one.SelectedItems[0].Text;//获取选择值
                if (Tool.num1 != "组合")
                {
                    Tool.num1 = Tool.num1 == "女歌手" ? "" : "";
                }
    
                lv_one.Visible = false;//隐藏第一个listview
    
                lv_two.View = View.LargeIcon;//设定显示listview显示方式
    
                lv_two.LargeImageList = imglist_two;//设定显示listview显示图片的方式
    
                gequleixinf();//从数据库加载歌曲类型
    
    
                lv_two.Visible = true;//让第二个listview显示
    
                lv_two.Location = lv_one.Location;//让显示的listview显示的位置和隐藏的listview相同
    
                lv_two.Size = lv_one.Size;//让显示的listview大小与隐藏的相同
            }
    
            private void lv_two_Click(object sender, EventArgs e)
            {
                Tool.num2 = lv_two.SelectedItems[0].Text;//获取选择值
                //MessageBox.Show(Tool.num2);
                dongtaijiazai();//加载歌手信息
                lv_two.Visible = false;
                lv_three.Visible = true;
                lv_three.Location = lv_two.Location;
                lv_three.Size = lv_two.Size;
            }
    
            private void lv_three_Click(object sender, EventArgs e)
            {
                Tool.num3 = lv_three.SelectedItems[0].Text;
                // MessageBox.Show(Tool.num3);
                Form_liebiao lb = new Form_liebiao();
                Tool.num7 = false;
                this.Hide();
                lb.Show();
               
            }
       
            //已点列表
            private void but_yi_Click(object sender, EventArgs e)
            {
                Form_Yidian fy = new Form_Yidian();
    
                fy.Show();
            }
            //切歌
            private void but_qie_Click(object sender, EventArgs e)
            {
                if (Tool.frM.txt_now.Text == "")
                {
                    MessageBox.Show("您未添加歌曲,没发切歌哟!亲", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                else if (Tool.frM.txt_now.Text != "" && Tool.frM.txt_next.Text != "")
                {
                    DialogResult result = MessageBox.Show("确定切歌", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        Playsong.CutSong(-1);
                    }
                }
                else
                {
                    MessageBox.Show("现在播放的是最后一首歌,已经没歌可切喽!再去添加吧!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
            }
            //重唱
            private void but_again_Click(object sender, EventArgs e)
            {
                Playsong.PlayAgain();
            }
    
            private void Form_GeXing_Load(object sender, EventArgs e)
            {
    
            }
    
            #region 窗体的拖动
            //一下是窗体的拖动
            private Point mouseOffset;        //记录鼠标指针的坐标        
            private bool isMouseDown = false; //记录鼠标按键是否按下   
    
            private void panel_top_MouseUp(object sender, MouseEventArgs e)
            {
                // 修改鼠标状态isMouseDown的值      
                // 确保只有鼠标左键按下并移动时,才移动窗体       
                if (e.Button == MouseButtons.Left)
                {
                    isMouseDown = false;
                }
    
    
            }
    
            private void panel_top_MouseMove(object sender, MouseEventArgs e)
            {
                if (isMouseDown)
                {
                    Point mousePos = Control.MousePosition;
                    mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
                    Location = mousePos;
                }
    
            }
    
            private void panel_top_MouseDown(object sender, MouseEventArgs e)
            {
                int xOffset;
                int yOffset;
                if (e.Button == MouseButtons.Left)
                {
                    xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                    yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
                    mouseOffset = new Point(xOffset, yOffset);
                    isMouseDown = true;
                }
    
            }
    
         
            #endregion
    
           
        }
    }

    歌曲列表

    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 Form_liebiao : Form
        {
            public Form_liebiao()
            {
                InitializeComponent();
            }
            public string  song_url;//歌曲名字
    
            public string singer_url;//歌手图片名字
           
            //显示列表的方法
            public void liebiao(string sql) {
    
               
                lv_liebiao.Items.Clear();
                string str = SqlServer.str;
                SqlConnection con = new SqlConnection(str);
                SqlCommand com = new SqlCommand(sql, con);
                try
                {
                    con.Open();
                    SqlDataReader dr = com.ExecuteReader();
                    if (dr != null)
                    {
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
                                string song_name = dr["song_name"].ToString();
                                string singer_name = dr["singer_name"].ToString();
    
                                ListViewItem item = new ListViewItem("" + song_name + "");
                                item.SubItems.Add("" + singer_name + "");
    
                                lv_liebiao.Items.Add(item);
                            }
                        }
                    }
                }
                catch (Exception)
                {
    
                    MessageBox.Show("网络异常哟!");
                }
                finally
                {
    
                    con.Close();
    
                }
            
            }
            //获得歌手的歌曲列表
            private void Form_liebiao_Load(object sender, EventArgs e)
            {
    
                if (Tool.num6!= 0 && Tool.num7==true)//字数点歌
                {
                    string sql = @"select song_name,singer_name from song_info,singer_info
                                    where song_info.singer_id=singer_info.singer_id
                                    and song_word_count=" + Tool.num6 + "";
                    liebiao(sql);
                }
            
                else if (Tool.num5 != 0)//分类点歌
                {
                    string sql= @"select song_name,singer_name from song_info,singer_info
                                    where song_info.singer_id=singer_info.singer_id
                                    and songtype_id=" + Tool.num5 + "";
                   liebiao(sql);
                }
                else if(Tool.ph==1)//点击排行榜
                {
                    string sql = @"select song_name,singer_name from song_info,singer_info
                                    where song_info.singer_id=singer_info.singer_id
                                     order by song_play_count desc ";
                    liebiao(sql);
                }
                else if (Tool.num3!=null&&Tool.num7==false) //歌星(歌手)点歌
                {
                    string sql = "select song_name,singer_name from singer_info,song_info where singer_info.singer_id=song_info.singer_id and singer_name='" + Tool.num3 + "' ";
                    liebiao(sql);
                }
               
            }
    
           
            //在歌单列表中点击添加到已点列表的方法
            public  void  Add(string s,string s1) {
    
                string str = SqlServer.str;
                string sql = "select song_name,song_url,singer_name,singer_phone_url,resource_path from song_info,singer_info,Resource_Path where singer_info.singer_id=song_info.singer_id and resource_type='song' and song_name='" + s + "' and singer_name='" + s1 + "'";
                SqlConnection con = new SqlConnection(str);
                SqlCommand com = new SqlCommand(sql, con);
                try
                {
    
                    con.Open();
                    SqlDataReader dr = com.ExecuteReader();
                    if (dr != null)
                    {
                        if (dr.HasRows)
                        {
    
                            while (dr.Read())
                            {
                                //string resource_path = dr["resource_path"].ToString();//歌曲路径
                                song_url = dr["song_url"].ToString();//歌曲名字  .mp3
                                singer_url = dr["singer_phone_url"].ToString();//歌手名字
                                //Tool.num4 = resource_path + song_url;//找到歌曲
                                //if (thing=="")
                                //{
                                //    Tool.frM.mp.URL = Tool.num4;
                                //    thing = Tool.num4;
                                //}
    
    
    
                            }
                        }
    
                    }
                    //用于把歌曲信息放在数组
                    Song song = new Song();
                    song.gequ_name = s;
                    song.geshou_name = s1;
                    song.gequ_dizhi = song_url;
                    song.geshou_url = singer_url;
                    //song.gequ_dizhi = Tool.num4;
                  
                    if (Playsong.Addsong(song)) //把歌曲信息添加到对象数组
                    {
                        MessageBox.Show("添加成功!");
                        //用于排行榜
                        string sql1 = "select singer_id,song_id from song_info where song_name='" + s + "'";
                        SqlConnection con1 = new SqlConnection(SqlServer.str);
                        SqlCommand cmd = new SqlCommand(sql1, con1);
                        con1.Open();
                        SqlDataReader dr1 = cmd.ExecuteReader();
                        int singer_id = 0;
                        int song_id = 0;
    
                        if (dr1.HasRows)
                        {
                            while (dr1.Read())
                            {
                                singer_id = Convert.ToInt32(dr1["singer_id"].ToString());
                                song_id = Convert.ToInt32(dr1["song_id"].ToString());
                            }
                        }
                        dr1.Close();
                        con1.Close();
                        string sql2 = "update song_info set song_play_count=song_play_count+1 where singer_id=" + singer_id + "  and song_id=" + song_id + "";
                        SqlConnection con2 = new SqlConnection(SqlServer.str);
                        SqlCommand cmd2 = new SqlCommand(sql2, con2);
                        con2.Open();
                        cmd2.ExecuteNonQuery();
                        con2.Close();
    
                    }
                    else 
                    {
                        MessageBox.Show("添加失败!");
                    }
    
                }
                catch (Exception)
                {
    
                    MessageBox.Show("网络出错!");
                }
                finally
                {
                    con.Close();
    
                }
                
            }
           //在歌曲列表中用于点击歌曲进行播放
            private void lv_liebiao_Click(object sender, EventArgs e)
            {
                if (lv_liebiao.SelectedItems.Count > 0)
                {
                    string s = lv_liebiao.SelectedItems[0].SubItems[0].Text;//歌曲名
                    string s1 = lv_liebiao.SelectedItems[0].SubItems[1].Text;//歌手名
                    Add(s, s1);//点击添加到已点列表
                }
    
                
            }
            //返回主页面
            private void but_home_Click(object sender, EventArgs e)
            {           
                this.Close();
                Tool.frM.Show();
            }
    
            private void lv_liebiao_SelectedIndexChanged(object sender, EventArgs e)
            {
             
            }
            //查看已点列表
            private void but_yi_Click(object sender, EventArgs e)
            {
                Form_Yidian fy = new Form_Yidian();
                this.Close();
                fy.Show();
            }
    
            private void but_qie_Click(object sender, EventArgs e)
            {
                if (Tool.frM.txt_now.Text == "")
                {
                    MessageBox.Show("您未添加歌曲,没发切歌哟!亲", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                else if (Tool.frM.txt_now.Text != "" && Tool.frM.txt_next.Text != "")
                {
                    DialogResult result = MessageBox.Show("确定切歌", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        Playsong.CutSong(-1);
                    }
                }
                else
                {
                    MessageBox.Show("现在播放的是最后一首歌,已经没歌可切喽!再去添加吧!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
            }
    
            private void but_again_Click(object sender, EventArgs e)
            {
                Playsong.PlayAgain();
            }
    
            private void but_fan_Click(object sender, EventArgs e)
            {
                this.Close();
                Tool.frM.Show();
    
            }
    
            #region 窗体拖动
            private Point mouseOffset;        //记录鼠标指针的坐标        
            private bool isMouseDown = false; //记录鼠标按键是否按下   
    
            private void panel_top_MouseUp(object sender, MouseEventArgs e)
            {
                // 修改鼠标状态isMouseDown的值      
                // 确保只有鼠标左键按下并移动时,才移动窗体       
                if (e.Button == MouseButtons.Left)
                {
                    isMouseDown = false;
                }
    
            }
    
            private void panel_top_MouseMove(object sender, MouseEventArgs e)
            {
                if (isMouseDown)
                {
                    Point mousePos = Control.MousePosition;
                    mousePos.Offset(mouseOffset.X + 5, mouseOffset.Y + 30);
                    Location = mousePos;
                }
    
            }
    
            private void panel_top_MouseDown(object sender, MouseEventArgs e)
            {
                int xOffset;
                int yOffset;
                if (e.Button == MouseButtons.Left)
                {
                    xOffset = -e.X - SystemInformation.FrameBorderSize.Width;
                    yOffset = -e.Y - SystemInformation.CaptionHeight - SystemInformation.FrameBorderSize.Height;
                    mouseOffset = new Point(xOffset, yOffset);
                    isMouseDown = true;
                }
    
            }
    
            #endregion
    
            private void panel_top_Paint(object sender, PaintEventArgs 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 Form_Yidian : Form
        {
            public Form_Yidian()
            {
                InitializeComponent();
            }
          
           //显示已点列表
            private void Form_Yidian_Load(object sender, EventArgs e)
            {
                yidiangequ();
                
               
            }
            //已点列表
            private void yidiangequ()
            {
                lv_yidian.Items.Clear();
               // int num = 0;
                foreach (Song item in Playsong.gequ)
                {
                    if (item != null)
                    {
                        //给listview绑定值
                        ListViewItem tem = new ListViewItem(item.gequ_name);
                        tem.SubItems.Add(item.geshou_name);               
                        string hao =item.PlayState==SongPlayState.unplayed ? "未播" : "已播";
                       
                      
    
                        tem.SubItems.Add(hao);
                        lv_yidian.Items.Add(tem);
                       // num++;
                    }
                    
    
                }
    
            }
    
           
    
            #region 已点列表可以播放的方法(未用)
             // string s = lv_yidian.SelectedItems[0].SubItems[0].Text;//歌曲名
               // string s1 = lv_yidian.SelectedItems[0].SubItems[1].Text;//歌手名
               // string s2 = lv_yidian.SelectedItems[0].SubItems[2].Text;
               ////改变歌曲状态
               // if (s2 == "在播")
               // {
    
               //     lv_yidian.SelectedItems[0].SubItems[2].Text = "已播";
               // }
               // else
               // {
               //     lv_yidian.SelectedItems[0].SubItems[2].Text = "已播";
               // }
               // string str = SqlServer.str;
               // string sql = "select song_name,song_url,singer_name,singer_phone_url,resource_path from song_info,singer_info,Resource_Path where singer_info.singer_id=song_info.singer_id and resource_type='song' and song_name='" + s + "' and singer_name='" + s1 + "'";
               // SqlConnection con = new SqlConnection(str);
               // SqlCommand com = new SqlCommand(sql, con);
               // try
               // {
               //     con.Open();
               //     SqlDataReader dr = com.ExecuteReader();
               //     if (dr != null)
               //     {
               //         if (dr.HasRows)
               //         {
               //             while (dr.Read())
               //             {
               //                 string resource_path = dr["resource_path"].ToString();//歌曲路径
               //                 string song_url = dr["song_url"].ToString();//歌曲名字
    
               //                 Tool.num4 = resource_path + song_url;//找到歌曲
                              
               //                 Tool.frM.mp.URL = Tool.num4;
    
    
               //             }
               //         }
    
               //     }          
    
               // }
               // catch (Exception)
               // {
    
               //     MessageBox.Show("网络出错!");
               // }
               // finally
               // {
               //     con.Close();
    
               // }
            #endregion
    
    
    
            //已点的单击事件,想在已点列表里进行点歌(未用)
            private void lv_yidian_Click(object sender, EventArgs e)
            {
                
              
               
            }
            //点击切歌触发的事件
            private void but_qie_Click(object sender, EventArgs e)
            {
                if (Tool.frM.txt_now.Text == "")
                {
                    MessageBox.Show("您未添加歌曲,没发切歌哟!亲", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                else if (Tool.frM.txt_now.Text != "" && Tool.frM.txt_next.Text != "")
                {
                    DialogResult result = MessageBox.Show("确定切歌", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        Playsong.CutSong(-1);
                        yidiangequ();//重新再加载了已点列表
                        
                    }
                }
                else
                {
                    MessageBox.Show("现在播放的是最后一首歌,已经没歌可切喽!再去添加吧!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                
            }
    
            //重唱
            private void but_again_Click(object sender, EventArgs e)
            {
                Playsong.PlayAgain();
               
            }
           //返回
            private void but_fan_Click(object sender, EventArgs e)
            {
                this.Close();
                Tool.frM.Show();
            }
            //主页
            private void but_home_Click(object sender, EventArgs e)
            {
                this.Close();
                Tool.frM.Show();
            }
    
        
            private void but_qing_Click(object sender, EventArgs e)
            {
                          yidiangequ();
               
                    
             
             }
               
            }
    
           
        }

    拼音点歌

    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 pinyindiange : Form
        {
            public pinyindiange()
            {
                InitializeComponent();
            }
    
            //加载有的歌曲方法
            public void jiazai() {
                lv_liebiao.Items.Clear();
                string sql = @"select song_name,singer_name from song_info,singer_info where song_info.singer_id=dbo.singer_info.singer_id and song_name like'%" + txt_name.Text + "%' or song_ab like '%" + txt_name.Text + "%' and song_info.singer_id=dbo.singer_info.singer_id";
                string str = SqlServer.str;
                SqlConnection con = new SqlConnection(str);
                SqlCommand com = new SqlCommand(sql, con);
                try
                {
                    con.Open();
                    SqlDataReader dr = com.ExecuteReader();
                    if (dr != null)
                    {
                        if (dr.HasRows)
                        {
                            while (dr.Read())
                            {
    
                                string song_name = dr["song_name"].ToString();
                                string singer_name = dr["singer_name"].ToString();
    
                                ListViewItem item = new ListViewItem("" + song_name + "");
                                item.SubItems.Add("" + singer_name + "");
    
                                lv_liebiao.Items.Add(item);
                            }
                        }
                    }
                }
                catch (Exception)
                {
    
                    MessageBox.Show("网络异常哟!");
                }
                finally
                {
    
                    con.Close();
                }
            
            }
            private void but_select_Click(object sender, EventArgs e)
            {
    
                jiazai();//点击可用模糊查询
    
            }
          
            //点击列表中的歌曲, 播放或添加
            private void lv_liebiao_Click(object sender, EventArgs e)
            {
                if (lv_liebiao.SelectedItems.Count > 0)//确定有选中项,要不下面选中时会报错
                {
                    string s = lv_liebiao.SelectedItems[0].SubItems[0].Text;//歌曲名
                    string s1 = lv_liebiao.SelectedItems[0].SubItems[1].Text;//歌手名
                    Tool.frm.Add(s, s1);//调用前面Form_liebiao中的方法
                }
    
            }
    
            private void pinyindiange_Load(object sender, EventArgs e)
            {
                txt_name.Focus();//锁定输入焦点
    
                jiazai();//窗体展现出来显示已有歌曲
            }
    
            private void but_home_Click(object sender, EventArgs e)
            {
                this.Close();
                Tool.frM.Show();
            }
    
            private void but_fan_Click(object sender, EventArgs e)
            {
                this.Close();
                Tool.frM.Show();
            }
    
            private void but_yi_Click(object sender, EventArgs e)
            {
                Form_Yidian yi = new Form_Yidian();
                this.Close();
                yi.Show();
            }
    
            private void but_qie_Click(object sender, EventArgs e)
            {
                if (Tool.frM.txt_now.Text == "")
                {
                    MessageBox.Show("您未添加歌曲,没发切歌哟!亲", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                else if (Tool.frM.txt_now.Text != "" && Tool.frM.txt_next.Text != "")
                {
                    DialogResult result = MessageBox.Show("确定切歌", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        Playsong.CutSong(-1);
                    }
                }
                else
                {
                    MessageBox.Show("现在播放的是最后一首歌,已经没歌可切喽!再去添加吧!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
                }
                
            }
    
            private void but_again_Click(object sender, EventArgs e)
            {
    
            }
    
            private void txt_name_TextChanged(object sender, EventArgs e)
            {
                //当文本框的内容改变为空时,则显示所有歌曲
                if (txt_name.Text=="")
                {
                    jiazai();
                }
            }
    
           
    
        }
    }
  • 相关阅读:
    【读书笔记】《思考,快与慢》
    【2020-12-09】别人看不上的,正是绝佳机会
    员工的重要性
    二叉树的堂兄弟节点
    占位
    数组中重复的数字
    从上到下打印二叉树
    Python生成exe
    二叉搜索树节点最小距离
    第N个斐波那契数
  • 原文地址:https://www.cnblogs.com/zhangzongle/p/5186566.html
Copyright © 2011-2022 走看看