Example #1
0
    private void ExecuteSelectPreviousPage( object sender, ExecutedRoutedEventArgs e )
    {
      WizardPage previousPage = null;

      if( CurrentPage != null )
      {
        var eventArgs = new CancelRoutedEventArgs( PreviousEvent );
        this.RaiseEvent( eventArgs );
        if( eventArgs.Cancel )
          return;

        //check previous page
        if( CurrentPage.PreviousPage != null )
          previousPage = CurrentPage.PreviousPage;
        else
        {
          //no previous page defined so use index
          var currentIndex = Items.IndexOf( CurrentPage );
          var previousPageIndex = currentIndex - 1;
          if( previousPageIndex >= 0 && previousPageIndex < Items.Count )
            previousPage = Items[ previousPageIndex ] as WizardPage;
        }
      }

      CurrentPage = previousPage;
    }
Example #2
0
    protected virtual void OnDeleteExecuted( object sender, ExecutedRoutedEventArgs e )
    {
      CancelRoutedEventArgs args = new CancelRoutedEventArgs( DataGridControl.DeletingSelectedItemsEvent, this );
      this.OnDeletingSelectedItems( args );

      if( args.Cancel )
        return;

      // Copy the selected item in a temp hashtable.
      List<KeyValuePair<DataGridContext, object[]>> selectedItemList = new List<KeyValuePair<DataGridContext, object[]>>();

      for( int i = m_selectedContexts.Count - 1; i >= 0; i-- )
      {
        DataGridContext selectedContext = m_selectedContexts[ i ];
        IList<object> sourceSelectedItems = selectedContext.SelectedItems;
        object[] clonedSelectedItems = new object[ sourceSelectedItems.Count ];
        sourceSelectedItems.CopyTo( clonedSelectedItems, 0 );
        selectedItemList.Add( new KeyValuePair<DataGridContext, object[]>( selectedContext, clonedSelectedItems ) );
      }

      bool raiseItemDeleted = false;

      // Delete the selected item
      foreach( KeyValuePair<DataGridContext, object[]> keyValuePair in selectedItemList )
      {
        DataGridContext dataGridContext = keyValuePair.Key;
        object[] selectedItems = keyValuePair.Value;

        if( ( !dataGridContext.IsDeleteCommandEnabled ) || ( selectedItems.Length == 0 ) )
          continue;

        DataGridCollectionViewBase dataGridCollectionViewBase =
          dataGridContext.ItemsSourceCollection as DataGridCollectionViewBase;

        IList list = ( dataGridCollectionViewBase == null )
          ? ItemsSourceHelper.TryGetIList( dataGridContext.ItemsSourceCollection )
          : null; // If we already have a DataGridCollectionView, no need to look for an IList source.

        if( ( dataGridCollectionViewBase != null )
          || ( ( list != null ) && DataGridControl.IsRemoveAllowedForDeleteCommand( list ) ) )
        {
          foreach( object item in selectedItems )
          {
            bool retry = false;

            do
            {
              try
              {
                int itemIndex;

                if( dataGridCollectionViewBase != null )
                {
                  itemIndex = dataGridCollectionViewBase.IndexOf( item );

                  if( itemIndex != -1 )
                    dataGridCollectionViewBase.RemoveAt( itemIndex );
                }
                else if( list != null )
                {
                  itemIndex = list.IndexOf( item );

                  if( itemIndex != -1 )
                    list.RemoveAt( itemIndex );
                }

                retry = false;
                raiseItemDeleted = true;
              }
              catch( Exception ex )
              {
                DeletingSelectedItemErrorRoutedEventArgs deletingItemErrorArgs = new DeletingSelectedItemErrorRoutedEventArgs( item, ex, DataGridControl.DeletingSelectedItemErrorEvent, this );
                this.OnDeletingSelectedItemError( deletingItemErrorArgs );

                switch( deletingItemErrorArgs.Action )
                {
                  case DeletingSelectedItemErrorAction.Abort:
                    return;

                  default:
                    retry = ( deletingItemErrorArgs.Action == DeletingSelectedItemErrorAction.Retry );
                    break;
                }
              }
            }
            while( retry );
          }
        }
      }

      if( raiseItemDeleted )
        this.OnSelectedItemsDeleted();
    }
