Exemple #1
0
        /// <summary>
        /// Change the value of the cell applying the rule of the current editor.
        /// Is recommend to use this method to simulate a edit operation and to validate
        /// the cell value using the current model.
        /// </summary>
        /// <param name="p_Cell">Cell to change value</param>
        /// <param name="position">Current Cell Position</param>
        /// <param name="p_NewValue">New value</param>
        /// <returns>
        /// returns true if the value passed is valid and has been applied to the cell
        /// </returns>
        public virtual bool SetCellValue(Cells.ICellVirtual p_Cell, Position position, object p_NewValue)
        {
            if (EnableEdit == false)
            {
                return(false);
            }

            CellValidatingEventArgs l_cancelEvent = new CellValidatingEventArgs(p_Cell, p_NewValue);

            OnValidating(l_cancelEvent);

            // check whether cancel == true
            if (l_cancelEvent.Cancel == false)
            {
                object l_PrevValue = p_Cell.GetValue(position);
                try
                {
                    p_Cell.SetValue(position, ObjectToValue(l_cancelEvent.NewValue));
                    OnValidated(new CellValidatedEventArgs(p_Cell));
                }
                catch (Exception ex)
                {
                    LoggerManager.Log(LogLevels.Warning, "Exception caught: " + ex.ToString());
                    p_Cell.SetValue(position, l_PrevValue);
                    l_cancelEvent.Cancel = true;
                }
            }

            return(l_cancelEvent.Cancel == false);
        }
Exemple #2
0
        /// <summary>
        /// Change the value of the cell applying the rule of the current editor. Is recommend to use this method to simulate a edit operation and to validate the cell value using the current model.
        /// </summary>
        /// <param name="p_Cell">Cell to change value</param>
        /// <param name="p_Position">Current Cell Position</param>
        /// <param name="p_NewValue"></param>
        /// <returns>returns true if the value passed is valid and has been applied to the cell</returns>
        public virtual bool SetCellValue(Cells.ICellVirtual p_Cell, Position p_Position, object p_NewValue)
        {
            if (EnableEdit)
            {
                ValidatingCellEventArgs l_cancelEvent = new ValidatingCellEventArgs(p_Cell, p_NewValue);
                OnValidating(l_cancelEvent);

                //check if cancel == true
                if (l_cancelEvent.Cancel == false)
                {
                    object l_PrevValue = p_Cell.GetValue(p_Position);
                    try
                    {
                        p_Cell.SetValue(p_Position, ObjectToValue(l_cancelEvent.NewValue));
                        OnValidated(new CellEventArgs(p_Cell));
                    }
                    catch (Exception)
                    {
                        p_Cell.SetValue(p_Position, l_PrevValue);
                        //throw err;
                        l_cancelEvent.Cancel = true;                        //di fatto � fallita la validazione del dato
                    }
                }

                return(l_cancelEvent.Cancel == false);
            }
            else
            {
                return(false);
            }
        }