more tweaking of the display all list
This commit is contained in:
parent
c4d8ea9c08
commit
39b41430f6
@ -84,6 +84,7 @@
|
||||
return -1
|
||||
end
|
||||
contactId = db~lastInsertRowId() /* the row id of 'contacts' table is the master id */
|
||||
|
||||
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,
|
||||
@ -109,10 +110,29 @@
|
||||
END
|
||||
return contacts[1] /* Rexx is 1-indexed */
|
||||
|
||||
/***************************
|
||||
* GET ALL CONTACT INFO *
|
||||
***************************/
|
||||
::METHOD getAllContacts
|
||||
expose db
|
||||
sql = "SELECT * FROM contacts ORDER BY last_name, first_name"
|
||||
contacts = db~exec(sql, .true, .ooSQLite~OO_ARRAY_OF_DIRECTORIES)
|
||||
|
||||
do contact over contacts
|
||||
/* 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"]
|
||||
END
|
||||
return contacts
|
||||
|
||||
::METHOD searchContacts
|
||||
@ -144,6 +164,9 @@
|
||||
end
|
||||
return rc
|
||||
|
||||
/**************************
|
||||
* DELETE CONTACT *
|
||||
*************************/
|
||||
::METHOD deleteContact
|
||||
expose db
|
||||
use arg contactId
|
||||
|
@ -87,6 +87,9 @@
|
||||
panel~refresh
|
||||
RETURN
|
||||
|
||||
/***********************
|
||||
* SETUP MAIN MENU *
|
||||
***********************/
|
||||
::method setupMainMenu
|
||||
expose mainMenu menuwin menu_items menu_keys selected
|
||||
use arg win
|
||||
@ -106,12 +109,14 @@
|
||||
menu_items = .array~of("[A]dd Contact", "[D]elete Contact", "[E]dit Contact", "[S]earch", "[L]ist All", "[Q]uit")
|
||||
menu_keys = .array~of("a", "d", "e", "s", "l", "q")
|
||||
|
||||
/* Display menu items */
|
||||
.environment~selected = 1
|
||||
self~DrawMenu(menuwin, menu_items, .environment~selected, win)
|
||||
menuwin~refresh
|
||||
RETURN
|
||||
|
||||
/***********************
|
||||
* DRAW MENU *
|
||||
***********************/
|
||||
::method DrawMenu
|
||||
expose win menu_items menu_keys selected mainwin
|
||||
use arg menuwin, items, selected, mainwin
|
||||
@ -131,6 +136,9 @@
|
||||
menuwin~refresh
|
||||
return
|
||||
|
||||
/***********************
|
||||
* DROP WINDOW *
|
||||
***********************/
|
||||
::method dropWindow
|
||||
expose win menuwin
|
||||
use arg window
|
||||
@ -153,7 +161,7 @@
|
||||
max_y = win~lines
|
||||
max_x = win~cols
|
||||
form_height = 14
|
||||
form_width = 50
|
||||
form_width = 55
|
||||
start_y = (max_y - form_height) % 2
|
||||
start_x = (max_x - form_width) % 2
|
||||
formwin = self~DrawSubPanel(form_height, form_width, start_y, start_x, 0, "Add New Contact", .true)
|
||||
@ -161,8 +169,8 @@
|
||||
/* Create form fields */
|
||||
formwin~mvaddstr(3, 2, "First Name: ")
|
||||
formwin~mvaddstr(4, 2, "Last Name: ")
|
||||
formwin~mvaddstr(5, 2, "Phone: ")
|
||||
formwin~mvaddstr(6, 2, "Email: ")
|
||||
formwin~mvaddstr(5, 2, "Phone: "); formwin~mvaddstr(5, 35, "Type: ");
|
||||
formwin~mvaddstr(6, 2, "Email: "); formwin~mvaddstr(7, 2, "Email Type: ");
|
||||
formwin~mvaddstr(form_height-2, 2, "[Enter] to save, [Esc] to cancel")
|
||||
formwin~refresh()
|
||||
|
||||
@ -178,11 +186,21 @@
|
||||
RETURN
|
||||
END
|
||||
phone = self~getInputField(formwin, 5, 14, 15)
|
||||
if phone = .nil then do
|
||||
self~dropWindow(formwin)
|
||||
RETURN
|
||||
END
|
||||
phone_type = self~getInputField(formwin, 5, 45, 15)
|
||||
if phone = .nil then do
|
||||
self~dropWindow(formwin)
|
||||
RETURN
|
||||
END
|
||||
email = self~getInputField(formwin, 6, 14, 30)
|
||||
if email = .nil then do
|
||||
self~dropWindow(formwin)
|
||||
RETURN
|
||||
END
|
||||
email_type = self~getInputField(formwin, 7, 14, 15)
|
||||
if email = .nil then do
|
||||
self~dropWindow(formwin)
|
||||
RETURN
|
||||
@ -198,8 +216,10 @@
|
||||
contactDict = .Directory~new()
|
||||
contactDict["FIRST_NAME"] = firstName
|
||||
contactDict["LAST_NAME"] = lastName
|
||||
contactDict["PHONE"] = phone
|
||||
contactDict["EMAIL"] = email
|
||||
contactDict["PHONE_NUMBER"] = phone
|
||||
contactDict["PHONE_TYPE"] = phone_type
|
||||
contactDict["EMAIL_ADDRESS"] = email
|
||||
contactDict["EMAIL_TYPE"] = email_type
|
||||
result = db~addContact(contactDict)
|
||||
|
||||
/* Display result message */
|
||||
@ -267,7 +287,7 @@
|
||||
max_y = win~lines
|
||||
max_x = win~cols
|
||||
list_height = max_y - 5
|
||||
list_width = 70
|
||||
list_width = max_x - 23
|
||||
start_y = (max_y - list_height) % 2
|
||||
start_x = (max_x - list_width) % 2
|
||||
|
||||
@ -277,27 +297,25 @@
|
||||
|
||||
/* Display column headers */
|
||||
listwin~attron(listwin~A_BOLD)
|
||||
listwin~mvaddstr(3, 2, "ID")
|
||||
listwin~mvaddstr(3, 6, "First Name")
|
||||
listwin~mvaddstr(3, 22, "Last Name")
|
||||
listwin~mvaddstr(4, 2, "-- ---------- ---------")
|
||||
/* listwin~mvaddstr(2, 38, "Phone")
|
||||
listwin~mvaddstr(2, 54, "Email") */
|
||||
listwin~mvaddstr(4, 2, "ID")
|
||||
listwin~mvaddstr(4, 6, "First Name")
|
||||
listwin~mvaddstr(4, 18, "Last Name")
|
||||
listwin~mvaddstr(4, 30, "Phone")
|
||||
listwin~mvaddstr(4, 50, "Email")
|
||||
listwin~mvaddstr(5, 2, "-- ---------- --------- --------------- ------------------")
|
||||
listwin~attroff(listwin~A_BOLD)
|
||||
|
||||
/* Get all contacts */
|
||||
contacts = db~getAllContacts()
|
||||
|
||||
/* Display contacts */
|
||||
if contacts~items > 0 then do
|
||||
do i = 1 to contacts~items
|
||||
contact = contacts[i]
|
||||
listwin~mvaddstr(i+4, 2, contact['ID'])
|
||||
listwin~mvaddstr(i+4, 6, contact['FIRST_NAME'])
|
||||
listwin~mvaddstr(i+4, 22, contact['LAST_NAME'])
|
||||
/* listwin~mvaddstr(i+3, 38, contact['phone'])
|
||||
listwin~mvaddstr(i+3, 54, contact['email']) */
|
||||
|
||||
listwin~mvaddstr(i+5, 2, contact['ID'])
|
||||
listwin~mvaddstr(i+5, 6, contact['FIRST_NAME'])
|
||||
listwin~mvaddstr(i+5, 18, contact['LAST_NAME'])
|
||||
listwin~mvaddstr(i+5, 30, contact['PHONE_NUMBER'])
|
||||
listwin~mvaddstr(i+5, 50, contact['EMAIL_ADDRESS'])
|
||||
/* Break if we run out of screen space */
|
||||
if i > list_height-7 then LEAVE
|
||||
end
|
||||
@ -305,12 +323,7 @@
|
||||
else do
|
||||
listwin~mvaddstr(5, 5, "No contacts found.")
|
||||
end
|
||||
/*
|
||||
listwin~mvaddstr(list_height-1, 2, "Press any key to return to main menu")
|
||||
listwin~refresh()
|
||||
*/
|
||||
|
||||
/* Wait for any key */
|
||||
listwin~getch()
|
||||
self~dropWindow(listwin)
|
||||
RETURN
|
||||
@ -352,6 +365,9 @@
|
||||
self~displaySearchResults(term)
|
||||
return
|
||||
|
||||
/**************************
|
||||
* DISPLAY SEARCH RESULTS *
|
||||
**************************/
|
||||
::METHOD displaySearchResults
|
||||
expose win menuwin db
|
||||
use arg term
|
||||
@ -408,7 +424,9 @@
|
||||
end
|
||||
return buffer
|
||||
|
||||
/***************/
|
||||
/** MAIN LOOP **/
|
||||
/***************/
|
||||
::method mainLoop
|
||||
expose win mainMenu menuwin selected menu_items menu_keys
|
||||
menuwin~refresh
|
||||
@ -462,7 +480,9 @@
|
||||
end /* do while running */
|
||||
return
|
||||
|
||||
/* Process selection */
|
||||
/***********************
|
||||
* PROCESS SELECTION *
|
||||
***********************/
|
||||
::METHOD ProcessSelection
|
||||
expose menu_items menu_keys
|
||||
use arg menuwin, key_char
|
||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user