MyKTV项目总结

王朝学院·作者佚名  2016-08-28
窄屏简体版  字體: 小  |  中  |  大  |  超大  

项目名称:KTV点歌系统

--指导老师原玉明

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

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

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

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

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

首先先看前台:

前台核心类:

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

//连接字符串publicstaticstringstr ="Data Source=HYJ-PC;Initial Catalog=MyKTV;User ID=sa;pwd=123";

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

//保存歌曲的目录publicstaticstringsongURL ="";//保存歌手图片的目录publicstaticstringsinger_photoURL ="";

FrmByValue类(窗体对象之间的传值)publicstaticfrmsonglist frmsl;publicstaticFrmMain frM;publicstaticSelectedSong ss;

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

[flash=500,400]http://s1.knowsky.com/20160211/j1pqgepggv501.png[/flash]

//定义一个枚举:歌曲播放状态publicenumSongPlayState

{

unplayed, played, newplayed, cut

}publicclassSong

{publicstringSongName

{get{returnsongName; }set{ songName =value; }

}publicstringSongURL

{get{returnsongURL; }set{ songURL =value; }

}internalSongPlayState Playseat

{get{returnplayseat; }set{ playseat =value; }

}PRivatestringsongName;//歌曲名称字段privatestringsongURL;//歌曲存放路径字段//让歌曲的播放状态默认为未播放;privateSongPlayState playseat =SongPlayState.unplayed;//把歌曲状态改为已播放publicvoidSetSongPlayed()

{this.playseat =SongPlayState.played;

}//把歌曲状态改为重唱publicvoidSetnewSong()

{this.playseat =SongPlayState.newplayed;

}//把歌曲状态改为一切歌publicvoidSetcut()

{this.playseat =SongPlayState.cut;

}

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

[flash=500,400]http://s1.knowsky.com/20160211/u34vomvhh1m01.png[/flash]

publicclassPlayList

{//定义一个数组,默认可以储存50首歌publicstaticSong[] songList=newSong[50];//歌曲播放列表数组publicstaticintsongIndex;//当前播放的歌曲在数组的索引#region添加播放歌曲publicstaticboolAddSong(Song song)

{boolhappy =false;for(inti =0; i < songList.Length; i++)

{if(songList[i] ==null)

{

songList[i]=song;

happy=true;

break;

}

}returnhappy;

}#endregion#region当前播放的歌曲名称publicstaticstringPlayingSongName()

{stringsongName ="";//歌曲名称if(songList.Length>songIndex)

{if(songList[songIndex] !=null)

{

songName=songList[songIndex].SongName;

}

}returnsongName;

}#endregion#region获取当前播放的歌曲publicstaticSong GetPlayingSong()

{if(songIndex<songList.Length)

{if(songList[songIndex] !=null)

{returnsongList[songIndex];

}else{returnnull;

}

}returnnull;

}#endregion#region下一首要播放的歌曲名称publicstaticstringNextSongName()

{stringsongName ="";//歌曲名称if(songIndex<songList.Length)

{if(songList.Length > songIndex +1)

{if(songList[songIndex +1] !=null)

{

songName= songList[songIndex +1].SongName;

}

}

}returnsongName;

}#endregion#region切歌:publicstaticvoidCutSong()

{//代表切歌的位置inti =songIndex;if(songList[i]!=null)

{

songList[i].Setcut();

}while(songList[i] !=null)

{

songList[i]= songList[i +1];

i++;//如果到达数组最后一个元素,就将最后一个元素指向空if(i ==songList.Length)

{

songList[i]=null;

}

}if(songList[0] !=null)

{

songList[0].Playseat =SongPlayState.played;

}

}#endregion#region重放当前歌曲publicstaticvoidPlayAgain()

{if(songList[songIndex] !=null)

{

songList[songIndex].SetnewSong();

}

}#endregion#region播放下一首publicstaticvoidMoveOn()

{if(songIndex<songList.Length)

{if(songList[songIndex] !=null&& songList[songIndex].Playseat ==SongPlayState.newplayed)

{

songList[songIndex].SetSongPlayed();

}else{

songIndex++;

}

}

}#endregion}

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

#region让窗体实现拖动publicPoint mouSEOffset;//记录鼠标指针的坐标publicboolisMouseDown =false;//记录鼠标按键是否按下privatevoidFrmMain_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;

}

}privatevoidFrmMain_MouseMove(objectsender, MouseEventArgs e)

{if(isMouseDown)

{

Point mousePos=Control.MousePosition;

mousePos.Offset(mouseOffset.X+5, mouseOffset.Y +30);

Location=mousePos;

}

}privatevoidFrmMain_MouseUp(objectsender, MouseEventArgs e)

{//修改鼠标状态isMouseDown的值//确保只有鼠标左键按下并移动时,才移动窗体if(e.Button ==MouseButtons.Left)

{

isMouseDown=false;

}

}#endregion

主界面:(FrmMain)

[flash=500,400]http://s1.knowsky.com/20160211/uyrzdkltjm401.png[/flash]

//当前播放的歌曲publicSong songname;#region让窗体实现拖动publicPoint mouseOffset;//记录鼠标指针的坐标publicboolisMouseDown =false;//记录鼠标按键是否按下privatevoidFrmMain_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;

}

}privatevoidFrmMain_MouseMove(objectsender, MouseEventArgs e)

{if(isMouseDown)

{

Point mousePos=Control.MousePosition;

mousePos.Offset(mouseOffset.X+5, mouseOffset.Y +30);

Location=mousePos;

}

}privatevoidFrmMain_MouseUp(objectsender, MouseEventArgs e)

{//修改鼠标状态isMouseDown的值//确保只有鼠标左键按下并移动时,才移动窗体if(e.Button ==MouseButtons.Left)

{

isMouseDown=false;

}

}#endregion//点击退出按钮触发的事件privatevoidbtnexit_Click(objectsender, EventArgs e)

{application.Exit();

}//Login事件privatevoidFrmMain_Load(objectsender, EventArgs e)

{//把整个窗体对象赋给FrmByValue的静态frM对象FrmByValue.frM =this;//运行窗体时启动定时器this.tilist_played.Start();//调用查询返回路径的方法,传入SQL语句//歌曲路径stringsql ="select resource_path from Resource_path where resource_id=1";

KtvHelper.songURL=song_path(sql);//歌手图片路径stringsql1 ="select resource_path from Resource_path where resource_id=2";

KtvHelper.singer_photoURL=song_path(sql1);

}///<summary>///查询返回路径的方法///</summary>///<param name="sql">传入sql语句</param>///<returns>根据传入的sql语句返回不同的路径(1.resource_id=1歌曲路径:resource_id=2歌手图片路径)</returns>privatestringsong_path(stringsql)

{

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlCommand cmd=newSqlCommand(sql, con);stringpath ="";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;

}//点击显示播放触发的事件privatevoidbtnshow_Click(objectsender, EventArgs e)

{if(this.Width ==567)

{this.Width =this.Width +208;

btnshow.Text="隐 藏 播 放";

}elseif(this.Width >567)

{this.Width =567;

btnshow.Text="显 示 播 放";

}

}//已点歌曲窗体privatevoidbtnopen_Click(objectsender, EventArgs e)

{

SelectedSong frm=newSelectedSong();this.Hide();

frm.Show();

}//点击拼音点歌触发的事件privatevoidbtnspell_Click(objectsender, EventArgs e)

{

frmbySongname frm=newfrmbySongname();this.Hide();

frm.Show();

}//点击字数点歌触发的事件privatevoidbtnnum_Click(objectsender, EventArgs e)

{

frmbyziSong frm=newfrmbyziSong();this.Hide();

frm.Show();

}//点击类型点歌触发的事件privatevoidbtntype_Click(objectsender, EventArgs e)

