-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New functions: Add FoodDatabase Add Factor Database by time Import and export for factor db and food db
- Loading branch information
Showing
25 changed files
with
1,689 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/src/main/java/de/crazyinfo/fpe_rechner/FactorDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package de.crazyinfo.fpe_rechner; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
/** | ||
* Created by l.boettcher on 28.09.2017. | ||
*/ | ||
|
||
public class FactorDatabase extends SQLiteOpenHelper { | ||
|
||
private static final String DATABASE_NAME = "FactorDB.db"; | ||
private static final String TABLE_NAME = "Factor"; | ||
private static final String COL1 = "hour"; | ||
private static final String COL2 = "factor"; | ||
|
||
|
||
public FactorDatabase(Context context) { | ||
super(context, DATABASE_NAME, null, 1); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + COL1 + " INTEGER PRIMARY KEY, " + COL2 + " REAL)"); | ||
|
||
|
||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int i, int i1) { | ||
|
||
} | ||
|
||
public boolean addDataFactor(int Hour,String Factor){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(COL1, Hour); | ||
contentValues.put(COL2, Factor); | ||
long result = db.insert(TABLE_NAME, null, contentValues); | ||
|
||
if (result == -1){ | ||
db.update(TABLE_NAME, contentValues, "hour = ?", new String[] {String.valueOf(Hour)}); | ||
return true; | ||
} else { | ||
return true; | ||
} | ||
|
||
} | ||
|
||
public Cursor checkFactor(int Hour){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
Cursor res1 = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE hour = "+ Hour + ";",null); | ||
return res1; | ||
} | ||
|
||
public Cursor getAllDataFactor() { | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
Cursor res = db.rawQuery("SELECT * FROM " + TABLE_NAME + ";", null); | ||
return res; | ||
} | ||
|
||
} | ||
|
70 changes: 70 additions & 0 deletions
70
app/src/main/java/de/crazyinfo/fpe_rechner/FoodCalcDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package de.crazyinfo.fpe_rechner; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
|
||
/** | ||
* Created by l.boettcher on 06.10.2017. | ||
*/ | ||
|
||
public class FoodCalcDatabase extends SQLiteOpenHelper { | ||
|
||
private static final String DATABASE_NAME = "FoodCalcDB.db"; | ||
private static final String TABLE_NAME = "FoodCalc"; | ||
private static final String Col1 = "name"; | ||
private static final String Col2 = "cho"; | ||
private static final String Col3 = "kcal"; | ||
|
||
public FoodCalcDatabase(Context context) { | ||
super(context, DATABASE_NAME, null, 1); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + Col1 + " TEXT, "+Col2+" REAL, "+Col3+" REAL"+")"); | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int i, int i1) { | ||
|
||
} | ||
|
||
public boolean addFoodCalc(String NAME, String CHO, String KCAL){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(Col1, NAME); | ||
contentValues.put(Col2, CHO); | ||
contentValues.put(Col3, KCAL); | ||
long result = db.insert(TABLE_NAME, null, contentValues); | ||
|
||
return result != -1; | ||
|
||
} | ||
|
||
public Cursor getFoodCalc(long id){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
Cursor res1 = db.rawQuery("SELECT rowid _id, * FROM " + TABLE_NAME + " WHERE rowid = "+ id + ";",null); | ||
return res1; | ||
} | ||
|
||
public boolean removeFoodCalc(String rowId){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
return db.delete(TABLE_NAME,"rowid = " + rowId + ";", null) > 0; | ||
} | ||
|
||
public Cursor getAllFoodCalc() { | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
Cursor resFood = db.rawQuery("SELECT rowid _id,* FROM " + TABLE_NAME + ";", null); | ||
return resFood; | ||
} | ||
|
||
public void removeAllFoodCalc(){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
db.delete(TABLE_NAME,null,null); | ||
db.execSQL("delete from "+ TABLE_NAME); | ||
db.close(); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
app/src/main/java/de/crazyinfo/fpe_rechner/FoodDatabase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package de.crazyinfo.fpe_rechner; | ||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.database.sqlite.SQLiteDatabase; | ||
import android.database.sqlite.SQLiteOpenHelper; | ||
import android.widget.Toast; | ||
|
||
/** | ||
* Created by l.boettcher on 04.10.2017. | ||
*/ | ||
|
||
public class FoodDatabase extends SQLiteOpenHelper { | ||
|
||
private static final String DATABASE_NAME = "FoodDB.db"; | ||
private static final String TABLE_NAME = "Food"; | ||
private static final String Col1 = "id"; | ||
private static final String Col2 = "name"; | ||
private static final String Col3 = "cho"; | ||
private static final String Col4 = "kcal"; | ||
|
||
public FoodDatabase(Context context) { | ||
super(context, DATABASE_NAME, null, 1); | ||
} | ||
|
||
@Override | ||
public void onCreate(SQLiteDatabase db) { | ||
db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + Col1 + " INTEGER PRIMARY KEY AUTOINCREMENT, " + Col2 + " TEXT UNIQUE, "+Col3+" REAL, "+Col4+" REAL"+")"); | ||
|
||
Cursor res = db.rawQuery("select * from " + TABLE_NAME + ";", null); | ||
if (res.getCount() == 0) { | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(Col2, "Steak \uD83D\uDC37 100g"); | ||
contentValues.put(Col3, "0"); | ||
contentValues.put(Col4, "112"); | ||
db.insert(TABLE_NAME, null, contentValues); | ||
} | ||
} | ||
|
||
@Override | ||
public void onUpgrade(SQLiteDatabase db, int i, int i1) { | ||
|
||
} | ||
|
||
public boolean addDataFood(String NAME, String CHO, String KCAL){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(Col2, NAME); | ||
contentValues.put(Col3, CHO); | ||
contentValues.put(Col4, KCAL); | ||
long result = db.insert(TABLE_NAME, null, contentValues); | ||
|
||
if (result == -1){ | ||
db.update(TABLE_NAME, contentValues, "name = ?", new String[] {String.valueOf(NAME)}); | ||
return true; | ||
} else { | ||
return true; | ||
} | ||
|
||
} | ||
|
||
public boolean addFood(String NAME, String CHO, String KCAL){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(Col2, NAME); | ||
contentValues.put(Col3, CHO); | ||
contentValues.put(Col4, KCAL); | ||
long result = db.insert(TABLE_NAME, null, contentValues); | ||
return result != -1; | ||
|
||
} | ||
|
||
public boolean updateFood(long id, String NAME, String CHO, String KCAL){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
ContentValues contentValues = new ContentValues(); | ||
contentValues.put(Col2, NAME); | ||
contentValues.put(Col3, CHO); | ||
contentValues.put(Col4, KCAL); | ||
db.update(TABLE_NAME, contentValues, "id = ?", new String[] {String.valueOf(id)}); | ||
return true; | ||
|
||
} | ||
|
||
public Cursor getFood(long id){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
Cursor res1 = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE id = "+ id + ";",null); | ||
return res1; | ||
} | ||
|
||
public Cursor checkFood(String chkname){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
Cursor res1 = db.rawQuery("SELECT * FROM " + TABLE_NAME + " WHERE name = '"+ chkname + "';",null); | ||
return res1; | ||
} | ||
|
||
public Cursor getAllFood() { | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
//Cursor resFood = db.rawQuery("select rowid _id,* from " + TABLE_NAME + ";", null); | ||
Cursor resFood = db.rawQuery("SELECT rowid _id,* FROM " + TABLE_NAME + " ORDER BY name;", null); | ||
return resFood; | ||
} | ||
|
||
public Cursor getAllDataFood() { | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
Cursor res = db.rawQuery("SELECT NAME, CHO, KCAL FROM " + TABLE_NAME + ";", null); | ||
return res; | ||
} | ||
|
||
public boolean removeFood(long rowId){ | ||
SQLiteDatabase db = this.getWritableDatabase(); | ||
return db.delete(TABLE_NAME,"id = " + rowId + ";", null) > 0; | ||
} | ||
} |
Oops, something went wrong.