Học liệu

Chương trình quản lý thanh toán tiền bán hàng trên Android

  • 18/09/2019
  • Học liệu

undefined

undefined

Các bước thực hiện:

Bước 1: Xây dựng giao diện theo file XML sau:

xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_light"
android:text="Thông Tin Hóa Đơn"
android:textColor="@android:color/black"
android:textSize="18sp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tên Khách Hàng: "
android:textSize="18sp" />

<EditText
android:id="@+id/edthoten"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="Đoàn Ái Nương" />
TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Số lượng sách: "
android:textSize="18sp" />
<EditText
android:id="@+id/edtsl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="113" />
TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/chkvip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_weight="1"
android:checked="true"
android:text="Khách hàng VIP"
android:textSize="18sp" />
TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Thành Tiền"
android:textSize="18sp" />
<EditText
android:id="@+id/edtthanhtien"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="2034000"
android:textColor="@android:color/holo_green_dark"
android:textStyle="bold" />
TableRow>
TableLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/btntinh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tính TT" />
<Button
android:id="@+id/btntiep"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Tiếp" />
<Button
android:id="@+id/btnthongke"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Thống kê" />
LinearLayout>
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/holo_orange_light"
android:text="Thông Tin Thống Kê"
android:textColor="@android:color/black"
android:textSize="18sp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tổng số KH"
android:textSize="18sp" />
<EditText
android:id="@+id/edttongkh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="3" />
TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tổng số KH VIP"
android:textSize="18sp" />
<EditText
android:id="@+id/edttongvip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="1" />
TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tổng doanh thu"
android:textSize="18sp" />
<EditText
android:id="@+id/edttongdt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="textPersonName"
android:text="2184000" />
TableRow>
TableLayout>

LinearLayout>

Bước 2: Mở File MainActivity.java, và cập nhật đoạn Code sau:
public class MainActivity extends AppCompatActivity {
EditText edttenkh,edtsl,edtthanhtien,edttongkh,edttongvip,edttongdt;
Button btntinh,btntiep,btntk;
CheckBox chkvip; int tongkh = 0;
    int tongkhvip = 0;
double tongdoanhthu = 0.0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edttenkh= findViewById(R.id.edthoten);
edtsl = findViewById(R.id.edtsl);
edtthanhtien = findViewById(R.id.edtthanhtien);
edttongkh = findViewById(R.id.edttongkh);
edttongvip = findViewById(R.id.edttongvip);
edttongdt = findViewById(R.id.edttongdt);
btntinh = findViewById(R.id.btntinh);
btntiep = findViewById(R.id.btntiep);
btntk = findViewById(R.id.btnthongke);
chkvip = findViewById(R.id.chkvip);

btntinh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int sl = Integer.parseInt(edtsl.getText().toString());
if (chkvip.isChecked())
{
edtthanhtien.setText(""+(sl*20000*0.9));
}
else
{
edtthanhtien.setText(""+(sl*20000));
}
}
});
btntiep.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (chkvip.isChecked())
{
tongkhvip = tongkhvip +1;

}
else
{
tongkh = tongkh +1;
}
tongdoanhthu = tongdoanhthu + Double.parseDouble(edtthanhtien.getText().toString());
edttenkh.setText("");
edttenkh.requestFocus();
edtsl.setText("");
edtthanhtien.setText("");
}
});
btntk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edttongkh.setText(""+tongkh);
edttongvip.setText(""+tongkhvip);
edttongdt.setText(""+tongdoanhthu);
}
});
}
}
 

Các tin khác