{

frmbyTypesong frm=newfrmbyTypesong();this.Hide();

frm.Show();

}//定时扫描歌曲列表,显示当前播放歌曲的名称publicvoidShowPlayingSongName()

{

txtopen.Text=PlayList.PlayingSongName();

txtnext.Text=PlayList.NextSongName();

}//播放歌曲的方法publicvoidPlaySong()

{//获取当前要播放的歌曲this.songname =PlayList.GetPlayingSong();if(songname !=null)

{#region播放时显示歌曲图片stringname =songname.SongName;stringsql ="select singer_id from song_info where song_name ='"+ name +"'";

SqlConnection con=newSqlConnection(SqlHelper.str);

con.Open();

SqlCommand cmd=newSqlCommand(sql, con);intsingerid =Convert.ToInt32(cmd.ExecuteScalar());

con.Close();stringsql1 ="select singer_photo from singer_info where singer_id="+ singerid +"";

SqlConnection con1=newSqlConnection(SqlHelper.str);

con1.Open();

SqlCommand cmd1=newSqlCommand(sql1, con1);stringsinger_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事件privatevoidtilist_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();

}

}//点击切歌触发的事件privatevoidbtnnextsong_Click(objectsender, EventArgs e)

{if(this.songname !=null)

{

PlayList.CutSong();

}else{

MessageBox.Show("亲!你还没有添加歌曲");

}

}//点击重唱触发的事件privatevoidbtnnew_Click(objectsender, EventArgs e)

{if(this.songname !=null)

{

PlayList.PlayAgain();

}else{

MessageBox.Show("亲!你还没有添加歌曲");

}

}//点击金曲排行触发的时间privatevoidbtnorderby_Click(objectsender, EventArgs e)

{

frmsonglist frm=newfrmsonglist();

frm.ph=1;this.Hide();

frm.Show();

}//歌星点歌privatevoidbtnswan_Click_1(objectsender, EventArgs e)

{

Frmbyswangetsong frm=newFrmbyswangetsong();

frm.Show();this.Hide();

}//当鼠标进入控件可见状态是触发的事件privatevoidbtnswan_MouseEnter(objectsender, EventArgs e)

{

ToolTiptp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnswan,"歌星点歌");

}privatevoidbtnspell_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnspell,"拼音点歌");

}privatevoidbtnnum_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnum,"字数点歌");

}privatevoidbtntype_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btntype,"类型选择");

}privatevoidbtnorderby_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnorderby,"金曲排行");

}privatevoidbtnnew_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnew,"重唱");

}privatevoidbtnnextsong_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnextsong,"切歌");

}privatevoidbtnopen_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnopen,"已点");

}privatevoidbtnfw_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnfw,"服务");

}privatevoidbtnexit_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnexit,"退出");

}privatevoidbtnfw_Click(objectsender, EventArgs e)

{

MessageBox.Show("正在呼叫服务...");

}

歌星点歌(Frmbyswangetsong):

[flash=500,400]http://s1.knowsky.com/20160211/3svmqz0yhq101.png[/flash]

//图片索引publicintindex=0;publicintindex_singer =0;//Load事件privatevoidFrmbyswangetsong_Load(objectsender, EventArgs e)

{//在显示当前窗体时,让第二个lvlisttwo和第三个lvlistthere控件不显示lvlisttwo.Visible =false;

lvlistthere.Visible=false;#region给第一个listview绑定数据//给listview1绑定数据和图片ListViewItem lv =newListViewItem("组合",0);

lv.Tag="组合";

ListViewItem lv1=newListViewItem("女歌手",1);

lv1.Tag="女";

ListViewItem lv2=newListViewItem("男歌手",2);

lv2.Tag="男";

lvlistone.Items.Add(lv);

lvlistone.Items.Add(lv1);

lvlistone.Items.Add(lv2);#endregion}//点击lvlistone中项时触发的事件privatevoidlvlistone_Click(objectsender, EventArgs e)

{//如果没有选中lvlistone控件中的任何一项是不会显示第二个窗体//让第二个出现的lvlisttwo和lvlistone显示在同一个位置lvlisttwo.Location =lvlistone.Location;//如果选中一项,就把第二个llvlisttwo显示出来//让第二个lvlisttwo显示lvlisttwo.Visible =true;if(lvlistone.SelectedItems[0] !=null)

{//给第二个listview控件动态绑定数据的方法lvlisttwoadd();

}

}//给第二个listview控件动态绑定数据的方法lvlisttwoadd();privatevoidlvlisttwoadd()

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select * from singer_type";

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();

SqlDataReader dr=cmd.ExecuteReader();if(dr !=null)

{if(dr.HasRows)

{while(dr.Read())

{stringsingertype_group = dr["singertype_name"].ToString();intid = Convert.ToInt32(dr["singertype_id"]);

ListViewItem lv=newListViewItem();

lv.ImageIndex= index++;

lv.Text=singertype_group;

lv.Tag=id;//MessageBox.Show(lvlisttwo.Tag.ToString());lvlisttwo.Items.Add(lv);

}

}

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//03点击lvlisttwo中项时触发的事件privatevoidlvlisttwo_Click(objectsender, EventArgs e)

{

lvlistthere.Items.Clear();//如果没有选中lvlisttwo控件中的任何一项是不会显示第三个窗体//如果选中一项,就把第二个llvlistthere显示出来if(lvlisttwo.SelectedItems[0] !=null)

{

lvlisttwo.Visible=false;//让第三个出现的lvlistthere和lvlistone显示在同一个位置lvlistthere.Location =lvlistone.Location;//让第三个lvlistthere显示lvlistthere.Visible =true;//获取用户点击第一个listview是男歌手还是女歌手或者是组合stringsinger_group = lvlistone.SelectedItems[0].Tag.ToString();//获取用户点击点击第二个listview是哪个地区的idintcityid = Convert.ToInt32(lvlisttwo.SelectedItems[0].Tag);

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select singer_name,singer_photo from singer_info where singer_sex ='"+ singer_group +"' and singertype_id="+cityid+"";

SqlCommand cmd=newSqlCommand(sql,con);try{

con.Open();

SqlDataReader dr=cmd.ExecuteReader();if(dr!=null)

{if(dr.HasRows)

{while(dr.Read())

{//获取到歌手姓名和歌手图片路径stringsinger_name = dr["singer_name"].ToString();stringsinger_photo_url = dr["singer_photo"].ToString();//并接路径stringURL = KtvHelper.singer_photoURL +singer_photo_url;

imgsingerinfo .Images.Add(Image.FromFile(URL));

ListViewItem lv=newListViewItem();

lv.Text=singer_name;

lv.ImageIndex=index_singer++;

lvlistthere.Items.Add(lv);

}

}

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}

}//点击按钮主界面触发的事件privatevoidbtnmain_Click(objectsender, EventArgs e)

{

FrmByValue.frM.Show();this.Close();

}//点击返回触发的事件privatevoidbtnreturn_Click(objectsender, EventArgs e)

{if(lvlistthere.Visible ==true)

{

lvlistthere.Visible=false;

lvlisttwo.Visible=true;

}elseif(lvlisttwo.Visible ==true)

{

lvlisttwo.Visible=false;

lvlistone.Visible=true;

}else{

FrmByValue.frM.Show();this.Close();

}

}//点击歌手图片触发的事件privatevoidlvlistthere_Click(objectsender, EventArgs e)

{

frmsonglist frm=newfrmsonglist();//通过窗体传值把歌手姓名赋给frmsonglist窗体的singer_name变量frm.singer_name= lvlistthere.SelectedItems[0].Text;

frm.Show();this.Close();

}//点击已点触发的事件privatevoidbtnopen_Click(objectsender, EventArgs e)

{

SelectedSong frm=newSelectedSong();

frm.Show();this.Close();

}//点击切歌触发的事件privatevoidbtnnextsong_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.CutSong();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}//点击重唱触发的事件privatevoidbtnnew_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.PlayAgain();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}privatevoidlabllist_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(labllist,"歌星点歌");

}privatevoidbtnmain_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnmain,"主界面");

}privatevoidbtnnew_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnew,"重唱");

}privatevoidbtnnextsong_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnextsong,"切歌");

}privatevoidbtnopen_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnopen,"已点");

}privatevoidbtnfw_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnfw,"服务");

}privatevoidbtnreturn_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnreturn,"返回");

}privatevoidbtnfw_Click(objectsender, EventArgs e)

