· 7 years ago · Dec 08, 2018, 02:36 PM
1package com.layerfarm.setting;
2
3import android.content.Context;
4import android.database.sqlite.SQLiteDatabase;
5import android.database.sqlite.SQLiteOpenHelper;
6import android.util.Log;
7
8import android.widget.Toast;
9
10
11public class DataHelper extends SQLiteOpenHelper {
12
13 private static final String LOGCAT = null;
14 private static final String DATABASE_NAME = "layerfarm-mobile.db";
15 private static final int DATABASE_VERSION = 1;
16 public static final String locationSQL = "CREATE TABLE IF NOT EXISTS location(id integer primary key, name text null, address text null, rid integer);";
17 public static final String flockSQL = "CREATE TABLE IF NOT EXISTS flock(id integer primary key, name text null, location_id integer, type text null, period text null, status text null, capacity integer, rid integer);";
18 public static final String eqq_qualitySQL = "CREATE TABLE IF NOT EXISTS eqq_quality(id integer primary key, name text null);";
19 public static final String feedSQL = "CREATE TABLE IF NOT EXISTS feed(id integer primary key, nama text null, description text null, status text null, rid integer);";
20 public static final String vendorSQL = "CREATE TABLE IF NOT EXISTS vendor(id integer primary key, nama text null, rid integer);";
21 public static final String mortality_categorySQL = "CREATE TABLE IF NOT EXISTS mortality_category(id integer primary key, name text null);";
22 public static final String strainSQL = "CREATE TABLE IF NOT EXISTS strain(id integer primary key, name text null);";
23 public static final String medication_vaccinationSQL = "CREATE TABLE IF NOT EXISTS medication_vaccination(id integer primary key, product_name text null, vendor_id integer, capacity float, unit text null, type text null, status text null, rid integer);";
24
25
26 public DataHelper(Context context) {
27 super(context, DATABASE_NAME, null, DATABASE_VERSION);
28 Log.d(LOGCAT,"Created");
29 // TODO Auto-generated constructor stub
30 }
31
32 @Override
33 public void onCreate(SQLiteDatabase db) {
34 try {
35 // TODO Auto-generated method stub
36 Log.d("Data", "onCreate: " + locationSQL);
37 db.execSQL(locationSQL);
38 String InsertlocationSQL = "INSERT INTO location (id, name, address, rid) VALUES " +
39 "(1,'Location A','Blitar',1)," +
40 "(2,'Location B','Blitar',2)," +
41 "(3,'Location C','Blitar',3)," +
42 "(4,'Location D','Blitar',4);";
43 db.execSQL(InsertlocationSQL);
44
45
46 Log.d("Data", "onCreate: " + flockSQL);
47 db.execSQL(flockSQL);
48 //flockSQL = "INSERT INTO flock (id, name, location_id, type, period, status, capacity, rid) VALUES ('1001', 'Fathur', '1994-02-03', 'Laki-laki','Jakarta');";
49 //db.execSQL(flockSQL);
50
51 Log.d("Data", "onCreate: " + eqq_qualitySQL);
52 db.execSQL(eqq_qualitySQL);
53 String InsertEggQualitySQL = "INSERT INTO egg_quality (id, name) VALUES " +
54 "(1,'Quality A'), " +
55 "(2,'Quality B'), " +
56 "(3,'Quality C'), " +
57 "(4,'Cracked');";
58 db.execSQL(InsertEggQualitySQL);
59
60 Log.d("Data", "onCreate: " + feedSQL);
61 db.execSQL(feedSQL);
62 //feedSQL = "INSERT INTO feed (id, name, description, status, rid) VALUES ('1001', 'Fathur', '1994-02-03', 'Laki-laki','Jakarta');";
63 //db.execSQL(feedSQL);
64
65
66 Log.d("Data", "onCreate: " + vendorSQL);
67 db.execSQL(vendorSQL);
68 String InsertVendorSQL = "INSERT INTO vendor (id, name, rid) VALUES ('1', 'Kalbe', ''), ('2', 'Romindo', '');";
69 db.execSQL(InsertVendorSQL);
70
71
72
73 Log.d("Data", "onCreate: " + mortality_categorySQL);
74 db.execSQL(mortality_categorySQL);
75 String InsertMortalityCategorySQL = "INSERT INTO mortality_category (id, name) VALUES " +
76 "(1, 'Death (Sick)'), " +
77 "(2, 'Death (Mechanic)'), " +
78 "(3, 'Death (Other)'), " +
79 "(4, 'Culling (killed)'), " +
80 "(5, 'Culling (removed)'), " +
81 "(6, 'Spent Hen');";
82 db.execSQL(InsertMortalityCategorySQL);
83
84
85
86 Log.d("Data", "onCreate: " + strainSQL);
87 db.execSQL(strainSQL);
88 String InsertStrainSQL = "INSERT INTO strain (id, name) VALUES " +
89 "(1, 'Babcock Brown')," +
90 "(2, 'Babcock White')," +
91 "(3, 'Bovans Black')," +
92 "(4, 'Bovans Brown')," +
93 "(5, 'Bovans White')," +
94 "(6, 'Dekalb Brown')," +
95 "(7, 'Dekalb White')," +
96 "(8, 'Hisex Brown')," +
97 "(9, 'Hisex White')," +
98 "(10, 'Hy-Line Brown')," +
99 "(11, 'Hy-Line CV-22')," +
100 "(12, 'Hy-Line Silver Brown')," +
101 "(13, 'Hy-Line Sonia')," +
102 "(14, 'Hy-Line W-36')," +
103 "(15, 'ISA Brown')," +
104 "(16, 'Isa White')," +
105 "(17, 'Lohmann Brown Classic')," +
106 "(18, 'Lohmann Brown Lite')," +
107 "(19, 'Shaver Black')," +
108 "(20, 'Shaver Brown')," +
109 "(21, 'Shaver White');";
110 db.execSQL(InsertStrainSQL);
111
112 Log.d("Data", "onCreate: " + medication_vaccinationSQL);
113 db.execSQL(medication_vaccinationSQL);
114 //medication_vaccinationSQL = "INSERT INTO medication_vaccination (id, product_name, vendor_id, capacity, unit, type, status,rid) VALUES ('1001', 'Fathur', '1994-02-03', 'Laki-laki','Jakarta');";
115 // db.execSQL(medication_vaccinationSQL);
116 }catch (Exception e){
117 e.printStackTrace();
118 }
119 }
120
121
122 @Override
123 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
124
125
126 // Drop table if existed, all data will be gone!!!
127 db.execSQL("DROP TABLE IF EXISTS location;");
128 db.execSQL("DROP TABLE IF EXISTS flock;");
129 db.execSQL("DROP TABLE IF EXISTS eqq_quality;");
130 db.execSQL("DROP TABLE IF EXISTS feed;");
131 db.execSQL("DROP TABLE IF EXISTS vendor;");
132 db.execSQL("DROP TABLE IF EXISTS mortality_category;");
133 db.execSQL("DROP TABLE IF EXISTS strain;");
134 db.execSQL("DROP TABLE IF EXISTS medication_vaccination;");
135 onCreate(db);
136 }
137
138}