Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Android.App;
- using Android.Content;
- using Android.OS;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- using SQLite;
- using P4AndroidApp.Model;
- using Android.Util;
- namespace P4AndroidApp.Resources.Datahelp
- {
- public class DataBase
- {
- public static string folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
- #pragma warning disable IDE1006 // Naming Styles
- public static bool createDataBase()
- {
- try
- {
- using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db3")))
- {
- connection.CreateTable<Person>();
- return true;
- }
- }
- catch (SQLiteException ex)
- {
- Log.Info("SQLiteEx", ex.Message);
- return false;
- }
- }
- public static bool InsertIntoTablePerson(Person person)
- {
- try
- {
- using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db3")))
- {
- connection.Insert(person);
- return true;
- }
- }
- catch (SQLiteException ex)
- {
- Log.Info("SQLiteEx", ex.Message);
- return false;
- }
- }
- public static List<Person> selectTablePerson()
- {
- try
- {
- using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db3")))
- {
- return connection.Table<Person>().ToList();
- }
- }
- catch (SQLiteException ex)
- {
- Log.Info("SQLiteEx", ex.Message);
- return null;
- }
- }
- public static bool updateTablePerson(Person person)
- {
- try
- {
- using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db3")))
- {
- connection.Query<Person>("UPDATE Person set Username=?,Password=?,Firstname=?,Lastname=?,Weight=? Where Id=?", person.Username, person.Password, person.Firstname, person.Lastname, person.Weight, person.Id);
- return true;
- }
- }
- catch (SQLiteException ex)
- {
- Log.Info("SQLiteEx", ex.Message);
- return false;
- }
- }
- public static bool selectQueryTablePerson(int Id)
- {
- try
- {
- using (var connection = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db3")))
- {
- connection.Query<Person>("Select * FROM Person Where Id=?", Id);
- return true;
- }
- }
- catch (SQLiteException ex)
- {
- Log.Info("SQLiteEx", ex.Message);
- return false;
- }
- }
- public static Boolean CheckIsDataAlreadyInDBorNot(string TableName,
- string dbfield, string fieldValue)
- {
- var check = new SQLiteConnection(System.IO.Path.Combine(folder, "Persons.db3"));
- check.Query<Person>("Select * FROM Person Where Username=?", fieldValue);
- //SQLiteDatabase sqldb = EGLifeStyleApplication.sqLiteDatabase;
- string Query = "Select * from " + TableName + " where " + dbfield + " = " + fieldValue;
- Person cursor = check.Query(Query, null);
- if (cursor.getCount() <= 0)
- {
- cursor.close();
- return false;
- }
- cursor.close();
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement