Aplikasi Android dengan koneksi database SQLite

BENTUKfikrillazi

screenshot_2014-07-21-15-09-17

screenshot_2014-07-21-15-09-57

FIKRIL INPUT

HASIL FIKRIL

DAFTAR

*** DBpracticeActivity.java***

package com.example.activity;

import com.example.db.R;

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

public class DBPracticeActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button regButton = (Button)findViewById(R.id.buttonMainRegister);
Button listButton = (Button)findViewById(R.id.ButtonMainList);
regButton.setOnClickListener(this);
listButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {
Intent intent;
switch(v.getId()) {
case R.id.buttonMainRegister :
intent = new Intent();
intent.setClass(getApplicationContext(), Registration.class);
startActivity(intent);
break;
case R.id.ButtonMainList :
intent = new Intent();
intent.setClass(getApplicationContext(), ListUsers.class);
startActivity(intent);
break;
}
}
}

***DetailUser***

package com.example.activity;

import com.example.db.DatabaseHandler;
import com.example.db.R;
import com.example.db.User;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class DetailsUsers extends Activity implements OnClickListener{
private static String position = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.details_users);
Intent intent = getIntent();
position = intent.getStringExtra(“position”);
Log.d(“value of position from intent”, position);
DatabaseHandler db = new DatabaseHandler(this);
User user = db.getUser(position);
TextView textViewDetailName = (TextView) findViewById(R.id.textViewDetailsName);
textViewDetailName.setText(user.getName());

TextView textViewDetailAddress = (TextView) findViewById(R.id.textViewDetailsAddress);
textViewDetailAddress.setText(user.getAddress());

TextView textViewDetailsPhone = (TextView) findViewById(R.id.textViewDetailsPhone);
textViewDetailsPhone.setText(user.getPhone());

Button backButton = (Button)findViewById(R.id.buttonDetailsBack);
backButton.setOnClickListener(this);

Button editButton = (Button)findViewById(R.id.buttonEditDetails);
editButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if(v.getId() == R.id.buttonDetailsBack) {
Intent intent = new Intent(getApplicationContext(), ListUsers.class);
startActivity(intent);
}
else if(v.getId() == R.id.buttonEditDetails) {
Intent intent = new Intent(getApplicationContext(), EditUsers.class);
intent.putExtra(“position”, position);
startActivity(intent);
}
}
}

***EditUser***

package com.example.activity;

import com.example.db.DatabaseHandler;
import com.example.db.R;
import com.example.db.User;

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

public class EditUsers extends Activity implements OnClickListener{
private static String position = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_user);
Intent intent = getIntent();
position = intent.getStringExtra(“position”);

DatabaseHandler db = new DatabaseHandler(this);
Log.d(“position”, position);
//get user for the position clicked for edit
User user = db.getUser(position);

Log.d(“User Name”, user.getName());
Log.d(“Address”, user.getAddress());
Log.d(“Users phone”, user.getPhone());

//set the values in editText boxes
EditText name = ((EditText)findViewById(R.id.editTextEditName));
name.setText(user.getName());
EditText address = ((EditText)findViewById(R.id.editTextEditAddress));
address.setText(user.getAddress());
EditText phone = ((EditText)findViewById(R.id.editTextEditPhone));
phone.setText(user.getPhone());

Button backButton = (Button)findViewById(R.id.buttonEditBack);
backButton.setOnClickListener(this);

Button updateButton = (Button)findViewById(R.id.buttonEdit);
updateButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if(v.getId() == R.id.buttonEditBack) {
Intent intent = new Intent(getApplicationContext(), ListUsers.class);
startActivity(intent);
}
else if(v.getId() == R.id.buttonEdit) {
User user = new User(
((EditText)findViewById(R.id.editTextEditName)).getText().toString(),
((EditText)findViewById(R.id.editTextEditAddress)).getText().toString(),
((EditText)findViewById(R.id.editTextEditPhone)).getText().toString()
);
DatabaseHandler db = new DatabaseHandler(this);
int updateCount = db.editUser(user, position);
if(updateCount == 1) {
Toast toast = Toast.makeText(getApplicationContext(),
“User successfully updated”,
Toast.LENGTH_SHORT);
toast.show();
}
else{
Toast toast = Toast.makeText(getApplicationContext(),
“User update failed, Try Again”,
Toast.LENGTH_SHORT);
toast.show();
}
}
}

}

***ListUser***

package com.example.activity;

import java.util.List;

import com.example.db.DatabaseHandler;
import com.example.db.R;
import com.example.db.User;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListUsers extends ListActivity{

public void onCreate(Bundle icicle) {
super.onCreate(icicle);
DatabaseHandler db = new DatabaseHandler(this);
String[] users = db.getAllUsers();
if(users!=null) {
for(String us:users) {
Log.d(“String Array Value”, us);
}
db.close();
}
// Use your own layout
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_users, R.id.textViewList, users);
setListAdapter(adapter);
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Log.d(“On click of a item”, Integer.toString(position));
Intent intent = new Intent();
intent.setClass(getApplicationContext(), DetailsUsers.class);
intent.putExtra(“position”, Integer.toString(position + 1)); //position starts from 0, but in db row starts from 1
startActivity(intent);
}
}

***Registration***

package com.example.activity;

import com.example.db.DatabaseHandler;
import com.example.db.R;
import com.example.db.User;

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

public class Registration extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.registration);
Button regButton = (Button)findViewById(R.id.buttonRegister);
regButton.setOnClickListener(this);
Button backButton = (Button)findViewById(R.id.buttonRegisterBack);
backButton.setOnClickListener(this);
}

@Override
public void onClick(View v) {
Intent intent;
switch(v.getId()) {
case R.id.buttonRegister :
register();
break;
case R.id.buttonRegisterBack :
intent = new Intent();
intent.setClass(getApplicationContext(), DBPracticeActivity.class);
startActivity(intent);
break;
}
}

private void register() {
String user = ((EditText)findViewById(R.id.editTextRegName)).getText().toString();
String address = ((EditText)findViewById(R.id.editTextRegAddress)).getText().toString();
String phone = ((EditText)findViewById(R.id.editTextRegPhone)).getText().toString();
DatabaseHandler db = new DatabaseHandler(this);
int id = db.addUser(new User(user,address,phone));
db.close();
if(id>0) {
Toast toast = Toast.makeText(getApplicationContext(),
“User registered at id ” + id,
Toast.LENGTH_SHORT);
toast.show();
}
else {
Toast toast = Toast.makeText(getApplicationContext(),
“User registration failed”,
Toast.LENGTH_SHORT);
toast.show();
}
((EditText)findViewById(R.id.editTextRegName)).setText(“”);
((EditText)findViewById(R.id.editTextRegAddress)).setText(“”);
((EditText)findViewById(R.id.editTextRegPhone)).setText(“”);
}

}

 

Advertisements

APLIKASI HITUNG PERSEGI PANJANG

APLIKASI SEDERHANA HITUNG PERSEGI PANJANG

#SKRIP DI MAIN CLASS

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class HitungPersegiPanjang extends Activity {
private EditText txtPanjang;
private EditText txtLebar;
private EditText txtLuas;
private Button btnHitung;

/**
* Method yang dipanggil pada saat applikaasi dijalankan
* */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.persegipanjang);
txtPanjang = (EditText) findViewById(R.id.txtPanjang);
txtLebar = (EditText) findViewById(R.id.txtLebar);
txtLuas = (EditText) findViewById(R.id.txtLuas);
btnHitung = (Button) findViewById(R.id.btnHitung);
/**
* Method untuk Menghitung Luas Persegi panjang dipanggil pada saat button
* Hitung Luas diklik
*
* @param view
*/
public void hitungLuas(View view) {
try {

int panjang = Integer.parseInt(txtPanjang.getText().toString());
int lebar = Integer.parseInt(txtLebar.getText().toString());
int luas = panjang * lebar;
txtLuas.setText(String.valueOf(luas));
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Method untuk menutup activity dan kembali ke menu
* @param view
*/
public void backtoMenu(View view){
finish();
}
}

 

#SKRIP PADA LAYOUT

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android&#8221;
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”Menghitung Luas Persegi Panjang”
/>
<TextView android:text=”Panjang :” android:id=”@+id/TextView01″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”></TextView>

<EditText android:text=”” android:id=”@+id/txtPanjang” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:inputType=”numberSigned|numberDecimal”></EditText>

<TextView android:text=”Lebar :” android:id=”@+id/TextView02″ android:layout_width=”wrap_content” android:layout_height=”wrap_content”></TextView>

<EditText android:text=”” android:id=”@+id/txtLebar” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:inputType=”numberSigned|numberDecimal”></EditText>

<Button android:text=”Hitung Luas” android:id=”@+id/btnHitung” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:onClick=”hitungLuas”></Button>

<TextView android:text=”Luas :” android:id=”@+id/TextView03″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” ></TextView>

<EditText android:text=”” android:id=”@+id/txtLuas” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:editable=”false”></EditText>

<Button android:text=”Kembali ke Menu” android:id=”@+id/btnBack” android:layout_width=”fill_parent” android:layout_height=”wrap_content” android:onClick=”backtoMenu”></Button>

</LinearLayout>

aplikasi ini untuk menghitung luas lingkaran

#SKRIP DI MAIN CLASS

package com.example.hitunglingkaran;
 
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
 
public class MainActivity extends Activity implements OnClickListener
{
 private EditText etJari, etHasil;
 private Button  btnHitung;
 
 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 
  etJari = (EditText) findViewById(R.id.editTextJari);
  etHasil = (EditText) findViewById(R.id.editTextHasil);
  btnHitung = (Button) findViewById(R.id.btnHitung);
 
  btnHitung.setOnClickListener(this);
 }
 
 @Override
 public boolean onCreateOptionsMenu(Menu menu)
 {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }
 
 @Override
 public void onClick(View v)
 {
  switch (v.getId())
  {
   case R.id.btnHitung:
    etHasil.setText(String.valueOf(hitLuas(Float.parseFloat(etJari.getText().toString()))));
    break;
  }
 
 }
 
 private float hitLuas(float jari)
 {
  float luas;
  luas = (float) (3.14 * jari * jari);
  return luas;
 
 }
 
}
 
#SKRIP DI LAYOUT
<relativelayout android:layout_height="match_parent" android:layout_width="match_parent" tools:context=".MainActivity" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
    <textview android:id="@+id/textView1" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_height="wrap_content" android:layout_margintop="65dp" android:layout_width="wrap_content" android:text="Jari">
    <edittext android:ems="10" android:id="@+id/editTextJari" android:layout_below="@+id/textView1" android:layout_centerhorizontal="true" android:layout_height="wrap_content" android:layout_width="wrap_content">
     <requestfocus>
    </requestfocus></edittext>
    <edittext android:ems="10" android:id="@+id/editTextHasil" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:layout_height="wrap_content" android:layout_width="wrap_content">
    <button android:id="@+id/btnHitung" android:layout_below="@+id/editTextHasil" android:layout_centerhorizontal="true" android:layout_height="wrap_content" android:layout_margintop="34dp" android:layout_width="wrap_content" android:text="Hitung">
    <textview android:id="@+id/textView2" android:layout_above="@+id/editTextHasil" android:layout_alignleft="@+id/textView1" android:layout_height="wrap_content" android:layout_marginbottom="16dp" android:layout_width="wrap_content" android:text="Hasil">
</textview></button></edittext></textview></relativelayout>
Image

aplikasi sederhana android hitung luas lingkaran

aplikasi ini untuk menghitung luas lingkaran

#SKRIP DI MAIN CLASS

package com.example.hitunglingkaran;
 
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
 
public class MainActivity extends Activity implements OnClickListener
{
 private EditText etJari, etHasil;
 private Button  btnHitung;
 
 @Override
 protected void onCreate(Bundle savedInstanceState)
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
 
  etJari = (EditText) findViewById(R.id.editTextJari);
  etHasil = (EditText) findViewById(R.id.editTextHasil);
  btnHitung = (Button) findViewById(R.id.btnHitung);
 
  btnHitung.setOnClickListener(this);
 }
 
 @Override
 public boolean onCreateOptionsMenu(Menu menu)
 {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.activity_main, menu);
  return true;
 }
 
 @Override
 public void onClick(View v)
 {
  switch (v.getId())
  {
   case R.id.btnHitung:
    etHasil.setText(String.valueOf(hitLuas(Float.parseFloat(etJari.getText().toString()))));
    break;
  }
 
 }
 
 private float hitLuas(float jari)
 {
  float luas;
  luas = (float) (3.14 * jari * jari);
  return luas;
 
 }
 
}
 
#SKRIP DI LAYOUT
<relativelayout android:layout_height="match_parent" android:layout_width="match_parent" tools:context=".MainActivity" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools">
    <textview android:id="@+id/textView1" android:layout_alignparenttop="true" android:layout_centerhorizontal="true" android:layout_height="wrap_content" android:layout_margintop="65dp" android:layout_width="wrap_content" android:text="Jari">
    <edittext android:ems="10" android:id="@+id/editTextJari" android:layout_below="@+id/textView1" android:layout_centerhorizontal="true" android:layout_height="wrap_content" android:layout_width="wrap_content">
     <requestfocus>
    </requestfocus></edittext>
    <edittext android:ems="10" android:id="@+id/editTextHasil" android:layout_centerhorizontal="true" android:layout_centervertical="true" android:layout_height="wrap_content" android:layout_width="wrap_content">
    <button android:id="@+id/btnHitung" android:layout_below="@+id/editTextHasil" android:layout_centerhorizontal="true" android:layout_height="wrap_content" android:layout_margintop="34dp" android:layout_width="wrap_content" android:text="Hitung">
    <textview android:id="@+id/textView2" android:layout_above="@+id/editTextHasil" android:layout_alignleft="@+id/textView1" android:layout_height="wrap_content" android:layout_marginbottom="16dp" android:layout_width="wrap_content" android:text="Hasil">
</textview></button></edittext></textview></relativelayout>
 

Membuat Aplikasi Android Hitung Segitiga

aplikasi ini mampu mengutung luas segitiga.
#SKRIP UNTUK class main.

package co.id.cahayabuana.tugas;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class segitiga extends Activity implements OnClickListener{

EditText eAlas;
EditText eTinggi;
EditText eHasil;
Button bSegitiga;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.hsegitiga);
eAlas = (EditText)findViewById(R.id.eAlas);
eTinggi = (EditText)findViewById(R.id.eTinggi);
eHasil = (EditText)findViewById(R.id.eHasil);
bSegitiga = (Button)findViewById(R.id.bSegitiga);

bSegitiga.setOnClickListener(this);
}

@Override
public void onClick(View view) {
// TODO Auto-generated method stub
//fikrillazi
double Alas = Double.parseDouble(String.valueOf(eAlas.getText()));
double Tinggi = Double.parseDouble(String.valueOf(eTinggi.getText()));
double Hasil = 0.5*Alas*Tinggi;

eHasil.setText(String.valueOf(Hasil));

}

}

#SKRIP UNTUK LAYOUT

FIKRILLAZ

FIKRILLAZI

Aplikasi mobile Java

Aplikasi ini dibuat untuk kelengkapan uts FIKRILLAZI
aplikasi yang dibuat ini adalah kompilasi dari materi yang pernah di ajarkan dikelas.

kronologi aplikasi.
ketika aplikasi dibuka maka akan keluar suara atau loading sound.
setelah itu akan muncul 2 modul, dan bila modul di pilih maka akan masuk ke modul selanjutnya (berpindah Layout)
dan juga diikuti dengan sound klik yang telah di setting.
di modul pertama (Tutorial One) disitu terdapat isian yang mampu menampilkan inputan dan
merubah menjadi pengaturan Gravity dan Style.
di modul kedua hanya terdapat tulisan untuk menujukkan bahwa aplikasi telah berganti layout.

pertama-tama siapkan 3 layout tambahan dan 3 class tambahan dan 3 sound untuk loading sound & click sound
layout :
1. splash (untuk loading season)
2. tutorialone (untuk modul ke 1)
3. tutirialtwo (untuk modul ke 2)
class :
1. menu
2. tutrial1
3. tutorial2

#SKRIP CLASS PERTAMA (Main)
package co.id.cahayabuana.tugas;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class Main extends Activity {
MediaPlayer logomusik;

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

logomusik = MediaPlayer.create(Main.this, R.raw.dragon);
logomusik.start();
Thread waktu = new Thread(){
public void run(){
try{
sleep(10000);
Intent menuIntent = new Intent(“co.id.cayahabuana.tugas.MENU”);
startActivity(menuIntent);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
finish();
}
}
};
waktu.start();

}

@Override
protected void onPause() {
// TODO Auto-generated method stub fikrillazi
super.onPause();
logomusik.release();
}

}

#SKRIP DI CLASS KE DUA (Menu)
package co.id.cahayabuana.tugas;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class menu extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);

final MediaPlayer klik = MediaPlayer.create(menu.this,R.raw.button2);

Button tut1 = (Button) findViewById(R.id.tutorial1);

tut1.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub fikrillazi
klik.start();
startActivity(new Intent(“co.id.cayahabuana.tugas.TUTORIAL1”));
}
});
final MediaPlayer klok = MediaPlayer.create(menu.this,R.raw.button6);
Button tut2 = (Button) findViewById(R.id.tutorial2);
tut2.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
klok.start();
startActivity(new Intent(“co.id.cayahabuana.tugas.TUTORIAL2”));
}
});
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}

}

#SKRIP DI CLASS KE 3(TUTORIAL1)
package co.id.cahayabuana.tugas;

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

public class tutorial1 extends Activity implements OnCheckedChangeListener {
TextView textout;
EditText textin;
RadioGroup Gravity, Style;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorialone);
textout = (TextView) findViewById(R.id.tvchange);
textin = (EditText) findViewById(R.id.editText1);
Gravity = (RadioGroup)findViewById(R.id.rggravity);
Gravity.setOnCheckedChangeListener(this);
Style = (RadioGroup)findViewById(R.id.rgstyle);
Style.setOnCheckedChangeListener(this);
Button rubah = (Button) findViewById(R.id.bproses);
rubah.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
textout.setText(textin.getText());
}
});
}

@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId){
case R.id.rbleft:
textout.setGravity(android.view.Gravity.LEFT);
break;
case R.id.rbright:
textout.setGravity(android.view.Gravity.RIGHT);
break;
case R.id.rbcenter:
textout.setGravity(android.view.Gravity.CENTER);
break;
case R.id.rbnormal:
textout.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL), Typeface.NORMAL);
case R.id.rbbold:
textout.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD), Typeface.BOLD);
case R.id.rbitalic:
textout.setTypeface(Typeface.defaultFromStyle(Typeface.ITALIC), Typeface.ITALIC);
}
}

}

#SKRIP #SKRIP DI CLASS KE 4(TUTORIAL2)
package co.id.cahayabuana.tugas;

import android.app.Activity;
import android.os.Bundle;

public class tutorial2 extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tutorialtwo);
}

}

#SKRIP DI LAYOUT TUTORIALONE

#SKRIP DI manifest

pemograman cekat kwitansi

Imports wordku = Microsoft.Office.Interop.Word

Imports System.Data.OleDb

 

Public Class Form1

 

//untuk membuat koneksi database

Public conn As New OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\data\kwitansi.accdb”)

    Sub tampilgrid(ByVal tablenya As String)

        conn.Close()

        conn.Open()

        Dim da As New OleDb.OleDbDataAdapter(“select * from “ + kwitansi, conn)

        Dim ds As New DataSet

        da.Fill(ds, tablenya)

        DataGridView1.DataSource = (ds.Tables(tablenya))

    End Sub

 

//untuk reset text

    Sub cleartext()

        TextBox1.Text = “”

        TextBox2.Text = “”

        TextBox3.Text = “”

        TextBox4.Text = “”

    End Sub

 