{

MessageBox.Show("正在呼叫服务...");

}

拼音点歌(frmbySongname):

[flash=500,400]http://s1.knowsky.com/20160211/yr0xb4xnvop01.png[/flash]

//login事件privatevoidfrmbySongname_Load(objectsender, EventArgs e)

{stringRowFilter ="";

dgvlistgetzhi( RowFilter);

}privatevoiddgvlistgetzhi(stringRowFilter)

{//取消英文列自动生成dgvlist.AutoGenerateColumns =false;

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select song_id,song_name,singer_name,song_url,song_ab from song_info,singer_info where song_info.singer_id=singer_info.singer_id";

SqlDataAdapter da=newSqlDataAdapter(sql, con);

DataSet ds=newDataSet();try{

da.Fill(ds,"info");

DataView dv=newDataView(ds.Tables["info"]);

dv.RowFilter=RowFilter;

dgvlist.DataSource=dv;

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//点击按钮查询触发的事件privatevoidbtnselect_Click(objectsender, EventArgs e)

{stringRowFilter ="song_ab like '%"+ txtlist.Text +"%' or song_name like '%"+ txtlist.Text +"%'";

dgvlistgetzhi(RowFilter);

}///点击单元格触发的事件privatevoiddgvlist_CellClick(objectsender, DataGridViewCellEventArgs e)

{if(dgvlist.SelectedRows[0].Cells[0].Value.ToString() !="")

{

Song so=newSong();stringsong_name = dgvlist.SelectedRows[0].Cells["song_name"].Value.ToString();stringsong_url = dgvlist.SelectedRows[0].Cells["song_url"].Value.ToString();

so.SongName=song_name;

so.SongURL=song_url;boolresult =PlayList.AddSong(so);if(result ==true)

{

MessageBox.Show("添加成功!");intsongid = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["song_Id"].Value);

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="update song_info set song_play_count=song_play_count+1 where song_id='"+ songid +"'";try{

con.Open();

SqlCommand cmd=newSqlCommand(sql, con);intcount =cmd.ExecuteNonQuery();

}catch(Exception)

{

MessageBox.Show("失败");

}finally{

con.Close();

}

}else{

MessageBox.Show("添加失败!");

}

}else{

MessageBox.Show("请选择一首歌");

}

}//点击已点触发的事件privatevoidbutton1_Click(objectsender, EventArgs e)

{

SelectedSong frm=newSelectedSong();

frm.Show();this.Close();

}//点击切歌触发的事件privatevoidbutton2_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.CutSong();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}//点击重唱触发的事件privatevoidbutton5_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.PlayAgain();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}privatevoidbutton3_Click(objectsender, EventArgs e)

{

FrmByValue.frM.Show();this.Close();

}privatevoidlabel2_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(label2,"拼音点歌");

}privatevoidbutton3_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button3,"主界面");

}privatevoidbutton5_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button5,"重唱");

}privatevoidbutton2_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button2,"切歌");

}privatevoidbutton1_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button1,"已点");

}privatevoidbutton6_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button6,"服务");

}privatevoidbutton6_Click(objectsender, EventArgs e)

{

MessageBox.Show("正在呼叫服务....");

}privatevoidbtnselect_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnselect,"查询");

}

字数点歌(frmbyziSong):

[flash=500,400]http://s1.knowsky.com/20160211/t2adf0knrq401.png[/flash]

//login事件privatevoidfrmbyziSong_Load(objectsender, EventArgs e)

{//将字数列表添加到窗体中for(inti =0; i <12; i++)

{//循环生成字数项添加到窗体中ListViewItem item =newListViewItem();

item.Text= (i +1) +"个字";

item.Tag= i +1;

lvlist.Items.Add(item);

}

}//单击listview组件触发的事件privatevoidlvlist_Click(objectsender, EventArgs e)

{//获取每一个item.Tag对应的值intcount= Convert.ToInt32(lvlist.SelectedItems[0].Tag);

frmsonglist frm=newfrmsonglist();

frm.count=count;

frm.Show();this.Close();

}//点击主界面触发的事件privatevoidbutton3_Click(objectsender, EventArgs e)

{

FrmByValue.frM.Show();this.Close();

}//点击已点触发的事件privatevoidbutton1_Click(objectsender, EventArgs e)

{

SelectedSong frm=newSelectedSong();

frm.Show();

}privatevoidbutton2_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.CutSong();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}privatevoidbutton5_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.PlayAgain();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}privatevoidlabel2_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(label2,"字数点歌");

}privatevoidbutton3_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button3,"主界面");

}privatevoidbutton5_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button5,"重唱");

}privatevoidbutton2_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button2,"切歌");

}privatevoidbutton1_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button1,"已点");

}privatevoidbutton6_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button6,"服务");

}privatevoidbutton6_Click(objectsender, EventArgs e)

{

MessageBox.Show("正在呼叫服务...");

}

类型选择(frmbyTypesong):

[flash=500,400]http://s1.knowsky.com/20160211/rtyim1bhwxv01.png[/flash]

//定义一个变量index,表示imagelistintindex =0;//login事件privatevoidfrmbyTypesong_Load(objectsender, EventArgs e)

{//给listview控件绑定值lvlistgetzhi();

}//给listview控件绑定值privatevoidlvlistgetzhi()

{//读取歌曲类别SqlConnection con =newSqlConnection(SqlHelper.str);stringsql ="select * from song_type";

SqlCommand cmd=newSqlCommand(sql, con);try{//查询数据库con.Open();

SqlDataReader dr=cmd.ExecuteReader();//循环将类别读取出来添加到ListView中lvlist.Items.Clear();if(dr!=null)

{if(dr.HasRows)

{while(dr.Read())

{

ListViewItem item=newListViewItem();

item.Text= Convert.ToString(dr["songtype_name"]);

item.Tag= Convert.ToInt32(dr["songtype_id"]);

item.ImageIndex= index++;

lvlist.Items.Add(item);

}

}

}

dr.Close();

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//点击listview控件中组件触发的事件privatevoidlvlist_Click(objectsender, EventArgs e)

{//获取选中的歌曲隐藏的Tag值intTagid = Convert.ToInt32(lvlist.SelectedItems[0].Tag);//new出歌曲列表窗体对象frmsonglist frm =newfrmsonglist();//把获取的歌曲隐藏值Tag赋给frmsonglist窗体的公有变量Tagidfrm.Tagid =Tagid;

frm.Show();this.Close();

}//点击已点触发的事件privatevoidbutton7_Click(objectsender, EventArgs e)

{

SelectedSong frm=newSelectedSong();

frm.Show();this.Close();

}//点击重唱触发的事件privatevoidbutton11_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.PlayAgain();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}//点击切歌触发的事件privatevoidbutton8_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.CutSong();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}//点击主界面触发的事件privatevoidbutton9_Click(objectsender, EventArgs e)

{

FrmByValue.frM.Show();this.Close();

}privatevoidlabel2_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(label2,"分类点歌");

}privatevoidbutton9_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button9,"主界面");

}privatevoidbutton11_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button11,"重唱");

}privatevoidbutton8_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button8,"切歌");

}privatevoidbutton7_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button7,"已点");

}privatevoidbutton12_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(button12,"服务");

}privatevoidbutton12_Click(objectsender, EventArgs e)

{

MessageBox.Show("正在呼叫服务...");

}

金曲排行(frmsonglist公用窗体):

