今日计划
继续app的开发
今日完成情况
- 主页面的头部控件可以实时更新数据
在数据库管理类中加入获取支出或收入总金额的方法:
/**
* 获取某一天的支出或者收入的总金额 kind:支出==0 收入==1
*/
public static float getSumMoneyOneDay(int year,int month, int day,int kind) {
float total = 0.0f;
String sql = "select sum(money) from accounttb where year=? and month=? and day = ? and kind=?";
Cursor cursor = db.rawQuery(sql, new String[]{year + "", month + "", day + "", kind + ""});
//遍历
if (cursor.moveToFirst()){
float money = cursor.getFloat(cursor.getColumnIndex("sum(money)"));
total = money;
}
return total;
}
/**
* 获取某一月的支出或者收入的总金额 kind:支出==0 收入==1
*/
public static float getSumMoneyOneMonth(int year,int month, int kind) {
float total = 0.0f;
String sql = "select sum(money) from accounttb where year=? and month=? and kind=?";
Cursor cursor = db.rawQuery(sql, new String[]{year + "", month + "", kind + ""});
//遍历
if (cursor.moveToFirst()){
float money = cursor.getFloat(cursor.getColumnIndex("sum(money)"));
total = money;
}
return total;
}
/**
* 获取某一年的支出或者收入的总金额 kind:支出==0 收入==1
*/
public static float getSumMoneyOneYear(int year,int kind) {
float total = 0.0f;
String sql = "select sum(money) from accounttb where year=? and kind=?";
Cursor cursor = db.rawQuery(sql, new String[]{year + "", kind + ""});
//遍历
if (cursor.moveToFirst()){
float money = cursor.getFloat(cursor.getColumnIndex("sum(money)"));
total = money;
}
return total;
}
在MainActivity中加入如下头部数据更新代码:
/**
* 设置头布局当中文本内容的更新
*/
private void setTopTvShow() {
//获取今日支出和收入总金额,显示在view中
float incomeOneDay = DBManger.getSumMoneyOneDay(year, month, day, 1);
float outcomeOneDay = DBManger.getSumMoneyOneDay(year, month, day, 0);
String infoOneDay = "今日支出 ¥"+ outcomeOneDay + " 收入 ¥" +incomeOneDay;
topConTv.setText(infoOneDay);
//获取本月支出和收入总金额
float incomeOneMonth = DBManger.getSumMoneyOneMonth(year, month, 1);
float outcomeOneMonth = DBManger.getSumMoneyOneMonth(year, month, 0);
topInTv.setText("¥ " + incomeOneMonth);
topOutTv.setText("¥ " + outcomeOneMonth);
//设置显示预算剩余