public ActionResult GeolocationPointPost(HttpPostedFileBase postedFIle, TransData transdata) { List <GeolocationPoint> geolocations = new List <GeolocationPoint>(); string filepath = string.Empty; if (postedFIle != null) { filepath = Server.MapPath("~/DB/") + Path.GetFileName(postedFIle.FileName); string csvData = System.IO.File.ReadAllText(filepath, Encoding.Default); int counter = 0; foreach (string row in csvData.Split('\n')) { if (row != null && row != "" && counter != 0) { GeolocationPoint geolocation = new GeolocationPoint { Inep = Convert.ToString(row.Split(',')[0]), Latitude = Convert.ToString(row.Split(',')[1]), Longitude = Convert.ToString(row.Split(',')[2]) }; geolocations.Add(geolocation); if (counter > 1) { mainSqlService.InsertGeolocation(geolocation, Server.MapPath("~/DB/banco.db")); } } counter++; } } transdata.Points = geolocations; return(View("Index", "_Layout", transdata)); }
public void InsertGeolocation(GeolocationPoint geolocation, string path) { if (string.IsNullOrEmpty(path)) { throw new Exception("Não é possível gravar sem o caminho esperado do banco."); } else { geolocationDAO.InsertGeolocation(geolocation, path); } }
public void InsertGeolocation(GeolocationPoint geolocation, string path) { try { using (var cmd = DbConnection(path).CreateCommand()) { cmd.CommandText = "INSERT INTO GeolocationPoint (Inep, Latitude, Longitude) values(@Inep, @Latitude, @Longitude)"; cmd.Parameters.AddWithValue("@Inep", geolocation.Inep); cmd.Parameters.AddWithValue("@Longitude", geolocation.Longitude); cmd.Parameters.AddWithValue("@Latitude", geolocation.Latitude); cmd.ExecuteNonQuery(); cmd.Connection.Close(); } } catch (Exception ex) { // throw new Exception("Não foi possível gravar o registro no banco: " + ex.Message); } }
public GeolocationPoint Geolocation(string path, string Innep) { GeolocationPoint point = new GeolocationPoint(); try { var command = DbConnection(path).CreateCommand(); command.CommandText = "SELECT * FROM GeolocationPoint WHERE Inep like @Inep"; var reader = command.ExecuteReader(); command.Connection.Close(); while (reader.Read()) { point = (new GeolocationPoint { Inep = reader["Inep"].ToString(), Latitude = reader["Latitude"].ToString(), Longitude = reader["Longitude"].ToString() }); } } catch (Exception ex) { throw ex; } if (point == null) { return(null); } else { return(point); } }