第二阶段冲刺-10

昨天制作了一个自定义的控件,可以实现,对时间的ViewText进行侦听,当点击时弹出自定义框,选择获取,年月日,并更改数据库方法

遇到的问题:所用的数据库查询方法使用不够熟悉,只能通过查询出结果之后通过if语句进行处理。

今天打算做:对项目进行整合,将所有实现的功能加入到项目中。

 public void showDateDialog() {
        mView = View.inflate(this, R.layout.date_dialog, null);

        np1 = (NumberPicker) mView.findViewById(R.id.np1);
        np2 = (NumberPicker) mView.findViewById(R.id.np2);

        //获取当前日期
        Calendar c = Calendar.getInstance();
//
        final int year =  c.get(Calendar.YEAR);
        final int month1 = c.get(Calendar.MONTH)+1;//月份是从0开始算的
//        final int day = c.get(Calendar.DAY_OF_MONTH);
        //获取当前的记账日期


        //设置年份
        np1.setMaxValue(2999);
        np1.setValue(year); //中间参数 设置默认值
        np1.setMinValue(2000);



        //设置月份
        np2.setMaxValue(12);
        np2.setValue(month1);
        np2.setMinValue(1);







        new AlertDialog.Builder(MainActivity.this).setTitle("请选择时间")
                .setView(mView)
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        int months = np2.getValue();

                        month.setText( year + "年"+months + "月" );
                        dialog.dismiss();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                })
                .show();
    }

    public float Query(String year1,String month,String type1) {
        db = helper_person.getWritableDatabase();
        float m =0;
        Cursor cursor = db.query("student", null, "month=?",new String[]{month}, null, null, null);
        while (cursor.moveToNext()) {

            String money = cursor.getString(2);
            String type = cursor.getString(3);
            String year = cursor.getString(4);
            if (year.equals(year1))
            {
                if (type.equals(type1))
                {
                    m = Float.parseFloat(money);
                }
            }
        }
        db.close();
        return m;
    }