Saturday, October 13, 2012

Costum menu untuk list outlet

Sebelumnya, ane akan menjelaskan terlebih dahulu apa itu costum menu. Seperti arti bahasa indonesia nya, costum menu merupakan hasil dari costumisasi menu yang akan kita tampilkan dimana menu standart yang ada pada android hanya terdiri atas peringatan, trus dua tombol yes/no.

Sementara pada project ini, kita membutuhkan tampilan menu seperti :
sehingga komponen yang disediakan oleh eclipse sendiri tidak mencukupinya. Makanya kita butuh untuk mengkostumisasinya terlebih dahulu dengan membuatnya sendiri.

Berikut caranya :
Buat file layout baru dengan nama cm_list_outlet.xml dan isikan kode seperti berikut ini :

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="USER NAME :"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="USER NAME"
            android:id="@+id/cmlo_user"
            />
       
    </LinearLayout>
           
       
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="KODE OUTLET :"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="KODE OUTLET"
            android:id="@+id/cmlo_kode_outlet"
            />
       
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="NAMA OUTLET :"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="NAMA OUTLET"
            android:id="@+id/cmlo_nama_outlet"
            />
       
    </LinearLayout>
   
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="ALAMAT OUTLET :"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="ALAMAT OUTLET"
            android:id="@+id/cmlo_alamat_outlet"
            />
       
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="KOTA OUTLET :"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="KOTA OUTLET"
            android:id="@+id/cmlo_kota_outlet"
            />
       
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="VALUE BL :"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="VALUE BL"
            android:id="@+id/cmlo_vbl"
            />
       
    </LinearLayout>
   
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="VALUE BR :"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="VALUE BR"
            android:id="@+id/cmlo_vbr"
            />
       
    </LinearLayout>
   
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="VALUE BB :"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="VALUE BB"
            android:id="@+id/cmlo_vbb"
            />
       
    </LinearLayout>
   
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
       
        <TextView
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="TARGET :"
            />
        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="TARGET"
            android:id="@+id/cmlo_target"
            />
       
    </LinearLayout>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="CEK STOCK"
        android:id="@+id/cmlo_cek_stock"
        />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="PENJUALAN"
        android:id="@+id/cmlo_penjualan"
        />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="PENAGIHAN"
        android:id="@+id/cmlo_tagihan"
        />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="BATAL CALL"
        android:id="@+id/cmlo_batal"
        />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="GAGAL CALL"
        android:id="@+id/cmlo_gagal"
        />
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="SELESAI CALL"
        android:id="@+id/cmlo_selesai"
        />
</LinearLayout>
</ScrollView>
 Lalu untuk file javanya beri nama C_cm_list_outlet.java dengan code :
package com.esa.demo;

import java.text.SimpleDateFormat;
import java.util.Calendar;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.TextView;
import android.widget.Toast;

public class C_cm_list_outlet extends Activity {
    mySqlHelper dbHelper;
    protected Cursor cursor;
    protected ListAdapter adapter;
    String xuser_name, xkode_outlet, xnama_outlet, xalamat_outlet, xkota_outlet;
   
