/// <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); }
/// <summary> /// Validating the value of the cell. /// </summary> /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.CellValidatingEventArgs"/> instance containing the event data.</param> protected virtual void OnValidating(CellValidatingEventArgs e) { if (this.validatingHandler != null) { this.validatingHandler(this, e); } }
private void ValidarCelda(GridViewDataColumn Column, CellValidatingEventArgs e) { try { /* validacion en edicion de registro */ Int16 _Col = 10; e.Row.ErrorText = string.Empty; GridViewDataColumn column = e.Column as GridViewDataColumn; var cell = e.Row.Cells[e.ColumnIndex]; if (e.Row is GridViewDataRowInfo) { switch (column.Index) { case 10: /* Pago */ if (((Decimal)e.Value) == 0) { e.Row.ErrorText = "Debe ingresar Pago "; e.Row.Cells[_Col].ErrorText = "Debe ingresar Pago "; e.Cancel = true; e.Row.Cells[_Col].Style.DrawFill = true; e.Row.Cells[_Col].Style.NumberOfColors = 1; e.Row.Cells[_Col].Style.GradientStyle = GradientStyles.Solid; e.Row.Cells[_Col].Style.CustomizeBorder = true; e.Row.Cells[_Col].Style.DrawBorder = true; e.Row.Cells[_Col].Style.BorderWidth = 2; e.Row.Cells[_Col].Style.BorderGradientStyle = GradientStyles.Solid; e.Row.Cells[_Col].Style.BorderColor = Color.Red; } else { if (Convert.ToDecimal(e.Row.Cells[_Col - 1].Value) < ((Decimal)e.Value)) { if (Dialogos.MostrarMensajePregunta(Presenter.Title, "El pago es mayor que el saldo. Desea continuar?") == System.Windows.Forms.DialogResult.OK) { CalculaTotal(); NUDCAJA_Monto.Value = (NUDCAJA_Monto.Value - Convert.ToDecimal(e.Row.Cells[_Col].Value)) + ((Decimal)e.Value); e.Row.Cells[_Col].Style.Reset(); } else { e.Cancel = true; e.Row.ErrorText = "El pago no puede ser mayor que el saldo "; e.Row.Cells[_Col].Value = e.Row.Cells[_Col - 1].Value; e.Row.Cells[_Col].Style.Reset(); e.Row.Cells[_Col].Style.Reset(); } } else { CalculaTotal(); NUDCAJA_Monto.Value = (NUDCAJA_Monto.Value - Convert.ToDecimal(e.Row.Cells[_Col].Value)) + ((Decimal)e.Value); e.Row.Cells[_Col].Style.Reset(); } } break; } } } catch (Exception ex) { Dialogos.MostrarMensajeError("", "Ha ocurrido un error al validar el registro." + ex.Message); } }
void grdItems_CellValidating(object sender, CellValidatingEventArgs e) { try { String _MensajeError = String.Empty; GridViewDataColumn column = e.Column as GridViewDataColumn; ValidarCelda(column, e); } catch (Exception ex) { Dialogos.MostrarMensajeError("", "Ha ocurrido un error al validar el dato." + ex.Message); } }
private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e) { if (this.radGridView1.CurrentCell != null) { int cellIndex = e.ColumnIndex; object initialCellValue = e.Row.Cells[cellIndex].Value; if (!initialValues.ContainsKey(cellIndex)) { initialValues.Add(cellIndex, initialCellValue); } } }
private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e) { if (radGridView1.IsInEditMode) { ColumnValidationInfo validationInfo = GetColumnValidationInfo(e.Column); if (validationInfo != null && !validationInfo.Validate(Convert.ToDecimal(e.Value))) { e.Cancel = true; e.Row.ErrorText = "Validation Error!"; } } }
void radGridView1_CellValidating(object sender, CellValidatingEventArgs e) { GridViewDataColumn column = (GridViewDataColumn)e.Column; if (column != null && column.Name == "End") { DateTime date = (DateTime)e.Row.Cells["Start"].Value; DateTime newDate = (DateTime)e.Value; if (newDate < date) { e.Cancel = true; } } }
void grdLocationTypes_CellValidating(object sender, CellValidatingEventArgs e) { if (e.Row != null) { if (e.Value.ToStr().Length > 3) { e.Row.ErrorText = "ShortKey Length cannot exceed 3 Characters"; e.Cancel = true; } else { e.Row.ErrorText = ""; } } }
public override ValidationResult Validate( object value, CultureInfo culture, CellValidationContext context) { if (this.Validating != null) { CellValidatingEventArgs cellValidatingEventArgs = new CellValidatingEventArgs(value, culture, context); this.Validating(this, cellValidatingEventArgs); return(cellValidatingEventArgs.Result); } return(ValidationResult.ValidResult); }
public override ValidationResult Validate( object value, CultureInfo culture, CellValidationContext context ) { if( this.Validating != null ) { CellValidatingEventArgs cellValidatingEventArgs = new CellValidatingEventArgs( value, culture, context ); this.Validating( this, cellValidatingEventArgs ); return cellValidatingEventArgs.Result; } return ValidationResult.ValidResult; }
private void gridUsers_CellValidating(object sender, CellValidatingEventArgs e) { if (e.RowIndex < 0) // Don't check if it's the new adding row { return; } switch (gridUsers.CurrentColumn.Name) { case "UserName": // Name cannot be empty if (Helper.ConvertToString(e.Value) == string.Empty) { Helper.ShowError("Input the username of the account."); e.Cancel = true; } break; default: break; } }
private void GridTitulos_CellValidating(object sender, CellValidatingEventArgs eventArgs) { if (eventArgs.Column.Name == "CantidadADevolver") { if (eventArgs.Value == null) { eventArgs.Cancel = true; } else { try { int intValue; var valor = eventArgs.Value == "" ? 0 : eventArgs.Value; if (!Int32.TryParse(valor.ToString(), out intValue)) { eventArgs.Cancel = true; } else { //Todo: validar que la cantidad a rendir no supere la cantidad en consignación var item = eventArgs.Row.DataBoundItem as ConsignacionesParaDevolver; if ((item != null && intValue > item.CantidadSinRendir) || intValue < 0) { eventArgs.Cancel = true; } else { _validating = true; } } } catch { // Error occured so validation error! eventArgs.Cancel = true; } } } }
private void GridTitulos_CellValidating(object sender, CellValidatingEventArgs eventArgs) { if (eventArgs.Column.Name == "CantidadADevolver") { if (eventArgs.Value == null) { eventArgs.Cancel = true; } else { try { int intValue; var valor = eventArgs.Value == "" ? 0 : eventArgs.Value; if (!Int32.TryParse(valor.ToString(), out intValue)) { eventArgs.Cancel = true; } else { //Todo: validar que la cantidad a rendir no supere la cantidad en consignación var item = eventArgs.Row.DataBoundItem as ConsignacionesParaDevolver; if ((item != null && intValue > item.CantidadSinRendir) || intValue < 0) { eventArgs.Cancel = true; } else { _validating = true; } } } catch { // Error occured so validation error! eventArgs.Cancel = true; } } } }
public static void ValidateCellInput(CellValidatingEventArgs e, ParameterDefinition activeDefinition, RadGridView paramDefinitionGrid) { var col = e.Column as GridViewDataColumn; if (!(e.Row is GridViewDataRowInfo) || col == null) { return; } var param = e.Row.DataBoundItem as Parameter; if (param == null || param.IsReadOnly) { return; } if (col.Name != "Sollwert") { return; } e.Row.ErrorText = string.Empty; try { var stringValue = e.Value as string; if (string.IsNullOrEmpty(stringValue) || stringValue.Trim() == string.Empty) { e.Cancel = true; e.Row.ErrorText = "Validierung fehlgeschlagen, kein Wert angegeben!"; throw new ApplicationException(e.Row.ErrorText); } stringValue = stringValue.Trim(); if (param.Type == ParameterType.Boolean) { if (stringValue == "AN" == false && stringValue == "AUS" == false) { e.Cancel = true; e.Row.ErrorText = "Validierung fehlgeschlagen, nur 'AN' oder 'AUS' können angegeben werden!"; throw new ApplicationException(e.Row.ErrorText); } } // find and set param value (override databinding) var listParam = activeDefinition.ParameterList.Find(p => p.Id == param.Id); if (listParam != null) { if (param.Id == ParameterId.ServerId) { var bytes = Utils.ByteArray.FromHexString(stringValue.Replace("-", string.Empty)); if (bytes.Length != 10) { e.Cancel = true; e.Row.ErrorText = "Validierung fehlgeschlagen, als ServerId sind exakt 10 Bytes anzugeben."; throw new ApplicationException(e.Row.ErrorText); } listParam.TargetValue = BitConverter.ToString(bytes); } else { listParam.TargetValue = stringValue; } if (e.ActiveEditor != null) { e.ActiveEditor.Value = listParam.TargetValue; } LoadDefinitionParamGridAsync(paramDefinitionGrid, activeDefinition); } } catch (ApplicationException ex) { e.Cancel = true; MessageBox.Show(ex.Message); } }
private void GridTitulos_CellValidating(object sender, CellValidatingEventArgs eventArgs) { if (eventArgs.Column.Name == "CantidadARendir") { if (eventArgs.Value == null) { eventArgs.Cancel = true; } else { try { int intValue; var valor = eventArgs.Value == "" ? 0 : eventArgs.Value; if (!Int32.TryParse(valor.ToString(), out intValue)) { eventArgs.Cancel = true; } else { //Todo: validar que la cantidad a rendir no supere la cantidad en consignación var item = eventArgs.Row.DataBoundItem as ConsignacionSinRendir; if ((item != null && intValue > item.CantidadSinRendir) || intValue < 0) { eventArgs.Cancel = true; } else { _validating = true; } } } catch { // Error occured so validation error! eventArgs.Cancel = true; } } } if (eventArgs.Column.Name == "PrecioVentaTitulo") { if (eventArgs.Value == null) { eventArgs.Cancel = true; } else { try { Decimal value; var text = eventArgs.Value == null ? null : eventArgs.Value.ToString().Replace("$ ", "").Replace(".", "").Replace(",", "."); if (!Decimal.TryParse(text, out value) || value <= 0) { eventArgs.Cancel = true; } else { _validating = true; } } catch { // Error occured so validation error! eventArgs.Cancel = true; } } } }
private void GridTitulos_CellValidating(object sender, CellValidatingEventArgs eventArgs) { if (eventArgs.Column.Name == "CantidadARendir") { if (eventArgs.Value == null) { eventArgs.Cancel = true; } else { try { int intValue; var valor = eventArgs.Value == "" ? 0 : eventArgs.Value; if (!Int32.TryParse(valor.ToString(), out intValue)) { eventArgs.Cancel = true; } else { //Todo: validar que la cantidad a rendir no supere la cantidad en consignación var item = eventArgs.Row.DataBoundItem as ConsignacionSinRendir; if ((item != null && intValue > item.CantidadSinRendir) || intValue < 0) { eventArgs.Cancel = true; } else { _validating = true; } } } catch { // Error occured so validation error! eventArgs.Cancel = true; } } } if (eventArgs.Column.Name == "PrecioVentaTitulo") { if (eventArgs.Value == null) { eventArgs.Cancel = true; } else { try { Decimal value; var text = eventArgs.Value == null ? null : eventArgs.Value.ToString().Replace("$ ", "").Replace(".", "").Replace(",", "."); if (!Decimal.TryParse(text, out value) || value <= 0) { eventArgs.Cancel = true; } else { _validating = true; } } catch { // Error occured so validation error! eventArgs.Cancel = true; } } } }
/// <summary> /// Gvs the parameter definition cell validating. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="Telerik.WinControls.UI.CellValidatingEventArgs"/> instance containing the event data.</param> private void GvParameterDefinitionCellValidating(object sender, CellValidatingEventArgs e) { ViewUtil.ValidateCellInput(e, this.activeDefinition, this.gvParameterDefinition); }
/// <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; }
/// <summary> /// Validating the value of the cell. /// </summary> /// <param name="e">The <see cref="Fr.Medit.MedDataGrid.CellValidatingEventArgs"/> instance containing the event data.</param> protected virtual void OnValidating(CellValidatingEventArgs e) { if (this.validatingHandler != null) { this.validatingHandler(this, e); } }