public ActionResult Ver_Encontrado(int?id) { Modelo_Encontrado me = new Modelo_Encontrado(); Modelo_Bienes mb = new Modelo_Bienes(); Bienes bie; if (id != null) { v_enc = me.obtener(id); bie = mb.obtener(v_enc.Id_bienes); Info datos = new Info(); datos.Obj_enc = v_enc; datos.Obj_bie = bie; ////arr = v_enc.arr_byte; //Image imagen; //MemoryStream ms = new MemoryStream(v_enc.arr_byte); // imagen = Image.FromStream(ms); //ms = new MemoryStream(); //imagen.Save(ms, ImageFormat.Jpeg); //ms.Position = 0; //return File(ms,"image/jpg"); return(View(datos)); } else { return(RedirectToAction("Consultar_Encontrado")); } }
public Encontrado obtener(int?id) { //try //{ MySqlDataReader rd; Encontrado enc = new Encontrado(); using (con = Conexion.conectar()) { using (cmd = new MySqlCommand()) { cmd.CommandText = "SP_O_Tabla_Encontrado"; //cmd.CommandText = string.Format("Select * from tbl_categoria where id_categoria='{0}'", id); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = con; cmd.Parameters.AddWithValue("_id_encontrado", id); rd = cmd.ExecuteReader(); while (rd.Read()) { byte[] arr_byte = (byte[])rd.GetValue(10); enc.Imagen_byte = arr_byte; enc.Id_encontrado = rd.GetInt32("id_encontrado"); enc.Id_inventario = rd.GetInt32("id_inventario"); enc.Inventario = rd.GetString("inventario"); enc.Id_bienes = rd.GetInt32("id_bienes"); enc.Bien = rd.GetString("bien"); enc.Codigo = rd.GetString("codigo"); enc.Id_categoria = rd.GetInt32("id_categoria"); enc.Categoria = rd.GetString("categoria"); enc.Fecha = rd.GetDateTime("fecha"); enc.Estado = rd.GetString("estado"); enc.Detalle_estado = rd.IsDBNull(11) ? "" : rd.GetString("detalle_estado"); enc.T_documento = rd.IsDBNull(12) ? "" : rd.GetString("t_documento"); enc.N_documento = rd.IsDBNull(13) ? "" : rd.GetString("n_documento"); enc.Archivo = rd.IsDBNull(14) ? null : rd.GetString("archivo"); enc.Marca = rd.GetString("marca"); enc.Modelo = rd.GetString("modelo"); enc.Color = rd.GetString("color"); enc.Serie = rd.GetString("serie"); } rd.Close(); } } return(enc); //} //catch (Exception) //{ // return null; //} }
public IHttpActionResult Post(FormDataCollection dataCollection) { int id_bien = Convert.ToInt32(dataCollection.Get("id_bien")); string estado = dataCollection.Get("estado"); DateTime fecha = Convert.ToDateTime(dataCollection.Get("fecha")); string descripcion = dataCollection.Get("descripcion"); string imagen = dataCollection.Get("imagen"); imagen = imagen.Replace(" ", "+"); //imagen = imagen.Replace("=", ""); /*int mod4 = imagen.Length%4; * if (mod4 != 0) * { * imagen += new string('=', 4 - mod4); * } * int cantidaddd = imagen.Length;*/ Modelo_Inventario mi = new Modelo_Inventario(); Modelo_Encontrado me = new Modelo_Encontrado(); Inventario inv; Encontrado enc = new Encontrado(); byte[] img_byte = Convert.FromBase64String(imagen); //byte[] img_byte = Encoding.ASCII.GetBytes(imagen); inv = mi.buscar_ultimo(); enc.Estado = estado; enc.Fecha = fecha; enc.Detalle_estado = descripcion; enc.Imagen_byte = img_byte; enc.Id_inventario = inv.Id_inventario; enc.Inventario = inv.Nombre; enc.Id_bienes = id_bien; enc.T_documento = ""; enc.N_documento = ""; enc.Archivo = ""; if (me.guardar(enc)) { return(Json(new { success = true, message = "Se registró correctamente" })); } else { return(Json(new { success = false, message = "No se registró correctamente" })); } }
public Boolean actualizar(Encontrado enc) { //try //{ using (con = Conexion.conectar()) { using (cmd = new MySqlCommand()) { cmd.CommandText = "SP_U_Tabla_Encontrado"; cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Connection = con; cmd.Parameters.AddWithValue("_id_encontrado", enc.Id_encontrado); cmd.Parameters.AddWithValue("_id_bienes", enc.Id_bienes); cmd.Parameters.AddWithValue("_id_inventario", enc.Id_inventario); cmd.Parameters.AddWithValue("_fecha", enc.Fecha); cmd.Parameters.AddWithValue("_estado", enc.Estado); cmd.Parameters.AddWithValue("_imagen", enc.Imagen_byte); cmd.Parameters.AddWithValue("_detalle_estado", enc.Detalle_estado); cmd.Parameters.AddWithValue("_t_documento", enc.T_documento); cmd.Parameters.AddWithValue("_n_documento", enc.N_documento); cmd.Parameters.AddWithValue("_archivo", enc.Archivo); //using (MemoryStream ms = new MemoryStream()) //{ // enc.Imagen.Save(ms, ImageFormat.Jpeg); // byte[] img_byte = ms.ToArray(); // cmd.Parameters.AddWithValue("_imagen", img_byte); //} if (cmd.ExecuteNonQuery() > 0) { return(true); } else { return(false); } } } //} //catch (Exception) //{ // return false; //} }
public ActionResult Registrar_Encontrado_Baja(int id_bien, int id_inventario, DateTime?mod_fecha, string mod_estado, string mod_descripcion, HttpPostedFileBase mod_imagen, string tipo_documento, string num_documento, HttpPostedFileBase adj_doc) { Encontrado enc = new Encontrado(); Modelo_Encontrado me = new Modelo_Encontrado(); string message; SortedList <string, string> error = new SortedList <string, string>(); if (id_bien == 0) { error.Add("sp_id_bien", "Seleccione el Bien"); } if (id_inventario == 0) { error.Add("sp_id_inventario", "Seleccione el inventario"); } if (mod_fecha == null) { error.Add("sp_mod_fecha", "Seleccione la Fecha"); } if (String.IsNullOrEmpty(mod_estado)) { error.Add("sp_mod_estado", "Seleccione el Estado"); } if (String.IsNullOrEmpty(mod_descripcion)) { error.Add("sp_mod_descripcion", "Describa el estado de bien"); } if (mod_imagen == null) { error.Add("sp_mod_imagen", "Ingrese una fotografia actual del bien"); } if (String.IsNullOrEmpty(tipo_documento)) { error.Add("sp_tipo_documento", "Seleccione el Tipo de documento"); } if (String.IsNullOrEmpty(num_documento)) { error.Add("sp_num_documento", "Ingrese el numero del documento"); } if (error.Count == 0) { Image img = cambiar_tamaño(mod_imagen); using (MemoryStream ms = new MemoryStream()) { img.Save(ms, ImageFormat.Jpeg); byte[] img_byte = ms.ToArray(); string im = Convert.ToBase64String(img_byte); enc.Id_bienes = id_bien == 0 ? 0 : id_bien; enc.Id_inventario = id_inventario == 0 ? 0 : id_inventario; enc.Fecha = mod_fecha == null ? DateTime.Now : mod_fecha.Value; enc.Estado = mod_estado == null ? "" : mod_estado; enc.Detalle_estado = mod_descripcion == null ? "" : mod_descripcion; enc.T_documento = tipo_documento == null ? "" : tipo_documento; enc.N_documento = num_documento == null ? "" : num_documento; enc.Archivo = adj_doc == null ? "": adj_doc.FileName; enc.Imagen_byte = img_byte == null ? null : img_byte; } if (me.guardar(enc)) { guardar_archivo(adj_doc); message = "Se guardaron los datos correctamente"; } else { message = "No se Guardaron lo datos"; } return(Json(new { message = message, success = true })); } else { message = "Ingrese los datos necesarios"; return(Json(new { message = message, success = false, datos = error })); } }
public ActionResult Modificar_Encontrado(int id, int id_bienes, int id_inventario, DateTime fecha, string estado, HttpPostedFileBase imagen) { Modelo_Encontrado me = new Modelo_Encontrado(); Encontrado enc = new Encontrado(); string message; SortedList <string, string> error = new SortedList <string, string>(); if (id != 0) { if (id_bienes == 0) { error.Add("sp_id_bienes", "Seleccione el Bien"); } if (id_inventario == 0) { error.Add("sp_id_inventario", "Seleccione el inventario"); } if (fecha == null) { error.Add("sp_fecha", "Selecciones la fecha"); } if (String.IsNullOrEmpty(estado)) { error.Add("sp_estado", "Seleccione el Estado"); } if (imagen == null) { error.Add("sp_imagen", "Seleccione una imagen"); } if (error.Count == 0) { Image img = cambiar_tamaño(imagen); using (MemoryStream ms = new MemoryStream()) { img.Save(ms, ImageFormat.Jpeg); byte[] arr = Convert.FromBase64String(ms.ToArray().ToString()); enc.Id_encontrado = id; enc.Id_bienes = id_bienes == 0 ? 0 : id_bienes; enc.Id_inventario = id_inventario == 0 ? 0 : id_inventario; enc.Fecha = fecha == null ? DateTime.Now : fecha; enc.Estado = estado == null ? "" : estado; enc.Imagen_byte = arr == null ? null : arr; } if (me.actualizar(enc)) { message = "Se actualizaron los datos correctamente"; } else { message = "No se logró actualizar lo datos"; } return(Json(new { message = message, success = true })); } else { message = "Ingrese los datos necesarios"; return(Json(new { message = message, success = false, datos = error })); } } return(RedirectToAction("Consultar_Encontrado")); }