Последняя миля

This commit is contained in:
2024-08-19 07:09:45 +05:00
parent 25348018ac
commit 8da3351cf9
29 changed files with 1099 additions and 571 deletions

View File

@ -86,11 +86,7 @@ public class DateTimeTM extends com.google.android.material.textfield.TextInputE
public static final Creator<SavedStateTDTM> CREATOR = new Creator<SavedStateTDTM>()
{
public SavedStateTDTM createFromParcel(Parcel in)
{
return new SavedStateTDTM(in);
}
public SavedStateTDTM createFromParcel(Parcel in) { return new SavedStateTDTM(in); }
public SavedStateTDTM[] newArray(int size)
{
return new SavedStateTDTM[size];

View File

@ -6,6 +6,7 @@ import android.os.Parcelable;
import android.util.AttributeSet;
import android.widget.EditText;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -28,15 +29,31 @@ public class DateTimeText extends EditText implements fieldDB
public void setValue(String val)
{
m_Value = val;
m_Value = null; //Присваиваю ниже так как нужно только проверянное значение даты
if(val!=null && !val.equals(""))
{
Date date = new Date(Long.parseLong(m_Value)*1000);
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
String str = format.format(date);
setText(str);
Date date=null;
try {
date = new Date(Long.parseLong(val)*1000);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); //Теперь для простого преобразования в тип даты PostgreSQL дату храню в виде текста в формате "yyyy-MM-dd HH:mm:ss"
m_Value=format.format(date);
} catch (NumberFormatException e) {
}
if(date==null){
try {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
date = format.parse(val);
m_Value = val;
} catch (ParseException e) {
}
}
if(date!=null) {
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm"); //Убрал секунды так всё равно то что отображается не соответствует тому что храниться
String str = format.format(date);
setText(str);
}else{
setText("");
}
}else
{
setText("");
@ -66,7 +83,6 @@ public class DateTimeText extends EditText implements fieldDB
{
return new SavedStateDTT(in);
}
public SavedStateDTT[] newArray(int size)
{
return new SavedStateDTT[size];

View File

@ -62,9 +62,10 @@ public class DBGUITable
//Считываем поля и их типы из таблицы
DbOpenHelper dboh = new DbOpenHelper(m_context);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("PRAGMA table_info('" + m_table + "');", null);
cursor = rdb.rawQuery("PRAGMA table_info('" + m_table + "');", null);
if (cursor.moveToFirst()) {
do {
if (Tools.getStringFromCursor(cursor, "name").equals(name.toLowerCase())) {
@ -73,10 +74,10 @@ public class DBGUITable
}
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb != null) { rdb.close(); }
}
dboh.close();
@ -94,9 +95,10 @@ public class DBGUITable
boolean result = true;
DbOpenHelper dboh = new DbOpenHelper(m_context);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("PRAGMA table_info('"+m_table+"');",null);
cursor = rdb.rawQuery("PRAGMA table_info('"+m_table+"');",null);
if(cursor.moveToFirst())
{
do{
@ -121,10 +123,10 @@ public class DBGUITable
Log.e("CCALM", "Validate field = " + name + " find in CV value = "+value);
}while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
} finally {
if(cursor != null) { cursor.close(); }
if (rdb != null) { rdb.close(); }
}
dboh.close();
@ -213,20 +215,21 @@ public class DBGUITable
//Проверка нужно ли вставить либо обновить по id записи
boolean b=false;
DbOpenHelper dboh = new DbOpenHelper(m_context);
Cursor cursor;
if(cv.getAsString("uid")!=null)
{
uid=cv.getAsString("uid");
String sql="select 1 from "+m_table+" where uid = '" + uid +"'";
SQLiteDatabase rdb=null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(sql,null);
b=cursor.moveToFirst();
cursor.close();
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if(cursor != null) { cursor.close(); }
if(rdb!=null) rdb.close();
}
}
@ -285,10 +288,10 @@ public class DBGUITable
DbOpenHelper dboh = new DbOpenHelper(m_context);
String sql = "";
Cursor cursor = null;
sql = "select * from "+m_table+" where uid='" + uid + "'";
SQLiteDatabase rdb=null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(sql, null);
@ -300,9 +303,9 @@ public class DBGUITable
Object obj=findComponent(cursor.getColumnName(i));
if(obj!=null)
{
if(cursor.getColumnName(i).equals("date")) {
Log.e("CCALM", "1 field " + cursor.getColumnName(i) + " = " + cursor.getString(i) + " type= " + cursor.getType(i));
}
//if(cursor.getColumnName(i).equals("date")) {
// Log.e("CCALM", "1 field " + cursor.getColumnName(i) + " = " + cursor.getString(i) + " type= " + cursor.getType(i));
//}
if(cursor.getType(i)==Cursor.FIELD_TYPE_FLOAT){ //Because cutting double
setValue(obj, ""+cursor.getDouble(i));
@ -311,14 +314,14 @@ public class DBGUITable
}
//для проверки обратное действие
Log.e("CCALM", "read field = " + cursor.getColumnName(i) + " val1 = " + cursor.getString(i) + " val2 = " + getValue(findComponent(cursor.getColumnName(i))));
//Log.e("CCALM", "read field = " + cursor.getColumnName(i) + " val1 = " + cursor.getString(i) + " val2 = " + getValue(findComponent(cursor.getColumnName(i))));
}
}
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb != null) { rdb.close(); }
}
dboh.close();

View File