Private Sub btnReset(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click

Call cleartext()

    End Sub

 

 

 

Private Sub btnSave(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click

        conn.Close()

        conn.Open()

 

        Dim confirm = MsgBox(“Simpan data ?”, vbYesNo +MsgBoxStyle.Question, “Konfirmasi”)

        If confirm = vbYes Then

 

            Dim CekDouble As New OleDbCommand

            CekDouble.Connection = conn

            CekDouble.CommandType = CommandType.Text

            CekDouble.CommandText = “SELECT * FROM kwitansi where kd_barang =’” & txtNo.Text & “‘”

            Dim DRead As OleDbDataReader

            DRead = CekDouble.ExecuteReader

            If DRead.HasRows = False Then

                Dim CMDsave As New OleDbCommand

                CMDsave.Connection = conn

                CMDsave.CommandType = CommandType.Text

                CMDsave.CommandText = “INSERT INTO kwitansi VALUES(‘” & txtNo.Text & “‘,’” & txtTerima.Text & “‘,’” & txtNominal.Text & “‘,’” & txtBayar.Text & “‘)”

                CMDsave.ExecuteNonQuery()

                MsgBox(“Data sudah disimpan”)

                tampilgrid(“kwitansi”)

                cleartext()

            Else

                MsgBox(“Data dengan kode barang “ & TextBox1.Text & ” sudah ada”)

            End If

        End If

    End Sub

 

    Private Sub btnToword(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click

 Dim wordapp As New wordku.Application

        Dim worddoc As New wordku.Document

 

        Dim folderword As String = “D:\data\kwitansi.docx”

        Dim folderwordhasil As String = “D:\Data Office\kwitansi_” + txtNno.Text + “.docx”

 

        worddoc = wordapp.Documents.Open(folderword)

 

        worddoc.Bookmarks(“bkNo”).Select()

        wordapp.Selection.TypeText(txtNo.Text)

 

        worddoc.Bookmarks(“bkNama”).Select()

        wordapp.Selection.TypeText(txtTerima.Text)

 

        worddoc.Bookmarks(“bkNominal”).Select()

        wordapp.Selection.TypeText(txtNominal.Text)

 

        worddoc.Bookmarks(“bkNominal”).Select()

        wordapp.Selection.TypeText(txtNominal.Text)

 

        exceldoc.Save()

        excelapp.Quit()

        worddoc.SaveAs(folderwordhasil)

        wordapp.Quit()

 

    End Sub

 

Private Sub btnCari(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click

        txtNo.Enabled = False

        Dim cari = InputBox(“Masukan data yang dicari…”)

        conn.Close()

        conn.Open()

 

        Dim CMDsearch As New OleDbCommand

        CMDsearch.Connection = conn

        CMDsearch.CommandType = CommandType.Text

        CMDsearch.CommandText = “SELECT * FROM kwitansi  where kd_barang =’” & Trim(cari) & “‘”

 

        Dim DRead As OleDbDataReader

        DRead = CMDsearch.ExecuteReader

 

        If DRead.HasRows = True Then

            DRead.Read()

            txtNO.Text = DRead(“no_kwitansi”)

            txtTerima.Text = DRead(“telah_terima”)

            txtNominal.Text = DRead(“nominal”)

            txtBayar.Text = DRead(“pembayaran”)

        Else

            MsgBox(“Data ‘” & cari & “‘ tidak ditemukan”,MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, “Pencarian”)

        End If

EndSub

 

Private Sub btnHapus(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button4.Click

        Dim CMDupdate As New OleDbCommand

        CMDupdate.Connection = conn

        CMDupdate.CommandType = CommandType.Text

        CMDupdate.CommandText = “DELETE FROM m_barang where kd_barang =’”& txtNo.Text & “‘”

        CMDupdate.ExecuteNonQuery()

        MsgBox(“Data sudah dihapus”)

        tampilgrid(“kwitansi”)

        cleartext()

    End Sub

 

End Class

 

Imports wordku = Microsoft.Office.Interop.Word

Imports System.Data.OleDb

 

Public Class Form1

 

//untuk membuat koneksi database

Public conn As New OleDbConnection(“Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\data\kwitansi.accdb”)

    Sub tampilgrid(ByVal tablenya As String)

        conn.Close()

        conn.Open()

        Dim da As New OleDb.OleDbDataAdapter(“select * from “ + kwitansi, conn)

        Dim ds As New DataSet

        da.Fill(ds, tablenya)

        DataGridView1.DataSource = (ds.Tables(tablenya))

    End Sub

 

//untuk reset text

    Sub cleartext()

        TextBox1.Text = “”

        TextBox2.Text = “”

        TextBox3.Text = “”

        TextBox4.Text = “”

    End Sub

 

Private Sub btnReset(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click

Call cleartext()

    End Sub

 

 

 

Private Sub btnSave(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click

        conn.Close()

        conn.Open()

 

        Dim confirm = MsgBox(“Simpan data ?”, vbYesNo +MsgBoxStyle.Question, “Konfirmasi”)

        If confirm = vbYes Then

 

            Dim CekDouble As New OleDbCommand

            CekDouble.Connection = conn

            CekDouble.CommandType = CommandType.Text

            CekDouble.CommandText = “SELECT * FROM kwitansi where kd_barang =’” & txtNo.Text & “‘”

            Dim DRead As OleDbDataReader

            DRead = CekDouble.ExecuteReader

            If DRead.HasRows = False Then

                Dim CMDsave As New OleDbCommand

                CMDsave.Connection = conn

                CMDsave.CommandType = CommandType.Text

                CMDsave.CommandText = “INSERT INTO kwitansi VALUES(‘” & txtNo.Text & “‘,’” & txtTerima.Text & “‘,’” & txtNominal.Text & “‘,’” & txtBayar.Text & “‘)”

                CMDsave.ExecuteNonQuery()

                MsgBox(“Data sudah disimpan”)

                tampilgrid(“kwitansi”)

                cleartext()

            Else

                MsgBox(“Data dengan kode barang “ & TextBox1.Text & ” sudah ada”)

            End If

        End If

    End Sub

 

    Private Sub btnToword(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click

 Dim wordapp As New wordku.Application

        Dim worddoc As New wordku.Document

 

        Dim folderword As String = “D:\data\kwitansi.docx”

        Dim folderwordhasil As String = “D:\Data Office\kwitansi_” + txtNno.Text + “.docx”

 

        worddoc = wordapp.Documents.Open(folderword)

 

        worddoc.Bookmarks(“bkNo”).Select()

        wordapp.Selection.TypeText(txtNo.Text)

 

        worddoc.Bookmarks(“bkNama”).Select()

        wordapp.Selection.TypeText(txtTerima.Text)

 

        worddoc.Bookmarks(“bkNominal”).Select()

        wordapp.Selection.TypeText(txtNominal.Text)

 

        worddoc.Bookmarks(“bkNominal”).Select()

        wordapp.Selection.TypeText(txtNominal.Text)

 

        exceldoc.Save()

        excelapp.Quit()

        worddoc.SaveAs(folderwordhasil)

        wordapp.Quit()

 

    End Sub

 

Private Sub btnCari(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click

        txtNo.Enabled = False

        Dim cari = InputBox(“Masukan data yang dicari…”)

        conn.Close()

        conn.Open()

 

        Dim CMDsearch As New OleDbCommand

        CMDsearch.Connection = conn

        CMDsearch.CommandType = CommandType.Text

        CMDsearch.CommandText = “SELECT * FROM kwitansi  where kd_barang =’” & Trim(cari) & “‘”

 

        Dim DRead As OleDbDataReader

        DRead = CMDsearch.ExecuteReader

 

        If DRead.HasRows = True Then

            DRead.Read()

            txtNO.Text = DRead(“no_kwitansi”)

            txtTerima.Text = DRead(“telah_terima”)

            txtNominal.Text = DRead(“nominal”)

            txtBayar.Text = DRead(“pembayaran”)

        Else

            MsgBox(“Data ‘” & cari & “‘ tidak ditemukan”,MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, “Pencarian”)

        End If

EndSub

 

Private Sub btnHapus(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button4.Click

        Dim CMDupdate As New OleDbCommand

        CMDupdate.Connection = conn

        CMDupdate.CommandType = CommandType.Text

        CMDupdate.CommandText = “DELETE FROM m_barang where kd_barang =’”& txtNo.Text & “‘”

        CMDupdate.ExecuteNonQuery()

        MsgBox(“Data sudah dihapus”)

        tampilgrid(“kwitansi”)

        cleartext()

    End Sub

 

End Class