Browse Source

账单表提交

Xieshengqi 7 years ago
parent
commit
e9dafd240f

+ 3 - 1
.idea/misc.xml

@@ -24,5 +24,7 @@
24 24
       </value>
25 25
     </option>
26 26
   </component>
27
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK" />
27
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK">
28
+    <output url="file://$PROJECT_DIR$/build/classes" />
29
+  </component>
28 30
 </project>

+ 1 - 0
.idea/modules.xml

@@ -3,6 +3,7 @@
3 3
   <component name="ProjectModuleManager">
4 4
     <modules>
5 5
       <module fileurl="file://$PROJECT_DIR$/MoneyMoreMoreNote.iml" filepath="$PROJECT_DIR$/MoneyMoreMoreNote.iml" />
6
+      <module fileurl="file://$PROJECT_DIR$/MoneyNote.iml" filepath="$PROJECT_DIR$/MoneyNote.iml" />
6 7
       <module fileurl="file://$PROJECT_DIR$/MoneyNote_Sqlite/MoneyNote_Sqlite.iml" filepath="$PROJECT_DIR$/MoneyNote_Sqlite/MoneyNote_Sqlite.iml" />
7 8
       <module fileurl="file://E:\moneymoremorenote\MoneyMoreMoreNote\MoneyNote_Sqlite\MoneyNote_Sqlite.iml" filepath="E:\moneymoremorenote\MoneyMoreMoreNote\MoneyNote_Sqlite\MoneyNote_Sqlite.iml" />
8 9
       <module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />

+ 174 - 0
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/dao/CategoryDBDao.java

@@ -0,0 +1,174 @@
1
+package com.kuxuan.sqlite.dao;
2
+
3
+import android.database.Cursor;
4
+import android.database.sqlite.SQLiteStatement;
5
+
6
+import org.greenrobot.greendao.AbstractDao;
7
+import org.greenrobot.greendao.Property;
8
+import org.greenrobot.greendao.internal.DaoConfig;
9
+import org.greenrobot.greendao.database.Database;
10
+import org.greenrobot.greendao.database.DatabaseStatement;
11
+
12
+import com.kuxuan.sqlite.db.CategoryDB;
13
+
14
+// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
15
+/** 
16
+ * DAO for table "CATEGORY_DB".
17
+*/
18
+public class CategoryDBDao extends AbstractDao<CategoryDB, Void> {
19
+
20
+    public static final String TABLENAME = "CATEGORY_DB";
21
+
22
+    /**
23
+     * Properties of entity CategoryDB.<br/>
24
+     * Can be used for QueryBuilder and for referencing column names.
25
+     */
26
+    public static class Properties {
27
+        public final static Property Bill_id = new Property(0, long.class, "bill_id", false, "BILL_ID");
28
+        public final static Property Demo = new Property(1, String.class, "demo", false, "DEMO");
29
+        public final static Property Name = new Property(2, String.class, "name", false, "NAME");
30
+        public final static Property Type = new Property(3, int.class, "type", false, "TYPE");
31
+        public final static Property Account = new Property(4, long.class, "account", false, "ACCOUNT");
32
+        public final static Property Category_id = new Property(5, int.class, "category_id", false, "CATEGORY_ID");
33
+        public final static Property Year = new Property(6, int.class, "year", false, "YEAR");
34
+        public final static Property Month = new Property(7, int.class, "month", false, "MONTH");
35
+        public final static Property Day = new Property(8, int.class, "day", false, "DAY");
36
+        public final static Property User_id = new Property(9, int.class, "user_id", false, "USER_ID");
37
+    }
38
+
39
+
40
+    public CategoryDBDao(DaoConfig config) {
41
+        super(config);
42
+    }
43
+    
44
+    public CategoryDBDao(DaoConfig config, DaoSession daoSession) {
45
+        super(config, daoSession);
46
+    }
47
+
48
+    /** Creates the underlying database table. */
49
+    public static void createTable(Database db, boolean ifNotExists) {
50
+        String constraint = ifNotExists? "IF NOT EXISTS ": "";
51
+        db.execSQL("CREATE TABLE " + constraint + "\"CATEGORY_DB\" (" + //
52
+                "\"BILL_ID\" INTEGER NOT NULL UNIQUE ," + // 0: bill_id
53
+                "\"DEMO\" TEXT," + // 1: demo
54
+                "\"NAME\" TEXT," + // 2: name
55
+                "\"TYPE\" INTEGER NOT NULL ," + // 3: type
56
+                "\"ACCOUNT\" INTEGER NOT NULL ," + // 4: account
57
+                "\"CATEGORY_ID\" INTEGER NOT NULL ," + // 5: category_id
58
+                "\"YEAR\" INTEGER NOT NULL ," + // 6: year
59
+                "\"MONTH\" INTEGER NOT NULL ," + // 7: month
60
+                "\"DAY\" INTEGER NOT NULL ," + // 8: day
61
+                "\"USER_ID\" INTEGER NOT NULL );"); // 9: user_id
62
+    }
63
+
64
+    /** Drops the underlying database table. */
65
+    public static void dropTable(Database db, boolean ifExists) {
66
+        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"CATEGORY_DB\"";
67
+        db.execSQL(sql);
68
+    }
69
+
70
+    @Override
71
+    protected final void bindValues(DatabaseStatement stmt, CategoryDB entity) {
72
+        stmt.clearBindings();
73
+        stmt.bindLong(1, entity.getBill_id());
74
+ 
75
+        String demo = entity.getDemo();
76
+        if (demo != null) {
77
+            stmt.bindString(2, demo);
78
+        }
79
+ 
80
+        String name = entity.getName();
81
+        if (name != null) {
82
+            stmt.bindString(3, name);
83
+        }
84
+        stmt.bindLong(4, entity.getType());
85
+        stmt.bindLong(5, entity.getAccount());
86
+        stmt.bindLong(6, entity.getCategory_id());
87
+        stmt.bindLong(7, entity.getYear());
88
+        stmt.bindLong(8, entity.getMonth());
89
+        stmt.bindLong(9, entity.getDay());
90
+        stmt.bindLong(10, entity.getUser_id());
91
+    }
92
+
93
+    @Override
94
+    protected final void bindValues(SQLiteStatement stmt, CategoryDB entity) {
95
+        stmt.clearBindings();
96
+        stmt.bindLong(1, entity.getBill_id());
97
+ 
98
+        String demo = entity.getDemo();
99
+        if (demo != null) {
100
+            stmt.bindString(2, demo);
101
+        }
102
+ 
103
+        String name = entity.getName();
104
+        if (name != null) {
105
+            stmt.bindString(3, name);
106
+        }
107
+        stmt.bindLong(4, entity.getType());
108
+        stmt.bindLong(5, entity.getAccount());
109
+        stmt.bindLong(6, entity.getCategory_id());
110
+        stmt.bindLong(7, entity.getYear());
111
+        stmt.bindLong(8, entity.getMonth());
112
+        stmt.bindLong(9, entity.getDay());
113
+        stmt.bindLong(10, entity.getUser_id());
114
+    }
115
+
116
+    @Override
117
+    public Void readKey(Cursor cursor, int offset) {
118
+        return null;
119
+    }    
120
+
121
+    @Override
122
+    public CategoryDB readEntity(Cursor cursor, int offset) {
123
+        CategoryDB entity = new CategoryDB( //
124
+            cursor.getLong(offset + 0), // bill_id
125
+            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // demo
126
+            cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2), // name
127
+            cursor.getInt(offset + 3), // type
128
+            cursor.getLong(offset + 4), // account
129
+            cursor.getInt(offset + 5), // category_id
130
+            cursor.getInt(offset + 6), // year
131
+            cursor.getInt(offset + 7), // month
132
+            cursor.getInt(offset + 8), // day
133
+            cursor.getInt(offset + 9) // user_id
134
+        );
135
+        return entity;
136
+    }
137
+     
138
+    @Override
139
+    public void readEntity(Cursor cursor, CategoryDB entity, int offset) {
140
+        entity.setBill_id(cursor.getLong(offset + 0));
141
+        entity.setDemo(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
142
+        entity.setName(cursor.isNull(offset + 2) ? null : cursor.getString(offset + 2));
143
+        entity.setType(cursor.getInt(offset + 3));
144
+        entity.setAccount(cursor.getLong(offset + 4));
145
+        entity.setCategory_id(cursor.getInt(offset + 5));
146
+        entity.setYear(cursor.getInt(offset + 6));
147
+        entity.setMonth(cursor.getInt(offset + 7));
148
+        entity.setDay(cursor.getInt(offset + 8));
149
+        entity.setUser_id(cursor.getInt(offset + 9));
150
+     }
151
+    
152
+    @Override
153
+    protected final Void updateKeyAfterInsert(CategoryDB entity, long rowId) {
154
+        // Unsupported or missing PK type
155
+        return null;
156
+    }
157
+    
158
+    @Override
159
+    public Void getKey(CategoryDB entity) {
160
+        return null;
161
+    }
162
+
163
+    @Override
164
+    public boolean hasKey(CategoryDB entity) {
165
+        // TODO
166
+        return false;
167
+    }
168
+
169
+    @Override
170
+    protected final boolean isEntityUpdateable() {
171
+        return true;
172
+    }
173
+    
174
+}

