Search operation, By Word. |
Search operation, By Word
- the new text Code to be add is red.
// 2- Search Operations by
word.... public void btnDisplay_click(Object source, Event e) { // Variables String upperword, lowerword, leftword, rightword, ulword; String vtextdata, vbook, vtitle, vchapter, vverse; // ListView Subitems variables String[] subitems = new String[4]; int recordno = 0; int i = 0; int j = 0; // Display this message lbInfo.setText(" One moment ..."); //Set the btnDisplay button disable btnDisplay.setEnabled(false); // Uppercase style - exemple: WORD upperword = editWord.getText().toString().toUpperCase(); //Lowercase style - example: word lowerword = editWord.getText().toString().toLowerCase(); //Uppercase + lowercase style - example: Word // 1st chararcter - W leftword = editWord.getText().substring(0,1); // Others characters - ord rightword = editWord.getText().substring(1); ulword = leftword.toUpperCase() + rightword.toLowerCase(); //The view selected is Report i = 0; m_rs_word.move(2); //Max items to found, less then 5000 while (!m_rs_word.getEOF() && i < 5000) { // Use RichEdit control to store TextData field richEdit1.setText(m_rs_word.getField("TextData").getString()); // Search by word, for this use the Find function of the RichEdit control if ( (richEdit1.find(lowerword.toString()) != -1) && (richEdit1.find(upperword.toString()) != -1) && (richEdit1.find(ulword.toString()) != -1)) { // Absolute position of the record recordno = m_rs_word.getAbsolutePosition(); // Book field value vbook = m_rs_word.getField("Book").getString().toString(); //Title field value vtitle = m_rs_word.getField("BookTitle").getString().toString(); //Chapter field value vchapter = m_rs_word.getField("Chapter").getString().toString(); //Verse field value vverse = m_rs_word.getField("Verse").getString().toString(); // ListView Control // Values of Subitems subitems[0] = vbook.toString().toString(); subitems[1] = vtitle.toString(); subitems[2] = vchapter.toString(); subitems[3]= vverse.toString(); listViewSearch.insertItem(i,String.valueOf(recordno).toString(),0,subitems ); i = i + 1; // Number of item(s) found j = i-1; } m_rs_word.moveNext(); } //Information about Items found if (i < 1) lbInfo.setText( "0 item found."); else { if (j >= 4999) lbInfo.setText( "More then " + String.valueOf(j + 1).toString() + " items found."); else lbInfo.setText( String.valueOf(j + 1).toString() + " items found."); } } public void editWord_textChanged(Object source, Event e) { if (editWord.getText().length()>0) { // Set the btnDisplay control enebled btnDisplay.setEnabled(true); // lbinfo control value lbInfo.setText("Search operation ..."); // Clear the listView control listViewSearch.clear(); // Add header columns listViewSearch.addColumn("Record",70,1,0); listViewSearch.addColumn("Bk",30,2,0); listViewSearch.addColumn("Title",85,3,0); listViewSearch.addColumn("Chp",45,4,0); listViewSearch.addColumn("Verse",45,5,0); } } public void listViewSearch_mouseUp(Object source, MouseEvent e) { String itemselected = new String(); int itemindex; //Value of the item selected itemselected = listViewSearch.getItemText(listViewSearch.getFocusedItem().getIndex()); itemindex = Integer.valueOf(itemselected.toString()).intValue(); //Display the record corresponding to the item selected itemindex = itemindex - 1; if (itemindex > 1) { m_rs.moveFirst(); m_rs.move(itemindex); CalculValue(); if (itemindex == 31103) SetButtons(false); else { if (itemindex == 2) SetButtons(true); else SetButtonsAll(true); } } } public void
listViewSearch_keypress(Object source, KeyEvent e) |