示例#1
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            IEditableCollectionViewAddNewItem viewToAddDisparateItems =
                catalogList.Items as IEditableCollectionViewAddNewItem;

            if (!viewToAddDisparateItems.CanAddNewItem)
            {
                MessageBox.Show("You cannot add items to the list.");
                return;
            }

            // Create a window that prompts the user to enter a new
            // item to sell.
            AddItemWindow win = new AddItemWindow();

            // Create an item, depending on which RadioButton is selected.
            // Radio buttons correspond to book, cd, dvd, or other.
            LibraryItem newItem;

            if ((bool)book.IsChecked)
            {
                newItem = new Book("Enter the book title", "Enter an Author", "Enter a Genre",
                                   "Enter a call number", DateTime.Now + new TimeSpan(21, 0, 0, 0));
            }
            else if ((bool)cd.IsChecked)
            {
                newItem = new MusicCD("Enter the Album", "Enter the artist", 0, "CD.******",
                                      DateTime.Now + new TimeSpan(14, 0, 0, 0));
            }

            else if ((bool)dvd.IsChecked)
            {
                newItem = new MovieDVD("Enter the movie title", "Enter the director",
                                       "Enter the genre", new TimeSpan(), "DVD.******",
                                       DateTime.Now + new TimeSpan(7, 0, 0, 0));
            }
            else
            {
                newItem = new LibraryItem("Enter the title", "Enter the call number",
                                          DateTime.Now + new TimeSpan(14, 0, 0, 0));
            }

            // Add the new item to the collection by calling
            // IEditableCollectionViewAddNewItem.AddNewItem.
            // Set the DataContext of the AddItemWindow to the
            // returned item.
            win.DataContext = viewToAddDisparateItems.AddNewItem(newItem);

            // If the user submits the new item, commit the new
            // object to the collection.  If the user cancels
            // adding the new item, discard the new item.
            if ((bool)win.ShowDialog())
            {
                viewToAddDisparateItems.CommitNew();
            }
            else
            {
                viewToAddDisparateItems.CancelNew();
            }
        }
示例#2
0
        private async Task <bool> SaveChangesAsync()
        {
            try
            {
                if (this.CurrentSession != null)
                {
                    var session = this.CurrentSession;
                    if (_editView.IsAddingNew && this.CurrentSession != _editView.CurrentAddItem)
                    {
                        return(true);
                    }
                    if (_hasChanges || _editView.IsAddingNew)
                    {
                        if (!this.Validate())
                        {
                            return(false);
                        }

                        _isChanging      = true;
                        this.IsBusy      = true;
                        session.TrackIds = new ObservableCollection <int>();
                        foreach (var uitrack in _uiTrackList)
                        {
                            if (uitrack.IsChecked)
                            {
                                session.TrackIds.Add(uitrack.Track.Id);
                            }
                        }

                        if (_editView.IsAddingNew)
                        {
                            var newSession = await _sessionService.AddSessionAsync(session);

                            session.SessionBaseId = newSession.SessionBaseId;
                            _editView.CommitNew();
                        }
                        else
                        {
                            await _sessionService.UpdateSessionAsync(session);
                        }
                        session.Speaker1  = (from s in _speakerList where s.Id == session.Speaker1Id select s).FirstOrDefault();
                        session.Speaker2  = (from s in _speakerList where s.Id == session.Speaker2Id select s).FirstOrDefault();
                        this.CurrentState = NORMAL_STATE;
                        this.IsBusy       = false;
                        _isChanging       = false;
                        _hasChanges       = false;
                    }
                    this.CurrentSession.PropertyChanged -= this.OnSessionPropertyChanged;
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
示例#3
0
 void VisualCanvas_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     if (IsEditable)
     {
         Mouse.Capture(this, CaptureMode.SubTree);
         this.IsDragStart = true;
         IEditableCollectionViewAddNewItem items = this.Items;
         StartMousePoint = e.GetPosition(sender as IInputElement);
         Debug.WriteLine(StartMousePoint);
         if (items.CanAddNewItem)
         {
             NewItem = items.AddNew();
             items.CommitNew();
             Canvas.SetLeft(NewCanvasItem, StartMousePoint.X);
             Canvas.SetTop(NewCanvasItem, StartMousePoint.Y);
         }
     }
 }
示例#4
0
        private async Task <bool> SaveChangesAsync()
        {
            try
            {
                if (this.CurrentSpeaker != null)
                {
                    this.CurrentSpeaker.PropertyChanged -= this.OnCurrentSpeakerPropertyChanged;
                    if (_editView.IsAddingNew && this.CurrentSpeaker != _editView.CurrentAddItem)
                    {
                        return(true);
                    }
                    if (_hasChanges || _editView.IsAddingNew)
                    {
                        if (!this.Validate())
                        {
                            return(false);
                        }
                        this.IsBusy = true;
                        var speaker = this.CurrentSpeaker;
                        if (_editView.IsAddingNew)
                        {
                            _isChanging = true;
                            var newSpeaker = await _sessionService.AddSpeakerAsync(speaker);

                            speaker.Id = newSpeaker.Id;
                            _editView.CommitNew();
                            _isChanging = false;
                        }
                        else
                        {
                            await _sessionService.UpdateSpeakerAsync(speaker);
                        }
                        this.CurrentState = NORMAL_STATE;
                    }
                }
                this.IsBusy = false;
                _hasChanges = false;
                return(true);
            }
            catch
            {
                return(false);
            }
        }