Example #1
0
        /// <summary>
        /// Save the grid back to the model.
        /// </summary>
        private void SaveGrid()
        {
            this.presenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            // Get the data source of the profile grid.
            DataTable data = this.xYPairsView.VariablesGrid.DataSource;

            // Maintain a list of all property changes that we need to make.
            List <Commands.ChangeProperty.Property> properties = new List <Commands.ChangeProperty.Property>();

            // add missing data as 0 otherwise it will throw an exception
            // could make this work as an entire row, but will stick to X & Y columns for now

            /*
             * for (int Row = 0; Row != data.Rows.Count; Row++)
             * {
             *  if (data.Rows[Row]["Y"].ToString() == "" && data.Rows[Row]["X"].ToString() != "")
             *      data.Rows[Row]["Y"] = "0";
             *  if (data.Rows[Row]["X"].ToString() == "" && data.Rows[Row]["Y"].ToString() != "")
             *      data.Rows[Row]["X"] = "0";
             *  if (data.Rows[Row]["Y"].ToString() == "" && data.Rows[Row]["X"].ToString() == "")
             *      break;
             * }
             */
            //// Loop through all non-readonly properties, get an array of values from the data table
            //// for the property and then set the property value.
            for (int i = 0; i < this.propertiesInGrid.Count; i++)
            {
                // If this property is NOT readonly then set its value.
                if (!this.propertiesInGrid[i].IsReadOnly)
                {
                    // Get an array of values for this property.
                    Array values;
                    if (this.propertiesInGrid[i].DataType.GetElementType() == typeof(double))
                    {
                        values = DataTableUtilities.GetColumnAsDoubles(data, data.Columns[i].ColumnName);
                        if (!MathUtilities.ValuesInArray((double[])values))
                        {
                            values = null;
                        }
                        else
                        {
                            values = MathUtilities.RemoveMissingValuesFromBottom((double[])values);
                        }
                    }
                    else
                    {
                        values = DataTableUtilities.GetColumnAsStrings(data, data.Columns[i].ColumnName);
                        values = MathUtilities.RemoveMissingValuesFromBottom((string[])values);
                    }

                    // Is the value any different to the former property value?
                    bool changedValues;
                    if (this.propertiesInGrid[i].DataType == typeof(double[]))
                    {
                        changedValues = !MathUtilities.AreEqual((double[])values, (double[])this.propertiesInGrid[i].Value);
                    }
                    else
                    {
                        changedValues = !MathUtilities.AreEqual((string[])values, (string[])this.propertiesInGrid[i].Value);
                    }

                    if (changedValues)
                    {
                        // Store the property change.
                        Commands.ChangeProperty.Property property =
                            new Commands.ChangeProperty.Property(this.propertiesInGrid[i].Object, this.propertiesInGrid[i].Name, values);
                        properties.Add(property);
                    }
                }
            }

            // If there are property changes pending, then commit the changes in a block.
            if (properties.Count > 0)
            {
                Commands.ChangeProperty command = new Commands.ChangeProperty(properties);
                this.presenter.CommandHistory.Add(command);
            }

            this.presenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
Example #2
0
        /// <summary>
        /// Save the grid back to the model.
        /// </summary>
        private void SaveGrid()
        {
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            // Get the data source of the profile grid.
            DataTable data = this.view.ProfileGrid.DataSource;

            // Maintain a list of all property changes that we need to make.
            List<Commands.ChangeProperty.Property> properties = new List<Commands.ChangeProperty.Property>();

            // Loop through all non-readonly properties, get an array of values from the data table
            // for the property and then set the property value.
            for (int i = 0; i < this.propertiesInGrid.Count; i++)
            {
                // If this property is NOT readonly then set its value.
                if (!this.propertiesInGrid[i].IsReadOnly)
                {
                    // Get an array of values for this property.
                    Array values;
                    if (this.propertiesInGrid[i].DataType.GetElementType() == typeof(double))
                    {
                        values = DataTableUtilities.GetColumnAsDoubles(data, data.Columns[i].ColumnName);
                        if (!MathUtilities.ValuesInArray((double[])values))
                            values = null;
                        else
                            values = MathUtilities.RemoveMissingValuesFromBottom((double[])values);
                    }
                    else
                    {
                        values = DataTableUtilities.GetColumnAsStrings(data, data.Columns[i].ColumnName);
                        values = MathUtilities.RemoveMissingValuesFromBottom((string[])values);
                    }

                    // Is the value any different to the former property value?
                    bool changedValues;
                    if (this.propertiesInGrid[i].DataType == typeof(double[]))
                    {
                        changedValues = !MathUtilities.AreEqual((double[])values, (double[])this.propertiesInGrid[i].Value);
                    }
                    else
                    {
                        changedValues = !MathUtilities.AreEqual((string[])values, (string[])this.propertiesInGrid[i].Value);
                    }

                    if (changedValues)
                    {
                        // Store the property change.
                        Commands.ChangeProperty.Property property = new Commands.ChangeProperty.Property();
                        property.Name = this.propertiesInGrid[i].Name;
                        property.Obj = this.propertiesInGrid[i].Object;
                        property.NewValue = values;
                        properties.Add(property);
                    }
                }
            }

            // If there are property changes pending, then commit the changes in a block.
            if (properties.Count > 0)
            {
                Commands.ChangeProperty command = new Commands.ChangeProperty(properties);
                this.explorerPresenter.CommandHistory.Add(command);
            }

            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }
        /// <summary>
        /// Save the grid back to the model.
        /// </summary>
        private void SaveGrid()
        {
            try
            {
                this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

                // Get the data source of the profile grid.
                DataTable data = this.view.ProfileGrid.DataSource;

                // Maintain a list of all property changes that we need to make.
                List <Commands.ChangeProperty.Property> properties = new List <Commands.ChangeProperty.Property>();

                // Loop through all non-readonly properties, get an array of values from the data table
                // for the property and then set the property value.
                for (int i = 0; i < this.propertiesInGrid.Count; i++)
                {
                    // If this property is NOT readonly then set its value.
                    if (!this.propertiesInGrid[i].IsReadOnly)
                    {
                        // Get an array of values for this property.
                        Array values;
                        if (this.propertiesInGrid[i].DataType.GetElementType() == typeof(double))
                        {
                            values = DataTableUtilities.GetColumnAsDoubles(data, data.Columns[i].ColumnName);
                            if (!MathUtilities.ValuesInArray((double[])values))
                            {
                                values = null;
                            }
                            else
                            {
                                values = MathUtilities.RemoveMissingValuesFromBottom((double[])values);
                            }
                        }
                        else
                        {
                            values = DataTableUtilities.GetColumnAsStrings(data, data.Columns[i].ColumnName);
                            values = MathUtilities.RemoveMissingValuesFromBottom((string[])values);
                        }

                        // Is the value any different to the former property value?
                        bool changedValues;
                        if (this.propertiesInGrid[i].DataType == typeof(double[]))
                        {
                            changedValues = !MathUtilities.AreEqual((double[])values, (double[])this.propertiesInGrid[i].Value);
                        }
                        else
                        {
                            changedValues = !MathUtilities.AreEqual((string[])values, (string[])this.propertiesInGrid[i].Value);
                        }

                        if (changedValues)
                        {
                            // Store the property change.
                            Commands.ChangeProperty.Property property =
                                new Commands.ChangeProperty.Property(this.propertiesInGrid[i].Object, this.propertiesInGrid[i].Name, values);
                            properties.Add(property);
                        }
                    }
                }

                // If there are property changes pending, then commit the changes in a block.
                if (properties.Count > 0)
                {
                    Commands.ChangeProperty command = new Commands.ChangeProperty(properties);
                    this.explorerPresenter.CommandHistory.Add(command);
                }

                this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
            }
            catch (Exception e)
            {
                if (e is System.Reflection.TargetInvocationException)
                {
                    e = (e as System.Reflection.TargetInvocationException).InnerException;
                }

                this.explorerPresenter.MainPresenter.ShowError(e);
            }
        }
Example #4
0
        /// <summary>
        /// Save the grid back to the model.
        /// </summary>
        private void SaveGrid()
        {
            this.explorerPresenter.CommandHistory.ModelChanged -= this.OnModelChanged;

            // Get the data source of the profile grid.
            DataTable data = this.xyPairsView.VariablesGrid.DataSource;

            // Maintain a list of all property changes that we need to make.
            List<Commands.ChangeProperty.Property> properties = new List<Commands.ChangeProperty.Property>();

            //add missing data as 0 otherwise it will throw an exception
            //could make this work as an entire row, but will stick to X & Y columns for now
            /*
            for (int Row = 0; Row != data.Rows.Count; Row++)
            {
                if (data.Rows[Row]["Y"].ToString() == "" && data.Rows[Row]["X"].ToString() != "")
                    data.Rows[Row]["Y"] = "0";
                if (data.Rows[Row]["X"].ToString() == "" && data.Rows[Row]["Y"].ToString() != "")
                    data.Rows[Row]["X"] = "0";
                if (data.Rows[Row]["Y"].ToString() == "" && data.Rows[Row]["X"].ToString() == "")
                    break;
            }
            */
            // Loop through all non-readonly properties, get an array of values from the data table
            // for the property and then set the property value.
            for (int i = 0; i < this.propertiesInGrid.Count; i++)
            {
                // If this property is NOT readonly then set its value.
                if (!this.propertiesInGrid[i].IsReadOnly)
                {
                    // Get an array of values for this property.
                    Array values;
                    if (this.propertiesInGrid[i].DataType.GetElementType() == typeof(double))
                    {
                        values = DataTableUtilities.GetColumnAsDoubles(data, data.Columns[i].ColumnName);
                        if (!MathUtilities.ValuesInArray((double[])values))
                            values = null;
                        else
                            values = MathUtilities.RemoveMissingValuesFromBottom((double[])values);
                    }
                    else
                    {
                        values = DataTableUtilities.GetColumnAsStrings(data, data.Columns[i].ColumnName);
                        values = MathUtilities.RemoveMissingValuesFromBottom((string[])values);
                    }

                    // Is the value any different to the former property value?
                    bool changedValues;
                    if (this.propertiesInGrid[i].DataType == typeof(double[]))
                    {
                        changedValues = !MathUtilities.AreEqual((double[])values, (double[])this.propertiesInGrid[i].Value);
                    }
                    else
                    {
                        changedValues = !MathUtilities.AreEqual((string[])values, (string[])this.propertiesInGrid[i].Value);
                    }

                    if (changedValues)
                    {
                        // Store the property change.
                        Commands.ChangeProperty.Property property = new Commands.ChangeProperty.Property();
                        property.Name = this.propertiesInGrid[i].Name;
                        property.Obj = this.propertiesInGrid[i].Object;
                        property.NewValue = values;
                        properties.Add(property);
                    }
                }
            }

            // If there are property changes pending, then commit the changes in a block.
            if (properties.Count > 0)
            {
                Commands.ChangeProperty command = new Commands.ChangeProperty(properties);
                this.explorerPresenter.CommandHistory.Add(command);
            }

            this.explorerPresenter.CommandHistory.ModelChanged += this.OnModelChanged;
        }