private void MakeInsertes(IDataSource ds, XmlDocument xml) { XmlNodeList insertingRecords = xml.SelectNodes("records/Created/record"); string id = GetIdColumnName(); foreach (XmlNode node in insertingRecords) { 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); if (this.UseIdConfirmation && keyNode != null && keyNode.InnerText.IsNotEmpty()) { confirmation = changingEventArgs.ConfirmationList[keyNode.InnerText]; } } BeforeRecordInsertedEventArgs eBeforeRecordInserted = new BeforeRecordInsertedEventArgs(record, keys, values, confirmation); this.OnBeforeRecordInserted(eBeforeRecordInserted); if (eBeforeRecordInserted.CancelAll) { break; } if (eBeforeRecordInserted.Cancel) { continue; } if (ds != null) { ds.GetView("").Insert(values, InsertCallback); } else { this.InsertCallback(0, null); } } if (insertingRecords.Count > 0) { needRetrieve = true; } }
protected virtual void OnBeforeRecordInserted(BeforeRecordInsertedEventArgs e) { BeforeRecordInsertedEventHandler handler = (BeforeRecordInsertedEventHandler)Events[EventBeforeRecordInserted]; if (handler != null) { handler(this, e); } }
private void MakeInsertes(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; } BeforeRecordInsertedEventArgs eBeforeRecordInserted = new BeforeRecordInsertedEventArgs(record, keys, values); this.OnBeforeRecordInserted(eBeforeRecordInserted); if (eBeforeRecordInserted.CancelAll) { break; } if (eBeforeRecordInserted.Cancel) { continue; } if (ds != null) { ds.GetView("").Insert(values, InsertCallback); } else { this.InsertCallback(0, null); } } }
private void MakeInsertes(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); } BeforeRecordInsertedEventArgs eBeforeRecordInserted = new BeforeRecordInsertedEventArgs(record, keys, values); this.OnBeforeRecordInserted(eBeforeRecordInserted); if (eBeforeRecordInserted.CancelAll) { break; } if (eBeforeRecordInserted.Cancel) { continue; } if (ds != null) { ds.GetView("").Insert(values, InsertCallback); } else { this.InsertCallback(0, null); } } }
/// <summary> /// Ejecuta el evento antes de insertar un registro en la base de datos. /// </summary> /// <param name="e"></param> protected void AlInsertarRecord(ref BeforeRecordInsertedEventArgs 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 insertar if (AlInsertar != 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"); } CallAlInsertar(obj, ref e); } }
/// <summary> /// Ejecuta el evento "AlInsertar". /// </summary> /// <param name="tag"></param> /// <param name="e"></param> protected void CallAlInsertar(object tag, ref BeforeRecordInsertedEventArgs e) { if (AlInsertar != null) { EventInsertAbm ev = new EventInsertAbm(tag, ref e); AlInsertar.Invoke(this, ev); } }
public EventInsertAbm(object tag, ref BeforeRecordInsertedEventArgs parentEventArgs) : base() { Tag = tag; ParentEventArgs = parentEventArgs; }
private void MakeInsertes(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); } BeforeRecordInsertedEventArgs eBeforeRecordInserted = new BeforeRecordInsertedEventArgs(record, keys, values); this.OnBeforeRecordInserted(eBeforeRecordInserted); if (eBeforeRecordInserted.CancelAll) { break; } if (eBeforeRecordInserted.Cancel) { continue; } if (ds != null) { ds.GetView("").Insert(values, InsertCallback); } else { this.InsertCallback(0, null); } } }