コード例 #1
0
        public override void Execute(object parameter)
        {
            var viewModel = (SongViewModel)parameter;
            var cloneSong = (Song)viewModel.SelectedSong.Clone();
            var sw        = new SongWindow();

            sw.DataContext = cloneSong;
            sw.ShowDialog();

            if (sw.DialogResult.HasValue && sw.DialogResult.Value)
            {
                viewModel.SelectedSong.Title  = cloneSong.Title;
                viewModel.SelectedSong.Artist = cloneSong.Artist;
                viewModel.SelectedSong.Album  = cloneSong.Album;
                viewModel.SelectedSong.Genre  = cloneSong.Genre;

                using (var db = new SongDbContext())
                {
                    var song = db.Songs.First(s => s.Id == cloneSong.Id);
                    song.Title  = cloneSong.Title;
                    song.Artist = cloneSong.Artist;
                    song.Album  = cloneSong.Album;
                    song.Genre  = cloneSong.Genre;

                    db.SaveChanges();
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Show dialog to modify an Instruction.
        /// </summary>
        /// <param name="ins">The Instruction being modified.</param>
        /// <param name="owner">The owner Window.</param>
        /// <returns>The modified Instruction.</returns>
        public static Instruction ShowDialog(Instruction ins, Window owner)
        {
            BaseParamWindow dlg = null;

            switch (ins.opcode)
            {
            case Instruction.MOVE:
                dlg = new MoveWindow();
                break;

            case Instruction.ROTATE:
                dlg = new RotateWindow();
                break;

            case Instruction.LED:
                dlg = new LedWindow();
                break;

            case Instruction.SONG:
                dlg = new SongWindow();
                break;

            case Instruction.DEMO:
                dlg = new DemoWindow();
                break;

            case Instruction.DRIVE:
                dlg = new DriveWindow();
                break;

            case Instruction.DELAY:
                dlg = new DelayWindow();
                break;
            }

            if (dlg != null)
            {
                dlg.Owner = owner;
                dlg.Ins   = ins;
                dlg.ShowDialog();

                // Alway read from the Window. There is no guarantee that the original Instruction is modified.
                Instruction result = dlg.Ins;
                Debug.WriteLine(result);
                return(dlg.Ins);
            }
            else
            {
                MessageBox.Show(ins.opcode + " no implemented.");
            }
            return(null);
        }
コード例 #3
0
        public override void Execute(object parameter)
        {
            var viewModel = (SongViewModel)parameter;
            var song      = new SongDb();


            var sw = new SongWindow();

            sw.DataContext = song;
            sw.ShowDialog();

            if (sw.DialogResult.HasValue && sw.DialogResult.Value)
            {
                using (var db = new SongDbContext())
                {
                    db.Songs.Add(song);
                    db.SaveChanges();
                }
                viewModel.Songs.Add(SongViewModel.SongConverter(song));
                viewModel.SelectedSong = SongViewModel.SongConverter(song);
            }
        }