@ -1581,26 +1581,16 @@ public class DbOpenHelper extends SQLiteOpenHelper
public List<String> GetColumns(String tableName)
{
List<String> ar = null;
Cursor c = null;
SQLiteDatabase rdb=null;
Cursor cursor = null;
try {
rdb = getReadableDatabase();
try {
c = rdb.rawQuery("select * from " + tableName + " limit 1", null);
if (c != null) {
ar = new ArrayList<String>(Arrays.asList(c.getColumnNames()));
}
} catch (Exception e) {
Log.v(tableName, e.toString(), e);
//e.printStackTrace();
} finally
{
if (c != null)
c.close();
}
cursor = rdb.rawQuery("select * from " + tableName + " limit 1", null);
ar = new ArrayList<String>(Arrays.asList(cursor.getColumnNames()));
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb != null) { rdb.close(); }
}
return ar;
@ -1611,11 +1601,9 @@ public class DbOpenHelper extends SQLiteOpenHelper
{
if(tbl==null) return false;
Cursor cursor;
//if(tbl.name.equals("countries"))
// Log.i("CCALM", "tbl0=" + tbl.name);
//if(tbl.name.equals("countriesregions"))
// Log.i("CCALM", "tbl0=" + tbl.name);
if(tbl.name.equals("frmlocustdel_locations")){
Log.i("CCALM", "tbl.name = "+tbl.name);
}
//Проверка на существование полей
Boolean[] fb=new Boolean[tbl.fields.size()]; //Для проверки существования полей в локальной таблице
@ -1636,7 +1624,7 @@ public class DbOpenHelper extends SQLiteOpenHelper
while(tbl.ReadNextRecord())
{
if(tbl.name.equals("frmlocustdel_locations")){
Log.i("CCALM","tbl.name="+tbl.name);
Log.i("CCALM","tbl.name="+tbl.name); //Дата не загрузилась и центр участка не загрузился
}
String sql=null;
String[] par=null;
@ -1652,22 +1640,24 @@ public class DbOpenHelper extends SQLiteOpenHelper
boolean exists=false;
SQLiteDatabase rdb=null;
Cursor cursor = null;
try {
rdb = getReadableDatabase();
cursor = rdb.rawQuery(sql, par);
exists=cursor.moveToFirst();
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb != null) { rdb.close(); }
}
ContentValues cv = new ContentValues();
for(int i=0;i<tbl.fields.size();i++)
{
//if(b && tbl.fields.get(i).name.equals("id")) continue; //Если существует не записываем
//Log.i("CCALM","fld="+tbl.fields.get(i).name+" val="+tbl.fields.get(i).getStrVal()+" type="+tbl.fields.get(i).type); //Для дебага
if(tbl.name.equals("frmlocustdel_locations")){
Log.i("CCALM","fld="+tbl.fields.get(i).name+" val="+tbl.fields.get(i).getStrVal()+" type="+tbl.fields.get(i).type); //Для дебага
}
if(fb[i]) //Присваиваем только поля существующие в локальной базе
{
@ -1678,7 +1668,7 @@ public class DbOpenHelper extends SQLiteOpenHelper
}
}
if(!exists)
if(!exists) //Если существует запись то вставляем, иначе обновляем.
{
SQLiteDatabase wdb = null;
try {
@ -1808,15 +1798,16 @@ public class DbOpenHelper extends SQLiteOpenHelper
//так как пользователь может быть только 1 то удаляем всех остальных
boolean b=false;
SQLiteDatabase rdb=null;
Cursor cursor=null;
try {
rdb=getReadableDatabase();
rdb.execSQL("update _user set del=1;");
Cursor cursor = rdb.rawQuery("select 1 from _user where id = ?", new String[]{String.valueOf(id)});
cursor = rdb.rawQuery("select 1 from _user where id = ?", new String[]{String.valueOf(id)});
b = cursor.moveToFirst();
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null) rdb.close();
}
@ -2247,10 +2238,11 @@ public class DbOpenHelper extends SQLiteOpenHelper
{
int result[]={0,0};
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = this.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select id,country_id,lon_max,name from CountriesRegions where del=0 and " + lon + ">lon_min and " + lon + "<lon_max and " + lat + ">lat_min and " + lat + "<lat_max order by area", null);
cursor = rdb.rawQuery("select id,country_id,lon_max,name from CountriesRegions where del=0 and " + lon + ">lon_min and " + lon + "<lon_max and " + lat + ">lat_min and " + lat + "<lat_max order by area", null);
if (cursor.moveToFirst()) {
do {
result[0] = cursor.getInt(cursor.getColumnIndex("country_id"));
@ -2310,8 +2302,9 @@ public class DbOpenHelper extends SQLiteOpenHelper
} while (cursor.moveToNext());
}
cursor.close();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb != null) { rdb.close(); }
}
return result;

View File

@ -253,6 +253,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select c.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = c.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),c.name) name from countries c where c.del=0 order by c.name", null);
@ -261,10 +262,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB) spiCountry).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -295,18 +296,19 @@ public class LocustActivity extends FragmentActivity implements LocationListener
String sql = "select id, name, lon_min from countriesregions where del=0 and country_id=" + ((selectDB)spiCountry).getValue() + " order by name";
DbOpenHelper dboh = new DbOpenHelper(LocustActivity.this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery(sql, null);
cursor = rdb.rawQuery(sql, null);
if (cursor.moveToFirst()) {
do {
((selectDB)spiRegion).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -440,6 +442,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select b.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = b.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),b.name) name from list_biotope b where b.del=0 order by b.name", null);
@ -448,10 +451,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiBioBiotope).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -463,6 +466,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
sql = "select g.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = g.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),g.name) name from list_greenery g where g.del=0 order by g.sort";
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(sql, null);
@ -471,10 +475,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiBioGreenery).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -485,6 +489,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select c.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = c.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),c.name) name from list_cover c where c.del=0 order by c.sort,c.name", null);
@ -493,10 +498,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiBioGreeneryCover).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -522,6 +527,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select lt.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = lt.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),lt.name) name from LocustsTypes lt where lt.del=0 order by lt.sort,lt.name", null);
@ -530,10 +536,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiLocustType).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -560,6 +566,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем отрождение и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select b.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = b.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),b.name) name from list_enemies b where b.del=0 order by b.sort", null);
@ -568,10 +575,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiEggsEnemies).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -583,6 +590,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем отрождение и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select b.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = b.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),b.name) name from Borns b where b.del=0 order by b.sort", null);
@ -591,10 +599,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiLarvaBorn).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -605,6 +613,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем отрождение и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select a.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = a.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),a.name) name from list_age a where a.del=0 order by a.sort", null);
@ -613,10 +622,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiLarvaAge).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -627,6 +636,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем отрождение и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select a.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = a.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),a.name) name from list_paintings a where a.del=0 order by a.sort", null);
@ -635,10 +645,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiLarvaPainting).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -650,6 +660,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем отрождение и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select a.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = a.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),a.name) name from list_behaviors a where a.del=0 order by a.sort", null);
@ -658,10 +669,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiLarvaBehavior).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -687,6 +698,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiKuliguliAction).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select a.id,COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = a.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),a.name) name from list_actions a where a.del=0 order by a.sort", null);
@ -695,10 +707,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiKuliguliAction).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -709,6 +721,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
// Выбираем отрождение и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select a.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = a.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),a.name) name from list_age a where a.del=0 order by a.sort", null);
@ -717,10 +730,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiKuliguliAge).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -731,6 +744,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiImagoWing).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select f.id,COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = f.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),f.name) name from Fledgling f where f.del=0 order by f.sort", null);
@ -739,10 +753,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiImagoWing).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -758,6 +772,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiImagoPhase).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),d.name) name from list_phase d where d.del=0 order by d.sort,d.name", null);
@ -766,10 +781,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiImagoPhase).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -780,6 +795,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiImagoAction).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select f.id,COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = f.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),f.name) name from list_breeding f where f.del=0 order by f.sort", null);
@ -788,10 +804,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiImagoAction).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -844,6 +860,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiSwarmDensity).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),d.name) name from list_density d where d.del=0 order by d.percent,d.name", null);
@ -852,10 +869,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiSwarmDensity).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -871,6 +888,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiSwarmFlying).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),d.name) name, d.degree from list_directions d where d.del=0 order by d.degree", null);
@ -879,10 +897,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiSwarmFlying).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -892,6 +910,7 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiSwarmHeight).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='" + Tools.getLang() + "' LIMIT 1),d.name) name from list_height d where d.del=0 order by d.sort,d.name", null);
@ -900,10 +919,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
((selectDB)spiSwarmHeight).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1955,9 +1974,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
list.clear();
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select uid,lat,lon from frmlocust_locations where del=false and frmlocust_uid='" + uid + "' order by pos", null);
cursor = rdb.rawQuery("select uid,lat,lon from frmlocust_locations where del=0 and frmlocust_uid='" + uid + "' order by pos", null);
if (cursor.moveToFirst())
{
do
@ -1965,10 +1985,10 @@ public class LocustActivity extends FragmentActivity implements LocationListener
list.add(new LatLon(cursor.getString(0), cursor.getDouble(1), cursor.getDouble(2)));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -2701,10 +2721,11 @@ public class LocustActivity extends FragmentActivity implements LocationListener
super.onStart();
DbOpenHelper dboh = new DbOpenHelper(this);
String sql="select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';";
try(
SQLiteDatabase rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery(sql, null);
) {
SQLiteDatabase rdb = null;
Cursor cursor = null;
try{
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(sql, null);
if(!cursor.moveToFirst())
{
Toast toast = Toast.makeText(getApplicationContext(),
@ -2713,6 +2734,9 @@ public class LocustActivity extends FragmentActivity implements LocationListener
}
} catch (Exception e) {
Log.e("CCALM", "Database error occurred", e);
}finally{
if(cursor != null) { cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
}

View File

@ -299,6 +299,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
// Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select id, name from countries where del=0 order by name", null);
@ -309,10 +310,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiCountry).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -330,9 +331,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
{
DbOpenHelper dboh = new DbOpenHelper(LocustDelActivity.this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select id, name from countriesregions where del=0 and country_id=" + ((selectDB)spiCountry).getValue() + " order by name", null);
cursor = rdb.rawQuery("select id, name from countriesregions where del=0 and country_id=" + ((selectDB)spiCountry).getValue() + " order by name", null);
if (cursor.moveToFirst())
{
do
@ -341,10 +343,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -403,6 +405,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiVegType).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='"
@ -414,10 +417,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiVegType).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -430,6 +433,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiVegCover).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -442,10 +446,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiVegCover).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -459,6 +463,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
// Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -471,10 +476,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiVegDamage).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -495,6 +500,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiInsFormulation).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor=null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -507,10 +513,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiInsFormulation).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -522,6 +528,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiInsDiluted).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -534,10 +541,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiInsDiluted).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -577,6 +584,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiWindDirectionStart).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -589,10 +597,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiWindDirectionStart).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -602,6 +610,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiWindDirectionEnd).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='"
@ -613,10 +622,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiWindDirectionEnd).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -626,6 +635,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprayDirectionStart).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -639,10 +649,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprayDirectionStart).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -652,6 +662,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprayDirectionEnd).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -665,10 +676,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprayDirectionEnd).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -679,6 +690,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiLocSpecies).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -691,10 +703,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiLocSpecies).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -704,6 +716,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiLocHoppers).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select lt.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = lt.name AND l.short_name='"
@ -715,10 +728,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiLocHoppers).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -761,6 +774,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiMainPurpose).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select lt.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = lt.name AND l.short_name='"
@ -772,10 +786,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiMainPurpose).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -786,6 +800,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiLocustPhaseId).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -798,10 +813,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiLocustPhaseId).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -811,6 +826,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprPlatform).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='"
@ -822,10 +838,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprPlatform).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -835,6 +851,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprPlatformA).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -848,10 +865,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprPlatformA).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -861,6 +878,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprPlatformG).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -874,10 +892,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprPlatformG).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -887,6 +905,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprPlatformH).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -900,10 +919,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprPlatformH).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -949,6 +968,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprMarking).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -961,10 +981,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiSprMarking).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1011,6 +1031,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiTypeImpact).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='"
@ -1022,10 +1043,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiTypeImpact).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1042,6 +1063,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiEffMethod).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -1054,10 +1076,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
((selectDB)spiEffMethod).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1235,6 +1257,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
//spiSafEmptyСontainers.addField(this, "", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -1261,10 +1284,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1886,7 +1909,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
SQLiteDatabase rdb = null;
try {
rdb = dboh.getReadableDatabase();
rdb.execSQL("update frmlocustdel_locations set del=true where frmlocustdel_uid=\'" + uid+"\'");
rdb.execSQL("update frmlocustdel_locations set del=1 where frmlocustdel_uid=\'" + uid+"\'");
ArrayList<LatLon> list = ((LatLonAdapter)latlonList.getAdapter()).latlonList;
for(int i=0;i<list.size();i++)
{
@ -1903,7 +1926,7 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
} catch (Exception e) {
}
if(exists){
stmt = wdb.compileStatement("update frmlocustdel_locations set del=false,frmlocustdel_uid=?,pos=?,lat=?,lon=? where uid=?");
stmt = wdb.compileStatement("update frmlocustdel_locations set del=0,frmlocustdel_uid=?,pos=?,lat=?,lon=? where uid=?");
stmt.bindString(1, uid);
stmt.bindLong(2, i);
stmt.bindDouble(3, list.get(i).lat);
@ -1998,9 +2021,11 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
list.clear();
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select uid,lat,lon from frmlocustdel_locations where del=false and frmlocustdel_uid='" + uid + "' order by pos", null);
String sql="select uid,lat,lon from frmlocustdel_locations where del=0 and frmlocustdel_uid='" + uid + "' order by pos";
cursor = rdb.rawQuery(sql, null);
if (cursor.moveToFirst())
{
do
@ -2008,10 +2033,10 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
list.add(new LatLon(cursor.getString(0), cursor.getDouble(1), cursor.getDouble(2)));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -2528,19 +2553,20 @@ public class LocustDelActivity extends FragmentActivity implements LocationListe
super.onStart();
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null);
cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null);
if(!cursor.moveToFirst())
{
Toast toast = Toast.makeText(getApplicationContext(),
getResources().getString(R.string.Please_authorize_the_tablet), Toast.LENGTH_LONG);
toast.show();
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();

View File

@ -608,9 +608,9 @@ public class LocustDelListActivity extends AppCompatActivity
DbOpenHelper dboh = new DbOpenHelper(LocustDelListActivity.this);
SQLiteDatabase rdb = null;
Cursor cursor =null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = null;
switch (spiList.getSelectedItemPosition())
{
case 0:
@ -686,10 +686,10 @@ public class LocustDelListActivity extends AppCompatActivity
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -705,19 +705,20 @@ public class LocustDelListActivity extends AppCompatActivity
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null);
cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null);
if(!cursor.moveToFirst())
{
Toast toast = Toast.makeText(getApplicationContext(),
getResources().getString(R.string.Please_authorize_the_tablet), Toast.LENGTH_LONG);
toast.show();
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();

View File

@ -394,6 +394,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
// Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select id, uid, name from countries where del=0 order by name", null);
@ -404,10 +405,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiCountry).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -424,6 +425,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiRegion).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select id, name from countriesregions where del=0 order by name", null);
@ -435,10 +437,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -519,6 +521,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiVegType).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -531,10 +534,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiVegType).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -549,6 +552,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiVegCover).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -561,10 +565,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiVegCover).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -602,6 +606,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
// Выбираем страны и заполняем поля
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -614,10 +619,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiInsFormulation).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -632,6 +637,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiInsDiluted).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor =null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='"
@ -643,10 +649,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiInsDiluted).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -665,6 +671,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiInsContainerState).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -677,10 +684,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiInsContainerState).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -713,6 +720,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiWindDirectionStart).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -725,10 +733,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiWindDirectionStart).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -739,6 +747,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiWindDirectionEnd).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -751,10 +760,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiWindDirectionEnd).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -765,6 +774,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprayDirectionStart).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -778,10 +788,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprayDirectionStart).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -792,6 +802,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprayDirectionEnd).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -805,10 +816,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprayDirectionEnd).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -820,6 +831,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiLocSpecies).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -832,10 +844,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiLocSpecies).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -845,6 +857,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiLocHoppers).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -857,10 +870,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiLocHoppers).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -874,6 +887,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiMainPurpose).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -886,10 +900,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiMainPurpose).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -901,6 +915,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprPlatform).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -913,10 +928,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprPlatform).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -927,6 +942,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprPlatformA).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -940,10 +956,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprPlatformA).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -954,6 +970,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprPlatformG).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select d.id, COALESCE((SELECT translation FROM _translations t JOIN _languages l ON t.language_id=l.id WHERE t.del = 0 AND identifier = d.name AND l.short_name='"
@ -966,10 +983,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprPlatformG).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -980,6 +997,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprPlatformH).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -993,10 +1011,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprPlatformH).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1085,6 +1103,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprMarking).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -1097,10 +1116,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiSprMarking).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1259,6 +1278,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiEffTypeImpact).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -1271,10 +1291,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiEffTypeImpact).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1293,6 +1313,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiEffMethod).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -1305,8 +1326,8 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiEffMethod).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1358,6 +1379,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiEffTypeImpact2).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -1370,8 +1392,8 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiEffTypeImpact2).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1388,6 +1410,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiEffMethod2).addField("", "");
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery(
@ -1400,8 +1423,8 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((selectDB)spiEffMethod2).addField(cursor.getString(cursor.getColumnIndex("name")), cursor.getString(cursor.getColumnIndex("id")));
} while (cursor.moveToNext());
}
cursor.close();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -1516,6 +1539,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
// Пустые контейнеры (выборка локализованных названий)
dboh = new DbOpenHelper(this);
rdb = null;
cursor = null;
try {
rdb = dboh.getWritableDatabase();
cursor = rdb.rawQuery(
@ -1539,8 +1563,8 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
((CheckBox) findViewById(R.id.cbBurned)).setText(cursor.getString(cursor.getColumnIndex("name")));
} while (cursor.moveToNext());
}
cursor.close();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -2877,9 +2901,10 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
list.clear();
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getWritableDatabase();
Cursor cursor = rdb.rawQuery("select uid,lat,lon from frmlocustdel_locations where frmlocustdel_uid='" + uid + "' order by pos", null);
cursor = rdb.rawQuery("select uid,lat,lon from frmlocustdel_locations where frmlocustdel_uid='" + uid + "' order by pos", null);
if (cursor.moveToFirst())
{
do
@ -2889,6 +2914,7 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
}
cursor.close();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -3190,17 +3216,18 @@ public class LocustHealthActivity extends FragmentActivity implements LocationLi
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getWritableDatabase();
Cursor cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Secure.getString(getContentResolver(), Secure.ANDROID_ID)+"';", null);
cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Secure.getString(getContentResolver(), Secure.ANDROID_ID)+"';", null);
if(!cursor.moveToFirst())
{
Toast toast = Toast.makeText(getApplicationContext(),
getResources().getString(R.string.Please_authorize_the_tablet), Toast.LENGTH_LONG);
toast.show();
}
cursor.close();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();

