您的位置:首页 > 其它

MyKTV项目总结

2015-07-31 10:37 501 查看
经过一个多星期的KTV项目总与写完了,

先进入主界面吧:



主界面有五个点歌功能,歌星点歌,拼音点歌,类型选择,金榜排行,字数点歌

先看看歌星点歌吧:

进入歌星点歌胡会出现如下界面



通过点击男,女,组合,会进入下一级菜单

进入到地区分类界面

如图:



通过第一个界面进入到对应的地区界面

代码如下:

public void ShowSingerDiQu()
{
if (listView1.SelectedItems[0]!=null)
{
listView1.Visible = false;
listView2.Visible = true;
listView2.Location = listView1.Location;

this.SingerType = Convert.ToString(listView1.SelectedItems[0].Tag);
}
string sql = "select singertype_name,singertype_id from singer_type";
SqlCommand cmd = new SqlCommand(sql,db.Conection);
SqlDataReader sdr;
try
{
db.OpenConnection();
sdr = cmd.ExecuteReader();
listView1.Items.Clear();
if (sdr.HasRows)
{
int result = 0;
while (sdr.Read())
{
ListViewItem lvitem = new ListViewItem();
string typename = Convert.ToString(sdr["singertype_name"]);
int typeid = Convert.ToInt32(sdr["singertype_id"]);
lvitem.Text = typename;
lvitem.Tag = typeid;
lvitem.ImageIndex = result;
listView2.Items.Add(lvitem);
result++;
}
sdr.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("第二个系统报错" + ex.Message);
}
finally
{
db.CloseConnection();
}
}


通过地区界面会进入到具体的人名下:

人名下会有歌星的歌曲



通过读取对应的地区得到对应的歌手

/// <summary>
/// 读取对应地区的歌手名称
/// </summary>
public void ShowSingerName()
{
if (listView2.SelectedItems[0]!=null)
{
listView2.Visible = false;
lvName.Visible = true;
lvName.Location = listView1.Location;
SingerId = Convert.ToInt32(listView2.SelectedItems[0].Tag);
StringBuilder sb = new StringBuilder();
string sum = SingerType;
if (sum!="组合")
{
sum = SingerType == "女歌手" ? "男" : "女";
}
string sql = string.Format("select singer_name,singer_photo_url,singer_id from singer_info where singertype_id='{0}' and singer_sex='{1}'", SingerId,sum);
SqlCommand cmd = new SqlCommand(sql, db.Conection);
try
{
db.OpenConnection();
SqlDataReader read = cmd.ExecuteReader();

//歌手头像索引
int imageindex = 0;
//清空图片集合
imageName.Images.Clear();
//清空listview列表集合
lvName.Items.Clear();
if (read.HasRows)
{
while (read.Read())
{
//图片的地址
string path = KtvUtil.FilePath + @"\" + Convert.ToString(read["singer_photo_url"]);
//图片路径装载到imagelist
imageName.Images.Add(Image.FromFile(path));
//将类型装载到集合中去
ListViewItem lvitem = new ListViewItem();
string typename = Convert.ToString(read["singer_name"]);
int typeid = Convert.ToInt32(read["singer_id"]);
lvitem.Text = typename;
lvitem.Tag = typeid;
lvitem.ImageIndex = imageindex;
lvName.Items.Add(lvitem);
imageindex++;
}
read.Close();
}
}
catch (Exception ex)
{
MessageBox.Show("第三个系统报错!" + ex.Message);
}
finally
{
db.CloseConnection();
}
}

}




通过歌手界面进入到对应歌手的歌曲:

代码如下:

public void ShowList()
{
//定义一个StringBuilder对象
StringBuilder sb = new StringBuilder();
//sql语句
string sql = string.Format("select song_id,song_name,singer_name='{0}',song_url from song_info where singer_id={1}",lvName.SelectedItems[0].Text,Convert.ToInt32(lvName.SelectedItems[0].Tag));
//定义歌曲列表窗体的对象
FrmSongList sl=new FrmSongList();
//把sql语句传到第三个窗体上
sl.Sql=sql;
sl.ShowDialog();
this.Close();
}


歌手点歌是用同一个窗体用listview实现了三层筛选进入到歌曲,进行点歌,

当点击歌曲的时候歌曲会自动播放并添加到已播放歌曲列表中,



代码如下:

在palylist类中

先声明一个数组用来存放歌曲,在写一个添加歌曲的方法

//定义一个集合存放歌曲
public static SongList[] song=new SongList[50];
//定义一个数组索引
public static int selectindex=0;
/// <summary>
/// 添加歌曲
/// </summary>
/// <param name="sl"></param>
/// <returns></returns>
public static void AddSong(SongList sl)
{
//记录歌曲是否添加成功
for (int i = 0; i < song.Length; i++)
{
if (song[i]==null)
{
//把歌曲类里的歌曲添加到数组中
song[i] = sl;
//添加成功
break;
}
}

}


/// <summary>
/// 播放歌曲方法
/// </summary>
/// <returns></returns>
public static SongList GetSong()
{
if (song[selectindex]!=null)
{
return song[selectindex];
}
else
{
return null;
}
}


在songlist类中要有如下代码:

public enum PalySongState
{
//未播放 , 播放, 重播,切歌
unplayed,played,again,cut
}
/// <summary>
/// 歌曲播放类
/// </summary>
public class SongList
{
//歌曲名称
private string SongName;
//歌曲路径
private string SongUl;
//歌曲状态
private string SongState;

public string SongState1
{
get { return SongState; }
set { SongState = value; }
}

public string SongUl1
{
get { return SongUl; }
set { SongUl = value; }
}

public string SongName1
{
get { return SongName; }
set { SongName = value; }
}

//把当前的播放状态设置为未播放状态
private  PalySongState playSong = PalySongState.unplayed;

public  PalySongState PlaySong
{
get { return playSong; }
set { playSong = value; }
}
/// <summary>
/// 将未播放状态改为播放状态
/// </summary>
public void PalyState()
{
this.PlaySong = PalySongState.played;
}
/// <summary>
/// 将歌曲重新播放
/// </summary>
public void AgainState()
{
this.PlaySong = PalySongState.again;
}
/// <summary>
/// 切歌状态
/// </summary>
public void CutState()
{
this.PlaySong = PalySongState.cut;
}


再把歌曲添加到数组中去:

代码如下:

在dataGridView的CellContentClick的事件写代码;

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
if (this.dataGridView1.SelectedRows[0] != null)
{
SongList song = new SongList();
//歌曲名称
song.SongName1 = this.dataGridView1.SelectedRows[0].Cells[0].Value.ToString();
//歌曲路径
song.SongUl1 = this.dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
MessageBox.Show(song.SongUl1);
PalyList.AddSong(song);

}
}


在已播界面的lode事件中写如下代码用来控制播放类型

private void FrmOrderedSongList_Load(object sender, EventArgs e)
{
//遍历播放类里面的数组
foreach (SongList item in PalyList.song)
{

if (item!=null)
{
ListViewItem lvitem = new ListViewItem(item.SongName1);
string type = item.PlaySong == PalySongState.unplayed ? "未播放" : "已播放";
lvitem.SubItems.Add(type);
this.listView1.Items.Add(lvitem);
}

}
}


在通过ktvUtil类中写两个静态的字段,一个是图片路径,一个是歌曲路径

//定义一个静态变量存放图片路径
public static string FilePath="";
//定义一个静态变量存放歌曲的路径
public static string SongPath = "";


在主界面的lode事件中写图片和歌曲的路径

private void Form1_Load(object sender, EventArgs e)
{
//读取路径表中的图片路径放到filepath上
string sql = "select resource_path from resource_path where resource_id=1";
SqlCommand cmd = new SqlCommand(sql,db.Conection);
db.OpenConnection();
KtvUtil.FilePath = cmd.ExecuteScalar().ToString();
db.CloseConnection();

//读取歌曲的路径
string sql2 = "select resource_path from resource_path where resource_id=2";
SqlCommand cmd2 = new SqlCommand(sql2, db.Conection);
db.OpenConnection();
KtvUtil.SongPath = cmd2.ExecuteScalar().ToString();
db.CloseConnection();

}


然后进入 拼音点歌



代码如下:

/// <summary>
/// 绑定dgv数据
/// </summary>
public void ShowPinYin(string ab)
{
ab = textBox1.Text;
string sql = "select singer_info.singer_name,song_info.song_name,song_url from singer_info,song_info where singer_info.singer_id=song_info.singer_id";
if (ab!=string.Empty)
{
sql = string.Format(sql+" and song_info.song_ab like '{0}%'",ab);
}
sda.SelectCommand = new SqlCommand(sql,db.Conection);
if (ds.Tables["songinfo"]!=null)
{
ds.Tables["songinfo"].Clear();
}
sda.Fill(ds,"songinfo");
DataTable table=ds.Tables["songinfo"];
this.dataGridView1.DataSource = ds.Tables["songinfo"];
//return;

}


/// <summary>
/// 查询按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1!=null)
{
this.ShowPinYin(this.textBox1.Text);
}
else
{
MessageBox.Show("查询内容不可为空,请填写查询信息!","信息提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
ShowPinYin(string.Empty);
}


类型选择:

如图:



代码如下:

public void FrmOrderBySongType_Load(object sender, EventArgs e)
{

int index = 0;
string sql = "select songtype_id,songtype_name,songtype_URL from song_type";
SqlCommand cmd = new SqlCommand(sql, db.Conection);
try
{
db.OpenConnection();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
string path = KtvUtil.FilePath +"\\"+ Convert.ToString(reader["songtype_URL"]);
imageList1.Images.Add(Image.FromFile(path));
ListViewItem lvitem = new ListViewItem();
string typename = Convert.ToString(reader["songtype_name"]);
int typeid = Convert.ToInt32(reader["songtype_id"]);
lvitem.Text = typename;
lvitem.Tag = typeid;
lvitem.ImageIndex = index;
this.listView1.Items.Add(lvitem);
index++;

}
}
reader.Close();
}
catch (Exception ex)
{
MessageBox.Show("系统出错!"+ex.Message);
}
finally {
db.CloseConnection();
}
this.dataGridView1.Visible = false;
}


