• Android_小账本_筛选功能的实现


    昨天对小账本的相关功能做了完善,新增了筛选功能。

     支持对类型、收支项、日期进行修改。

     但暂时尚不完善,只能针对相关小项进行筛选,无法连续对小项的结果进行筛选。这一功能预计在本周三进行完善。

    相关代码

     public String[] readCord_select() {
            SQLiteUserChager sqLiteUserChager = new SQLiteUserChager(getContext(), "Userr", null, 1);
            SQLiteDatabase sqLiteDatabase = sqLiteUserChager.getReadableDatabase();
            number=0;
            if (group.length() < 3) {
                Cursor cursor;
                if (Integer.parseInt(group) == 1) {
                    cursor = sqLiteDatabase.rawQuery("select * from Cord where inout=? and username=?", new String[]{select[1][Integer.parseInt(item)],nowusername});
                } else {
                    cursor = sqLiteDatabase.rawQuery("select * from Cord where type=? and username=?", new String[]{select[2][Integer.parseInt(item)],nowusername});
                }
                String[] strings = new String[count = cursor.getCount()];
                int i = 0;
                if (cursor.moveToNext())
                    do {
                        number+=Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                        String[] strings1 = new String[7];
                        strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                        strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                        strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                        strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                        strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                        strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                        strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                        arr.add(strings1);
                        strings[i] = "我" + cursor.getString(cursor.getColumnIndex("date")) +
                                " 在" + cursor.getString(cursor.getColumnIndex("type")) +
                                "上" + cursor.getString(cursor.getColumnIndex("inout")) +
                                "了" + cursor.getString(cursor.getColumnIndex("number")) + "元";
                        i++;
                    } while (cursor.moveToNext());
                cursor.close();
                sqLiteDatabase.close();
                sqLiteUserChager.close();
                tv_sum.setText("总收支:"+number);
                return strings;
            } else {                                                                                     //dateselect
                String[] min = group.split("/");
                String[] max = item.split("/");
                Log.d("----max", max[0] + "/" + max[1] + "/" + max[2]);
                Log.d("----min", min[0] + "/" + min[1] + "/" + min[2]);
                Cursor cursor = sqLiteDatabase.rawQuery("select * from Cord where username=?", new String[]{nowusername});
                String[] strings = new String[cursor.getCount() + 8000];
                while (cursor.moveToNext()) {
                    String date = cursor.getString(cursor.getColumnIndex("date"));
                    String[] dats = date.split("/");
                    if (Integer.parseInt(dats[0]) > Integer.parseInt(min[0]) && Integer.parseInt(dats[0]) < Integer.parseInt(max[0])) {
                        String[] strings1 = new String[7];
                        number+=Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                        strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                        strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                        strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                        strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                        strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                        strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                        strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                        arr.add(strings1);
                        strings[i] = "我" + cursor.getString(cursor.getColumnIndex("date")) +
                                " 在" + cursor.getString(cursor.getColumnIndex("type")) +
                                "上" + cursor.getString(cursor.getColumnIndex("inout")) +
                                "了" + cursor.getString(cursor.getColumnIndex("number")) + "元";
                        i++;
                    } else if (Integer.parseInt(dats[0]) == Integer.parseInt(min[0])) {
                        if (Integer.parseInt(dats[1]) > Integer.parseInt(min[1]) && Integer.parseInt(dats[1]) < Integer.parseInt(max[1])) {
                            String[] strings1 = new String[7];
                            number+=Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                            strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                            strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                            strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                            strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                            strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                            strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                            strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                            arr.add(strings1);
                            strings[i] = "我" + cursor.getString(cursor.getColumnIndex("date")) +
                                    " 在" + cursor.getString(cursor.getColumnIndex("type")) +
                                    "上" + cursor.getString(cursor.getColumnIndex("inout")) +
                                    "了" + cursor.getString(cursor.getColumnIndex("number")) + "元";
                            i++;
                        } else if (Integer.parseInt(dats[1]) == Integer.parseInt(min[1])) {
                            if ((Integer.parseInt(dats[2]) >= Integer.parseInt(min[2]) && Integer.parseInt(dats[1]) < Integer.parseInt(max[1])) || (Integer.parseInt(dats[2]) >= Integer.parseInt(min[2]) && Integer.parseInt(dats[2]) <= Integer.parseInt(max[2]))) {
                                String[] strings1 = new String[7];
                                number+=Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                                strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                                strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                                strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                                strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                                strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                                strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                                strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                                arr.add(strings1);
                                strings[i] = "我" + cursor.getString(cursor.getColumnIndex("date")) +
                                        " 在" + cursor.getString(cursor.getColumnIndex("type")) +
                                        "上" + cursor.getString(cursor.getColumnIndex("inout")) +
                                        "了" + cursor.getString(cursor.getColumnIndex("number")) + "元";
                                i++;
                            }
                        } else if (Integer.parseInt(dats[1]) == Integer.parseInt(max[1])) {
                            if ((Integer.parseInt(dats[2]) <= Integer.parseInt(max[2]) && Integer.parseInt(dats[1]) > Integer.parseInt(min[1])) || (Integer.parseInt(dats[2]) >= Integer.parseInt(min[2]) && Integer.parseInt(dats[2]) <= Integer.parseInt(max[2]))) {
                                String[] strings1 = new String[7];
                                number+=Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                                strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                                strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                                strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                                strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                                strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                                strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                                strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                                arr.add(strings1);
                                strings[i] = "我" + cursor.getString(cursor.getColumnIndex("date")) +
                                        " 在" + cursor.getString(cursor.getColumnIndex("type")) +
                                        "上" + cursor.getString(cursor.getColumnIndex("inout")) +
                                        "了" + cursor.getString(cursor.getColumnIndex("number")) + "元";
                                i++;
                            }
                        }
                    } else if (Integer.parseInt(dats[0]) == Integer.parseInt(max[0])) {
                        if (Integer.parseInt(dats[1]) < Integer.parseInt(max[1])) {
                            String[] strings1 = new String[7];
                            number+=Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                            strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                            strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                            strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                            strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                            strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                            strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                            strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                            arr.add(strings1);
                            strings[i] = "我" + cursor.getString(cursor.getColumnIndex("date")) +
                                    " 在" + cursor.getString(cursor.getColumnIndex("type")) +
                                    "上" + cursor.getString(cursor.getColumnIndex("inout")) +
                                    "了" + cursor.getString(cursor.getColumnIndex("number")) + "元";
                            i++;
                        } else if (Integer.parseInt(dats[1]) == Integer.parseInt(max[1])) {
                            if (Integer.parseInt(dats[2]) <= Integer.parseInt(max[2])) {
                                String[] strings1 = new String[7];
                                number+=Double.parseDouble(cursor.getString(cursor.getColumnIndex("number")));
                                strings1[0] = cursor.getString(cursor.getColumnIndex("date"));
                                strings1[1] = cursor.getString(cursor.getColumnIndex("type"));
                                strings1[2] = cursor.getString(cursor.getColumnIndex("inout"));
                                strings1[3] = cursor.getString(cursor.getColumnIndex("number"));
                                strings1[4] = cursor.getString(cursor.getColumnIndex("info"));
                                strings1[5] = cursor.getString(cursor.getColumnIndex("username"));
                                strings1[6] = cursor.getString(cursor.getColumnIndex("id"));
                                arr.add(strings1);
                                strings[i] = "我" + cursor.getString(cursor.getColumnIndex("date")) +
                                        " 在" + cursor.getString(cursor.getColumnIndex("type")) +
                                        "上" + cursor.getString(cursor.getColumnIndex("inout")) +
                                        "了" + cursor.getString(cursor.getColumnIndex("number")) + "元";
                                i++;
                            }
                        }
                    }
                }
                cursor.close();
                sqLiteDatabase.close();
                sqLiteUserChager.close();
                ArrayList<String> arrayList = new ArrayList<>();
                for (int i = 0; i < strings.length; i++) {
                    if (strings[i] != null) {
                        arrayList.add(strings[i]);
                    }
                }
                String[] strings2 = new String[arrayList.size()];
                for (int i = 0; i < arrayList.size(); i++) {
                    strings2[i] = arrayList.get(i);
                }
                Log.d("-----gropuitem", group + "+" + item);
                tv_sum.setText("总收支:"+number);
                return strings2;
            }
    
        }
    

      

  • 相关阅读:
    白话LINQ系列2以代码演进方式学习LINQ必备条件
    《Entity Framework 6 Recipes》中文翻译系列 (9) 第二章 实体数据建模基础之继承关系映射TPH
    Linq To Sqlite 一一二二
    《Entity Framework 6 Recipes》中文翻译系列 (10) 第二章 实体数据建模基础之两实体间Isa和Hasa关系建模、嵌入值映射
    《Entity Framework 6 Recipes》中文翻译系列 (14) 第三章 查询之查询中设置默认值和存储过程返回多结果集
    《Entity Framework 6 Recipes》中文翻译系列 (13) 第三章 查询之使用Entity SQL
    白话LINQ系列1什么是LINQ?
    《Entity Framework 6 Recipes》翻译系列 (3) 第二章 实体数据建模基础之创建一个简单的模型
    JS 实现trim()
    mysql表切换引擎的几种方法
  • 原文地址:https://www.cnblogs.com/XiaoGao128/p/12350078.html
Copyright © 2020-2023  润新知