[flash=500,400]http://s1.knowsky.com/20160211/qkpdrajahkb01.png[/flash]

//接收金曲排行传过来的值publicintph;publicintTagid;//接收窗体传过来的歌手姓名publicstringsinger_name;publicstringname ="";//并接的歌曲完整路径publicstringURL1;//获取歌曲名//public string singer_name = "";//获取歌曲演唱者publicstringsong_name ="";publicintindex =0;publicintcount =0;//Login事件privatevoidfrmsonglist_Load(objectsender, EventArgs e)

{//FrmByValue.frmsl = this;//给listview控件绑定值if(Tagid !=0)

{stringsql ="select song_name,singer_name,song_url,song_id from singer_info,song_info where singer_info.singer_id=song_info.singer_id and songtype_id="+ Tagid +"";

lvlistgetzhi(sql);

}elseif(count!=0)

{stringsql ="select song_name,singer_name,song_url,song_id from singer_info,song_info where singer_info.singer_id=song_info.singer_id and song_Word_count="+count+"";

lvlistgetzhi(sql);

}elseif(ph!=0)

{stringsql ="select song_name,singer_name,song_url,song_id from singer_info,song_info where singer_info.singer_id=song_info.singer_id order by song_play_count desc";

lvlistgetzhi(sql);

}else{stringsql ="select song_id,song_name,singer_name,song_url from singer_info,song_info where singer_info.singer_id=song_info.singer_id and singer_name='"+ singer_name +"'";

lvlistgetzhi(sql);

}

}//给listview控件绑定值的方法lvlistgetzhi(string sql)传入SQL语句publicvoidlvlistgetzhi(stringsql)

{

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlDataAdapter da=newSqlDataAdapter(sql, con);

DataSet ds=newDataSet();try{

da.Fill(ds,"info");

dgvlist.DataSource= ds.Tables["info"];

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//点击主界面触发的事件privatevoidbtnmain_Click(objectsender, EventArgs e)

{

FrmByValue.frM.Show();this.Close();

}//点击dgvlsit单元格触发的事件privatevoiddgvlist_CellClick_1(objectsender, DataGridViewCellEventArgs e)

{//点选中行不为空时把歌曲信息添加到Song类的歌曲名称和歌曲路径属性中if(dgvlist.SelectedRows[0].Cells[0].Value.ToString()!="")

{//获取歌曲路径stringsongpath = dgvlist.SelectedRows[0].Cells["song_url"].Value.ToString();//获取歌曲名stringsong_name = dgvlist.SelectedRows[0].Cells["songname"].Value.ToString();

Song so=newSong();

so.SongName=song_name;

so.SongURL=songpath;boolresult =PlayList.AddSong(so);if(result ==true)

{

MessageBox.Show("添加成功!");

}else{

MessageBox.Show("添加失败!");

}//更新数据库,将选中的歌曲点播次数加1update_count();

}else{

MessageBox.Show("请选择一首歌");

}

}//更新数据库,将选中的歌曲点播次数加1的方法privatevoidupdate_count()

{intsongid = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["song_Id"].Value);

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="update song_info set song_play_count=song_play_count+1 where song_id='"+ songid +"'";try{

con.Open();

SqlCommand cmd=newSqlCommand(sql, con);intcount =cmd.ExecuteNonQuery();

}catch(Exception)

{

MessageBox.Show("失败");

}finally{

con.Close();

}

}//点击已点触发的事件privatevoidbtnopen_Click(objectsender, EventArgs e)

{

SelectedSong frm=newSelectedSong();this.Close();

frm.Show();

}//点击切歌触发的事件privatevoidbtnnextsong_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.CutSong();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}//点击重唱触发的事件privatevoidbtnnew_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.PlayAgain();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}privatevoiddgvlist_CellContentClick(objectsender, DataGridViewCellEventArgs e)

{

}privatevoidlabel2_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(label2,"歌曲列表");

}privatevoidbtnmain_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnmain,"主界面");

}privatevoidbtnnew_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnew,"重唱");

}privatevoidbtnnextsong_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnextsong,"切歌");

}privatevoidbtnopen_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnopen,"已点");

}privatevoidbtnfw_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnfw,"服务");

}privatevoidbtnfw_Click(objectsender, EventArgs e)

{

MessageBox.Show("正在呼叫服务...");

}

}

已点列表(SelectedSong):

[flash=500,400]http://s1.knowsky.com/20160211/vz1twf5gzzv01.png[/flash]

//login事件privatevoidSelectedSong_Load(objectsender, EventArgs e)

{

FrmByValue.ss=this;//给一点列表绑定值getselectsongzhi();

}publicvoidgetselectsongzhi()

{

lvlist.Items.Clear();//清空原列表//定义一个数组长度为50的对象数组Song[] so =newSong[50];

so=PlayList.songList;//用foreacher循环出对象数组里的歌曲信息foreach(Song iteminso)

{if(item !=null)

{//遍历出歌曲名stringsong_name =item.SongName;//遍历出歌曲路径stringsong_url =item.SongURL;//遍历出播放状态//对于这行代码的理解 string type = item.Playseat == SongPlayState.unplayed ? "未播放" : "已播放";//<<item.Playseat>>如果他保存的是 SongPlayState.unplayed 那么(tem.Playseat == SongPlayState.unplayed)==true,就会把未播放的值赋给type变量//<<item.Playseat>>如果他保存的是 不是SongPlayState.unplayed 是枚举类型的其他值那么(tem.Playseat == SongPlayState.unplayed)==false,就会把已播放的值赋给type变量stringtype = item.Playseat == SongPlayState.unplayed ?"未播放":"已播放";//给lvlist绑定值ListViewItem lv =newListViewItem(song_name);

lv.SubItems.Add(type);

lvlist.Items.Add(lv);

}

}

}//点击切歌触发的事件privatevoidbtnnextsong_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.CutSong();

getselectsongzhi();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}//点击重唱触发的事件privatevoidbtnnew_Click(objectsender, EventArgs e)

{if(FrmByValue.frM.songname !=null)

{

PlayList.PlayAgain();

}else{

MessageBox.Show("亲!还没有歌曲");

}

}//点击主界面触发的事件privatevoidbtnmain_Click(objectsender, EventArgs e)

{

FrmByValue.frM.Show();this.Close();

}privatevoidlabel2_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(label2,"已点列表");

}privatevoidbtnmain_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnmain,"主界面");

}privatevoidbtnnew_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnew,"重唱");

}privatevoidbtnnextsong_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnnextsong,"切歌");

}privatevoidbtnfw_MouseEnter(objectsender, EventArgs e)

{

ToolTip tp=newToolTip();

tp.ShowAlways=true;

tp.SetToolTip(btnfw,"服务");

}privatevoidbtnfw_Click(objectsender, EventArgs e)

{

MessageBox.Show("正在呼叫服务...");

}

后台:

核心类:

Hanzitopinyin类(汉字转拼音)