通过歌曲类型进入到下一层



代码如下:

public void ShowDGV()
{

string sql = "SELECT song_name,singer_name FROM singer_info,song_info WHERE singer_info.singer_id=song_info.singer_id AND songtype_id={0}";
sql = string.Format(sql + " AND songtype_id={0}", Convert.ToInt32(listView1.SelectedItems[0].Tag));
sda.SelectCommand = new SqlCommand(sql, db.Conection);
if (ds.Tables["num"] != null)
{
ds.Tables["num"].Clear();
}
sda.Fill(ds, "num");
this.dataGridView1.DataSource = ds.Tables["num"];

}


字数点歌:

如图



字数点歌用的是动态加载代码如下:

public void FrmOrderByWordCount_Load(object sender, EventArgs e)
{
for (int i = 1; i <= 2; i++)
{
for (int j = 1; j <= 6; j++)
{
Label lbl = new Label();
lbl.Text = "第" + j + "个字";
if (i ==2)
{
lbl.Text = "第" + (j+6) + "个字";
}
//背景颜色
lbl.BackColor = Color.Red;
//字体大小
lbl.Size = new Size(55, 25);
//字体居中
lbl.TextAlign = ContentAlignment.MiddleCenter;
//点击事件
lbl.Click += lbl_Click;
//位置
lbl.Location = new Point(50 + 100 * i, 50 + 40 * j);
this.Controls.Add(lbl);
}
}
//隐藏dgv
this.dataGridView1.Visible = false;
}


