|
|
@@ -35,16 +35,19 @@ public class DBManager {
|
|
|
|
|
|
private SQLiteDatabase db;
|
|
|
private static volatile DBManager instance;
|
|
|
- public static DBManager getInstance(){
|
|
|
- if (instance==null){
|
|
|
- synchronized (DBManager.class){
|
|
|
- if (instance==null){
|
|
|
- instance=new DBManager();
|
|
|
+
|
|
|
+ public static DBManager getInstance() {
|
|
|
+ if (instance == null) {
|
|
|
+ synchronized (DBManager.class) {
|
|
|
+ if (instance == null) {
|
|
|
+ instance = new DBManager();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return instance;
|
|
|
- };
|
|
|
+ return instance;
|
|
|
+ }
|
|
|
+
|
|
|
+ ;
|
|
|
|
|
|
public DBManager() {
|
|
|
db = DatabaseManager.getInstance().openDatabase();
|
|
|
@@ -59,7 +62,7 @@ public class DBManager {
|
|
|
String sql = "replace into B2BMSG"
|
|
|
+ "(b2b_content,b2b_time,b2b_hasRead,b2b_master)"
|
|
|
+ " values (?, ?, ?, ?);";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
sta.bindString(1, entity.getContent());
|
|
|
sta.bindString(2, entity.getTime());
|
|
|
@@ -74,7 +77,7 @@ public class DBManager {
|
|
|
String groupBy = null;
|
|
|
String having = null;
|
|
|
String orderBy = " b2b_hasRead,b2b_time DESC";
|
|
|
- if (!db.isOpen()) return entity;
|
|
|
+ if (checkDbObject()) return entity;
|
|
|
Cursor cursor = db.query(table, null, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
while (cursor.moveToNext()) {
|
|
|
B2BMsg model = new B2BMsg();
|
|
|
@@ -95,7 +98,7 @@ public class DBManager {
|
|
|
String sql = "update B2BMSG"
|
|
|
+ " set b2b_hasRead=?"
|
|
|
+ " where id=? and b2b_master=? ;";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
sta.bindLong(1, data.getHasRead());
|
|
|
sta.bindLong(2, data.getId());
|
|
|
@@ -107,7 +110,7 @@ public class DBManager {
|
|
|
String table = "B2BMSG";
|
|
|
String[] whereArgs = {String.valueOf(data.getId()), data.getMaster()};
|
|
|
String whereClause = "id=? and b2b_master=? ";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
db.delete(table, whereClause, whereArgs);
|
|
|
}
|
|
|
|
|
|
@@ -119,7 +122,7 @@ public class DBManager {
|
|
|
String sql = "replace into hrorgs"
|
|
|
+ "(or_code,whichsys,or_subof,company,or_isleaf,or_name,or_id,or_flag,or_headmanname,or_headmancode,or_remark)"
|
|
|
+ " values (?, ?, ?, ?, ?, ?, ?,?,?,?,?);";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
db.beginTransaction();
|
|
|
for (int i = 0; i < hrorgsList.size(); i++) {
|
|
|
@@ -149,7 +152,7 @@ public class DBManager {
|
|
|
String sql = "update hrorgs"
|
|
|
+ " set or_remark=?"
|
|
|
+ " where or_id=? and whichsys=?;";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
sta.bindLong(1, or_remark);
|
|
|
sta.bindLong(2, or_id);//更新关键字段
|
|
|
@@ -165,7 +168,7 @@ public class DBManager {
|
|
|
String sql = "update hrorgs"
|
|
|
+ " set or_code=?,whichsys=?,or_subof=?,company=?,or_isleaf=?,or_name=?,or_id=?,or_flag=?"
|
|
|
+ " where or_code=?;";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
db.beginTransaction();
|
|
|
for (int i = 0; i < hrorgsList.size(); i++) {
|
|
|
@@ -189,31 +192,31 @@ public class DBManager {
|
|
|
/**
|
|
|
* @author Administrator
|
|
|
* @功能:增加员工信息---批量
|
|
|
- *
|
|
|
*/
|
|
|
public void saveEmployees(List<EmployeesEntity> employeesEntities) {
|
|
|
String sql = "replace into employees(EM_ID,EM_CODE,EM_NAME,EM_POSITION,EM_DEFAULTORNAME,EM_DEPART,EM_MOBILE,EM_UU,COMPANY,WHICHSYS,Em_defaultorid,Em_flag,Em_imid,EM_EMAIL) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?,?,?,?);";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
db.beginTransaction();
|
|
|
- String whichsys=CommonUtil.getMaster();
|
|
|
- if (StringUtils.isEmpty(whichsys))whichsys=MyApplication.getInstance().getString(R.string.common_noinput);
|
|
|
+ String whichsys = CommonUtil.getMaster();
|
|
|
+ if (StringUtils.isEmpty(whichsys))
|
|
|
+ whichsys = MyApplication.getInstance().getString(R.string.common_noinput);
|
|
|
for (int i = 0; i < employeesEntities.size(); i++) {
|
|
|
EmployeesEntity entity = employeesEntities.get(i);
|
|
|
sta.bindString(1, String.valueOf(entity.getEM_ID()));
|
|
|
sta.bindString(2, entity.getEM_CODE() == null ? "null" : entity.getEM_CODE());
|
|
|
sta.bindString(3, entity.getEM_NAME());
|
|
|
sta.bindString(4, entity.getEM_POSITION());
|
|
|
- sta.bindString(5, entity.getEM_DEFAULTORNAME() == null ? MyApplication.getInstance().getString(R.string.common_noinput): entity.getEM_DEFAULTORNAME());
|
|
|
+ sta.bindString(5, entity.getEM_DEFAULTORNAME() == null ? MyApplication.getInstance().getString(R.string.common_noinput) : entity.getEM_DEFAULTORNAME());
|
|
|
sta.bindString(6, entity.getEM_DEPART());
|
|
|
sta.bindString(7, entity.getEM_MOBILE() == null ? MyApplication.getInstance().getString(R.string.common_noinput) : entity.getEM_MOBILE());
|
|
|
sta.bindString(8, String.valueOf(entity.getEM_UU()));
|
|
|
sta.bindString(9, entity.getCOMPANY());
|
|
|
- sta.bindString(10, StringUtils.isEmpty(entity.getWHICHSYS())?whichsys:entity.getWHICHSYS());
|
|
|
+ sta.bindString(10, StringUtils.isEmpty(entity.getWHICHSYS()) ? whichsys : entity.getWHICHSYS());
|
|
|
sta.bindLong(11, entity.getEm_defaultorid());
|
|
|
sta.bindString(12, entity.getFLAG());
|
|
|
sta.bindString(13, String.valueOf(entity.getEm_IMID()));
|
|
|
- sta.bindString(14, StringUtils.isEmpty(entity.getEM_EMAIL()) ?MyApplication.getInstance().getString(R.string.common_noinput) : entity.getEM_EMAIL());
|
|
|
+ sta.bindString(14, StringUtils.isEmpty(entity.getEM_EMAIL()) ? MyApplication.getInstance().getString(R.string.common_noinput) : entity.getEM_EMAIL());
|
|
|
sta.executeInsert();
|
|
|
}
|
|
|
db.setTransactionSuccessful();
|
|
|
@@ -228,7 +231,7 @@ public class DBManager {
|
|
|
String sql = "update employees"
|
|
|
+ " set EM_ID=?,EM_CODE=?,EM_NAME=?,EM_POSITION=?,EM_DEFAULTORNAME=?,EM_DEPART=?,EM_MOBILE=?,EM_UU=?,COMPANY=?,WHICHSYS=?,Em_defaultorid=?,Em_flag=?"
|
|
|
+ " where EM_CODE=?;";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
db.beginTransaction();
|
|
|
for (int i = 0; i < employeesEntities.size(); i++) {
|
|
|
@@ -239,7 +242,7 @@ public class DBManager {
|
|
|
sta.bindString(4, entity.getEM_POSITION());
|
|
|
sta.bindString(5, entity.getEM_DEFAULTORNAME() == null ? MyApplication.getInstance().getString(R.string.common_noinput) : entity.getEM_DEFAULTORNAME());
|
|
|
sta.bindString(6, entity.getEM_DEPART());
|
|
|
- sta.bindString(7, entity.getEM_MOBILE() == null ?MyApplication.getInstance().getString(R.string.common_noinput) : entity.getEM_MOBILE());
|
|
|
+ sta.bindString(7, entity.getEM_MOBILE() == null ? MyApplication.getInstance().getString(R.string.common_noinput) : entity.getEM_MOBILE());
|
|
|
sta.bindString(8, String.valueOf(entity.getEM_UU()));
|
|
|
sta.bindString(9, entity.getCOMPANY());
|
|
|
sta.bindString(10, entity.getWHICHSYS());
|
|
|
@@ -253,6 +256,15 @@ public class DBManager {
|
|
|
// db.close();
|
|
|
}
|
|
|
|
|
|
+ private boolean checkDbObject() {
|
|
|
+ if (db==null)db=DatabaseManager.getInstance().openDatabase();
|
|
|
+ if (!db.isOpen()) {
|
|
|
+ return true;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @author Administrator
|
|
|
* @功能:记录缓存的时间
|
|
|
@@ -261,7 +273,7 @@ public class DBManager {
|
|
|
String sql = "insert into empdate"
|
|
|
+ "(ed_lastdate,ed_kind,ed_company,ed_whichsys)"
|
|
|
+ " values (?, ?, ?, ?);";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
|
|
|
sta.bindString(1, data.get("ed_lastdate").toString());
|
|
|
@@ -280,7 +292,7 @@ public class DBManager {
|
|
|
String sql = "update empdate"
|
|
|
+ " set ed_lastdate=?"
|
|
|
+ " where ed_kind=? and ed_company=? and ed_whichsys=?;";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
sta.bindString(1, data.get("ed_lastdate").toString());
|
|
|
sta.bindString(2, data.get("ed_kind").toString());
|
|
|
@@ -300,7 +312,7 @@ public class DBManager {
|
|
|
String groupBy = null;
|
|
|
String having = null;
|
|
|
String orderBy = null;
|
|
|
- if (!db.isOpen()) return null;
|
|
|
+ if (checkDbObject()) return null;
|
|
|
Cursor cursor = db.query(table, columns, where, selectionArgs, groupBy, having, orderBy);
|
|
|
while (cursor.moveToNext()) {
|
|
|
datestr = cursor.getString(cursor.getColumnIndex("ed_lastdate"));
|
|
|
@@ -317,7 +329,7 @@ public class DBManager {
|
|
|
String table = "employees";
|
|
|
String whereClause = "em_flag=?";
|
|
|
String[] whereArgs = {"DELETE"};
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
db.delete(table, whereClause, whereArgs);
|
|
|
|
|
|
table = "hrorgs";
|
|
|
@@ -339,7 +351,7 @@ public class DBManager {
|
|
|
String groupBy = null;
|
|
|
String having = null;
|
|
|
String orderBy = null;
|
|
|
- if (!db.isOpen()) return hrorgsEntities;
|
|
|
+ if (checkDbObject()) return hrorgsEntities;
|
|
|
Cursor cursor = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
while (cursor.moveToNext()) {
|
|
|
Hrorgs.HrorgItem hrorgItem = new Hrorgs().new HrorgItem();
|
|
|
@@ -391,7 +403,7 @@ public class DBManager {
|
|
|
// String having = null;
|
|
|
// String orderBy = null;
|
|
|
//db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
- if (!db.isOpen()) return 0;
|
|
|
+ if (checkDbObject()) return 0;
|
|
|
Cursor cursor =
|
|
|
db.rawQuery("select count(*) from employees where em_defaultorid=? and WHICHSYS=?", selectionArgs);
|
|
|
if (cursor.moveToFirst()) {
|
|
|
@@ -407,7 +419,7 @@ public class DBManager {
|
|
|
String table = "hrorgs";
|
|
|
String[] whereArgs = {master};
|
|
|
String whereClause = "whichsys=?";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
db.delete(table, whereClause, whereArgs);
|
|
|
table = "employees";
|
|
|
db.delete(table, whereClause, whereArgs);
|
|
|
@@ -427,7 +439,7 @@ public class DBManager {
|
|
|
String groupBy = null;
|
|
|
String having = null;
|
|
|
String orderBy = null;
|
|
|
- if (!db.isOpen()) return hrorgsEntities;
|
|
|
+ if (checkDbObject()) return hrorgsEntities;
|
|
|
Cursor cursor = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
while (cursor.moveToNext()) {
|
|
|
hrorgsEntities = new HrorgsEntity();
|
|
|
@@ -463,7 +475,7 @@ public class DBManager {
|
|
|
String groupBy = null;
|
|
|
String having = null;
|
|
|
String orderBy = null;
|
|
|
- if (!db.isOpen()) return hrorgsEntities;
|
|
|
+ if (checkDbObject()) return hrorgsEntities;
|
|
|
Cursor cursor = db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
while (cursor.moveToNext()) {
|
|
|
HrorgsEntity hrorgsEntity = new HrorgsEntity();
|
|
|
@@ -496,7 +508,7 @@ public class DBManager {
|
|
|
String orderBy = null;
|
|
|
Cursor cursor = null;
|
|
|
try {
|
|
|
- if (!db.isOpen())
|
|
|
+ if (checkDbObject())
|
|
|
db = DatabaseManager.getInstance().openDatabase();
|
|
|
cursor = db.query(table, null, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
while (cursor.moveToNext()) {
|
|
|
@@ -539,7 +551,7 @@ public class DBManager {
|
|
|
int count = 0;
|
|
|
try {
|
|
|
String master = CommonUtil.getSharedPreferences(MyApplication.getInstance(), "erp_master");
|
|
|
- if (!db.isOpen())
|
|
|
+ if (checkDbObject())
|
|
|
db = DatabaseManager.getInstance().openDatabase();
|
|
|
String sql = "SELECT * FROM EMPLOYEES WHERE WHICHSYS=\'" + master + "\' AND EM_DEFAULTORID IN(" + defaulid + ") ";
|
|
|
Cursor cursor = db.rawQuery(sql, null);
|
|
|
@@ -564,7 +576,7 @@ public class DBManager {
|
|
|
Log.i("todo", "e=" + e);
|
|
|
}
|
|
|
EmployeesEntity model = null;
|
|
|
- if (!db.isOpen()) return model;
|
|
|
+ if (checkDbObject()) return model;
|
|
|
Cursor cursor = db.query(table, null, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
|
|
|
Log.i("todo", "e数据为空");
|
|
|
@@ -607,7 +619,7 @@ public class DBManager {
|
|
|
}*/
|
|
|
public void saveListToAllSubs(List<SubscriptionNumber> subscriptionNumbers) {
|
|
|
String saveSql = "replace into AllSubs(subs_id,subs_title,subs_kind,subs_status,subs_type,subs_master,subs_username,subs_removed,subs_img) values (?,?,?,?,?,?,?,?,?)";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sqLiteStatement = db.compileStatement(saveSql);
|
|
|
for (int i = 0; i < subscriptionNumbers.size(); i++) {
|
|
|
SubscriptionNumber subscriptionNumber = subscriptionNumbers.get(i);
|
|
|
@@ -631,7 +643,7 @@ public class DBManager {
|
|
|
String groupBy = null;
|
|
|
String having = null;
|
|
|
String orderBy = null;
|
|
|
- if (!db.isOpen()) return subscriptionNumbers;
|
|
|
+ if (checkDbObject()) return subscriptionNumbers;
|
|
|
Cursor cursor = db.query(table, null, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
while (cursor.moveToNext()) {
|
|
|
SubscriptionNumber subscriptionNumber = new SubscriptionNumber();
|
|
|
@@ -656,7 +668,7 @@ public class DBManager {
|
|
|
String sql = "update AllSubs"
|
|
|
+ " set subs_status=?, subs_removed=? "
|
|
|
+ " where subs_id=? and subs_master=? and subs_username=? ;";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
sta.bindLong(1, subscriptionNumber.getStatus());
|
|
|
sta.bindLong(2, subscriptionNumber.getRemoved());
|
|
|
@@ -670,7 +682,7 @@ public class DBManager {
|
|
|
String sql = "update AllSubs"
|
|
|
+ " set subs_status=?, subs_removed=? "
|
|
|
+ " where subs_id=? and subs_master=? and subs_username=? ;";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sta = db.compileStatement(sql);
|
|
|
|
|
|
for (int i = 0; i < subscriptionNumbers.size(); i++) {
|
|
|
@@ -706,7 +718,7 @@ public class DBManager {
|
|
|
String table = "AllSubs";
|
|
|
String[] whereArgs = {master, username};
|
|
|
String whereClause = "subs_master=? and subs_username=? ";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
db.delete(table, whereClause, whereArgs);
|
|
|
}
|
|
|
|
|
|
@@ -729,7 +741,7 @@ public class DBManager {
|
|
|
|
|
|
public void saveListToMySubs(List<PersonalSubscriptionBean> personalSubscriptionBeans) {
|
|
|
String saveSql = "replace into MySubs(subs_id,subs_title,subs_kind,subs_type,subs_applied,subs_master,subs_username,subs_img) values (?,?,?,?,?,?,?,?)";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
SQLiteStatement sqLiteStatement = db.compileStatement(saveSql);
|
|
|
for (int i = 0; i < personalSubscriptionBeans.size(); i++) {
|
|
|
PersonalSubscriptionBean personalSubscriptionBean = personalSubscriptionBeans.get(i);
|
|
|
@@ -751,7 +763,7 @@ public class DBManager {
|
|
|
String groupBy = null;
|
|
|
String having = null;
|
|
|
String orderBy = null;
|
|
|
- if (!db.isOpen()) return personalSubscriptionBeans;
|
|
|
+ if (checkDbObject()) return personalSubscriptionBeans;
|
|
|
Cursor cursor = db.query(table, null, selection, selectionArgs, groupBy, having, orderBy);
|
|
|
while (cursor.moveToNext()) {
|
|
|
PersonalSubscriptionBean personalSubscriptionBean = new PersonalSubscriptionBean();
|
|
|
@@ -787,7 +799,7 @@ public class DBManager {
|
|
|
String table = "MySubs";
|
|
|
String[] whereArgs = {String.valueOf(personalSubscriptionBean.getNUM_ID()), personalSubscriptionBean.getMASTER(), personalSubscriptionBean.getUSERNAME()};
|
|
|
String whereClause = "subs_id=? and subs_master=? and subs_username=? ";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
db.delete(table, whereClause, whereArgs);
|
|
|
}
|
|
|
|
|
|
@@ -805,7 +817,7 @@ public class DBManager {
|
|
|
String table = "MySubs";
|
|
|
String[] whereArgs = {master, username};
|
|
|
String whereClause = "subs_master=? and subs_username=? ";
|
|
|
- if (!db.isOpen()) return;
|
|
|
+ if (checkDbObject()) return;
|
|
|
db.delete(table, whereClause, whereArgs);
|
|
|
}
|
|
|
|