admin
2022-08-09 399ac289f80b7a40aa4210341db6b447cacdcf14
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.tejia.lijin.app.sqlite;
 
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
 
import com.wpc.library.util.common.StringUtils;
 
/**
 * 首页弹框+配置信息
 */
public class UserSQHelper {
    private SQLiteDatabase db;
    private CustomServiceSQLiteOpenHelper openHelper;
 
    public UserSQHelper(Context context) {
        openHelper = new CustomServiceSQLiteOpenHelper(context);
    }
 
    /**
     * 查询数据
     *
     * @param id
     * @return
     */
    public String getShowTime(String id, String Inquire) {
        if (StringUtils.isEmpty(id))
            return "";
        db = openHelper.getWritableDatabase();//以读写的方式访问数据库
        Cursor cursor = db.rawQuery("select * from user_table where adid=?", new String[]{id});
        String t = "";
        if (cursor.getCount() != 0) {
            while (cursor.moveToNext()) { //遍历数据库
                t = cursor.getString(cursor.getColumnIndex(Inquire));
            }
        }
        cursor.close();//关闭cursor
        db.close();// 关闭数据库
        Log.e("eee", "getShowTime: " + t);
        return t;
    }
 
//    /**
//     * 设置数据
//     *
//     * @param id
//     * @param time
//     */
//    public boolean setShowTime(String id, String time) {
//        if (StringUtils.isEmpty(id) || StringUtils.isEmpty(time))
//            return false;
//        boolean b = true;
//        //更具ID查询有这条数据
//        if (getShowTime(id) != null && getShowTime(id).length() > 0) {
//            b = update(id, time);//更新信息
//        } else {
//            b = insert(id, time);//插入数据
//        }
//        return b;
//    }
 
    /**
     * 插入数据
     *
     * @param id
     * @param time
     */
    private boolean insertsharecheck(String id, String time) {
        if (StringUtils.isEmpty(id) || StringUtils.isEmpty(time))
            return false;
        db = openHelper.getWritableDatabase();//以读写的方式访问数据库
        ContentValues value = new ContentValues();
        value.put("defaultid", id);
        value.put("sharecheck", time);
        db.insert("user_table", null, value);
        db.close();// 关闭数据库
        return true;
    }
 
    /**
     * 更新数据
     *
     * @param id
     * @param time
     */
    private boolean updatesharecheck(String id, String time) {
        if (StringUtils.isEmpty(id) || StringUtils.isEmpty(time))
            return false;
        db = openHelper.getWritableDatabase();//以读写的方式访问数据库
        ContentValues value = new ContentValues();
        value.put("defaultid", id);
        value.put("sharecheck", time);
        db.update("user_table", value, "defaultid=?", new String[]{id});
        db.close();// 关闭数据库
        return true;
    }
}