From 2212d9561ccbdc6141be2e36393d01e4bba0f743 Mon Sep 17 00:00:00 2001
From: qvyuanxin <qvyuanxin@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期四, 20 七月 2017 17:30:16 +0800
Subject: [PATCH] 

---
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DictionaryDao.java |   60 ++++++++++++--
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DepartmentDao.java |    3 
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/PostDao.java       |    3 
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DeviceDao.java     |  117 ++++++++++++++++++++++++++++
 4 files changed, 171 insertions(+), 12 deletions(-)

diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DepartmentDao.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DepartmentDao.java
index f1af8ab..5bb57e1 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DepartmentDao.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DepartmentDao.java
@@ -40,6 +40,9 @@
             e.printStackTrace();
         }finally {
             db.endTransaction();
+            if(db!=null){
+                db.close();
+            }
         }
         return list;
 
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DeviceDao.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DeviceDao.java
index d566ba4..30f0205 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DeviceDao.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DeviceDao.java
@@ -1,8 +1,14 @@
 package cn.com.basic.face.service.sqlite;
 
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import java.util.ArrayList;
 import java.util.List;
 
+import cn.com.basic.face.base.Config;
 import cn.com.basic.face.discern.entity.Device;
+import cn.com.basic.face.discern.entity.Dictionary;
 
 /**
  * 璁惧Dao
@@ -22,7 +28,60 @@
      */
     public List<Device> loadMainDevice(String type, String sn) {
 
-        return null;
+        List<Device> list = new ArrayList<Device>();
+        SQLiteDatabase db = Config.sqlMap.getDb();
+        db.beginTransaction();
+        try {
+            StringBuilder sb = new StringBuilder(40);
+                    sb.append("select a.device_id, ").append("a.company_id, ").
+                            append("a.device_name, ").append("a.type, ").append("a.install_address, ")
+                            .append("a.school_name, ").append("a.brand_id, ").append("a.ip, ")
+                            .append("a.port, ").append("a.resolution_id, ").append("a.username, ")
+                            .append("a.password, ").append("a.protocol_id, ").append("a.sn, ")
+                            .append("a.belong_id ").append("from device a ")
+                            .append("where 1 = 1");
+            if(type != null && !type.trim().isEmpty()) {
+                sb.append(" AND a.type = '").append(type).append("'");
+            }
+            if(sn != null && !sn.trim().isEmpty()) {
+                sb.append(" AND a.sn = ").append(sn) ;
+            }
+
+
+
+            Device aqi = null;
+            Cursor c = db.rawQuery(sb.toString(), new String[]{});
+            while (c.moveToNext()) {
+                aqi = new Device();
+                aqi.setDeviceId(c.getString(c.getColumnIndex("device_id")));
+                aqi.setCompanyId(c.getString((c.getColumnIndex("company_id"))));
+                aqi.setDeviceName(c.getString((c.getColumnIndex("device_name"))));
+                aqi.setType(c.getString(c.getColumnIndex("type")));
+                aqi.setInstallAdress(c.getString((c.getColumnIndex("install_address"))));
+                aqi.setSchoolName(c.getString((c.getColumnIndex("school_name"))));
+                aqi.setBrandId(c.getString(c.getColumnIndex("brand_id")));
+                aqi.setIp(c.getString(c.getColumnIndex("ip")));
+                aqi.setPort(c.getString(c.getColumnIndex("port")));
+                aqi.setResolutionId(c.getString(c.getColumnIndex("resolution_id")));
+                aqi.setUsername(c.getString(c.getColumnIndex("username")));
+                aqi.setPassword(c.getString(c.getColumnIndex("password")));
+                aqi.setProtocolId(c.getString(c.getColumnIndex("protocol_id")));
+                aqi.setSn(c.getString(c.getColumnIndex("sn")));
+                aqi.setBelongId(c.getString(c.getColumnIndex("belong_id")));
+
+                list.add(aqi);
+            }
+            c.close();
+            db.setTransactionSuccessful();
+        }catch (Exception e) {
+            e.printStackTrace();
+        }finally {
+            db.endTransaction();
+            if(db!=null){
+                db.close();
+            }
+        }
+        return list;
     }
 
     /**
@@ -33,7 +92,61 @@
      */
     public List<Device> loadCamera(String type, String belongId) {
 
-        return null;
+        List<Device> list = new ArrayList<Device>();
+        SQLiteDatabase db = Config.sqlMap.getDb();
+        db.beginTransaction();
+        try {
+            StringBuilder sb = new StringBuilder(40);
+
+            sb.append("select a.device_id, ").append("a.company_id, ").
+                    append("a.device_name, ").append("a.type, ").append("a.install_address, ")
+                    .append("a.school_name, ").append("a.brand_id, ").append("a.ip, ")
+                    .append("a.port, ").append("a.resolution_id, ").append("a.username, ")
+                    .append("a.password, ").append("a.protocol_id, ").append("a.sn, ")
+                    .append("a.belong_id ").append("from device a ")
+                    .append("where 1 = 1");
+            if(type != null && !type.trim().isEmpty()) {
+                sb.append(" AND a.type = '").append(type).append("'");
+            }
+            if(belongId != null && !belongId.trim().isEmpty()) {
+                sb.append(" AND a.belong_id = ").append(belongId) ;
+            }
+
+
+
+            Device aqi = null;
+            Cursor c = db.rawQuery(sb.toString(), new String[]{});
+            while (c.moveToNext()) {
+                aqi = new Device();
+                aqi.setDeviceId(c.getString(c.getColumnIndex("device_id")));
+                aqi.setCompanyId(c.getString((c.getColumnIndex("company_id"))));
+                aqi.setDeviceName(c.getString((c.getColumnIndex("device_name"))));
+                aqi.setType(c.getString(c.getColumnIndex("type")));
+                aqi.setInstallAdress(c.getString((c.getColumnIndex("install_address"))));
+                aqi.setSchoolName(c.getString((c.getColumnIndex("school_name"))));
+                aqi.setBrandId(c.getString(c.getColumnIndex("brand_id")));
+                aqi.setIp(c.getString(c.getColumnIndex("ip")));
+                aqi.setPort(c.getString(c.getColumnIndex("port")));
+                aqi.setResolutionId(c.getString(c.getColumnIndex("resolution_id")));
+                aqi.setUsername(c.getString(c.getColumnIndex("username")));
+                aqi.setPassword(c.getString(c.getColumnIndex("password")));
+                aqi.setProtocolId(c.getString(c.getColumnIndex("protocol_id")));
+                aqi.setSn(c.getString(c.getColumnIndex("sn")));
+                aqi.setBelongId(c.getString(c.getColumnIndex("belong_id")));
+
+                list.add(aqi);
+            }
+            c.close();
+            db.setTransactionSuccessful();
+        }catch (Exception e) {
+            e.printStackTrace();
+        }finally {
+            db.endTransaction();
+            if(db!=null){
+                db.close();
+            }
+        }
+        return list;
     }
 
 }
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DictionaryDao.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DictionaryDao.java
index 7b0a7f9..fcfb627 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DictionaryDao.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/DictionaryDao.java
@@ -1,7 +1,13 @@
 package cn.com.basic.face.service.sqlite;
 
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
+import java.util.ArrayList;
 import java.util.List;
 
