Skip to content

Commit

Permalink
实现恩格尔系数视图
Browse files Browse the repository at this point in the history
  • Loading branch information
guohuan78 committed Dec 17, 2022
1 parent ef79edb commit 974907c
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .idea/dictionaries/78121.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@

1. 尝试写一下大作业的报告,遇到问题有需要补充的再继续开发
2. 添加在固定时间指定备注的功能 √
3. 添加恩格尔系数视图
3. 添加恩格尔系数视图
4. 添加定时记账功能
5. 备份功能
6. 在记录界面添加点击弹出修改框可以修改备注的功能 √
24 changes: 24 additions & 0 deletions app/src/main/java/com/eb/easy_bookkeeping/SettingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public void onClick(View view) {
case R.id.setting_tv_clear:
showDeleteDialog();
break;
case R.id.setting_tv_engel:
showEngelCoefficient();
break;
}
}

Expand All @@ -43,4 +46,25 @@ public void onClick(DialogInterface dialog, int which) {
});
builder.create().show();
}

private void showEngelCoefficient() {
float engelCoefficient = DBManager.getEngelCoefficient();
String hint;
if (engelCoefficient < 0.3) {
hint = "最富裕!钱花不完可以多多打赏哦~";
} else if (engelCoefficient < 0.4) {
hint = "富裕~钱挣够了可以好好享受生活呀";
} else if (engelCoefficient < 0.5) {
hint = "小康,生活还是很滋润滴。";
} else if (engelCoefficient < 0.59) {
hint = "温饱,争取为全面建成小康社会贡献一份力量!";
} else {
hint = "贫困,脱贫攻坚战漏网之鱼嘛呜呜呜";
}
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("恩格尔系数为:")
.setMessage(String.format("%.3f", engelCoefficient) + "\n" + hint)
.setNegativeButton("确定", null);
builder.create().show();
}
}
14 changes: 14 additions & 0 deletions app/src/main/java/com/eb/easy_bookkeeping/db/DBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ public static void updateItemBeizhuFromAccounttbById(int id, String beizhu){
}
return list;
}
/**
* 获取恩格尔系数值
* */
public static float getEngelCoefficient(){
String sql = "select * from foodcostsumview";
Cursor cursor = db.rawQuery(sql, null);
cursor.moveToNext();
float foodcost = cursor.getFloat(cursor.getColumnIndex("foodcost"));
sql = "select sum(money) as sum from accounttb where kind = 0";
cursor = db.rawQuery(sql, null);
cursor.moveToNext();
float sum = cursor.getFloat(cursor.getColumnIndex("sum"));
return foodcost/sum;
}
/*
* 获取记账表当中某一月的所有支出或者收入情况
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public void onCreate(SQLiteDatabase db) {
sql = "create table accounttb(id integer primary key autoincrement,typename varchar(10),ImageId integer,beizhu varchar(80),money float," +
"time varchar(60),year integer,month integer,day integer,kind integer)";
db.execSQL(sql);
createFoodCostSumView(db);
}

private void createFoodCostSumView(SQLiteDatabase db) {
String sql = "create view foodcostsumview as select sum(money) as foodcost from accounttb where kind = 0 and typename in (select typename from typetb where id = 1 )";
db.execSQL(sql);
}

private void insertType(SQLiteDatabase db) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/activity_setting.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
android:textStyle="bold"
android:padding="15dp"
android:background="@color/white"/>
<TextView
android:id="@+id/setting_tv_engel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/engel_coefficient"
android:onClick="onClick"
android:textSize="16sp"
android:textStyle="bold"
android:padding="15dp"
android:background="@color/white"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

<string name="history_info">本月账单记录</string>
<string name="clear_all">清空所有记录</string>
<string name="engel_coefficient">恩格尔系数视图</string>

<!-- TODO: Remove or change this placeholder text -->
<string name="not_data">暂无数据</string>
Expand Down

0 comments on commit 974907c

Please sign in to comment.