Beispiel #1
0
        void bwCDList_DoWork(object sender, DoWorkEventArgs e)
        {
            SafeObservableCollection <AlbumItem> items = new SafeObservableCollection <AlbumItem>();

            int count = 0;

            Big3.Hitbase.DataBaseEngine.Condition searchCondition = Big3.Hitbase.DataBaseEngine.Condition.Combine(Condition, ConditionFromTree);

            using (DataBaseView view = AlbumView.CreateView(this.DataBase, this.CdListFields.GetFields(), new SortFieldCollection(), 0, searchCondition))
            {
                object[] values;

                while ((values = view.Read()) != null)
                {
                    AlbumItem newItem = new AlbumItem();
                    newItem.ID = (int)values[0];

                    newItem.Items = new object[values.Length - 1];
                    FillRowValues(newItem, values);
                    items.AddItemFromThread(newItem);

                    count++;
                }
            }

            e.Result = items;
        }
Beispiel #2
0
        private void dataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            if (VisualTreeExtensions.FindParent <DataGridRow>(e.OriginalSource as DependencyObject) != null)
            {
                AlbumListItem item = dataGrid.SelectedItem as AlbumListItem;
                if (item != null)
                {
                    switch (CurrentViewMode)
                    {
                    case CurrentViewMode.MediumTable:
                    {
                        ChangeViewCommandParameters changeViewParams = new ChangeViewCommandParameters();
                        changeViewParams.ViewMode = MainControls.CurrentViewMode.AlbumTable;

                        Big3.Hitbase.DataBaseEngine.Condition condition = new Big3.Hitbase.DataBaseEngine.Condition();
                        condition.Add(new SingleCondition(Field.Medium, Operator.Equal, item.Title));
                        changeViewParams.Condition = condition;

                        CatalogViewCommands.ChangeView.Execute(changeViewParams, this);
                        break;
                    }
                    }
                }
            }
        }
        public void Restore(RegistryKey regKey)
        {
            string xml = (string)regKey.GetValue("ConditionFromTree", "");

            XmlSerializer xmlSerializer = new XmlSerializer(typeof(Big3.Hitbase.DataBaseEngine.Condition));

            using (StringReader sr = new StringReader(xml))
            {
                Big3.Hitbase.DataBaseEngine.Condition condition = (Big3.Hitbase.DataBaseEngine.Condition)xmlSerializer.Deserialize(sr);

                int viewMode = (int)regKey.GetValue("CurrentViewMode", 0);
                CurrentViewMode        = (CurrentViewMode)viewMode;
                this.ConditionFromTree = condition;
                FillList();
            }
        }
        void bwTrackList_DoWork(object sender, DoWorkEventArgs e)
        {
            SafeObservableCollection <MyMusicListItem> items = new SafeObservableCollection <MyMusicListItem>();

            int count = 0;

            FieldCollection fc = new FieldCollection();

            int internalFieldsCount = 0;

            foreach (Field field in internalFields)
            {
                if (this.trackListFields.SingleOrDefault(x => x.Field == field) == null)
                {
                    fc.Add(field);
                    internalFieldsCount++;
                }
            }

            fc.AddRange(this.trackListFields.GetFields());

            int soundFileIndex = fc.IndexOf(Field.TrackSoundFile);

            Big3.Hitbase.DataBaseEngine.Condition searchCondition = Big3.Hitbase.DataBaseEngine.Condition.Combine(Condition, ConditionFromTree);

            using (DataBaseView view = TrackView.CreateView(this.DataBase, fc, this.trackListSort, 0, searchCondition))
            {
                object[] values;

                while ((values = view.Read()) != null)
                {
                    MyMusicListItem newItem = new MyMusicListItem();

                    FillRowValues(newItem, values, soundFileIndex, internalFieldsCount);
                    items.AddItemFromThread(newItem);

                    count++;
                }
            }

            e.Result = items;
        }
        void bwTrackList_DoWork(object sender, DoWorkEventArgs e)
        {
            string sql = "";

            Big3.Hitbase.DataBaseEngine.Condition searchCondition = Big3.Hitbase.DataBaseEngine.Condition.Combine(Condition, ConditionFromTree);

            switch (CurrentViewMode)
            {
            case MainControls.CurrentViewMode.ArtistTable:
                sql = "SELECT PersonGroup.Name, COUNT(*) AS TotalCount, SUM(Cast(Track.Length as bigint)) AS TotalLength " +
                      "FROM Track INNER JOIN " +
                      "PersonGroup ON Track.ArtistID = PersonGroup.PersonGroupID " +
                      "GROUP BY PersonGroup.Name, PersonGroup.SaveAs";
                if (searchCondition != null && searchCondition.Count > 0)
                {
                    if (searchCondition[0].Value.ToString() == "?")
                    {
                        sql += " HAVING PersonGroup.SaveAs < 'A' OR PersonGroup.SaveAs > 'ZZZZZ'";
                    }
                    else
                    {
                        sql += " HAVING PersonGroup.SaveAs >= '" + searchCondition[0].Value + "' AND PersonGroup.SaveAs < '" + searchCondition[0].Value + "ZZZZZ'";
                    }
                }

                sql += " ORDER BY PersonGroup.SaveAs";

                break;

            case MainControls.CurrentViewMode.ComposerTable:
                sql = "SELECT PersonGroup.Name, COUNT(*) AS TotalCount, SUM(Cast(Track.Length as bigint)) AS TotalLength " +
                      "FROM Track INNER JOIN " +
                      "PersonGroup ON Track.ComposerID = PersonGroup.PersonGroupID " +
                      "GROUP BY PersonGroup.Name, PersonGroup.SaveAs ";
                if (searchCondition != null && searchCondition.Count > 0)
                {
                    if (searchCondition[0].Value.ToString() == "?")
                    {
                        sql += " HAVING PersonGroup.SaveAs < 'A' OR PersonGroup.SaveAs > 'ZZZZZ'";
                    }
                    else
                    {
                        sql += " HAVING PersonGroup.SaveAs >= '" + searchCondition[0].Value + "' AND PersonGroup.SaveAs < '" + searchCondition[0].Value + "ZZZZZ'";
                    }
                }

                sql += " ORDER BY PersonGroup.SaveAs";

                break;

            case MainControls.CurrentViewMode.GenreTable:
                sql = "SELECT Category.Name, COUNT(*) AS TotalCount, SUM(Cast(Track.Length as bigint)) AS TotalLength " +
                      "FROM Track LEFT JOIN " +
                      "CD ON Track.CDID = CD.CDID LEFT JOIN " +
                      "Category ON Track.CategoryID = Category.CategoryID OR CD.CategoryID = Category.CategoryID " +
                      "GROUP BY Category.Name";
                if (searchCondition != null && searchCondition.Count > 0)
                {
                    sql += " HAVING Category.Name LIKE '" + searchCondition[0].Value + "%'";
                }
                break;

            case MainControls.CurrentViewMode.MediumTable:
                sql = "SELECT Medium.Name, COUNT(*) AS TotalCount, SUM(Cast(Track.Length as bigint)) AS TotalLength " +
                      "FROM Track INNER JOIN " +
                      "CD ON Track.CDID = CD.CDID LEFT JOIN " +
                      "Medium ON CD.MediumID = Medium.MediumID " +
                      "GROUP BY Medium.Name";
                if (searchCondition != null && searchCondition.Count > 0)
                {
                    sql += " HAVING Medium.Name LIKE '" + searchCondition[0].Value + "%'";
                }
                break;

            case MainControls.CurrentViewMode.YearTable:
                sql = "SELECT Track.YearRecorded, COUNT(*) AS TotalCount, SUM(CAST(Track.Length as bigint)) AS TotalLength " +
                      "FROM Track " +
                      "GROUP BY Track.YearRecorded";
                if (searchCondition != null && searchCondition.Count > 0)
                {
                    if (searchCondition.Count > 1)
                    {
                        sql += " HAVING Track.YearRecorded >= " + searchCondition[0].Value + " AND Track.YearRecorded < " + searchCondition[1].Value;
                    }
                    else
                    {
                        sql += " HAVING Track.YearRecorded=" + searchCondition[0].Value + "";
                    }
                }
                break;

            case MainControls.CurrentViewMode.RatingTable:
                sql = "SELECT Track.Rating, COUNT(*) AS TotalCount, SUM(CAST(Track.Length as bigint)) AS TotalLength " +
                      "FROM Track " +
                      "GROUP BY Track.Rating";
                if (searchCondition != null && searchCondition.Count > 0 && searchCondition[0].Value != null)
                {
                    sql += " HAVING Track.Rating = " + searchCondition[0].Value + "";
                }
                break;
            }

            SafeObservableCollection <TrackListItem> items     = new SafeObservableCollection <TrackListItem>();
            Dictionary <string, TrackListItem>       dictItems = new Dictionary <string, TrackListItem>(); // Für schnelleren Zugriff

            using (DataBaseView view = DataBaseView.Create(this.DataBase, sql))
            {
                object[] values;

                while ((values = view.Read()) != null)
                {
                    TrackListItem trackListItem = new TrackListItem();
                    trackListItem.Title = values[0].ToString();
                    if (CurrentViewMode == MainControls.CurrentViewMode.YearTable && trackListItem.Title == "0")
                    {
                        trackListItem.Title = StringTable.Undefined;
                    }

                    trackListItem.Count  = (int)values[1];
                    trackListItem.Length = (long)values[2];
                    trackListItem.Rating = 0;
                    dictItems.Add(trackListItem.Title, trackListItem);
                    items.AddItemFromThread(trackListItem);
                }
            }

            // Rating ermitteln
            sql = "";
            switch (CurrentViewMode)
            {
            case MainControls.CurrentViewMode.ArtistTable:
            {
                sql = "SELECT PersonGroup.Name, AVG(CAST(Track.Rating AS decimal)) AS Expr3, PersonGroup.SaveAs " +
                      "FROM Track INNER JOIN " +
                      "PersonGroup ON Track.ArtistID = PersonGroup.PersonGroupID " +
                      "WHERE (Track.Rating > 0) " +
                      "GROUP BY PersonGroup.Name, PersonGroup.SaveAs";
                break;
            }

            case MainControls.CurrentViewMode.ComposerTable:
            {
                sql = "SELECT PersonGroup.Name, AVG(CAST(Track.Rating AS decimal)) AS Expr3 " +
                      "FROM Track INNER JOIN " +
                      "PersonGroup ON Track.ComposerID = PersonGroup.PersonGroupID " +
                      "WHERE (Track.Rating > 0) " +
                      "GROUP BY PersonGroup.Name";
                break;
            }

            case MainControls.CurrentViewMode.GenreTable:
            {
                sql = "SELECT category.Name, AVG(CAST(Track.Rating AS decimal)) AS Expr3 " +
                      "FROM Track LEFT JOIN " +
                      "CD ON Track.CDID = CD.CDID LEFT JOIN " +
                      "Category AS Category ON Track.CategoryID = Category.CategoryID OR CD.CategoryID = Category.CategoryID " +
                      "WHERE        (Track.Rating > 0) " +
                      "GROUP BY Category.Name";

                break;
            }

            case MainControls.CurrentViewMode.YearTable:
            {
                sql = "SELECT Track.YearRecorded, AVG(CAST(Track.Rating AS decimal)) AS Expr3 " +
                      "FROM Track " +
                      "WHERE        (Track.Rating > 0) " +
                      "GROUP BY Track.YearRecorded";

                break;
            }
            }

            if (sql != "")
            {
                using (DataBaseView view = DataBaseView.Create(this.DataBase, sql))
                {
                    object[] values;

                    while ((values = view.Read()) != null)
                    {
                        string key = values[0].ToString();

                        if (CurrentViewMode == MainControls.CurrentViewMode.YearTable && key == "0")
                        {
                            key = StringTable.Undefined;
                        }

                        if (dictItems.ContainsKey(key))
                        {
                            TrackListItem trackListItem = dictItems[key];
                            trackListItem.Rating = (double)(decimal)values[1];
                        }
                    }
                }
            }

            e.Result = items;
        }
        private void Search()
        {
            Big3.Hitbase.DataBaseEngine.Condition sel = new Big3.Hitbase.DataBaseEngine.Condition();

            // Diese Sachen direkt speichern, wenn einmal gesucht wurde.
            Settings.SetValue("LinkSameNumber", checkBoxSameTrackCount.IsChecked == true ? (int)1 : (int)0);
            Settings.SetValue("LinkNotLinked", checkBoxNotAssigned.IsChecked == true ? (int)1 : (int)0);

            // Nur CDs.
            sel.Add(Field.AlbumType, Operator.Equal, 0);

            if (this.checkBoxNotAssigned.IsChecked == true)
            {
                sel.Add(Field.Identity, Operator.Empty, 0);
            }

            if (this.checkBoxSameTrackCount.IsChecked == true)
            {
                sel.Add(Field.NumberOfTracks, Operator.Equal, cdInDrive.NumberOfTracks);
            }

            if (textBoxArtist.Text != "")
            {
                sel.Add(Field.ArtistCDName, Operator.Contains, textBoxArtist.Text);
            }

            if (textBoxTitle.Text != "")
            {
                sel.Add(Field.Title, Operator.Contains, textBoxTitle.Text);
            }

            SortFieldCollection sortKeys = new SortFieldCollection();

            sortKeys.Add(Field.ArtistCDName);
            sortKeys.Add(Field.Title);

            FieldCollection fc = new FieldCollection();

            fc.Add(Field.ArtistCDName);
            fc.Add(Field.Title);
            fc.Add(Field.TotalLength);
            fc.Add(Field.NumberOfTracks);

            List <CDItemResult> items = new List <CDItemResult>();

            using (DataBaseView albumView = AlbumView.CreateView(dataBase, fc, sortKeys, 0, sel))
            {
                object[] values;

                while ((values = albumView.Read()) != null)
                {
                    CDItemResult newItem = new CDItemResult();
                    newItem.CDID           = (int)values[0];
                    newItem.Artist         = (string)values[1];
                    newItem.Title          = values[2] is DBNull ? "" : (string)values[2];
                    newItem.Length         = (int)values[3];
                    newItem.NumberOfTracks = (int)values[4];

                    items.Add(newItem);
                }
            }

            DataGridResult.ItemsSource = items;

            return;
        }
