package patrice;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import net.kerul.fstmdirektori.R;

public class AddNewRecord extends Activity {
	private EditText txtnama, txtjbt, txttelefon, txtemel;
	private Button btnsave;
	private DBHelper mHelper;
	private SQLiteDatabase dataBase;
	private String id,name,telno,email,dept;//to hold the data strings

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_new_record);
		
		mHelper=new DBHelper(this);
		dataBase = mHelper.getWritableDatabase();
		
		//initiate all textbox container to hold the data for the staff
		txtnama=(EditText)findViewById(R.id.txtnama);
		txtjbt=(EditText)findViewById(R.id.txtjbt);
		txttelefon=(EditText)findViewById(R.id.txttelefon);
		txtemel=(EditText)findViewById(R.id.txtemel);
		
		btnsave=(Button)findViewById(R.id.btnsavenew);
		btnsave.setOnClickListener( new OnClickListener(){
			public void onClick(View v){
				//capture amendment
				name=txtnama.getText().toString();
				telno=txttelefon.getText().toString();
				email=txtemel.getText().toString();
				dept=txtjbt.getText().toString();
				
				saveData();
			}
		});//end btnsave setOnCLickCListener
	}
	
	//save new record
	private void saveData(){
		ContentValues values=new ContentValues();
		
		values.put(DBHelper.NAMA,name);
		values.put(DBHelper.JBT,dept);
		values.put(DBHelper.EMEL,email );
		values.put(DBHelper.TELEFON,telno );
		
		System.out.println("");
		
		//save new record to the database into database
		dataBase.insert(DBHelper.TABLE_NAME, null, values);

		//close database
		dataBase.close();
		finish();
		
		
	}

}