Example #3
0
    private void ExecuteSelectNextPage( object sender, ExecutedRoutedEventArgs e )
    {
      WizardPage nextPage = null;

      if( CurrentPage != null )
      {
        var eventArgs = new CancelRoutedEventArgs( NextEvent );
        this.RaiseEvent( eventArgs );
        if( eventArgs.Cancel )
          return;

        //check next page
        if( CurrentPage.NextPage != null )
          nextPage = CurrentPage.NextPage;
        else
        {
          //no next page defined use index
          var currentIndex = Items.IndexOf( CurrentPage );
          var nextPageIndex = currentIndex + 1;
          if( nextPageIndex < Items.Count )
            nextPage = Items[ nextPageIndex ] as WizardPage;
        }
      }

      CurrentPage = nextPage;
    }
Example #4
0
    public void EndEdit()
    {
      if( !this.IsBeingEdited )
        return;

      if( this.IsEndingEdition )
        throw new InvalidOperationException( "An attempt was made to end the edit process while it is already in the process of being ended." );

      if( this.IsCancelingEdition )
        throw new InvalidOperationException( "An attempt was made to end the edit process while it is being canceled." );

      CancelRoutedEventArgs e = new CancelRoutedEventArgs( Row.EditEndingEvent, this );

      try
      {
        this.OnEditEnding( e );

        if( e.Cancel )
          throw new DataGridValidationException( "EndEdit was canceled." );
      }
      catch( Exception exception )
      {
        // This method will set a validation error on the row and throw back a DataGridValidationException so that 
        // the row stays in edition.
        Row.SetRowValidationErrorOnException( this, exception );
      }

      this.IsEndingEdition = true;

      try
      {
        DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );

        if( dataGridContext == null )
        {
          Debug.Fail( "DataGridContext cannot be null." );
          return;
        }

        IDisposable deferRefresh = ( this is DataRow )
          ? DataRow.DeferCollectionViewRefresh( dataGridContext ) : null;

        try
        {
          this.EndEditCore();
          this.TerminateEditionFromEndEdit();
        }
        finally
        {
          if( deferRefresh != null )
          {
            deferRefresh.Dispose();
          }
        }

        this.PreEditEnded();

        // Item validation has passed if we reached this far.  
        // Since it is the Row's HasValidationError which drives the error styles, setting 
        // the ItemValidationError to null will not get in the way of the row's cells validation.
        this.SetValidationError( null );

      }
      finally
      {
        this.IsEndingEdition = false;
      }

      this.OnEditEnded();
    }
Example #5
0
 protected virtual void OnDeletingSelectedItems( CancelRoutedEventArgs e )
 {
   this.RaiseEvent( e );
 }
Example #6
0
    public void BeginEdit()
    {
      if( this.IsBeingEdited )
        return;

      // If there is no dataItem mapped to this container, we don't want to
      // enter in edition
      DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );

      if( dataGridContext != null )
      {
        object dataItem = dataGridContext.GetItemFromContainer( this );

        if( dataItem == null )
          return;
      }

      // We must prevent entering in edition of an EmptyDataItem.
      if( this.DataContext is EmptyDataItem )
        return;

      Debug.Assert( this.IsContainerPrepared, "Can't edit a container that has not been prepared." );

      if( this.ReadOnly )
        throw new DataGridException( "An attempt was made to edit a read-only row." );

      if( this.IsBeginningEdition )
        throw new DataGridException( "An attempt was made to edit a row for which the edit process has already begun." );

      this.IsBeginningEdition = true;

      try
      {
        if( !this.IsBeginningEditFromCell )
        {
          CancelRoutedEventArgs e = new CancelRoutedEventArgs( Row.EditBeginningEvent, this );
          this.OnEditBeginning( e );

          if( e.Cancel )
            throw new DataGridException( "BeginEdit was canceled." );
        }

        // We must update the CellStates before calling BeginEditCore to ensure we have the
        // values that are currently present in the Cells before entering in edition.
        DataGridControl gridControl = ( dataGridContext != null )
          ? dataGridContext.DataGridControl
          : null;

        // This call will also validate that we're not starting a second row edition.
        // It will also save the row state and update the columns' CurrentRowInEditionCellState.
        if( gridControl != null )
          gridControl.UpdateCurrentRowInEditionCellStates( this, this.DataContext );

        this.SetIsBeingEdited( true );

        try
        {
          this.BeginEditCore();
        }
        catch
        {
          this.SetIsBeingEdited( false );

          // Ensure to clear the CellStates
          if( gridControl != null )
            gridControl.UpdateCurrentRowInEditionCellStates( null, null );

          throw;
        }
      }
      finally
      {
        this.IsBeginningEdition = false;
      }

      if( !this.IsBeginningEditFromCell )
        this.OnEditBegun();
    }