显示出歌曲

int mains;
void lbl_Click(object sender, EventArgs e)
{
Label label = (Label)sender;
//文本
string main = label.Text;
//文本的长度
int sum = main.Length;
if (sum == 4)
{
mains = int.Parse(main.Substring(1, 1));
}
else
{
mains = int.Parse(main.Substring(1,2));
}
//MessageBox.Show(mains.ToString());
//释放dgv
this.dataGridView1.Visible = true;

ShowDGV();

}
public void ShowDGV()
{
if (ds.Tables["num"] != null)
{
ds.Tables["num"].Clear();
}
string sql = "select song_info.song_name,singer_info.singer_name,song_info.song_url from song_info,singer_info where song_info.singer_id=singer_info.singer_id ";
sql = string.Format(sql + " and song_info.song_word_count={0}", mains.ToString());
sda.SelectCommand = new SqlCommand(sql,db.Conection);

sda.Fill(ds,"num");
this.dataGridView1.DataSource=ds.Tables["num"];

}


主界面的下方有工具菜单

有播放,有切歌,

切歌代码如下:

/// <summary>
/// 切歌方法
/// </summary>
/// <param name="index"></param>
public static void CutSong(int index)
{
//歌曲的位置
int num;
if (index==-1)
{
num = selectindex;
}
else
{
num = index;
}
song[selectindex].CutState();
while (song[num]!=null)
{
song[num] = song[num + 1];
num++;
if (num==song.Length)
{
song[num] = null;
}
}

}


/// <summary>
/// 切歌
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripButton6_Click(object sender, EventArgs e)
{
if (MessageBox.Show("确定要切歌吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
{
PalyList.CutSong(-1);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: