0% found this document useful (0 votes)
35 views32 pages

Main Activity

XVXXVCXVC

Uploaded by

silvestre004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views32 pages

Main Activity

XVXXVCXVC

Uploaded by

silvestre004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

MainActivity.

java

import android.os.Bundle;
import android.preference.PreferenceManager;
import android.app.Activity;
import android.view.Menu;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button alumno=(Button)findViewById(R.id.button1);
Button carrera=(Button)findViewById(R.id.button2);
Button prof=(Button)findViewById(R.id.button3);
Button curs=(Button)findViewById(R.id.button4);

alumno.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this,ALUMO.class));
}
});

carrera.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this,CARRERA.class));
}
});

prof.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new
Intent(MainActivity.this,PROFESORES.class));
}
});

curs.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
startActivity(new Intent(MainActivity.this,CURSO.class));
}
});

}
Activity_main.xml

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondoazul"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="44dp"
android:text="PROFESORES" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginRight="43dp"
android:layout_marginTop="49dp"
android:layout_toLeftOf="@+id/button4"
android:text="ALUMNO" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button3"
android:layout_alignBottom="@+id/button3"
android:layout_alignLeft="@+id/button4"
android:text="CARRERA" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button3"
android:layout_alignParentRight="true"
android:layout_marginRight="19dp"
android:text="CURSOS" />

</RelativeLayout>
Dbmatricula.java

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class dbmatricula extends SQLiteOpenHelper {

public dbmatricula(Context context, String name, CursorFactory


factory,
int version) {
super(context, name, factory, version);
// TODO Auto-generated constructor stub
}

public void onCreate(SQLiteDatabase db){

db.execSQL("create table alumno(cod_alu integer primary key,


nom_alu text, dir_alu text, correo text, celular integer)");
db.execSQL("create table carrera(cod_carrera integer primary
key, carrera text)");
db.execSQL("create table profesores(cod_prof integer primary
key, nom_prof text, telefono integer, dir_prof text,email text)");
db.execSQL("create table cursos(cod_cursos integer primary
key,nom_curso text)");

public void onUpgrade(SQLiteDatabase db, int VerAnt, int VerNew){


db.execSQL("drop table if exists alumno");
db.execSQL("drop table if exists carrera");
db.execSQL("drop table if exists profesores");
db.execSQL("drop table if exists cursos");
db.execSQL("create table alumno(cod_alu integer primary key,
nom_alu text, dir_alu text, correo text, celular integer)");
db.execSQL("create table carrera(cod_carrera integer primary
key, carrera text)");
db.execSQL("create table profesores(cod_prof integer primary
key, nom_prof text, telefono integer, dir_prof text,email text)");
db.execSQL("create table cursos(cod_cursos integer primary
key,nom_curso text)");
}
}
Activity_login.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/fondoazul"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".LOGIN" >

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="117dp"

android:textSize="29dp"

android:textStyle="bold"

android:textColor="#0B2FF8"

android:shadowRadius="1.8"

android:text="Login" />

<EditText

android:id="@+id/txtlog"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true"

android:layout_marginTop="27dp"

android:ems="10"

android:inputType="textPassword" />

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@+id/txtlog"

android:layout_centerHorizontal="true"

android:layout_marginTop="63dp"

android:text="ingresar"

android:textColor="#0B2FF8"

android:textStyle="bold" />

</RelativeLayout>
Login.java

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.view.View.OnClickListener;
import android.content.Intent;

public class LOGIN extends Activity {


EditText contra;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);

contra=(EditText) findViewById(R.id.txtlog);
final Button button1=(Button)findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if
(contra.getText().toString().equals("administrador"))
startActivity(new
Intent(LOGIN.this,MainActivity.class));
else

Toast.makeText(button1.getContext(),"Error",Toast.LENGTH_SHORT).show();
}
}); }

}
Activity_curso.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondoazul"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CURSO" >

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button3"
android:layout_alignTop="@+id/button4"
android:onClick="insertar"
android:text="INSERTAR" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="32dp"
android:onClick="actualizar"
android:text="ACTUALIZAR" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_marginLeft="18dp"
android:layout_toRightOf="@+id/button2"
android:onClick="consultadatos"
android:text="CONSULTA" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button4"
android:layout_alignRight="@+id/button4"
android:layout_marginBottom="22dp"
android:onClick="eliminar"
android:text="ELIMINAR" />

