// get parents list public ArrayList<Parent> getParentsDetails() { ArrayList<Parent> getparetd = new ArrayList<Parent>(); String selectQuery = null; // if(trigger.equals("all")) // { selectQuery = "SELECT * FROM " + TABLE_PARENTS_DETAILS; // } // else // { // selectQuery = "SELECT * FROM "+TABLE_PARENTS_DETAILS+" where "+PID+" = "+id; // } Parent temp = new Parent(); temp.setParentId("0"); temp.setName("Select existing parent"); getparetd.add(temp); SQLiteDatabase db = this.getReadableDatabase(); try { cursor = (SQLiteCursor) db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { Parent studentList = new Parent(); // StudentList studentList = new StudentList(); studentList.setParentId(cursor.getString(cursor.getColumnIndex(PID))); studentList.setName(cursor.getString(cursor.getColumnIndex(ParentName))); studentList.setEmail(cursor.getString(cursor.getColumnIndex(ParentEmail))); studentList.setAddress(cursor.getString(cursor.getColumnIndex(ParentAddress))); studentList.setContactNumber(cursor.getString(cursor.getColumnIndex(ParentContactInfo))); studentList.setAltContactNumber( cursor.getString(cursor.getColumnIndex(ParentContactInfo_Alt))); studentList.setStudentCount(cursor.getString(cursor.getColumnIndex(Parent_NO_Students))); studentList.setActivestudents( cursor.getString(cursor.getColumnIndex(Parent_No_Of_Active_Student))); studentList.setNotes(cursor.getString(cursor.getColumnIndex(ParentNotes))); studentList.setOutstandingBalance( cursor.getString(cursor.getColumnIndex(Parent_Out_Standing_Balance))); getparetd.add(studentList); // array_studentlist.set(studentList); } while (cursor.moveToNext()); } cursor.getWindow().clear(); cursor.close(); // close inserting data from database db.close(); // return city list return getparetd; } catch (Exception e) { e.printStackTrace(); if (cursor != null) { cursor.getWindow().clear(); cursor.close(); } db.close(); return getparetd; } }
// update parent public void updateParentDetail(ArrayList<Parent> parentList) { // TODO Auto-generated method stub SQLiteDatabase db = this.getWritableDatabase(); for (int i = 0; i < parentList.size(); i++) { Parent ParentList = parentList.get(i); // String selectQuery1 = "SELECT * FROM "+TABLE_PARENTS_DETAILS +" where "+PID+"="+ // ParentList.getParentId(); try { ContentValues values = new ContentValues(); values.put(PID, ParentList.getParentId()); values.put(ParentName, ParentList.getName()); values.put(ParentEmail, ParentList.getEmail()); values.put(ParentAddress, ParentList.getAddress()); values.put(ParentContactInfo, ParentList.getContactNumber()); values.put(ParentContactInfo_Alt, ParentList.getAltContactNumber()); values.put(Parent_NO_Students, ParentList.getStudentCount()); values.put(Parent_No_Of_Active_Student, ParentList.getActivestudents()); values.put(ParentNotes, ParentList.getNotes()); values.put(Parent_Out_Standing_Balance, ParentList.getOutstandingBalance()); // cursor = (SQLiteCursor) db.rawQuery(selectQuery1, null); // if (cursor.moveToFirst()) { // updating row // int a=db.update(TABLE_PARENTS_DETAILS, values, PID + " = ?", // new String[] { String.valueOf(ParentList.getParentId()) }); // }else{ db.insert(TABLE_PARENTS_DETAILS, null, values); // } } catch (Exception e) { e.printStackTrace(); } } db.close(); }