Beispiel #7
0
        void bwAlbumView_DoWork(object sender, DoWorkEventArgs e)
        {
            FieldCollection fc = new FieldCollection();

            fc.AddRange(new Field[] { Field.CDID, Field.Title, Field.ArchiveNumber, Field.CDCoverFront, Field.YearRecorded,
                                      Field.TrackNumber, Field.TrackTitle, Field.TrackLength, Field.TrackRating, Field.TrackSoundFile,
                                      Field.ArtistCDName, Field.ArtistCDSaveAs, Field.ArtistTrackName, Field.Category, Field.ComposerTrackName });

            int count = 0;

            SortFieldCollection sfc = new SortFieldCollection();

            sfc.Add(Field.ArtistCDSaveAs);
            sfc.Add(Field.Title);
            sfc.Add(Field.CDID);
            // Die Verzeichnisansicht immer sortiert nach Dateiname
            if (this.ShowItemType == ShowItemType.Directory)
            {
                sfc.Add(Field.TrackSoundFile);
            }
            else
            {
                sfc.Add(Field.TrackNumber);
            }

            SafeObservableCollection <AlbumViewItemBase> items = new SafeObservableCollection <AlbumViewItemBase>();

            AlbumViewItem newItem         = null;
            string        lastArtist      = "";
            string        lastArtistTitle = "";
            string        lastTitle       = "";
            int           lastcdid        = 0;

            Big3.Hitbase.DataBaseEngine.Condition searchCondition = Big3.Hitbase.DataBaseEngine.Condition.Combine(Condition, ConditionFromTree);

            using (DataBaseView view = TrackView.CreateView(DataBase, fc, sfc, 0, searchCondition))
            {
                // Überall auf die Indizes 1 addieren, da die erste Spalte die TrackID ist.
                int colArtistName     = fc.IndexOf(Field.ArtistCDName) + 1;
                int colArtistSaveAs   = fc.IndexOf(Field.ArtistCDSaveAs) + 1;
                int colTitle          = fc.IndexOf(Field.Title) + 1;
                int colCDID           = fc.IndexOf(Field.CDID) + 1;
                int colFrontCover     = fc.IndexOf(Field.CDCoverFront) + 1;
                int colCategory       = fc.IndexOf(Field.Category) + 1;
                int colArchiveNumber  = fc.IndexOf(Field.ArchiveNumber) + 1;
                int colYearRecorded   = fc.IndexOf(Field.YearRecorded) + 1;
                int colTrackNumber    = fc.IndexOf(Field.TrackNumber) + 1;
                int colTrackTitle     = fc.IndexOf(Field.TrackTitle) + 1;
                int colTrackLength    = fc.IndexOf(Field.TrackLength) + 1;
                int colTrackRating    = fc.IndexOf(Field.TrackRating) + 1;
                int colTrackArtist    = fc.IndexOf(Field.ArtistTrackName) + 1;
                int colTrackComposer  = fc.IndexOf(Field.ComposerTrackName) + 1;
                int colTrackSoundFile = fc.IndexOf(Field.TrackSoundFile) + 1;
                int colTrackID        = 0;

                object[] values;

                while ((values = view.Read()) != null)
                {
                    string artistDisplay = values[colArtistName] is DBNull ? "" : (string)values[colArtistName];
                    string artist        = values[colArtistSaveAs] is DBNull ? "" : (string)values[colArtistSaveAs];
                    string title         = values[colTitle] is DBNull ? "" : (string)values[colTitle];
                    int    cdid          = (int)values[colCDID];

                    if (cdid != lastcdid)
                    {
                        if (newItem != null)
                        {
                            if (newItem.Artist != lastArtistTitle)
                            {
                                AlbumViewTitle albumTitle = new AlbumViewTitle();
                                albumTitle.Title = newItem.Artist;
                                items.Add(albumTitle);

                                lastArtistTitle = newItem.Artist;
                            }

                            items.Add(newItem);
                        }

                        newItem               = new AlbumViewItem();
                        newItem.ID            = cdid;
                        newItem.Artist        = artistDisplay;
                        newItem.Title         = title;
                        newItem.ImageFilename = values[colFrontCover] is DBNull ? "" : (string)values[colFrontCover];
                        newItem.Genre         = values[colCategory] is DBNull ? "" : (string)values[colCategory];
                        newItem.ArchiveNumber = values[colArchiveNumber] is DBNull ? "" : (string)values[colArchiveNumber];
                        int yearRecorded = values[colYearRecorded] is DBNull ? 0 : (int)values[colYearRecorded];
                        if (yearRecorded > 0)
                        {
                            newItem.Year = yearRecorded.ToString();
                        }

                        newItem.Tracks = new SafeObservableCollection <Track>();
                        lastArtist     = artist;
                        lastTitle      = title;
                    }

                    if (newItem != null)
                    {
                        Track track = new Track();
                        track.TrackNumber = (int)values[colTrackNumber];
                        track.Title       = values[colTrackTitle] is DBNull ? "" : (string)values[colTrackTitle];
                        track.Length      = (int)values[colTrackLength];
                        track.Rating      = values[colTrackRating] is DBNull ? 0 : (int)values[colTrackRating];
                        track.Artist      = values[colTrackArtist] is DBNull ? "" : (string)values[colTrackArtist];
                        track.Composer    = values[colTrackComposer] is DBNull ? "" : (string)values[colTrackComposer];
                        track.Soundfile   = values[colTrackSoundFile] is DBNull ? "" : (string)values[colTrackSoundFile];
                        track.CDID        = cdid;
                        track.ID          = (int)values[colTrackID];

                        newItem.Tracks.Add(track);
                    }

                    //toolStripStatusProgressBar.Value = (int)(100.0 / TrackView.Rows.Count * count);

                    count++;

                    lastcdid = cdid;
                }
            }


            if (newItem != null)
            {
                if (newItem.Artist != lastArtistTitle)
                {
                    AlbumViewTitle albumTitle = new AlbumViewTitle();
                    albumTitle.Title = newItem.Artist;
                    items.Add(albumTitle);
                }

                items.Add(newItem);
            }

            e.Result = items;
        }