Langkah-langkah membuat Aplikasi Perhitungan Dana Pembangunan Rumah
Langkah pertama siapkan Komputer Processor Intel Pentium, RAM 2 GB, Hardisk 500 GB. Selanjutnya, siapkan aplikasi-aplikasi yang diperlukan :
1. Sistem
Operasi (Windows Seven).
2. Xampp 1.6.4
3. Eclipse Indigo.
4. SQL Server 2005.
5.
Microsoft
Visual Studio 2010.
First
buatlah Database baru pada SQL Server 2005. Cukup 5 saja (m_pengunjung, Data_HSP, l_jenis, t_HSP dan Login).
Keterangan :
1. m_pengunjung digunakan untuk menyimpan data nama user dan password.
2. Data_HSP digunakan untuk menampilkan data HSP.
3. l_jenis digunakan untuk
menamilkan kolom jenis.
4. t_HSP digunakan untuk menampilkan hasil perhitungan keseluruhan.
5. Login menyimpan data admin
yang digunakan untuk masuk kedalam aplikasi.
Waktunya Coding mengcoding Cantiiik
Coding di Androidnya dulu
1. Source code MainActivity.java
package e.hsp;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity_ extends Activity {
String user_name, password;
EditText user;
JSONArray str_login = null;
JSONParser jParser = new
JSONParser();
//private ProgressDialog
progressDialog;
/** Called when the activity
is first created. */
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
user = (EditText)
findViewById(R.id.txt_username);
//pass = (EditText)
findViewById(R.id.txt_password);
Button reset =
(Button) findViewById(R.id.btn_batal);
reset.setOnClickListener(new
OnClickListener() {
public void
onClick(View v) {
user.setText("");
//ass.setText("");
}
});
Button submit =
(Button) findViewById(R.id.btn_login);
submit.setOnClickListener(new
OnClickListener() {
public void
onClick(View v) {
/*progressDialog
= ProgressDialog.show(MainActivity_.this, "",
"Loading...");
new
Thread() {
public
void run() {
try
{
sleep(500);
}
catch (Exception e) {
Log.e("tag",
e.getMessage());
}
//
dismiss the progress dialog
progressDialog.dismiss();
}
}.start();*/
user_name
= user.getText().toString();
//password
= pass.getText().toString();
String
stts = "";
String
userr = "";
String
link = "http://192.168.43.49:8081/e_hsp/login.php?user="+user_name;
JSONObject
json = jParser.AmbilJson(link);
try {
str_login
= json.getJSONArray("start");
for
(int i = 0; i < str_login.length(); i++) {
JSONObject
ar = str_login.getJSONObject(i);
stts
= ar.getString("status");
userr
= ar.getString("userr");
user.setText("");
//pass.setText("");
if
(stts.trim().equals("berhasil")) {
Toast.makeText(getBaseContext(),
"Silahkan
Pilih ..!!!", Toast.LENGTH_LONG)
.show();
Intent
ni = null;
ni
= new Intent(MainActivity_.this,
DashBoardActivity.class);
Bundle
b = new Bundle();
b.putString("par_kode",
userr);
ni.putExtras(b);
startActivity(ni);
}
else {
Toast.makeText(getBaseContext(),
"Username
atau Password Salah..!!!",
Toast.LENGTH_LONG).show();
}
}
} catch
(JSONException e) {
e.printStackTrace();
}
}
});
}
}
2. Source code daftar.java digunakan oleh user saat pertama masuk aplikasi
package e.hsp;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class daftar extends
Activity {
Button btnSave;
JSONArray str_detail = null;
public String kd_jns, no,
nip,pengunjung;
private ProgressDialog
pDialog;
JSONParser jsonParser = new
JSONParser();
EditText peng,pass;
TextView
kode_jenis,kode_jp,kode_hrg,kode_peng;
private static String
url_update_product = "http://199.160.40.44:8085/e_hsp/daftar.php";--------> sesuaikan dengan ipconfig, nama database dan juga format php kamu.
private static final String
TAG_SUCCESS = "success";
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.panel_input_daftar);
Bundle b =
getIntent().getExtras();
//kd_jns =
b.getString("jns");
//no =
b.getString("n");
//pengunjung = b.getString("pengunjung");
peng=(EditText)findViewById(R.id.t_peng);
pass=(EditText)findViewById(R.id.t_pass);
btnSave =
(Button) findViewById(R.id.btnSave);
btnSave.setOnClickListener(new
View.OnClickListener() {
public void
onClick(View view) {
new
CreateNewProduct().execute();
}
});
}
class CreateNewProduct
extends AsyncTask<String, String, String> {
@Override
protected void
onPreExecute() {
super.onPreExecute();
pDialog = new
ProgressDialog(daftar.this);
pDialog.setMessage("Proses..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String
doInBackground(String... args) {
String name =
peng.getText().toString();
String name4 =
pass.getText().toString();
List<NameValuePair>
params = new ArrayList<NameValuePair>();
params.add(new
BasicNameValuePair("pengunjung", name));
params.add(new
BasicNameValuePair("pass", name4));
JSONObject
json = jsonParser.makeHttpRequest(url_update_product,"POST", params);
Log.d("Create
Response", json.toString());
try {
int
success = json.getInt(TAG_SUCCESS);
if
(success == 1) {
Intent
ni = null;
ni
= new Intent(daftar.this, MainActivity.class);
Bundle
b = new Bundle();
//b.putString("pengunjung",
pengunjung);
//b.putString("kode",
kode);
//ni.putExtras(b);
startActivity(ni);
finish();
} else {
}
} catch
(JSONException e) {
e.printStackTrace();
}
return null;
}
protected void
onPostExecute(String file_url) {
pDialog.dismiss();
}
}
}
3. Source
code DashBoardActivity.Java
package e.hsp;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
public class DashBoardActivity extends Activity {
public String
nim,pengunjung;
private ProgressDialog
progressDialog;
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.panel_dasboard);
Bundle b =
getIntent().getExtras();
pengunjung =
b.getString("pengunjung");
//Button btn_about =
(Button) findViewById(R.id.btn_about);
Button btn_rab =
(Button) findViewById(R.id.btn_rab);
Button btn_his =
(Button) findViewById(R.id.btn_his);
Button btn_ttg =
(Button) findViewById(R.id.btn_ttg);
//Button
btn_DBim = (Button) findViewById(R.id.btn_DB);
//Button btn_info =
(Button) findViewById(R.id.btn_inf);
btn_rab.setOnClickListener(new View.OnClickListener()
{
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), cari_jenis.class);
Bundle
b = new Bundle();
b.putString("pengunjung",
pengunjung);
i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
btn_his.setOnClickListener(new
View.OnClickListener() {
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), data_rab.class);
Bundle b = new Bundle();
b.putString("pengunjung",
pengunjung);
i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
btn_ttg.setOnClickListener(new
View.OnClickListener() {
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), infoActivity.class);
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
/* btn_daftbim.setOnClickListener(new
View.OnClickListener() {
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), daftar_bimActivity.class);
Bundle
b = new Bundle();
b.putString("par_kode",
nim);
i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
btn_about.setOnClickListener(new
View.OnClickListener() {
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), infoActivity.class);
Bundle
b = new Bundle();
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});*/
/*
btn_info.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), infoActivity.class);
Bundle
b = new Bundle();
b.putString("par_kode",
nik);
i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
/*btn_matkul.setOnClickListener(new
View.OnClickListener() {
@Override
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), KhsActivity.class);
Bundle
b = new Bundle();
b.putString("par_kode",
nik);
i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
btn_ruang.setOnClickListener(new
View.OnClickListener() {
@Override
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), IpsActivity.class);
Bundle
b = new Bundle();
b.putString("par_kode",
nik);
i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
btn_hari.setOnClickListener(new
View.OnClickListener() {
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), AllProductsActivity.class);
Bundle
b = new Bundle();
//b.putString("par_kode",
nim);
//i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(DashBoardActivity.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});*/
/*
btn_logout.setOnClickListener(new View.OnClickListener()
{
public
void onClick(View view) {
Intent
exit = new Intent(Intent.ACTION_MAIN);
exit.addCategory(Intent.CATEGORY_HOME);
exit.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
DashBoardActivity.this.finish();
startActivity(exit);
}
}); */
}
@Override
public boolean
onCreateOptionsMenu(Menu menu) {
MenuInflater inflater =
getMenuInflater();
inflater.inflate(R.menu.activity_main, menu);
return true;
}}
4. Source code DashBoardLayout.Java
package e.hsp;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
public class DashboardLayout extends ViewGroup {
private static final int
UNEVEN_GRID_PENALTY_MULTIPLIER = 10;
private int mMaxChildWidth =
0;
private int mMaxChildHeight =
0;
public DashboardLayout(Context
context) {
super(context, null);
}
public DashboardLayout(Context
context, AttributeSet attrs) {
super(context, attrs, 0);
}
public DashboardLayout(Context
context, AttributeSet attrs, int defStyle) {
super(context, attrs,
defStyle);
}
@Override
protected void onMeasure(int
widthMeasureSpec, int heightMeasureSpec) {
mMaxChildWidth = 0;
mMaxChildHeight = 0;
// Measure once to find
the maximum child size.
int childWidthMeasureSpec
= MeasureSpec.makeMeasureSpec(
MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
int childHeightMeasureSpec
= MeasureSpec.makeMeasureSpec(
MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.AT_MOST);
final int count =
getChildCount();
for (int i = 0; i <
count; i++) {
final View child =
getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
mMaxChildWidth =
Math.max(mMaxChildWidth, child.getMeasuredWidth());
mMaxChildHeight =
Math.max(mMaxChildHeight, child.getMeasuredHeight());
}
// Measure again for each
child to be exactly the same size.
childWidthMeasureSpec =
MeasureSpec.makeMeasureSpec(
mMaxChildWidth,
MeasureSpec.EXACTLY);
childHeightMeasureSpec =
MeasureSpec.makeMeasureSpec(
mMaxChildHeight,
MeasureSpec.EXACTLY);
for (int i = 0; i <
count; i++) {
final View child =
getChildAt(i);
if
(child.getVisibility() == GONE) {
continue;
}
child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
}
setMeasuredDimension(
resolveSize(mMaxChildWidth, widthMeasureSpec),
resolveSize(mMaxChildHeight,
heightMeasureSpec));
}
@Override
protected void
onLayout(boolean changed, int l, int t, int r, int b) {
int width = r - l;
int height = b - t;
final int count =
getChildCount();
// Calculate the number of
visible children.
int visibleCount = 0;
for (int i = 0; i <
count; i++) {
final View child =
getChildAt(i);
if
(child.getVisibility() == GONE) {
continue;
}
++visibleCount;
}
if (visibleCount == 0) {
return;
}
// Calculate what number
of rows and columns will optimize for even horizontal and
// vertical whitespace
between items. Start with a 1 x N grid, then try 2 x N, and so on.
int bestSpaceDifference =
Integer.MAX_VALUE;
int spaceDifference;
// Horizontal and vertical
space between items
int hSpace = 0;
int vSpace = 0;
int cols = 1;
int rows;
while (true) {
rows = (visibleCount -
1) / cols + 1;
hSpace = ((width -
mMaxChildWidth * cols) / (cols + 1));
vSpace = ((height -
mMaxChildHeight * rows) / (rows + 1));
spaceDifference =
Math.abs(vSpace - hSpace);
if (rows * cols !=
visibleCount) {
spaceDifference *=
UNEVEN_GRID_PENALTY_MULTIPLIER;
}
if (spaceDifference
< bestSpaceDifference) {
// Found a better
whitespace squareness/ratio
bestSpaceDifference = spaceDifference;
// If we found a
better whitespace squareness and there's only 1 row, this is
// the best we can
do.
if (rows == 1) {
break;
}
} else {
// This is a worse
whitespace ratio, use the previous value of cols and exit.
--cols;
rows =
(visibleCount - 1) / cols + 1;
hSpace = ((width -
mMaxChildWidth * cols) / (cols + 1));
vSpace = ((height
- mMaxChildHeight * rows) / (rows + 1));
break;
}
++cols;
}
// Lay out children based
on calculated best-fit number of rows and cols.
// If we chose a layout
that has negative horizontal or vertical space, force it to zero.
hSpace = Math.max(0,
hSpace);
vSpace = Math.max(0,
vSpace);
// Re-use width/height
variables to be child width/height.
width = (width - hSpace *
(cols + 1)) / cols;
height = (height - vSpace
* (rows + 1)) / rows;
int left, top;
int col, row;
int visibleIndex = 0;
for (int i = 0; i <
count; i++) {
final View child =
getChildAt(i);
if (child.getVisibility() == GONE) {
continue;
}
row = visibleIndex /
cols;
col = visibleIndex %
cols;
left = hSpace * (col +
1) + width * col;
top = vSpace * (row +
1) + height * row;
child.layout(left,
top,
(hSpace == 0
&& col == cols - 1) ? r : (left + width),
(vSpace == 0
&& row == rows - 1) ? b : (top + height));
++visibleIndex;
}
}
}
5. Source code cari_jenis.java untuk memilih jenis pekerjaan yang akan dipilih.
package e.hsp;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class cari_jenis extends
Activity {
private ProgressDialog
progressDialog;
public String
kode_guru1,pengunjung;
Button btnSave;
String Paramater;
JSONArray str_detail = null;
public String WAKTU, kode,
nip, nl,nik,KODEWAKTU,KODEHARI,KODENIM,norekam,guru_kode;
private ProgressDialog pDialog;
JSONParser jsonParser = new
JSONParser();
InputStream is = null;
String result = null;
String line = null;
String[] roll_no;
Spinner spinner1;
EditText nama,jns,waktu;
TextView
kode_guru,alamat1,ketjam1,nojam1,ket2;
private static String url_update_product
= "http://199.160.40.44:8085/e_hsp/cari_jenis.php";
//private static String
url_update_product = "http://10.0.2.2/ta_banu_mhs/update_matkul.php";
private static final String
TAG_SUCCESS = "success";
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.cari_jenis);
Bundle b = getIntent().getExtras();
pengunjung =
b.getString("pengunjung");
Button
b_selesai = (Button) findViewById(R.id.b_selesai);
b_selesai.setOnClickListener(new
View.OnClickListener() {
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), data_rab.class);
Bundle
b = new Bundle();
b.putString("pengunjung",
pengunjung);
i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(cari_jenis.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
jns=(EditText)findViewById(R.id.t_nis);
//final
List<String> list1 = new ArrayList<String>();
//JSONParser jParser
= new JSONParser();
btnSave = (Button)
findViewById(R.id.btnCari);
btnSave.setOnClickListener(new
View.OnClickListener() {
public void
onClick(View view) {
new
CreateNewProduct().execute();
}
});
}
class CreateNewProduct extends
AsyncTask<String, String, String> {
@Override
protected void
onPreExecute() {
super.onPreExecute();
pDialog = new
ProgressDialog(cari_jenis.this);
pDialog.setMessage("Pencarian
Data..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String
doInBackground(String... args) {
//String name
= kode_guru.getText().toString();
String name2 =
jns.getText().toString();
List<NameValuePair>
params = new ArrayList<NameValuePair>();
//params.add(new
BasicNameValuePair("guru_kode", name));
params.add(new
BasicNameValuePair("Jenis", name2));
JSONObject
json = jsonParser.makeHttpRequest(url_update_product,"POST", params);
Log.d("Create
Response", json.toString());
try {
int
success = json.getInt(TAG_SUCCESS);
if
(success == 1) {
Intent
i = new Intent(getApplicationContext(),lihat_data_jenis.class);
Bundle
b = new Bundle();
b.putString("jns",
name2);
b.putString("pengunjung",
pengunjung);
i.putExtras(b);
startActivity(i);
finish();
} else {
}
} catch
(JSONException e) {
e.printStackTrace();
}
return null;
}
protected void
onPostExecute(String file_url) {
pDialog.dismiss();
} } }
6. Source code data_RAB.java
package e.hsp;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.widget.AdapterView.OnItemClickListener;
import android.app.Activity;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
public class data_rab extends Activity {
private ProgressDialog
progressDialog;
public String
nis,matpl,KODENIM,KODEWAKTU,pengunjung;
JSONArray str_login =
null,str_login1=null;
//ArrayList<HashMap<String,
String>> daftar_mk_detail = new ArrayList<HashMap<String,
String>>();
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.data_mapel_detail_layout);
Bundle b =
getIntent().getExtras();
pengunjung =
b.getString("pengunjung");
Button b_selesai =
(Button) findViewById(R.id.b_selesai);
b_selesai.setOnClickListener(new
View.OnClickListener() {
public
void onClick(View view) {
Intent
i = new Intent(getApplicationContext(), DashBoardActivity.class);
Bundle
b = new Bundle();
b.putString("pengunjung",
pengunjung);
i.putExtras(b);
startActivity(i);
progressDialog=ProgressDialog.show(data_rab.this,"","loading");
new
Thread(){
public
void run(){
try{
sleep (5000);
}
catch
(Exception E){ Log.e ("tag",E.getMessage());}
//dismiss
the progress dialog
progressDialog.dismiss();
}
}
.start();
}
});
//matpl =
b.getString("matpel");
//KODEWAKTU =
b.getString("keter");
String link_url =
"http://199.160.40.44:8085/e_hsp/data_rab.php?pengunjung="+pengunjung;
String link_url2 =
"http://199.160.40.44:8085/e_hsp/data_rabtot.php?pengunjung="+pengunjung;
JSONParser jParser = new JSONParser();
JSONObject json =
jParser.AmbilJson(link_url);
JSONObject json2 =
jParser.AmbilJson(link_url2);
try {
str_login =
json.getJSONArray("data_rab");
str_login1 =
json2.getJSONArray("data_rabtot");
if(str_login1.equals(str_login1)){
String
mkul21 = "";
TextView
isi1 = (TextView) findViewById(R.id.t_tot);
for(int
i = 0; i < str_login1.length(); i++){
JSONObject
ar = str_login1.getJSONObject(i);
mkul21
+=""+ar.getString("subtotal")+"\n\n";
}
isi1.setText(mkul21);
}
if(str_login.equals(str_login)){
String
mkul2 = "";
TextView
isi = (TextView) findViewById(R.id.textSenin);
for(int
i = 0; i < str_login.length(); i++){
JSONObject
ar = str_login.getJSONObject(i);
mkul2
+=""+ar.getString("Jenis")+"\n\n";
}
isi.setText(mkul2);
}
if(str_login.equals(str_login)){
String
mkul21 = "";
TextView
isi = (TextView) findViewById(R.id.textSenin2);
for(int
i = 0; i < str_login.length(); i++){
JSONObject
ar = str_login.getJSONObject(i);
mkul21+=""+ar.getString("Jenis_Pekerjaan")+"\n\n";
}
isi.setText(mkul21);
}
if(str_login.equals(str_login)){
String
mkul232 = "";
TextView
isi = (TextView) findViewById(R.id.textSenin3);
for(int
i = 0; i < str_login.length(); i++){
JSONObject
ar = str_login.getJSONObject(i);
mkul232
+=""+ar.getString("Harga")+"\n\n";
}
isi.setText(mkul232);
}
if(str_login.equals(str_login)){
String
mkul3 = "";
TextView
isi = (TextView) findViewById(R.id.textSelasa);
for(int
i = 0; i < str_login.length(); i++){
JSONObject
ar = str_login.getJSONObject(i);
mkul3
+=""+ar.getString("volume")+"\n\n";
}
isi.setText(mkul3);
}
if(str_login.equals(str_login)){
String
mkul4 = "";
TextView
isi = (TextView) findViewById(R.id.textRabu);
for(int
i = 0; i < str_login.length(); i++){
JSONObject
ar = str_login.getJSONObject(i);
mkul4
+=""+ar.getString("total")+"\n\n";
}
isi.setText(mkul4);
}
}
catch (JSONException e) {
e.printStackTrace();
}
}}
7. Source code lihat_data_jenis.java
package e.hsp;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.Semaphore;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.R.anim;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
public class lihat_data_jenis extends ListActivity {
public String
jns,pengunjung,nim,ket, KODEHARI,KODENIM,KODEWAKTU;
JSONArray str_login = null;
ArrayList<HashMap<String,
String>> daftar_penprop = new ArrayList<HashMap<String,
String>>();
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.panel_lih_data_jenis);
Bundle b =
getIntent().getExtras();
jns =
b.getString("jns");
pengunjung =
b.getString("pengunjung");
String link_url =
"http://192.168.43.49:8081/e_hsp/lihat_data_jenis.php?Jenis="+jns;
JSONParser jParser =
new JSONParser();
JSONObject json =
jParser.AmbilJson(link_url);
try {
str_login =
json.getJSONArray("mhs");
for(int i = 0;
i < str_login.length(); i++){
JSONObject
ar = str_login.getJSONObject(i);
String
snis = ar.getString("Jenis");
String
snama= ar.getString("Jenis_Pekerjaan");
String
spoin= ar.getString("Harga");
String N = ar.getString("No");
HashMap<String,
String> map = new HashMap<String, String>();
map.put("Jenis",
snis);
map.put("Jenis_Pekerjaan",
snama);
map.put("Harga",
spoin);
map.put("No",
N);
daftar_penprop.add(map);
}
} catch
(JSONException e) {
e.printStackTrace();
}
this.adapter_listview();
}
public void
adapter_listview() {
ListAdapter kode_mk = new SimpleAdapter(this, daftar_penprop,
R.layout.daftar_lih_data_jenis ,new String[]
{"Jenis",
"Jenis_Pekerjaan","Harga","No"}, new int[]
{R.id.parameter1, R.id.tampilan1, R.id.ket,R.id.n});
setListAdapter(kode_mk);
ListView lv =
getListView();
lv.setOnItemClickListener(new
OnItemClickListener() {
public void
onItemClick(AdapterView<?> parent, View view,int position, long id) {
String
kode_nis = ((TextView) view.findViewById(R.id.parameter1)).getText().toString();
String
kode_ket = ((TextView) view.findViewById(R.id.n)).getText().toString();
Intent
in = new Intent(getApplicationContext(), input_volume.class);
in.putExtra("jns",
kode_nis);
in.putExtra("n",
kode_ket);
in.putExtra("pengunjung",
pengunjung);
startActivity(in);
}
});
}
}
8. Source code input_volume.java
package e.hsp;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.app.AlertDialog;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class input_volume extends
Activity {
Button btnSave;
JSONArray str_detail = null;
public String kd_jns, no,
nip,pengunjung;
private ProgressDialog
pDialog;
JSONParser jsonParser = new
JSONParser();
EditText nil;
TextView
kode_jenis,kode_jp,kode_hrg,kode_peng;
private static String
url_update_product = "http://192.168.43.49:8081/e_hsp/insert.php";
private static final String
TAG_SUCCESS = "success";
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.panel_input_volume);
Bundle b = getIntent().getExtras();
kd_jns =
b.getString("jns");
no =
b.getString("n");
pengunjung =
b.getString("pengunjung");
final TextView jns = (TextView)
findViewById(R.id.t_jns);
final TextView jp =
(TextView) findViewById(R.id.t_jp);
final TextView hg=(TextView)findViewById(R.id.t_hrg);
nil=(EditText)findViewById(R.id.t_vol);
kode_jenis=(TextView)findViewById(R.id.t_jns);
kode_jp=(TextView)findViewById(R.id.t_jp);
kode_hrg=(TextView)findViewById(R.id.t_hrg);
kode_peng=(TextView)findViewById(R.id.t_peng);
final String
url_product_detail =
"http://192.168.43.49:8081/e_hsp/data_jenis.php?Jenis="+ kd_jns +
"&Jenis_Pekerjaan=" + no;
JSONParser jParser =
new JSONParser();
JSONObject json =
jParser.AmbilJson(url_product_detail);
btnSave = (Button)
findViewById(R.id.btnSave);
try {
str_detail =
json.getJSONArray("data_guru");
if
(str_detail.equals(str_detail)) {
String
nim = "";
String
nama = "";
String
nilai = "";
for (int
i = 0; i < str_detail.length(); i++) {
JSONObject
ar = str_detail.getJSONObject(i);
nim
+= "" + ar.getString("Jenis");
nama
+= "" + ar.getString("Jenis_Pekerjaan");
nilai
+= "" + ar.getString("Harga");
}
jns.setText(nim);
jp.setText(nama);
hg.setText(nilai);
} else {
Toast.makeText(getBaseContext(),
"Gagal Loading Data..!!!",
Toast.LENGTH_LONG).show();
}
} catch
(JSONException e) {
e.printStackTrace();
}
btnSave.setOnClickListener(new
View.OnClickListener() {
String vol =
((EditText) findViewById(R.id.t_vol)).getText().toString().trim();
public void
onClick(View view) {
Context
context=input_volume.this;
if
(nil.getText().toString().equals("") )
{
String
e = "Silahkan Masukan Volume";
new
AlertDialog.Builder(context).setTitle("Salah Masukan").setMessage(e)
.setNeutralButton("Tutup",
new DialogInterface.OnClickListener() {
public
void onClick(DialogInterface dialog, int which) {
//
TODO Auto-generated method stub
}
}).show();
} else
{
new
CreateNewProduct().execute();
}
}
});
}
class CreateNewProduct
extends AsyncTask<String, String, String> {
@Override
protected void
onPreExecute() {
super.onPreExecute();
pDialog = new
ProgressDialog(input_volume.this);
pDialog.setMessage("Proses..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
protected String
doInBackground(String... args) {
//String name2
= nm.getText().toString();
String name1 =
kode_jenis.getText().toString();
String name2 =
kode_jp.getText().toString();
String name3 =
kode_hrg.getText().toString();
String name =
nil.getText().toString();
String name4 =
pengunjung.toString();
List<NameValuePair>
params = new ArrayList<NameValuePair>();
params.add(new
BasicNameValuePair("Jenis", name1));
params.add(new
BasicNameValuePair("Jenis_Pekerjaan", name2));
params.add(new
BasicNameValuePair("Harga", name3));
params.add(new
BasicNameValuePair("volume", name));
params.add(new
BasicNameValuePair("pengunjung", name4));
JSONObject
json = jsonParser.makeHttpRequest(url_update_product,"POST", params);
Log.d("Create
Response", json.toString());
try {
int
success = json.getInt(TAG_SUCCESS);
if
(success == 1) {
Intent
ni = null;
ni
= new Intent(input_volume.this, cari_jenis.class);
Bundle
b = new Bundle();
b.putString("pengunjung",
pengunjung);
//b.putString("kode",
kode);
ni.putExtras(b);
startActivity(ni);
finish();
} else {
}
} catch
(JSONException e) {
e.printStackTrace();
}
return null;
}
protected void
onPostExecute(String file_url) {
pDialog.dismiss();
}
}
}
9. Source code JSONParser.java
package e.hsp;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONException;
import org.json.JSONObject;
import android.util.Log;
public class JSONParser {
InputStream is;
String json;
static JSONObject jObj =
null;
JSONObject object;
public JSONObject
AmbilJson(String url) {
// Making HTTP
request
try {
//
defaultHttpClient
DefaultHttpClient
httpClient = new DefaultHttpClient();
HttpPost
httpPost = new HttpPost(url);
HttpResponse
httpResponse = httpClient.execute(httpPost);
HttpEntity
httpEntity = httpResponse.getEntity();
is =
httpEntity.getContent();
} catch
(UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException
e) {
e.printStackTrace();
} catch (IOException
e) {
e.printStackTrace();
}
try {
BufferedReader
reader = new BufferedReader(new InputStreamReader(
is,
"iso-8859-1"), 8);
StringBuilder
sb = new StringBuilder();
String line =
null;
while ((line =
reader.readLine()) != null) {
sb.append(line
+ "\n");
}
is.close();
json =
sb.toString();
} catch (Exception e)
{
Log.e("Buffer
Error", "Error converting result " + e.toString());
}
// try parse the string
to a JSON object
try {
jObj = new
JSONObject(json);
} catch
(JSONException e) {
Log.e("JSON
Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
public JSONObject
getObject(String url, String method, List<NameValuePair> value) throws IOException {
if(method ==
"POST"){
DefaultHttpClient
client = new DefaultHttpClient();
HttpPost post
= new HttpPost(url);
try {
post.setEntity(new
UrlEncodedFormEntity(value));
HttpResponse
response = client.execute(post);
HttpEntity
entity = response.getEntity();
is =
entity.getContent();
} catch
(UnsupportedEncodingException e) {
// TODO
Auto-generated catch block
e.printStackTrace();
} catch
(ClientProtocolException e) {
// TODO
Auto-generated catch block
e.printStackTrace();
} catch
(IOException e) {
// TODO
Auto-generated catch block
e.printStackTrace();
}
}else if(method ==
"GET"){
DefaultHttpClient
client = new DefaultHttpClient();
String param = URLEncodedUtils.format(value,
"utf-8");
url +=
"?" + param;
HttpGet get =
new HttpGet(url);
HttpResponse
response;
try {
response
= client.execute(get);
is =
response.getEntity().getContent();
} catch
(ClientProtocolException e) {
// TODO
Auto-generated catch block
e.printStackTrace();
} catch
(IOException e) {
// TODO
Auto-generated catch block
e.printStackTrace();
}
}
try {
BufferedReader
reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"));
StringBuilder
sb = new StringBuilder();
String line;
while((line =
reader.readLine())!=null){
sb.append(line+"\n");
}
is.close();
json =
sb.toString();
object = null;
} catch (Exception
e1) {
// TODO Auto-generated
catch block
e1.printStackTrace();
}
try {
object = new
JSONObject(json);
} catch
(JSONException e) {
// TODO
Auto-generated catch block
e.printStackTrace();
}
return object;
}
public JSONObject
makeHttpRequest(String url, String method,
List<NameValuePair>
params) {
// Making HTTP
request
try {
// check for
request method
if (method ==
"POST") {
//
request method is POST
//
defaultHttpClient
DefaultHttpClient
httpClient = new DefaultHttpClient();
HttpPost
httpPost = new HttpPost(url);
httpPost.setEntity(new
UrlEncodedFormEntity(params));
HttpResponse
httpResponse = httpClient.execute(httpPost);
HttpEntity
httpEntity = httpResponse.getEntity();
is =
httpEntity.getContent();
} else if
(method == "GET") {
//
request method is GET
DefaultHttpClient
httpClient = new DefaultHttpClient();
String
paramString = URLEncodedUtils.format(params, "utf-8");
url +=
"?" + paramString;
HttpGet
httpGet = new HttpGet(url);
HttpResponse
httpResponse = httpClient.execute(httpGet);
HttpEntity
httpEntity = httpResponse.getEntity();
is =
httpEntity.getContent();
}
} catch
(UnsupportedEncodingException e) {
e.printStackTrace();
} catch
(ClientProtocolException e) {
e.printStackTrace();
} catch (IOException
e) {
e.printStackTrace();
}
try {
BufferedReader
reader = new BufferedReader(new InputStreamReader(
is,
"iso-8859-1"), 8);
StringBuilder
sb = new StringBuilder();
String line =
null;
while ((line =
reader.readLine()) != null) {
sb.append(line
+ "\n");
}
is.close();
json =
sb.toString();
} catch (Exception e)
{
Log.e("Buffer
Error", "Error converting result " + e.toString());
}
// try parse the
string to a JSON object
try {
jObj = new
JSONObject(json);
} catch
(JSONException e) {
Log.e("JSON
Parser", "Error parsing data " + e.toString());
}
return
jObj;
Selanjutnya Coding PHP
1. Source
code koneksi.php
<?php
$server = 'dian-pc';
$link = mssql_connect($server, 'nama koneksi', 'password');
if ($link<=0){
$info = "Tidak Bisa Konek";
echo $info;
return;
}
if (!mssql_select_db('e_hsp', $link))
{
$info = "masuk";
echo $info;
return;
}
else
{
$info = "";
}
?>
Ket: untuk koneksi database
e_hsp
2. Source code daftar.php
<?php
/*
* Following code will create a
new product row
* All product details are read
from HTTP Post Request
*/
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['pengunjung'])&& isset($_POST['pass'])) {
$pass = $_POST['pass'];
$pengunjung =
$_POST['pengunjung'];
// include db connect class
include_once("koneksi.php");
//$link =
mysql_connect("localhost","root","") or
die("Cannot connect to the DB");
// mysql_select_db("pendaftaran",
$link) or die("Cannot select the DB");
// mysql inserting a new row
$result =
mssql_query("INSERT INTO m_pengunjung(pengunjung,pass)
VALUES('".$pengunjung."','".$pass."')");
// check if row inserted or
not
if ($result) {
// successfully inserted
into database
$response["success"]
= 1;
$response["message"] = "penambahan berhasil";
// echoing JSON response
echo
json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"]
= "Oops! An error occurred.";
// echoing JSON response
echo
json_encode($response);
}
} else {
// required field is missing
$response["success"]
= 0;
$response["message"]
= "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
Ket: membuat akun untuk
login pengunjung pada table m_pengunjung
Parameter : pengunjung,
pass
3. Source
code login.php
<?php
include("koneksi.php");
$user = $_GET['user'];
$pass = $_GET['pass'];
$q = mssql_query('SELECT * FROM m_pengunjung where
pengunjung="'.$user.'" and pass="'.$pass.'"');
if(mssql_num_rows($q)>0)
{
$v = '{"start" :
[';
$v .= '{"status" :
"berhasil", "userr" : "'.$user.'",
"hasil" : "Log In Berhasil..!!!"}';
$v .= ']}';
echo $v;
}
else
{
$v = '{"start" :
[';
$v .= '{"status" :
"gagal", "userr" : "'.$user.'", "hasil"
: "Username atau Password Salah..!!!"}';
$v .= ']}';
echo $v;
}
?>
Ket: masuk kedalam aplikasi
dengan akun pada table m_pengunjung
Parameter : pengunjung,
pass
4. Source
code cari_jenis.php
<?php
$response = array();
if (isset($_POST['jenis'])) {
$jenis = $_POST['jenis'];
include_once("koneksi.php");
$result =
mssql_query("select jenis from l_jenis");
if ($result) {
// successfully inserted
into database
$response["success"] = 1;
$response["message"] = "Pencarian Selesai";
// echoing JSON response
echo
json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo
json_encode($response);
}
} else {
// required field is missing
$response["success"]
= 0;
$response["message"]
= "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
Ket: mencari data jenis
pekerjaan(table data_HSP) sesuai jenis pada table l_jenis
Parameter : jenis
5. Source
code ket2.php untuk memudahkan pencarian jenis pekerjaan
<?php
include("koneksi.php");
$sql = mssql_query(" SELECT
jenis FROM l_jenis");
while($row=mssql_fetch_array($sql))
{
$cls[]=$row;
//echo $fin."<br>";
}
print(json_encode($cls));
?>
Ket: mencari data hsp
melalui l_jenis
Parameter : jenis
6. Source
code lihat_data_jenis.php
<?php
include("koneksi.php");
$Jenis = $_GET['Jenis'];
$q = mssql_query(' SELECT Jenis,Jenis_Pekerjaan,Harga,No from Data_HSP
where Jenis="'.$Jenis.'" ');
$v = '{"mhs" : [';
while($r=mssql_fetch_array($q))
{
if(strlen($v)<20)
{
$v .=
'{"Jenis" : "'.$r['Jenis'].'","Jenis_Pekerjaan" :
"'.$r['Jenis_Pekerjaan'].'","Harga" :
"'.$r['Harga'].'","No" : "'.$r['No'].'"}';
}
else
{
$v .=
',{"Jenis" : "'.$r['Jenis'].'","Jenis_Pekerjaan"
: "'.$r['Jenis_Pekerjaan'].'","Harga" : "'.$r['Harga'].'","No"
: "'.$r['No'].'"}';
}
}
$v .= ']}';
echo $v;
?>
Ket: menampilkan data HSP
pada table Data_HSP
Parameter : jenis,
jenis_pekerjaan, harga
7. Source code insert.php untuk memasukkan Volume
<?php
/*
* Following code will create a
new product row
* All product details are read
from HTTP Post Request
*/
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['Jenis'])&&
isset($_POST['Jenis_Pekerjaan'])&& isset($_POST['Harga'])&&
isset($_POST['volume'])&& isset($_POST['pengunjung'])) {
$Jenis = $_POST['Jenis'];
$Jenis_Pekerjaan =
$_POST['Jenis_Pekerjaan'];
$Harga = $_POST['Harga'];
$volume = $_POST['volume'];
$pengunjung =
$_POST['pengunjung'];
// include db connect class
include_once("koneksi.php");
//$link =
mysql_connect("localhost","root","") or
die("Cannot connect to the DB");
// mysql_select_db("pendaftaran",
$link) or die("Cannot select the DB");
// mysql inserting a new row
$result =
mssql_query("INSERT INTO t_hsp(Jenis,Jenis_Pekerjaan,Harga,volume,pengunjung)
VALUES('".$Jenis."','".$Jenis_Pekerjaan."',
'".$Harga."', '".$volume."',
'".$pengunjung."')");
// check if row inserted or
not
if ($result) {
// successfully inserted
into database
$response["success"]
= 1;
$response["message"] = "penambahan berhasil";
// echoing JSON response
echo
json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo
json_encode($response);
}
} else {
// required field is missing
$response["success"]
= 0;
$response["message"]
= "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
Ket: memasukkan jumlah
volume pada table t_hsp
Parameter : jenis,
jenis_pekerjaan, harga, volume, pangunjung
8. Source
code data_jenis.php
<?php
include("koneksi.php");
$Jenis = $_GET['Jenis'];
$Jenis_Pekerjaan = $_GET['Jenis_Pekerjaan'];
$kodee = $_GET['kodee'];
$sql = mssql_query(' SELECT
Jenis,Jenis_Pekerjaan,Harga FROM Data_HSP
where Jenis="'.$Jenis.'" and
No="'.$Jenis_Pekerjaan.'" ');
$v = '{"data_guru" : [';
while($r=mssql_fetch_array($sql))
{
if(strlen($v)<20)
{
$v .=
'{"Jenis" : "'.$r['Jenis'].'","Jenis_Pekerjaan" :
"'.$r['Jenis_Pekerjaan'].'","Harga" :
"'.$r['Harga'].'"}';
}
else
{
$v .=
',{"Jenis" : "'.$r['Jenis'].'","Jenis_Pekerjaan"
: "'.$r['Jenis_Pekerjaan'].'","Harga" : "'.$r['Harga'].'"}';
}
}
$v .= ']}';
echo $v;
?>
Ket: menampilkan data jenis
dari table data_HSP
Parameter : jenis,
jenis_pekerjaan, harga
9. Source code data_rab.php
<?php
include("koneksi.php");
$pengunjung = $_GET['pengunjung'];
$q = mssql_query(' SELECT hsp_id,
pengunjung,
No,
Jenis,
Jenis_Pekerjaan,
Harga,
volume,
total=(harga*volume)
FROM [dbo].[t_hsp]
where
pengunjung="'.$pengunjung.'" ');
$v = '{"data_rab" : [';
while($r=mssql_fetch_array($q))
{
if(strlen($v)<20)
{
$v .=
'{"Jenis" : "'.$r['Jenis'].'","Jenis_Pekerjaan" :
"'.$r['Jenis_Pekerjaan'].'","Harga" :
"'.$r['Harga'].'","volume" :
"'.$r['volume'].'","total" : "'.$r['total'].'"}';
}
else
{
$v .=
',{"Jenis" : "'.$r['Jenis'].'","Jenis_Pekerjaan"
: "'.$r['Jenis_Pekerjaan'].'","Harga" :
"'.$r['Harga'].'","volume" :
"'.$r['volume'].'","total" : "'.$r['total'].'"}';
}
}
$v .= ']}';
echo $v;
?>
Ket: menampilkan table
t_hsp dan menambahkan nilai keseluruhan total penjumlahan jenis pekerjaan dari
(harga * volume)
Parameter : pengunjung,
jenis, jenis_pekerjaan, harga, volume, total
10. Source code data_rabtot.php
<?php
include("koneksi.php");
$pengunjung = $_GET['pengunjung'];
$q = mssql_query(' SELECT
subtotal=sum(harga*volume)
FROM [dbo].[t_hsp]
where
pengunjung="'.$pengunjung.'" ');
$v = '{"data_rabtot" : [';
while($r=mssql_fetch_array($q))
{
if(strlen($v)<20)
{
$v .=
'{"subtotal" : "'.$r['subtotal'].'"}';
}
else
{
$v .= ',{"subtotal"
: "'.$r['subtotal'].'"}';
}
}
$v .= ']}';
echo $v;
?>
Ket: dari table t_hsp
diambil subtotal dari (harga*volume)
Parameter : pengunjung