I have to access an application with the login and the correct pass, once I access it, it shows me the name in the activity of queries of the user who started the session.
Now I need to know the unanswered calls of that user, the user's data is in a database of a msql server and the data of the tasks are in another database of the same server. How can I get unanswered calls from that user?
Activity 1 this allows me to access the data with a specific user of the bd I am working correctly the problem is in activity 2
package com.example.usuario.controlllamadas;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.CursorAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Arrays;
import static android.R.attr.password;
import static android.R.attr.userVisible;
public class MainActivity extends AppCompatActivity {
Connection conn;
Button btnlogin;
EditText euser,epass;
TextView tuser,tpass;
String CUsuario;
String Pwd;
Boolean prueba=false,prueba2=false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnlogin = (Button) findViewById(R.id.BtnAceptar);
euser=(EditText) findViewById(R.id.TxtUsuario);
epass = (EditText) findViewById(R.id.TxtPassword);
tuser = (TextView) findViewById(R.id.TextView01);
tpass = (TextView) findViewById(R.id.TextView02);
btnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Pwd= epass.getText().toString();
CUsuario=euser.getText().toString();
Login tarea6=new Login(euser.getText().toString(),epass.getText().toString());
tarea6.execute();
}
});
}
private class Login extends AsyncTask<String, Integer, Boolean> {
public Login(String usuario, String contraseña) {
super();
}
@Override
protected Boolean doInBackground(String...usuario) {
conn = DBConnection.getInstance().getConnection();
try {
prueba = false;
prueba2=false;
String stsql = "SELECT CUsuario,Pwd FROM dbo.xUser WHERE CUsuario='"+CUsuario+"' or Pwd='"+Pwd+"'";
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery(stsql);
while (rs.next()) {
if(CUsuario.equals(rs.getString(1)) && Pwd.equals(rs.getString(2))) {
prueba = true;
CUsuario = rs.getString(1);
Pwd = rs.getString(2);
}
else if(CUsuario.equals(rs.getString(1))) {
prueba2=true;
}
}
}catch (SQLException e1) {
e1.printStackTrace();
}
publishProgress(100);
return true;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
if (CUsuario.equals("") || Pwd.equals("")) {
Toast.makeText(getApplicationContext(),"inserta un usuario y una contraseña", Toast.LENGTH_SHORT).show();
euser.setText("");
epass.setText("");
}
else if (prueba==true) {
Toast.makeText(getApplicationContext(), "acceso permitido", Toast.LENGTH_SHORT).show();
euser.setText(CUsuario);
epass.setText("");
String userstring = euser.getText().toString();
Intent siguiente = new Intent(MainActivity.this, Main2Activity.class);
siguiente.putExtra("USUARIO", userstring);
startActivity(siguiente);
euser.setText("");
epass.setText("");
prueba=false;
}
else if ((prueba == false)&&(prueba2==false)) {
Toast.makeText(getApplicationContext(), "contraseña y usuario incorrectos", Toast.LENGTH_SHORT).show();
euser.setText("");
epass.setText("");
}else{
Toast.makeText(getApplicationContext(), "usuario correcto,contraseña incorrecta", Toast.LENGTH_SHORT).show();
epass.setText("");
}
}
@Override
protected void onProgressUpdate(Integer... values) {//este es para interactuar con la interfaz grafica mientras esta en ejecucion la tarea asyncrona
int progreso = values[0].intValue();
}
}
}
}
Activity 2 This tells me in a textview
the user with whom I log in now what I need are the unanswered calls of that user but since they are in the same server in two bases of different data I do not know how to do the query.
package com.example.usuario.controlllamadas;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.lang.reflect.Type;
import java.sql.Connection;
import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class Main2Activity extends Activity {
Button btn1,btn2,btn3;
public TextView t1;
Connection conn3,conn;
String[]llamadas;
int IdLlamada;
Date Fecha;
String Mensaje;
String De;
String IdUsuarioDestino;
String Cusuario;
boolean Estado;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
t1=(TextView)findViewById(R.id.t1);
btn1= (Button) findViewById(R.id.Btnllamadasatendidas);
btn2= (Button) findViewById(R.id.Btnllamadasperdidas);
btn3= (Button) findViewById(R.id.Btncerrar);
Intent intent = getIntent();
String user= intent.getStringExtra("USUARIO");
t1.setText(user);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RegistroLlamadasatendidas tareaatendidas=new RegistroLlamadasatendidas();
tareaatendidas.execute();
}
});
btn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RegistroLlamadasperdidas tareaperdidas=new RegistroLlamadasperdidas();
tareaperdidas.execute();
}
});
btn3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
cerrar();
}
});
}
private void cerrar() {
finish();
}
I was going to do it in an asynchronous task, passing the field textview
that the user has already collected, I have it this way, can someone solve it for me?
private class RegistroLlamadasperdidas extends AsyncTask<String,Integer,Boolean> {
public RegistroLlamadasperdidas() {
super();
}
String consulta5;
protected Boolean doInBackground(String... params) {
conn3 = DBConnection3.getInstance().getConnection();
try {
// String stsql = "Select IdLlamada,Fecha,Mensaje,De,IdUsuarioDestino,Estado from dbo.Llamadas where Estado='0' and CUsuario='"+t1+"' ORDER BY IDLlamada asc";
//String stsql = "Select IdLlamada,Fecha,Mensaje,De,IdUsuarioDestino,Estado from dbo.Llamadas where Estado='0' ORDER BY IDLlamada asc";
String stsql = "Select sxPhoenix. dbo.xUser.dbo.CUsuario,IdLlamada,Fecha,Mensaje,De,IdUsuarioDestino,Estado from dbo.Llamadas,dbo.xUser where Estado='0' and CUsuario='"+t1+"' ORDER BY IDLlamada asc";
// ""'wordFlow.sxPhoenix.dbo.xUser.IdLlamada,wordFlow.sxPhoenix.dbo.xUserdbo.Fecha,wordFlow.sxPhoenix.dbo.xUserdbo.Mensaje=Mensaje,wordFlow.sxPhoenix.dbo.xUserdbo.De=De,wordFlow.sxPhoenix.dbo.xUserdbo.IdUsuarioDestino=IdUsuarioDestino,wordFlow.sxPhoenix.dbo.xUserdbo.Estado=Estado
// FROM sxPhoenix.dbo.xUser INNER
//FROM BASE1.dbo.TABLA1
//INNER JOIN BASE2.dbo.TABLA2 ON BASE2.dbo.TABLA2.CAMPO2.ID=BASE1.dbo.TABLA1.ID
Statement st = conn3.createStatement();
ResultSet rs = st.executeQuery(stsql);
while (rs.next()) {
IdLlamada = rs.getInt(1);
Fecha = rs.getDate(2);
Mensaje = rs.getString(3);
De = rs.getString(4);
IdUsuarioDestino = rs.getString(5);
Estado =true;
Cusuario=rs.getString(6);
consulta5 = "IdLlamada" + rs.getInt(1) + " Fecha " + rs.getDate(2) + " Mensaje " + rs.getString(3) + " De " + rs.getString(4) + " IdUsuarioDestino " + rs.getString(5)+ " CUsuario " + rs.getString(6);
System.out.println("IdLlamada" + rs.getInt(1) + " Fecha " + rs.getDate(2) + " Mensaje " + rs.getString(3) + " De " + rs.getString(4) + " IdUsuarioDestino " + rs.getString(5) + "Estado" + rs.getBoolean("Estado")+ "CUsuario" + rs.getString(6));
}
} catch (SQLException e1) {
e1.printStackTrace();
}
publishProgress(100);
return true;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected void onPostExecute(Boolean aBoolean) {
super.onPostExecute(aBoolean);
if (Estado=true) {
Toast.makeText(Main2Activity.this, "registro de llamadas perdidas", Toast.LENGTH_SHORT).show();}
Toast.makeText(Main2Activity.this,consulta5,Toast.LENGTH_LONG).show();
}}
}