{

"A阿啊锕嗄厑哎哀唉埃挨溾锿鎄啀捱皑凒溰嘊敳皚癌毐昹嗳矮蔼躷噯藹譪霭靄艾伌爱砹硋隘嗌塧嫒愛碍暧瑷僾壒嬡懓薆曖璦鴱皧瞹馤鑀鱫安侒峖桉氨庵谙萻腤鹌蓭誝鞌鞍盦馣鮟盫韽啽雸垵", //此处有省略}

///<summary>///获得一个字符串的汉语拼音码///</summary>///<param name="strText">字符串</param>///<returns>汉语拼音码,该字符串只包含大写的英文字母</returns>publicstaticstringGetChineseSpell(stringstrText)

{if(strText ==null|| strText.Length ==0)returnstrText;

System.Text.StringBuilder myStr=newSystem.Text.StringBuilder();foreach(charvCharinstrText)

{//若是字母则直接输出if((vChar >='a'&& vChar <='z') || (vChar >='A'&& vChar <='Z'))

myStr.Append(char.ToUpper(vChar));elseif((int)vChar >=19968&& (int)vChar <=40869)

{//若字符Unicode编码在编码范围则 查汉字列表进行转换输出foreach(stringstrListinstrChineseCharList)

{if(strList.IndexOf(vChar) >0)

{

myStr.Append(strList[0]);

break;

}

}

}

}returnmyStr.ToString();

}//GetChineseSpell

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

//连接字符串publicstaticstringstr ="Data Source=HYJ-PC;Initial Catalog=MyKTV;User ID=sa;pwd=123";

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

//保存歌曲的目录publicstaticstringsongURL ="";//保存歌手图片的目录publicstaticstringsinger_photoURL ="";

登录界面(frnAdmin):

[flash=500,400]http://s1.knowsky.com/20160211/0poywzwlxhx01.png[/flash]

privatevoidbtnlogin_Click(objectsender, EventArgs e)

{//登录Login();

}//登录的方法publicvoidLogin()

{//获取用户名stringloginname =txtname.Text;//获取密码stringpwd =txtpassword.Text;

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select * from admin_info where admin_name='"+ loginname +"' and admin_pwd='"+ pwd +"'";

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();intcount =Convert.ToInt32(cmd.ExecuteScalar());if(count >0)

{

MessageBox.Show("登录成功!");this.Hide();

frmMain frm=newfrmMain();

frm.Show();

}else{

MessageBox.Show("登录失败!");

}

}catch(Exception)

{

MessageBox.Show("网路异常!");

}finally{

con.Close();

}

}privatevoidbtnexit_Click(objectsender, EventArgs e)

{

Application.Exit();

}

主界面(frmMain):

[flash=500,400]http://s1.knowsky.com/20160211/rt34yomedbt01.png[/flash]

privatevoid编辑歌手信息ToolStripMenuItem_Click(objectsender, EventArgs e)

{

AddSingerInfo frm=newAddSingerInfo();

frm.MdiParent=this;

frm.Show();

}privatevoid歌手查询ToolStripMenuItem_Click(objectsender, EventArgs e)

{

frmsingerselect frm=newfrmsingerselect();

frm.MdiParent=this;

frm.Show();

}//点击编辑歌曲信息触发的事件privatevoid编辑歌曲信息ToolStripMenuItem_Click(objectsender, EventArgs e)

{

AddSongInfo frm=newAddSongInfo();

frm.MdiParent=this;

frm.Show();

}privatevoid歌曲查询ToolStripMenuItem_Click(objectsender, EventArgs e)

{

frmsongselect frm=newfrmsongselect();

frm.MdiParent=this;

frm.Show();

}privatevoidfrmMain_Load(objectsender, EventArgs e)

{//调用查询返回路径的方法,传入SQL语句//歌曲路径stringsql ="select resource_path from Resource_path where resource_id=1";

KTVUtil.songURL=song_path(sql);//歌手图片路径stringsql1 ="select resource_path from Resource_path where resource_id=2";

KTVUtil.singer_photoURL=song_path(sql1);

}///<summary>///查询返回路径的方法///</summary>///<param name="sql">传入sql语句</param>///<returns>根据传入的sql语句返回不同的路径(1.resource_id=1歌曲路径:resource_id=2歌手图片路径)</returns>privatestringsong_path(stringsql)

{

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlCommand cmd=newSqlCommand(sql, con);stringpath ="";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;

}//修改歌曲路径privatevoid设置歌曲路径ToolStripMenuItem_Click(objectsender, EventArgs e)

{

frmsongurl frm=newfrmsongurl();

frm.MdiParent=this;

frm.Show();

}privatevoid修改歌手图片路径ToolStripMenuItem_Click(objectsender, EventArgs e)

{

frmsingerphotourl frm=newfrmsingerphotourl();

frm.MdiParent=this;

frm.Show();

}//退出privatevoid退出ToolStripMenuItem_Click(objectsender, EventArgs e)

{

Application.Exit();

}privatevoidfrmMain_FormClosing(objectsender, FormClosingEventArgs e)

{

Application.Exit();

}

新增歌手(FrmAddSingerinfo):

[flash=500,400]http://s1.knowsky.com/20160211/hh4el1ck0d202.png[/flash]

//相对路径publicstringtxtFileName;//绝对路径publicstringtxtPath;//用来接受窗体传过来的值//歌手编号publicintsinger_id;//点击浏览触发的时间privatevoidbtnll_Click(objectsender, EventArgs e)

{//Fiter属性的构成:Excel文件|*.xls,Exce是一个可读的自定义字符串;|*.xls筛选器//试用*表示匹配文件名的字符使用.后缀匹配文件的后缀名,使用;来将需要的后缀分开通过|连接不同的筛选器表示通过用户选择后缀名来进行文件筛选openFileDialog1.Filter="图片文件|*.jpg;*.png;*.gif;";//01.openFileDialog1.Filter="图片文件|*.jpg;*.png;*.gif";//02.openFileDialog1.Filter = "(*.jpg,*.gif,*.png;)|*.jpg;*.gif;*.png;";DialogResult result =openFileDialog1.ShowDialog();if(result == DialogResult.OK)//证明用户双击(选中了)一个文件,我就获取路径{//相对路径txtFileName =openFileDialog1.SafeFileName;//绝对路径txtPath =openFileDialog1.FileName;

pblist.Image=Image.FromFile(txtPath);

}

}//点击添加触发的事件privatevoidbtnok_Click(objectsender, EventArgs e)

{if(infoisnull())

{if(singer_id !=0)

{//执行修改歌手信息的方法Updatesingerinfo();

}else{//添加歌手信息的方法Addsingerinfo();

}

}

}//执行修改歌手信息的方法publicvoidUpdatesingerinfo()

