Monday, May 28, 2012

SQLIte Database Take Two

I wanted to redo the database in the simplest way possible to make things clearer. To do this I made a simple initial form with two buttons:

I still needed to create the sqlHelper class. But this time I only created a single table. Here is the code for the SqlHelperClass

package com.spconger.programmingresourcesdata;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;


public class SqlHelperClass extends SQLiteOpenHelper{

 /*
  * This class extends SqlLiteOpenHelper
  * It creates the database and the tables
  * and sets static constants that are used
  * in the other classes
  */
 
 //set database as priiate constatn
 private static final String DATABASE_NAME = "ProgramResources.db";
 private static final int DATABASE_VERSION = 1;
 
 //public constants
 //database table
 public static final String TABLE_NAME="Book";
 
 //columns
 public static final String BOOK_ID="bookId";
 public static final String BOOK_TITLE="title";
 public static final String BOOK_AUTHOR="author";
 public static final String BOOK_RATING="Rating";
 
 //required constructor
 //takes the contest which is usually the current 
 //activity, it also passes the database name and
 //version to the super class
 public SqlHelperClass(Context context) {
  super(context, DATABASE_NAME, null, DATABASE_VERSION);
  // TODO Auto-generated constructor stub
 }

 @Override
 public void onCreate(SQLiteDatabase db) {
  // here we create the table
  String sql_Book="CREATE TABLE " + TABLE_NAME
  +"(" + BOOK_ID + " integer primary key autoincrement, " 
  + BOOK_TITLE + " text not null, "
  + BOOK_AUTHOR + " text not null, "
  + BOOK_RATING + " int, "
  + "unique (" +BOOK_TITLE + "))";
  
  //add the table to the database
  db.execSQL(sql_Book);
 }

 @Override
 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
  //You should put code here to handle new versions of the database
  
 }

}


Here is the form for adding records


The java behind this form is fairly straight forward. I just initialize a writable database, get the values from the EditText controls and insert them into the database

package com.spconger.programmingresourcesdata;



import android.app.Activity;
import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class AddRecordsActivity extends Activity{
 /*
  * This activity adds records to the database. 
  * I purposefully kept this simple
  * not breaking it into too many methods
  * Consequently the AddRecord method does 
  * more than it probably should
  */
 EditText txtTitle;
 EditText txtAuthor;
 EditText txtRating;
 Button btnSave;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.addrecords);
  
  btnSave = (Button)findViewById(R.id.button1);
  btnSave.setOnClickListener(new AddRecordListener());
 }
 
 private class AddRecordListener implements View.OnClickListener{

  @Override
  public void onClick(View v) {
   
   //get database
   SqlHelperClass sqlHelper = new SqlHelperClass(AddRecordsActivity.this);
   SQLiteDatabase db= sqlHelper.getWritableDatabase();
   
   //get the values from the EditText controls
   
   txtTitle = (EditText)findViewById(R.id.editTextTitle);
   String title=txtTitle.getText().toString();
   
   txtAuthor=(EditText)findViewById(R.id.editTextAuthor);
   String author=txtAuthor.getText().toString();
   
   txtRating = (EditText)findViewById(R.id.editTextRating);
   String ratingString=txtRating.getText().toString();
   int rating=Integer.parseInt(ratingString);
   
   //add the values from the EditViews to the columns
   ContentValues values = new ContentValues();
   values.put(SqlHelperClass.BOOK_TITLE,title);
   values.put(SqlHelperClass.BOOK_AUTHOR, author);
   values.put(SqlHelperClass.BOOK_RATING, rating);
   
   
   //Insert into the database
   long book_id= db.insert(SqlHelperClass.TABLE_NAME, null, values);
   db.close();
   
   //if the insert is successful
   if(book_id != -1)
   {
    //start a toast (a message)
    Toast toast = Toast.makeText
       (AddRecordsActivity.this, "Record Added", Toast.LENGTH_LONG);
    toast.show();
   }
   else
   {
    Toast toast = Toast.makeText
      (AddRecordsActivity.this, "Record failed to Insert", Toast.LENGTH_LONG);
             toast.show();
   }
            
   //clear for next record
            clearForm();
   
   
   }
   
  }
  
  private void clearForm()
  {
   txtTitle.setText("");
   txtAuthor.setText("");
   txtRating.setText("");
  }
  }
  

