//public event EventHandler AlModificar = null; protected void CallAlModificar(object tag, ref BeforeRecordUpdatedEventArgs e) { if (AlModificar != null) { var ev = new EventUpdateAbm(tag, ref e); AlModificar.Invoke(this, ev); } }
protected virtual void OnBeforeRecordUpdated(BeforeRecordUpdatedEventArgs e) { BeforeRecordUpdatedEventHandler handler = (BeforeRecordUpdatedEventHandler)Events[EventBeforeRecordUpdated]; if (handler != null) { handler(this, e); } }
private void MakeUpdates(IDataSource ds, JArray data) { string id = this.ModelInstance.GetIDProperty(); foreach (JToken token in data) { this.record = token; var jObject = (JObject)token; values = new SortedList(this.ModelInstance.Fields.Count); keys = new SortedList(); oldValues = new SortedList(); foreach (ModelField field in this.ModelInstance.Fields) { var jProperty = jObject.Property(field.Mapping.IsNotEmpty() ? field.Mapping : field.Name) ?? jObject.Property(field.Name); values[field.Name] = jProperty != null && jProperty.Value.Type != JTokenType.Null && jProperty.Value.Type != JTokenType.Undefined ? (jProperty.Value.Type == JTokenType.String ? (string)jProperty.Value : this.ChopQuotes(jProperty.Value.ToString(Newtonsoft.Json.Formatting.None))) : null; } if (id.IsNotEmpty()) { string idStr = token.Value <string>(id); int idInt; if (int.TryParse(idStr, out idInt)) { keys[id] = idInt; } else { keys[id] = idStr; } } BeforeRecordUpdatedEventArgs eBeforeRecordUpdated = new BeforeRecordUpdatedEventArgs(record, keys, values, oldValues); this.OnBeforeRecordUpdated(eBeforeRecordUpdated); if (eBeforeRecordUpdated.CancelAll) { break; } if (eBeforeRecordUpdated.Cancel) { continue; } if (ds != null) { ds.GetView("").Update(keys, values, oldValues, this.UpdateCallback); } else { this.UpdateCallback(0, null); } } }
private void MakeUpdates(IDataSource ds, JArray data) { string id = this.ModelInstance.GetIDProperty(); foreach (JToken token in data) { this.record = token; values = new SortedList(this.ModelInstance.Fields.Count); keys = new SortedList(); oldValues = new SortedList(); foreach (ModelField field in this.ModelInstance.Fields) { values[field.Name] = token.Value <string>(field.Mapping.IsNotEmpty() ? field.Mapping : field.Name) ?? token.Value <string>(field.Name); } if (id.IsNotEmpty()) { string idStr = token.Value <string>(id); int idInt; if (int.TryParse(idStr, out idInt)) { keys[id] = idInt; } else { keys[id] = idStr; } } BeforeRecordUpdatedEventArgs eBeforeRecordUpdated = new BeforeRecordUpdatedEventArgs(record, keys, values, oldValues); this.OnBeforeRecordUpdated(eBeforeRecordUpdated); if (eBeforeRecordUpdated.CancelAll) { break; } if (eBeforeRecordUpdated.Cancel) { continue; } if (ds != null) { ds.GetView("").Update(keys, values, oldValues, this.UpdateCallback); } else { this.UpdateCallback(0, null); } } }
private void MakeUpdates(IDataSource ds, JArray data) { string id = this.ModelInstance.GetIDProperty(); foreach (JToken token in data) { this.record = token; var jObject = (JObject)token; values = new SortedList(this.ModelInstance.Fields.Count); keys = new SortedList(); oldValues = new SortedList(); foreach (ModelField field in this.ModelInstance.Fields) { var jProperty = jObject.Property(field.Mapping.IsNotEmpty() ? field.Mapping : field.Name) ?? jObject.Property(field.Name); values[field.Name] = jProperty != null && jProperty.Value.Type != JTokenType.Null && jProperty.Value.Type != JTokenType.Undefined ? (jProperty.Value.Type == JTokenType.String ? (string)jProperty.Value : this.ChopQuotes(jProperty.Value.ToString(Newtonsoft.Json.Formatting.None))) : null; } if (id.IsNotEmpty()) { string idStr = token.Value<string>(id); int idInt; if (int.TryParse(idStr, out idInt)) { keys[id] = idInt; } else { keys[id] = idStr; } } BeforeRecordUpdatedEventArgs eBeforeRecordUpdated = new BeforeRecordUpdatedEventArgs(record, keys, values, oldValues); this.OnBeforeRecordUpdated(eBeforeRecordUpdated); if (eBeforeRecordUpdated.CancelAll) { break; } if (eBeforeRecordUpdated.Cancel) { continue; } if (ds != null) { ds.GetView("").Update(keys, values, oldValues, this.UpdateCallback); } else { this.UpdateCallback(0, null); } } }
/// <summary> /// Ejecuta el evento antes de modificar un registro en la base de datos. /// </summary> /// <param name="e"></param> protected void AlModificarRecord(ref BeforeRecordUpdatedEventArgs e) { // Seguridad IDictionary test = e.NewValues; var companies = new Dictionary<string, string>[1]; companies[0] = new Dictionary<string, string>(); try { foreach (object o in test.Keys) { var value = test[o].ToString(); SQLInjection.AplicarSeguridad(ref value); if (SQLInjection.IsSqlSentence(value)) { throw new Exception("Uno de los valores ingresados no cumple con las reglas de seguridad del sistema. La operación será cancelada."); } else { companies[0].Add(o.ToString(), value); } } } catch (Exception ex) { UIHelper.MostrarExcepcionSimple(ex, "Error de seguridad"); e.Cancel = true; } // Evento al modificar if (AlModificar != null) { object obj; try { Storer st = new Storer(Tipo); st.Valores = ValoresCombo; obj = st.MakeObjectFromRow(companies); } catch (Exception ex) { obj = null; UIHelper.MostrarExcepcionSimple(ex, "Error"); } CallAlModificar(obj, ref e); } }
public EventUpdateAbm(object tag, ref BeforeRecordUpdatedEventArgs parentEventArgs) : base() { Tag = tag; ParentEventArgs = parentEventArgs; }
private void MakeUpdates(IDataSource ds, XmlDocument xml) { XmlNodeList updatingRecords = xml.SelectNodes("records/Updated/record"); string id = GetIdColumnName(); foreach (XmlNode node in updatingRecords) { record = node; values = new SortedList(this.Reader.Reader.Fields.Count); keys = new SortedList(); oldValues = new SortedList(); foreach (RecordField field in this.Reader.Reader.Fields) { XmlNode keyNode = node.SelectSingleNode(field.Name); values[field.Name] = keyNode != null ? keyNode.InnerText : null; } confirmation = null; if (id.IsNotEmpty()) { XmlNode keyNode = node.SelectSingleNode(id); string idStr = keyNode != null ? keyNode.InnerText : null; int idInt; if (int.TryParse(idStr, out idInt)) { keys[id] = idInt; } else { keys[id] = idStr; } if (this.UseIdConfirmation && keys[id] != null) { confirmation = changingEventArgs.ConfirmationList[keys[id].ToString()]; } } BeforeRecordUpdatedEventArgs eBeforeRecordUpdated = new BeforeRecordUpdatedEventArgs(record, keys, values, oldValues, confirmation); this.OnBeforeRecordUpdated(eBeforeRecordUpdated); if (eBeforeRecordUpdated.CancelAll) { break; } if (eBeforeRecordUpdated.Cancel) { continue; } if (ds !=null) { ds.GetView("").Update(keys, values, oldValues, this.UpdateCallback); } else { this.UpdateCallback(0, null); } } }
private void MakeUpdates(IDataSource ds, JArray data) { string id = this.ModelInstance.GetIDProperty(); foreach (JToken token in data) { this.record = token; values = new SortedList(this.ModelInstance.Fields.Count); keys = new SortedList(); oldValues = new SortedList(); foreach (ModelField field in this.ModelInstance.Fields) { values[field.Name] = token.Value<string>(field.Mapping.IsNotEmpty() ? field.Mapping : field.Name) ?? token.Value<string>(field.Name); } if (id.IsNotEmpty()) { string idStr = token.Value<string>(id); int idInt; if (int.TryParse(idStr, out idInt)) { keys[id] = idInt; } else { keys[id] = idStr; } } BeforeRecordUpdatedEventArgs eBeforeRecordUpdated = new BeforeRecordUpdatedEventArgs(record, keys, values, oldValues); this.OnBeforeRecordUpdated(eBeforeRecordUpdated); if (eBeforeRecordUpdated.CancelAll) { break; } if (eBeforeRecordUpdated.Cancel) { continue; } if (ds !=null) { ds.GetView("").Update(keys, values, oldValues, this.UpdateCallback); } else { this.UpdateCallback(0, null); } } }
private void MakeUpdates(IDataSource ds, XmlDocument xml) { XmlNodeList updatingRecords = xml.SelectNodes("records/Updated/record"); string id = GetIdColumnName(); foreach (XmlNode node in updatingRecords) { record = node; values = new SortedList(this.Reader.Reader.Fields.Count); keys = new SortedList(); oldValues = new SortedList(); foreach (RecordField field in this.Reader.Reader.Fields) { XmlNode keyNode = node.SelectSingleNode(field.Name); values[field.Name] = keyNode != null ? keyNode.InnerText : null; } confirmation = null; if (id.IsNotEmpty()) { XmlNode keyNode = node.SelectSingleNode(id); string idStr = keyNode != null ? keyNode.InnerText : null; int idInt; if (int.TryParse(idStr, out idInt)) { keys[id] = idInt; } else { keys[id] = idStr; } if (this.UseIdConfirmation && keys[id] != null) { confirmation = changingEventArgs.ConfirmationList[keys[id].ToString()]; } } BeforeRecordUpdatedEventArgs eBeforeRecordUpdated = new BeforeRecordUpdatedEventArgs(record, keys, values, oldValues, confirmation); this.OnBeforeRecordUpdated(eBeforeRecordUpdated); if (eBeforeRecordUpdated.CancelAll) { break; } if (eBeforeRecordUpdated.Cancel) { continue; } if (ds != null) { ds.GetView("").Update(keys, values, oldValues, this.UpdateCallback); } else { this.UpdateCallback(0, null); } } }