//当前播放的歌曲
publicSong songname;#region 让窗体实现拖动
public Point mouseOffset; //记录鼠标指针的坐标
public bool isMouseDown = false; //记录鼠标按键是否按下
private void FrmMain_MouseDown(objectsender, MouseEventArgs e)
{intxOffset;intyOffset;if (e.Button ==MouseButtons.Left)
{
xOffset= -e.X -SystemInformation.FrameBorderSize.Width;
yOffset= -e.Y - SystemInformation.CaptionHeight -SystemInformation.FrameBorderSize.Height;
mouseOffset= newPoint(xOffset, yOffset);
isMouseDown= true;
}
}private void FrmMain_MouseMove(objectsender, MouseEventArgs e)
{if(isMouseDown)
{
Point mousePos=Control.MousePosition;
mousePos.Offset(mouseOffset.X+ 5, mouseOffset.Y + 30);
Location=mousePos;
}
}private void FrmMain_MouseUp(objectsender, MouseEventArgs e)
{//修改鼠标状态isMouseDown的值//确保只有鼠标左键按下并移动时,才移动窗体
if (e.Button ==MouseButtons.Left)
{
isMouseDown= false;
}
}#endregion
//点击退出按钮触发的事件
private void btnexit_Click(objectsender, EventArgs e)
{
application.Exit();
}//Login事件
private void FrmMain_Load(objectsender, EventArgs e)
{//把整个窗体对象赋给FrmByValue的静态frM对象
FrmByValue.frM = this;//运行窗体时启动定时器
this.tilist_played.Start();//调用查询返回路径的方法,传入SQL语句//歌曲路径
string sql = "select resource_path from Resource_path where resource_id=1";
KtvHelper.songURL=song_path(sql);//歌手图片路径
string sql1 = "select resource_path from Resource_path where resource_id=2";
KtvHelper.singer_photoURL=song_path(sql1);
}///
///查询返回路径的方法///
/// 传入sql语句
/// 根据传入的sql语句返回不同的路径(1.resource_id=1歌曲路径:resource_id=2歌手图片路径)
private string song_path(stringsql)
{
SqlConnection con= newSqlConnection(SqlHelper.str);
SqlCommand cmd= newSqlCommand(sql, con);string path = "";try{
con.Open();
SqlDataReader dr=cmd.ExecuteReader();if (dr != null)
{if(dr.HasRows)
{while(dr.Read())
{
path= dr["resource_path"].ToString();
}
}
}
}catch(Exception)
{
MessageBox.Show("网络异常!");
}finally{
con.Close();
}returnpath;
}//点击显示播放触发的事件
private void btnshow_Click(objectsender, EventArgs e)
{if (this.Width == 567)
{this.Width = this.Width + 208;
btnshow.Text= "隐 藏 播 放";
}else if (this.Width > 567)
{this.Width = 567;
btnshow.Text= "显 示 播 放";
}
}//已点歌曲窗体
private void btnopen_Click(objectsender, EventArgs e)
{
SelectedSong frm= newSelectedSong();this.Hide();
frm.Show();
}//点击拼音点歌触发的事件
private void btnspell_Click(objectsender, EventArgs e)
{
frmbySongname frm= newfrmbySongname();this.Hide();
frm.Show();
}//点击字数点歌触发的事件
private void btnnum_Click(objectsender, EventArgs e)
{
frmbyziSong frm= newfrmbyziSong();this.Hide();
frm.Show();
}//点击类型点歌触发的事件
private void btntype_Click(objectsender, EventArgs e)
{
frmbyTypesong frm= newfrmbyTypesong();this.Hide();
frm.Show();
}//定时扫描歌曲列表,显示当前播放歌曲的名称
public voidShowPlayingSongName()
{
txtopen.Text=PlayList.PlayingSongName();
txtnext.Text=PlayList.NextSongName();
}//播放歌曲的方法
public voidPlaySong()
{//获取当前要播放的歌曲
this.songname =PlayList.GetPlayingSong();if (songname != null)
{#region 播放时显示歌曲图片
string name =songname.SongName;string sql = "select singer_id from song_info where song_name ='" + name + "'";
SqlConnection con= newSqlConnection(SqlHelper.str);
con.Open();
SqlCommand cmd= newSqlCommand(sql, con);int singerid =Convert.ToInt32(cmd.ExecuteScalar());
con.Close();string sql1 = "select singer_photo from singer_info where singer_id=" + singerid + "";
SqlConnection con1= newSqlConnection(SqlHelper.str);
con1.Open();
SqlCommand cmd1= newSqlCommand(sql1, con1);string singer_photo =cmd1.ExecuteScalar().ToString();
con1.Close();
plist.Image= Image.FromFile(KtvHelper.singer_photoURL +singer_photo);#endregion
//将当前歌曲播放状态设为已播放
this.songname.SetSongPlayed();//得到当前播放歌曲的路径
Playerlist.URL = KtvHelper.songURL +songname.SongURL;
}
}//计时器控件的Tick事件
private void tilist_played_Tick(objectsender, EventArgs e)
{
ShowPlayingSongName();if(this.songname==null)
{this.PlaySong();
}if (this.Playerlist.playState ==WMPLib.WMPPlayState.wmppsStopped)
{this.songname = null;
PlayList.MoveOn();
}if(this.songname!=null&&this.songname.Playseat==SongPlayState.cut)
{this.Playerlist.URL = "";this.songname = null;
}if (this.songname != null && this.songname.Playseat ==SongPlayState.newplayed)
{this.PlaySong();
}
}//点击切歌触发的事件
private void btnnextsong_Click(objectsender, EventArgs e)
{if (this.songname != null)
{
PlayList.CutSong();
}else{
MessageBox.Show("亲!你还没有添加歌曲");
}
}//点击重唱触发的事件
private void btnnew_Click(objectsender, EventArgs e)
{if (this.songname != null)
{
PlayList.PlayAgain();
}else{
MessageBox.Show("亲!你还没有添加歌曲");
}
}//点击金曲排行触发的时间
private void btnorderby_Click(objectsender, EventArgs e)
{
frmsonglist frm= newfrmsonglist();
frm.ph= 1;this.Hide();
frm.Show();
}//歌星点歌
private void btnswan_Click_1(objectsender, EventArgs e)
{
Frmbyswangetsong frm= newFrmbyswangetsong();
frm.Show();this.Hide();
}//当鼠标进入控件可见状态是触发的事件
private void btnswan_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnswan,"歌星点歌");
}private void btnspell_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnspell,"拼音点歌");
}private void btnnum_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnnum,"字数点歌");
}private void btntype_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btntype,"类型选择");
}private void btnorderby_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnorderby,"金曲排行");
}private void btnnew_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnnew,"重唱");
}private void btnnextsong_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnnextsong,"切歌");
}private void btnopen_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnopen,"已点");
}private void btnfw_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnfw,"服务");
}private void btnexit_MouseEnter(objectsender, EventArgs e)
{
ToolTip tp= newToolTip();
tp.ShowAlways= true;
tp.SetToolTip(btnexit,"退出");
}private void btnfw_Click(objectsender, EventArgs e)
{
MessageBox.Show("正在呼叫服务...");
}