Example #7
0
 protected virtual void OnEditEnding( CancelRoutedEventArgs e )
 {
   this.RaiseEvent( e );
 }
Example #8
0
    internal void EndEdit( bool validateCellEditorRules, bool validateUIRules, bool updateContentBindingSource )
    {
      if( !this.IsBeingEdited )
        return;

      CancelRoutedEventArgs e = new CancelRoutedEventArgs( Cell.EditEndingEvent, this );

      try
      {
        this.OnEditEnding( e );

        // Throwing a DataGridValidationException will be caught by the grid and will make the cell stay in edition.
        if( e.Cancel )
          throw new DataGridValidationException( "EndEdit was canceled." );

        //There is an identified weakness with the IsKeyboardFocusWithin property where it cannot tell if the focus is within a Popup which is within the element
        //This has been identified, and only the places where it caused problems were fixed... This comment is only here to remind developpers of the flaw
        if( ( !this.IsKeyboardFocused ) && ( this.IsKeyboardFocusWithin ) )
        {
          DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );

          if( ( dataGridContext != null ) && ( !dataGridContext.DataGridControl.IsSetFocusInhibited ) )
          {
            // Prevent the focus to make a RequestBringIntoView
            using( this.InhibitMakeVisible() )
            {
              // We want to try to focus the Cell before we continue the EndEdit to ensure 
              // any validation or process in the lost focus is done
              if( !dataGridContext.DataGridControl.SetFocusHelper( m_parentRow, m_parentColumn, false, false ) )
                throw new DataGridFocusException( "Unable to set focus on the Cell." );
            }
          }
        }
      }
      catch( Exception exception )
      {
        if( exception is TargetInvocationException )
          exception = exception.InnerException;

        // In the case it's the focus that failed, we don't want to make that a ValidationError since it 
        // must be retained by the editor itself with his own error mechanic.
        //
        // Also, for example, clicking on another cell will trigger the lost focus first and editor 
        // will retain focus without any EndEdit being called and without any error displayed by the grid.  
        // So with that focus exception we make sure the behaviour is uniform.
        if( exception is DataGridFocusException )
          throw;

        this.SetValidationError( new CellValidationError(
          Cell.CustomCellValidationExceptionValidationRule,
          this,
          exception.Message,
          exception ) );

        // Throwing a DataGridValidationException will be caught by the grid and will make the cell stay in edition.
        throw new DataGridValidationException( "An error occurred while attempting to end the edit process.", exception );
      }

      Exception notUsed;
      CellValidationRule ruleInError;

      ValidationResult result =
        this.ValidateAndSetAllErrors( validateCellEditorRules, validateUIRules, updateContentBindingSource, true, out notUsed, out ruleInError );


      CellState cellState = this.GetEditCachedState();

      if( cellState != null )
      {
        if( result.IsValid )
          cellState.SetContentBeforeCellEdition( DependencyProperty.UnsetValue );

        cellState.SetIsDirtyBeforeEdition( null );
      }

      this.SetIsBeingEdited( false );
      this.OnEditEnded();
    }
Example #9
0
 protected internal virtual void OnEditBeginning( CancelRoutedEventArgs e )
 {
   this.RaiseEvent( e );
 }
