記賬本的設計與實現
一、需求分析
1.1特性需求分析
(1):易操作和功能簡單明確不令人誤解。一個良好的個人記賬本應該功能明確,用戶可以很明了的通過界面介紹明白各項功能的實現方法大,而不是看到界面不知道按鈕的具體用途,及操作簡單,界面友好易懂。用戶可以根據手機界面很清楚的進行記賬,刪除,查賬,更改等功能。
(2):軟件功能流暢,軟件在運行不能發生崩潰,卡頓等問題,整個頁面操作起來很流暢。
(3)軟件以維護,系統各個模塊設計應該很明確,核心代碼處應有必要的注釋,使得今后的軟件維護能夠順利地進行。
1.2功能需求分析
用戶應該能實現添加賬單,查詢賬戶信息,顯示消費記錄,顯示余額四大功能。
(1)用戶添加賬單功能:利用計算器輸入價錢並選擇消費用途,例如(餐飲,娛樂,水果,日常),並選擇消費方式(現金,支付寶,銀行卡)。
(2)查詢賬戶信息:用戶可以在我的賬戶頁面查詢消費記錄,詳細地記錄了消費用途,消費金額以及支付方式,同時也記錄了消費金額及賬戶余額。並且可以進行修改賬戶和添加收入等操作。
(3)顯示消費記錄:系統制定出一份分類帳單,詳細地記錄了消費用途及消費金額。

二、總體設計
2.1系統總功能結構圖

2.2 E-R模型
2.2.1 總的E-R模型

2.2.2 記錄的E-R模型

2.2.3 賬戶的E-R模型

2.3數據庫設計

三、系統測試
3.1查詢賬單
進入首頁便是賬單、余額、消費金額
3.2 添加記錄
經操作,可以手動輸入,也可以通過計算器計算輸入
3.3 查看個人賬戶
可以查看,可以修改個人賬戶,也可以添加收入
3.4 查看分類消費
點擊余額,可以查看個人消費的分類信息
3.5總結
經過測試,程序可以使用。
四、系統實現
4.1主頁

4.1.2顯示主頁的內容(MainActivity)
public void ListViewRecord() {
// 獲取所有賬單信息
ridlist = rid.findAll();
ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
// 要將goodslist中的內容格式改變,讓適配器可識別
for (RecordInfo record : ridlist) {
Map<String, Object> map = new HashMap<String, Object>();
map.put("type", record.getType());
map.put("money", "¥" +record.getMoney());
sum = sum + record.getMoney();
map.put("payway", record.getPayway());
list.add(map);
}
SimpleAdapter listAdapter = new SimpleAdapter(MainActivity.this, list,
R.layout.details_style, new String[] { "type", "money",
"payway" }, new int[] { R.id.tv_type, R.id.tv_money,
R.id.tv_payway });
lv_details.setAdapter(listAdapter);
}
4.2記賬頁面

4.2.1顯示記賬頁面(RecordActivity)
private void executeExpression() {
try {
// 調用第三方jar包來執行運算
total = Calculator.execute(content);
} catch (Exception e) {
total = "0";
return;
}
et_money.setText(total);
}
class ButtonClickListener implements OnClickListener {
@Override
public void onClick(View v) {
Button button = (Button) v;
content = et_money.getText().toString();
switch (button.getId()) {
case R.id.bt_one:
content = content + "1";
et_money.setText(content);
break;
case R.id.bt_two:
content = content + "2";
et_money.setText(content);
break;
case R.id.bt_three:
content = content + "3";
et_money.setText(content);
break;
case R.id.bt_four:
content = content + "4";
et_money.setText(content);
break;
case R.id.bt_five:
content = content + "5";
et_money.setText(content);
break;
case R.id.bt_six:
content = content + "6";
et_money.setText(content);
break;
case R.id.bt_seven:
content = content + "7";
et_money.setText(content);
break;
case R.id.bt_eight:
content = content + "8";
et_money.setText(content);
break;
case R.id.bt_nine:
content = content + "9";
et_money.setText(content);
break;
case R.id.bt_zero:
content = content + "0";
et_money.setText(content);
break;
case R.id.bt_plus:
content = content + "+";
et_money.setText(content);
break;
case R.id.bt_min:
content = content + "-";
et_money.setText(content);
break;
case R.id.bt_mud:
content = content + "*";
et_money.setText(content);
break;
case R.id.bt_div:
content = content + "/";
et_money.setText(content);
break;
case R.id.bt_backspace:
content = content.substring(0, content.length()-1);
et_money.setText(content);
break;
case R.id.bt_point:
content = content + ".";
et_money.setText(content);
break;
case R.id.bt_left:
content = content + "(";
et_money.setText(content);
break;
case R.id.bt_right:
content = content + ")";
et_money.setText(content);
break;
case R.id.bt_equal:
executeExpression();
content = "";
break;
}
}}
4.3 分類帳單

