示例#1
0
        protected virtual void DeleteButton_Click()
        {
            if (DataGrid.SelectedItem == null)
            {
                return;
            }

            string message        = null;
            bool   closeOnSuccess = false;

            if (typeof(T) == typeof(Publisher))
            {
                message = $"Are you sure you want to delete publisher '{DataGrid.SelectedItem as Publisher}'?\n\n"
                          + "WARNING! Deleting a publisher will delete all its publications!";
            }
            else if (typeof(T) == typeof(Employee))
            {
                message = $"Are you sure you want to delete employee {DataGrid.SelectedItem as Employee}?\n\n"
                          + "WARNING! Deleting an employee will delete all his user accounts!";
            }
            else if (typeof(T) == typeof(User))
            {
                var user = DataGrid.SelectedItem as User;
                if (user.Equals(EntitiesManager.CurrentUser))
                {
                    closeOnSuccess = true;
                    message        = $"Are you sure you want to delete the current logged-in user? (implies logout)";
                }
                else
                {
                    message = $"Are you sure you want to delete user '{DataGrid.SelectedItem as User}'?";
                }
            }
            else if (typeof(T) == typeof(LibraryItem))
            {
                message = $"Are you sure you want to delete {DataGrid.SelectedItem as LibraryItem}?";
            }
            else
            {
                message = $"Are you sure you want to delete selected {typeof(T).Name} (Id = {(DataGrid.SelectedItem as Entity<T>).EntityId()})?";
            }

            MessageBoxResult result = GUIUtils.ShowMessage(message, MessageBoxType.WarningQuestion);

            if (result.In(MessageBoxResult.Cancel, MessageBoxResult.No))
            {
                return;
            }

            if (EntitiesManager.Delete(DataGrid.SelectedItem as T) && closeOnSuccess)
            {
                Close();
            }
        }
        protected override void OnClosing(CancelEventArgs e)
        {
            base.OnClosing(e);

            if (btnSave.IsEnabled)
            {
                MessageBoxResult result =
                    GUIUtils.ShowMessage("Are you sure you want to leave without saving?",
                                         MessageBoxType.Question);

                if (result.In(MessageBoxResult.Cancel, MessageBoxResult.No))
                {
                    e.Cancel = true;
                }
            }
        }