@@ -8,6 +8,7 @@ | |||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> | |||
<application | |||
android:name="com.example.bpa.app.ICSApp" | |||
android:allowBackup="true" | |||
android:icon="@mipmap/ncd" | |||
android:label="@string/app_name" | |||
@@ -8,6 +8,7 @@ import android.widget.EditText; | |||
import com.example.bpa.app.Main; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.helper.T; | |||
public class LoginActivity extends Activity implements View.OnClickListener { | |||
//region 界面变量 | |||
//用户名 | |||
@@ -33,7 +34,6 @@ public class LoginActivity extends Activity implements View.OnClickListener { | |||
* 初始化 | |||
*/ | |||
private void Init() { | |||
ConfigName.getInstance().dishesCon = LoginActivity.this; | |||
username = findViewById(R.id.input_layout_name); | |||
password = findViewById(R.id.input_layout_psw); | |||
btn_login = findViewById(R.id.btn_login); | |||
@@ -61,6 +61,7 @@ public class LoginActivity extends Activity implements View.OnClickListener { | |||
//根据点击的Tab切换不同的页面及设置对应的ImageButton为绿色 | |||
switch (v.getId()) { | |||
case R.id.btn_login: | |||
String inputName = username.getText().toString(); | |||
String pwd = password.getText().toString(); | |||
if (inputName.equals("admin") && pwd.equals("123456")) { | |||
@@ -0,0 +1,64 @@ | |||
package com.example.bpa.app; | |||
import android.app.Application; | |||
import android.util.Log; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.db.QueryDB; | |||
import com.example.bpa.db.mode.BPA_MATERIAL; | |||
import com.example.bpa.helper.Json; | |||
import com.example.bpa.helper.SdCart; | |||
import java.util.ArrayList; | |||
/** | |||
* 程序启动执行 | |||
* 创建:fengyoufu 20230413 | |||
*/ | |||
public class ICSApp extends Application { | |||
private static ICSApp instance; | |||
@Override | |||
public void onCreate() { | |||
super.onCreate(); | |||
//1.设置程序active | |||
ConfigName.getInstance().dishesCon = this; | |||
Main.getInstance(); | |||
//2.初始化SD卡,数据库DB | |||
SdCart.getInstance().initSD(); | |||
Test(); | |||
} | |||
public void Test() | |||
{ | |||
//新增 | |||
// BPA_MATERIAL ba=new BPA_MATERIAL(); | |||
// ba.deviceID=java.util.UUID.randomUUID().toString(); | |||
// ba.userID="张三"; | |||
// ba.exp="测试"; | |||
// ba.name="测试物料"; | |||
// ba.imgUrl="wwwwwwwww"; | |||
// QueryDB.AddMaterial(ba); | |||
//查询 | |||
ArrayList<BPA_MATERIAL> wl= QueryDB.GetMaterialALL(); | |||
for (BPA_MATERIAL d:wl | |||
) { | |||
String json= new Json<BPA_MATERIAL>().objectToJson(BPA_MATERIAL.class,d); | |||
Log.i("日志","物料查询:"+ json); | |||
//d.name="测试修改"; | |||
// QueryDB.UpdateMaterial(d); | |||
} | |||
//删除 | |||
//808be95d-68ae-4c7c-8e9e-b064408a61db | |||
// BPA_MATERIAL ba1=new BPA_MATERIAL(); | |||
// ba1.id="fa3e7c53-d349-4637-9d97-4ba96b8b1d65"; | |||
// QueryDB.DeleteMaterial(ba1); | |||
} | |||
} |
@@ -34,6 +34,7 @@ public class Main { | |||
LoadingPZ(); | |||
} | |||
/** | |||
* 加载配置 | |||
*/ | |||
@@ -20,7 +20,24 @@ public class ConfigName { | |||
} | |||
//endregion | |||
//region 程序进入界面 | |||
public Context dishesCon; | |||
//endregion | |||
//region SD卡路径设置 | |||
/** | |||
* SD卡路径 | |||
*/ | |||
public String sdCardPath; | |||
/** | |||
* 应用程序 Res 根路径 | |||
*/ | |||
public String appResRoot; | |||
/** | |||
* Db文件路径 | |||
*/ | |||
public static String dbPath = ""; | |||
//endregion | |||
//region 店铺配置 | |||
/** | |||
@@ -1,183 +0,0 @@ | |||
package com.example.bpa.db; | |||
import android.content.Context; | |||
import android.database.sqlite.SQLiteDatabase; | |||
import android.database.sqlite.SQLiteOpenHelper; | |||
import com.example.bpa.db.file.ICSAppFileDb; | |||
import com.example.bpa.db.file.Feild; | |||
import com.example.bpa.db.file.Table; | |||
import java.lang.reflect.Field; | |||
import java.util.ArrayList; | |||
import java.util.List; | |||
/** | |||
* 数据库帮助类 | |||
*/ | |||
public class DBHelper extends SQLiteOpenHelper { | |||
private static final String TABLE_FOOD = "TABLE_FOOD"; | |||
private static DBHelper instance; | |||
private static int version = 3; | |||
public DBHelper(Context context) { | |||
super(context, ICSAppFileDb.dbPath, null, version); | |||
} | |||
@Override | |||
public void onCreate(SQLiteDatabase db) { | |||
System.out.println("-----------------------------------------来了"); | |||
createTables(db, prepareTableInfo()); | |||
} | |||
@Override | |||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | |||
} | |||
public static DBHelper getInstance(Context context) { | |||
if (instance == null) { | |||
instance = new DBHelper(context); | |||
} | |||
return instance; | |||
} | |||
private ArrayList<Table> prepareTableInfo() { | |||
ArrayList<Table> tables = new ArrayList<Table>(); | |||
Table t; | |||
t = new Table(TABLE_FOOD); // 通讯录 | |||
t.addFeild(new Feild("NAME", "text")); // 姓名 | |||
t.addFeild(new Feild("TYPE", "text")); // 号码 | |||
t.addFeild(new Feild("STAR", "text")); // 号码 | |||
t.addFeild(new Feild("PRICE", "text")); // 号码 | |||
tables.add(t); | |||
return tables; | |||
} | |||
/** | |||
* 创建数据表 | |||
* | |||
* @param db | |||
* 数据库名称 | |||
* @param tables | |||
* 所要创建的数据库表列表 | |||
*/ | |||
private void createTables(SQLiteDatabase db, ArrayList<Table> tables) { | |||
db.beginTransaction(); | |||
for (Table table : tables) { | |||
db.execSQL(table.createSQL()); | |||
} | |||
db.setTransactionSuccessful(); | |||
db.endTransaction(); | |||
} | |||
public void CreateTablesAll(Class c) | |||
{ | |||
// SQLiteDatabase db =this.getWritableDatabase(); | |||
// db.beginTransaction(); | |||
// for (Field field : c.getDeclaredFields()){ | |||
// String name=field.getName(); | |||
// String type=field.getType() ; | |||
// nameList.add(field.getName()); | |||
// } | |||
// | |||
// for (Table table : tables) { | |||
// db.execSQL(table.createSQL()); | |||
// } | |||
// db.setTransactionSuccessful(); | |||
// db.endTransaction(); | |||
} | |||
public static List<String> getNameList(Class c){ | |||
ArrayList<String> nameList = new ArrayList<>(); | |||
for (Field field : c.getDeclaredFields()){ | |||
nameList.add(field.getName()); | |||
} | |||
return nameList; | |||
} | |||
// /** | |||
// * 添加菜单 | |||
// * | |||
// * @param tz | |||
// */ | |||
// public long addFood(Food food) { | |||
// SQLiteDatabase db = this.getWritableDatabase(); | |||
// | |||
// ContentValues cv = new ContentValues(); | |||
// cv.put("NAME", food.name); | |||
// cv.put("TYPE", food.type); | |||
// cv.put("PRICE", food.price); | |||
// cv.put("STAR", food.star); | |||
// | |||
// long insert = db.insert(DBHelper.TABLE_FOOD, null, cv); | |||
// db.close(); | |||
// return insert; | |||
// } | |||
// | |||
// /** | |||
// * 修改菜单 | |||
// * | |||
// * @param tz | |||
// */ | |||
// public void updateFood(Food food) { | |||
// SQLiteDatabase db = this.getWritableDatabase(); | |||
// | |||
// ContentValues cv = new ContentValues(); | |||
// cv.put("NAME", food.name); | |||
// cv.put("TYPE", food.type); | |||
// cv.put("PRICE", food.price); | |||
// cv.put("STAR", food.star); | |||
// | |||
// db.insert(DBHelper.TABLE_FOOD, null, cv); | |||
// db.close(); | |||
// | |||
// } | |||
// | |||
// /** | |||
// * 删除菜单 | |||
// * | |||
// * @param food | |||
// */ | |||
// public int deleteFood(Food food) { | |||
// SQLiteDatabase db = this.getWritableDatabase(); | |||
// | |||
// int i = db.delete(TABLE_FOOD, "NAME = ?", | |||
// new String[] { food.name }); | |||
// db.close(); | |||
// return i; | |||
// } | |||
// | |||
// /** | |||
// * 获取所有菜单 | |||
// * | |||
// * @param tz | |||
// */ | |||
// public ArrayList<Food> getAllFood() { | |||
// ArrayList<Food> rlts = new ArrayList<Food>(); | |||
// SQLiteDatabase db = this.getReadableDatabase(); | |||
// String whereClause = null; | |||
// String[] columns = { "NAME", "TYPE", "PRICE", "STAR" }; | |||
// String orderby = "TYPE desc"; | |||
// | |||
// Cursor cursor = db.query(TABLE_FOOD, columns, whereClause, null, null, | |||
// null, orderby, null); | |||
// Food food = null; | |||
// while (cursor.moveToNext()) { | |||
// food = new Food(); | |||
// food.name = cursor.getString(cursor.getColumnIndex("NAME")); | |||
// food.type = cursor.getString(cursor.getColumnIndex("TYPE")); | |||
// food.price = cursor.getString(cursor.getColumnIndex("PRICE")); | |||
// food.star = cursor.getString(cursor.getColumnIndex("STAR")); | |||
// | |||
// rlts.add(food); | |||
// } | |||
// cursor.close(); | |||
// db.close(); | |||
// return rlts; | |||
// } | |||
} |
@@ -0,0 +1,358 @@ | |||
package com.example.bpa.db; | |||
import android.content.ContentValues; | |||
import android.database.Cursor; | |||
import android.database.sqlite.SQLiteDatabase; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.db.file.DBHelper; | |||
import com.example.bpa.db.mode.BPA_ALERTLOG; | |||
import com.example.bpa.db.mode.BPA_GOODS; | |||
import com.example.bpa.db.mode.BPA_GOODSRECIPE; | |||
import com.example.bpa.db.mode.BPA_LOG; | |||
import com.example.bpa.db.mode.BPA_MATERIAL; | |||
import com.example.bpa.db.mode.BPA_MENU; | |||
import com.example.bpa.db.mode.BPA_MENUANDUSER; | |||
import com.example.bpa.db.mode.BPA_ORDER; | |||
import com.example.bpa.db.mode.BPA_ORDERLOG; | |||
import com.example.bpa.db.mode.BPA_ORDERLOGDESC; | |||
import com.example.bpa.db.mode.BPA_SILOS; | |||
import com.example.bpa.db.mode.BPA_SILOSANDMATERIAL; | |||
import com.example.bpa.db.mode.BPA_SUBORDER; | |||
import com.example.bpa.db.mode.BPA_SYSTEMSET; | |||
import com.example.bpa.db.mode.BPA_USER; | |||
import com.example.bpa.helper.Tools; | |||
import java.lang.reflect.Field; | |||
import java.text.SimpleDateFormat; | |||
import java.util.ArrayList; | |||
import java.util.Date; | |||
import java.util.List; | |||
import java.util.Map; | |||
/** | |||
* 数据库数据访问类库 | |||
* add fengyoufu 20230413 | |||
*/ | |||
public class QueryDB { | |||
//region 成员变量 | |||
/** | |||
* 数据库链接 | |||
*/ | |||
private static DBHelper helper=DBHelper.getInstance(ConfigName.getInstance().dishesCon); | |||
/** | |||
* 时间倒序 | |||
*/ | |||
public static String Desc_Time_Down="createTime desc"; | |||
/** | |||
* 时间正序 | |||
*/ | |||
public static String Desc_Time_Up="createTime"; | |||
/** | |||
* 排序、优先顺序 | |||
*/ | |||
public static String Desc_Sort_Up="Sort"; | |||
//endregion | |||
//region BPA_MATERIAL 物料表 | |||
/** | |||
* 新增物料数据 | |||
* add fengyoufu 20230413 | |||
* @param data 物料数据 | |||
* @return 是否成功 | |||
*/ | |||
public static boolean AddMaterial(BPA_MATERIAL data) | |||
{ | |||
return Add(BPA_MATERIAL.class,data); | |||
} | |||
/** | |||
* 修改物料数据 | |||
* add fengyoufu 20230413 | |||
* @param data | |||
*/ | |||
public static void UpdateMaterial(BPA_MATERIAL data) | |||
{ | |||
Update(BPA_MATERIAL.class,data); | |||
} | |||
/** | |||
* 删除物料数据 | |||
* add fengyoufu 20230413 | |||
* @param data 物料数据 | |||
* @return 是否成功 | |||
*/ | |||
public static boolean DeleteMaterial(BPA_MATERIAL data) | |||
{ | |||
return Delete(BPA_MATERIAL.class,data.id); | |||
} | |||
/** | |||
* 获取所有物料信息 | |||
* @return | |||
*/ | |||
public static ArrayList<BPA_MATERIAL> GetMaterialALL() | |||
{ | |||
String orderby=Desc_Time_Up;//出料顺序 | |||
String where="IsDelete=?"; | |||
String[] args=new String[] { "0" }; | |||
ArrayList<BPA_MATERIAL> data=new ArrayList<>(); | |||
ArrayList<Object> obj=Get(BPA_MATERIAL.class,where,args,orderby); | |||
for (Object k:obj) { | |||
data.add((BPA_MATERIAL)k); | |||
} | |||
return data; | |||
} | |||
//endregion | |||
//region BPA_SILOS 料仓管理表 | |||
/** | |||
* 新增料仓管理 | |||
* add fengyoufu 20230413 | |||
* @param data 物料数据 | |||
* @return 是否成功 | |||
*/ | |||
public static boolean AddSilos(BPA_SILOS data) | |||
{ | |||
return Add(BPA_SILOS.class,data); | |||
} | |||
/** | |||
* 修改料仓管理 | |||
* add fengyoufu 20230413 | |||
* @param data | |||
*/ | |||
public static void UpdateSilos(BPA_SILOS data) | |||
{ | |||
Update(BPA_SILOS.class,data); | |||
} | |||
/** | |||
* 删除料仓管理 | |||
* add fengyoufu 20230413 | |||
* @param data 物料数据 | |||
* @return 是否成功 | |||
*/ | |||
public static boolean DeleteSilos(BPA_SILOS data) | |||
{ | |||
return Delete(BPA_SILOS.class,data.id); | |||
} | |||
/** | |||
* 获取所有料仓管理 | |||
* @return | |||
*/ | |||
public static ArrayList<BPA_SILOS> GetSilosALL() | |||
{ | |||
String orderby=Desc_Sort_Up+','+Desc_Time_Up;//先按排序 创建时间倒序 | |||
String where="IsDelete=?"; | |||
String[] args=new String[] { "0" }; | |||
ArrayList<BPA_SILOS> data=new ArrayList<>(); | |||
ArrayList<Object> obj=Get(BPA_SILOS.class,where,args,orderby); | |||
for (Object k:obj) { | |||
data.add((BPA_SILOS)k); | |||
} | |||
return data; | |||
} | |||
//endregion | |||
//region BPA_SILOSANDMATERIAL 料仓物料关联表 | |||
//endregion | |||
//region BPA_GOODS 商品表 | |||
//endregion | |||
//region BPA_GOODSRECIPE 商品配方明细表 | |||
//endregion | |||
//region BPA_ORDER 订单表 | |||
//endregion | |||
//region BPA_SUBORDER 订单子表 | |||
//endregion | |||
//region BPA_ALERTLOG 预警日志表 | |||
//endregion | |||
//region BPA_LOG 日志表 | |||
//endregion | |||
//region BPA_ORDERLOG 订单制作记录表 | |||
//endregion | |||
//region BPA_ORDERLOGDESC 订单制作记录描述表 | |||
//endregion | |||
//region BPA_SYSTEMSET 系统设置表 | |||
//endregion | |||
//region BPA_USER 账户表 | |||
//endregion | |||
//region BPA_MENU 菜单表 | |||
//endregion | |||
//region BPA_MENUANDUSER 菜单用户关联表 | |||
//endregion | |||
//region 私有 | |||
/** | |||
* 新增 | |||
* @param c | |||
* @param data | |||
* @return | |||
*/ | |||
private static boolean Add(Class c,Object data) | |||
{ | |||
ContentValues cv = new ContentValues(); | |||
Map<String, Object> map= Tools.getObjValue(data); | |||
if (map.get("id").toString().isEmpty()) | |||
return false; | |||
for (String key : map.keySet()) { | |||
Object value = map.get(key); | |||
if(value instanceof String) | |||
{ | |||
cv.put(key, (String) value); | |||
}else if (value instanceof Integer) | |||
{ | |||
cv.put(key, ((Integer) value).intValue()); | |||
}else if (value instanceof Double) | |||
{ | |||
cv.put(key, ((Double) value).doubleValue()); | |||
}else if (value instanceof Float) | |||
{ | |||
cv.put(key, ((Float) value).floatValue()); | |||
}else if (value instanceof Long) | |||
{ | |||
cv.put(key, ((Long) value).longValue()); | |||
}else if (value instanceof Boolean) | |||
{ | |||
cv.put(key, ((Boolean) value).booleanValue()); | |||
} | |||
// else if (value instanceof Date) | |||
// { | |||
// cv.put(key, (Date) value); | |||
// } | |||
} | |||
SQLiteDatabase db = helper.getWritableDatabase(); | |||
long insert = db.insert(c.getSimpleName(), null, cv); | |||
db.close(); | |||
return insert>0; | |||
} | |||
/** | |||
* 修改 | |||
* @param c | |||
* @param data | |||
* @return | |||
*/ | |||
private static boolean Update(Class c,Object data) | |||
{ | |||
ContentValues cv = new ContentValues(); | |||
Map<String, Object> map= Tools.getObjValue(data); | |||
String id=map.get("id").toString(); | |||
if (id.isEmpty()) | |||
return false; | |||
for (String key : map.keySet()) { | |||
Object value = map.get(key); | |||
if(value instanceof String) | |||
{ | |||
cv.put(key, (String) value); | |||
}else if (value instanceof Integer) | |||
{ | |||
cv.put(key, ((Integer) value).intValue()); | |||
}else if (value instanceof Double) | |||
{ | |||
cv.put(key, ((Double) value).doubleValue()); | |||
}else if (value instanceof Float) | |||
{ | |||
cv.put(key, ((Float) value).floatValue()); | |||
}else if (value instanceof Long) | |||
{ | |||
cv.put(key, ((Long) value).longValue()); | |||
}else if (value instanceof Boolean) | |||
{ | |||
cv.put(key, ((Boolean) value).booleanValue()); | |||
} | |||
// else if (value instanceof Date) | |||
// { | |||
// cv.put(key, (Date) value); | |||
// } | |||
} | |||
SQLiteDatabase db = helper.getWritableDatabase(); | |||
long insert = db.insert(c.getSimpleName(), null, cv); | |||
db.update(c.getSimpleName(),cv,"id = ?", new String[] { id }); | |||
db.close(); | |||
return true; | |||
} | |||
/** | |||
* 删除 | |||
* @param c | |||
* @param id | |||
* @return | |||
*/ | |||
private static boolean Delete(Class c,String id) | |||
{ | |||
if (id.isEmpty()) | |||
return false; | |||
SQLiteDatabase db = helper.getWritableDatabase(); | |||
long delete=db.delete(c.getSimpleName(), "id = ?", | |||
new String[] { id }); | |||
db.close(); | |||
return delete>0; | |||
} | |||
/** | |||
* 获取数据 | |||
* @param c | |||
* @param whereClause "id = ? and id=?" "sys_pre>? and dia_pre<?" "createTime>?" | |||
* @param Args new String[] { id,id } | |||
* @param orderby "date("+COLUMN_DATE+") desc" "TYPE desc"; desc 倒序 | |||
* @return | |||
*/ | |||
private static ArrayList<Object> Get(Class c,String whereClause,String[] Args,String orderby) | |||
{ | |||
ArrayList<Object> rlts = new ArrayList<Object>(); | |||
SQLiteDatabase db = helper.getReadableDatabase(); | |||
//String orderby = "TYPE desc"; | |||
List<String> col=new ArrayList<>(); | |||
for (Field field : c.getFields()){ | |||
col.add(field.getName()); | |||
} | |||
String[] columns= (String[]) col.toArray(new String[col.size()]); | |||
Cursor cursor = db.query(c.getSimpleName(), columns, whereClause, Args, null, | |||
null, orderby, null); | |||
while (cursor.moveToNext()) { | |||
switch (c.getSimpleName()) | |||
{ | |||
case "BPA_MATERIAL": | |||
BPA_MATERIAL data = new BPA_MATERIAL(); | |||
//私有 | |||
data.imgUrl=cursor.getString((int)cursor.getColumnIndex("imgUrl")); | |||
data.name=cursor.getString((int)cursor.getColumnIndex("name")); | |||
//公有 | |||
data.id=cursor.getString((int)cursor.getColumnIndex("id")); | |||
data.createTime=cursor.getString((int)cursor.getColumnIndex("createTime")); | |||
data.updateTime=cursor.getString((int)cursor.getColumnIndex("updateTime")); | |||
data.deleteTime=cursor.getString((int)cursor.getColumnIndex("deleteTime")); | |||
data.deviceID=cursor.getString((int)cursor.getColumnIndex("deviceID")); | |||
data.userID=cursor.getString((int)cursor.getColumnIndex("userID")); | |||
data.isDelete=cursor.getInt((int)cursor.getColumnIndex("isDelete")); | |||
data.exp=cursor.getString((int)cursor.getColumnIndex("exp")); | |||
rlts.add(data); | |||
break; | |||
} | |||
} | |||
cursor.close(); | |||
db.close(); | |||
return rlts; | |||
} | |||
//endregion | |||
} |
@@ -0,0 +1,129 @@ | |||
package com.example.bpa.db.file; | |||
import android.content.Context; | |||
import android.database.sqlite.SQLiteDatabase; | |||
import android.database.sqlite.SQLiteOpenHelper; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.db.mode.BPA_ALERTLOG; | |||
import com.example.bpa.db.mode.BPA_GOODS; | |||
import com.example.bpa.db.mode.BPA_GOODSRECIPE; | |||
import com.example.bpa.db.mode.BPA_LOG; | |||
import com.example.bpa.db.mode.BPA_MATERIAL; | |||
import com.example.bpa.db.mode.BPA_MENU; | |||
import com.example.bpa.db.mode.BPA_MENUANDUSER; | |||
import com.example.bpa.db.mode.BPA_ORDER; | |||
import com.example.bpa.db.mode.BPA_ORDERLOG; | |||
import com.example.bpa.db.mode.BPA_ORDERLOGDESC; | |||
import com.example.bpa.db.mode.BPA_SILOS; | |||
import com.example.bpa.db.mode.BPA_SILOSANDMATERIAL; | |||
import com.example.bpa.db.mode.BPA_SUBORDER; | |||
import com.example.bpa.db.mode.BPA_SYSTEMSET; | |||
import com.example.bpa.db.mode.BPA_USER; | |||
import java.lang.reflect.Field; | |||
import java.util.ArrayList; | |||
/** | |||
* 数据库帮助类 | |||
*/ | |||
public class DBHelper extends SQLiteOpenHelper { | |||
private static DBHelper instance; | |||
private static int version = 4; | |||
public DBHelper(Context context) { | |||
super(context, ConfigName.getInstance().dbPath, null, version); | |||
} | |||
@Override | |||
public void onCreate(SQLiteDatabase db) { | |||
System.out.println("-----------------------------------------来了"); | |||
createTables(db, prepareTableInfo()); | |||
} | |||
@Override | |||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { | |||
System.out.println("-----------------------------------------更新来了"); | |||
} | |||
public static DBHelper getInstance(Context context) { | |||
if (instance == null) { | |||
instance = new DBHelper(context); | |||
} | |||
return instance; | |||
} | |||
private ArrayList<Table> prepareTableInfo() { | |||
ArrayList<Table> tables = new ArrayList<Table>(); | |||
Table t; | |||
//t = new Table(TABLE_FOOD); // 通讯录 | |||
// t.addFeild(new Feild("NAME", "text")); // 姓名 | |||
// t.addFeild(new Feild("TYPE", "text")); // 号码 | |||
// t.addFeild(new Feild("STAR", "text")); // 号码 | |||
// t.addFeild(new Feild("PRICE", "text")); // 号码 | |||
// tables.add(t); | |||
return tables; | |||
} | |||
/** | |||
* 创建数据表 | |||
* | |||
* @param db | |||
* 数据库名称 | |||
* @param tables | |||
* 所要创建的数据库表列表 | |||
*/ | |||
private void createTables(SQLiteDatabase db, ArrayList<Table> tables) { | |||
db.beginTransaction(); | |||
for (Table table : tables) { | |||
db.execSQL(table.createSQL()); | |||
} | |||
db.setTransactionSuccessful(); | |||
db.endTransaction(); | |||
} | |||
/** | |||
* 创建数据库表 | |||
*/ | |||
public void CreateTables() | |||
{ | |||
CreateTablesAll(BPA_MATERIAL.class);//物料表 | |||
CreateTablesAll(BPA_SILOS.class);//料仓管理表 | |||
CreateTablesAll(BPA_SILOSANDMATERIAL.class);//料仓物料关联表 | |||
CreateTablesAll(BPA_GOODS.class);//商品表 | |||
CreateTablesAll(BPA_GOODSRECIPE.class);//商品配方明细表 | |||
CreateTablesAll(BPA_ORDER.class);//订单表 | |||
CreateTablesAll(BPA_SUBORDER.class);//订单子表 | |||
CreateTablesAll(BPA_ALERTLOG.class);//预警日志表 | |||
CreateTablesAll(BPA_LOG.class);//日志表 | |||
CreateTablesAll(BPA_ORDERLOG.class);//订单制作记录表 | |||
CreateTablesAll(BPA_ORDERLOGDESC.class);//订单制作记录描述表 | |||
CreateTablesAll(BPA_SYSTEMSET.class);//系统设置表 | |||
CreateTablesAll(BPA_USER.class);//账户表 | |||
CreateTablesAll(BPA_MENU.class);//菜单表 | |||
CreateTablesAll(BPA_MENUANDUSER.class);//菜单用户关联表 | |||
} | |||
/** | |||
* 创建数据库表 | |||
* @param c | |||
*/ | |||
private void CreateTablesAll(Class c) | |||
{ | |||
SQLiteDatabase db =this.getWritableDatabase(); | |||
db.beginTransaction(); | |||
String TabName= c.getSimpleName();//表名称 | |||
ArrayList<Table> tables = new ArrayList<Table>(); | |||
Table t; | |||
t = new Table(TabName); // 创建表名称 | |||
for (Field field : c.getFields()){ | |||
String name=field.getName(); | |||
String type=field.getType().getSimpleName(); | |||
if(type.equals("String") || type.equals("Date")) | |||
{ | |||
type="text"; | |||
} | |||
t.addFeild(new Feild(name, type)); // 字段名称 | |||
} | |||
tables.add(t); | |||
for (Table table : tables) { | |||
db.execSQL(table.createSQL()); | |||
} | |||
db.setTransactionSuccessful(); | |||
db.endTransaction(); | |||
} | |||
} |
@@ -1,83 +0,0 @@ | |||
package com.example.bpa.db.file; | |||
import android.app.Application; | |||
import android.content.Context; | |||
import android.os.Environment; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.InputStream; | |||
public class ICSAppFileDb extends Application { | |||
private static ICSAppFileDb instance; | |||
/** | |||
* SD卡路径 | |||
*/ | |||
private String sdCardPath; | |||
/** | |||
* 应用程序 Res 根路径 | |||
*/ | |||
public String appResRoot; | |||
/** | |||
* Db文件路径 | |||
*/ | |||
public static String dbPath = ""; | |||
@Override | |||
public void onCreate() { | |||
super.onCreate(); | |||
initSD(); | |||
} | |||
/** | |||
* 初始化数据库到SD卡 | |||
*/ | |||
private void initSD() { | |||
File sdDir = null; | |||
boolean sdCardExist = Environment.getExternalStorageState().equals( | |||
Environment.MEDIA_MOUNTED); | |||
if (sdCardExist) { | |||
sdDir = Environment.getExternalStorageDirectory(); | |||
sdCardPath = sdDir.toString(); | |||
} | |||
appResRoot = sdCardPath + "/fengyf"; | |||
File rootFile = new File(appResRoot); | |||
if (!rootFile.exists()) { | |||
boolean success = rootFile.mkdirs(); | |||
copyFilesFassets(this, dbPath); | |||
} | |||
dbPath = appResRoot + "/hbl.db"; | |||
} | |||
/** | |||
* 从assets目录中复制整个文件夹内容 | |||
* | |||
* @param context | |||
* Context 使用CopyFiles类的Activity | |||
* @param newPath | |||
* String 复制后路径 如:xx:/bb/cc | |||
*/ | |||
public void copyFilesFassets(Context context, String newPath) { | |||
try { | |||
// 如果是文件 | |||
InputStream is = context.getAssets().open("hbl.db"); | |||
FileOutputStream fos = new FileOutputStream(new File(newPath)); | |||
byte[] buffer = new byte[1024]; | |||
int byteCount = 0; | |||
while ((byteCount = is.read(buffer)) != -1) {// 循环从输入流读取 buffer字节 | |||
fos.write(buffer, 0, byteCount);// 将读取的输入流写入到输出流 | |||
} | |||
fos.flush();// 刷新缓冲区 | |||
is.close(); | |||
fos.close(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -1,5 +1,7 @@ | |||
package com.example.bpa.db.file; | |||
import android.util.Log; | |||
import java.util.ArrayList; | |||
@@ -41,6 +43,7 @@ public class Table { | |||
} | |||
sb.deleteCharAt(sb.length()-1); | |||
sb.append(")"); | |||
Log.i("sql:",sb.toString()); | |||
return sb.toString(); | |||
} | |||
} |
@@ -5,8 +5,6 @@ package com.example.bpa.db.mode; | |||
* 创建人:fengyoufu add 20230412 | |||
*/ | |||
public class BPA_MENUANDUSER extends ModeBase{ | |||
//用户ID | |||
public String userID; | |||
//菜单ID | |||
public String menuID; | |||
} |
@@ -22,5 +22,5 @@ public class BPA_SILOS extends ModeBase { | |||
//状态 状态:0 禁用 1 启用 | |||
public int status; | |||
//优先级 优先出料顺序 | |||
public int priority; | |||
public int Sort; | |||
} |
@@ -1,5 +1,12 @@ | |||
package com.example.bpa.db.mode; | |||
import java.sql.Date; | |||
import android.util.Log; | |||
import com.example.bpa.config.ConfigName; | |||
import java.text.DateFormat; | |||
import java.text.SimpleDateFormat; | |||
import java.util.Date; | |||
/** | |||
* 数据库基类 | |||
@@ -8,12 +15,12 @@ import java.sql.Date; | |||
public class ModeBase { | |||
//ID 号 | |||
public String id; | |||
//创建时间 | |||
public Date createTime; | |||
//修改时间 | |||
public Date updateTime; | |||
//修改时间 | |||
public Date deleteTime; | |||
//创建时间 统一用text存储 | |||
public String createTime; | |||
//修改时间 统一用text存储 | |||
public String updateTime; | |||
//删除时间 统一用text存储 | |||
public String deleteTime; | |||
//设备ID | |||
public String deviceID; | |||
//用户id | |||
@@ -25,5 +32,7 @@ public class ModeBase { | |||
public ModeBase() | |||
{ | |||
id=java.util.UUID.randomUUID().toString(); | |||
createTime= new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());; | |||
//Log.i("日志","创建时间:"+ createTime); | |||
} | |||
} |
@@ -0,0 +1,90 @@ | |||
package com.example.bpa.helper; | |||
import android.content.Context; | |||
import android.os.Environment; | |||
import android.util.Log; | |||
import com.example.bpa.config.ConfigName; | |||
import com.example.bpa.db.file.DBHelper; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.InputStream; | |||
/** | |||
* SD卡操作 | |||
*/ | |||
public class SdCart { | |||
//region 单例模式 | |||
private static SdCart mInstance; //实例变量设置私有,防止直接通过类名访问 | |||
private SdCart() { //默认构造函数私有,防止类外直接new创建对象 | |||
} | |||
public static synchronized SdCart getInstance() { //静态同步方法作为唯一的实例对象获取方式 | |||
if (mInstance==null) { | |||
mInstance = new SdCart(); | |||
} | |||
return mInstance; | |||
} | |||
//endregion | |||
/** | |||
* 初始化数据库到SD卡 | |||
*/ | |||
public void initSD() { | |||
File sdDir = null; | |||
boolean sdCardExist = Environment.getExternalStorageState().equals( | |||
Environment.MEDIA_MOUNTED); | |||
if (sdCardExist) { | |||
sdDir = Environment.getExternalStorageDirectory(); | |||
ConfigName.getInstance().sdCardPath = sdDir.toString(); | |||
} | |||
ConfigName.getInstance().appResRoot = ConfigName.getInstance().sdCardPath + "/hbldb"; | |||
ConfigName.getInstance().dbPath = ConfigName.getInstance().appResRoot + "/hbl.db"; | |||
File rootFile = new File(ConfigName.getInstance().appResRoot); | |||
if (!rootFile.exists()) //创建目录 | |||
{ | |||
rootFile.mkdirs(); | |||
} | |||
File file = new File(ConfigName.getInstance().dbPath); | |||
if(!file.exists())//文件不存在那么创建数据库 | |||
{ | |||
Log.i("日志","初始化数据库:文件不存在准备新建!"); | |||
//1.复制本地文件到SD卡 | |||
copyFilesFassets(ConfigName.getInstance().dishesCon, ConfigName.getInstance().dbPath); | |||
//2.创建数据库结构 | |||
DBHelper.getInstance(ConfigName.getInstance().dishesCon).CreateTables(); | |||
} | |||
Log.i("日志","初始化数据库目录:"+ConfigName.getInstance().dbPath); | |||
} | |||
/** | |||
* 从assets目录中复制整个文件夹内容 | |||
* | |||
* @param context | |||
* Context 使用CopyFiles类的Activity | |||
* @param newPath | |||
* String 复制后路径 如:xx:/bb/cc | |||
*/ | |||
public void copyFilesFassets(Context context, String newPath) { | |||
try { | |||
// 如果是文件 | |||
InputStream is = context.getAssets().open("hbl.db"); | |||
FileOutputStream fos = new FileOutputStream(new File(newPath)); | |||
byte[] buffer = new byte[1024]; | |||
int byteCount = 0; | |||
while ((byteCount = is.read(buffer)) != -1) {// 循环从输入流读取 buffer字节 | |||
fos.write(buffer, 0, byteCount);// 将读取的输入流写入到输出流 | |||
} | |||
fos.flush();// 刷新缓冲区 | |||
is.close(); | |||
fos.close(); | |||
} catch (Exception e) { | |||
e.printStackTrace(); | |||
} | |||
} | |||
} |
@@ -15,13 +15,43 @@ import android.os.Build; | |||
import android.os.Environment; | |||
import android.view.View; | |||
import com.google.gson.Gson; | |||
import org.json.JSONException; | |||
import org.json.JSONObject; | |||
import java.io.IOException; | |||
import java.io.InputStream; | |||
import java.util.HashMap; | |||
import java.util.Iterator; | |||
import java.util.Map; | |||
/* | |||
* 系统工具类 | |||
* */ | |||
public class Tools { | |||
/** | |||
* 根据O object 获取值和变量 | |||
* @param object | |||
* @return | |||
*/ | |||
public static Map<String, Object> getObjValue(Object object) { | |||
String dataStr = new Gson().toJson(object); | |||
JSONObject json = null; | |||
Map<String, Object> map = new HashMap<String, Object>(); | |||
try { | |||
json = new JSONObject(dataStr); | |||
Iterator it = json.keys(); | |||
while (it.hasNext()) { | |||
String key = (String) it.next(); | |||
Object value = json.get(key); | |||
map.put(key, value); | |||
} | |||
} catch (JSONException e) { | |||
e.printStackTrace(); | |||
} | |||
return map; | |||
} | |||
/** | |||
* 判断有没有sd卡 | |||