4.3.1顯示分類賬單內容(TypeActivity)
public void show() {
for (RecordInfo record : recordlist) {
String type = record.getType();
if (type.equals("餐飲")) {
sum_food = record.getMoney() + sum_food;
}else if(type.equals("水果")){
sum_fruit = record.getMoney() + sum_fruit;
}else if(type.equals("娛樂")){
sum_fun = record.getMoney() + sum_fun;
}else if(type.equals("日常")){
sum_daily = record.getMoney() + sum_daily;
}
}
tv_food.setText("¥" + sum_food);
tv_fruit.setText("¥" + sum_fruit);
tv_fun.setText("¥" + sum_fun);
tv_daily.setText("¥" + sum_daily);
}
4.4收入頁面

4.4.1添加收入(IncomeActivity)
class onclickListener implements OnClickListener {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.tv_cash:
tv_cash.setBackgroundColor(color.darker_gray);
Toast.makeText(IncomeActivity.this, "現金", Toast.LENGTH_SHORT)
.show();
type = "現金";
break;
case R.id.tv_card:
tv_card.setBackgroundColor(color.darker_gray);
Toast.makeText(IncomeActivity.this, "銀行卡", Toast.LENGTH_SHORT)
.show();
type = "銀行卡";
break;
case R.id.tv_alipay:
tv_alipay.setBackgroundColor(color.darker_gray);
Toast.makeText(IncomeActivity.this, "支付寶", Toast.LENGTH_SHORT)
.show();
type = "支付寶";
break;
case R.id.bt_ok:
boolean b = false;
if (null == et_money.getText().toString().trim()
|| et_money.getText().toString().trim().equals("")) {
Toast.makeText(IncomeActivity.this, "收入為0",
Toast.LENGTH_SHORT).show();
} else {
money = Double.parseDouble(et_money.getText().toString());
b = cid.IncomeCount(type, money);
if (b) {
Intent intent = new Intent(IncomeActivity.this,
MainActivity.class);
startActivity(intent);
IncomeActivity.this.finish();
}
}
break;
case R.id.bt_quit:
Intent intent1 = new Intent(IncomeActivity.this,
MainActivity.class);
startActivity(intent1);
IncomeActivity.this.finish();
break;
}
}
}
4.5更新用戶信息頁面

4.5.1修改賬戶資金(UpdateCountActivity)
public void toAdd(View v){
money = Double.parseDouble(et_money.getText().toString());
boolean b = false ;
b = cid.updateCount(type,money);
if(b){
Intent intent = new Intent(UpdateCountActivity.this,CountActivity.class);
startActivity(intent);
UpdateCountActivity.this.finish();
}
}
4.6我的賬戶頁面

