private void SearchRecipe(string nameCategory) { //настройка соединения с БД SQLite_Android dbPATH = new SQLite_Android(); var db = new SQLiteConnection(dbPATH.GetDbPath("Cooking.db")); List <String> add = new List <String>(); List <String> Recipe = new List <String>(); List <String> RecipeID = new List <String>(); Intent myIntent = new Intent(this, typeof(MaketCategory)); //поиск по категории блюда var ctg = db.Query <Category>("SELECT Category_ID FROM category WHERE Category_name = '" + nameCategory + "';"); foreach (Category j in ctg) { var Dish = db.Query <Recipe>("SELECT Recip_ID, Recipe_name, Cooking_method FROM recipe WHERE Rec_Category_ID = " + j.Category_ID + ";"); foreach (Recipe k in Dish) { add.Add(k.Recipe_name); Recipe.Add(k.Cooking_method); RecipeID.Add("r" + k.Recip_ID.ToString()); } } myIntent.PutStringArrayListExtra("recipeNAME", add.ToList()); myIntent.PutStringArrayListExtra("recipeCOOKING", Recipe.ToList()); myIntent.PutStringArrayListExtra("recipeID", RecipeID.ToList()); OverridePendingTransition(Resource.Animation.slide_right, Resource.Animation.fade_out); StartActivity(myIntent); }
private void SearchRecipe(string nameCategory, string country, string ingredients) { //настройка соединения с БД SQLite_Android dbPATH = new SQLite_Android(); var db = new SQLiteConnection(dbPATH.GetDbPath("Cooking.db")); Intent myIntent = new Intent(this, typeof(Maket)); List <String> nameRecipe = new List <String>(); List <String> Recipe = new List <String>(); List <String> RecipeID = new List <String>(); if ((nameCategory != "Не выбрано") && (country != "Не выбрано") && (ingredients != "")) { //поиск блюда по стране и категории Regex myReg = new Regex("\\,\\s"); string[] STRingredients = myReg.Split(ingredients); var ctry = db.Query <Cuisine>("SELECT Cuisine_ID FROM cuisine WHERE Cuisine_name = '" + country + "';"); var ctg = db.Query <Category>("SELECT Category_ID FROM category WHERE Category_name = '" + nameCategory + "';"); int checkING = 0; foreach (Cuisine i in ctry) { foreach (Category j in ctg) { foreach (string s in STRingredients) { if (s != "") { checkING++; var ingID = db.Query <Ingredient>("SELECT Ingredient_ID FROM ingredient WHERE Ingredient_name = '" + s + "'"); foreach (Ingredient ing in ingID) { var cmpstn = db.Query <Composition>("SELECT Comp_recipe_ID FROM composition WHERE Comp_Ingredient_ID = " + ing.Ingredient_ID + ";"); foreach (Composition c in cmpstn) { var Dish = db.Query <Recipe>("SELECT Recip_ID, Rec_Cuisine_ID, Rec_Category_ID, Recipe_name, Cooking_method FROM recipe WHERE Recip_ID = " + c.Comp_recipe_ID + ";"); foreach (Recipe k in Dish) { if ((i.Cuisine_ID == k.Rec_Cuisine_ID) && (j.Category_ID == k.Rec_Category_ID) && (checkING == LenghtING(ingredients))) { nameRecipe.Add(k.Recipe_name); Recipe.Add(k.Cooking_method); RecipeID.Add("r" + k.Recip_ID.ToString()); } } } } } } } } if (nameRecipe.Count != 0) { myIntent.PutStringArrayListExtra("recipeNAME", nameRecipe.ToList()); myIntent.PutStringArrayListExtra("recipeCOOKING", Recipe.ToList()); myIntent.PutStringArrayListExtra("recipeID", RecipeID.ToList()); OverridePendingTransition(Resource.Animation.slide_right, Resource.Animation.fade_out); StartActivity(myIntent); } else { string toast = string.Format("Подходящих рецептов не найдено."); Toast.MakeText(this, toast, ToastLength.Long).Show(); } } else { string toast = string.Format("Некоторые поля не заполнены."); Toast.MakeText(this, toast, ToastLength.Long).Show(); } }