/// <summary>
        /// 通过专辑ID获得专辑内曲目
        /// </summary>
        /// <param name="AlbumID"></param>
        /// <returns></returns>
        public List<TrackSeries> GetTracks(string AlbumID)
        {
            List<TrackSeries> tracks = new List<TrackSeries>();

            DataSet ds = dao.GetTrackIDByAlbumID(AlbumID);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                TrackSeries track = new TrackSeries(dr[CommonConst.ColumnName.TRACK_ID].ToString());

                tracks.Add(track);
            }

            return tracks;
        }
        /// <summary>
        /// 数据插入
        /// </summary>
        public bool Insert(TrackSeries track)
        {
            foreach (ResourceSeries resource in track.Resource)
            {
                if (!resource.Insert())
                {
                    return false;
                }
            }

            foreach (TrackResource map in track.ResourceMap)
            {
                if (!map.Insert())
                {
                    return false;
                }
            }

            return dao.Insert(track);
        }
        /// <summary>
        /// 数据插入
        /// </summary>
        public bool Insert(TrackSeries track)
        {
            StringBuilder cmd1 = new StringBuilder();
            StringBuilder cmd2 = new StringBuilder();
            StringBuilder sqlcmd = new StringBuilder();

            Collection<DbParameter> paras = new Collection<DbParameter>();

            if (track.AnimeNo != null && !track.AnimeNo.Trim().Equals(string.Empty))
            {
                cmd1.Append(",ANIME_NO");
                cmd2.Append(",@AnimeNo");
                paras.Add(new SqlParameter("@AnimeNo", track.AnimeNo));
            }

            if (track.SalesYear > 0)
            {
                cmd1.Append(",SALES_YEAR");
                cmd2.Append(",@SalesYear");
                paras.Add(new SqlParameter("@SalesYear", track.SalesYear));
            }

            if (track.Description != null && !track.Description.Trim().Equals(string.Empty))
            {
                cmd1.Append(",DESCRIPTION");
                cmd2.Append(",@Description");
                paras.Add(new SqlParameter("@Description", track.Description));
            }

            sqlcmd.Append(@"INSERT INTO {0} (
                                  TRACK_ID
                                 ,P_ALBUM_ID
                                 ,TRACK_TYPE_ID
                                 ,DISC_NO
                                 ,TRACK_NO
                                 ,TRACK_TITLE_NAME
                                 ,ARTIST_ID
                                 ,ENABLE_FLG
                                 ,LAST_UPDATE_DATETIME
                                 ");
            sqlcmd.Append(cmd1);
            sqlcmd.Append(@")
                            VALUES (
                                    @id
                                    ,@PAlbumID
                                    ,@TrackTypeId
                                    ,@DiscNo
                                    ,@TrackNo
                                    ,@TrackTitleName
                                    ,@ArtistID
                                    ,1
                                    ,GETDATE() ");
            sqlcmd.Append(cmd2);
            sqlcmd.Append(@")");
            paras.Add(new SqlParameter("@id", track.ID));
            paras.Add(new SqlParameter("@PAlbumID", track.PAlbumID));
            paras.Add(new SqlParameter("@TrackTypeId", track.TrackTypeId));
            paras.Add(new SqlParameter("@DiscNo", track.DiscNo));
            paras.Add(new SqlParameter("@TrackNo", track.TrackNo));
            paras.Add(new SqlParameter("@TrackTitleName", track.TrackTitleName));
            paras.Add(new SqlParameter("@ArtistID", track.ArtistID));

            DbCmd.DoCommand(string.Format(sqlcmd.ToString(), CommonConst.TableName.T_TRACK_TBL), paras);

            return true;
        }
Exemple #4
0
        /// <summary>
        /// 插入音乐信息
        /// </summary>
        /// <returns></returns>
        private bool ImportMusicToDB()
        {
            try
            {
                //格式检查
                if (!FormatCheck())
                {
                    return false;
                }

                //导入列表
                MusicDataSet.ImportMusicListDataTable resultList = new MusicDataSet.ImportMusicListDataTable();

                #region resultList作成
                foreach (DataGridViewRow dr in MusicDataGridView.Rows)
                {
                    //------做成需要导入的曲目 开始------
                    MusicDataSet.ImportMusicListRow resRow = resultList.NewImportMusicListRow();

                    //曲号
                    resRow.TrackID = dr.Cells[TRACKIDCLN].Value.ToString();
                    //曲名
                    resRow.TrackTitleName = dr.Cells[TRACKNAMECLN].Value.ToString().Trim();
                    //曲目类型
                    resRow.TrackTypeId = Convert.ToInt32(dr.Cells[TRACKTYPEIDCLN].Value);
                    //专辑号
                    resRow.AlbumID = dr.Cells[ALBUMIDCLN].Value.ToString();
                    //专辑名
                    resRow.AlbumTitleName = dr.Cells[ALBUMNAMECLN].Value.ToString().Trim();
                    //专辑类型
                    resRow.AlbumTypeID = Convert.ToInt32(dr.Cells[ALBUMTYPEIDCLN].Value);
                    //艺术家编号
                    resRow.ArtistID = Convert.ToInt32(dr.Cells[ARTISTIDCLN].Value);
                    //碟号
                    resRow.DiscNo = dr.Cells[DISCNOCLN].Value.ToString().Trim();
                    //音轨
                    resRow.TrackNo = dr.Cells[TRACKNOCLN].Value.ToString().Trim();
                    //发售年份
                    if (dr.Cells[YEARCLN].Value != null)
                    {
                        resRow.SalesYear = dr.Cells[YEARCLN].Value.ToString().Trim();
                    }
                    //资源路径
                    resRow.FilePath = dr.Cells[RESOURCEPATHCLN].Value.ToString();
                    //描述
                    if (dr.Cells[DESCRIPTIONCLN].Value != null)
                    {
                        resRow.Description = dr.Cells[DESCRIPTIONCLN].Value.ToString();
                    }
                    //动画编号
                    if (dr.Cells[ANIMENOCLN].Value != null)
                    {
                        resRow.AnimeNo = dr.Cells[ANIMENOCLN].Value.ToString();
                    }
                    //专辑类型编号
                    resRow.AlbumTypeID = Convert.ToInt32(dr.Cells[ALBUMTYPEIDCLN].Value);
                    //曲目类型编号
                    resRow.TrackTypeId = Convert.ToInt32(dr.Cells[TRACKTYPEIDCLN].Value);
                    //比特率
                    resRow.BitRate = dr.Cells[BITRATECLN].Value.ToString();
                    //歌曲长度
                    resRow.TrackLength = dr.Cells[TRACKTIMELENGTHCLN].Value.ToString();
                    //艺术家姓名
                    resRow.ArtistName = dr.Cells[ARTISTNAMECLN].Value.ToString();

                    resultList.Rows.Add(resRow);
                }

                resultList.AcceptChanges();
                #endregion

                //所有需要插入数据物理表对应的List
                List<AlbumSeries> AlbumSeriesList = new List<AlbumSeries>();
                //所有需要复制的资源,考虑到以后的专辑封面图预留
                List<ResourceSeries> ResourceToCopy = new List<ResourceSeries>();

                #region 所有信息作成

                var targetAlbum = (from v in resultList
                                   select new
                                   {
                                       v.AlbumID,
                                       v.AlbumTitleName,
                                       v.AlbumTypeID,
                                       v.AnimeNo
                                   }).Distinct().ToList();

                foreach (var albumInfo in targetAlbum)
                {
                    //专辑信息作成
                    AlbumSeries album = new AlbumSeries();

                    album.ID = albumInfo.AlbumID;
                    album.AlbumTitleName = albumInfo.AlbumTitleName;
                    album.AlbumTypeId = albumInfo.AlbumTypeID;
                    album.AnimeNo = albumInfo.AnimeNo;
                    album.InAnimeNo = service.GetNextInAnimeAlbumNo(album.ID, album.AlbumTypeId);

                    //计算总碟数:maxdiscno
                    album.TotalDiscCount = GetTotalDisc(album.ID, resultList);

                    //计算总曲数:count
                    var counttrack = (from discc in resultList
                                      select discc.TrackID).Count();
                    album.TotalTrackCount = Convert.ToInt32(counttrack);

                    //曲目信息作成
                    var targetTrack = from v in resultList
                                      where v.AlbumID.Equals(album.ID)
                                      select v;
                    foreach (MusicDataSet.ImportMusicListRow ir in targetTrack)
                    {
                        //曲目基本信息
                        TrackSeries track = new TrackSeries();

                        track.ID = ir.TrackID;
                        track.PAlbumID = ir.AlbumID;
                        track.TrackTypeId = ir.TrackTypeId;
                        track.TrackTitleName = ir.TrackTitleName;
                        track.ArtistID = ir.ArtistID;
                        track.AnimeNo = ir.AnimeNo;
                        if (!string.IsNullOrEmpty(ir.SalesYear))
                        {
                            track.SalesYear = Convert.ToInt32(ir.SalesYear);
                        }
                        if (!string.IsNullOrEmpty(track.Description))
                        {
                            track.Description = ir.Description;
                        }

                        if (!string.IsNullOrEmpty(ir.DiscNo))
                        {
                            track.DiscNo = format.GetDiscNoOrTrackNo(ir.DiscNo);
                        }
                        else
                        {
                            track.DiscNo = 0;
                        }
                        if (!string.IsNullOrEmpty(ir.TrackNo))
                        {
                            track.TrackNo = format.GetDiscNoOrTrackNo(ir.TrackNo);
                        }
                        else
                        {
                            track.TrackNo = 0;
                        }

                        //既存音源文件
                        FileInfo MusicResource = new FileInfo(ir.FilePath);

                        if (!MusicResource.Exists)
                        {
                            MsgBox.Show(MSG_IMPORTMUSIC_014, MusicResource.FullName);
                        }

                        //曲目资源信息
                        //1.备份音源
                        ResourceSeries bakMusic = new ResourceSeries();

                        bakMusic.GetNewID();
                        bakMusic.TypeID = ResourceFile.Type.MUSIC_MP3_1;
                        bakMusic.StorageID = StorageID.Path.BAK_RESOURCE_BUCKET_101;
                        //sound.FilePath = null;
                        bakMusic.FileName = format.FileNameFormat(bakMusic.ID.ToString());
                        bakMusic.Suffix = ".mp3";
                        bakMusic.TrackBitRate = ir.BitRate;
                        bakMusic.TrackLength = format.GetSecondFromTime(ir.TrackLength);
                        bakMusic.objectFilePath = ir.FilePath;
                        track.AddResource(bakMusic);
                        ResourceToCopy.Add(bakMusic);

                        TrackResource bakMusicMap = new TrackResource();
                        bakMusicMap.ResourceID = bakMusic.ID;
                        bakMusicMap.TrackID = ir.TrackID;
                        track.AddMapping(bakMusicMap);

                        //2.主要音源
                        ResourceSeries mainMusic = new ResourceSeries();
                        mainMusic.GetNewID();
                        mainMusic.TypeID = ResourceFile.Type.MUSIC_MP3_1;
                        mainMusic.StorageID = StorageID.Path.MAIN_RESOURCE_BUCKET_201;
                        //..\@anime_no\@album_type_name\@album_title_name\@[email protected]
                        mainMusic.FilePath = format.FilePathFormat(ir.AnimeNo + "\\" + service.GetAlbumTypeNameByAlbumTypeID(ir.AlbumTypeID) + "\\" + format.FileNameFormat(ir.AlbumTitleName));
                        mainMusic.FileName = format.FileNameFormat(ir.ArtistName + "_" + ir.TrackTitleName);
                        mainMusic.Suffix = ".mp3";
                        mainMusic.TrackBitRate = ir.BitRate;
                        mainMusic.TrackLength = format.GetSecondFromTime(ir.TrackLength);
                        mainMusic.objectFilePath = ir.FilePath;
                        track.AddResource(mainMusic);
                        ResourceToCopy.Add(mainMusic);

                        TrackResource mainMusicMap = new TrackResource();
                        mainMusicMap.ResourceID = mainMusic.ID;
                        mainMusicMap.TrackID = ir.TrackID;
                        track.AddMapping(mainMusicMap);

                        //歌词文件存否判断
                        string Directory = MusicResource.DirectoryName;
                        string ResourceName = Path.GetFileNameWithoutExtension(MusicResource.Name);
                        string LrcFullPath = Directory + "\\" + ResourceName + ".lrc";
                        FileInfo LrcResource = new FileInfo(LrcFullPath);

                        if (LrcResource.Exists)
                        {
                            //3.备份歌词
                            ResourceSeries bakLrc = new ResourceSeries();

                            bakLrc.GetNewID();
                            bakLrc.TypeID = ResourceFile.Type.LYRIC_LRC_201;
                            bakLrc.StorageID = StorageID.Path.BAK_RESOURCE_BUCKET_101;
                            //sound.FilePath = null;
                            bakLrc.FileName = format.FileNameFormat(bakLrc.ID.ToString());
                            bakLrc.Suffix = ".lrc";
                            bakLrc.objectFilePath = ir.FilePath;
                            track.AddResource(bakLrc);
                            ResourceToCopy.Add(bakLrc);

                            TrackResource bakLrcMap = new TrackResource();
                            bakLrcMap.ResourceID = bakLrc.ID;
                            bakLrcMap.TrackID = LrcFullPath;
                            track.AddMapping(bakLrcMap);

                            //4.主要歌词
                            ResourceSeries mainLrc = new ResourceSeries();
                            mainLrc.GetNewID();
                            mainLrc.TypeID = ResourceFile.Type.LYRIC_LRC_201;
                            mainLrc.StorageID = StorageID.Path.MAIN_RESOURCE_BUCKET_201;
                            //..\@anime_no\@album_type_name\@album_title_name\@[email protected]
                            mainLrc.FilePath = format.FilePathFormat(ir.AnimeNo + "\\" + service.GetAlbumTypeNameByAlbumTypeID(ir.AlbumTypeID) + "\\" + format.FileNameFormat(ir.AlbumTitleName));
                            mainLrc.FileName = format.FileNameFormat(ir.ArtistName + "_" + ir.TrackTitleName);
                            mainLrc.objectFilePath = LrcFullPath;
                            track.AddResource(mainLrc);
                            ResourceToCopy.Add(mainLrc);

                            TrackResource mainLrcMap = new TrackResource();
                            mainLrcMap.ResourceID = mainLrc.ID;
                            mainLrcMap.TrackID = ir.TrackID;
                            track.AddMapping(mainLrcMap);
                        }

                        album.AddTracks(track);
                    }
                    AlbumSeriesList.Add(album);
                }
                #endregion

                #region DB操作

                foreach (AlbumSeries album in AlbumSeriesList)
                {
                    album.Insert();
                }

                #endregion

                #region 文件操作

                foreach (ResourceSeries resource in ResourceToCopy)
                {
                    string DirPath = service.GetResourceDirectoryPath(resource.StorageID, resource.FilePath);
                    if (!Directory.Exists(DirPath))
                    {
                        Directory.CreateDirectory(DirPath);
                    }

                    string targetPath = service.GetResourcePath(resource.StorageID, resource.FilePath, resource.FileName, resource.Suffix);
                    File.Copy(resource.objectFilePath, targetPath);
                }

                #endregion
                return true;
            }
            catch (Exception ex)
            {
                MsgBox.Show(MSG_COMMON_001, ex.ToString());
                return false;
            }
        }