//agregar private void button1_Click(object sender, EventArgs e) { int indice = cmbsintomas.SelectedIndex; if (this.indice != -1) { /*while (!encontrado || this.listasintomas.Count<iter) * { * if (this.listasintomas[iter].Id == this.indice) * { * encontrado = true; * posicion = iter; * } * iter++; * }*/ long id = this.listasintomas[indice].Id; DTSintoma sintomaData = this.listasintomas[indice]; string sintoma = this.listasintomas[indice].Sintoma; //MessageBox.Show("id:" + id + " el sintoma es: " + sintoma); List <DTSintoma> listaAux = this.list.Where(a => a.Id == id).ToList(); if (listaAux.Count == 0) { this.list.Add(sintomaData); EliminarSintomas(); ListarSintomas(); } } //List<> }
}//AgregarSintomaPatologia public List <DTSintoma> ListarSintomasPatologia(long idPatologia) { //throw new NotImplementedException(); List <DTSintoma> list = new List <DTSintoma>(); MySqlConnection conexion = null; MySqlDataReader reader = null; int idPatologiaInt = 0; if (idPatologia < int.MaxValue) { idPatologiaInt = (int)idPatologia; } try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql; sql = @"SELECT sp.idsintomas, sin.nombre, sp.coeficiente FROM sintomapatologia as sp inner join sintomas as sin on sin.idsintomas = sp.idsintomas where sp.idpatologia=@idpatologia;"; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@idpatologia", idPatologiaInt); reader = comando.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string idstring = (reader[0] != DBNull.Value) ? reader.GetString(0) : "0"; string sintomastring = (reader[1] != DBNull.Value) ? reader.GetString(1) : ""; string coeficiente = (reader[2] != DBNull.Value) ? reader.GetString(2) : "0"; long idLong = long.Parse(idstring); long idSinomaLong = long.Parse(idstring); double sintomaDouble = double.Parse(coeficiente); DTSintoma sintomadata = new DTSintoma(idSinomaLong, sintomastring, sintomaDouble); list.Add(sintomadata); } } } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); } finally { if (conexion != null) { conexion.Close(); } if (reader != null) { reader.Close(); } } return(list); }//end ListarSintomasPatologia
}//end ListarSintomasPatologia public List <DTSintoma> ListarSintomas() { List <DTSintoma> list = new List <DTSintoma>(); MySqlConnection conexion = null; MySqlDataReader reader = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql; sql = @"select idsintomas as id, nombre as nombre from sintomas order by idsintomas asc"; MySqlCommand comando = new MySqlCommand(sql, conexion); reader = comando.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { //string s = reader.GetNameGet["id"]; string id = (reader[0] != DBNull.Value) ? reader.GetString(0) : "0";; string sintoma = (reader[1] != DBNull.Value) ? reader.GetString(1) : ""; long idLong = long.Parse(id); DTSintoma sintomadata = new DTSintoma(idLong, sintoma); list.Add(sintomadata); } } } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); } finally { if (conexion != null) { conexion.Close(); } if (reader != null) { reader.Close(); } } return(list); } // endListarSintomas