コード例 #1
0
ファイル: ImportMusic.cs プロジェクト: kirisamex/Animedata
        /// <summary>
        /// 展示导入的音乐
        /// </summary>
        /// <param name="musicPath">音乐路径数组</param>
        private void ShowMusicInfo(string[] musicPath)
        {
            //导入列表
            MusicDataSet.ImportMusicListDataTable importList = new MusicDataSet.ImportMusicListDataTable();

            for (int i = 0; i < musicPath.Length; i++)
            {
                if (!System.IO.File.Exists(musicPath[i]))
                {
                    MsgBox.Show(MSG_IMPORTMUSIC_001, musicPath[i]);
                    continue;
                }

                //------做成新曲目 开始------
                MusicDataSet.ImportMusicListRow importRow = importList.NewImportMusicListRow();

                //FilePath
                importRow.FilePath = musicPath[i];

                ID3V2Tag tag = new ID3V2Tag(importRow.FilePath);

                //TrackID 仮采番
                importRow.TrackID = service.GetNextTrackID();
                //AlbumID 仮采番
                importRow.AlbumID = service.GetAlbumIDFromAlbumTitleName(tag.AlbumName);
                //TrackTypeID
                //DiscNo
                importRow.DiscNo = tag.DiscNo;
                //TrackNo
                importRow.TrackNo = tag.TrackNo;
                //OldTrackNo

                //AlbumTitleName
                importRow.AlbumTitleName = tag.AlbumName.Replace('�', char.MinValue);
                //TrackTitleName
                importRow.TrackTitleName = tag.TrackTitleName.Replace('�', char.MinValue);
                //ArtistName
                importRow.ArtistName = tag.ArtistName.Replace('�', char.MinValue);
                //ArtistID
                //AnimeNo
                //SalesYear
                importRow.SalesYear = tag.SalesYear.Replace('�', char.MinValue);
                //TrackLength
                importRow.TrackLength = tag.TrackLength.Replace('�', char.MinValue);
                //BitRate
                importRow.BitRate = tag.BitRate.TrimEnd('\0');
                importList.AddImportMusicListRow(importRow);
            }

            importList.AcceptChanges();

            DataView dv = importList.DefaultView;
            dv.Sort = "AlbumID asc , DiscNo asc , TrackNo asc";
            MusicDataSet.ImportMusicListDataTable newImportList = new MusicDataSet.ImportMusicListDataTable();
            newImportList.Merge(dv.ToTable());

            foreach (MusicDataSet.ImportMusicListRow ir in newImportList.Rows)
            {
                DataGridViewRow dr = MusicDataGridView.Rows[MusicDataGridView.Rows.Add()];

                dr.Cells[TRACKIDCLN].Value = ir.TrackID;
              if (ir.TrackTitleName != null)
                {
                    dr.Cells[TRACKNAMECLN].Value = ir.TrackTitleName.Replace('�', char.MinValue).Trim('\0');
                }
                dr.Cells[ALBUMIDCLN].Value = ir.AlbumID;
                if (ir.AlbumTitleName != null)
                {
                    dr.Cells[ALBUMNAMECLN].Value = ir.AlbumTitleName.Replace('�', char.MinValue).Trim('\0');
                }
                if (ir.ArtistName != null)
                {
                    dr.Cells[ARTISTNAMECLN].Value = ir.ArtistName.Replace('�', char.MinValue).Trim('\0');
                }
                if (ir.DiscNo != null)
                {
                    dr.Cells[DISCNOCLN].Value = ir.DiscNo.Replace('�', char.MinValue).Trim('\0');
                }
                if (ir.TrackNo != null)
                {
                    dr.Cells[TRACKNOCLN].Value = ir.TrackNo.Replace('�', char.MinValue).Trim('\0');
                }
                if (!ir.IsSalesYearNull())
                {
                    dr.Cells[YEARCLN].Value = ir.SalesYear.Replace('�', char.MinValue).Trim('\0');
                }
                if (!ir.IsDescriptionNull())
                {
                    dr.Cells[DESCRIPTIONCLN].Value = ir.Description;
                }
                if (!ir.IsBitRateNull())
                {
                    dr.Cells[BITRATECLN].Value = ir.BitRate;
                }
                if (!ir.IsTrackLengthNull())
                {
                    dr.Cells[TRACKTIMELENGTHCLN].Value = ir.TrackLength;
                }
                dr.Cells[RESOURCEPATHCLN].Value = ir.FilePath;

                //艺术家处理
                //Todo:预留同名artist处理机制:复数artist
                int artistID = service.GetArtistIDFromArtistName(ir.ArtistName);
                if (artistID > 0)
                {
                    //不在dic,在DB中存在名称完全相同,加入dic
                    dr.Cells[ARTISTIDCLN].Value = artistID;
                }

                SetArtistCellStyle(dr.Cells[ARTISTNAMECLN], ir.ArtistName);

                //MusicDataGridView.Sort(MusicDataGridView.Columns[ALBUMIDCLN], ListSortDirection.Ascending);
            }

            dgvStyle.SetDataGridViewColumnWidch(MusicDataGridView, new int[] {
                120,    //OldTrackNo
                100,    //TrackNo
                200,    //TrackName
                80,    //TrackType
                100,    //AlbumNo
                200,    //AlbumName
                80,     //AlbumType
                200,    //ArtistName
                120,    //AnimeCHNName
                80,     //BitRate
                70,     //DiscNo
                70,     //TrackNo
                120,    //Year
                100,    //TrackLength
                300,    //ResourcePath
                200     //Description
            });

            string firstRowPath = null;

            if (MusicDataGridView.Rows.Count != 0)
            {
                firstRowPath = MusicDataGridView.Rows[0].Cells[RESOURCEPATHCLN].Value.ToString();

                ShowMP3TagInfo(firstRowPath);
            }
        }