qvyuanxin
2017-07-20 2212d9561ccbdc6141be2e36393d01e4bba0f743
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package cn.com.basic.face.service.sqlite;
 
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
 
import java.util.ArrayList;
import java.util.List;
 
import cn.com.basic.face.base.Config;
import cn.com.basic.face.discern.common.CommonVariables;
import cn.com.basic.face.discern.entity.Dictionary;
 
/**
 * 数据字典Dao
 */
public class DictionaryDao {
 
    public static DictionaryDao instance = new DictionaryDao();
    public static DictionaryDao getInstance() {
        return instance;
    }
    private  static StringBuffer sb = new StringBuffer("select dict_id, name from dictionary ");
 
 
 
    private  static  List<Dictionary>load(String type){
        List<Dictionary> list = new ArrayList<Dictionary>();
        SQLiteDatabase db = Config.sqlMap.getDb();
        db.beginTransaction();
        try {
            sb.append("where 1 = 1 and type = ");
            sb.append(type);
            Dictionary aqi = null;
            Cursor c = db.rawQuery(sb.toString(), new String[]{});
            while (c.moveToNext()) {
                aqi = new Dictionary();
                aqi.setDictId(c.getString(c.getColumnIndex("dict_id")));
                aqi.setName(c.getString((c.getColumnIndex("name"))));
                list.add(aqi);
            }
            c.close();
            db.setTransactionSuccessful();
        }catch (Exception e) {
            e.printStackTrace();
        }finally {
            db.endTransaction();
            if(db!=null){
                db.close();
            }
        }
        return list;
    }
 
    /**
     * 加载国家
     * @return
     */
    public List<Dictionary> loadCountries() {
 
         return   load(CommonVariables.DictionaryType.COUNTRY);
    }
 
    /**
     * 加载证件类型
     * @return
     */
    public List<Dictionary> loadIdTypeList() {
 
        return   load(CommonVariables.DictionaryType.ID_TYPE);
 
    }
 
    /**
     * 加载性别
     * @return
     */
    public List<Dictionary> loadGenderList() {
        return   load(CommonVariables.DictionaryType.GENDER);
    }
 
    /**
     * 加载访问事由
     * @return
     */
    public List<Dictionary> loadVisitReasonList() {
        return   load(CommonVariables.DictionaryType.VISIT_REASON);
    }
 
    /**
     * 加载分辨率
     * @return
     */
    public List<Dictionary> loadResolutionList() {
        return   load(CommonVariables.DictionaryType.RESOLUTION);
    }
 
    /**
     * 加载通讯协议
     * @return
     */
    public List<Dictionary> loadProtocolList() {
        return   load(CommonVariables.DictionaryType.PROTOCOL);
    }
 
    /**
     * 加载摄像机品牌
     * @return
     */
    public List<Dictionary> loadCameraBrandList() {
        return   load(CommonVariables.DictionaryType.CAMERA_BRAND);
    }
 
    /**
     * 加载访客类型
     * @return
     */
    public List<Dictionary> loadVisitorTypeList() {
        return   load(CommonVariables.DictionaryType.VISITOR_TYPE);
    }
 
    public List<Dictionary> addDictionary(String type, String name) {
        return   load(CommonVariables.DictionaryType.COUNTRY);
    }
 
 
    /**
     * 加载考勤类型
     * @return
     */
    public List<Dictionary> loadAttenderTypeList() {
        return   load(CommonVariables.DictionaryType.ATTENDER_TYPE);
    }
 
}