|
|
| Testing a file item for duplicates while Nulls are allowed Overview: Sometimes you run into a file item (numeric or alpha) which is not to be filled-in mandatory, but if there’s an input value, it has to be a unique one. As an example: POS systems need to have the EAN 8 / 13 (= UPC 8/13) number stored for scanning the bar-code while there are numerous items in a store which will not have a bar code on them at all. So, though one is tempted to define the EAN 8/13 file item to be a ‘unique’ key value this is in fact impossible because some items in the store will have no EAN bar code on them at all and HyperFileSQL treats two Nulls in key field as being duplicates! So, you have to define the file item as one ‘with duplicates’ but this is not the intended usage. Each EAN 8/13 number should point to a single article. So, we have to test that file item on our own in order to prevent duplicates - except for the Nulls or empty items, of course. Note: WindowMode is a string variable, used in ‘old’ RAD 11 to identify whether the Form is used to create a new record or modifies an existing record. It can take the values ‘Creation’ or ‘Modify’. MyPosition is 4-byte integer. File name is KUNDEN and the file item (with duplicates) is KUNDEN.KU_SORT1. Variable OLD_KU_SORT1 contains the value of KU_SORT1 before any modifications are applied. Example 1: Code in the exit code of a numeric Edit control named MySelf: IF MySelf <> 0 THEN // Gibt es diese KundenSortier-Nummer 1 schon ? IF Left(WindowMode,8) <> "Creation" THEN MyPosition = HSavePosition(KUNDEN) ELSE MyPosition = 0 END IF Left(WindowMode,8) = "Creation" THEN // Es darf kein solcher record da sein ! HReadSeekFirst(KUNDEN,KU_SORT1,MySelf) IF HFound(KUNDEN) THEN Error("Diese Kunden-SortierfolgeNummer 1 wurde schon für "+KUNDEN.KU_NUMSUCH+" vergeben !") IF MyPosition > 0 THEN HRestorePosition(MyPosition) ReturnToCapture(MySelf) ELSE IF MyPosition > 0 THEN HRestorePosition(MyPosition) END END IF Left(WindowMode,8)<>"Creation" AND OLD_KU_SORT1 <> MySelf THEN HReadSeekFirst(KUNDEN,KU_SORT1,MySelf) IF HFound(KUNDEN) THEN Error("Diese Kunden-SortierFolgeNummer 1 wurde schon für "+KUNDEN.KU_NUMSUCH+" vergeben !") IF MyPosition > 0 THEN HRestorePosition(MyPosition) ReturnToCapture(MySelf) ELSE IF MyPosition > 0 THEN HRestorePosition(MyPosition) END ENDEND Example 2: Code in the exit code of a text Edit control (contains EAN 8 / 13) File is ARTIKEL and file item is ARTIKEL.ART_EAN13. Variable OLD_EAN contains the EAN code before modification. Variable MyPosition is a 4-byte integer and contains the pointer to the saved file buffer / pointer etc. // Prüfung auf Doppelte!IF NoSpace(MySelf) <> "" THEN // Gibt es diese EAN-Nummer schon ? IF Left(WindowMode,8) <> "Creation" THEN MyPosition = HSavePosition(ARTIKEL) ELSE MyPosition = 0 END IF Left(WindowMode,8) = "Creation" THEN // Es darf kein solcher record da sein ! HReadSeekFirst(ARTIKEL,ART_EAN13,NoSpace(MySelf)) IF HFound(ARTIKEL) THEN Error("Diese EAN 13 / 8 - Nummer wurde schon für "+ARTIKEL.ART_NUMSUCH+" vergeben !") IF MyPosition > 0 THEN HRestorePosition(MyPosition) ReturnToCapture(MySelf) ELSE IF MyPosition > 0 THEN HRestorePosition(MyPosition) END END IF Left(WindowMode,8)<>"Creation" AND NoSpace(OLD_EAN) <> NoSpace(MySelf) THEN HReadSeekFirst(ARTIKEL,ART_EAN13,NoSpace(MySelf)) IF HFound(ARTIKEL) THEN Error("Diese EAN 13 / 8 - Nummer wurde schon für "+ARTIKEL.Art_NumSuch+" vergeben !") IF MyPosition > 0 THEN HRestorePosition(MyPosition) ReturnToCapture(MySelf) ELSE IF MyPosition > 0 THEN HRestorePosition(MyPosition) END ENDEND |
|
|
|