Tüm bu kodu nasıl basitleştirebilirim? Bir arama menüsü oluşturuyorum ve kullanıcı bir 'Metin Görünümünden' çıktığında değerleri kontrol etmek ve çıktıyı hemen aşağıda bir 'Geri Dönüşüm Görüntüleyicisi' olarak görüntülemek istiyorum.
Bir yol bunu çok sayıda IFS ile yapmaktır. Öneriyor musun başka bir yöntem?
Uygulama veritabanım için Roon Kütüphanesini kullanıyorum.
Bunun için bu kodu kullanmak istedim ama IFs sayısının çok yüksek olduğunu gördüm.
Bir arkadaşım veritabanında Case kullanmayı önerdi, ancak kodunu nasıl yazacağımı bilmiyorum!
public void searchHelper() { String sOperationValue = spinnerOperation.getText().toString(); String sTraderValue = spinnerTraderName.getText().toString(); String sSearchByValue = spinnerSearchBy.getText().toString(); long startValue = Long.parseLong(etStartDate.getText().toString()); long endValue = Long.parseLong(etEndDate.getText().toString()); // * * * * * if (!sOperationValue.isEmpty() && !sTraderValue.isEmpty() && !sSearchByValue.isEmpty() && startValue >= 14000000 && endValue <= 15000000) { } // * - * * * if (!sOperationValue.isEmpty() && sTraderValue.isEmpty() && !sSearchByValue.isEmpty() && startValue >= 14000000 && endValue <= 15000000) { } // * - - - - if (!sOperationValue.isEmpty() && sTraderValue.isEmpty() && sSearchByValue.isEmpty() && startValue <= 0 && endValue <= 0) { } // - * * * * if (sOperationValue.isEmpty() && !sTraderValue.isEmpty() && !sSearchByValue.isEmpty() && startValue >= 14000000 && endValue <= 15000000) { } // Here 'Search By' specifies whether the search should be based on the date of registration or on the date of the transaction. // Therefore, when Search By is empty, then the start date and end date values are also empty. // - * - - - if (sOperationValue.isEmpty() && !sTraderValue.isEmpty() && sSearchByValue.isEmpty() && startValue <= 0 && endValue <= 0) { } // - - * * * if (sOperationValue.isEmpty() && sTraderValue.isEmpty() && !sSearchByValue.isEmpty() && startValue >= 14000000 && endValue <= 15000000) { } // - - - - - if (sOperationValue.isEmpty() && sTraderValue.isEmpty() && sSearchByValue.isEmpty() && startValue <= 0 && endValue <= 0) { } }
Ayrıca Case kullanarak bir sorgu yazmak istedim ancak başarısız oldum. Yazdığım kod buydu.
@Query("SELECT * FROM tbl_transaction" + " WHERE CASE WHEN operation='null'" + " THEN CASE WHEN traderName='null'" + " THEN CASE WHEN transactionType ='null'" + " THEN CASE WHEN startDate=14000000" + " THEN CASE WHEN endDate=15000000" ) List<Transaction> getSearchValues(String operation, String traderName, String transactionType, long startDate, long endDate);
Doğru çözümü çok aramama rağmen maalesef bulamadım.
Yardımlarınız için şimdiden teşekkür ederim.