+import cn.com.basic.face.base.Config;
+import cn.com.basic.face.discern.common.CommonVariables;
 import cn.com.basic.face.discern.entity.Dictionary;
 
 /**
@@ -13,13 +19,45 @@
     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 = Config.sqlMap.getDb();
+        db.beginTransaction();
+        try {
+            sb.append("where 1 = 1 and type = ");
+            sb.append(type);
+            Dictionary aqi = null;
+            Cursor c = 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.endTransaction();
+            if(db!=null){
+                db.close();
+            }
+        }
+        return list;
+    }
 
     /**
      * 鍔犺浇鍥藉
      * @return
      */
     public List<Dictionary> loadCountries() {
-        return null;
+
+         return   load(CommonVariables.DictionaryType.COUNTRY);
     }
 
     /**
@@ -27,7 +65,9 @@
      * @return
      */
     public List<Dictionary> loadIdTypeList() {
-        return null;
+
+        return   load(CommonVariables.DictionaryType.ID_TYPE);
+
     }
 
     /**
@@ -35,7 +75,7 @@
      * @return
      */
     public List<Dictionary> loadGenderList() {
-        return null;
+        return   load(CommonVariables.DictionaryType.GENDER);
     }
 
     /**
@@ -43,7 +83,7 @@
      * @return
      */
     public List<Dictionary> loadVisitReasonList() {
-        return null;
+        return   load(CommonVariables.DictionaryType.VISIT_REASON);
     }
 
     /**
@@ -51,7 +91,7 @@
      * @return
      */
     public List<Dictionary> loadResolutionList() {
-        return null;
+        return   load(CommonVariables.DictionaryType.RESOLUTION);
     }
 
     /**
@@ -59,7 +99,7 @@
      * @return
      */
     public List<Dictionary> loadProtocolList() {
-        return null;
+        return   load(CommonVariables.DictionaryType.PROTOCOL);
     }
 
     /**
@@ -67,7 +107,7 @@
      * @return
      */
     public List<Dictionary> loadCameraBrandList() {
-        return null;
+        return   load(CommonVariables.DictionaryType.CAMERA_BRAND);
     }
 
     /**
@@ -75,11 +115,11 @@
      * @return
      */
     public List<Dictionary> loadVisitorTypeList() {
-        return null;
+        return   load(CommonVariables.DictionaryType.VISITOR_TYPE);
     }
 
     public List<Dictionary> addDictionary(String type, String name) {
-        return null;
+        return   load(CommonVariables.DictionaryType.COUNTRY);
     }
 
 
@@ -88,7 +128,7 @@
      * @return
      */
     public List<Dictionary> loadAttenderTypeList() {
-        return null;
+        return   load(CommonVariables.DictionaryType.ATTENDER_TYPE);
     }
 
 }
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/PostDao.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/PostDao.java
index f847ea0..75540e8 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/PostDao.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/sqlite/PostDao.java
@@ -45,6 +45,9 @@
             e.printStackTrace();
         }finally {
             db.endTransaction();
+            if(db!=null){
+                db.close();
+            }
         }
         return list;
     }

--
Gitblit v1.8.0