/// <summary> /// 判断歌手是否存在 /// </summary> /// <returns></returns> public bool isExeitsSinger(string singer) { bool falg = false; try { List <Singer> singerList = singerManager.GetAllSingers(); if (singerList != null) { foreach (Singer s in singerList) { if (s.Name == singer) { falg = true; break; } } } } catch (Exception ex) { MessageBox.Show("插入歌手异常 " + ex.Message, "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); } return(falg); }
/// <summary> /// 绑定歌手信息到DGV /// </summary> public void showDgvSingers() { try { dgvSinger.DataSource = singerManager.GetAllSingers(); } catch (Exception ex) { MessageBox.Show(ex.ToString(), "异常", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbSave_Click(object sender, EventArgs e) { if (String.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("请输入歌曲名!!!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (String.IsNullOrEmpty(cboSingers.Text)) { MessageBox.Show("请选择歌手!!!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } //if (String.IsNullOrEmpty(txtFile.Text)) //{ // MessageBox.Show("请选择歌曲文件!!!", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Information); // return; //} try { //手动录入,如果歌手不存在,则添加歌手 bool isExist = true; String SingerName = cboSingers.Text; String SingerId = ""; List <Singer> singers = singerManager.GetAllSingers(); foreach (Singer i in singers) { if (i.Name == SingerName) { isExist = false; break; } } if (isExist) { Singer singer = new Singer(); singer.Name = cboSingers.Text; singer.Type = "1"; singer.AddTime = DateTime.Now; singerManager.AddSingerInfo(singer); SingerId = singerManager.GetNewId(); bindSinger(); } Song s = new Song(); s.Id = txtId.Text; s.name = txtName.Text.Trim(); s.songName = SongName; s.pinyin = txtPinYin.Text; s.songtypeID = cboTypes.SelectedValue.ToString(); s.singerId = SingerId == "" ? cboSingers.SelectedValue.ToString() : SingerId; if (string.IsNullOrEmpty(txtId.Text)) { MoveSong(); //移动歌曲 s.songURL = ofFileURL; //文件全路径 } else { s.songURL = txtFile.Text.Trim();// 文件全路径 } int row = songManager.SaveSong(s); if (row > 0) { bindDgvSongs(); Reset(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "异常信息", MessageBoxButtons.OK, MessageBoxIcon.Information); } }