//Ingresa los valores en las tablas, por nivel de profundidad // (primero las que no tienen relaciones) private void inicializarTablas(Excel.Range xlRange) { //int rowCount = xlRange.Rows.Count; //este no cuenta bien int rowCount = 79526; int colCount = xlRange.Columns.Count; Console.WriteLine(rowCount); //Itera por todas las filas y columnas e imprime su contenidos for (int i = 79501; i <= rowCount; i++) { string idRegistro = xlRange.Cells[i, 1].Value2.ToString(); string idProvincia = xlRange.Cells[i, 2].Value2.ToString(); string provincia = xlRange.Cells[i, 3].Value2.ToString(); string canton = xlRange.Cells[i, 4].Value2.ToString(); string distrito = xlRange.Cells[i, 5].Value2.ToString(); string dia = xlRange.Cells[i, 6].Value2.ToString(); string mes = xlRange.Cells[i, 7].Value2.ToString(); string anno = xlRange.Cells[i, 8].Value2.ToString(); string idRol = xlRange.Cells[i, 9].Value2.ToString(); string rol = xlRange.Cells[i, 10].Value2.ToString(); string idLesion = xlRange.Cells[i, 11].Value2.ToString(); string lesion = xlRange.Cells[i, 12].Value2.ToString(); string edad = xlRange.Cells[i, 13].Value2.ToString(); string edadQuinquenal = xlRange.Cells[i, 14].Value2.ToString(); string idSexo = xlRange.Cells[i, 15].Value2.ToString(); string sexo = xlRange.Cells[i, 16].Value2.ToString(); if (edad.Equals("Desconocida")) { edad = "0"; } Ubicacion ubicacion = gestorUbicaciones.getUbicacion(idProvincia, canton, distrito); if (ubicacion == null) { Console.WriteLine("Error en el registro: " + idRegistro); } else { string idCanton = ubicacion.CodigoCanton; string idDistrito = ubicacion.CodigoDistrito; double latitud = gradosADecimales(ubicacion.Latitud); double longitud = gradosADecimales(ubicacion.Longitud); // SE INSERTA EL REGISTRO EN LA BASE, DESCOMPONIENDOLO POR TABLAS SEGÚN RELACIONES string values; //PROVINCIAS if (!provincias.Contains(idProvincia)) { values = "'" + idProvincia + "','" + provincia + "'"; baseDatos.Agregar("Provincias", values); provincias.Add(idProvincia); } //CANTONES values = "'" + idProvincia + "','" + idCanton + "','" + canton + "'"; baseDatos.Agregar("Cantones", values); //DISTRITOS values = "'" + idProvincia + "','" + idCanton + "','" + idDistrito + "','" + distrito + "'," + latitud + "," + longitud; baseDatos.Agregar("Distritos", values); //ROLES if (!roles.Contains(idRol)) { values = idRol + ",'" + rol + "'"; baseDatos.Agregar("Roles", values); roles.Add(idRol); } //LESIONES if (!lesiones.Contains(idLesion)) { values = idLesion + ",'" + lesion + "'"; baseDatos.Agregar("Lesiones", values); lesiones.Add(idLesion); } //PERSONAS values = idRegistro + "," + edad + ",'" + edadQuinquenal + "','" + sexo + "'," + idLesion + "," + idRol; baseDatos.Agregar("Personas", values); //REGISTROS values = idRegistro + ",'" + idProvincia + "','" + idCanton + "','" + idDistrito + "','" + dia + "','" + mes + "'," + anno + "," + idRegistro; baseDatos.Agregar("Registros", values); } //ejecuta bloques de 100 en 100 if (i % 100 == 0 || i == rowCount) { baseDatos.ejecutarTodo(); } } }