<EditText
android:id="@+id/txtnomO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_centerVertical="true"
android:ems="10" >
<requestFocus />
</EditText>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtnomO"
android:layout_marginBottom="20dp"
android:layout_toLeftOf="@+id/button3"
android:text="NOMBRE-CURSO" />

<EditText
android:id="@+id/txtcodO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView3"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:ems="10" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/txtcodO"
android:layout_alignLeft="@+id/txtcodO"
android:layout_marginBottom="17dp"
android:text="COD-CURSO" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_marginBottom="30dp"
android:layout_toRightOf="@+id/textView1"
android:text="CURSO"
android:textAppearance="?android:attr/textAppearanceLarge" />

</RelativeLayout>

Curso.java

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class CURSO extends Activity {


EditText codcurs,codcar,codprof,nomcur;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_curso);

codcurs=(EditText) findViewById(R.id.txtcodO);
nomcur=(EditText) findViewById(R.id.txtnomO);

public void insertar(View v){


dbmatricula gestion =new dbmatricula(this,"bdcursos", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();

int codigo=Integer.parseInt(codcurs.getText()+"");
String nom=nomcur.getText().toString();

ContentValues registro=new ContentValues();


registro.put("cod_cursos", codigo);
registro.put("nom_curso", nom);

bd.insert("cursos", null, registro);


bd.close();
codcurs.setText("");
nomcur.setText("");

Toast.makeText(this, "Se cargaron los datos",


Toast.LENGTH_SHORT).show();
}

public void eliminar(View v){


dbmatricula gestion=new dbmatricula(this,"bdcursos", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();
int codigo=Integer.parseInt(codcurs.getText()+"");
int cant = bd.delete("cursos", "cod_cursos=" + codigo, null);
bd.close();
codcurs.setText("");
if(cant==1)
Toast.makeText(this, "Se borraron los datos",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
}

public void consultadatos(View v){


dbmatricula gestion=new dbmatricula(this,"bdcursos", null,1);
SQLiteDatabase bdatos=gestion.getWritableDatabase();
String codigo=codcurs.getText().toString();
Cursor fila=bdatos.rawQuery("select nom_curso from cursos where
cod_cursos=" + codigo, null);
if(fila.moveToFirst()){
nomcur.setText(fila.getString(0));

}
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
bdatos.close();
}
public void actualizar(View v){
dbmatricula gestion=new dbmatricula(this,"bdcursos", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();
String codigo=codcurs.getText().toString();
String nom=nomcur.getText().toString();

ContentValues registro=new ContentValues();


registro.put("nom_curso", nom);

int cant=bd.update("cursos", registro, "cod_cursos="+ codigo,


null);
if(cant==1)
Toast.makeText(this, "Se modificaron los datos",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
}
}
Activy_carrera.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondoazul"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".CARRERA" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="@+id/textView4"
android:text="CARRERA"
android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtcodP"
android:layout_below="@+id/textView1"
android:layout_marginTop="19dp"
android:text="CODIGO" />

<EditText
android:id="@+id/txtcodP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_below="@+id/textView2"
android:layout_marginTop="23dp"
android:ems="10" >

<requestFocus />
</EditText>

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtcorP"
android:layout_below="@+id/txtcodP"
android:layout_marginTop="18dp"
android:text="CARRERA" />

<EditText
android:id="@+id/txtcorP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView4"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:ems="10" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/txtcorP"
android:layout_marginRight="18dp"
android:layout_marginTop="34dp"
android:onClick="actualizar"
android:text="ACTUALIZAR" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button4"
android:layout_alignBottom="@+id/button4"
android:layout_marginRight="16dp"
android:layout_toLeftOf="@+id/button4"
android:onClick="eliminar"
android:text="ELIMINAR" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="44dp"
android:onClick="insertar"
android:text="INSERTAR" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button1"
android:layout_alignBottom="@+id/button1"
android:layout_alignRight="@+id/button4"
android:onClick="consultadatos"
android:text="CONSULTA" />

</RelativeLayout>

Carrera.java

import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class CARRERA extends Activity {


EditText cod,carrera;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_carrer);

cod=(EditText) findViewById(R.id.txtcodP);
carrera=(EditText) findViewById(R.id.txtcorP);

public void insertar(View v){


dbmatricula gestion =new dbmatricula(this,"bdcarrera", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();

int codigo=Integer.parseInt(cod.getText()+"");
String car=carrera.getText().toString();

ContentValues registro=new ContentValues();


registro.put("cod_carrera", codigo);
registro.put("carrera", car);

bd.insert("carrera", null, registro);


bd.close();
cod.setText("");
carrera.setText("");

Toast.makeText(this, "Se cargaron los datos",


Toast.LENGTH_SHORT).show();
}

public void eliminar(View v){


dbmatricula gestion=new dbmatricula(this,"bdcarrera", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();
int codigo=Integer.parseInt(cod.getText()+"");
int cant = bd.delete("carrera", "cod_carrera=" + codigo, null);
bd.close();
cod.setText("");
if(cant==1)
Toast.makeText(this, "Se borraron los datos",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
}

public void consultadatos(View v){


dbmatricula gestion = new dbmatricula(this,"bdcarrera", null,1);
SQLiteDatabase bdatos=gestion.getWritableDatabase();
String codigo=cod.getText()+"";

Cursor fila=bdatos.rawQuery("select carrera from carrera where


cod_carrera=" + codigo, null);
if(fila.moveToFirst()){
carrera.setText(fila.getString(0));

}
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
bdatos.close();
}
public void actualizar(View v){

dbmatricula gestion=new dbmatricula(this,"bdcarrera", null,1);


SQLiteDatabase bd=gestion.getWritableDatabase();

int codigo=Integer.parseInt(cod.getText()+"");
String car=carrera.getText().toString();
ContentValues registro=new ContentValues();
registro.put("cod_carrera",codigo);
registro.put("carrera",car);

int cant=bd.update("carrera", registro, "cod_carrera="+ codigo,


null);
if(cant==1)
Toast.makeText(this, "Se modificaron los datos",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
}

}
Activity_alumno.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/fondoazul"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".ALUMO" >

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentLeft="true"

android:layout_alignParentTop="true"

android:layout_marginLeft="90dp"

android:text="ALUMNOs"

android:textAppearance="?android:attr/textAppearanceLarge" />

<Button

android:id="@+id/button2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_alignTop="@+id/button1"

android:layout_marginRight="36dp"

android:onClick="eliminar"
android:text="ELIMINAR" />

<Button

android:id="@+id/button4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignLeft="@+id/button2"

android:layout_alignParentBottom="true"

android:layout_marginBottom="15dp"

android:onClick="actualizar"

android:text="ACTUALIZAR" />

<Button

android:id="@+id/button3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignBaseline="@+id/button4"

android:layout_alignBottom="@+id/button4"

android:layout_alignRight="@+id/button1"

android:onClick="consultadatos"

android:text="CONSULTA" />

<Button

android:id="@+id/button1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/button3"

android:layout_toLeftOf="@+id/button2"

android:onClick="insertar"

android:text="INSERTAR" />
<EditText

android:id="@+id/txtcorrA"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/textView6"

android:layout_alignLeft="@+id/txtcelA"

android:ems="10" />

<EditText

android:id="@+id/txtdireA"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/textView5"

android:layout_alignLeft="@+id/button3"

android:ems="10" />

<TextView

android:id="@+id/textView4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/txtdireA"

android:layout_alignLeft="@+id/textView3"

android:text="DIRECION" />

<EditText

android:id="@+id/txtalumA"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/textView4"

android:layout_alignLeft="@+id/txtdireA"

android:ems="10" />
<EditText

android:id="@+id/txtcelA"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/button2"

android:layout_alignLeft="@+id/button1"

android:ems="10" />

<TextView

android:id="@+id/textView3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/txtalumA"

android:layout_alignLeft="@+id/txtalumA"

android:text="ALUMNO" />

<TextView

android:id="@+id/textView5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/txtcorrA"

android:layout_alignLeft="@+id/txtdireA"

android:text="CORREO" />

<TextView

android:id="@+id/textView6"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/txtcelA"

android:layout_alignLeft="@+id/textView5"
android:text="CELULAR" />

<EditText

android:id="@+id/txtcodA"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/textView3"

android:layout_alignLeft="@+id/textView3"

android:ems="10" />

<TextView

android:id="@+id/textView2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_above="@+id/txtcodA"

android:layout_alignLeft="@+id/txtcodA"

android:text="CODIGO" />

</RelativeLayout>
Alumno.java

import android.net.ParseException;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ALUMO extends Activity {


EditText cod,alum,direc,corr,cel;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alumo);

cod=(EditText) findViewById(R.id.txtcodA);
alum=(EditText) findViewById(R.id.txtalumA);
direc=(EditText) findViewById(R.id.txtdireA);
corr=(EditText) findViewById(R.id.txtcorrA);
cel=(EditText) findViewById(R.id.txtcelA);

}
public void insertar(View v){
dbmatricula gestion =new dbmatricula(this,"bdalumno", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();
int codigo=Integer.parseInt(cod.getText()+"");
String alumno=alum.getText().toString();
String direcion=direc.getText().toString();
String correo=corr.getText().toString();
int celular=Integer.parseInt(cel.getText()+"");

ContentValues registro=new ContentValues();


registro.put("cod_alu", codigo);
registro.put("nom_alu", alumno);
registro.put("dir_alu", direcion);
registro.put("correo", correo);
registro.put("celular", celular);
bd.insert("alumno", null, registro);
bd.close();
cod.setText("");
alum.setText("");
direc.setText("");
corr.setText("");
cel.setText("");

Toast.makeText(this, "Se cargaron los datos",


Toast.LENGTH_SHORT).show();
}

public void eliminar(View v){


dbmatricula gestion=new dbmatricula(this,"bdalumno", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();
int codigo=Integer.parseInt(cod.getText()+"");
int cant = bd.delete("alumno", "cod_alu=" + codigo, null);
bd.close();
cod.setText("");
if(cant==1)
Toast.makeText(this, "Se borraron los datos",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
}

public void consultadatos(View v){


dbmatricula gestion=new dbmatricula(this,"bdalumno", null,1);
SQLiteDatabase bdatos=gestion.getWritableDatabase();
String codigo=cod.getText()+"";

Cursor fila=bdatos.rawQuery("select nom_alu , dir_alu, correo ,


celular from alumno where cod_alu=" + codigo,null);
if(fila.moveToFirst()){
alum.setText(fila.getString(0));
direc.setText(fila.getString(1));
corr.setText(fila.getString(2));
cel.setText(fila.getString(3));

}
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
bdatos.close();

public void actualizar(View v){


dbmatricula gestion=new dbmatricula(this,"bdalumno", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();

int codigo=Integer.parseInt(cod.getText()+"");
String alumno=alum.getText().toString();
String direccion=direc.getText().toString();
String correo=corr.getText().toString();
int celular=Integer.parseInt(cel.getText()+"");

ContentValues registro=new ContentValues();


registro.put("nom_alu",alumno);
registro.put("dir_alu",direccion);
registro.put("correo",correo);
registro.put("celular", celular);

int cant=bd.update("alumno", registro, "cod_alu="+ codigo, null);


if(cant==1)
Toast.makeText(this, "Se modificaron los datos",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
}

}
Activity_profesor.xml

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/fondoazul"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".PROFESORES" >

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:text="CODIGO" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="PROFESORES"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/txtcodP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtcelP"
android:layout_below="@+id/textView2"
android:ems="10" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txtcodP"
android:text="NOMBRE" />

<EditText
android:id="@+id/txtnomP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtcodP"
android:layout_below="@+id/textView4"
android:ems="10" />

<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView4"
android:layout_below="@+id/txtnomP"
android:text="CELULAR" />

<EditText
android:id="@+id/txtcelP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtdireP"
android:layout_below="@+id/textView6"
android:ems="10" >

<requestFocus />
</EditText>

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView6"
android:layout_below="@+id/txtcelP"
android:text="DIRECION" />

<EditText
android:id="@+id/txtdireP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView3"
android:layout_centerHorizontal="true"
android:ems="10" />

<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/txtdireP"
android:text="EMAIL" />

<EditText
android:id="@+id/txtcorP"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView5"
android:layout_toRightOf="@+id/textView2"
android:ems="10" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button2"
android:layout_alignBottom="@+id/button2"
android:layout_alignParentRight="true"
android:onClick="actualizar"
android:text="ACTUALIZAR" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView5"
android:layout_below="@+id/txtcorP"
android:layout_marginLeft="22dp"
android:layout_marginTop="18dp"
android:onClick="eliminar"
android:text="ELIMINAR" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button2"
android:layout_below="@+id/button2"
android:onClick="consultadatos"
android:text="CONSULTA" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button4"
android:layout_below="@+id/button4"
android:onClick="insertar"
android:text="INSERTAR" />

</RelativeLayout>
Profesor.java

import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class PROFESORES extends Activity {


EditText cod,nom,cel,dir,email;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profesores);

cod=(EditText) findViewById(R.id.txtcodP);
nom=(EditText) findViewById(R.id.txtnomP);
cel=(EditText) findViewById(R.id.txtcelP);
dir=(EditText) findViewById(R.id.txtdireP);
email=(EditText) findViewById(R.id.txtcorP);

public void insertar(View v){


dbmatricula gestion =new dbmatricula(this,"bdprofesores",
null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();
int codigo=Integer.parseInt(cod.getText()+"");
String nombre=nom.getText().toString();
int celular=Integer.parseInt(cel.getText()+"");
String direccion=dir.getText().toString();
String emai=email.getText().toString();

ContentValues registro=new ContentValues();


registro.put("cod_prof", codigo);
registro.put("nom_prof", nombre);
registro.put("telefono", celular);
registro.put("dir_prof", direccion);
registro.put("email", emai);

bd.insert("profesores", null, registro);


bd.close();
cod.setText("");
nom.setText("");
cel.setText("");
dir.setText("");
email.setText("");

Toast.makeText(this, "Se cargaron los datos",


Toast.LENGTH_SHORT).show();
}

public void eliminar(View v){


dbmatricula gestion=new dbmatricula(this,"bdprofesores", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();
String codigo=cod.getText().toString();
int cant = bd.delete("profesores", "cod_prof=" + codigo, null);
bd.close();
cod.setText("");
if(cant==1)
Toast.makeText(this, "Se borraron los datos",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
}

public void consultadatos(View v){


dbmatricula gestion=new dbmatricula(this,"bdprofesores", null,1);
SQLiteDatabase bdatos=gestion.getWritableDatabase();
String codigo=cod.getText().toString();
Cursor fila=bdatos.rawQuery("select
nom_prof,telefono,dir_prof,email from profesores where cod_prof=" +
codigo, null);
if(fila.moveToFirst()){
nom.setText(fila.getString(0));
cel.setText(fila.getString(1));
dir.setText(fila.getString(2));
email.setText(fila.getString(3));

}
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
bdatos.close();

public void actualizar(View v){


dbmatricula gestion=new dbmatricula(this,"bdprofesores", null,1);
SQLiteDatabase bd=gestion.getWritableDatabase();
String codigo=cod.getText().toString();
String nombre=nom.getText().toString();
String celular=cel.getText().toString();
String direccion=dir.getText().toString();
String emai=email.getText().toString();

ContentValues registro=new ContentValues();


registro.put("nom_prof",nombre);
registro.put("telefono",celular);
registro.put("dir_prof",direccion);
registro.put("email", emai);

int cant=bd.update("profesores", registro, "cod_prof="+ codigo,


null);
if(cant==1)
Toast.makeText(this, "Se modificaron los datos",
Toast.LENGTH_SHORT).show();
else
Toast.makeText(this, "No existe el c�digo",
Toast.LENGTH_SHORT).show();
}
}

You might also like