public List <tbl_Fotos_arboles> Llamar_fotos_arboles(String idArbol) { tbl_Arbol ar = new tbl_Arbol(); ar.id_arbol = int.Parse(idArbol); List <tbl_Fotos_arboles> listaFo = new List <tbl_Fotos_arboles>(); List <tbl_Fotos_arboles> listaF = new tbl_Foto_arbolesCAD().Buscar_fotos(ar); foreach (var item in listaF) { String fil = HttpContext.Current.Server.MapPath(@"~/images/Fotos_Arbol/" + item.foto_arbol); bool existe = File.Exists(fil); if (existe) { tbl_Fotos_arboles fa = new tbl_Fotos_arboles(); StreamReader img = new StreamReader(fil); string imagenes = img.ReadLine(); String[] arregloimg = imagenes.Split('~'); for (int i = 0; i < arregloimg.Length - 1; i++) { fa.foto_arbol = arregloimg[i]; listaFo.Add(fa); } } } return(listaFo); }
public List <tbl_Fotos_arboles> Buscar_fotos(tbl_Arbol ar) { List <tbl_Fotos_arboles> lista = new List <tbl_Fotos_arboles>(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "prc_Buscar_tbl_Fotos_arboles_con_id_arbol"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", ar.id_arbol); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); foreach (var item in dr) { tbl_Fotos_arboles fa = new tbl_Fotos_arboles(); fa.foto_arbol = dr["foto_arbol"].ToString(); fa.id_arbol = int.Parse(dr["id_foto_arbol"].ToString()); lista.Add(fa); } con.Close(); } catch (Exception) { throw; } return(lista); }
public String Modificar_foto_arboles(tbl_Fotos_arboles tblFa) { String mensaje = "Error al modificar, intenta nuevamente"; try { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "prc_UPDATE_tbl_Foto_arboles"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@foto", tblFa.foto_arbol); cmd.Parameters.AddWithValue("@idA", tblFa.id_arbol); con.Open(); int rows = 0; rows = cmd.ExecuteNonQuery(); if (rows != 0) { mensaje = "Modificado correctamente"; } } catch (Exception e) { mensaje = e.Message; } return(mensaje); }
public string Insertar_imagen_arbol(string imagen, string nombreCientifico, string nombreComun, int especie) { tbl_Arbol tblAr = new tbl_Arbol(); tblAr.nom_cient_arbol = nombreCientifico; tblAr.nom_com_arbol = nombreComun; tblAr.id_especie_arbol = especie; tbl_Fotos_arboles tblfA = new tbl_Fotos_arboles(); tblfA.id_arbol = new tbl_ArbolCAD().Buscar_id_arbol(tblAr); tblfA.foto_arbol = nombreCientifico + ".txt"; string fil = HttpContext.Current.Server.MapPath(@"~/images/Fotos_Arbol/" + nombreCientifico + ".txt"); System.IO.StreamWriter file = new StreamWriter(fil); file.WriteLine(imagen); file.Close(); Boolean foto = System.IO.File.Exists(fil); string mensaje = ""; if (foto) { mensaje = new tbl_Foto_arbolesCAD().insert_foto_arboles(tblfA); } StreamReader sr = new StreamReader(fil); return(mensaje); //return new tbl_Foto_arbolesCAD().insert_foto_arboles(tblfA); }