finally we just view the records. I didn't do anything fancy. I created a cursor to look through the records and appended them to a string that terminates with a new line character. Then I set the resulting text to the ViewText. Here is the codeL

package com.spconger.programmingresourcesdata;

import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;


public class ViewRecordsActivity extends Activity{
 
 /*
  * Again, to make this simple, the getRecords method
  * does more than one record should do
  * 
  */
 @Override
  protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 setContentView(R.layout.viewrecords);
 
 getRecords();
 }
 
 private void getRecords(){
  
  //initiate the SqlHeperClass and get the database
  SqlHelperClass sqlHelper = new SqlHelperClass(ViewRecordsActivity.this);
  SQLiteDatabase db= sqlHelper.getWritableDatabase();
  
  //create an array of the columns
  String[] columns = new String[] 
         {sqlHelper.BOOK_TITLE, 
    sqlHelper.BOOK_AUTHOR, 
    sqlHelper.BOOK_RATING};
  
  //start a cursor to move through the records
  Cursor cursor = db.query(sqlHelper.TABLE_NAME, columns, null, null, null, null, null);
  
  String result="";
  //use the cursor to loop through the records
  for(cursor.moveToFirst();!cursor.isAfterLast();cursor.moveToNext()){
   //I am just concatenating the records into a string
   //terminated by a line break
   result+= cursor.getString(0) + ", " + cursor.getString(1) + "--" + cursor.getInt(2) + "\n" ;
  }
  
  //assign the result to the textview
  TextView content=(TextView)findViewById(R.id.content_list);
  content.setText(result);
 }
}

Here is the the activity running

Thursday, May 24, 2012

LINQ Example

here is our example using LINQ

Remember you need to add a LINQ to SQL designer to your project and the drag the tables from the Server Explorer onto the Designer. Then be sure to save the Designer so that it will generate the classes that you need.

The LINQ Designer

The first thing we did was to simple load the services into a dataList. Here is the code behind


Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CommunityAssistDataContext dc = new CommunityAssistDataContext();
        var serv = from s in dc.Services
                   orderby s.ServiceName
                   select new { s.ServiceName, s.ServiceDescription };
        /*
        var donors = from d in dc.Donations
                     select new { d.Person.FirstName, d.Person.LastName, d.DonationDate}
         */
        
        DataList1.DataSource = serv.ToList();
        DataList1.DataBind();
    }
    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("Donate.aspx");
    }
}

Here is the source for Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" 
CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Services Offered</h1>
    <p>
        <asp:DataList ID="DataList1" runat="server">
        <ItemTemplate>
        
            <strong><asp:Label ID="Label1" runat="server" 
Text='<%#Eval("ServiceName") %>'></asp:Label></strong>, 
            <asp:Label ID="Label2" runat="server" 
Text='<%#Eval("ServiceDescription") %>'></asp:Label>
         <br />
        </ItemTemplate>
        </asp:DataList>
        </p>
        <asp:LinkButton ID="LinkButton1" runat="server" 
onclick="LinkButton1_Click">Donate?</asp:LinkButton>
    </div>
    </form>
</body>
</html>


Here is the Source for Donate.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Donate.aspx.cs" Inherits="Donate" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td> 
        <asp:Label ID="Label1" runat="server" Text="First Name"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtFirstname" runat="server"></asp:TextBox></td>
    </tr>
    
     <tr>
    <td> 
        <asp:Label ID="Label2" runat="server" Text="Last Name"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtLastName" runat="server"></asp:TextBox></td>
    </tr>

     <tr>
    <td> 
        <asp:Label ID="Label3" runat="server" Text="Street"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtStreet" runat="server"></asp:TextBox></td>
    </tr>

     <tr>
    <td> 
        <asp:Label ID="Label4" runat="server" Text="City"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtCity" runat="server"></asp:TextBox></td>
    </tr>

     <tr>
    <td> 
        <asp:Label ID="Label5" runat="server" Text="State"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtState" runat="server"></asp:TextBox></td>
    </tr>

     <tr>
    <td> 
        <asp:Label ID="Label6" runat="server" Text="Zip Code"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtZipCode" runat="server"></asp:TextBox></td>
    </tr>

     <tr>
    <td> 
        <asp:Label ID="Label7" runat="server" Text="Phone"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtPhone" runat="server"></asp:TextBox></td>
    </tr>

     <tr>
    <td> 
        <asp:Label ID="Label8" runat="server" Text="Email"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox></td>
    </tr>

     <tr>
    <td> 
        <asp:Label ID="Label9" runat="server" Text="Donation"></asp:Label></td>
    <td> 
        <asp:TextBox ID="txtDonation" runat="server"></asp:TextBox></td>
    </tr>
     <tr>
    <td> 
        <asp:Button ID="Button1" runat="server" Text="Donate" onclick="Button1_Click" />
     </td>
    <td> 
        <asp:Label ID="lblResult" runat="server" Text=""></asp:Label>
        </td>
    </tr>
    </table>
    </div>
    </form>
