2021/5/19 工作日报 -- 简约记账app -- day4

今日计划

继续app的开发

今日完成情况

  1. 主页面的头部控件可以实时更新数据
    头部控件可以实时更新数据
    在数据库管理类中加入获取支出或收入总金额的方法:
/**
     * 获取某一天的支出或者收入的总金额  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);
        //设置显示预算剩余
   
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值