/// <summary> /// 保存修改 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbSave_Click(object sender, EventArgs e) { try { if (string.IsNullOrEmpty(txtName.Text)) { MessageBox.Show("请输入歌手姓名!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } CopyPhoto();//复制图片到运行目录下 Singer s = new Singer(); s.Name = txtName.Text.Trim(); s.Gender = cboGrande.Text.Trim(); s.Type = cboType.SelectedValue.ToString(); s.PhotoURL = ImageName.Trim(); s.Remake = txtRemark.Text.Trim(); s.AddTime = DateTime.Now; int count = 0; if (string.IsNullOrEmpty(txtId.Text))//增加 { count = singerManager.AddSingerInfo(s); } else//修改 { s.SingId = Convert.ToInt32(txtId.Text); count = singerManager.UpdateSingerInfo(s); } if (count > 0) { showDgvSingers(); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), "异常", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void btnStartDownLoad_Click(object sender, EventArgs e) { try { tsState.Value = 0; tsState.Visible = true; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (downloader == null) { downloader = new SongDownloader(provider, path); } foreach (ListViewItem item in lvSongs.CheckedItems) { timer1.Enabled = true; timer1.Interval = 100; MergedSong1 song = (MergedSong1)item.Tag; downloader.AddDownload(song); //若路径更改,则不往库中保存数据 if (txtDownLoadPath.Text.Trim() == Directory.GetCurrentDirectory() + @"\misucs\") { //判断歌手是否已存在,若不存在则添加 if (!isExeitsSinger(song.Singer)) { KtvMSModel.Singer singer = new KtvMSModel.Singer(); singer.Name = song.Singer; singerManager.AddSingerInfo(singer); } //根据歌名判断歌曲是否存在, if (!newSongManager.isExeitsSongByName(song.SongName)) { Song1 song1 = new Song1(); song1.SongName = song.SongName; song1.Singer = song.Singer; song1.Source = song.Source; song1.Duration = song.Duration; //播放时间 song1.Size = Convert.ToDouble((song.Size / (1024 * 1024)).ToString("F2")); //歌曲文件大小 int row = newSongManager.AddSong(song1);//添加歌曲 if (row > 0) { int songId = newSongManager.GetSongIdByName(song.SongName); if (songId != null && songId != 0) { downloadSongManger.AddDownloadSong(songId);//下载记录 } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示", 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); } }