</body>
</html>


Here is the code behind for Donate.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Donate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        CommunityAssistDataContext dc = new CommunityAssistDataContext();
        Person p = new Person();
        p.FirstName = txtFirstname.Text;
        p.LastName = txtLastName.Text;

        dc.Persons.InsertOnSubmit(p);

        PersonAddress pa = new PersonAddress();
        pa.Person = p;
        pa.Street = txtStreet.Text;
        pa.City = txtCity.Text;
        pa.State = txtState.Text;
        pa.Zip = txtZipCode.Text;

        dc.PersonAddresses.InsertOnSubmit(pa);

        PersonContact phone = new PersonContact();
        phone.Person = p;
        phone.ContactInfo = txtPhone.Text;
        phone.ContactTypeKey = 1;

        dc.PersonContacts.InsertOnSubmit(phone);

        PersonContact email = new PersonContact();
        email.Person=p;
        email.ContactInfo=txtEmail.Text;
        email.ContactTypeKey=6;

        dc.PersonContacts.InsertOnSubmit(email);

        Donation d = new Donation();
        d.Person = p;
        d.DonationAmount = decimal.Parse(txtDonation.Text);
        d.DonationDate = DateTime.Now;
        d.EmployeeKey = 1;

        dc.Donations.InsertOnSubmit(d);

        dc.SubmitChanges();

        lblResult.Text = "Thank you for your Donation";
    }
}

Wednesday, May 23, 2012

ITC 162 Project

I am going to make the requirements for this minimal, given how little of the quarter is left.

The project should involve multiple activities and multiple java classes. Other than that, all I really want to see is your attempts to explore Android.

If design is your interest, you can spend the time working with the android's controls and resources, or, if programming is more your interest, see about adding some functionality, maybe consuming services on the phone or from the cloud.

You can work on these alone or in groups

I would like for groups or individuals to present what they have done on Monday of finals week

Logins, Users, Schema, Roles

---sql server login
--schema dbo as ownership
--roles
--user
--logins give you connection access to the server but not much else
Create login emp with password='p@ssw0rd1', default_database =CommunityAssist


Use CommunityAssist
--users are database specific and are always associated with a server login
Create user employ for login emp 
go
--schemas are groups of ownership
Create schema Employee

--create an object that belongs to the schema
Create view Employee.Donors
as
Select LastName, firstname,
DonationDate, Donationamount
From Person p
inner Join Donation d
on p.PersonKey=d.PersonKey

--add the user to the schema
Alter user employ with default_schema=Employee

--give the user select permissions on all the objects 
--in the schema 
Grant select on  Schema::Employee to Employ 

--A role is a collection of permissions
Create Role humanResources
Grant Select, update on Employee to humanResources
Grant Select, update on Person to humanResources

/* 
these are all the database permissions you can grant
Select 
Insert
UPDATE
Delete
Create
Alter
exec
drop
*/

--add an use to the role using a stored procedure
exec sp_addRoleMember  humanResources, employ
go

--this drops a user from the role
exec sp_droprolemember humanResources employ

Tuesday, May 22, 2012

Code for Scanner and Testing

We programmed the core functionality of the scanner in order to test it. First here are some diagrams of the code

Class Diagram


Sequence Diagram


