/// <summary>
        /// 数据插入
        /// </summary>
        public bool Insert(TrackResource map)
        {
            try
            {
                StringBuilder sqlcmd = new StringBuilder();

                sqlcmd.Append(@"INSERT INTO {0} (
                                  TRACK_ID
                                 ,RESOURCE_ID
                                 ,ENABLE_FLG
                                 ,LAST_UPDATE_DATETIME
                                 )
                            VALUES (
                                    @TrackID
                                    ,@ResourceID
                                    ,1
                                    ,GETDATE())");

                Collection<DbParameter> paras = new Collection<DbParameter>();
                paras.Add(new SqlParameter("@TrackID", map.TrackID));
                paras.Add(new SqlParameter("@ResourceID", map.ResourceID));

                DbCmd.DoCommand(string.Format(sqlcmd.ToString(), CommonConst.TableName.T_TRACK_RESOURCE_TBL), paras);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return true;
        }
        /// <summary>
        /// 获取匹配表
        /// </summary>
        /// <param name="TrackID"></param>
        /// <returns></returns>
        public List<TrackResource> GetResourceMaps(string TrackID)
        {
            List<TrackResource> mapList = new List<TrackResource>();

            DataSet ds = dao.GetResourceMapByTrackId(TrackID);

            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                TrackResource map = new TrackResource();
                map.ResourceID = Convert.ToInt32(dr[CommonConst.ColumnName.RESOURCE_ID]);
                map.TrackID = dr[CommonConst.ColumnName.TRACK_ID].ToString();
                mapList.Add(map);
            }

            return mapList;
        }
 /// <summary>
 /// 数据插入
 /// </summary>
 /// <param name="map"></param>
 /// <returns></returns>
 public bool Insert(TrackResource map)
 {
     return dao.Insert(map);
 }
Beispiel #4
0
 /// <summary>
 /// 添加资源匹配
 /// </summary>
 /// <param name="track"></param>
 public void AddMapping(TrackResource map)
 {
     this.ResourceMap.Add(map);
 }
Beispiel #5
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;
            }
        }