From 39b41430f6dd18f0fec12c9b98a627fc59dd6a5c Mon Sep 17 00:00:00 2001 From: Greg Gauthier Date: Wed, 7 May 2025 21:25:20 +0100 Subject: [PATCH] more tweaking of the display all list --- app/appdb.cls | 23 +++++++++++++++ app/appui.cls | 72 +++++++++++++++++++++++++++++---------------- db/contacts.sqlite | Bin 10240 -> 10240 bytes 3 files changed, 69 insertions(+), 26 deletions(-) diff --git a/app/appdb.cls b/app/appdb.cls index 3ada79c..0c8571b 100644 --- a/app/appdb.cls +++ b/app/appdb.cls @@ -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 diff --git a/app/appui.cls b/app/appui.cls index 878d8c9..33241de 100644 --- a/app/appui.cls +++ b/app/appui.cls @@ -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 diff --git a/db/contacts.sqlite b/db/contacts.sqlite index 75334250164610bd828816dd3c1cb96727936d5b..8585a86125678511a8ef83f6ef221c9ac54d8845 100644 GIT binary patch delta 635 zcmZvYO>5Lp6ozkdGO3FeDHckN@nca+39b2>+({_dqQfv78L$*_Q!_J{nc5_`O(uw& zGX4Rvy-PRh%0)%Row#sQ!R}p4cW(6;c{+1b5vTiN;W z@D0E-hU-@ zmFNmIR!=k>=Dje-?%%^=wP|`@BWGAP!|74kbAy2DWE$UAvdx6mlQw^R2JG6A zL!+vHj#LZ8glSl#0sU&^)y{bEXGYQlMgbfW_zgec@Z;o#&v54wfTgfB-bmKtZZ~H| z!3vmEVNTiV^Ng)$W!h$Wp^qzIDjl8;;?AI;lBB``fg?D8pGbNEod=3x`3;t_JWed% z$7P3(ZHK-aP;yzX5XGFOEkyAwPC_SKIC&hig1woW!CjuG|9wf_z&noGC-5EiG3X_% z&Vhv8I)%k@Rf|mSYPnygan|PDCyO1P&a0B#I3f4aUWvT89P~F>zPy$50ng;%()xO8 F>JKpMo!|ff delta 270 zcmZn&Xb6}f%@{pV#+fmCW5PmaO(ru2ZiXd{3`-d9F^V(#Gqy1vVEn^W$h4AKlKCWa z9~howXk>7m=qNqel|^-OmWv%ESVT&}0tzg2@lrEGAnj*-j2)m!EuGNz$5ufx%i*+Su47 zKe;5oC@LefEHOPFO|zwykr5W5$%U%sT)aR77@0pYFn`)CDDr}tkB5<2mN7X$uOu=sEFyn|0b)%>9{>OV