public string Insertar_imagen_ave(string imagen, string nombreCientifico, string nombreComun, int especie) { tbl_Ave tblAv = new tbl_Ave(); tblAv.Nombre_cientifico = nombreCientifico; tblAv.Nombre_comun = nombreComun; tblAv.id_Especie_ave = especie; tbl_Fotos_aves tblfA = new tbl_Fotos_aves(); tblfA.id_Aves = new tbl_AveCAD().Buscar_id_ave(tblAv); tblfA.Fotos_aves = nombreCientifico + ".txt"; string fil = HttpContext.Current.Server.MapPath(@"~/images/Fotos_Ave/" + nombreCientifico + ".txt"); 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_avesCAD().insert_foto_aves(tblfA); } StreamReader sr = new StreamReader(fil); return(mensaje); }
public String Modificar_foto_aves(tbl_Fotos_aves tblFa) { String mensaje = "Error al modificar, intenta nuevamente"; try { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "prc_UPDATE_tbl_Foto_aves"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@foto", tblFa.Fotos_aves); cmd.Parameters.AddWithValue("@idA", tblFa.id_Aves); con.Open(); int rows = 0; rows = cmd.ExecuteNonQuery(); if (rows != 0) { mensaje = "Modificado correctamente"; } } catch (Exception e) { mensaje = e.Message; } return(mensaje); }
public List <tbl_Fotos_aves> Buscar_fotos_aves(tbl_Ave av) { List <tbl_Fotos_aves> list = new List <tbl_Fotos_aves>(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = con; cmd.CommandText = "prc_Buscar_tbl_Fotos_aves_con_id_ave"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@id", av.id_Ave); con.Open(); SqlDataReader dr = cmd.ExecuteReader(); foreach (var item in dr) { tbl_Fotos_aves fa = new tbl_Fotos_aves(); fa.id_Fotos_aves = int.Parse(dr["id_foto_ave"].ToString()); fa.Fotos_aves = dr["foto_ave"].ToString(); list.Add(fa); } con.Close(); } catch (Exception) { throw; } return(list); }
public List <tbl_Fotos_aves> Llamar_fotos_aves(String idAve) { tbl_Ave ar = new tbl_Ave(); ar.id_Ave = int.Parse(idAve); List <tbl_Fotos_aves> listaFo = new List <tbl_Fotos_aves>(); List <tbl_Fotos_aves> listaF = new tbl_Foto_avesCAD().Buscar_fotos_aves(ar); foreach (var item in listaF) { String fil = HttpContext.Current.Server.MapPath(@"~/images/Fotos_Ave/" + item.Fotos_aves); bool existe = File.Exists(fil); if (existe) { tbl_Fotos_aves fa = new tbl_Fotos_aves(); StreamReader img = new StreamReader(fil); string imagenes = img.ReadLine(); String[] arregloimg = imagenes.Split('~'); for (int i = 0; i < arregloimg.Length - 1; i++) { fa.Fotos_aves = arregloimg[i]; fa.id_Fotos_aves = item.id_Fotos_aves; listaFo.Add(fa); } } } return(listaFo); }
public string Modificar_foto_ave(String imagen) { tbl_Ave tblAv = new tbl_Ave(); tblAv.Nombre_cientifico = HttpContext.Current.Session["ave"].ToString(); tbl_Fotos_aves tblfA = new tbl_Fotos_aves(); Random rn = new Random(); tblfA.id_Aves = new tbl_AveCAD().Buscar_id_ave_cient(tblAv); tblfA.Fotos_aves = tblAv.Nombre_cientifico + rn.Next(1, 9999) + ".txt"; string fil = HttpContext.Current.Server.MapPath(@"~/images/Fotos_Ave/" + tblfA.Fotos_aves); 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_avesCAD().Modificar_foto_aves(tblfA); } return(mensaje); }