{//获取添加的歌手姓名stringsinger_name =txtname.Text;//获取添加歌手的性别信息stringgender;if(rbboy.Checked ==true)

{

gender="男";

}elseif(rbgerey.Checked ==true)

{

gender="女";

}else{

gender="组合";

}//获取歌手类型的隐藏值intstype_id =Convert.ToInt32(cbolist.SelectedValue);//获取歌手描述的信息stringsinger_ms =txtms.Text;//SqlConnection con =newSqlConnection(SqlHelper.str);stringsql ="update singer_info set singer_name='"+ singer_name +"',singer_sex='"+ gender +"',singertype_id="+ stype_id +",singer_describe='"+ singer_ms +"',singer_photo='"+ txtFileName +"' where singer_id="+ singer_id +"";

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();intcount =cmd.ExecuteNonQuery();if(count >0)

{

MessageBox.Show("修改成功!");if(txtPath !=null)

{if(txtPath != KTVUtil.singer_photoURL +txtFileName)

{

File.Copy(txtPath, KTVUtil.singer_photoURL+ txtFileName,true);

}

}

}else{

MessageBox.Show("修改失败!");

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//load事件privatevoidAddSingerInfo_Load(objectsender, EventArgs e)

{//给歌手类型下拉框绑定数据getcbolistzhi();if(singer_id !=0)

{this.Text ="修改歌手信息";

btnok.Text="修改";

updatagetzhi();

}else{this.Text ="编辑歌歌手信息";

btnok.Text="保存";

}

}//给歌手类型下拉框绑定数据的方法publicvoidgetcbolistzhi()

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select * from dbo.singer_type";

SqlDataAdapter da=newSqlDataAdapter(sql,con);

DataSet ds=newDataSet();try{

da.Fill(ds,"info");

cbolist.DataSource=ds.Tables["info"];

cbolist.DisplayMember="singertype_name";

cbolist.ValueMember="singertype_id";

}catch(Exception)

{

MessageBox.Show("网路异常!");

}finally{

con.Close();

}

}//修改时给修改窗体赋值publicvoidupdatagetzhi()

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select singer_photo,singer_name,singer_sex,singertype_name,singer_describe from singer_info,singer_type where singer_info.singertype_id=singer_type.singertype_id and singer_id="+ singer_id +"";

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();

SqlDataReader dr=cmd.ExecuteReader();if(dr !=null)

{if(dr.HasRows)

{while(dr.Read())

{//给歌手姓名文本框赋值txtname.Text = dr["singer_name"].ToString();//选中性别按钮if(dr["singer_sex"].ToString().Equals("男"))

{

rbboy.Checked=true;

}elseif(dr["singer_sex"].ToString().Equals("女"))

{

rbgerey.Checked=true;

}else{

rbbox.Checked=true;

}

cbolist.Text= dr["singertype_name"].ToString();

txtms.Text= dr["singer_describe"].ToString();stringurl= dr["singer_photo"].ToString();if(url!="")

{

pblist.Image= Image.FromFile(KTVUtil.singer_photoURL +url);

}

txtFileName=url;

}

}

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//添加歌手信息的方法publicvoidAddsingerinfo()

{if(txtFileName !=null)

{#region获取添加的歌手的信息//获取添加的歌手姓名stringsinger_name =txtname.Text;//获取添加歌手的性别信息stringgender;if(rbboy.Checked ==true)

{

gender="男";

}elseif(rbgerey.Checked ==true)

{

gender="女";

}else{

gender="组合";

}//获取歌手类型的隐藏值intstype_id =Convert.ToInt32(cbolist.SelectedValue);//获取歌手描述的信息stringsinger_ms =txtms.Text;#endregionSqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="insert into singer_info values('"+ singer_name +"',"+ stype_id +",'"+ gender +"','"+ txtFileName +"','"+ txtms.Text +"')";

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();intcount =cmd.ExecuteNonQuery();if(count >0)

{

MessageBox.Show("添加成功!");if(txtPath !=null)

{if(txtPath != KTVUtil.singer_photoURL +txtFileName)

{

File.Copy(txtPath, KTVUtil.singer_photoURL+ txtFileName,true);

}

}

}else{

MessageBox.Show("添加失败!");

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}else{

MessageBox.Show("请选择歌手图片路径");

}

}///验证用户界面输入的信息是否为空privateboolinfoisnull()

{boolhappy =false;if(txtname.Text.Trim() =="")

{

MessageBox.Show("请输入歌手姓名","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

txtname.Focus();

}elseif(cbolist.SelectedValue ==null)

{

MessageBox.Show("请选择歌手类型","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

cbolist.Focus();

}elseif(rbboy.Checked==false&&rbbox.Checked==false&&rbgerey.Checked==false)

{

MessageBox.Show("请选择歌手性别","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}else{

happy=true;

}returnhappy;

}//关闭privatevoidbtnexit_Click(objectsender, EventArgs e)

{this.Close();

}

歌手信息查询(frmsingerselect)

[flash=500,400]http://s1.knowsky.com/20160211/q5iqubahbba02.png[/flash]

publicAddSongInfo add;//Load事件privatevoidfrmsingerselect_Load(objectsender, EventArgs e)

{//给歌手类型下拉框绑定数据的方法getcbolistzhi();if(cbolist.Text=="全部")

{

txtname.Enabled=false;

}//给dgvlist控件绑定数据stringRowFilter ="";

getdgvlistzhi(RowFilter);

}//给歌手类型下拉框绑定数据的方法publicvoidgetcbolistzhi()

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select * from dbo.singer_type";

SqlDataAdapter da=newSqlDataAdapter(sql, con);

DataSet ds=newDataSet();try{

da.Fill(ds,"info");

cbolist.DataSource= ds.Tables["info"];

cbolist.DisplayMember="singertype_name";

cbolist.ValueMember="singertype_id";

DataRow row= ds.Tables["info"].NewRow();

row["singertype_id"] = -1;

row["singertype_name"] ="全部";

ds.Tables["info"].Rows.InsertAt(row,0);

cbolist.SelectedIndex=0;

}catch(Exception)

{

MessageBox.Show("网路异常!");

}finally{

con.Close();

}

}//给dgvlist控件绑定数据的方法publicvoidgetdgvlistzhi(stringRowFilter)

{

dgvlist.AutoGenerateColumns=false;//歌手姓名,歌手类型,歌手性别,歌手描述SqlConnection con =newSqlConnection(SqlHelper.str);stringsql ="select singer_info.singertype_id,singer_name,singer_id,singertype_name,singer_sex,singer_describe from dbo.singer_info,dbo.singer_type where singer_info.singertype_id=singer_type.singertype_id";

SqlDataAdapter da=newSqlDataAdapter(sql,con);

DataSet ds=newDataSet();try{

da.Fill(ds,"info");

DataView dv=newDataView(ds.Tables["info"]);

dv.RowFilter=RowFilter;

dgvlist.DataSource=dv;

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//点击查询触发的事件privatevoidbtnselect_Click(objectsender, EventArgs e)

{

}privatevoid删除ToolStripMenuItem_Click(objectsender, EventArgs e)

{if(dgvlist.SelectedRows[0].Cells[0].Value.ToString() !="")

{

DialogResult result= MessageBox.Show("你确定删除该歌手信息吗?(会同时删除歌曲信息)","提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if(result ==DialogResult.OK)

{//删除歌手信息的方法deletesonginfo();

deletesingerinfo();

}

}else{

MessageBox.Show("请选择一名歌手");

}

}//删除歌手对应的歌曲信息的方法publicvoiddeletesonginfo()

{//获取选中行的歌手编号intsinger_id = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["ID"].Value);stringsql ="delete song_info where singer_id="+singer_id+"";

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlCommand cmd=newSqlCommand(sql,con);

con.Open();

cmd.ExecuteNonQuery();

con.Close();

}//删除歌手信息的方法publicvoiddeletesingerinfo()

{//获取选中行的歌手编号intsinger_id = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["ID"].Value);stringsql1 ="select song_id from song_info where singer_id="+singer_id+"";

SqlConnection con1=newSqlConnection(SqlHelper.str);

SqlCommand cmd1=newSqlCommand(sql1,con1);

con1.Open();intsong_id=Convert.ToInt32(cmd1.ExecuteScalar());

con1.Close();if(song_id !=0)

{

MessageBox.Show("请先删除该歌手的歌曲信息");

}else{//并接SQL语句stringsql ="delete dbo.singer_info where singer_id="+ singer_id +"";

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();intcount =cmd.ExecuteNonQuery();if(count >0)

{

MessageBox.Show("删除成功!");stringRowFilter ="";

getdgvlistzhi(RowFilter);

}else{

MessageBox.Show("删除失败!");

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}

}//点击单元格触发的事件privatevoiddgvlist_CellClick(objectsender, DataGridViewCellEventArgs e)

{

}//点击修改触发的事件privatevoid修改ToolStripMenuItem_Click(objectsender, EventArgs e)

{if(dgvlist.SelectedRows[0].Cells[0].Value.ToString() !="")

{//获取选中行的歌手信息//歌手编号intsinger_id = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["ID"].Value);

AddSingerInfo frm=newAddSingerInfo();

frm.singer_id=singer_id;

frm.Show();

}else{

MessageBox.Show("请选择一名歌手");

}

}privatevoiddgvlist_CellDoubleClick(objectsender, DataGridViewCellEventArgs e)

{//获取用户选中行的歌手姓名stringsingername = dgvlist.SelectedRows[0].Cells["singer_name"].Value.ToString();//获取用户选中行的歌手编号intsinger_id = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["ID"].Value);//给新增歌曲窗体的歌手文本框赋值add.txtsingername.Text =singername;

add.txtsingername.Tag=singer_id;

}privatevoidbtnselect_Click_1(objectsender, EventArgs e)

{if(txtname.Text ==""&& cbolist.Text =="全部")

{stringRowFilter ="";

getdgvlistzhi(RowFilter);

}elseif(txtname.Text !=""&&cbolist.Text=="全部")

{//获取要查询歌手的姓名stringname =txtname.Text;//获取要查询的歌手类型inttype =Convert.ToInt32(cbolist.SelectedValue);stringRowFilter ="singer_name like '%"+ name +"%'";

getdgvlistzhi(RowFilter);

}else{//获取要查询歌手的姓名stringname =txtname.Text;//获取要查询的歌手类型inttype =Convert.ToInt32(cbolist.SelectedValue);stringRowFilter ="singer_name like '%"+ name +"%' and singertype_id="+ type +"";

getdgvlistzhi(RowFilter);

}

}privatevoiddgvlist_CellContentClick(objectsender, DataGridViewCellEventArgs e)

{

}privatevoidcbolist_SelectedIndexChanged(objectsender, EventArgs e)

{if(cbolist.Text =="全部")

{

txtname.Enabled=false;

}else{

txtname.Enabled=true;

}

}

新增歌曲(AddSongInfo):

[flash=500,400]http://s1.knowsky.com/20160211/2qcspmq1pz302.png[/flash]

publicfrmsingerselect frmss;publicintsong_id;publicstringtxtPath;//相对路径publicstringtxtxdpath;//Load事件privatevoidAddSongInfo_Load(objectsender, EventArgs e)

{//给歌曲类型下拉框绑定数据getcbolistzhi();if(song_id !=0)

{this.Text ="修改歌曲信息";

btnok.Text="修改";

updategetzhi();

}else{this.Text ="编辑歌曲信息";

btnok.Text="保存";

}

}//给歌曲类型下拉框绑定数据的方法publicvoidgetcbolistzhi()

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select * from dbo.song_type";

SqlDataAdapter da=newSqlDataAdapter(sql, con);

DataSet ds=newDataSet();try{

da.Fill(ds,"info");

cbolist.DataSource= ds.Tables["info"];

cbolist.DisplayMember="songtype_name";

cbolist.ValueMember="songtype_id";

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Open();

}

}privatevoidbutton1_Click(objectsender, EventArgs e)

{

openFileDialog1.Filter="歌曲文件|*.mp3;";

DialogResult result=openFileDialog1.ShowDialog();if(result == DialogResult.OK)//证明用户双击(选中了)一个文件,我就获取路径{//相对路径txtxdpath =openFileDialog1.SafeFileName;

txturl.Text=txtxdpath;//绝对路径txtPath =openFileDialog1.FileName;intdot = txtxdpath.LastIndexOf('.');stringfileType = txtxdpath.Substring(dot +1);if(fileType !="mp3")

{

MessageBox.Show("文件类型错误!");

}////给PictureBox的Image属性赋值//pblist.Image = Image.FromFile(txtPath);}

}//点击查询触发的事件privatevoidbutton4_Click(objectsender, EventArgs e)

{

frmsingerselect frm=newfrmsingerselect();

frm.add=this;

frm.ShowDialog();

}//点击关闭触发的事件privatevoidbutton3_Click(objectsender, EventArgs e)

{this.Close();

}//点击保存触发的事件privatevoidbutton2_Click(objectsender, EventArgs e)

{if(isnull())

{if(song_id !=0)

{//执行修改的方法updatesonginfo();

}else{//保存的方法addinfo();

}

}

}//执行修改给修改窗体相关信息赋值publicvoidupdategetzhi()

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select song_info.singer_id,song_url,song_name,singer_name,song_ab,song_word_count,song_url,song_play_count,songtype_name from song_info,song_type,singer_info where song_info.songtype_id=song_type.songtype_id and song_info.singer_id=singer_info.singer_id and song_id="+ song_id +"";

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();

SqlDataReader dr=cmd.ExecuteReader();if(dr !=null)

{if(dr.HasRows)

{while(dr.Read())

{

txtsongname.Text= dr["song_name"].ToString();

txtsingername.Text= dr["singer_name"].ToString();

txtsingername.Tag= Convert.ToInt32(dr["singer_id"]);

txtpy.Text= dr["song_ab"].ToString();

cbolist.Text= dr["songtype_name"].ToString();

txtsingername.Text= dr["singer_name"].ToString();

txturl.Text= dr["song_url"].ToString();

}

}

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//修改歌曲信息的方法publicvoidupdatesonginfo()

{//获取歌曲名称stringsong_name =txtsongname.Text;//获取拼音缩写信息stringpy =txtpy.Text;//获取歌曲类型对应的隐藏值inttype_id =Convert.ToInt32(cbolist.SelectedValue);//获取歌手姓名对应的编号intsinge_id =Convert.ToInt32(txtsingername.Tag);//获取歌曲文件名stringurl =txturl.Text;//获取歌曲名称的长度intlength =song_name.Length;stringsql ="update song_info set song_name='"+ song_name +"',song_ab='"+ py +"',song_word_count="+ length +",songtype_id="+ type_id +",singer_id="+ singe_id +",song_url='"+ url +"',song_play_count=default where song_id="+ song_id +"";

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();intresult =cmd.ExecuteNonQuery();if(result >0)

{

MessageBox.Show("修改成功!");if(txtPath !=null)

{if(txtPath != KTVUtil.songURL +txtxdpath)

{

File.Copy(txtPath, KTVUtil.songURL+ txtxdpath,true);

}

}else{

MessageBox.Show("修改失败!");

}

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}//新增歌曲信息的方法publicvoidaddinfo()

{//获取歌曲名称stringsong_name =txtsongname.Text;//获取拼音缩写信息stringpy =txtpy.Text;//获取歌曲类型对应的隐藏值inttype_id =Convert.ToInt32(cbolist.SelectedValue);//获取歌手姓名对应的编号intsinge_id =Convert.ToInt32(txtsingername.Tag);//获取歌曲文件名stringurl =txturl.Text;//获取歌曲名称的长度intlength =song_name.Length;//拼接sql语句stringsql ="insert into song_info values('"+ song_name +"','"+ py +"',"+ length +","+ type_id +","+ singe_id +",'"+ url +"',default)";

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();intresult =cmd.ExecuteNonQuery();if(result >0)

{

MessageBox.Show("保存成功!");if(txtPath !=null)

{if(txtPath != KTVUtil.songURL +txtxdpath)

{

File.Copy(txtPath, KTVUtil.songURL+ txtxdpath,true);

}

}

}else{

MessageBox.Show("保存失败!");

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}privatevoidtxtsongname_TextChanged(objectsender, EventArgs e)

{//将第一个文本框中内容转换成py,写入到第二个文本框中stringword =txtsongname.Text;if(word !="")

{

txtpy.Text=hanzitopinyin.GetChineseSpell(word);

}else{

txtpy.Text=string.Empty;

}

}publicboolisnull()

{boolhappy =false;if(txtsongname.Text.Trim() =="")

{

MessageBox.Show("请输入歌曲名称","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

txtsongname.Focus();

}elseif(txtpy.Text.Trim() =="")

{

MessageBox.Show("请输入拼音缩写","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

txtpy.Focus();

}elseif(cbolist.Text==null)

{

MessageBox.Show("青选择歌曲类型","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

}elseif(txtsingername.Text=="")

{

MessageBox.Show("请选择歌手","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

txtsingername.Focus();

}elseif(txturl.Text =="")

{

MessageBox.Show("请选择歌曲路径","提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

txturl.Focus();

}else{

happy=true;

}returnhappy;

}

查询歌曲信息(frmsongselect):

[flash=500,400]http://s1.knowsky.com/20160211/riazdtwr2pr02.png[/flash]

//Load事件privatevoidfrmsongselect_Load(objectsender, EventArgs e)

{//给歌曲类型下拉框赋值getsongtypezhi();if(cbolist.Text =="全部")

{

txtsongname.Enabled=false;

}//给dgvlist绑定数据stringRowFilter ="";

getdgvlistzhi(RowFilter);

}//给歌曲类型下拉框赋值的方法publicvoidgetsongtypezhi()

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select * from song_type";

SqlDataAdapter da=newSqlDataAdapter(sql, con);

DataSet ds=newDataSet();try{

da.Fill(ds,"info");

cbolist.DataSource= ds.Tables["info"];

cbolist.DisplayMember="songtype_name";

cbolist.ValueMember="songtype_id";

DataRow row= ds.Tables["info"].NewRow();

row["songtype_id"] = -1;

row["songtype_name"] ="全部";

ds.Tables["info"].Rows.InsertAt(row,0);

cbolist.SelectedIndex=0;

}catch(Exception)

{

MessageBox.Show("网路异常!");

}finally{

con.Close();

}

}//给dgvlist绑定数据的方法publicvoidgetdgvlistzhi(stringRowFilter)

{//取消英文列自动生成dgvlist.AutoGenerateColumns =false;

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select song_id,song_name,songtype_name,song_play_count,song_info.songtype_id from song_info,song_type where song_info.songtype_id=song_type.songtype_id";

SqlDataAdapter da=newSqlDataAdapter(sql,con);

DataSet ds=newDataSet();try{

da.Fill(ds,"info");

DataView dv=newDataView(ds.Tables["info"]);

dv.RowFilter=RowFilter;

dgvlist.DataSource=dv;

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Open();

}

}//点击查询触发的事件privatevoidbtnselect_Click(objectsender, EventArgs e)

{if(txtsongname.Text ==""&& cbolist.Text =="全部")

{stringRowFilter ="";

getdgvlistzhi(RowFilter);

}elseif(txtsongname.Text !=""&& cbolist.Text =="全部")

{//获取歌曲名称stringsong_name =txtsongname.Text;//获取歌曲类型对应的隐藏值inttype_id =Convert.ToInt32(cbolist.SelectedValue);stringRowFilter ="song_name like '%"+ song_name +"%'";

getdgvlistzhi(RowFilter);

}else{//获取歌曲名称stringsong_name =txtsongname.Text;//获取歌曲类型对应的隐藏值inttype_id =Convert.ToInt32(cbolist.SelectedValue);stringRowFilter ="song_name like '%"+ song_name +"%' and songtype_id ="+ type_id +"";

getdgvlistzhi(RowFilter);

}

}//点击dgvlist单元格触发的事件privatevoiddgvlist_CellClick(objectsender, DataGridViewCellEventArgs e)

{

}//删除歌曲信息的方法publicvoiddeletesong()

{if(dgvlist.SelectedRows[0].Cells[0].Value.ToString() !="")

{//获取选中行的歌曲编号intsong_id = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["song_id"].Value);

DialogResult result= MessageBox.Show("确定删除吗?","提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);if(result ==DialogResult.OK)

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="delete song_info where song_id="+ song_id +"";

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();intcount =cmd.ExecuteNonQuery();if(count >0)

{

MessageBox.Show("删除成功!");

}else{

MessageBox.Show("删除失败!");

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}

}else{

MessageBox.Show("请选择一首歌曲");

}

}privatevoid删除ToolStripMenuItem_Click(objectsender, EventArgs e)

{//删除歌曲信息的方法deletesong();

}//修改privatevoid修改ToolStripMenuItem_Click(objectsender, EventArgs e)

{if(dgvlist.SelectedRows[0].Cells[0].Value.ToString() !="")

{//获取选中行的歌曲编号intsong_id = Convert.ToInt32(dgvlist.SelectedRows[0].Cells["song_id"].Value);

AddSongInfo frm=newAddSongInfo();

frm.song_id=song_id;

frm.Show();

}else{

MessageBox.Show("请选择一首歌曲");

}

}privatevoidcbolist_SelectedIndexChanged(objectsender, EventArgs e)

{if(cbolist.Text =="全部")

{

txtsongname.Enabled=false;

}else{

txtsongname.Enabled=true;

}

}

修改歌手信息(共用窗体新增歌手(FrmAddSingerinfo)):

[flash=500,400]http://s1.knowsky.com/20160211/15maiuxntzr02.png[/flash]

修改歌曲信息(共用窗体新增歌曲(AddSongInfo):):

[flash=500,400]http://s1.knowsky.com/20160211/fjh0t5ehuop02.png[/flash]

修改歌手图片路径(Frmsingerphotourl)

[flash=500,400]http://s1.knowsky.com/20160211/2yw2ugggvvp02.png[/flash]

privatevoidbutton2_Click(objectsender, EventArgs e)

{//如果新路径为空,提示if(this.txtnewurl.Text.Trim() =="")

{

MessageBox.Show("请选择新路径!");

}else{//用户确认修改if(MessageBox.Show("确定要修改路径吗?","操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==DialogResult.Yes)

{

Directory.Delete(txtnewurl.Text);

Directory.Move(txturl.Text, txtnewurl.Text);stringnewUrl =txtnewurl.Text;

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="update Resource_path set resource_path='"+ newUrl +"' where resource_id=2";

SqlCommand cmd=newSqlCommand(sql, con);try{

con.Open();intcount =cmd.ExecuteNonQuery();if(count >0)

{

MessageBox.Show("保存成功!");

}else{

MessageBox.Show("保存失败!");

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}

}

}//点击关闭触发的事件privatevoidbutton3_Click(objectsender, EventArgs e)

{this.Close();

}privatevoidbtnll_Click(objectsender, EventArgs e)

{

DialogResult result=folderBrowserDialog1.ShowDialog();if(result ==DialogResult.OK)

{

txtnewurl.Text= folderBrowserDialog1.SelectedPath +"\\";

}

}privatevoidfrmsingerphotourl_Load(objectsender, EventArgs e)

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select resource_path from Resource_path where resource_id=2";

txturl.Text=song_path(sql);

}//给当前路径赋值privatestringsong_path(stringsql)

{

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlCommand cmd=newSqlCommand(sql, con);stringpath ="";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;

}

修改歌曲路径(frmsongurl)

[flash=500,400]http://s1.knowsky.com/20160211/s5hn2x3tu3g02.png[/flash]

privatevoidfrmsongurl_Load(objectsender, EventArgs e)

{

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="select resource_path from Resource_path where resource_id=1";

txturl.Text=song_path(sql);

}//给当前路径赋值privatestringsong_path(stringsql)

{

SqlConnection con=newSqlConnection(SqlHelper.str);

SqlCommand cmd=newSqlCommand(sql, con);stringpath ="";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;

}//点击浏览触发的事件privatevoidbtnll_Click(objectsender, EventArgs e)

{

DialogResult result=folderBrowserDialog1.ShowDialog();if(result ==DialogResult.OK)

{

txtnewurl.Text= folderBrowserDialog1.SelectedPath +"\\";

}

}//点击关闭触发的事件privatevoidbutton3_Click(objectsender, EventArgs e)

{this.Close();

}//点击保存触发的事件privatevoidbutton2_Click(objectsender, EventArgs e)

{//如果新路径为空,提示if(this.txtnewurl.Text.Trim() =="")

{

MessageBox.Show("请选择新路径!");

}else{//用户确认修改if(MessageBox.Show("确定要修改路径吗?","操作提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==DialogResult.Yes)

{

Directory.Delete(txtnewurl.Text);

Directory.Move(txturl.Text, txtnewurl.Text);stringnewUrl =txtnewurl.Text;

SqlConnection con=newSqlConnection(SqlHelper.str);stringsql ="update Resource_path set resource_path='"+ newUrl +"' where resource_id=1";

SqlCommand cmd=newSqlCommand(sql,con);try{

con.Open();intcount=cmd.ExecuteNonQuery();if(count >0)

{

MessageBox.Show("保存成功!");

}else{

MessageBox.Show("保存失败!");

}

}catch(Exception)

{

MessageBox.Show("网络异常!");

}finally{

con.Close();

}

}

}

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航