Example #10
0
    public void BeginEdit()
    {
      if( this.IsBeingEdited )
        return;

      bool readOnly = this.GetInheritedReadOnly();

      if( readOnly )
        throw new DataGridException( "An attempt was made to edit a read-only cell or the cell content is not bound using two way binding." );

      // If there is no dataItem mapped to this container, we don't want to
      // enter in edition
      DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );

      if( dataGridContext != null )
      {
        object dataItem = dataGridContext.GetItemFromContainer( this );

        if( dataItem == null )
          return;
      }

      Debug.Assert( this.IsContainerPrepared, "Can't edit a cell that has not been prepared." );

      Row parentRow = this.ParentRow;

      try
      {
        if( !parentRow.IsBeingEdited )
        {
          // Prevent the Row Beginning and Begun events from being raised.  The cell will handle them in order
          // to maintain the same logical order as in other scenarios.
          parentRow.IsBeginningEditFromCell = true;

          CancelRoutedEventArgs rowCancelEventArgs = new CancelRoutedEventArgs( Row.EditBeginningEvent, parentRow );
          parentRow.OnEditBeginning( rowCancelEventArgs );

          if( rowCancelEventArgs.Cancel )
            throw new DataGridException( "BeginEdit was canceled." );
        }

        CancelRoutedEventArgs e = new CancelRoutedEventArgs( Cell.EditBeginningEvent, this );
        this.OnEditBeginning( e );

        if( e.Cancel )
          throw new DataGridException( "BeginEdit was canceled." );

        if( !this.IsCurrent )
        {
          dataGridContext.SetCurrent(
            dataGridContext.GetItemFromContainer( parentRow ),
            parentRow, DataGridVirtualizingPanel.GetItemIndex( parentRow ),
            this.ParentColumn, false, true, dataGridContext.DataGridControl.SynchronizeSelectionWithCurrent );
        }

        if( ( !m_parentRow.IsBeingEdited ) && ( !m_parentRow.IsBeginningEdition ) )
          m_parentRow.BeginEdit();

        this.SetIsBeingEdited( true );
        CellState cellState = this.GetEditCachedState();

        if( cellState != null )
        {
          if( cellState.ContentBeforeCellEdition == DependencyProperty.UnsetValue )
            cellState.SetContentBeforeCellEdition( this.Content );

          cellState.SetIsDirtyBeforeEdition( this.IsDirty );
        }

        this.OnEditBegun();

        if( parentRow.IsBeginningEditFromCell )
          parentRow.OnEditBegun();
      }
      finally
      {
        parentRow.IsBeginningEditFromCell = false;
      }
    }
        private void FinishButtonPressed(CancelRoutedEventArgs e)
        {

            var settings = Settings.Default;

            RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
            byte[] buffer = new byte[1024];

            rng.GetBytes(buffer);
            string salt = BitConverter.ToString(buffer);

            rng.Dispose();

            settings.Entropy = salt;

            settings.DBHost = MySQLHost;
            settings.DBPort = MySQLPort;
            settings.DBUsername = MySQLUsername;
            settings.DBPassword = MySQLPassword.ToSecureString().EncryptString(Encoding.Unicode.GetBytes(salt));

            settings.DBAuthName = SelectedAuthDB;
            settings.DBCharName = SelectedCharDB;
            settings.DBWorldName = SelectedWorldDB;

            if (ConnectLocally)
            {
                settings.ServerType = (int)ServerType.Local;
                settings.ServerFolder = ServerFolderLocation;
            }
            else
            {
                settings.ServerType = (int)ServerType.RemoteAccess;
                settings.RAUsername = Username;
                settings.RAPassword = Password.ToSecureString().EncryptString(Encoding.Unicode.GetBytes(salt));
                settings.RAHost = Host;
                settings.RAPort = Port;
            }

            settings.Save();
            SaveAndCloseViewModel();
        }
        private void PreviousButtonPressed(CancelRoutedEventArgs e)
        {

            var wizard = e.Source as Xceed.Wpf.Toolkit.Wizard;

            if (wizard != null)
            {

                string page = wizard.CurrentPage.Name.ToLower();

            }

        }
        private void NextButtonPressed(CancelRoutedEventArgs e)
        {
            var wizard = e.Source as Xceed.Wpf.Toolkit.Wizard;

            if (wizard != null)
            {

                string page = wizard.CurrentPage.Name.ToLower();

                if (page == "connectoptionpage")
                {
                    if (!ConnectLocally && !ConnectRemotely)
                    {
                        _messageService.ShowError("You must choose one of the options! If you're not sure, choose 'Locally'.");
                        e.Cancel = true;
                        return;
                    }
                }
                else if (page == "trinityinfo")
                {

                    if (ConnectLocally)
                    {

                        if (string.IsNullOrEmpty(ServerFolderLocation))
                        {

                            _messageService.ShowError("Server path cannot be empty!");

                            e.Cancel = true;

                            return;

                        }

                    }
                    else
                    {

                        if (string.IsNullOrEmpty(Host) || string.IsNullOrEmpty(Username))
                        {

                            _messageService.ShowError("All fields must be filled out!");

                            e.Cancel = true;

                            return;

                        }

                    }

                }
                else if (page == "mysqldetails")
                {

                    if (string.IsNullOrEmpty(MySQLHost) || string.IsNullOrEmpty(MySQLUsername))
                    {

                        _messageService.ShowError("All fields must be filled out!");

                        e.Cancel = true;

                        return;

                    }

                    string connectionError = String.Empty;

                    _pleaseWaitService.Show(() =>
                    {

                        var connStr = new MySqlConnectionStringBuilder();
                        connStr.Server = MySQLHost;
                        connStr.Port = (uint)MySQLPort;
                        connStr.UserID = MySQLUsername;
                        connStr.Database = "mysql";
                        connStr.Password = MySQLPassword;

                        using (var conn = new MySqlConnection(connStr.ToString()))
                        {

                            try
                            {
                                conn.Open();
                                conn.Close();
                            }
                            catch (Exception ex)
                            {
                                connectionError = ex.Message;
                            }

                        }

                    }, "Testing Connection...");

                    if (!string.IsNullOrEmpty(connectionError))
                    {

                        _messageService.ShowError(connectionError);

                        e.Cancel = true;

                    }

                }
                else if (page == "databaseselection")
                {

                    if (string.IsNullOrEmpty(SelectedAuthDB) || string.IsNullOrEmpty(SelectedCharDB) || string.IsNullOrEmpty(SelectedWorldDB))
                    {

                        _messageService.ShowError("You must choose for all databases!");

                        e.Cancel = true;

                    }

                }

            }

        }
    public void EndEdit()
    {
      if( !this.IsBeingEdited )
        return;

      if( this.IsEndingEdition )
        throw new InvalidOperationException( "An attempt was made to end the edit process while it is already in the process of being ended." );

      if( this.IsCancelingEdition )
        throw new InvalidOperationException( "An attempt was made to end the edit process while it is being canceled." );

      CancelRoutedEventArgs e = new CancelRoutedEventArgs( Row.EditEndingEvent, this );

      try
      {
        this.OnEditEnding( e );

        if( e.Cancel )
          throw new DataGridValidationException( "EndEdit was canceled." );
      }
      catch( Exception exception )
      {
        // This method will set a validation error on the row and throw back a DataGridValidationException so that 
        // the row stays in edition.
        Row.SetRowValidationErrorOnException( this, exception );
      }

      this.IsEndingEdition = true;

      try
      {
        DataGridContext dataGridContext = DataGridControl.GetDataGridContext( this );

        if( dataGridContext == null )
        {
          Debug.Fail( "DataGridContext cannot be null." );
          return;
        }

        IDisposable deferRefresh = ( ( this is DataRow )
          && ( dataGridContext.ItemsSourceCollection is DataGridCollectionViewBase ) )
          ? DataRow.DeferCollectionViewRefresh( dataGridContext ) : null;

        try
        {
          this.EndEditCore();
          this.TerminateEditionFromEndEdit();
        }
        finally
        {
          if( deferRefresh != null )
          {
            // If there is a validation error, The Dispose of the deferRefresh
            // may clear (local value) the current error. Be sure to keep it in order
            // to restore it if needed.
            object hasValidationError = this.ReadLocalValue( Row.HasValidationErrorProperty );
            object validationError = this.ReadLocalValue( Row.ValidationErrorProperty );

            deferRefresh.Dispose();

            if( hasValidationError != DependencyProperty.UnsetValue )
            {
              // This will use the PropertyKey.
              this.SetHasValidationError( ( bool )hasValidationError );
            }
            if( validationError != DependencyProperty.UnsetValue )
            {
              this.SetValidationError( ( RowValidationError )validationError );
            }
          }
        }

        this.PreEditEnded();

        // Item validation has passed if we reached this far.  
        // Since it is the Row's HasValidationError which drives the error styles, setting 
        // the ItemValidationError to null will not get in the way of the row's cells validation.
        this.SetValidationError( null );

      }
      finally
      {
        this.IsEndingEdition = false;
      }

      this.OnEditEnded();
    }