| | |
| | | package cn.com.basic.face.service.sqlite;
|
| | |
|
| | | import android.database.Cursor;
|
| | | import android.database.sqlite.SQLiteDatabase;
|
| | |
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | |
|
| | | import cn.com.basic.face.base.BaseApplication;
|
| | | import cn.com.basic.face.base.Config;
|
| | | import cn.com.basic.face.base.MainActivity;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.entity.Dictionary;
|
| | |
| | | public static DictionaryDao getInstance() {
|
| | | return instance;
|
| | | }
|
| | | private static StringBuffer sb = new StringBuffer("select dict_id, name from dictionary ");
|
| | |
|
| | |
|
| | |
|
| | | private static List<Dictionary>load(String type){
|
| | | List<Dictionary> list = new ArrayList<Dictionary>();
|
| | | SQLiteDatabase db = MainActivity.getInstance().db;
|
| | | StringBuffer sb = new StringBuffer("select dict_id, name from dictionary ");
|
| | | try {
|
| | | sb.append("where 1 = 1 and type = ");
|
| | | sb.append("'");
|
| | | sb.append(type);
|
| | | sb.append("'");
|
| | | Dictionary aqi = null;
|
| | | Cursor c = db.rawQuery(sb.toString(), new String[]{});
|
| | | Cursor c = MainActivity.getInstance().db.rawQuery(sb.toString(), new String[]{});
|
| | | while (c.moveToNext()) {
|
| | | aqi = new Dictionary();
|
| | | aqi.setDictId(c.getString(c.getColumnIndex("dict_id")));
|
| | | aqi.setName(c.getString((c.getColumnIndex("name"))));
|
| | | list.add(aqi);
|
| | | }
|
| | | c.close();
|
| | | db.setTransactionSuccessful();
|
| | | }catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }finally {
|
| | | db.close();
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
| | | return load(CommonVariables.DictionaryType.VISITOR_TYPE);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | /**
|
| | | * 加载考勤类型
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadAttenderTypeList() {
|
| | | return load(CommonVariables.DictionaryType.ATTENDER_TYPE);
|
| | | }
|
| | |
|
| | |
|
| | | /**
|
| | | * 加载考勤类型
|
| | | * @return
|
| | | */
|
| | | public List<Dictionary> loadAttenderTypeList() {
|
| | | return load(CommonVariables.DictionaryType.ATTENDER_TYPE);
|
| | | }
|
| | |
|
| | | public List<Dictionary> addDictionary(String type, String name) {
|
| | | SQLiteDatabase db = Config.sqlMap.getDb();
|
| | | List<Dictionary> list = new ArrayList<Dictionary>();
|
| | | db.beginTransaction();
|
| | | try {
|
| | | StringBuilder sb = new StringBuilder(40);
|
| | |
|
| | | sb.append("insert into dictionary ( dict_id, name) values (")
|
| | | .append("'")
|
| | | .append(type)
|
| | | .append("'")
|
| | | .append(" , ")
|
| | | .append(")");
|
| | | db.rawQuery(sb.toString(), new String[]{});
|
| | | MainActivity.getInstance().db.rawQuery(sb.toString(), new String[]{});
|
| | | Dictionary aqi = null;
|
| | | Cursor c = db.rawQuery(sb.toString(), new String[]{});
|
| | | Cursor c = MainActivity.getInstance().db.rawQuery("select dict_id,name from dictionary", new String[]{});
|
| | | while (c.moveToNext()) {
|
| | | aqi = new Dictionary();
|
| | | aqi.setDictId(c.getString(c.getColumnIndex("dict_id")));
|
| | | aqi.setName(c.getString((c.getColumnIndex("name"))));
|
| | | list.add(aqi);
|
| | | }
|
| | | db.setTransactionSuccessful();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | } finally {
|
| | | db.endTransaction();
|
| | | }
|
| | | return list;
|
| | | }
|
| | |
|
| | | }
|
| | | //加载需要同步的数据
|
| | | public List<Dictionary> getDictionayList(String deviceCompanyId){
|
| | | String sql="select * from dictionary WHERE is_synchron='N' and device_company_id="+Integer.parseInt(deviceCompanyId);
|
| | | Cursor c =MainActivity.getInstance().db.rawQuery(sql,new String[]{});
|
| | | List<Dictionary> result=new ArrayList<Dictionary>();
|
| | | Dictionary dic=null;
|
| | | if(c.moveToFirst()){
|
| | | dic=new Dictionary();
|
| | | dic.setSn(c.getString(c.getColumnIndex("sn")));
|
| | | dic.setType(c.getString(c.getColumnIndex("type")));
|
| | | dic.setCompnayId(c.getString(c.getColumnIndex("compnay_id")));
|
| | | dic.setDeviceCompanyId(c.getString(c.getColumnIndex("device_company_id")));
|
| | | dic.setDictId(c.getString(c.getColumnIndex("dict_id")));
|
| | | dic.setIsSynchron(c.getString(c.getColumnIndex("is_synchron")));
|
| | | dic.setUpdateTime(c.getString(c.getColumnIndex("update_time")));
|
| | | dic.setName(c.getString(c.getColumnIndex("name")));
|
| | | dic.setOrderBy(c.getString(c.getColumnIndex("order_by")));
|
| | | dic.setPid(c.getString(c.getColumnIndex("pid")));
|
| | | dic.setRemark(c.getString(c.getColumnIndex("remark")));
|
| | | result.add(dic);
|
| | | }
|
| | | return result;
|
| | | }
|
| | |
|
| | | //删除已经上传到服务器的数据
|
| | | public void delDictionary(String deviceCompanyId){
|
| | | String sql="delete from dictionary where is_synchron='N' and device_company_id="+Integer.parseInt(deviceCompanyId);
|
| | | MainActivity.getInstance().db.execSQL(sql);
|
| | |
|
| | | }
|
| | | //获取未同步数据总数
|
| | | public int getSynDataCount(){
|
| | | String sql="select count(*) from dictionary where is_synchron='N' ";
|
| | | Cursor c =MainActivity.getInstance().db.rawQuery(sql,new String[]{});
|
| | | return c.getCount();
|
| | | }
|
| | |
|
| | | }
|
| | |
|