# <center><i class="fa fa-edit"></i> Smart Dispenser: `members_additional_card` Subfunction Pseudocode </center> ###### tags: `Internship` :::info **Goal:** - [x] Code the subfunction for collection `members_additional_Card` - [x] Need to test run later, do not change the original member data - [x] 由於目前的系統設計是只要有卡片能感應就能夠取水,因此在新增卡片前請記得檢查成員資料庫中是否已有相同卡號且身份為"unregistered" 成員,如果有的話則需要刪掉該筆資料 同時也須要注意是否有卡號重複的情形 **Resources:** [PyQt](https://hackmd.io/Ibk_VuuWRXOjkION4wk3tg) [newXinXingPyQtStructure](https://drive.google.com/drive/folders/1QNJJxxug1Njb9ATe-BdzcZKZZ1PGI2Sd?usp=sharing) [CodiMD](https://hackmd.io/c/codimd-documentation/%2F%40codimd%2Fextra-supported-syntax#Flow-Chart) [冠辰參考的筆記](https://www.wongwonggoods.com/page/4/?s=pyqt&ct_post_type=post%3Apage&ct_product_price=1) ::: ### Figures *Figure 1. Open a new collection members_additional_card* ![](https://i.imgur.com/HIZq4rs.jpg) *Figure 2. Flowchart* ![](https://i.imgur.com/KeSi6dk.jpg) ### Subfunction PseudoCode **main** ``` while loop to keep asking for user put { s = user input of schoolID verify(s) } if input is NOT in schoolID field of members_additional_data popupRRE() if schoolID is in collection members_additional card display PyQt page ask user if they want to add an additonal card if yes while loop to keep asking for user put { a = user input of cardID verify(a) } if checkPrim(a,s) is true, then display error popup: sorry, this ID is already registered as your primary card else if checkAdd(a,s) is true , then display error popup: sorry, this ID is already registered as your additional card else addCard(a,s) checkDoubles(a) display updated members_additional_card in PyQt ``` **subfunctions of subfunctions** ``` void verify8(int input) if len(input) is not 8 system print "Please enter 8 numbers" change input from string to integer if input is not an int: raise TypeError("Only numbers are allowed") ask if they want to reenter ``` ``` void verify10(int input) if len(input) is not 10 system print "Please enter 10 numbers" change input from string to integer if input is not an int: raise TypeError("Only numbers are allowed") ask if they want to re-enter ``` ``` void popupRRE() display error invalid schoolID with options to re-enter schoolID, register as new user, or exit if re-enter is hit, go through process above else if register as new user is hit, direct them to registration window else exit = system exit ``` ``` boolean checkPrim(int a, int s) if fields with s and primaryCard contain a, then return true else return false ``` ``` boolean checkAdd(int a, int s) if fields with s and additionalCard contain a, then return true else return false ``` ``` void addCard(int a, int s) add card to collection with schoolID field filled in as s, primaryCard field filled in as the interger whens && (primaryCard == additionalCard) ``` ``` void checkDoubles(int a) search through collections members_data for the following: if (a == cardID and unregistered) deleteAll ```