# <center><i class="fa fa-edit"></i> Smart Dispenser: `members_additional_card` Subfunction Code Cont. </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 **Resources:** [PyQt](https://hackmd.io/Ibk_VuuWRXOjkION4wk3tg) [newXinXingPyQtStructure](https://drive.google.com/drive/u/0/folders/1Ahr8zkZgUv8ujauLKGz1ZSzkZq0M9_mx) [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) ::: --- :::spoiler **Expand Catalog** [TOC] ::: --- ### 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) --- ### Current Code **Current Imports** * Added XinxingQt as an import. * This is the python file 冠辰 wrote for querying and updating the collection. ![](https://i.imgur.com/GURCG4K.png) **Ask for schoolID** * A lot of changes made here: * Created global variable `count1` as a counter because the popup would show up and not close itself. * If I put `pop.destroy()` in the beginning of the function, `pop` would not be declared at all since its declation is in `popupRR()` which is called in verified. * Created global variable `s` so that the schoolID string could be referenced everywhere. * Put `verify8(s)` inside the function to make sure every time an input is asked, it is them immediately verified. * Changes being made to `verify8(input)` will be specified later on in this notes page * When hitting cancel on the input dialogue box, `popupRR()` would execute regardless. Changed it so that when cancel is hit (or when the `input == None`), the code exits the system ![](https://i.imgur.com/fc5nVrj.png) **Ask for CardID** * A lot of changes made here as well but are analogous to **Ask for SchoolID** * Only differences are `count1` is now `count2`, `s` is now `a`, and`verify8(input)` is now `verify10(input)` ![](https://i.imgur.com/BVoKPes.png) **Verify the Input for School ID is 8 numbers** * Utilized a try-except-else. * Did not updated `s` to its parsed integer counterpart`int(input)` since MongoDB utilizes strings as field values. ![](https://i.imgur.com/yPh0N3T.png) **Verify the Input for Card ID is 10 numbers** * Highly similar to **Verify the Input for School ID is 8 numbers**. * Only Only differences are `s` is now `a` and`verify8(input)` is now `verify10(input)`. ![](https://i.imgur.com/ENsxN1h.png) :::warning Ended up making a registration function in addition to the planned ones ([can be referenced here](https://hackmd.io/@tiffanycheng/ry3LHLn55)) ::: **Register New User** * They way the current system is built is that when a new user swipes their new card, it will automatically be added to the database, thus qualifying the definition of being registered. :::danger *Need to confirm with Ren if this is what she intended* ::: * Utilizes a try-except ![](https://i.imgur.com/qQZejSH.png) **User Choice to Re-enter or Register** * Two changes: * The function is called not only in the two verify functions, but also in the `check()` function. However, it requires a different message being displayed, so I added a `msg` parameter. * Made `pop` global so that `pop.destroy()` could be called in `askSI()` and `askCI()` * `pop.destroy` did not work so tried `pop.destroy()` instead. This ended up working. ![](https://i.imgur.com/RrlgiK7.png) :::warning Ended up making a check function in addition to the planned ones ([can be referenced here](https://hackmd.io/@tiffanycheng/ry3LHLn55)) ::: **Check if the School ID is in `members_data`** * This step was preplanned in the flowchart (See Figure 2). * However, when writing the pseudocode, I envisioned this as a one line if statement and did not create a function for it. * This ended up being a try-catch so I prefer this to be organaized into a function. ![](https://i.imgur.com/IpBSdkY.png) **Check if Card ID is Already Registered as a Primary Card** * Changed the fields from `(a, s)` to `(s1, a1)` * `a` and `s` are now my global variables for the user input of their additional card ID and school ID respectively * Did not want variables and parameters having same name. * Personal preference of disliking and not wanting to use `this.` for same name variables. * Function still returns true or false as planned in the pseudocode. ![](https://i.imgur.com/W30X10w.png) **Check if Card ID is Already Registered as an Additional Card** * Same as above ![](https://i.imgur.com/SUZKDv6.png) :::warning `askAdd()` was built to ask user if they want to input an additional card. Originally coded it as a tkinker popup but changed it to a tkinker message box as shown: ![](https://i.imgur.com/Zgk9rLi.png) This ended up being one line of code and no longer needed to be a function so it is now put in the condition of an if statement as follows: ![](https://i.imgur.com/dvqu0uA.png) ::: **Current Main Method** * Not sure if the displaying to PyQt is part of my task or part of 冠辰's task. *Will confirm.* ![](https://i.imgur.com/JEHnoQQ.png)