public void InsertGroupCrime(Activity act){ using (var db = FactoryConn.GetConn ()) { db.CreateTable<GroupCrime> (); if (db.Table<GroupCrime> ().Count () == 0) { IEnumerable<String[]> data = GetDataOfFile (ConstantsDb.CONTENT_FOLDER_CATALOG + "/group_crime.txt", act); List<GroupCrime> entities = new List<GroupCrime> (); foreach (String[] line in data) { try { GroupCrime model = new GroupCrime (); model.Id = int.Parse (line [0]); model.Name = line [1]; model.Description = line [2]; model.IsObsolete = line [3].Equals ("1"); entities.Add (model); } catch (Exception e) { Console.WriteLine ("group_crime error " + e.Message); } } db.InsertAll (entities); var content = db.Table<HearingType> ().ToList (); Console.WriteLine ("Se inserto en tabla group_crime:"); foreach (HearingType m in content) { Console.WriteLine ("Id: " + m.Id + " Name:" + m.Description); } } db.Close (); } }
public void InsertCrime(Activity act) { var db = new SQLiteConnection(ConstantsDB.DB_PATH); db.CreateTable <GroupCrime> (); if (db.Table <GroupCrime> ().Count() == 0) { IEnumerable <String[]> data = GetDataOfFile(ConstantsDB.CONTENT_FOLDER_CATALOG + "/group_crime.txt", act); List <GroupCrime> entities = new List <GroupCrime>(); foreach (String[] line in data) { try{ GroupCrime model = new GroupCrime(); model.Id = int.Parse(line [0]); model.Name = line [1]; model.IsObsolete = line [2].Equals("1"); entities.Add(model); }catch (Exception e) { Console.WriteLine("error " + e.Message); } } db.InsertAll(entities); IEnumerable <String[]> dataCrime = GetDataOfFile(ConstantsDB.CONTENT_FOLDER_CATALOG + "/crime.txt", act); List <CrimeCatalog> entitiesCrime = new List <CrimeCatalog>(); foreach (String[] line in data) { try{ CrimeCatalog model = new CrimeCatalog(); model.Id = int.Parse(line [0]); model.Name = line [1]; model.Description = line[2]; model.IsObsolete = line [3].Equals("1"); model.GroupCrimeId = int.Parse(line[4]); entitiesCrime.Add(model); }catch (Exception e) { Console.WriteLine("error " + e.Message); } } db.InsertAll(entitiesCrime); var content = db.Table <GroupCrime> ().ToList(); Console.WriteLine("Se inserto en tabla GroupCrime:"); foreach (GroupCrime m in content) { Console.WriteLine("Id: " + m.Id + " Name:" + m.Name); Console.WriteLine(" Crime"); var CrimeCatalogs = (from c in db.Table <CrimeCatalog>() where c.GroupCrimeId.Equals(m.Id) select c).ToList(); foreach (CrimeCatalog d in CrimeCatalogs) { Console.WriteLine("Id: " + d.Id + " Name:" + d.Name); } } } db.Close(); }