public Int32 RegistrarUsuario(DTUsuario usu) { MySqlConnection conexion = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = @"insert into usuarios ( nombre,password) values (@nombre, @password)"; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@nombre", usu.Nombre); comando.Parameters.AddWithValue("@password", usu.Password); comando.ExecuteNonQuery(); //obtiene el ultimo id ingresado return(Int32.Parse(comando.LastInsertedId.ToString())); } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("Error: " + mensaje); return(-1); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } } }
}//ListarUsuarios end public int AgregarUsuario(string nombre, string estado, string password, string rolseleccionado) { MySqlConnection conexion = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = @"insert into usuarios (nombre,estado ,password, rol) values (@nombre, @estado,@password, @rol)"; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@nombre", nombre); comando.Parameters.AddWithValue("@estado", estado); comando.Parameters.AddWithValue("@password", password); comando.Parameters.AddWithValue("@rol", rolseleccionado); comando.ExecuteNonQuery(); //obtiene el ultimo id ingresado return(Int32.Parse(comando.LastInsertedId.ToString())); } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("Error: " + mensaje); return(-1); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } } }//end AgregarUsuario
public long AgregarPatologia1(string nombre, int gravedad) { MySqlConnection conexion = null; long idsintoma = 0; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = "insert into patologia (nombre,gravedad) values (@nombre,@gravedad)"; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@nombre", nombre); comando.Parameters.AddWithValue("@gravedad", gravedad); comando.ExecuteNonQuery(); //obtiene el ultimo id ingresado idsintoma = comando.LastInsertedId; } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } } return(idsintoma); }//end agregar patologia
}//end getmensajes public void Agregar(int idDiagnostico, int idUsuario, string mensaje) { //hago el insert //throw new NotImplementedException(); MySqlConnection conexion = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = @"insert into mensaje (idUsuario, idDiagnostico ,mensaje) values (?idusuario,?idiag,?mensaje)"; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.Add("?idusuario", MySqlDbType.Int32).Value = idUsuario; comando.Parameters.Add("?idiag", MySqlDbType.Int32).Value = idDiagnostico; comando.Parameters.Add("?mensaje", MySqlDbType.String).Value = mensaje; comando.ExecuteNonQuery(); //obtiene el ultimo id ingresado long id = comando.LastInsertedId; } catch (MySqlException ex) { string mensajeError = ex.ToString(); Console.WriteLine("hola" + mensajeError); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } } } //end agregar
public void ActualizartDiagnostico(int idDiagonostico) { MySqlConnection conexion = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = @"update diagnosticos set quierechat=1 where iddiagnosticos = @iddialog"; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@iddialog", idDiagonostico); comando.ExecuteNonQuery(); } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); } finally { if (conexion != null) { conexion.Close(); } } // }
}//end listar Diagnostico public void ActualizartDiagnosticoEstado(int idDiago) { MySqlConnection conexion = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = @"update diagnosticos SET estado='atendido' WHERE iddiagnosticos=@idDiago"; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@idDiago", idDiago); comando.ExecuteNonQuery(); } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } } }
public List <DTDiagnosticoMostrarMedico> ListarDiagnosticoMedico() { { 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 diag.estado='pendiente' order by pat.gravedad desc"; MySqlCommand comando = new MySqlCommand(sql, conexion); reader = comando.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string idDiagnosticoStr = (reader[0] != DBNull.Value) ? reader.GetString(0) : "0"; string estado = (reader[1] != DBNull.Value) ? reader.GetString(1) : "0"; string gravedadStr = (reader[2] != DBNull.Value) ? reader.GetString(2) : "0"; string nombrePatologia = (reader[3] != DBNull.Value) ? reader.GetString(3) : "0"; string nombrePaciente = (reader[4] != DBNull.Value) ? reader.GetString(4) : ""; int idDiagnosticoInt = int.Parse(idDiagnosticoStr); int graveddadInt = int.Parse(gravedadStr); DTDiagnosticoMostrarMedico dataMedico = new DTDiagnosticoMostrarMedico(idDiagnosticoInt, estado, graveddadInt, nombrePatologia, nombrePaciente); list.Add(dataMedico); } } } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); } finally { if (conexion != null) { conexion.Close(); } if (reader != null) { reader.Close(); } } return(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
public List <DTUsuario> ListarUsuarios() { List <DTUsuario> list = new List <DTUsuario>(); MySqlConnection conexion = null; MySqlDataReader reader = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); //nombre string sql = @"select idUsuarios, rol, nombre, estado from usuarios where 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("@password", usuarioPasword); reader = comando.ExecuteReader(); //si hay por lo menos una fila entra if (reader.HasRows) { while (reader.Read()) { string idUsuario = (reader[0] != DBNull.Value) ? reader.GetString(0) : ""; string rol = (reader[1] != DBNull.Value) ? reader.GetString(1) : ""; string nombre = (reader[2] != DBNull.Value) ? reader.GetString(2) : ""; string estado = (reader[3] != DBNull.Value) ? reader.GetString(3) : ""; int idUsuarioInt = int.Parse(idUsuario); DTUsuario data = new DTUsuario(nombre, idUsuarioInt, estado, rol); list.Add(data); } } } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("Error: " + mensaje); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } if (reader != null) { reader.Close(); conexion.Dispose(); } } return(list); }//ListarUsuarios end
}//end agregar patologia public List <DTPatologia> ListarPatologia() { List <DTPatologia> list = new List <DTPatologia>(); MySqlConnection conexion = null; MySqlDataReader reader = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql; sql = @"select idpatologia,gravedad,nombre from patologia order by idpatologia 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 gravedad = (reader[1] != DBNull.Value) ? reader.GetString(1) : "0";; string nombre = (reader[2] != DBNull.Value) ? reader.GetString(2) : ""; long idLong = long.Parse(id); int gravedadInt = int.Parse(gravedad); DTPatologia sintomadata = new DTPatologia(idLong, gravedadInt, nombre); 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); }
public List <DataChat> GetMensajes(int diag) { List <DataChat> list = new List <DataChat>(); MySqlDataReader reader = null; MySqlConnection conexion = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql; sql = @"select usu.nombre, men.mensaje from mensaje as men inner join usuarios as usu on usu.idUsuarios = men.idUsuario where men.idDiagnostico=?diag"; MySqlCommand comando = new MySqlCommand(sql, conexion); //comando.Parameters.AddWithValue("@diag", diag); comando.Parameters.Add("?diag", MySqlDbType.Int32).Value = diag; reader = comando.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { string nombre = (reader[0] != DBNull.Value) ? reader.GetString(0) : ""; string mensaje = (reader[1] != DBNull.Value) ? reader.GetString(1) : ""; DataChat dataMensaje = new DataChat(nombre, mensaje); list.Add(dataMensaje); } } } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } if (reader != null) { reader.Close(); reader.Dispose(); } } return(list); }//end getmensajes
public DTUsuario ObtenerUsuario(DTUsuario usu) { DTUsuario uARetornar = null; MySqlConnection conexion = null; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = "select idusuario, nombre, password from usuarios where nombre = @nombre and password = @password "; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@nombre", usu.Nombre); comando.Parameters.AddWithValue("@password", usu.Password); MySqlDataReader reader = comando.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Int32 id = reader.GetInt32(0); string nombre = (reader[1] != DBNull.Value) ? reader.GetString(1) : ""; string password = (reader[2] != DBNull.Value) ? reader.GetString(2) : ""; uARetornar = new DTUsuario(id, nombre, password); } } return(uARetornar); } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("Error: " + mensaje); return(uARetornar); } finally { if (conexion != null) { conexion.Close(); } } }
public int AgregarDiagnostico(int idpatologia, int idUsuario, int gravedad) { // 'pendiente' string estadoDiagnostico = "pendiente"; MySqlConnection conexion = null; int iddiagnostico = -1; try { conexion = ConexionDB.GetConexion(); conexion.Open(); string sql = @"insert into diagnosticos (idPaciente, estado, gravedad, idPatologia) values (@idPaciente, @estado, @gravedad,@idPatologia)"; MySqlCommand comando = new MySqlCommand(sql, conexion); comando.Parameters.AddWithValue("@idPaciente", idUsuario); comando.Parameters.AddWithValue("@estado", estadoDiagnostico); comando.Parameters.AddWithValue("@gravedad", gravedad); comando.Parameters.AddWithValue("@idPatologia", idpatologia); comando.ExecuteNonQuery(); //obtiene el ultimo id ingresado long idDiagnosticoLong = comando.LastInsertedId; if (iddiagnostico <= int.MaxValue) { iddiagnostico = (int)idDiagnosticoLong; } } catch (MySqlException ex) { string mensaje = ex.ToString(); Console.WriteLine("hola" + mensaje); } finally { if (conexion != null) { conexion.Close(); conexion.Dispose(); } } return(iddiagnostico); }//end agregar patologia
}//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