public bool Update(DataRow r, DataRow observacion) { bool result = false; DBRepository repository = DBRepository.GetDbRepository(true); try { repository.BeginTransaction(); List <IDbDataParameter> paramList = new List <IDbDataParameter>(); Datasets.Tickets.TICKETSDataTable dtable = (Datasets.Tickets.TICKETSDataTable)r.Table; Datasets.Tickets.TICKETSRow dr = (Datasets.Tickets.TICKETSRow)r; paramList.Add(repository.DbFactory.getDataParameter("P_ID", DbType.Int32, Int32.Parse(dr[dtable.IDTICKETColumn].ToString()))); paramList.Add(repository.DbFactory.getDataParameter("P_IDOPERADOR", DbType.Int32, Int32.Parse(dr[dtable.IDOPERADORColumn].ToString()))); paramList.Add(repository.DbFactory.getDataParameter("P_IDAFILIADO", DbType.Int32, Int32.Parse(dr[dtable.IDAFILIADOColumn].ToString()))); paramList.Add(repository.DbFactory.getDataParameter("P_ID_PAIS_ORIGEN", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDPAIS_ORIGENColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_ID_PROV_ORIGEN", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDPROVINCIA_ORIGENColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_CIUDAD_ORIGEN", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDCIUDAD_ORIGENColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_ID_PAIS_DEST", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDPAIS_DESTINOColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_ID_PROV_DEST", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDPROVINCIA_DESTINOColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_CIUDAD_DEST", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDCIUDAD_DESTINOColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_IDPRESTADOR", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDPRESTADORColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_TELEFONO", DbType.String, dr[dtable.TELEFONOColumn].ToString())); paramList.Add(repository.DbFactory.getDataParameter("P_IDESTADO", DbType.Int32, Int32.Parse(dr[dtable.IDESTADOColumn].ToString()))); paramList.Add(repository.DbFactory.getDataParameter("P_CALLE_ORIGEN", DbType.String, dr[dtable.CALLE_ORIGENColumn].ToString())); paramList.Add(repository.DbFactory.getDataParameter("P_ALTURA_ORIGEN", DbType.String, dr[dtable.ALTURA_ORIGENColumn].ToString())); paramList.Add(repository.DbFactory.getDataParameter("P_CALLE_DESTINO", DbType.String, dr[dtable.CALLE_DESTINOColumn].ToString())); paramList.Add(repository.DbFactory.getDataParameter("P_ALTURA_DESTINO", DbType.String, dr[dtable.ALTURA_DESTINOColumn].ToString())); paramList.Add(repository.DbFactory.getDataParameter("P_ID_LOCALIDAD_DESTINO", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDLOCALIDAD_DESTINOColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_ID_LOCALIDAD_ORIGEN", DbType.Int32, Dataservices.IntNUlleable(Int32.Parse(dr[dtable.IDLOCALIDAD_ORIGENColumn].ToString())))); paramList.Add(repository.DbFactory.getDataParameter("P_IDPROBLEMA", DbType.Int32, Int32.Parse(dr[dtable.IDPROBLEMAColumn].ToString()))); paramList.Add(repository.DbFactory.getDataParameter("P_IDTIPOSERVICIO", DbType.Int32, Int32.Parse(dr[dtable.IDTIPOSERVICIOColumn].ToString()))); paramList.Add(repository.DbFactory.getDataParameter("P_TIPO_TICKET", DbType.String, dr[dtable.TIPO_TICKETColumn].ToString())); result = (repository.ExecuteUpdateProcedure(CONST_UPDATE_PROCEDURE_NAME, paramList, dr[dtable.OBJECTHASHColumn].ToString()) == 1); // Guardar Observaciones. DBRepository repositoryObservacion = DBRepository.GetDbRepository(repository); ObservacionDS dataserviceObservacion = new ObservacionDS(); Datasets.Observaciones.OBSERVACIONESRow obs = (Datasets.Observaciones.OBSERVACIONESRow)observacion; obs.IDTICKET = Int32.Parse(dr[dtable.IDTICKETColumn].ToString()); dataserviceObservacion.Create(obs); if (result) { repository.CommitTransaction(); } else { repository.RollbackTransaction(); } } catch (Exception ex) { throw ex; } return(result); }
/// <summary> /// Runs the worker. /// </summary> /// <param name="worker">The worker.</param> /// <param name="args">The <see cref="DoWorkEventArgs"/> instance containing the event data.</param> public async void RunWorker(BackgroundWorker worker, DoWorkEventArgs args) { NumberRecordsInserted = 0; DeleteExisting(); Action <IEnumerable <ElementMappingValueException>, IStatelessSession, int> guardErrors = (errorList, session, recordnum) => { foreach (var item in errorList) { GuardError(item.Element.Description, item.Message, recordnum, RecordState.CriticalError, session); } }; var getProgress = args.Argument as Func <ProgressState> ?? (() => ProgressState.Empty); CurrentProgress = getProgress() ?? ProgressState.Empty; int current = 0; int total = CurrentProgress.Total; var mappings = DataContextObject.RequiredMappings.Concat(DataContextObject.OptionalMappings) .Where(kvp => !string.IsNullOrWhiteSpace(kvp.Value) && kvp.Key != null) .ToDictionary(k => k.Key, v => v.Value); var connElem = Dataservices.Configuration; NotifyProgress(this, new ExtendedEventArgs <Action>(ApplyNullResults)); ValidationStarted(this, EventArgs.Empty); using (var session = DataContextObject.Provider.SessionFactory.OpenStatelessSession()) { var importer = DataContextObject.Mapper.CreateBulkImporter(session.Connection); try { EventHandler <ExtendedEventArgs <SqlConnection> > connectionRequested = (o, e) => e.Data = session.Connection as SqlConnection; importer.ConnectionRequested += connectionRequested; importer.Prepare(); using (var conn = Dataservices.ConnectionFactory()) { conn.Open(); try { using (var cmd = conn.CreateCommand() as OleDbCommand) { cmd.CommandText = string.Format("select {1} from [{0}]", connElem.SelectFrom, FactorySelectFields(mappings)); using (var rdr = cmd.ExecuteReader()) { try { while (rdr.Read() && !args.Cancel && !Cancelled) { if (worker.CancellationPending) { args.Cancel = true; } else { current++; var progress = new ProgressState(current, total); worker.ReportProgress((int)Math.Floor(progress.Ratio * 100d), progress); foreach (var kvp in mappings) { var ordinal = rdr.GetOrdinal(kvp.Value); var value = rdr.GetValue(ordinal); DataContextObject.Mapper[kvp.Key] = value; } //current++; var currentErrors = DataContextObject.Mapper.Errors.ToList(); var hasErrors = currentErrors.Any(); if (hasErrors) { guardErrors(currentErrors, session, current); } if (!hasErrors) { dynamic target = DataContextObject.Mapper.Target; var temp = (ValidationStatus)ValidateTarget(target, current, rdr, mappings, session); hasErrors |= temp.HasErrors; if (!hasErrors) { (target as DatasetRecord).Dataset = DataContextObject.DatasetItem; try { importer.Insert(target); NumberRecordsInserted++; } catch (Exception ex) { GuardError("DATA ERROR", ex.Message, current, RecordState.CriticalError, session); } } } DataContextObject.Mapper.Reset(); } } } finally { importer.Dispose(); } } } } finally { conn.Close(); EventAggregator.GetEvent <DisableWizardButtons>().Publish(true); } } } finally { importer.Dispose(); } } }