Android 酒店客房管理簡單小程式
程式實現功能:使用者登陸註冊,客房預訂,房間查詢,房間報修,房間退訂,以維修部身份登陸檢視房間損壞情況。。。
程式執行截圖:
資料庫幫助類:
package com.engineer.shizhibin.myhotel2;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class dbHelper extends SQLiteOpenHelper {
public dbHelper(Context context, String name, int version) {
super(context, name, null, version);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL("create table reg_manage (name varchar(255)," + "pass varchar(255),"
+ "type varchar(20))");
db.execSQL("create table employee (name varchar(10)," +"sex varchar(10),"
+ "id varchar(18)," + "time varchar(255)," + "days varchar,"
+ "room_id varchar(10)primary key," + "money varchar)");
db.execSQL("create table repair (room_id varchar(10),"
+ " item varchar(255),"+"finish varchar(255))");
db.execSQL("create table reg_repair (name varchar(255)," + "pass varchar(255),"
+ "type varchar(20))");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
}
}
登陸首頁程式碼:
package com.engineer.shizhibin.myhotel2;
import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
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.Spinner;
import android.widget.Toast;
/**
* ShiZhiBin
* */
public class Login extends Activity {
private EditText name;
private EditText password;
private Spinner title;
private Button login;
private Button cancel;
private Button comein;
private dbHelper helper = new dbHelper(Login.this, "hotel", 1);
private SQLiteDatabase sdb;
private String strSpinner;
String strName = "";
String strPassword = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
login = (Button) findViewById(R.id.login);
cancel = (Button) findViewById(R.id.cancel);
comein = (Button) findViewById(R.id.reg);
name = (EditText) findViewById(R.id.name);
password = (EditText) findViewById(R.id.password);
title = (Spinner) findViewById(R.id.Spinner);
sdb = helper.getReadableDatabase();
login.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
//取得介面上的內容
strSpinner = title.getSelectedItem().toString();
strName = name.getText().toString();
strPassword = password.getText().toString();
//判斷使用者名稱和密碼是否為空
if (strName.equals("") || strPassword.equals("")) {
Toast.makeText(Login.this, "使用者名稱或者密碼不能為空", Toast.LENGTH_LONG)
.show();
} else {
//如果密碼不為空,判斷登入的人員是屬於哪個部門的
if (strSpinner.equals("管理部")) {
//以使用者名稱為限定條件,查詢密碼
Cursor cursor = sdb.query("reg_manage",
new String[] { "pass" }, "name=?",
new String[] { strName }, null, null, null);
// System.out.println("aaaaaaaaaaaaa");
//如果密碼不是空,獲得的密碼和輸入的密碼判斷
if (cursor.moveToNext()) {
//獲得的密碼和輸入的密碼相等的情況下,執行頁面跳轉
if (strPassword.equals(cursor.getString(cursor
.getColumnIndex("pass")))) {
Intent intent = new Intent(Login.this,
Manage.class);
startActivity(intent);
// System.out.println("bbbbbbbbbbb");
}
//獲得的密碼和輸入的密碼不相等的情況下,toast顯示提示資訊
else {
Toast.makeText(Login.this, "密碼不正確",
Toast.LENGTH_LONG).show();
}
}
//如果密碼為空,則說明使用者名稱不存在
else {
Toast.makeText(Login.this, "使用者名稱不存在",
Toast.LENGTH_LONG).show();
}
}
//同上
else {
Cursor cursor = sdb.query("reg_repair",
new String[] { "pass" }, "name=?",
new String[] { strName }, null, null, null);
if (cursor.moveToNext()) {
if (strPassword.equals(cursor.getString(cursor
.getColumnIndex("pass")))) {
Intent intent = new Intent(Login.this,
Repair.class);
startActivity(intent);
} else {
Toast.makeText(Login.this, "密碼不正確",
Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(Login.this, "使用者名稱不存在",
Toast.LENGTH_LONG).show();
}
}
}
name.setText("");
password.setText("");
}
});
comein.setOnClickListener(new OnClickListenercomein());
cancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
class OnClickListenercomein implements View.OnClickListener {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Login.this, Register.class);
startActivity(intent);
}
}
}
入住管理類:
package com.engineer.shizhibin.myhotel2;
import android.app.TabActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TabHost;
import android.widget.Toast;
public class Manage extends TabActivity {
private Button bnTime, bnCacul, ruzhu_commit, ruzhu_fresh, rep_sure,
rep_cancel, exits_sure, exits_query, query_button;
private EditText ruzhu_edTime;
SQLiteDatabase db;
String strCurrentTime = "";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabhost = getTabHost();
LayoutInflater.from(this).inflate(R.layout.maneger,
tabhost.getTabContentView(), true);
tabhost.addTab(tabhost.newTabSpec("tab1").setIndicator("入住")
.setContent(R.id.ruzhu));
tabhost.addTab(tabhost.newTabSpec("tab2").setIndicator("查詢")
.setContent(R.id.query));
tabhost.addTab(tabhost.newTabSpec("tab3").setIndicator("報修")
.setContent(R.id.repairs));
tabhost.addTab(tabhost.newTabSpec("tab3").setIndicator("退房")
.setContent(R.id.exits));
final dbHelper helper = new dbHelper(Manage.this, "hotel", 1);
db = helper.getWritableDatabase();
/**
* 入住Java程式碼
*/
// 獲取入住時間
bnTime = (Button) findViewById(R.id.bntime);
bnTime.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ruzhu_edTime = (EditText) findViewById(R.id.ruzhu_edtime);
strCurrentTime = new Time().currentTime();
ruzhu_edTime.setText(strCurrentTime);
}
});
// 通過入住天數來自動計算價格
bnCacul = (Button) findViewById(R.id.allPrice);
bnCacul.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String days = ((EditText) findViewById(R.id.ruzhu_days))
.getText().toString();
String room_id = ((EditText) findViewById(R.id.ruzhu_room_id))
.getText().toString();
EditText money = (EditText) findViewById(R.id.ruzhu_money);
if (days.equals("") || room_id.equals("")) {
Toast.makeText(Manage.this, "入住房間號和天數是必填的",
Toast.LENGTH_LONG).show();
} else {
if (Integer.parseInt(room_id) > 20) {
int APrice = Integer.parseInt(days) * 120;
money.setText(String.valueOf(APrice));
} else {
int APrice = Integer.parseInt(days) * 80;
money.setText(String.valueOf(APrice));
}
}
}
});
// 重新整理按鈕監聽事件實現
ruzhu_fresh = (Button) findViewById(R.id.ruzhu_fresh);
ruzhu_fresh.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
EditText name = ((EditText) findViewById(R.id.ruzhu_person_name));
name.setText("");
EditText id = ((EditText) findViewById(R.id.ruzhu_person_id));
id.setText("");
EditText days = ((EditText) findViewById(R.id.ruzhu_days));
days.setText("");
EditText room_id = ((EditText) findViewById(R.id.ruzhu_room_id));
room_id.setText("");
EditText money = ((EditText) findViewById(R.id.ruzhu_money));
money.setText("");
ruzhu_edTime = (EditText) findViewById(R.id.ruzhu_edtime);
ruzhu_edTime.setText("");
}
});
// 實現入住按鈕監聽事件
ruzhu_commit = (Button) findViewById(R.id.ruzhu_commit);
ruzhu_commit.setOnClickListener(new OnClickListener() {
String sex = "";
public void onClick(View v) {
// 獲取入住介面資訊
String name = ((EditText) findViewById(R.id.ruzhu_person_name))
.getText().toString();
final RadioButton radioButton1 = (RadioButton) findViewById(R.id.radioButton1);
if (radioButton1.isChecked()) {
sex = "男";
} else {
sex = "女";
}
String id = ((EditText) findViewById(R.id.ruzhu_person_id))
.getText().toString();
String days = ((EditText) findViewById(R.id.ruzhu_days))
.getText().toString();
String room_id = ((EditText) findViewById(R.id.ruzhu_room_id))
.getText().toString();
String money = ((EditText) findViewById(R.id.ruzhu_money))
.getText().toString();
String time = strCurrentTime;
// 判斷顧客資訊是否為空
if (name.equals("")) {
Toast.makeText(Manage.this, "顧客姓名不能為空", Toast.LENGTH_LONG)
.show();
} else if (id.equals("")) {
Toast.makeText(Manage.this, "顧客身份證號不能為空", Toast.LENGTH_LONG)
.show();
} else if (time.equals("")) {
Toast.makeText(Manage.this, "入住時間不能為空", Toast.LENGTH_LONG)
.show();
} else if (days.equals("")) {
Toast.makeText(Manage.this, "入住天數不能為空", Toast.LENGTH_LONG)
.show();
} else if (room_id.equals("")) {
Toast.makeText(Manage.this, "房間號不能為空", Toast.LENGTH_LONG)
.show();
} else if (money.equals("")) {
Toast.makeText(Manage.this, "總價格不能為空", Toast.LENGTH_LONG)
.show();
} else {
// 判斷想要入住的房間是否有人
Cursor cursor = db.query("employee",
new String[] { "name" }, "room_id= ?",
new String[] { room_id }, null, null, null);
if (cursor.moveToNext()) {
String strName = cursor.getString(cursor
.getColumnIndex("name"));
System.out.println(strName);
Toast.makeText(Manage.this, "該房間有顧客,請選擇其它房間",
Toast.LENGTH_LONG).show();
} else {
// 判斷身份證號是否是18位
if (id.length() == 18) {
// 將入住資訊插入資料庫
db.execSQL(
"insert into employee values(?,?,?,?,?,?,?)",
new String[] { name, sex, id, time, days,
room_id, money });
Toast.makeText(Manage.this, "入住成功", 10000).show();
} else {
Toast.makeText(Manage.this, "身份證號不正確,請重新輸入",
Toast.LENGTH_LONG).show();
((EditText) findViewById(R.id.ruzhu_person_id))
.setText("");
}
}
}
}
});
/**
* 查詢java程式碼
*/
final EditText query_room_id = (EditText) findViewById(R.id.query_room_id);
query_button = (Button) findViewById(R.id.query_button);
final WebView wv = (WebView) findViewById(R.id.weserach);
// 為查詢按鈕繫結監聽器
query_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// 獲得使用者輸入的房間號
String room_id_2 = query_room_id.getText().toString();
// 查詢使用者輸入的房間號是否與資料庫中的房間號匹配
Cursor cursor = db.query("employee", new String[] { "name",
"sex", "id", "room_id", "time", "days", "money" },
"room_id= ?", new String[] { room_id_2 }, null, null,
null);
if (cursor.moveToNext()) {
// 獲得資料庫資訊
String query_room_id = cursor.getString(cursor
.getColumnIndex("room_id"));
String query_name = cursor.getString(cursor
.getColumnIndex("name"));
String sex = cursor.getString(cursor.getColumnIndex("sex"));
String query_id = cursor.getString(cursor
.getColumnIndex("id"));
String query_time = cursor.getString(cursor
.getColumnIndex("time"));
String query_days = cursor.getString(cursor
.getColumnIndex("days"));
String query_money = cursor.getString(cursor
.getColumnIndex("money"));
StringBuilder sb = new StringBuilder();
// 拼接HTML程式碼
sb.append("<html>");
sb.append("<head>");
sb.append("</head>");
sb.append("<body>");
sb.append("房間號:" + query_room_id);
sb.append("<br>");
sb.append("<br>");
sb.append("姓名:" + query_name);
sb.append("<br>");
sb.append("<br>");
sb.append("性別:" + sex + "\n");
sb.append("<br>");
sb.append("<br>");
sb.append("身份證:" + query_id);
sb.append("<br>");
sb.append("<br>");
sb.append("入住時間:" + query_time);
sb.append("<br>");
sb.append("<br>");
sb.append("入住天數:" + query_days);
sb.append("<br>");
sb.append("<br>");
sb.append("總錢數:" + query_money);
sb.append("</body>");
sb.append("</html>");
// 把內容載入到webview中讓其顯示查詢資訊
wv.loadDataWithBaseURL(null, sb.toString(), "text/html",
"utf-8", null);
} else {
// 沒有人入住時顯示提示資訊
Toast.makeText(Manage.this, "該房間沒有入住資訊!", 5000).show();
wv.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
}
}
});
/**
* 報修Java程式碼
*/
rep_sure = (Button) findViewById(R.id.rep_sure);
rep_cancel = (Button) findViewById(R.id.rep_cancel);
final EditText rep_id = (EditText) findViewById(R.id.rep_id);
final EditText rep_status = (EditText) findViewById(R.id.rep_status);
rep_sure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String mRep_id = (rep_id.getText()).toString();
String mRep_status = (rep_status.getText()).toString();
db.execSQL("insert into repair values(?,?,?)", new String[] {
mRep_id, mRep_status, "no_repairs" });
Toast.makeText(Manage.this, "報修成功", 10000).show();
}
});
rep_cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
rep_id.setText("");
rep_status.setText("");
}
});
// 退房程式碼
final EditText exits_name = (EditText) findViewById(R.id.exits_name);
final EditText exits_room_id = (EditText) findViewById(R.id.exits_room_id);
exits_sure = (Button) findViewById(R.id.exits_sure);
exits_query = (Button) findViewById(R.id.exits_query);
// 取得當前房間編號的使用者名稱
exits_sure.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String name_demo = "";
String room_id1 = exits_room_id.getText().toString();
String strNameid = exits_name.getText().toString();
Cursor cursor = db.query("employee", new String[] { "name" },
"room_id like ?", new String[] { room_id1 }, null,
null, null);
// cursor.moveToFirst();
while (cursor.moveToNext()) {
name_demo = cursor.getString(cursor.getColumnIndex("name"));
}
// 判斷該房間的使用者名稱是否與輸入的使用者名稱相等
if (strNameid.equals(name_demo)) {
// 刪除該房間的登記資訊
db.delete("employee", "room_id like ?",
new String[] { room_id1 });
exits_room_id.setText("");
exits_name.setText("");
Toast.makeText(Manage.this, "刪除成功", 10000).show();
} else {
Toast.makeText(Manage.this, "刪除不成功", 10000).show();
}
cursor.close();
}
});
exits_query.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
註冊類:
package com.engineer.shizhibin.myhotel2;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
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.EditText;
import android.widget.Spinner;
import android.widget.Toast;
public class Register extends Activity {
private EditText name;
private EditText pass;
private Button reg;
private Button back;
private Spinner r_spinner;
SQLiteDatabase db;
dbHelper helper = new dbHelper(Register.this, "hotel", 1);
List<String> listName_manage = new ArrayList<String>();
List<String> listName_repair = new ArrayList<String>();
String strName;
String strSpinner;
String strPass;
int numTemp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.regis);
name = (EditText) findViewById(R.id.Ereg_name);
pass = (EditText) findViewById(R.id.Ereg_pass);
r_spinner = (Spinner) findViewById(R.id.r_Spinner);
reg = (Button) findViewById(R.id.re);
back = (Button) findViewById(R.id.back);
db = helper.getWritableDatabase();
reg.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
strName = name.getText().toString();
strPass = pass.getText().toString();
int numTemp = 0;
strSpinner = r_spinner.getSelectedItem().toString();
// Toast.makeText(Register.this, strSpinner, 10000).show();
if (strSpinner.equals("管理部")) {
// db.execSQL("insert into reg_manage values(?,?,?)",
// new String[] { strName, strPass, strSpinner });
// Toast.makeText(Register.this, "註冊成功", 10000).show();
Cursor cursor = db.query("reg_manage",
new String[] { "name" }, null, null, null, null,
null);
// Cursor cursor =
// db.rawQuery("select name from reg_manage",
// null);
while (cursor.moveToNext()) {
listName_manage.add(cursor.getString(cursor
.getColumnIndex("name")));
}
for (int i = 0; i < listName_manage.size(); i++) {
if (strName.equals(listName_manage.get(i))) {
new AlertDialog.Builder(Register.this)
.setTitle("提示框")
.setMessage("該使用者名稱已存在,請重新輸入!")
.setPositiveButton(
R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
}
}
).show();
break;
}
numTemp = i;
}
if ((numTemp + 1) >= listName_manage.size()) {
db.execSQL("insert into reg_manage values(?,?,?)",
new String[] { strName, strPass, strSpinner });
Toast.makeText(Register.this, "註冊成功", 10000).show();
}
}
if (strSpinner.equals("維修部")) {
Cursor cursor = db.query("reg_repair",
new String[] { "name" }, null, null, null, null,
null);
// Cursor cursor =
// db.rawQuery("select name from reg_manage",
// null);
while (cursor.moveToNext()) {
listName_repair.add(cursor.getString(cursor
.getColumnIndex("name")));
}
for (int i = 0; i < listName_repair.size(); i++) {
if (strName.equals(listName_repair.get(i))) {
new AlertDialog.Builder(Register.this)
.setTitle("提示框")
.setMessage("該使用者名稱已存在,請重新輸入!")
.setPositiveButton(
R.string.ok,
new DialogInterface.OnClickListener() {
@Override
public void onClick(
DialogInterface dialog,
int which) {
}
}
).show();
break;
}
numTemp = i;
}
if ((numTemp + 1) >= listName_repair.size()) {
db.execSQL("insert into reg_repair values(?,?,?)",
new String[] { strName, strPass, strSpinner });
Toast.makeText(Register.this, "註冊成功", 10000).show();
}
// db.execSQL("insert into reg_repair values(?,?,?)",
// new String[] { strName, strPass, strSpinner });
}
// Toast.makeText(Register.this, "註冊成功", 10000).show();
}
});
back.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
});
}
}
報修類:
package com.engineer.shizhibin.myhotel2;
import android.app.Activity;
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.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class Repair extends Activity {
SQLiteDatabase db;
// 維修事項
TextView repMatter;
EditText rep_room_id;
Spinner repStatus;
private Button rep_delete, rep_query;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.repair);
rep_delete = (Button) findViewById(R.id.rep_commit);
rep_query = (Button) findViewById(R.id.rep_select);
final dbHelper helper = new dbHelper(Repair.this, "hotel", 1);
db = helper.getWritableDatabase();
// 維修事項
repMatter = (TextView) findViewById(R.id.repMatter);
// 維修的房間號
rep_room_id = (EditText) findViewById(R.id.rep_room_id);
final String result_room_id = rep_room_id.getText().toString();
rep_query.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Cursor cursor = db.query("repair", new String[] { "room_id",
"item", "finish" }, " room_id=?",
new String[] { result_room_id }, null, null, null);
String strOne = cursor.getString(cursor
.getColumnIndex("room_id"));
String strTwo = cursor.getString(cursor.getColumnIndex("item"));
rep_room_id.setText(strOne);
repMatter.setText(strTwo);
}
});
rep_delete.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
db.delete("repair", "id=?", new String[] { result_room_id });
Toast.makeText(Repair.this, "刪除成功", 10000).show();
}
});
}
}
介面的XML程式碼不再貼出來了
相關文章
- 小程式 – 簡單入門
- 建立一個簡單的小程式
- Android 開發簡單記事本程式Android
- 簡單-定義一個小程式元件元件
- 小程式簡單實現表格佈局
- 原生小程式最最簡單的分享功能
- 簡單的小程式小結, 瞭解一下
- Android 最簡單的自定義檢視管理之一Android
- 逮蝦戶!Android程式除錯竟簡單如斯Android除錯
- 小程式wx.request()方法簡單封裝封裝
- JavaScript 簡單/不簡單 (小Tips分享)JavaScript
- 微信小程式之簡單開發操作(一)微信小程式
- axios簡單實現小程式延時loading指示iOS
- 小程式的生命週期函式(簡單易懂)函式
- Spring Boot + DD小程式 超級簡單的webscoketSpring BootWeb
- 簡單講講小程式外掛是什麼
- Android 混淆簡單入門Android
- Android 簡單控制元件Android控制元件
- Python訪問小程式簡單方法程式碼例項詳解Python
- 微信小程式wx.request的簡單封裝微信小程式封裝
- java實現一個簡單的爬蟲小程式Java爬蟲
- python手機版做小遊戲程式碼大全-python簡單小遊戲程式碼 怎麼用Python製作簡單小遊戲...Python遊戲
- Android中Lottie的簡單使用Android
- Android開發簡單教程.docAndroid
- Anbox:在 Linux 上執行 Android 應用程式的簡單方式LinuxAndroid
- 微信小程式簡單封裝圖片上傳元件微信小程式封裝元件
- 微信小程式教程01:小程式簡介微信小程式
- 使用簡單的Java程式碼實現酒店管理系統Java
- 一隻android簡訊控制馬的簡單分析Android
- Android分頁元件Paging簡單使用Android元件
- Android中SharePreferences的簡單實現Android
- Android熱修復簡單總結Android
- 簡單塔防小遊戲遊戲
- 微信小程式關於分享一些簡單總結微信小程式
- 一款簡單好用的微信小程式商城原始碼微信小程式原始碼
- 仿寫一個簡單的微信小程式(番茄鬧鐘)微信小程式
- 小程式爆紅專家:對簡單APP是巨大打擊APP
- 玩Android微信小程式版Android微信小程式