private async void btn_pushPlans_Clicked(object sender, EventArgs e) { var result1 = await DisplayAlert(ResxFile.msg_rusure, ResxFile.msg_coachResponsibility, ResxFile.btn_yes, ResxFile.btn_cancel); if (result1) { String queryString = "SELECT * FROM [HabitPlans] WHERE habitID_DB IS NULL"; ObservableCollection <HabitPlans> plans = new ObservableCollection <HabitPlans>(await App.Database.QueryHabitPlans(queryString)); if (plans.Count == 0) { await DisplayAlert(ResxFile.str_error, ResxFile.err_noPlanPush, ResxFile.err_confirm); return; } String planIDs = "("; Boolean isFirst = true; foreach (HabitPlans plan in plans) { if (isFirst) { planIDs = planIDs + plan.habitID; isFirst = false; } else { planIDs = planIDs + ", " + plan.habitID; } } planIDs = planIDs + ")"; String queryString2 = "SELECT * FROM [PlanItems] WHERE habitID IN " + planIDs; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ObservableCollection <PlanItems> items = new ObservableCollection <PlanItems>(await App.Database.QueryPlanItems(queryString2)); String userID = await Constants.GetUserId(); BaseModel result2 = await APIConnection.PushPlans(plans, items, userID); if (result2.Errors != null) { await DisplayAlert(ResxFile.btn_Logout, result2.Errors[0].Message, ResxFile.btn_ok); } else { foreach (Models.APIModels.HabitPlan plan in result2.Data.PushPlans) { String queryString3 = "Update [HabitPlans] SET habitID_DB='" + plan.Id + "' WHERE habitID=" + plan.LocalId; var result3 = await App.Database.ExecuteQuery(queryString3); if (result3 == 0) { await DisplayAlert(ResxFile.str_error, "Update row(habitID = " + plan.LocalId + ") Failed.", ResxFile.err_confirm); break; } } await DisplayAlert(ResxFile.msg_Success, ResxFile.msg_pushPlanSucc, ResxFile.btn_ok); } } }