View File

@ -605,10 +605,10 @@ public class LocustHealthListActivity extends AppCompatActivity
DbOpenHelper dboh = new DbOpenHelper(LocustHealthListActivity.this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = null;
switch (spiList.getSelectedItemPosition())
{
case 0:
@ -618,7 +618,7 @@ public class LocustHealthListActivity extends AppCompatActivity
lh.uid as frmlocusthealth_uid,
coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
lh.date,
EXISTS(select true from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
from
frmlocusthealth lh
left join frmlocustdel ld on lh.frmlocustdel_uid=ld.uid
@ -634,7 +634,7 @@ public class LocustHealthListActivity extends AppCompatActivity
lh.uid as frmlocusthealth_uid,
coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
lh.date,
EXISTS(select true from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
from
frmlocusthealth lh
left join frmlocustdel ld on lh.frmlocustdel_uid=ld.uid
@ -651,7 +651,7 @@ public class LocustHealthListActivity extends AppCompatActivity
lh.uid as frmlocusthealth_uid,
coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
lh.date,
EXISTS(select true from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
from
frmlocusthealth lh
left join frmlocustdel ld on lh.frmlocustdel_uid=ld.uid
@ -667,11 +667,11 @@ public class LocustHealthListActivity extends AppCompatActivity
lh.uid as frmlocusthealth_uid,
coalesce(ld.district,'') || ' ' || coalesce(ld.terrain,'') terrain,
coalesce(lh.date,ld.date) as date,
EXISTS(select true from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
EXISTS(select 1 from frmlocusthealth where frmlocustdel_uid=ld.uid) as health
from
frmlocustdel ld
left join frmlocusthealth lh on lh.frmlocustdel_uid=ld.uid
where ld.del=0 and ld.filled=true
where ld.del=0 and ld.filled=1
""", null); //Все
break;
}
@ -701,6 +701,9 @@ public class LocustHealthListActivity extends AppCompatActivity
int buttonPinkStyle = R.style.ButtonPinkTheme;
ContextThemeWrapper newContext = new ContextThemeWrapper(this, R.style.ButtonPinkTheme);
btn = new MyButton(newContext, null, 0, buttonPinkStyle);
}else{
btn = new MyButton(this);
btn.setBackgroundResource(R.drawable.button_pink); // Задаете фон кнопки через drawable
}
}
if(btn==null) {
@ -747,10 +750,10 @@ public class LocustHealthListActivity extends AppCompatActivity
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -766,19 +769,20 @@ public class LocustHealthListActivity extends AppCompatActivity
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null);
cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null);
if(!cursor.moveToFirst())
{
Toast toast = Toast.makeText(getApplicationContext(),
getResources().getString(R.string.Please_authorize_the_tablet), Toast.LENGTH_LONG);
toast.show();
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();

View File

@ -582,10 +582,10 @@ public class LocustListActivity extends AppCompatActivity
DbOpenHelper dboh = new DbOpenHelper(LocustListActivity.this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
String sql;
Cursor cursor = null;
switch (spiList.getSelectedItemPosition())
{
case 0:
@ -650,11 +650,10 @@ public class LocustListActivity extends AppCompatActivity
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -668,19 +667,20 @@ public class LocustListActivity extends AppCompatActivity
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null);
cursor = rdb.rawQuery("select * from terminals where del=0 and serial='"+ Settings.Secure.getString(getContentResolver(), Settings.Secure.ANDROID_ID)+"';", null);
if(!cursor.moveToFirst())
{
Toast toast = Toast.makeText(getApplicationContext(),
getResources().getString(R.string.Please_authorize_the_tablet), Toast.LENGTH_LONG);
toast.show();
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();

View File

@ -102,18 +102,30 @@ public class MainActivity extends Activity {
boolean exest = false;
String sql;
Cursor cursor;
sql = "select 1 from frmlocust where image_name1='" + fileName + "' or image_name2='" + fileName + "' or image_name3='" + fileName + "';";
cursor = rdb.rawQuery(sql, null);
if (cursor.moveToFirst())
exest = exest | true;
cursor.close();
Cursor cursor=null;
try {
sql = "select 1 from frmlocust where image_name1='" + fileName + "' or image_name2='" + fileName + "' or image_name3='" + fileName + "';";
cursor = rdb.rawQuery(sql, null);
if (cursor.moveToFirst())
exest = exest | true;
}catch(Exception e){
e.printStackTrace();;
}finally{
cursor.close();
}
cursor=null;
try {
sql = "select 1 from frmlocustdel where image_name1='" + fileName + "' or image_name2='" + fileName + "' or image_name3='" + fileName + "';";
cursor = rdb.rawQuery(sql, null);
if (cursor.moveToFirst())
exest = exest | true;
}catch(Exception e){
e.printStackTrace();;
}finally{
cursor.close();
}
sql = "select 1 from frmlocustdel where image_name1='" + fileName + "' or image_name2='" + fileName + "' or image_name3='" + fileName + "';";
cursor = rdb.rawQuery(sql, null);
if (cursor.moveToFirst())
exest = exest | true;
cursor.close();
if (!exest) //Если в базе нет удаляем
{
@ -202,10 +214,9 @@ public class MainActivity extends Activity {
{
//Если в справочнике нет ни одной записи то перезапускаем синхронизацию (иначе отображаем главное меню)
boolean exists=false;
DbOpenHelper dboh;
Cursor cursor;
dboh = new DbOpenHelper(MainActivity.this);
DbOpenHelper dboh = new DbOpenHelper(MainActivity.this);
SQLiteDatabase rdb = null;
Cursor cursor=null;
try {
rdb = dboh.getReadableDatabase();
cursor = rdb.rawQuery("select c.id from borns c limit 1;", null);
@ -216,10 +227,10 @@ public class MainActivity extends Activity {
exists=true;
} while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){cursor.close();}
if(rdb!=null){ rdb.close(); }
}
dboh.close();

View File

@ -135,54 +135,69 @@ public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select frmlocust_uid,lat,lon from frmlocust_locations where frmlocust_uid!='"+uid+"' order by frmlocust_uid,pos;", null);
if (cursor.moveToFirst()) {
String uid="";
PolygonOptions pOptions2 = new PolygonOptions();
do {
if(!uid.equals(cursor.getString(0)) && pOptions2.getPoints().size()>1) {
Cursor cursor=null;
try {
cursor = rdb.rawQuery("select frmlocust_uid,lat,lon from frmlocust_locations where frmlocust_uid!='" + uid + "' order by frmlocust_uid,pos;", null);
if (cursor.moveToFirst()) {
String uid = "";
PolygonOptions pOptions2 = new PolygonOptions();
do {
if (!uid.equals(cursor.getString(0)) && pOptions2.getPoints().size() > 1) {
Polygon polygon = mMap.addPolygon(pOptions2);
polygons.add(polygon);
polygon.setFillColor(0x7F0000FF);
}
if (!uid.equals(cursor.getString(0))) {
pOptions2 = new PolygonOptions();
uid = cursor.getString(0);
}
pOptions2.add(new LatLng(cursor.getDouble(1), cursor.getDouble(2)));
} while (cursor.moveToNext());
if (pOptions2.getPoints().size() > 1) {
Polygon polygon = mMap.addPolygon(pOptions2);
polygons.add(polygon);
polygon.setFillColor(0x7F0000FF);
}
if(!uid.equals(cursor.getString(0))) {
pOptions2 = new PolygonOptions();
uid=cursor.getString(0);
}
pOptions2.add(new LatLng(cursor.getDouble(1), cursor.getDouble(2)));
} while (cursor.moveToNext());
if(pOptions2.getPoints().size()>1){
Polygon polygon = mMap.addPolygon(pOptions2);
polygons.add(polygon);
polygon.setFillColor(0x7F0000FF);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
}
cursor.close();
//Геозоны противосаначовой обработки
cursor = rdb.rawQuery("select frmlocustdel_uid,lat,lon from frmlocustdel_locations where frmlocustdel_uid!='"+uid+"' order by frmlocustdel_uid,pos;", null);
if (cursor.moveToFirst()) {
String uid="";
PolygonOptions pOptions2 = new PolygonOptions();
do {
if(!uid.equals(cursor.getString(0)) && pOptions2.getPoints().size()>1) {
cursor=null;
try {
cursor = rdb.rawQuery("select frmlocustdel_uid,lat,lon from frmlocustdel_locations where frmlocustdel_uid!='" + uid + "' order by frmlocustdel_uid,pos;", null);
if (cursor.moveToFirst()) {
String uid = "";
PolygonOptions pOptions2 = new PolygonOptions();
do {
if (!uid.equals(cursor.getString(0)) && pOptions2.getPoints().size() > 1) {
Polygon polygon = mMap.addPolygon(pOptions2);
polygons.add(polygon);
polygon.setFillColor(0x7FFF0000);
}
if (!uid.equals(cursor.getString(0))) {
pOptions2 = new PolygonOptions();
uid = cursor.getString(0);
}
pOptions2.add(new LatLng(cursor.getDouble(1), cursor.getDouble(2)));
} while (cursor.moveToNext());
if (pOptions2.getPoints().size() > 1) {
Polygon polygon = mMap.addPolygon(pOptions2);
polygons.add(polygon);
polygon.setFillColor(0x7FFF0000);
}
if(!uid.equals(cursor.getString(0))) {
pOptions2 = new PolygonOptions();
uid=cursor.getString(0);
}
pOptions2.add(new LatLng(cursor.getDouble(1), cursor.getDouble(2)));
} while (cursor.moveToNext());
if(pOptions2.getPoints().size()>1){
Polygon polygon = mMap.addPolygon(pOptions2);
polygons.add(polygon);
polygon.setFillColor(0x7FFF0000);
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{

View File

@ -1,5 +1,6 @@
package kz.istt.locust;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
@ -241,27 +242,33 @@ public class MySynchronizationOld
}
String geom="";
Cursor cursor2 = rdb.rawQuery("select lat,lon from frmlocust_locations where frmlocust_uid=? order by pos", new String[] { String.valueOf(uid) });
if(cursor2.moveToFirst()) {
String first="["+cursor2.getDouble(1)+","+cursor2.getDouble(0)+"]";
do {
geom+="["+cursor2.getDouble(1)+","+cursor2.getDouble(0)+"],";
}while (cursor2.moveToNext());
geom += first;
geom="{\"type\":\"Polygon\",\"coordinates\":[["+geom+"]]}";
Cursor cursor2 = null;
try {
cursor2 = rdb.rawQuery("select lat,lon from frmlocust_locations where frmlocust_uid=? order by pos", new String[]{String.valueOf(uid)});
if (cursor2.moveToFirst()) {
String first = "[" + cursor2.getDouble(1) + "," + cursor2.getDouble(0) + "]";
do {
geom += "[" + cursor2.getDouble(1) + "," + cursor2.getDouble(0) + "],";
} while (cursor2.moveToNext());
geom += first;
geom = "{\"type\":\"Polygon\",\"coordinates\":[[" + geom + "]]}";
}
xml += " <geom><![CDATA[" + geom + "]]></geom>";
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor2!=null){ cursor2.close(); }
}
xml+=" <geom><![CDATA["+geom+"]]></geom>";
cursor2.close();
xml+="</metadata>";
myThread.addRequest("sendFrmLocust","xml",MySynchronizationOld.URL+"/get/", xml, null,null,null);
}while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -316,17 +323,23 @@ public class MySynchronizationOld
xml+=" <"+cursor.getColumnName(i)+"><![CDATA["+val+"]]></"+cursor.getColumnName(i)+">\n";
}
String geom="";
Cursor cursor2 = rdb.rawQuery("select lat,lon from frmlocustdel_locations where frmlocustdel_uid=? order by pos", new String[] { String.valueOf(uid) });
if(cursor2.moveToFirst()) {
String first="["+cursor2.getDouble(1)+","+cursor2.getDouble(0)+"]";
do {
geom+="["+cursor2.getDouble(1)+","+cursor2.getDouble(0)+"],";
}while (cursor2.moveToNext());
geom += first;
geom="{\"type\":\"Polygon\",\"coordinates\":[["+geom+"]]}";
Cursor cursor2 = null;
try {
cursor2 = rdb.rawQuery("select lat,lon from frmlocustdel_locations where frmlocustdel_uid=? order by pos", new String[]{String.valueOf(uid)});
if (cursor2.moveToFirst()) {
String first = "[" + cursor2.getDouble(1) + "," + cursor2.getDouble(0) + "]";
do {
geom += "[" + cursor2.getDouble(1) + "," + cursor2.getDouble(0) + "],";
} while (cursor2.moveToNext());
geom += first;
geom = "{\"type\":\"Polygon\",\"coordinates\":[[" + geom + "]]}";
}
xml += " <geom><![CDATA[" + geom + "]]></geom>";
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor2!=null){ cursor2.close(); }
}
xml+=" <geom><![CDATA["+geom+"]]></geom>";
cursor2.close();
xml+="</metadata>";
myThread.addRequest("sendFrmLocust","xml",MySynchronizationOld.URL+"/get/", xml, null,null,null);
@ -348,29 +361,35 @@ public class MySynchronizationOld
tbl.addField(new TCField("lat",TCField.BD_FLOAT8));
tbl.getHeader(outStream);
//Переписываю значения из базы данных в outStream
Cursor cursor3 = rdb.rawQuery("select uid,del,seq,frmlocustdel_uid,pos,lon,lat from frmlocustdel_locations where frmlocustdel_uid=? order by pos", new String[] { String.valueOf(uid) });
if(cursor3.moveToFirst()) {
do {
tbl.fields.get(0).setValue(cursor3.getString(0));
tbl.fields.get(1).setValue(cursor3.getString(1));
tbl.fields.get(2).setValue(cursor3.getString(2));
tbl.fields.get(3).setValue(cursor3.getString(3));
tbl.fields.get(4).setValue(cursor3.getString(4));
tbl.fields.get(5).setDoubleVal(cursor3.getDouble(5));
tbl.fields.get(6).setDoubleVal(cursor3.getDouble(6));
tbl.getCol(outStream);
}while (cursor3.moveToNext());
Cursor cursor3 = null;
try {
cursor3 = rdb.rawQuery("select uid,del,seq,frmlocustdel_uid,pos,lon,lat from frmlocustdel_locations where frmlocustdel_uid=? order by pos", new String[]{String.valueOf(uid)});
if (cursor3.moveToFirst()) {
do {
tbl.fields.get(0).setValue(cursor3.getString(0));
tbl.fields.get(1).setValue(cursor3.getString(1));
tbl.fields.get(2).setValue(cursor3.getString(2));
tbl.fields.get(3).setValue(cursor3.getString(3));
tbl.fields.get(4).setValue(cursor3.getString(4));
tbl.fields.get(5).setDoubleVal(cursor3.getDouble(5));
tbl.fields.get(6).setDoubleVal(cursor3.getDouble(6));
tbl.getCol(outStream);
} while (cursor3.moveToNext());
}
}catch(Exception e){
e.printStackTrace();
}finally{
cursor3.close();
}
cursor3.close();
//Отправляю пакет данных на сервер для вставки либо обновления
myThread.addRequest(tbl.name,"",MySynchronizationOld.URL+"/asdc/tctable/", null,null, null, outStream.toByteArray());
}while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -434,32 +453,33 @@ public class MySynchronizationOld
}while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
}
//Для обновления справочников и загрузки старых анкет уничножения саранчи
int makeRequest(String tableName,String days,String country_id)
boolean makeRequest(String tableName,String days,String country_id)
{
String seq="";
DbOpenHelper dboh = new DbOpenHelper(_context);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select max(seq) as seq from " + tableName + ";", null);
cursor = rdb.rawQuery("select max(seq) as seq from " + tableName + ";", null);
if (cursor.moveToFirst()) {
seq = cursor.getString(cursor.getColumnIndex("seq"));
}
if (seq == null) seq = "0";
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -487,19 +507,20 @@ public class MySynchronizationOld
//Последовательно отправляю изменёные пользователям записи (send=0 и они заполнены)
DbOpenHelper dboh = new DbOpenHelper(_context);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select uid from frmlocust where send=0 and filled=1 and device_id=?", new String[]{ android_id });
cursor = rdb.rawQuery("select uid from frmlocust where send=0 and filled=1 and device_id=?", new String[]{ android_id });
if(cursor.moveToFirst())
{
do{
sendFrmLocust(cursor.getString(cursor.getColumnIndex("uid")));
}while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -507,19 +528,20 @@ public class MySynchronizationOld
//Последовательно отправляю изменёные пользователям записи (send=0 и они заполнены)
dboh = new DbOpenHelper(_context);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select uid from frmlocustdel where send=0 and filled=1 and device_id=?", new String[]{ android_id });
cursor = rdb.rawQuery("select uid from frmlocustdel where send=0 and filled=1 and device_id=?", new String[]{ android_id });
if(cursor.moveToFirst())
{
do{
sendFrmLocustDel(cursor.getString(cursor.getColumnIndex("uid")));
}while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -527,19 +549,20 @@ public class MySynchronizationOld
//Последовательно отправляю изменёные пользователям записи (send=0 и они заполнены)
dboh = new DbOpenHelper(_context);
rdb = null;
cursor =null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select uid from frmlocusthealth where send=0 and filled=1 and device_id=?", new String[]{ android_id });
cursor = rdb.rawQuery("select uid from frmlocusthealth where send=0 and filled=1 and device_id=?", new String[]{ android_id });
if(cursor.moveToFirst())
{
do{
sendFrmLocustHealth(cursor.getString(0));
}while (cursor.moveToNext());
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -585,19 +608,20 @@ public class MySynchronizationOld
//Загружаю формы саранчовых обработок за последние X дней для страны Y
dboh = new DbOpenHelper(_context);
rdb = null;
cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select t.country_id from terminals t where t.del=0 and t.serial='"+ android_id +"';", null);
cursor = rdb.rawQuery("select t.country_id from terminals t where t.del=0 and t.serial='"+ android_id +"';", null);
if(cursor.moveToFirst())
{
String country_id = cursor.getString(0);
makeRequest("frmlocustdel",String.valueOf(MySynchronizationOld.SyncDays),country_id);
makeRequest("frmlocustdel_locations",String.valueOf(MySynchronizationOld.SyncDays),country_id);
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -627,9 +651,10 @@ public class MySynchronizationOld
if(filePath==null || filePath.equals("")) return false;
File file=new File(filePath);
if(!file.exists()) return false;
FileInputStream is=null;
try
{
FileInputStream is=new FileInputStream(file);
is=new FileInputStream(file);
DbOpenHelper dbOpenHelper = new DbOpenHelper(_context);
@ -650,8 +675,6 @@ public class MySynchronizationOld
try {
doc = builder.parse(is);
} catch (Exception e) {
is.close();
file.delete();
return false;
}
@ -673,10 +696,10 @@ public class MySynchronizationOld
String uid = XMLTools.getCDATAValue(XMLTools.findFirstNode(root, "uid"));
if (uid.isBlank() || uid == "null") uid = null;
Cursor cursor;
DbOpenHelper dboh = new DbOpenHelper(_context);
SQLiteDatabase rdb = null;
SQLiteDatabase wdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
wdb = dboh.getWritableDatabase();
@ -704,6 +727,7 @@ public class MySynchronizationOld
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
if(wdb!=null){ wdb.close(); }
}
@ -714,10 +738,10 @@ public class MySynchronizationOld
String uid = XMLTools.getCDATAValue(XMLTools.findFirstNode(root, "uid"));
if (uid.isBlank() || uid == "null") uid = null;
Cursor cursor;
DbOpenHelper dboh = new DbOpenHelper(_context);
SQLiteDatabase rdb = null;
SQLiteDatabase wdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
wdb = dboh.getWritableDatabase();
@ -746,6 +770,7 @@ public class MySynchronizationOld
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
if(wdb!=null){ wdb.close(); }
}
@ -781,10 +806,11 @@ public class MySynchronizationOld
String uid = jsonObject.getString("uid");
if (uid.isBlank() || uid == "null") uid = null;
Cursor cursor;
DbOpenHelper dboh = new DbOpenHelper(_context);
SQLiteDatabase rdb = null;
SQLiteDatabase wdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
wdb = dboh.getWritableDatabase();
@ -815,6 +841,7 @@ public class MySynchronizationOld
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
if(wdb!=null){ wdb.close(); }
}
@ -831,11 +858,13 @@ public class MySynchronizationOld
Log.e("CCALM", "Unknown data type");
}
is.close();
file.delete();
} catch (Exception e) {
result = false;
}finally{
if(is!=null) { try { is.close(); } catch (IOException e) { } }
file.delete();
}
return result;
}
@ -845,10 +874,12 @@ public class MySynchronizationOld
/* Поток заданий на отправку данных на сервер */
class MyThread extends Thread
{
private int rid = 0; //Инкреминтальный номер ответа для сохранения уникальных файлов
class Tsk //Задание отправки данных
{
private static int mId=0; //Переменная для создания инкриментального идентификатора запроса
int id = 0; //Инкриментальный идентификатор запроса
String name = ""; //Название запроса для дебага
String type = ""; //Тип ожидаемого результата, такие сейчас: "xml", "json", "tbl"
@ -858,56 +889,34 @@ class MyThread extends Thread
String json = ""; //Отправляемая JSON строка
String file = ""; //Отправляемый файл
byte[] data = null; //Отправляемые данные
Boolean s = false; //Integer s = 0; // false - не отправлялось true - в процессе отправки (если ошибка то ставиться статус не отправлено иначе удаляется из списка заданий)
int id = 0; //Инкриментальный идентификатор запроса
Boolean send = false; //Integer s = 0; // false - не отправлялось true - в процессе отправки (TODO поменять на int 0=не отправлялось, 1=в процессе отправки 2=отправленно, если ошибка то прибавляется 100 к статусу)
int wait = 10; //Милисекунд ждать перед отправкой текущего задания
int t=0; //Количество совершенных попыток отправки
Tsk(){
mId++;
this.id=mId;
}
}
private int mId=0; //Инкриментальный идентификатор запроса
private Semaphore mSemaphore = null; //Семафор для доступа к списку заданий
private ArrayList<Tsk> mTList = new ArrayList<Tsk>(); //Защищёный список
private MySynchronizationOld mListener = null; //Для отправки ответов в основной поток
private String mAppPath = "";
//@SuppressLint("HandlerLeak") //Подавить предупреждения о неоптимальности
private Handler myHandle = new Handler() //Для ловли сообщений из другого потока
@SuppressLint("HandlerLeak")
private final Handler myHandle = new Handler() //Для ловли сообщений из другого потока
{
@Override
public void handleMessage(Message msg) //Слушатель ответа после отправки данных на сервер
{
String type = msg.getData().getString("type");
Boolean b = mListener.incomingData(type, msg.getData().getString("file")); //Слушатель должен вернуть true иниче запрос останется в очереди
try
{
mSemaphore.acquire();
for(int i=0; i<mTList.size();i++)
{
if(mTList.get(i).id==rid)
{
if(b) //Удаляем обработанное заданин по id
{ mTList.remove(i);
break;
}else //Не обработаное пытаемся отправить заново (но увеличив ожидание перед повтором прохода заданий на 5 минут но не больше чем раз в 30 минут)
{
mTList.get(i).wait += 1000 * 60 * 5; //Увеличиваем ожидание перед новой отправкой на 5 минут
if(mTList.get(i).wait > 1000 * 60 * 30 ) mTList.get(i).wait = 1000 * 60 * 30; //Ограничение 30 минут
mTList.get(i).s = false; //Отмечаем как не отправленное
mTList.get(i).t++; //Увиличиваем счётчик количество попыток отправки
if(mTList.get(i).t>10) mTList.remove(i); //Удаляем задание после 10 попыток отправки
break;
}
}
}
} catch (InterruptedException e)
{
e.printStackTrace();
} finally
{ mSemaphore.release();
}
boolean done = mListener.incomingData(type, msg.getData().getString("file")); //Слушатель должен вернуть true иниче запрос останется в очереди
if(!done){
Log.e("CCALM", "Failed to process data");
//TODO вывести в лог приложения и наверно отправить накопившиеся на сайт
}
}
};
@ -922,9 +931,9 @@ class MyThread extends Thread
// Добавление в задание на отправку до того как не получен ответ от предедущего запроса следующий не отсылается те. последовательно это делает (обработка результатов не в потоке загрузки а в основном потоке)
//return id запроса
public int addRequest(String name, String type,String url, String xml, String json, String file,byte[] data)
public boolean addRequest(String name, String type,String url, String xml, String json, String file,byte[] data)
{
mId++; //Инкрементируем идентификатор запроса
boolean result=false;
try
{
mSemaphore.acquire();
@ -936,15 +945,16 @@ class MyThread extends Thread
t.json = json;
t.file = file;
t.data = data;
t.s = false;
t.id = mId;
t.send = false;
mTList.add(t);
result=true;
} catch (InterruptedException ex)
{
} finally
{ mSemaphore.release();
}
return mId;
return result;
}
/**
@ -975,15 +985,30 @@ class MyThread extends Thread
//Считываем первое задание из защищёного семафором списка
tsk = null;
try {
mSemaphore.acquire();
for(int i=0;i<mTList.size();i++)
{
if(! mTList.get(i).s)
if(! mTList.get(i).send)
{ tsk = mTList.get(i);
break;
}
}
//Для дебага:
// String names="";
// int cnt1=0, cnt2=0;
// for(int i=0;i<mTList.size();i++)
// {
// cnt1++;
// if(! mTList.get(i).send)
// {
// names+=" "+mTList.get(i).name+" id="+String.valueOf(mTList.get(i).id);
// cnt2++;
// }else{
// names+=" *"+mTList.get(i).name+" id="+String.valueOf(mTList.get(i).id);
// }
// }
// Log.i("CCALM", "download task names = "+names+" cnt1 = "+String.valueOf(cnt1)+" cnt2 = "+String.valueOf(cnt2));
} catch (InterruptedException ex) {
// вот такое может произойти, если поток например прервут thread.interrupt()
} finally {
@ -994,11 +1019,11 @@ class MyThread extends Thread
if(tsk != null)
{
Log.i("CCALM", "download task = "+tsk.name);
//if(tsk.name.equals("frmlocustdel_locations")){
// Log.i("CCALM", "download task = "+tsk.name);
//}
if(tsk.name.equals("frmlocustdel_locations")){
Log.i("CCALM", "download task = "+tsk.name);
}
boolean bError=false;
tsk.s = true; //Признак отправляемости запроса на сервер
tsk.send = true; //Признак отправляемости запроса на сервер
try {
sleep(tsk.wait); //Если в задании задано сколько подождать перед запуском
@ -1010,6 +1035,7 @@ class MyThread extends Thread
{
URL url = new URL(tsk.url);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setReadTimeout(60000); //60000 = 60 секунд
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
@ -1099,8 +1125,8 @@ class MyThread extends Thread
int responseCode=conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
rid++;
String filePath = mAppPath+"/"+"data_"+ String.valueOf(rid)+".txt";
String filePath = mAppPath+"/"+"data_"+ String.valueOf(tsk.id)+".txt";
//Так как файл может быть большим и он может не поместиться в памяти то сохраняем его на диск (допустим таблица с языками очень большая)
try {
@ -1111,107 +1137,46 @@ class MyThread extends Thread
bos.write(inByte);
bis.close();
bos.close();
}catch(Exception ex)
{}
}catch(Exception e)
{
e.printStackTrace();
Log.e("CCALM", "Error: ", e);
}
//Информирую слушателя о приёме данных
Message msg = myHandle.obtainMessage();
Bundle b = new Bundle();
b.putString("file", filePath);
b.putString("type", tsk.type);
msg.setData(b);
Bundle bundle = new Bundle();
bundle.putString("file", filePath); //Путь к файлу
bundle.putString("type", tsk.type); //Тип файла
msg.setData(bundle);
myHandle.sendMessage(msg);
}else{
Log.e("CCALM", "ERROR URL = "+tsk.url+" responseCode"+String.valueOf(responseCode));
}
} catch (Exception ex) {
bError = true;
Log.i("CCALM", "URL = "+tsk.url,ex);
}
/*
HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpPost httpPost = new HttpPost(tsk.url);
if(tsk.file!=null) //Отправляем файл на сервер
{
File file = new File(tsk.file);
if(file.exists())
{
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/jpeg");
mpEntity.addPart("file", cbFile);
httpPost.setEntity(mpEntity);
}
}else //Отправляем XML строку
{
httpPost.addHeader("Content-Type", "application/xml");
StringEntity entity = new StringEntity(tsk.str, "UTF-8");
entity.setContentType("application/xml");
httpPost.setEntity(entity);
}
HttpResponse response = httpClient.execute(httpPost);
if(response != null)
{
rid++;
String filePath = mAppPath+"/"+"data_"+ String.valueOf(rid)+".txt";
//Так как файл может быть большим и он может не поместиться в памяти то сохраняем его на диск
try {
BufferedInputStream bis = new BufferedInputStream(response.getEntity().getContent());
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(filePath)));
int inByte;
while ((inByte = bis.read()) != -1) bos.write(inByte);
bis.close();
bos.close();
}catch(Exception ex)
{}
Message msg = myHandle.obtainMessage();
Bundle b = new Bundle();
b.putString("file", filePath);
b.putInt("id", tsk.id);
msg.setData(b);
myHandle.sendMessage(msg);
}else
bError = true; //Если ошибка при принятии ответа
} catch (UnsupportedEncodingException ex)
{
bError = true;
Log.i("CCALM", "Error 5 = " + ex.toString());
} catch (ClientProtocolException ex)
{
bError = true;
Log.i("CCALM", "Error 6 = " + ex.toString());
} catch (IOException ex)
{
bError = true;
Log.i("CCALM", "Error 7 = " + ex.toString());
}
*/
if(bError) //Если произошла ошибка при отправке.
{
tsk.wait += 1000 * 60 * 1; //Увеличиваем ожидание перед новой отправкой на 1 минуту
if(tsk.wait > 1000 * 60 * 10 ) tsk.wait = 1000 * 60 * 10; //Ограничение 10 минут
tsk.s = false; //Отмечаем как не отправленное
tsk.t++; //Увеличиваем счётчик количество попыток отправки
if(tsk.t>5) //Удаляем задание после 10 попыток отправки
{
try {
mSemaphore.acquire();
mTList.remove(tsk);
} catch (InterruptedException ex)
{
// вот такое может произойти, если поток например прервут thread.interrupt()
} finally
{
mSemaphore.release(); //Отдаем семафор
}
}
}
//TODO при старте можно проверять совершен ли полный цикл загрузки без ошибок
//Удаляю задание независемо как оно отработало (пусть на верхнем уровне думают пускать ли задание повторно)
try
{
mSemaphore.acquire();
for(int i=0; i<mTList.size();i++)
{
if(mTList.get(i).id==tsk.id)
{
mTList.remove(i);
break;
}
}
} catch (Exception e)
{
e.printStackTrace();
} finally
{ mSemaphore.release();
}
}

View File

@ -121,9 +121,10 @@ public class ScanActivity extends Activity {
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
Cursor cursor = rdb.rawQuery("select " +
cursor = rdb.rawQuery("select " +
" cr.name as country_name," +
" cp.name as company_name," +
" t.name " +
@ -138,10 +139,10 @@ public class ScanActivity extends Activity {
tvOrganization.setText(cursor.getString(cursor.getColumnIndex("company_name")));
tvName.setText(cursor.getString(cursor.getColumnIndex("name")));
}
cursor.close();
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
}
dboh.close();
@ -252,15 +253,16 @@ public class ScanActivity extends Activity {
DbOpenHelper dboh = new DbOpenHelper(this);
SQLiteDatabase rdb = null;
SQLiteDatabase wdb = null;
Cursor cursor = null;
try {
rdb = dboh.getReadableDatabase();
wdb = dboh.getWritableDatabase();
Cursor cursor = rdb.rawQuery(sql, null);
cursor = rdb.rawQuery(sql, null);
if(cursor.moveToFirst())
{
exists=true;
}
cursor.close();
if(exists){
sql="update terminals set country_id=?,company_id=?,name=?,serial=? where id=?";
SQLiteStatement stmt = wdb.compileStatement(sql);
@ -283,6 +285,7 @@ public class ScanActivity extends Activity {
}catch(Exception e){
e.printStackTrace();
}finally{
if(cursor!=null){ cursor.close(); }
if(rdb!=null){ rdb.close(); }
if(wdb!=null){ wdb.close(); }
}

View File

@ -54,7 +54,7 @@ public class Tools
StringBuilder result = new StringBuilder();
int length;
while ((length = is.read(buffer)) != -1) {
result.append(new String(buffer, 0, length, StandardCharsets.UTF_8));
result.append(new String(buffer, 0, length, "UTF-8")); // StandardCharsets.UTF_8.name() > JDK 7
}
return result.toString();
} catch (IOException e) {