NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.test.quizandroid;

import android.database.Cursor;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
DatabaseHelper myDb;
EditText editNomorBarang, editNamaBarang, editHarga, editDiskon, editHargaAkhir;
Button btnInsert;
Button btnView;
Button btnUpdate;

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

myDb = new DatabaseHelper(this);

editNomorBarang = (EditText) findViewById(R.id.edtNomorBarang);
editNamaBarang = (EditText) findViewById(R.id.edtNamaBarang);
editHarga = (EditText) findViewById(R.id.edtHarga);
editDiskon = (EditText) findViewById(R.id.edtDiskon);
editHargaAkhir = (EditText) findViewById(R.id.edtHargaAkhir);

btnInsert = (Button) findViewById(R.id.btnInsert);
btnUpdate = (Button) findViewById(R.id.btnUpdate);
btnView = (Button) findViewById(R.id.btnView);

AddData();
viewAll();
UpdateData();
}

public void UpdateData() {
btnUpdate.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
boolean isUpdate = myDb.updateData(editNomorBarang.getText().toString(),
editNamaBarang.getText().toString(),
Integer.parseInt(editHarga.getText().toString()),Integer.parseInt(editDiskon.getText().toString()),Integer.parseInt(editHargaAkhir.getText().toString()));
if(isUpdate == true)
Toast.makeText(MainActivity.this,"Data Update",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"Data not Updated",Toast.LENGTH_LONG).show();
}
}
);
}

public void AddData() {
btnInsert.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
int hrg = Integer.parseInt(editHarga.getText().toString());
int dsk = Integer.parseInt(editDiskon.getText().toString());
int total = Integer.parseInt(editHargaAkhir.getText().toString());

total = ((hrg * dsk) - (hrg * dsk/100));

boolean isInserted = myDb.insertData(editNamaBarang.getText().toString(),
hrg,
dsk,
total);
if(isInserted == true)
Toast.makeText(MainActivity.this,"Data Inserted",Toast.LENGTH_LONG).show();
else
Toast.makeText(MainActivity.this,"Data not Inserted",Toast.LENGTH_LONG).show();
}
}
);
}

public void viewAll() {
btnView.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Cursor res = myDb.getAllData();
if(res.getCount() == 0) {
// show message
showMessage("Error","Nothing found");
return;
}

StringBuffer buffer = new StringBuffer();
while (res.moveToNext()) {
buffer.append("Id :"+ res.getString(0)+"n");
buffer.append("Nama :"+ res.getString(1)+"n");
buffer.append("Harga :"+ res.getString(2)+"n");
buffer.append("Diskon :"+ res.getString(3)+"n");
buffer.append("Harga Akhir :"+ res.getString(4)+"n");
}

// Show all data
showMessage("Data Penjualan 2019",buffer.toString());
}
}
);
}

public void showMessage(String title,String Message){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCancelable(true);
builder.setTitle(title);
builder.setMessage(Message);
builder.show();
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.