ยังไงฉัน simplify ทั้งหมดนี่รหัสหรอ? ฉันกำลังสร้างเป็นการค้นหาของเมนูและฉันต้องตรวจสอบค่าต่างๆที่ผู้ใช้ออกจากเป็นข้อความในมุมมองและมีการแสดงผลส่งออกทันทีที่เป็น'Recycle เครื่องมือแสดง'ทางด้านล่างนี้
ทางเดียวคือต้องทำอย่างนี้กับตัวใหญ่กว่าจำนวนของคำว่าถ้า คุณจะแนะนำว่า วิธีอื่นอีกมั้ย
ฉันใช้ Roon องสมุดของโปรแกรมฐานข้อมูล
ฉันอยากจะใช้รหัสสำหรับเรื่องนี้เลยแต่ฉันเห็นว่าจำนวนของเงื่อนไขคือสูงมาก.
เพื่อนแนะนำให้ใช้ในกรณีที่ลอกฐานข้อมูลแต่ฉันไม่รู้ว่าต้องเขียนมันรหัส!
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) { } }
ฉันยังต้องการที่จะเขียนมีการใช้กรณีแต่ล้มเหลว นี่เป็นรหัสฉันเขียน
@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);
ถึงแม้ว่าฉันจะเป็นอย่างมากกำลังมองหาทางออกฉันช่างโชคร้ายไม่สามารถหามันให้เจอ
ขอบคุณล่วงหน้าสำหรับความช่วยเหลือ