}//end agregar patologia public List <DTDiagnosticoMostrarMedico> ListarDiagnostico() { List <DTDiagnosticoMostrarMedico> list = new List <DTDiagnosticoMostrarMedico>(); MySqlConnection conexion = null; MySqlDataReader reader = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql; sql = @"select diag.iddiagnosticos, diag.estado, diag.gravedad, pat.nombre, usu.nombre from diagnosticos as diag inner join patologia as pat on pat.idPatologia = diag.idPatologia inner join usuarios as usu on diag.idPaciente = usu.idUsuarios where diag.quierechat=1 and estado='pendiente' order by pat.gravedad desc"; MySqlCommand comando = new MySqlCommand(sql, conexion); reader = comando.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string iddiagnostico = (reader[0] != DBNull.Value) ? reader.GetString(0) : "0";; string idpatologia = (reader[1] != DBNull.Value) ? reader.GetString(1) : "0";; string idpaciente = (reader[2] != DBNull.Value) ? reader.GetString(2) : "0"; string iddoctor = (reader[3] != DBNull.Value) ? reader.GetString(3) : "0"; string nombrepatologia = (reader[4] != DBNull.Value) ? reader.GetString(4) : ""; string chat = (reader[5] != DBNull.Value) ? reader.GetString(5) : ""; string nombrepaciente = (reader[6] != DBNull.Value) ? reader.GetString(6) : ""; string nombredoctor = (reader[7] != DBNull.Value) ? reader.GetString(7) : ""; int iddiagnosticoInt = int.Parse(iddiagnostico); int idpatologiaInt = int.Parse(idpatologia); int idpacienteInt = int.Parse(idpaciente); int iddoctorInt = int.Parse(iddoctor); string nombrepatologiaVarchar = nombrepatologia; string chatVarchar = chat; string nombrepacienteVarchar = nombrepaciente; string nombredoctorVarchar = nombredoctor; } } } 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 listar Diagnostico
}//end AgregarUsuario /// <summary> /// login /// </summary> /// <param name="usu"></param> /// <returns></returns> public int ObtenerUsuario(string usuarioNombre, string usuarioPasword, string usuarioRol) { int uARetornar = -2; MySqlConnection conexion = null; MySqlDataReader reader = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); //nombre string sql = @"select idUsuarios, password, rol from usuarios where nombre=@nombre and estado='activo'"; /*string sql = @"select idUsuarios, nombre, password, * from usuarios where nombre=@nombre and password=@password";*/ MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@nombre", usuarioNombre); //comando.Parameters.AddWithValue("@password", usuarioPasword); reader = comando.ExecuteReader(); //si hay por lo menos una fila entra if (reader.HasRows) { while (reader.Read()) { int id = reader.GetInt32(0); //string nombre = (reader[1] != DBNull.Value) ? reader.GetString(1) : ""; string password = (reader[1] != DBNull.Value) ? reader.GetString(1) : ""; string rol = (reader[2] != DBNull.Value) ? reader.GetString(2) : ""; if ((rol == usuarioRol || rol == "admin") && password == usuarioPasword) { uARetornar = id; } //string password = (reader[2] != DBNull.Value) ? reader.GetString(2) : ""; //string rol = (reader[3] != DBNull.Value) ? reader.GetString(2) : ""; //if (usuarioRol==) } } } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("Error: " + mensaje); uARetornar = -1; } finally { /**/ if (conexion != null) { conexion.Close(); conexion.Dispose(); } if (reader != null) { reader.Close(); conexion.Dispose(); } } return(uARetornar); } //end
public void AgregarSintomaPatologia(List <DTSintoma> list, long idPatologia) { //long idsintoma = 0; MySqlConnection conexion = null; MySqlTransaction trans = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = "insert into productos (codigo, descripcion,precio,fecha) values " + "(@codigo, @descripcion, @precio, @fecha)"; MySqlCommand comando = new MySqlCommand(sql, conexion); sql = "delete from sintomapatologia where idpatologia=@idpat"; comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@idpat", idPatologia); comando.ExecuteNonQuery(); conexion.Close(); conexion.Dispose(); conexion = ConexionDB.GetConexion(); conexion.Open(); sql = @"insert into sintomapatologia (idsintomas, idpatologia, coeficiente) VALUES(@idsintoma, @idpatologia, @coef)"; comando = new MySqlCommand(sql, conexion); trans = conexion.BeginTransaction(); /*long longVar = 15; * int entero = 15; * if (longVar< int.MaxValue) * { * entero = (int) longVar; * }*/ //int.MaxValue; foreach (DTSintoma item in list) { comando.Parameters.Clear(); comando.Parameters.AddWithValue("@idsintoma", item.Id); comando.Parameters.AddWithValue("@idpatologia", idPatologia); comando.Parameters.AddWithValue("@coef", item.Coef); comando.ExecuteNonQuery(); } trans.Commit(); } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); trans.Rollback(); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } if (trans != null) { trans.Dispose(); } } }//AgregarSintomaPatologia