Now here is the code for the classes

Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DoorCardProofOfConcept
{
    class Program
    {
      
    
        static void Main(string[] args)
        {
            int exit = 1;
            while (exit != -1)
            {
                Console.WriteLine("Enter Card Number");
                string card = Console.ReadLine();
                Console.WriteLine("enter the Door number");
                string door = Console.ReadLine();
                Scanner s = new Scanner(card, door);
                Console.WriteLine(s.DoorState);
                Console.WriteLine("Enter -1 to Exit");
                exit = int.Parse(Console.ReadLine());
            }

           // Console.ReadKey();

        }
    }
}


Scanner.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DoorCardProofOfConcept
{
    /// 
    /// This class represents the physical
    /// scanner. It reads the card
    /// creates a scan object and sends it
    /// off to be validated
    /// if the validation returns true
    /// it opens the door
    /// 
    /// 
    class Scanner
    {
        string cardNumber;
        string scannerID;
        string doorState;
        Scan scan;

        public Scanner(string card, string ID)
        {
            cardNumber = card;
            scannerID = ID;
            doorState = "closed";
            CreateScan();
            getScanValidated();

        }

        public string DoorState
        {
            get { return doorState; }
        }

        internal Validator Validator
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        internal Scan Scan
        {
            get
            {
                throw new System.NotImplementedException();
            }
            set
            {
            }
        }

        private void CreateScan()
        {
            DateTime date = DateTime.Now;
            scan = new Scan(scannerID,cardNumber, date);
        }

        public void getScanValidated()
        {
            bool isValid = false;
            Validator v = new Validator(scan);
            isValid = v.Validate();
            if (isValid)
            {
                doorState = "Open";
            }
            
        }
    }
}


Scan.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DoorCardProofOfConcept
{
    class Scan
    {
        /// 
        /// this class is simply a collection
        /// of data so that it can be passed
        /// as a single package
        /// 
        /// 
        /// 
        /// 

        public Scan(string number, string card, DateTime date)
        {
            scannerNumber = number;
            cardNumber = card;
            this.date = date;

        }
        private string scannerNumber;

        public string ScannerNumber
        {
            get { return scannerNumber; }
           
        }
        private string cardNumber;

        public string CardNumber
        {
            get { return cardNumber; }
           
        }
        private DateTime date;

        public DateTime Date
        {
            get { return date; }
           
        }
        

    }
}


Validator

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DoorCardProofOfConcept
{
    /// 
    /// this class recieve the scan
    /// and validate its contents
    /// against a database
    /// (for now an xmlFile)
    /// 
    class Validator
    {

        private Scan scan;

        public Validator(Scan s)
        {
            scan = s;
        }

        public bool Validate()
        {
            bool valid = false;
            DataSet table = new DataSet();
            table.ReadXml(@"ScheduleData.xml");

            foreach (DataRow row in table.Tables[0].Rows)
            {
                if (scan.CardNumber.Equals(row["card"].ToString()) &&
                    scan.ScannerNumber.Equals(row["door"].ToString()) &&
                    scan.Date.ToShortDateString().Equals(row["date"].ToString())
                    && scan.Date>=DateTime.Parse(row["begintime"].ToString())
                     && scan.Date<=DateTime.Parse(row["endtime"].ToString()))
                {
                    valid = true;
                }


            }

            return valid;
        }
    }
}


ScannerData.xml

<?xml version="1.0" encoding="utf-8" ?>
<schedule>
  <item>
    <card>100</card>
    <door>1</door>
    <date>5/22/2012</date>
    <begintime>9:00</begintime>
    <endtime>17:00</endtime>
  </item>
  <item>
    <card>100</card>
    <door>2</door>
    <date>5/23/2012</date>
    <begintime>9:00</begintime>
    <endtime>13:00</endtime>
  </item>
  <item>
    <card>101</card>
    <door>2</door>
    <date>5/22/2012</date>
    <begintime>10:00</begintime>
    <endtime>15:00</endtime>
  </item>
</schedule>

Here is the spreadsheet of our results

Monday, May 21, 2012

XML and SQL

use CommunityAssist

--xml
--outputting data as xml
--xml as a data type
--xml schema collections
--xquery
--these are using all options
Select * from Person for xml raw('person'), root ('Persons'), elements

Select lastName, FirstName, DonationDate, donationAmount
From Person 
Inner Join Donation 
on person.PersonKey=donation.PersonKey
for xml auto, elements, root('dataroot') 

