Exemplo n.º 1
0
        private void moveSongButton_Click(object sender, EventArgs e)
        {
            int selectedValue = ((SongPlacement)fromToComboBox.SelectedItem).PlacementValue;

            if (selectedValue == 0)
            {
                //Dont move
            }
            else if (selectedValue == 1)
            {
                //Move to before
                if (currentPart != null && currentSong != null)
                {
                    Workout.WorkoutPart part = ((Workout.WorkoutPart)workoutPartComboBox.SelectedItem);
                    Workout.WorkoutSong song = ((Workout.WorkoutSong)songComboBox.SelectedItem);

                    int currentIndex = part.Songs.IndexOf(song);

                    int currentPlacement = currentPart.Songs.IndexOf(currentSong);

                    currentPart.Songs.Remove(currentSong);

                    if (currentPart == part)
                    {
                        if (currentPlacement < currentIndex)
                        {
                            part.Songs.Insert(currentIndex - 1, currentSong);
                        }
                        else
                        {
                            part.Songs.Insert(currentIndex, currentSong);
                        }
                    }
                    else
                    {
                        if (currentIndex == -1)
                            part.Songs.Add(currentSong);
                        else
                            part.Songs.Insert(currentIndex, currentSong);
                    }
                    currentPart = part;

                    workoutPartComboBox_SelectedIndexChanged(workoutPartComboBox, EventArgs.Empty);
                }
            }
            else
            {

                Workout.WorkoutPart part = ((Workout.WorkoutPart)workoutPartComboBox.SelectedItem);
                Workout.WorkoutSong song = ((Workout.WorkoutSong)songComboBox.SelectedItem);

                int currentIndex = part.Songs.IndexOf(song);

                currentPart.Songs.Remove(currentSong);

                if (part == currentPart)
                {
                    if (currentIndex >= part.Songs.Count)
                        part.Songs.Add(currentSong);
                    else
                        part.Songs.Insert(currentIndex, currentSong);
                }
                else
                {
                    if (currentIndex >= part.Songs.Count)
                        part.Songs.Add(currentSong);
                    else
                        part.Songs.Insert(currentIndex + 1, currentSong);
                }
                currentPart = part;

                workoutPartComboBox_SelectedIndexChanged(workoutPartComboBox, EventArgs.Empty);
            }
        }
Exemplo n.º 2
0
        public void LoadPlacement(WorkoutCreator.Workout.Workout workout)
        {
            this.workout = workout;

            workoutPartComboBox.Items.Clear();
            workoutPartComboBox.DisplayMember = "Title";
            workoutPartComboBox.ValueMember = "Title";

            fromToComboBox.Items.Clear();

            fromToComboBox.DisplayMember = "Title";
            fromToComboBox.ValueMember = "PlacementValue";

            //fromToComboBox.Items.Add(new SongPlacement() { PlacementValue = 0, Title = "Flytta inte" });
            fromToComboBox.Items.Add(new SongPlacement() { PlacementValue = 1, Title = "Före vald låt" });
            fromToComboBox.Items.Add(new SongPlacement() { PlacementValue = 2, Title = "Efter vald låt" });
            fromToComboBox.SelectedIndex = 0;

            foreach (Workout.WorkoutPart part in workout.WorkoutParts)
            {
                workoutPartComboBox.Items.Add(part);

                Workout.WorkoutSong song = part.Songs.FirstOrDefault(x =>
                    x.Album == albumTextBox.Text &&
                    x.Artist == artistTextBox.Text &&
                    x.Bpm1 == bpm1TextBox.Text.ToInt() &&
                    x.Bpm2 == bpm2TextBox.Text.ToInt() &&
                    x.Description == descriptionTextBox.Text &&
                    x.FromTime == fromTimeTextBox.TotalSeconds &&
                    x.ToTime == toTimeTextBox.TotalSeconds &&
                    x.Title == titleTextBox.Text);

                if (song != null)
                {
                    currentSong = song;
                    currentPart = part;
                    workoutPartComboBox.SelectedItem = part;
                }
            }
        }