Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. package company.viral.organizadorjec.ActivitysPrincipales;
  2.  
  3. import android.content.Context;
  4. import android.database.sqlite.SQLiteDatabase;
  5. import android.database.sqlite.SQLiteOpenHelper;
  6.  
  7. /**
  8. * Created by erny on 27/10/2016.
  9. */
  10.  
  11. public class SQLite extends SQLiteOpenHelper {
  12.  
  13. //constructor.......
  14. public SQLite(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
  15. super(context, name, factory, version);
  16. }
  17.  
  18.  
  19.  
  20. //aqui se crea la tabla...
  21. @Override
  22. public void onCreate(SQLiteDatabase db) {
  23. db.execSQL("create table usuarios (id_usuario integer primary key autoincrement,usuario text, clave text)");
  24.  
  25. db.execSQL("create table profesores (id_profesor integer primary key autoincrement,nombreprofesor text, comentarioprofesor text)");
  26.  
  27.  
  28.  
  29.  
  30.  
  31. db.execSQL("insert into usuarios values('0','admin','admin')");
  32. db.execSQL("insert into profesores values('0','alfonso','pirata')");
  33.  
  34.  
  35. }
  36.  
  37. @Override
  38. public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  39. db.execSQL("create table usuarios (id_usuario integer primary key autoincrement, " +
  40. "usuario text, clave text)");
  41.  
  42. db.execSQL("create table profesores (id_profesor integer primary key autoincrement, " +
  43. "nombreprofesor text, comentarioprofesor text)");
  44.  
  45.  
  46. db.execSQL("insert into usuarios values('0','admin','admin')");
  47. db.execSQL("insert into profesores values('0','alfonso','autobus')");
  48.  
  49.  
  50.  
  51. }
  52. }
  53.  
  54. package company.viral.organizadorjec.ActivitysPrincipales;
  55.  
  56. import android.content.Intent;
  57. import android.database.Cursor;
  58. import android.database.sqlite.SQLiteDatabase;
  59. import android.support.v7.app.AppCompatActivity;
  60. import android.os.Bundle;
  61. import android.view.View;
  62. import android.widget.EditText;
  63. import android.widget.Toast;
  64.  
  65. import company.viral.organizadorjec.R;
  66.  
  67. //aqui empieza...
  68. public class MainActivity extends AppCompatActivity {
  69.  
  70. //creamos variables EditText para capturar los datos
  71. private EditText aetid,aetpass;
  72. private Cursor fila;
  73.  
  74.  
  75. //en este metodo SIEMPRE se dibuja la app correspondiente
  76. @Override
  77. protected void onCreate(Bundle savedInstanceState) {
  78. super.onCreate(savedInstanceState);
  79. setContentView(R.layout.activity_main);
  80.  
  81. //antes de dibujar definimos las variables y a quienes pertecen en el layout
  82.  
  83. aetid = (EditText) findViewById(R.id.etid);
  84. aetpass = (EditText) findViewById(R.id.etpass);
  85.  
  86. }
  87.  
  88.  
  89.  
  90.  
  91.  
  92. //creamos los metodos con los que reaccionan los btn (onClick)
  93. /*metodo para entrar y buscar (en construccion.... explorando metodos)*/
  94. public void onClickAceptar (View view) {
  95.  
  96. String auxn = aetid.getText().toString();
  97. String auxp = aetpass.getText().toString();
  98.  
  99. SQLite admin = new SQLite(this,"administracion", null, 1);
  100. SQLiteDatabase bd = admin.getWritableDatabase();
  101.  
  102. fila=bd.rawQuery("select usuario, clave from usuarios where usuario='"+auxn+"'and clave='"+auxp+"'",null);
  103.  
  104.  
  105.  
  106. if(fila.moveToFirst()==true){
  107.  
  108. //capturamos los valores del cursos y lo almacenamos en variable
  109. String usua=fila.getString(0);
  110. String pass=fila.getString(1);
  111.  
  112. //preguntamos si los datos ingresados son iguales
  113. if (auxn.equals(usua)&&auxp.equals(pass)){
  114.  
  115. //si son iguales entonces vamos a otra ventana
  116. //Menu es una nueva actividad empty
  117. Intent ven=new Intent(this,MenuCentral.class);
  118.  
  119. startActivity(ven);
  120.  
  121. //limpiamos las las cajas de texto
  122. aetid.setText("");
  123. aetpass.setText("");
  124.  
  125. }
  126.  
  127. }else {
  128.  
  129. Toast.makeText(getApplicationContext(), "Usuario o contraseña erroneo", Toast.LENGTH_LONG).show();
  130. }
  131.  
  132. bd.close();
  133. }
  134.  
  135.  
  136. //metodo para entrar a la actividad de registro
  137.  
  138. public void onClickRegistro(View view){
  139. Intent i = new Intent(this,Registro.class);
  140. startActivity(i);
  141. }
  142.  
  143. }
  144.  
  145. package company.viral.organizadorjec.FragmentMenu;
  146.  
  147. import android.database.Cursor;
  148. import android.database.sqlite.SQLiteDatabase;
  149. import android.os.Bundle;
  150. import android.support.v4.app.Fragment;
  151. import android.view.LayoutInflater;
  152. import android.view.View;
  153. import android.view.ViewGroup;
  154. import android.widget.ArrayAdapter;
  155. import android.widget.ListView;
  156.  
  157. import company.viral.organizadorjec.R;
  158. import company.viral.organizadorjec.ActivitysPrincipales.SQLite;
  159.  
  160.  
  161. public class ProfesoresF extends Fragment {
  162. private Cursor buscador;
  163. @Override
  164. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  165. Bundle savedInstanceState) {
  166. // Inflate the layout for this fragment
  167. View view = inflater.inflate(R.layout.fragment_profesores, container, false);
  168.  
  169. SQLite admin = new SQLite(getContext(),"administracion",null,1);
  170. SQLiteDatabase bd = admin.getWritableDatabase();
  171.  
  172.  
  173. buscador=bd.rawQuery("select nombreprofesor from profesores ",null);
  174.  
  175. String [] listamateria = new String[buscador.getCount()];
  176.  
  177. int i=0;
  178. while (buscador.moveToNext()){
  179. String contenedor = buscador.getString(buscador.getColumnIndex("nombreprofesor"));
  180. listamateria[i]=contenedor;
  181. i++;
  182. }
  183.  
  184. //adaptadores
  185. //adaptador dias
  186.  
  187. ListView listaprofe = (ListView) view.findViewById(R.id.listprofef);
  188.  
  189. ArrayAdapter<String> listavistaprofes = new ArrayAdapter<String>(
  190. getActivity(),
  191. android.R.layout.simple_list_item_1,listamateria);
  192.  
  193.  
  194. listaprofe.setAdapter(listavistaprofes);
  195.  
  196. return view ;
  197. }
  198.  
  199.  
  200.  
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement