diff --git a/app/appdb.cls b/app/appdb.cls index 0c8571b..f64024c 100644 --- a/app/appdb.cls +++ b/app/appdb.cls @@ -87,8 +87,8 @@ self~addPhoneNumber(contactId, contactDict["PHONE_TYPE"], contactDict["PHONE_NUMBER"]) self~addEmailAddress(contactId, contactDict["EMAIL_TYPE"], contactDict["EMAIL_ADDRESS"]) - self~addRealAddress(contactId, contactDict~addressType, contactDict~street, contactDict~city, contactDict~state, - contactDict~postalCode, contactDict~country) + /* contactId, addressType, street, city, state, postalCode, country */ + self~addRealAddress(contactId, "NA", contactDict~street, contactDict~city, contactDict~state, contactDict~postCode, "NA") return contactId ::METHOD getContact @@ -148,11 +148,28 @@ contactId = contactDir["ID"] contact = self~getContact(contactId) if contact \= .nil then do - contactsList~append(contact) - end + /* Get Phone Numbers */ + psql = "SELECT * FROM phone_numbers WHERE contact_id = "contact["ID"] + phones = db~exec(psql,.true,.ooSQLite~OO_ARRAY_OF_DIRECTORIES) + phone = phones[1] /* just grab the first phone */ + contact["PHONE_NUMBER"] = phone["NUMBER"] + contact["PHONE_TYPE"] = phone["TYPE"] + + /* Now get email addresses */ + esql = "SELECT * FROM email_addresses WHERE contact_id = "contact["ID"] + emails = db~exec(esql,.true,.ooSQLite~OO_ARRAY_OF_DIRECTORIES) + email = emails[1] + contact["EMAIL_ADDRESS"] = email["EMAIL"] + contact["EMAIL_TYPE"] = email["TYPE"] + + contactsList~append(contact) + end /* add contact details */ end return contactsList + /*********************** + * UPDATE CONTACT * + ***********************/ ::METHOD updateContact expose db use arg contactId, firstName, lastName @@ -162,7 +179,7 @@ say "Error updating contact:" db~errMsg() return -1 end - return rc + return rc /************************** * DELETE CONTACT * diff --git a/app/appui.cls b/app/appui.cls index 856f0e6..6788c2a 100644 --- a/app/appui.cls +++ b/app/appui.cls @@ -222,8 +222,8 @@ self~dropWindow(formwin) RETURN END - post = self~getInputField(formwin, 8, 50, 10) - if post = .nil then do + postCode = self~getInputField(formwin, 8, 50, 10) + if postCode = .nil then do self~dropWindow(formwin) RETURN END @@ -242,6 +242,10 @@ contactDict["PHONE_TYPE"] = phone_type contactDict["EMAIL_ADDRESS"] = email contactDict["EMAIL_TYPE"] = email_type + contactDict["STREET"] = street + contactDict["CITY"] = city + contactDict["STATE"] = state + contactDict["POSTCODE"] = postCode result = db~addContact(contactDict) /* Display result message */ @@ -364,13 +368,13 @@ search_width = 50 start_y = (max_y - search_height) % 2 start_x = (max_x - search_width) % 2 - searchwin = self~DrawSubPanel(search_height, search_width, start_y, start_x, 7, "Search Contacts", .true) + searchwin = self~DrawSubPanel(search_height, search_width, start_y, start_x, 7, "Search Contacts (First, Last)", .true) searchwin~mvaddstr(3, 2, "Search term: ") searchwin~refresh() /* Get search term */ - term = self~getInputField(searchwin, 3, 14, 30) + term = self~getInputField(searchwin, 3, 15, 30) /* If canceled, return to main menu */ if term = .nil then do @@ -383,8 +387,8 @@ searchwin~refresh() /* Display results in a new window */ - self~dropWindow(searchwin) self~displaySearchResults(term) + self~dropWindow(searchwin) return /************************** @@ -393,12 +397,54 @@ ::METHOD displaySearchResults expose win menuwin db use arg term - /* TODO: COMPLETE ME! */ - self~setupMainMenu(win) - menuwin~refresh() + /* Create a list panel */ + max_y = win~lines + max_x = win~cols + list_height = max_y - 5 + list_width = max_x - 23 + start_y = (max_y - list_height) % 2 + start_x = (max_x - list_width) % 2 + + searchoutwin = self~DrawSubPanel(list_height, list_width, start_y, start_x, 1, "All Contacts", .true) + searchoutwin~scrollok(.true) + searchoutwin~Setscrreg(4,18) + + /* Display column headers */ + searchoutwin~attron(searchoutwin~A_BOLD) + searchoutwin~mvaddstr(4, 2, "ID") + searchoutwin~mvaddstr(4, 6, "First Name") + searchoutwin~mvaddstr(4, 18, "Last Name") + searchoutwin~mvaddstr(4, 30, "Phone") + searchoutwin~mvaddstr(4, 50, "Email") + searchoutwin~mvaddstr(5, 2, "-- ---------- --------- --------------- -------------------------") + searchoutwin~attroff(searchoutwin~A_BOLD) + + contacts = db~searchContacts(term) + + /* Display contacts */ + if contacts~items > 0 then do + do i = 1 to contacts~items + contact = contacts[i] + searchoutwin~mvaddstr(i+5, 2, contact['ID']) + searchoutwin~mvaddstr(i+5, 6, contact['FIRST_NAME']) + searchoutwin~mvaddstr(i+5, 18, contact['LAST_NAME']) + searchoutwin~mvaddstr(i+5, 30, contact['PHONE_NUMBER']) + searchoutwin~mvaddstr(i+5, 50, contact['EMAIL_ADDRESS']) + /* Break if we run out of screen space */ + if i > list_height-7 then LEAVE + end + end + else do + searchoutwin~mvaddstr(6, 5, "No contacts found.") + end + + searchoutwin~getch() + self~dropWindow(searchoutwin) + RETURN + /************************ * Get Input From Field * ************************/ @@ -540,19 +586,6 @@ end return - ::METHOD stripChar263 - use arg inputString - - outputString = "" - - do i = 1 to inputString~length - char = inputString~substr(i, 1) - if C2D(char) \= 263 then - outputString = outputString || char - end - - return outputString~changeStr("263", "") - ::METHOD findInArray use arg array, item do i = 1 to array~items @@ -560,7 +593,7 @@ end return 0 /* Not found */ - ::method cleanup + ::METHOD cleanup expose win menuwin /* Clean up ncurses */ menuwin~endwin diff --git a/db/contacts.sqlite b/db/contacts.sqlite index a75cbd5..281ba8b 100644 Binary files a/db/contacts.sqlite and b/db/contacts.sqlite differ