public void asyncJson() { ConstantData.Displayprogress(Login.this); //perform a Google search in just a few lines of code JSONObject postJson = new JSONObject(); JSONObject obj = new JSONObject(); JSONArray array = new JSONArray(); TelephonyManager telephonyManager = (TelephonyManager) Login.this .getSystemService(Context.TELEPHONY_SERVICE); try { obj.put("userid", "" + etemail.getText()); obj.put("password", "" + etpassword.getText()); obj.put("deviceId", "" + telephonyManager.getDeviceId()); Log.i("json", obj.toString()); } catch (Exception e) { // TODO: handle exception } final AQuery aq = new AQuery(Login.this); aq.post(ConstantData.LoginSevice, obj, JSONObject.class, new AjaxCallback<JSONObject>() { @Override public void callback(String url, JSONObject json, AjaxStatus status) { if (json != null) { try { ConstantData.progressclose(Login.this); JsonResult jsonResult = new JsonResult(); JsonElement json2 = new JsonParser() .parse(json.toString()); Type type = new TypeToken<JsonResult>() { }.getType(); jsonResult = new Gson().fromJson(json2, type); if (jsonResult.getResult().equalsIgnoreCase("success")) { if (jsonResult.getData().isToken()) { SharedPreferences editor = getSharedPreferences( ConstantData.MyPREFERENCES, 0); SharedPreferences.Editor editor2 = editor .edit(); Intent intent = new Intent(Login.this, FragmentContainerActivity.class); if (editor.getString("userid", "").equalsIgnoreCase("")) intent.putExtra("isfirsttime", true); else intent.putExtra("isfirsttime", false); if (ck_reamind.isChecked()) editor2.putBoolean("checked", true); else editor2.putBoolean("checked", false); editor2.putString("userid", etemail .getText().toString()); editor2.putString("password", etpassword .getText().toString()); editor2.commit(); String urll = jsonResult.getData().getProfile().getUpLoadPhoto(); urll = urll.replace("~", ""); Log.v("path is", ConstantData.DISPLAY_PICTUR_URL + urll); new LoadImage().execute(ConstantData.DISPLAY_PICTUR_URL + urll); if (ck_reamind.isChecked()) Util.setSharePrefranceData(Login.this, jsonResult.getData().getProfile().getJsonString(), ConstantData.SHARED_PREFERENCES_Profile_Object); startActivity(intent); finish(); // Toast.makeText(aq.getContext(), jsonData.getString(ConstantData.MESSAGE), Toast.LENGTH_LONG).show(); } else { ConstantData.DisplayAlert("Message", jsonResult.getData().getMessage(), Login.this); } } } catch (Exception ex) { Toast.makeText(aq.getContext(), "Error :" + json.toString(), Toast.LENGTH_LONG).show(); } } else { ConstantData.progressclose(Login.this); //ajax error, show error code Toast.makeText(aq.getContext(), "Error:" + status.getCode(), Toast.LENGTH_LONG).show(); } } }); }
Friday, 29 April 2016
aquiry
constant data
package com.cygnus.apmlive;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.view.Window;
import com.datatype.apmtest.RecallingData;
import com.datatype.apmtest.UserData;
public class ConstantData {
// public static UserData LoginUser;
public static UserData LoginUser;
static Dialog dialog;
static Dialog dialog2;
static Dialog dialog_;
// Pref to Store user data
public static final String MyPREFERENCES = "MyPrefsSwift";
public static String customername = "";
public static String officername = "";
public static String totalcft = "";
public static String decvalue = "";
public static String imei = "";
public static final String ServerUrl = "http://223.30.71.118/Service2.svc/";
public static final String ServerUrl_survey = "http://223.30.71.117//ApplicationDoc//SurveyPDF//";
public static final String ServerUrl_quotation = "http://223.30.71.117//ApplicationDoc//QuotationPDF//";
public static final String ServerUrl_cfr = "http://223.30.71.117//ApplicationDoc//CFRPDF//";
public static final String ServerUrl_Docket = "http://223.30.71.118/Service3.svc/";
public static Docket_data passdata ;
public static String CardType = "";
public static String CustomerMobile = "";
public static String ExternalRefNum = "";
public static String InvoiceNumber = "";
public static String NameOnCard = "";
public static String PaymentMode = "";
public static String TransactionId = "";
public static double Amount = 0.00;
public static String AuthCode = "";
public static String BatchNumber = "";
public static String LastFourDigits = "";
public static String gcnumber = "";
public static String Version = "";
public static RecallingData passrecalling;
// ===============wishal===========
public static String parseenqdatass;
// ==========================
// public static CfrData cfrdatas;
public static String parseenqdatassss;
public static String directpassenquirydata;
public static JSONObject passenquirydataforsurvey;
public static String lat = "0.00";
public static String lon = "0.00";
public static boolean isValidEmail(String email) {
String EMAIL_PATTERN = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
Pattern pattern = Pattern.compile(EMAIL_PATTERN);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
public static void SetUserData(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(
MyPREFERENCES, Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.putString(UserData.prefpassword, LoginUser.password);
editor.putString(UserData.prefBrachName, LoginUser.getBrachName());
editor.putString(UserData.prefBranchCode, LoginUser.getBranchCode());
String RemoveSpaceUserId = LoginUser.getUserId().trim();
Log.v("removespace", "msg" + RemoveSpaceUserId);
editor.putString(UserData.prefUserId, RemoveSpaceUserId);
editor.putString(UserData.prefName, LoginUser.getName());
editor.commit();
}
public static UserData GetUserData(Context context) {
SharedPreferences prefs = context.getSharedPreferences(MyPREFERENCES,
Context.MODE_PRIVATE);
ConstantData.LoginUser = new UserData();
try {
ConstantData.LoginUser.password = prefs.getString(
UserData.prefpassword, "");
ConstantData.LoginUser.setBrachName(prefs.getString(
UserData.prefBrachName, ""));
ConstantData.LoginUser.setBranchCode(prefs.getString(
UserData.prefBranchCode, ""));
ConstantData.LoginUser.setName(prefs.getString(UserData.prefName,
""));
ConstantData.LoginUser.setUserId(prefs.getString(
UserData.prefUserId, ""));
} catch (Exception e) {
ConstantData.LoginUser.setUserId("");
ConstantData.LoginUser.password = "";
}
return ConstantData.LoginUser;
}
public static SimpleDateFormat dateformate = new SimpleDateFormat(
"dd MMM yyyy");
public static SimpleDateFormat dateformatesurvey = new SimpleDateFormat(
"dd MMM yyyy HH:mm");
public static Object cfrparsdata;
public static JSONObject passcfrdata;
// public static CfrDatass passcfrfield;
public static String getDateFromJson(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformate.format(time));
} catch (Exception e) {
return "Date issue";
}
}
public static String getDateFromJsonSurvey(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformatesurvey.format(time));
} catch (Exception e) {
return "Date issue";
}
}
public static String getwsDateJson(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformate.format(time));
} catch (Exception e) {
jsonDate = "01 Jan 1990";
return jsonDate;
}
}
public static void DisplayAlert(String title, String message,
Context context) {
AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setTitle(title);
builder1.setMessage(message);
builder1.setCancelable(true);
builder1.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
public static void Displayprogress(Context context) {
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressbarr);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
public static void Displayprogress_cfr(Context context) {
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressbarr);
dialog.show();
}
public static void close_cfr_progress(Context context) {
dialog.dismiss();
}
public static void Displayprogress_download(Context context) {
dialog2 = new Dialog(context);
dialog2.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog2.setContentView(R.layout.progress_download);
dialog2.setCanceledOnTouchOutside(false);
dialog2.setCancelable(false);
dialog2.show();
}
public static void progressclose_download(Context context) {
dialog2.dismiss();
}
public static void Displayprogress1(Context context) {
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.loadingemail);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.show();
}
public static void progressclose(Context context) {
dialog.dismiss();
}
public static void ClearUserData(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(
MyPREFERENCES, Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.clear();
editor.commit();
}
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
public static boolean isNetworkConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null)
return false;
else
return true;// return isInternetAvailable(context);
}
public static boolean isInternetAvailable(Context context) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet(ConstantData.ServerUrl);
httppost.addHeader("Content-Type", "multipart/form-data");
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() == 200) {
return true;
}
} catch (Exception e) {
Log.i("exce", "" + e.toString());
}
return false;
}
}
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONObject;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.view.Window;
import com.datatype.apmtest.RecallingData;
import com.datatype.apmtest.UserData;
public class ConstantData {
// public static UserData LoginUser;
public static UserData LoginUser;
static Dialog dialog;
static Dialog dialog2;
static Dialog dialog_;
// Pref to Store user data
public static final String MyPREFERENCES = "MyPrefsSwift";
public static String customername = "";
public static String officername = "";
public static String totalcft = "";
public static String decvalue = "";
public static String imei = "";
public static final String ServerUrl = "http://223.30.71.118/Service2.svc/";
public static final String ServerUrl_survey = "http://223.30.71.117//ApplicationDoc//SurveyPDF//";
public static final String ServerUrl_quotation = "http://223.30.71.117//ApplicationDoc//QuotationPDF//";
public static final String ServerUrl_cfr = "http://223.30.71.117//ApplicationDoc//CFRPDF//";
public static final String ServerUrl_Docket = "http://223.30.71.118/Service3.svc/";
public static Docket_data passdata ;
public static String CardType = "";
public static String CustomerMobile = "";
public static String ExternalRefNum = "";
public static String InvoiceNumber = "";
public static String NameOnCard = "";
public static String PaymentMode = "";
public static String TransactionId = "";
public static double Amount = 0.00;
public static String AuthCode = "";
public static String BatchNumber = "";
public static String LastFourDigits = "";
public static String gcnumber = "";
public static String Version = "";
public static RecallingData passrecalling;
// ===============wishal===========
public static String parseenqdatass;
// ==========================
// public static CfrData cfrdatas;
public static String parseenqdatassss;
public static String directpassenquirydata;
public static JSONObject passenquirydataforsurvey;
public static String lat = "0.00";
public static String lon = "0.00";
public static boolean isValidEmail(String email) {
String EMAIL_PATTERN = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";
Pattern pattern = Pattern.compile(EMAIL_PATTERN);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
public static void SetUserData(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(
MyPREFERENCES, Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.putString(UserData.prefpassword, LoginUser.password);
editor.putString(UserData.prefBrachName, LoginUser.getBrachName());
editor.putString(UserData.prefBranchCode, LoginUser.getBranchCode());
String RemoveSpaceUserId = LoginUser.getUserId().trim();
Log.v("removespace", "msg" + RemoveSpaceUserId);
editor.putString(UserData.prefUserId, RemoveSpaceUserId);
editor.putString(UserData.prefName, LoginUser.getName());
editor.commit();
}
public static UserData GetUserData(Context context) {
SharedPreferences prefs = context.getSharedPreferences(MyPREFERENCES,
Context.MODE_PRIVATE);
ConstantData.LoginUser = new UserData();
try {
ConstantData.LoginUser.password = prefs.getString(
UserData.prefpassword, "");
ConstantData.LoginUser.setBrachName(prefs.getString(
UserData.prefBrachName, ""));
ConstantData.LoginUser.setBranchCode(prefs.getString(
UserData.prefBranchCode, ""));
ConstantData.LoginUser.setName(prefs.getString(UserData.prefName,
""));
ConstantData.LoginUser.setUserId(prefs.getString(
UserData.prefUserId, ""));
} catch (Exception e) {
ConstantData.LoginUser.setUserId("");
ConstantData.LoginUser.password = "";
}
return ConstantData.LoginUser;
}
public static SimpleDateFormat dateformate = new SimpleDateFormat(
"dd MMM yyyy");
public static SimpleDateFormat dateformatesurvey = new SimpleDateFormat(
"dd MMM yyyy HH:mm");
public static Object cfrparsdata;
public static JSONObject passcfrdata;
// public static CfrDatass passcfrfield;
public static String getDateFromJson(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformate.format(time));
} catch (Exception e) {
return "Date issue";
}
}
public static String getDateFromJsonSurvey(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformatesurvey.format(time));
} catch (Exception e) {
return "Date issue";
}
}
public static String getwsDateJson(String jsonDate) {
try {
jsonDate = jsonDate.substring(jsonDate.indexOf("(") + 1,
jsonDate.indexOf(")"));
Date time = new Date(Long.valueOf(jsonDate));
return ("" + dateformate.format(time));
} catch (Exception e) {
jsonDate = "01 Jan 1990";
return jsonDate;
}
}
public static void DisplayAlert(String title, String message,
Context context) {
AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setTitle(title);
builder1.setMessage(message);
builder1.setCancelable(true);
builder1.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
public static void Displayprogress(Context context) {
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressbarr);
dialog.setCancelable(false);
dialog.setCanceledOnTouchOutside(false);
dialog.show();
}
public static void Displayprogress_cfr(Context context) {
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.progressbarr);
dialog.show();
}
public static void close_cfr_progress(Context context) {
dialog.dismiss();
}
public static void Displayprogress_download(Context context) {
dialog2 = new Dialog(context);
dialog2.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog2.setContentView(R.layout.progress_download);
dialog2.setCanceledOnTouchOutside(false);
dialog2.setCancelable(false);
dialog2.show();
}
public static void progressclose_download(Context context) {
dialog2.dismiss();
}
public static void Displayprogress1(Context context) {
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.loadingemail);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(false);
dialog.show();
}
public static void progressclose(Context context) {
dialog.dismiss();
}
public static void ClearUserData(Context context) {
SharedPreferences sharedpreferences = context.getSharedPreferences(
MyPREFERENCES, Context.MODE_PRIVATE);
Editor editor = sharedpreferences.edit();
editor.clear();
editor.commit();
}
public static boolean isTablet(Context context) {
return (context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}
public static boolean isNetworkConnected(Context context) {
ConnectivityManager cm = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo ni = cm.getActiveNetworkInfo();
if (ni == null)
return false;
else
return true;// return isInternetAvailable(context);
}
public static boolean isInternetAvailable(Context context) {
try {
HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet(ConstantData.ServerUrl);
httppost.addHeader("Content-Type", "multipart/form-data");
HttpResponse response = httpclient.execute(httppost);
if (response.getStatusLine().getStatusCode() == 200) {
return true;
}
} catch (Exception e) {
Log.i("exce", "" + e.toString());
}
return false;
}
}
database helper
package com.ibv.ibvfinance;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.IBinder;
import android.util.Log;
public class Databasehelper extends SQLiteOpenHelper {
private SQLiteDatabase myDataBase;
private final Context myContext;
private static final String DATABASE_NAME = "ibv";// "db.sqlite";
@SuppressLint("SdCardPath")
public final static String DATABASE_PATH = "/data/data/com.ibv.ibvfinance/databases/";
public static final int DATABASE_VERSION = 1;
private static final String TABAL_ibv = "ibvtb";
private static final String TABAL_goal = "goal";
private static final String TABAL_COUNTER = "counter";
@SuppressLint("SimpleDateFormat")
private SimpleDateFormat dateformate = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
public Databasehelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.myContext = context;
}
// Create a empty database on the system
public void createDataBase() throws IOException {
boolean dbExist = checkDataBase();
if (dbExist) {
Log.v("DB Exists", "db exists");
} else {
this.getReadableDatabase();
try {
this.close();
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
// Check database already exist or not
private boolean checkDataBase() {
boolean checkDB = false;
try {
String myPath = DATABASE_PATH + DATABASE_NAME;
File dbfile = new File(myPath);
checkDB = dbfile.exists();
} catch (SQLiteException e) {
System.out.println("delete database file.");
}
return checkDB;
}
// Copies your database from your local assets-folder to the just created
// empty database in the system folder
private void copyDataBase() throws IOException {
String outFileName = DATABASE_PATH + DATABASE_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
InputStream myInput = myContext.getAssets().open(DATABASE_NAME);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myInput.close();
myOutput.flush();
myOutput.close();
}
// delete database
public void db_delete() {
File file = new File(DATABASE_PATH + DATABASE_NAME);
if (file.exists()) {
file.delete();
System.out.println("delete database file.");
}
}
// Open database
public void openDatabase() throws SQLException {
String myPath = DATABASE_PATH + DATABASE_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READWRITE);
}
public synchronized void closeDataBase() throws SQLException {
if (myDataBase != null)
myDataBase.close();
super.close();
}
public boolean onSubmitForGcNo(HashMap<String, String> caclulatedData) {
return false;
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion > oldVersion) {
Log.v("Database Upgrade", "Database version higher than old.");
db_delete();
}
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
//--------------chating function----
// --insert chating data to offline-----
public boolean Insert_Goal(String date , String time , String userid, String goal, String task)
{
String Quiry = "insert into "+ TABAL_ibv+ " (date , time , userid , goal , work) values ('"+date+"' , '"+time+"' , '"+userid+"' , '"+goal+"' , '"+task+"')";
try {
myDataBase.execSQL(Quiry);
Log.v("insert", "success");
return true;
} catch (Exception e) {
Log.v("insert error", ""+e.toString());
return false;
}
}
public void Insert_place(String place)
{
String Quiry = "insert into "+ TABAL_goal+ " (name) values ('"+place+"')";
try {
myDataBase.execSQL(Quiry);
Log.v("insert", "success place");
} catch (Exception e) {
Log.v("insert error place", ""+e.toString());
}
}
public void InsertCounter(int value)
{
int id = 1;
String Quiry = "insert into "+ TABAL_COUNTER+ " (id , value) values ('"+id+"','"+value+"',)";
try {
myDataBase.execSQL(Quiry);
Log.v("insert", "success");
} catch (Exception e) {
Log.v("insert error", ""+e.toString());
}
}
public void UpdateCounter(int value)
{
String Quiry = "Update "+ TABAL_COUNTER + " set value='"+value+"' WHERE id=1";
try {
myDataBase.execSQL(Quiry);
Log.v("insert", "success");
} catch (Exception e) {
Log.v("insert error", ""+e.toString());
}
}
public List<String> get_place()
{
String quiry = "Select * from "+TABAL_goal+ "";
List<String> goallist = new ArrayList<String>();
try {
Cursor cursor = myDataBase.rawQuery(quiry, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
goallist.add(cursor.getString(0));
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}
return goallist;
}
public List<Datatype> get_all_from_goalName(String goalname ,String userid ,String fromdt ,String todt)
{
fromdt = "\'"+fromdt+"\'";
todt = "\'"+todt+"\'";
String quiry = "SELECT * FROM ibvtb WHERE goal='"+goalname +"' AND userid='"+userid +"' AND date BETWEEN "+fromdt+" AND "+todt+" order by id desc";
List<Datatype> goallist = new ArrayList<Datatype>();
try {
Cursor cursor = myDataBase.rawQuery(quiry, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
Datatype d = new Datatype();
d.setDate_offline(cursor.getString(0));
d.setTime_offline(cursor.getString(1));
d.setGoal_offline(cursor.getString(3));
d.setWork_offline(cursor.getString(4));
goallist.add(d);
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}
return goallist;
}
public List<Datatype> get_all(String fromdt ,String todt , String userid )
{
fromdt = "\'"+fromdt+"\'";
todt = "\'"+todt+"\'";
String quiry = "SELECT * FROM ibvtb WHERE userid='"+userid +"' AND date BETWEEN "+fromdt+" AND "+todt+" order by id desc";
// String quiry = "Select * from "+TABAL_ibv+ "";
List<Datatype> goallist = new ArrayList<Datatype>();
try {
Cursor cursor = myDataBase.rawQuery(quiry, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
Datatype d = new Datatype();
d.setDate_offline(cursor.getString(0));
d.setTime_offline(cursor.getString(1));
d.setGoal_offline(cursor.getString(3));
d.setWork_offline(cursor.getString(4));
goallist.add(d);
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}
return goallist;
}
public List<String> getcounter(String id)
{
String quiry = "Select * from "+TABAL_COUNTER+ " Where id='"+id+"'";
List<String> chatlist = new ArrayList<String>();
try {
Cursor cursor = myDataBase.rawQuery(quiry, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
chatlist.add(cursor.getString(0));
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}
return chatlist;
}
}
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.annotation.SuppressLint;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.IBinder;
import android.util.Log;
public class Databasehelper extends SQLiteOpenHelper {
private SQLiteDatabase myDataBase;
private final Context myContext;
private static final String DATABASE_NAME = "ibv";// "db.sqlite";
@SuppressLint("SdCardPath")
public final static String DATABASE_PATH = "/data/data/com.ibv.ibvfinance/databases/";
public static final int DATABASE_VERSION = 1;
private static final String TABAL_ibv = "ibvtb";
private static final String TABAL_goal = "goal";
private static final String TABAL_COUNTER = "counter";
@SuppressLint("SimpleDateFormat")
private SimpleDateFormat dateformate = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
public Databasehelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.myContext = context;
}
// Create a empty database on the system
public void createDataBase() throws IOException {
boolean dbExist = checkDataBase();
if (dbExist) {
Log.v("DB Exists", "db exists");
} else {
this.getReadableDatabase();
try {
this.close();
copyDataBase();
} catch (IOException e) {
throw new Error("Error copying database");
}
}
}
// Check database already exist or not
private boolean checkDataBase() {
boolean checkDB = false;
try {
String myPath = DATABASE_PATH + DATABASE_NAME;
File dbfile = new File(myPath);
checkDB = dbfile.exists();
} catch (SQLiteException e) {
System.out.println("delete database file.");
}
return checkDB;
}
// Copies your database from your local assets-folder to the just created
// empty database in the system folder
private void copyDataBase() throws IOException {
String outFileName = DATABASE_PATH + DATABASE_NAME;
OutputStream myOutput = new FileOutputStream(outFileName);
InputStream myInput = myContext.getAssets().open(DATABASE_NAME);
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer)) > 0) {
myOutput.write(buffer, 0, length);
}
myInput.close();
myOutput.flush();
myOutput.close();
}
// delete database
public void db_delete() {
File file = new File(DATABASE_PATH + DATABASE_NAME);
if (file.exists()) {
file.delete();
System.out.println("delete database file.");
}
}
// Open database
public void openDatabase() throws SQLException {
String myPath = DATABASE_PATH + DATABASE_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null,
SQLiteDatabase.OPEN_READWRITE);
}
public synchronized void closeDataBase() throws SQLException {
if (myDataBase != null)
myDataBase.close();
super.close();
}
public boolean onSubmitForGcNo(HashMap<String, String> caclulatedData) {
return false;
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (newVersion > oldVersion) {
Log.v("Database Upgrade", "Database version higher than old.");
db_delete();
}
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
}
//--------------chating function----
// --insert chating data to offline-----
public boolean Insert_Goal(String date , String time , String userid, String goal, String task)
{
String Quiry = "insert into "+ TABAL_ibv+ " (date , time , userid , goal , work) values ('"+date+"' , '"+time+"' , '"+userid+"' , '"+goal+"' , '"+task+"')";
try {
myDataBase.execSQL(Quiry);
Log.v("insert", "success");
return true;
} catch (Exception e) {
Log.v("insert error", ""+e.toString());
return false;
}
}
public void Insert_place(String place)
{
String Quiry = "insert into "+ TABAL_goal+ " (name) values ('"+place+"')";
try {
myDataBase.execSQL(Quiry);
Log.v("insert", "success place");
} catch (Exception e) {
Log.v("insert error place", ""+e.toString());
}
}
public void InsertCounter(int value)
{
int id = 1;
String Quiry = "insert into "+ TABAL_COUNTER+ " (id , value) values ('"+id+"','"+value+"',)";
try {
myDataBase.execSQL(Quiry);
Log.v("insert", "success");
} catch (Exception e) {
Log.v("insert error", ""+e.toString());
}
}
public void UpdateCounter(int value)
{
String Quiry = "Update "+ TABAL_COUNTER + " set value='"+value+"' WHERE id=1";
try {
myDataBase.execSQL(Quiry);
Log.v("insert", "success");
} catch (Exception e) {
Log.v("insert error", ""+e.toString());
}
}
public List<String> get_place()
{
String quiry = "Select * from "+TABAL_goal+ "";
List<String> goallist = new ArrayList<String>();
try {
Cursor cursor = myDataBase.rawQuery(quiry, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
goallist.add(cursor.getString(0));
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}
return goallist;
}
public List<Datatype> get_all_from_goalName(String goalname ,String userid ,String fromdt ,String todt)
{
fromdt = "\'"+fromdt+"\'";
todt = "\'"+todt+"\'";
String quiry = "SELECT * FROM ibvtb WHERE goal='"+goalname +"' AND userid='"+userid +"' AND date BETWEEN "+fromdt+" AND "+todt+" order by id desc";
List<Datatype> goallist = new ArrayList<Datatype>();
try {
Cursor cursor = myDataBase.rawQuery(quiry, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
Datatype d = new Datatype();
d.setDate_offline(cursor.getString(0));
d.setTime_offline(cursor.getString(1));
d.setGoal_offline(cursor.getString(3));
d.setWork_offline(cursor.getString(4));
goallist.add(d);
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}
return goallist;
}
public List<Datatype> get_all(String fromdt ,String todt , String userid )
{
fromdt = "\'"+fromdt+"\'";
todt = "\'"+todt+"\'";
String quiry = "SELECT * FROM ibvtb WHERE userid='"+userid +"' AND date BETWEEN "+fromdt+" AND "+todt+" order by id desc";
// String quiry = "Select * from "+TABAL_ibv+ "";
List<Datatype> goallist = new ArrayList<Datatype>();
try {
Cursor cursor = myDataBase.rawQuery(quiry, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
Datatype d = new Datatype();
d.setDate_offline(cursor.getString(0));
d.setTime_offline(cursor.getString(1));
d.setGoal_offline(cursor.getString(3));
d.setWork_offline(cursor.getString(4));
goallist.add(d);
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}
return goallist;
}
public List<String> getcounter(String id)
{
String quiry = "Select * from "+TABAL_COUNTER+ " Where id='"+id+"'";
List<String> chatlist = new ArrayList<String>();
try {
Cursor cursor = myDataBase.rawQuery(quiry, null);
if (cursor.getCount() > 0) {
if (cursor.moveToFirst()) {
do {
chatlist.add(cursor.getString(0));
} while (cursor.moveToNext());
}
}
} catch (Exception e) {
// TODO: handle exception
}
return chatlist;
}
}
Subscribe to:
Posts (Atom)