4.6.1顯示賬戶信息
class onclickListener implements OnClickListener{
@Override
public void onClick(View v) {
Intent intent = new Intent(CountActivity.this,UpdateCountActivity.class);
switch(v.getId()){
case R.id.rl_cash:
intent.putExtra("type","現金");
startActivity(intent);
CountActivity.this.finish();
break;
case R.id.rl_card:
intent.putExtra("type","銀行卡");
startActivity(intent);
CountActivity.this.finish();
break;
case R.id.rl_alipay:
intent.putExtra("type","支付寶");
startActivity(intent);
CountActivity.this.finish();
break;
}
}
}
public void ListViewCount() {
// 獲取所有賬戶信息
cinfo = cid.find();
tv_cash.setText("¥"+cinfo.getCash());
tv_card.setText("¥"+cinfo.getCard()+"");
tv_alipay.setText("¥"+cinfo.getAlipay()+"");
}
public void toBack(View view){
Intent intent = new Intent(CountActivity.this,MainActivity.class);
startActivity(intent);
CountActivity.this.finish();
}
public void toIncome(View view){
Intent intent = new Intent(CountActivity.this,IncomeActivity.class);
startActivity(intent);
CountActivity.this.finish();
}
4.7對賬戶進行操作
4.7.1查找賬戶信息
public CountInfo find() {
SQLiteDatabase db = dbHelper.getReadableDatabase();
String sql = "select * from tbl_count where uid = 1001";
Cursor cursor = db.rawQuery(sql, null);
// 用一個list來存儲每一個GoodsInfo 對象的值
CountInfo list = new CountInfo();
while (cursor.moveToNext()) {
Double cash = cursor.getDouble(cursor.getColumnIndex("cash"));
Double card = cursor.getDouble(cursor.getColumnIndex("card"));
Double alipay = cursor.getDouble(cursor.getColumnIndex("alipay"));
list = new CountInfo(1001, cash, card, alipay);
}
db.close();
cursor.close();
return list;
}
4.7.2更新賬戶信息(購買后修改)
@Override
public boolean updateCount(RecordInfo record) {
if (null != record) {
// 獲取一個可寫入的數據庫
CountInfo count = find();
SQLiteDatabase db = dbHelper.getWritableDatabase();
String payway = record.getPayway().trim();
String sql = null;
double money = 0.0;
if (payway.equals("現金")) {
money = count.getCash();
sql = "update tbl_count set cash=? where uid=1001";
} else if (payway.equals("銀行卡")) {
money = count.getCard();
sql = "update tbl_count set card=? where uid=1001";
} else if (payway.equals("支付寶")) {
money = count.getAlipay();
sql = "update tbl_count set alipay=? where uid=1001";
}
money = money - record.getMoney();
db.execSQL(sql, new Object[] {money});
db.close();
return true;
} else {
return false;
}
}
4.7.3更新賬戶信息(直接修改賬戶信息)
public boolean updateCount(String type ,double money) {
if (null != type) {
// 獲取一個可寫入的數據庫
SQLiteDatabase db = dbHelper.getWritableDatabase();
String sql = null;
if (type.equals("現金")) {
sql = "update tbl_count set cash=? where uid=1001";
} else if (type.equals("銀行卡")) {
sql = "update tbl_count set card=? where uid=1001";
} else if (type.equals("支付寶")) {
sql = "update tbl_count set alipay=? where uid=1001";
}
db.execSQL(sql, new Object[] {money});
db.close();
return true;
} else {
return false;
}
}
4.7.4更新賬戶信息(添加收入)
@Override
public boolean IncomeCount(String type, double money) {
CountInfo count = find();
if (null != type) {
// 獲取一個可寫入的數據庫
SQLiteDatabase db = dbHelper.getWritableDatabase();
String sql = null;
if (type.equals("現金")) {
sql = "update tbl_count set cash=? where uid=1001";
money = count.getCash() + money;
} else if (type.equals("銀行卡")) {
sql = "update tbl_count set card=? where uid=1001";
money = count.getCard() + money;
} else if (type.equals("支付寶")) {
sql = "update tbl_count set alipay=? where uid=1001";
money = count.getAlipay() + money;
}
db.execSQL(sql, new Object[] {money});
db.close();
return true;
} else {
return false;
}
}
}
4.9初始化數據庫
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table if not exists tbl_users"
+ "(uid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , uname String ,"
+ "upwd String )");
db.execSQL("insert into tbl_users values (1001,'admin','admin')");
db.execSQL("create table if not exists tbl_admin"
+ "(rid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , type String ,"
+ "money Double ,payway String)");
db.execSQL("create table if not exists tbl_count"
+ "(cid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL , uid Integer, cash Double ,"
+ "card Double ,alipay Double)");
db.execSQL("insert into tbl_count values (1,1001,0,0,0)");
}
五、總結
這次的課程設計時間比較短,所以完成的項目也不算完美,不過還是自己本身的問題,在這個學期學習的並不好,基礎比較差。真正來做項目的時候就顯示出了自己的不足,很多都不懂,好多都是現學的。項目並不是很難,不過確實能學到很多東西。
在系統測試過程中,系統可以在模擬器和真機上正常運行這些功能,能夠滿足系統的基本要求。但是也能發現系統中存在的小缺陷,對於這些小缺陷,也盡力作了修改。另外,在界面美化和流程控制方面還有待優化,以提高用戶的體