    @Override
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.cm_list_outlet);
        Intent myIntent = this.getIntent();
        dbHelper = new mySqlHelper(this);
       
        final TextView cmlo_kode_outlet = (TextView) findViewById(R.id.cmlo_kode_outlet);
        TextView cmlo_nama_outlet = (TextView) findViewById(R.id.cmlo_nama_outlet);
        TextView cmlo_alamat_outlet = (TextView) findViewById(R.id.cmlo_alamat_outlet);
        TextView cmlo_kota_outlet = (TextView) findViewById(R.id.cmlo_kota_outlet);
        TextView cmlo_vbl = (TextView) findViewById(R.id.cmlo_vbl);
        TextView cmlo_vbr = (TextView) findViewById(R.id.cmlo_vbr);
        TextView cmlo_vbb = (TextView) findViewById(R.id.cmlo_vbb);
        TextView cmlo_target = (TextView) findViewById(R.id.cmlo_target);
        final TextView cmlo_user = (TextView) findViewById(R.id.cmlo_user);

        cmlo_user.setText(myIntent.getStringExtra("xuser_name"));
        cmlo_kode_outlet.setText(myIntent.getStringExtra("xkode_outlet"));
        cmlo_nama_outlet.setText(myIntent.getStringExtra("xnama_outlet"));
        cmlo_alamat_outlet.setText(myIntent.getStringExtra("xalamat_outlet"));
        cmlo_kota_outlet.setText(myIntent.getStringExtra("xkota_outlet"));
               
        SQLiteDatabase db = dbHelper.getReadableDatabase();


        cursor = db.rawQuery("SELECT * FROM t_his_outlet where kode_outlet = '"+cmlo_kode_outlet.getText().toString()+"'", null);
        //cursor.moveToPosition(arg2);
   
   
        if(cursor.getCount()>0){
            cursor.moveToFirst();
            cmlo_vbl.setText(cursor.getString(2));
            Double vbl = Double.parseDouble(cmlo_vbl.getText().toString());
            cmlo_vbl.setText(Double.toString(vbl));
           
            cmlo_vbr.setText(cursor.getString(3));
            Double vbr = Double.parseDouble(cmlo_vbr.getText().toString());
            cmlo_vbr.setText(Double.toString(vbr));
           
            cmlo_vbb.setText(cursor.getString(4));
            Double vbb = Double.parseDouble(cmlo_vbb.getText().toString());
            cmlo_vbb.setText(Double.toString(vbb));
           
            cmlo_target.setText(cursor.getString(5));
            Double target = Double.parseDouble(cmlo_target.getText().toString());
            cmlo_target.setText(Double.toString(target));
           
        }else{
            cmlo_vbl.setText("0");
            cmlo_vbr.setText("0");
            cmlo_vbb.setText("0");
            cmlo_target.setText("0");
        }
   
        final Button cmlo_cek_stock = (Button) findViewById(R.id.cmlo_cek_stock);
        cmlo_cek_stock.setOnClickListener(new OnClickListener() {
       
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getBaseContext(), "Maaf, hanya tersedia di versi pro...", Toast.LENGTH_LONG).show();
            }
        });
       
        Button cmlo_penjualan = (Button) findViewById(R.id.cmlo_penjualan);
        cmlo_penjualan.setOnClickListener(new OnClickListener() {
       
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent myIntent =new Intent(C_cm_list_outlet.this, C_form_penjualan.class);
                myIntent.putExtra("xkode_outlet", cmlo_kode_outlet.getText().toString());
                startActivity(myIntent);
            }
        });

        Button cmlo_tagihan = (Button) findViewById(R.id.cmlo_tagihan);
        cmlo_tagihan.setOnClickListener(new OnClickListener() {
       
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getBaseContext(), "Maaf, hanya tersedia di versi pro...", Toast.LENGTH_LONG).show();
            }
        });

        Button cmlo_batal = (Button) findViewById(R.id.cmlo_batal);
        cmlo_batal.setOnClickListener(new OnClickListener() {
       
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
            batal_call();
            delete_kunjungan();
            delete_stock();
            delete_jual();

            finish();
            }
        });

        Button cmlo_gagal = (Button) findViewById(R.id.cmlo_gagal);
        cmlo_gagal.setOnClickListener(new OnClickListener() {
       
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent myIntent =new Intent(C_cm_list_outlet.this, C_form_gagal_call.class);
                myIntent.putExtra("xkode_outlet", cmlo_kode_outlet.getText().toString());
                myIntent.putExtra("xuser_name", cmlo_user.getText().toString());
                startActivity(myIntent);
                finish();
            }
        });

        Button cmlo_selesai = (Button) findViewById(R.id.cmlo_selesai);
        cmlo_selesai.setOnClickListener(new OnClickListener() {
       
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                selesai_kunjungan();
                finish();
            }
        });

    }

    public void batal_call(){
        final TextView cmlo_kode_outlet = (TextView) findViewById(R.id.cmlo_kode_outlet);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try{
            db.execSQL("update t_call set call = '0' where kode_outlet = '"+cmlo_kode_outlet.getText().toString()+"'");
        }catch(Exception e){
            Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
        }
    }

    public void delete_kunjungan(){
        final TextView cmlo_kode_outlet = (TextView) findViewById(R.id.cmlo_kode_outlet);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try{
            db.execSQL("delete from t_kunjungan where kode_outlet = '"+cmlo_kode_outlet.getText().toString()+"'");
        }catch(Exception e){
            Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
        }
    }

    public void delete_stock(){
        final TextView cmlo_kode_outlet = (TextView) findViewById(R.id.cmlo_kode_outlet);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try{
            db.execSQL("delete from t_stock where kode_outlet = '"+cmlo_kode_outlet.getText().toString()+"'");
        }catch(Exception e){
            Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
        }
    }

    public void delete_jual(){
        final TextView cmlo_kode_outlet = (TextView) findViewById(R.id.cmlo_kode_outlet);
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try{
            db.execSQL("delete from t_jual where kode_outlet = '"+cmlo_kode_outlet.getText().toString()+"'");
        }catch(Exception e){
            Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
        }
    }

    public void selesai_kunjungan(){
        final TextView cmlo_kode_outlet = (TextView) findViewById(R.id.cmlo_kode_outlet);
        Calendar kini = Calendar.getInstance();
        SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yy HH:mm");
       
        SQLiteDatabase db = dbHelper.getWritableDatabase();
        try{
            db.execSQL("update t_kunjungan set keluar = '"+df.format(kini.getTime())+"' where kode_outlet = '"+cmlo_kode_outlet.getText().toString()+"'");
        }catch(Exception e){
            Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
        }
    }

    public void onBackPressed(){
        AlertDialog.Builder ad=new AlertDialog.Builder(C_cm_list_outlet.this);
        ad.setTitle("Konfirmasi");
        ad.setMessage("Gunakan tombol BATAL/SELESAI");
        ad.show();
    }

}
Sedikit keterangan :
Pada interface list outlet, terdapat banyak sekali nama2 outlet yang menjadi target market dari perusahaan dan harus dikunjungi. Setelah menentukan outlet yang bakalan dikunjungi, maka salesman mengklik salah satu nama outlet sehingga muncul menu list outlet yag barusan sudah kita kostumisasi...

Dari situ, maka salesman tinggal pilih apakah mau melakukan cek stock, penjualan, penagihan, dll sesuai dengan menu yang sudah kita siapkan tadi...


Selamat mencoba, dan jangan lupa untuk komen bila ada yang meragukan... Dan jangan lupa bray... iklan nya... hahahaha

1 comment:

  1. dbHelpernya mana gan?? kog ga lengkap gitu??

    ReplyDelete

iklan melayang