public List <Desgaste> obtenerListaDesgastes(string filtro) { List <Desgaste> desgastes = new List <Desgaste>(); MySqlDataReader reader = null; String sql = @" select desgaste.id,desgaste.serialinterno,desgaste.descripcion, desgaste.cantidad,categoria.nombre,modelo.nombre,marca.nombre,unidad.nombre,empresa.nombre,desgaste.descontinuado,desgaste.dmotivo from desgaste left join categoria on desgaste.categoria_id=categoria.id left join modelo on desgaste.modelo_id=modelo.id left join marca on desgaste.marca_id=marca.id left join unidad on desgaste.unidad_id=unidad.id left join empresa on desgaste.empresa_id=empresa.id @filtro order by desgaste.descripcion"; try { using (MySqlConnection conex = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ToString())) { conex.Open(); sql = sql.Replace("@filtro", filtro); MySqlCommand comando = new MySqlCommand(sql, conex); reader = comando.ExecuteReader(); while (reader.Read()) { Desgaste desgaste = new Desgaste(); desgaste.id = reader.GetInt32(0); desgaste.control = reader[1] == DBNull.Value ? String.Empty : reader.GetValue(1).ToString(); desgaste.descrip = reader[2] == DBNull.Value ? String.Empty : reader.GetValue(2).ToString(); desgaste.cantidad = reader.GetFloat(3); desgaste.categoria = reader[4] == DBNull.Value ? String.Empty : reader.GetValue(4).ToString(); desgaste.modelo = reader[5] == DBNull.Value ? String.Empty : reader.GetValue(5).ToString(); desgaste.marca = reader[6] == DBNull.Value ? String.Empty : reader.GetValue(6).ToString(); desgaste.unidad = reader[7] == DBNull.Value ? String.Empty : reader.GetValue(7).ToString(); desgaste.empresa = reader[8] == DBNull.Value ? String.Empty : reader.GetValue(8).ToString(); desgaste.descontinuado = reader[9] == DBNull.Value ? String.Empty : reader.GetValue(9).ToString(); desgaste.dmotivo = reader[10] == DBNull.Value ? String.Empty : reader.GetValue(10).ToString(); desgastes.Add(desgaste); } } } catch { } finally { if (reader != null && !reader.IsClosed) { reader.Close(); } } return(desgastes); }
public int agregarExistencia(float cantidad, String obs, int desgaste_id, String usuario_id, String unidad, String responsable_id, String ubicacion_id, String tipo) { int retu = 1; String sql = "insert into existencia(cantidadAnterior,cantidadActual,obs,desgaste_id,usuario_id,unidad,responsable_id,ubicacion_id,tipo,cantidad) values(@cantidadAnterior,@cantidadActual,@obs,@desgaste_id,@usuario_id,@unidad,@responsable_id,@ubicacion_id,@tipo,@cantidad)"; Desgaste desgaste = new Desgaste(); cantidadAnterior = desgaste.obtenerCantidad(desgaste_id); if (tipo == "S") { cantidad = cantidad * (-1); } cantidadActual = cantidadAnterior + cantidad; if (cantidadActual < 0) { return(0); } try { using (MySqlConnection conex = new MySqlConnection(ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ToString())) { conex.Open(); MySqlCommand comando = new MySqlCommand(sql, conex); comando.Parameters.AddWithValue("@cantidadAnterior", cantidadAnterior); comando.Parameters.AddWithValue("@cantidadActual", cantidadActual); comando.Parameters.AddWithValue("@cantidad", cantidad); comando.Parameters.AddWithValue("@obs", obs.ToUpper()); comando.Parameters.AddWithValue("@desgaste_id", desgaste_id); comando.Parameters.AddWithValue("@usuario_id", usuario_id); comando.Parameters.AddWithValue("@unidad", unidad.ToUpper()); comando.Parameters.AddWithValue("@responsable_id", responsable_id); comando.Parameters.AddWithValue("@ubicacion_id", ubicacion_id); comando.Parameters.AddWithValue("@tipo", tipo); comando.ExecuteNonQuery(); if (!desgaste.actualizarCantidad(desgaste_id, cantidadActual)) { retu = -1; } } } catch { retu = -1; } return(retu); }