--explicit: you have to specify exactly where 
in the xml heirarchy each field belongs

--xml as a datatype

Select * From Meeting

--we are dropping the column in order to add it back in with a 
--schema

Alter Table Meeting
drop column meetingnotes

--this creates a schema collection which can be used
--to test whether a given xml document entered
--into an xml data column conforms to certain specifications
Create xml schema collection MeetingNotesSchemaCollection
As
'<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" 
elementFormDefault="qualified" 
targetNamespace="http://www.seattlecentral.edu/meetingnotes" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="meetingnotes">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="heading">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="attending">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="member" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="body">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="notes" />
              <xs:element name="tasks">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element maxOccurs="unbounded" name="taskname" />
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>'

--add back in the table column with the schema
Alter table meeting
Add meetingnotes xml(MeetingNotesSchemaCollection)

--insert a record with the xml column
Insert into Meeting (MeetingDate, MeetingTopic, meetingnotes)
Values(GETDATE(), 'More Naps',
'<?xml version="1.0" encoding="utf-8"?>
<meetingnotes xmlns="http://www.seattlecentral.edu/meetingnotes" >
  <heading>
    <attending>
      <member>Joe</member>
      <member>Sue</member>
    </attending>
  </heading>
  <body>
    <notes>The staff would like more nap time</notes>
    <tasks>
      <taskname>Find a napping place</taskname>
      <taskname>find a nap time</taskname>
    </tasks>
  </body>
</meetingnotes>')

select * from meeting


--this one fails because the capital A on Attending doesn't
--conform to the schema
Insert into Meeting (MeetingDate, MeetingTopic, meetingnotes)
Values(GETDATE(), 'More Naps',
'<?xml version="1.0" encoding="utf-8"?>
<meetingnotes xmlns="http://www.seattlecentral.edu/meetingnotes" >
  <heading>
    <Attending>
      <member>Joe</member>
      <member>Sue</member>
    </Attending>
  </heading>
  <body>
    <notes>The staff would like more nap time</notes>
    <tasks>
      <taskname>Find a napping place</taskname>
      <taskname>find a nap time</taskname>
    </tasks>
  </body>
</meetingnotes>')

--another insert
Insert into Meeting (MeetingDate, MeetingTopic, meetingnotes)
Values(GETDATE(), 'Application Review',
'<?xml version="1.0" encoding="utf-8"?>
<meetingnotes xmlns="http://www.seattlecentral.edu/meetingnotes" >
  <heading>
    <attending>
      <member>Bob</member>
      <member>Lisa</member>
      <member>Sasha</member>
    </attending>
  </heading>
  <body>
    <notes>We reviewed 20 applications and approved 12</notes>
    <tasks>
      <taskname>Inform recipients</taskname>
     
    </tasks>
  </body>
</meetingnotes>')

--these are examples of xquery
Select MeetingDate, MeetingTopic, 
meetingnotes.query('declare namespace mn="http://www.seattlecentral.edu/meetingnotes"; 
//mn:meetingnotes/mn:heading/mn:attending/mn:member') as Attending
From Meeting

Select MeetingDate, MeetingTopic, 
meetingnotes.query('declare namespace mn="http://www.seattlecentral.edu/meetingnotes"; 
//mn:meetingnotes/mn:body/mn:notes') as Attending
From Meeting

Select MeetingDate, MeetingTopic, 
meetingnotes.query('declare namespace mn="http://www.seattlecentral.edu/meetingnotes";
 //mn:meetingnotes/mn:body') as Attending
From Meeting

Sunday, May 20, 2012

Android Assignment 3 (assignment 6)

The goal of this assignment is to create a database with two tables, a recipe table and an ingredients table.

The Recipe Table should have a
RecipeID which is an autonumber
RecipeName which is String
RecipeDescription also String

The Ingredient Table should have
RecipeID as a foreign key
IngredientName as String

The structure is essentially identical to the CD/Tracks structure

The app should work like the example. the first activity should list the available recipes. When one is clicked on a second activity that shows all the ingredients should open. Also on the first activity there should be a button or a clickable text that takes you to an activity to insert a new recipe.

For an extra challenge you can try to add edit and delete buttons on the detail activity to further manage the records.