Skip to content

Commit

Permalink
[ADD] External library tools
Browse files Browse the repository at this point in the history
  • Loading branch information
sergio-teruel committed Dec 30, 2014
1 parent 033c763 commit 056a11e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 5 deletions.
1 change: 1 addition & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 26 additions & 1 deletion app/src/main/java/es/incaser/apps/stockcontrol/DbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class DbAdapter extends SQLiteOpenHelper {
{"MovimientoStock", "SELECT * FROM MovimientoStock", "AcumuladoStock=0"},
//{"INC_Incidencias", "SELECT * FROM INC_Incidencias", "INC_PendienteSync <> 0"},
//Fin Tablas a importar
{"MovimientosArticuloSerie", "SELECT * FROM MovimientosArticuloSerie", "(FechaRegistro > { fn NOW() } - 3)"},
{"MovimientosArticuloSerie", "SELECT * FROM MovimientosArticuloSerie", "(FechaRegistro > GETDATE() - 3)"},
};
public static int tablesToImport = 4; // Modificar en caso de añadir mas tablas
public static int tablesToExport = 4; // Exportar tablas a partir de este indice
Expand Down Expand Up @@ -112,6 +112,31 @@ public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}

public void recreateDb(){
for (String[] query : QUERY_LIST) {
db.execSQL("DROP TABLE IF EXISTS " + query[0]);
}
onCreate(db);
}

public boolean checkTables(){
String tableList = "";
int i = 0;
for (String[] query : QUERY_LIST) {
if (i > 0){
tableList = tableList + ",";
}
tableList = tableList + "'" + query + "'";
i ++;
}
Cursor curtmp = getCursor("Select * from sqlite_master WHERE name IN (" + tableList + ")");
if (curtmp.getCount() == i){
return true;
}else {
return false;
}
}

public void emptyTables() {
for (String[] query : QUERY_LIST) {
db.execSQL("DELETE FROM " + query[0]);
Expand Down
34 changes: 30 additions & 4 deletions app/src/main/java/es/incaser/apps/stockcontrol/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package es.incaser.apps.stockcontrol;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
Expand All @@ -14,13 +17,13 @@


public class MainActivity extends ActionBarActivity {

Timer timer = new Timer();

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

launchHardSync();
ReadPreferences(this);
}

@Override
Expand Down Expand Up @@ -50,6 +53,9 @@ public void onClickButtons(View view){
switch (view.getId()){
case R.id.btn_sync:
//forzamos el proceso de sincronizacion de los movimientos
//DbAdapter dbAdapter = new DbAdapter(getApplicationContext());
//dbAdapter.recreateDb();
launchHardSync();
break;
case R.id.btn_entradas_previstas:
break;
Expand Down Expand Up @@ -80,7 +86,6 @@ public void handleMessage(Message msg) {

private void launchHardSync(){
TimerTaskHard timerTaskHard = new TimerTaskHard(handler, getApplicationContext());
Timer timer = new Timer();
timer.schedule(timerTaskHard, 1500, 5000);
}

Expand All @@ -89,4 +94,25 @@ private void launchHardSync(){
// Timer timer = new Timer();
// timer.schedule(timerTaskHard, 1500, 5000);
// }



public static void ReadPreferences(Activity act) {
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(act);
if (pref.getBoolean("pref_out_office", false)) {
SQLConnection.host = pref.getString("pref_sql_host_remote", "");
} else {
SQLConnection.host = pref.getString("pref_sql_host", "");
}
SQLConnection.port = pref.getString("pref_sql_port", "");
SQLConnection.user = pref.getString("pref_sql_user", "");
SQLConnection.password = pref.getString("pref_sql_password", "");
SQLConnection.database = pref.getString("pref_sql_database", "");
}

@Override
protected void onDestroy() {
timer.cancel();
super.onDestroy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static es.incaser.apps.tools.Tools.str2date;


/**
* Created by sergio on 23/09/14.
*/
Expand Down

0 comments on commit 056a11e

Please sign in to comment.