+ 3 - 0
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/dao/DaoMaster.java

@@ -22,11 +22,13 @@ public class DaoMaster extends AbstractDaoMaster {
22 22
     /** Creates underlying database table using DAOs. */
23 23
     public static void createAllTables(Database db, boolean ifNotExists) {
24 24
         TestDao.createTable(db, ifNotExists);
25
+        CategoryDBDao.createTable(db, ifNotExists);
25 26
     }
26 27
 
27 28
     /** Drops underlying database table using DAOs. */
28 29
     public static void dropAllTables(Database db, boolean ifExists) {
29 30
         TestDao.dropTable(db, ifExists);
31
+        CategoryDBDao.dropTable(db, ifExists);
30 32
     }
31 33
 
32 34
     /**
@@ -46,6 +48,7 @@ public class DaoMaster extends AbstractDaoMaster {
46 48
     public DaoMaster(Database db) {
47 49
         super(db, SCHEMA_VERSION);
48 50
         registerDaoClass(TestDao.class);
51
+        registerDaoClass(CategoryDBDao.class);
49 52
     }
50 53
 
51 54
     public DaoSession newSession() {

+ 14 - 0
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/dao/DaoSession.java

@@ -9,8 +9,10 @@ import org.greenrobot.greendao.identityscope.IdentityScopeType;
9 9
 import org.greenrobot.greendao.internal.DaoConfig;
10 10
 
11 11
 import com.kuxuan.sqlite.db.Test;
12
+import com.kuxuan.sqlite.db.CategoryDB;
12 13
 
13 14
 import com.kuxuan.sqlite.dao.TestDao;
15
+import com.kuxuan.sqlite.dao.CategoryDBDao;
14 16
 
15 17
 // THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
16 18
 
@@ -22,8 +24,10 @@ import com.kuxuan.sqlite.dao.TestDao;
22 24
 public class DaoSession extends AbstractDaoSession {
23 25
 
24 26
     private final DaoConfig testDaoConfig;
27
+    private final DaoConfig categoryDBDaoConfig;
25 28
 
26 29
     private final TestDao testDao;
30
+    private final CategoryDBDao categoryDBDao;
27 31
 
28 32
     public DaoSession(Database db, IdentityScopeType type, Map<Class<? extends AbstractDao<?, ?>>, DaoConfig>
29 33
             daoConfigMap) {
@@ -32,17 +36,27 @@ public class DaoSession extends AbstractDaoSession {
32 36
         testDaoConfig = daoConfigMap.get(TestDao.class).clone();
33 37
         testDaoConfig.initIdentityScope(type);
34 38
 
39
+        categoryDBDaoConfig = daoConfigMap.get(CategoryDBDao.class).clone();
40
+        categoryDBDaoConfig.initIdentityScope(type);
41
+
35 42
         testDao = new TestDao(testDaoConfig, this);
43
+        categoryDBDao = new CategoryDBDao(categoryDBDaoConfig, this);
36 44
 
37 45
         registerDao(Test.class, testDao);
46
+        registerDao(CategoryDB.class, categoryDBDao);
38 47
     }
39 48
     
40 49
     public void clear() {
41 50
         testDaoConfig.clearIdentityScope();
51
+        categoryDBDaoConfig.clearIdentityScope();
42 52
     }
43 53
 
44 54
     public TestDao getTestDao() {
45 55
         return testDao;
46 56
     }
47 57
 
58
+    public CategoryDBDao getCategoryDBDao() {
59
+        return categoryDBDao;
60
+    }
61
+
48 62
 }

+ 202 - 0
MoneyNote_Sqlite/src/main/java/com/kuxuan/sqlite/db/CategoryDB.java

@@ -0,0 +1,202 @@
1
+package com.kuxuan.sqlite.db;
2
+
3
+import org.greenrobot.greendao.annotation.Entity;
4
+import org.greenrobot.greendao.annotation.Unique;
5
+import org.greenrobot.greendao.annotation.Generated;
6
+
7
+/**
8
+ * Created by xieshengqi on 2018/3/27.
9
+ */
10
+@Entity
11
+public class CategoryDB {
12
+
13
+
14
+
15
+
16
+
17
+    /*
18
+  bill_id  long  账单id(唯一主键)
19
+ demo  String  账单备注
20
+ name  String  账单名字
21
+ type  int     账单类型(收入还是支出)
22
+ accout  long  账单金额
23
+ category_id   类别id
24
+ year  int     账单年
25
+ month  int    账单月
26
+ day    int    账单日
27
+ user_id  int  用户id
28
+    * */
29
+    /***
30
+     * 账单id(唯一)
31
+     */
32
+    @Unique
33
+    private long bill_id;
34
+
35
+
36
+    /**
37
+     * 账单备注
38
+     */
39
+    private String demo;
40
+
41
+    /**
42
+     * 账单名字
43
+     */
44
+    private String name;
45
+
46
+
47
+    /**
48
+     * 账单类型(收入还是支出)
49
+     */
50
+    private int type;
51
+
52
+    /**
53
+     * 账单金额
54
+     */
55
+    private long account;
56
+
57
+    /**
58
+     * 类别id
59
+     */
60
+    private int category_id;
61
+
62
+    /**
63
+     * 账单年
64
+     */
65
+    private int year;
66
+    /**
67
+     * 账单月
68
+     */
69
+    private int month;
70
+    /**
71
+     * 账单日
72
+     */
73
+    private int day;
74
+
75
+
76
+    /**
77
+     * 账单用户id
78
+     */
79
+    private int user_id;
80
+
81
+
82
+    @Generated(hash = 312190513)
83
+    public CategoryDB(long bill_id, String demo, String name, int type,
84
+            long account, int category_id, int year, int month, int day,
85
+            int user_id) {
86
+        this.bill_id = bill_id;
87
+        this.demo = demo;
88
+        this.name = name;
89
+        this.type = type;
90
+        this.account = account;
91
+        this.category_id = category_id;
92
+        this.year = year;
93
+        this.month = month;
94
+        this.day = day;
95
+        this.user_id = user_id;
96
+    }
97
+
98
+
99
+    @Generated(hash = 2085389353)
100
+    public CategoryDB() {
101
+    }
102
+
103
+
104
+    public long getBill_id() {
105
+        return this.bill_id;
106
+    }
107
+
108
+
109
+    public void setBill_id(long bill_id) {
110
+        this.bill_id = bill_id;
111
+    }
112
+
113
+
114
+    public String getDemo() {
115
+        return this.demo;
116
+    }
117
+
118
+
119
+    public void setDemo(String demo) {
120
+        this.demo = demo;
121
+    }
122
+
123
+
124
+    public String getName() {
125
+        return this.name;
126
+    }
127
+
128
+
129
+    public void setName(String name) {
130
+        this.name = name;
131
+    }
132
+
133
+
134
+    public int getType() {
135
+        return this.type;
136
+    }
137
+
138
+
139
+    public void setType(int type) {
140
+        this.type = type;
141
+    }
142
+
143
+
144
+    public long getAccount() {
145
+        return this.account;
146
+    }
147
+
148
+
149
+    public void setAccount(long account) {
150
+        this.account = account;
151
+    }
152
+
153
+
154
+    public int getCategory_id() {
155
+        return this.category_id;
156
+    }
157
+
158
+
159
+    public void setCategory_id(int category_id) {
160
+        this.category_id = category_id;
161
+    }
162
+
163
+
164
+    public int getYear() {
165
+        return this.year;
166
+    }
167
+
168
+
169
+    public void setYear(int year) {
170
+        this.year = year;
171
+    }
172
+
173
+
174
+    public int getMonth() {
175
+        return this.month;
176
+    }
177
+
178
+
179
+    public void setMonth(int month) {
180
+        this.month = month;
181
+    }
182
+
183
+
184
+    public int getDay() {
185
+        return this.day;
186
+    }
187
+
188
+
189
+    public void setDay(int day) {
190
+        this.day = day;
191
+    }
192
+
193
+
194
+    public int getUser_id() {
195
+        return this.user_id;
196
+    }
197
+
198
+
199
+    public void setUser_id(int user_id) {
200
+        this.user_id = user_id;
201
+    }
202
+}

+ 66 - 0
app/src/main/java/com/kuxuan/moneynote/db/DbManager.java

@@ -0,0 +1,66 @@
1
+package com.kuxuan.moneynote.db;
2
+
3
+import android.content.Context;
4
+
5
+import com.kuxuan.moneynote.MyApplication;
6
+import com.kuxuan.sqlite.dao.DaoMaster;
7
+import com.kuxuan.sqlite.dao.DaoSession;
8
+
9
+
10
+/**
11
+ *
12
+ * @author xieshengqi
13
+ * @date 2017/12/19
14
+ */
15
+
16
+public class DbManager {
17
+
18
+    private DaoMaster mDaoMaster;
19
+    private DaoSession mDaoSession;
20
+    private static Context mContext;
21
+
22
+    private DbManager() {
23
+        init();
24
+    }
25
+
26
+    /**
27
+     * 静态内部类,实例化对象使用
28
+     */
29
+    private static class SingleInstanceHolder {
30
+        private static final DbManager INSTANCE = new DbManager();
31
+    }
32
+
33
+    /**
34
+     * 对外唯一实例的接口
35
+     *
36
+     * @return
37
+     */
38
+    public static DbManager getInstance() {
39
+        return SingleInstanceHolder.INSTANCE;
40
+    }
41
+
42
+    /**
43
+     * 初始化数据
44
+     */
45
+    private void init() {
46
+        DaoMaster.DevOpenHelper devOpenHelper = new DaoMaster.DevOpenHelper(MyApplication.getInstance(),
47
+                "moneynote");
48
+        mDaoMaster = new DaoMaster(devOpenHelper.getWritableDatabase());
49
+        mDaoSession = mDaoMaster.newSession();
50
+    }
51
+
52
+    public DaoMaster getmDaoMaster() {
53
+        return mDaoMaster;
54
+    }
55
+
56
+    public DaoSession getmDaoSession() {
57
+        return mDaoSession;
58
+    }
59
+
60
+    public DaoSession getNewSession() {
61
+        mDaoSession = mDaoMaster.newSession();
62
+        return mDaoSession;
63
+    }
64
+
65
+
66
+}