Esempio n. 1
0
 /// <summary>
 /// Validating the value of the cell.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnValidating(ValidatingCellEventArgs e)
 {
     if (m_Validating != null)
     {
         m_Validating(this, e);
     }
 }
Esempio n. 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);
            }
        }
Esempio n. 3
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.
        /// Doesn't call the StartEdit and EndEdit but change directly the cell value. Use the CellContext.Start edit to begin an edit operation.
        /// </summary>
        /// <param name="cellContext">Cell to change the value</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(CellContext cellContext, object p_NewValue)
        {
            if (cellContext.Cell == null)
            {
                throw new SourceGridException("Invalid CellContext, cell is null");
            }

            //[email protected] : to restrict the user to edit the data if the cell is readonly
            if (EnableEdit)
            {
                if (ReadOnly)
                {
                    //[email protected]: return true in case its readonly. Else cell wont be able to end edit mode.
                    return(true);
                }
                ValidatingCellEventArgs l_cancelEvent = new ValidatingCellEventArgs(cellContext, p_NewValue);
                OnValidating(l_cancelEvent);

                //check if cancel == true
                if (l_cancelEvent.Cancel == false)
                {
                    object l_PrevValue = cellContext.Cell.Model.ValueModel.GetValue(cellContext);
                    try
                    {
                        cellContext.Cell.Model.ValueModel.SetValue(cellContext, ObjectToValue(l_cancelEvent.NewValue));
                        OnValidated(new CellContextEventArgs(cellContext));
                    }
                    catch (Exception err)
                    {
                        OnEditException(new ExceptionEventArgs(err));
                        cellContext.Cell.Model.ValueModel.SetValue(cellContext, l_PrevValue);
                        l_cancelEvent.Cancel = true;//di fatto è fallita la validazione del dato
                    }
                }

                return(l_cancelEvent.Cancel == false);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 4
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.
        /// Doesn't call the StartEdit and EndEdit but change directly the cell value. Use the CellContext.Start edit to begin an edit operation.
        /// </summary>
        /// <param name="cellContext">Cell to change the value</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(CellContext cellContext, object p_NewValue)
        {
            if (EnableEdit)
            {
                if (cellContext.Cell == null)
                {
                    throw new SourceGridException("Invalid CellContext, cell is null");
                }

                ValidatingCellEventArgs l_cancelEvent = new ValidatingCellEventArgs(cellContext, p_NewValue);
                OnValidating(l_cancelEvent);

                //check if cancel == true
                if (l_cancelEvent.Cancel == false)
                {
                    object l_PrevValue = cellContext.Cell.Model.ValueModel.GetValue(cellContext);
                    try
                    {
                        cellContext.Cell.Model.ValueModel.SetValue(cellContext, ObjectToValue(l_cancelEvent.NewValue));
                        OnValidated(new CellContextEventArgs(cellContext));
                    }
                    catch (Exception err)
                    {
                        OnEditException(new ExceptionEventArgs(err));
                        cellContext.Cell.Model.ValueModel.SetValue(cellContext, l_PrevValue);
                        l_cancelEvent.Cancel = true;                        //di fatto è fallita la validazione del dato
                    }
                }

                return(l_cancelEvent.Cancel == false);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 5
0
		/// <summary>
		/// Validating the value of the cell.
		/// </summary>
		/// <param name="e"></param>
		protected void OnValidating(ValidatingCellEventArgs e)
		{
			if (m_Validating!=null)
				m_Validating(this,e);
		}
Esempio n. 6
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.
		/// Doesn't call the StartEdit and EndEdit but change directly the cell value. Use the CellContext.Start edit to begin an edit operation.
		/// </summary>
		/// <param name="cellContext">Cell to change the value</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(CellContext cellContext, object p_NewValue)
		{
			if (EnableEdit)
			{
				if (cellContext.Cell == null)
					throw new SourceGridException("Invalid CellContext, cell is null");

				ValidatingCellEventArgs l_cancelEvent = new ValidatingCellEventArgs(cellContext, p_NewValue);
				OnValidating(l_cancelEvent);

				//check if cancel == true 
				if (l_cancelEvent.Cancel == false)
				{
					object l_PrevValue = cellContext.Cell.Model.ValueModel.GetValue(cellContext);
					try
					{
						cellContext.Cell.Model.ValueModel.SetValue(cellContext, ObjectToValue(l_cancelEvent.NewValue));
						OnValidated(new CellContextEventArgs(cellContext));
					}
					catch(Exception err)
					{
						OnEditException(new ExceptionEventArgs(err));
						cellContext.Cell.Model.ValueModel.SetValue(cellContext, l_PrevValue);
						l_cancelEvent.Cancel = true;//di fatto è fallita la validazione del dato
					}
				}

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