package com.example.pmb_poligon;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
public class Pendaftaran_Step_2 extends Activity {
EditText nama_sekolah,tahun_lulus;
DatePickerDialog datePickerDialog;
SimpleDateFormat dateFormatter;
TextView tvDateResult,status;
Button btDatePicker,saveandnext2;
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pendaftaran__step_2);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
nama_sekolah=(EditText)findViewById(R.id.add_new_nama_sekolah);
tahun_lulus=(EditText)findViewById(R.id.tv_dateresult1);
saveandnext2 = (Button)findViewById(R.id.btn_saveandnext2);
status=(TextView)findViewById(R.id.txtstatus);
/**
* Kita menggunakan format tanggal dd-MM-yyyy
* jadi nanti tanggal nya akan diformat menjadi
* misalnya 01-12-2017
*/
dateFormatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
tvDateResult = (TextView) findViewById(R.id.tv_dateresult1);
btDatePicker = (Button) findViewById(R.id.bt_datepicker1);
btDatePicker.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDateDialog();
}
});
saveandnext2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent a=new Intent(getApplicationContext(),Pendaftaran_Step_3.class);
startActivity(a);
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("nama_sekolah", nama_sekolah.getText().toString()));
postParameters.add(new BasicNameValuePair("tahun_lulus", tahun_lulus.getText().toString()));
/* String valid = "1";*/
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://192.168.100.27/pmb/step2.php", postParameters);
String res = response.toString();
res = res.trim();
res = res.replaceAll("\\s+","");
status.setText(res);
if (res.equals("1")) status.setText("Data tidak Tersimpan Ke server");
else status.setText("");
}
catch (Exception e) {
nama_sekolah.setText(e.toString());
}
}
});
}
private void showDateDialog(){
/**
* Calendar untuk mendapatkan tanggal sekarang
*/
Calendar newCalendar = Calendar.getInstance();
/**
* Initiate DatePicker dialog
*/
datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
/**
* Method ini dipanggil saat kita selesai memilih tanggal di DatePicker
*/
/**
* Set Calendar untuk menampung tanggal yang dipilih
*/
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
/**
* Update TextView dengan tanggal yang kita pilih
*/
tvDateResult.setText(dateFormatter.format(newDate.getTime()));
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
/**
* Tampilkan DatePicker dialog
*/
datePickerDialog.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pendaftaran__step_2, menu);
return true;
}
}
2. PendaftaranStep_2.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
tools:context=".FormMahasiswa"
android:id="@+id/scrollView1"
android:background="#ffffff"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Sekolah" />
<EditText
android:id="@+id/add_new_nama_sekolah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:ems="10"
android:hint="nama sekolah" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:text="Tahun Lulus" />
<Button
android:id="@+id/bt_datepicker1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:layout_margin="1dp"
android:background="@drawable/date"
android:textColor="#00cccc" />
<EditText
android:id="@+id/tv_dateresult1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
android:ems="1000"
android:hint="tahun lulus"
android:inputType="number" />
<Button
android:id="@+id/btn_saveandnext2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1.73"
android:background="@drawable/tombol"
android:text="Save and Next"
android:textColor="#00cccc"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
3. PendaftaranStep_3.java
package com.example.pmb_poligon;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Locale;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.DatePickerDialog;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
public class Pendaftaran_Step_3 extends Activity {
EditText nama_ayah,tahun_lahir_ayah,pekerjaan_ayah,penghasilan_ayah,nik_ayah,nama_ibu,tahun_lahir_ibu,pekerjaan_ibu,penghasilan_ibu,nik_ibu;
RadioGroup jenjang_ayah,jenjang_ibu;
DatePickerDialog datePickerDialog2;
SimpleDateFormat dateFormatter2;
TextView tvDateResult2,status;
Button btDatePicker2,saveandnext3;
DatePickerDialog datePickerDialog3;
SimpleDateFormat dateFormatter3;
TextView tvDateResult3;
Button btDatePicker3;
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pendaftaran__step_3);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
nama_ayah=(EditText)findViewById(R.id.add_new_nama_ayah);
tahun_lahir_ayah=(EditText)findViewById(R.id.tv_dateresult2);
pekerjaan_ayah=(EditText)findViewById(R.id.add_new_pekerjaan_ayah);
penghasilan_ayah=(EditText)findViewById(R.id.add_new_penghasilan_ayah);
nik_ayah=(EditText)findViewById(R.id.add_new_nik_ayah);
nama_ibu=(EditText)findViewById(R.id.add_new_nama_ibu);
tahun_lahir_ibu=(EditText)findViewById(R.id.tv_dateresult3);
pekerjaan_ibu=(EditText)findViewById(R.id.add_new_pekerjaan_ibu);
penghasilan_ibu=(EditText)findViewById(R.id.add_new_penghasilan_ibu);
nik_ibu=(EditText)findViewById(R.id.add_new_nik_ibu);
jenjang_ayah=(RadioGroup)findViewById(R.id.rg_jenjang_ayah);
jenjang_ibu=(RadioGroup)findViewById(R.id.rg_jenjang_ibu);
saveandnext3=(Button)findViewById(R.id.btn_saveandnext3);
status=(TextView)findViewById(R.id.txtstatus);
/**
* Kita menggunakan format tanggal dd-MM-yyyy
* jadi nanti tanggal nya akan diformat menjadi
* misalnya 01-12-2017
*/
dateFormatter2 = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
dateFormatter3 = new SimpleDateFormat("yyyy-MM-dd", Locale.US);
tvDateResult2 = (TextView) findViewById(R.id.tv_dateresult2);
btDatePicker2 = (Button) findViewById(R.id.bt_datepicker2);
tvDateResult3 = (TextView) findViewById(R.id.tv_dateresult3);
btDatePicker3 = (Button) findViewById(R.id.bt_datepicker3);
btDatePicker2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDateDialog2();
}
});
btDatePicker3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showDateDialog3();
}
});
saveandnext3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent a=new Intent(getApplicationContext(),Pemilihan_jurusan.class);
startActivity(a);
// TODO Auto-generated method stub
//atur variabel utk menampung pilihan jenis kelamin
String type2=null;
switch (jenjang_ayah.getCheckedRadioButtonId()) {
case R.id.rb_sd:
type2="SD";
break;
case R.id.rb_smp:
type2="SMP Sederajat";
break;
case R.id.rb_sma:
type2="SMA Sederajat";
break;
}
String type3=null;
switch (jenjang_ibu.getCheckedRadioButtonId()) {
case R.id.rb_sd1:
type3="SD";
break;
case R.id.rb_smp1:
type3="SMP Sederajat";
break;
case R.id.rb_sma1:
type3="SMA Sederajat";
break;
}
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("nama", nama_ayah.getText().toString()));
postParameters.add(new BasicNameValuePair("tahun_lahir", tahun_lahir_ayah.getText().toString()));
postParameters.add(new BasicNameValuePair("pekerjaan", pekerjaan_ayah.getText().toString()));
postParameters.add(new BasicNameValuePair("penghasilan", penghasilan_ayah.getText().toString()));
postParameters.add(new BasicNameValuePair("nik", nik_ayah.getText().toString()));
postParameters.add(new BasicNameValuePair("nama_ibu", nama_ibu.getText().toString()));
postParameters.add(new BasicNameValuePair("tahun_lahir_ibu", tahun_lahir_ibu.getText().toString()));
postParameters.add(new BasicNameValuePair("pekerjaan_ibu", pekerjaan_ibu.getText().toString()));
postParameters.add(new BasicNameValuePair("penghasilan_ibu", penghasilan_ibu.getText().toString()));
postParameters.add(new BasicNameValuePair("nik_ibu", nik_ibu.getText().toString()));
postParameters.add(new BasicNameValuePair("jenjang_ayah", type2));
postParameters.add(new BasicNameValuePair("jenjang_ibu", type3));
/* String valid = "1";*/
String response = null;
try {
response = CustomHttpClient.executeHttpPost("http://192.168.100.27/pmb/step3.php", postParameters);
String res = response.toString();
res = res.trim();
res = res.replaceAll("\\s+","");
status.setText(res);
if (res.equals("1")) status.setText("Data tidak Tersimpan Ke server");
else status.setText("Data berhasil disimpan ke server");
}
catch (Exception e) {
nama_ayah.setText(e.toString());
}
}
});
}
private void showDateDialog2(){
/**
* Calendar untuk mendapatkan tanggal sekarang
*/
Calendar newCalendar = Calendar.getInstance();
/**
* Initiate DatePicker dialog
*/
datePickerDialog2 = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
/**
* Method ini dipanggil saat kita selesai memilih tanggal di DatePicker
*/
/**
* Set Calendar untuk menampung tanggal yang dipilih
*/
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
/**
* Update TextView dengan tanggal yang kita pilih
*/
tvDateResult2.setText(dateFormatter2.format(newDate.getTime()));
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
/**
* Tampilkan DatePicker dialog
*/
datePickerDialog2.show();
}
private void showDateDialog3(){
/**
* Calendar untuk mendapatkan tanggal sekarang
*/
Calendar newCalendar = Calendar.getInstance();
/**
* Initiate DatePicker dialog
*/
datePickerDialog3 = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener()
{
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
/**
* Method ini dipanggil saat kita selesai memilih tanggal di DatePicker
*/
/**
* Set Calendar untuk menampung tanggal yang dipilih
*/
Calendar newDate = Calendar.getInstance();
newDate.set(year, monthOfYear, dayOfMonth);
/**
* Update TextView dengan tanggal yang kita pilih
*/
tvDateResult3.setText(dateFormatter3.format(newDate.getTime()));
}
},newCalendar.get(Calendar.YEAR), newCalendar.get(Calendar.MONTH), newCalendar.get(Calendar.DAY_OF_MONTH));
/**
* Tampilkan DatePicker dialog
*/
datePickerDialog3.show();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.pendaftaran__step_3, menu);
return true;
}
}
4. PendaftaranStep_3.xml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
tools:context=".FormMahasiswa"
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginBottom="20dp"
android:text="AYAH :" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Lengkap" />
<EditText
android:id="@+id/add_new_nama_ayah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="nama lengkap"
android:layout_marginBottom="30dp"
android:ems="10" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tahun Lahir" />
<Button
android:id="@+id/bt_datepicker2"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:layout_margin="1dp"
android:background="@drawable/date"
android:textColor="#00cccc" />
<EditText
android:id="@+id/tv_dateresult2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="tahun lahir"
android:inputType="number"
android:layout_marginBottom="30dp"
android:ems="10" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jenjang Pendidikan" />
<RadioGroup
android:id="@+id/rg_jenjang_ayah"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rb_sd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="SD" />
<RadioButton
android:id="@+id/rb_smp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="SMP Sederajat" />
<RadioButton
android:id="@+id/rb_sma"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SMA Sederajat"
android:layout_marginBottom="30dp"
android:ems="10" />
</RadioGroup>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pekerjaan" />
<EditText
android:id="@+id/add_new_pekerjaan_ayah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="pekerjaan"
android:layout_marginBottom="30dp"
android:ems="10" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Penghasilan" />
<EditText
android:id="@+id/add_new_penghasilan_ayah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="penghasilan"
android:inputType="numberDecimal"
android:layout_marginBottom="30dp"
android:ems="10" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NIK" />
<EditText
android:id="@+id/add_new_nik_ayah"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="nomor induk keluarga"
android:inputType="number"
android:layout_marginBottom="30dp"
android:ems="10" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
android:layout_marginBottom="20dp"
android:text="IBU :" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Lengkap" />
<EditText
android:id="@+id/add_new_nama_ibu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="nama lengkap"
android:layout_marginBottom="30dp"
android:ems="10" >
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tahun Lahir" />
<Button
android:id="@+id/bt_datepicker3"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:layout_margin="1dp"
android:background="@drawable/date"
android:textColor="#00cccc" />
<EditText
android:id="@+id/tv_dateresult3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="tahun lahir"
android:inputType="number"
android:layout_marginBottom="30dp"
android:ems="10" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Jenjang Pendidikan" />
<RadioGroup
android:id="@+id/rg_jenjang_ibu"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/rb_sd1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="SD" />
<RadioButton
android:id="@+id/rb_smp1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="SMP Sederajat" />
<RadioButton
android:id="@+id/rb_sma1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SMA Sederajat"
android:layout_marginBottom="30dp"
android:ems="10" />
</RadioGroup>
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pekerjaan" />
<EditText
android:id="@+id/add_new_pekerjaan_ibu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="pekerjaan"
android:layout_marginBottom="30dp"
android:ems="10" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Penghasilan" />
<EditText
android:id="@+id/add_new_penghasilan_ibu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="penghasilan"
android:inputType="numberDecimal"
android:layout_marginBottom="30dp"
android:ems="10" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="NIK" />
<EditText
android:id="@+id/add_new_nik_ibu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="nomor induk keluarga"
android:inputType="number"
android:layout_marginBottom="30dp"
android:ems="10" />
<Button
android:id="@+id/btn_saveandnext3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="1dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_weight="1.73"
android:background="@drawable/tombol"
android:text="Save and Next"
android:textColor="#00cccc"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="@+id/txtstatus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
</ScrollView>
0 komentar: