zoukankan      html  css  js  c++  java
  • JAVA日报

    换汤不换药之家庭记账本app开发(dao)

    package dao;

    import android.content.ContentValues;
    import android.content.Context;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteDatabase;

    import java.util.ArrayList;
    import java.util.List;

    import bean.user;
    import sqlite.db;
    public class userdao {
    public double eat=0;
    public double play=0;
    public double clothes=0;
    public double live=0;
    public double usual=0;
    public double total=0;
    private final db Db;
    private static userdao userDao=null;
    private userdao(Context context){
    Db =new db(context);
    }
    public static userdao getInstance(Context context){
    if(userDao==null){
    userDao=new userdao(context);
    }
    return userDao;
    }
    public db getDb() {
    return Db;
    }
    //保存
    public void insert(user u){
    SQLiteDatabase db=Db.getWritableDatabase();
    ContentValues values=new ContentValues();
    values.put("date",u.get("date"));
    values.put("eat",u.get("eat"));
    values.put("play",u.get("play"));
    values.put("clothes",u.get("clothes"));
    values.put("live",u.get("live"));
    values.put("usual",u.get("usual"));
    db.insert("tex",null,values);
    db.close();
    }
    //获取
    public void delete(String id) {
    SQLiteDatabase db =Db.getWritableDatabase();
    if (db.isOpen()) {
    db.execSQL("delete from tex where date=?", new Object[]{id});
    db.close();
    }
    }//删除
    public List<user> findAll(){
    SQLiteDatabase db=Db.getWritableDatabase();
    Cursor cursor=db.query("tex",new String[]{"date","eat","play","clothes","live","usual"},null,null,null,null,null);
    List<user> userList=new ArrayList<>();
    while(cursor.moveToNext()){
    user u=new user();
    u.setDate(cursor.getString(0));
    u.setEat(cursor.getString(1));
    u.setPlay(cursor.getString(2));
    u.setClothes(cursor.getString(3));
    u.setLive(cursor.getString(4));
    u.setUsual(cursor.getString(5));
    //Log.e("sqliteshow",user.getName()+" "+user.getDate()+" "+user.getTime()+" "+user.getTem()+" "+user.getArea());
    userList.add(u);
    }
    total=eat+play+clothes+live+usual;
    db.close();
    return userList;
    }
    public void Initdata(){
    SQLiteDatabase db=Db.getWritableDatabase();
    Cursor cursor=db.query("tex",new String[]{"date","eat","play","clothes","live","usual"},null,null,null,null,null);
    while(cursor.moveToNext()){
    eat = eat + Double.valueOf(cursor.getString(1));
    play = play + Double.valueOf(cursor.getString(2));
    clothes = clothes + Double.valueOf(cursor.getString(3));
    live = live + Double.valueOf(cursor.getString(4));
    usual = usual + Double.valueOf(cursor.getString(5));
    }
    total=eat+play+clothes+live+usual;
    db.close();
    }
    public void clear(){
    eat=0;play=0;clothes=0;live=0;usual=0;total=0;
    }
    }
  • 相关阅读:
    vue----计算与监听属性
    vue---条件与循环语句
    vue--模板语法
    git版本控制系统--介绍
    HttpWebRequest使用总结
    计算机专业的书普遍都这么贵,你们都是怎么获取资源的?
    130 个相见恨晚的超实用网站,一次性分享出来
    实现客户端与服务端的HTTP通讯
    默认网关(地址)
    .NET Reactor使用教程(加密源代码示例)
  • 原文地址:https://www.cnblogs.com/mumulailai/p/14909766.html
Copyright © 2011-2022 走看看