• 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;
    }
    }
  • 相关阅读:
    台湾大学李宏毅机器学习教程
    自编码器AE & 变分自编码器VAE
    深度信念网络(DBN)和堆叠自编码(SAE)、深度自编码器(DAE)的区别
    花式自动编码器
    迁移和域自适应
    MMD :maximum mean discrepancy
    数据可视化工具t-SNE
    线性判别分析(LDA)
    弱监督学习
    如何生成不重复的随机数
  • 原文地址:https://www.cnblogs.com/mumulailai/p/14909766.html
Copyright © 2020-2023  润新知