首页 > 其他 > 详细

MyKTV项目总结

时间:2016-02-11 19:13:05      阅读:487      评论:0      收藏:0      [点我收藏+]

  今天和大伙分享一下我的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 } }

 未完待续。。。。。

MyKTV项目总结

原文:http://www.cnblogs.com/zhangzongle/p/5186566.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!