Advertisement
GrahamC

parts.r

Apr 5th, 2014
1,117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rebol [title: "Parts"]
  2.  
  3. write/append %data.txt ""
  4. database: load %data.txt
  5.  
  6. clear-values: func [] [
  7.     foreach fc gui/pane [
  8.         if any [
  9.             fc/style = 'field
  10.             fc/style = 'area
  11.         ][
  12.             clear-face fc
  13.         ]
  14.     ]
  15. ]
  16.  
  17. view center-face gui: layout [
  18.     text "Parts in Stock:"
  19.         name-list: text-list blue 400x100 data sort (extract database 4) [
  20.         if none? value [return]
  21.         marker: index? find database value
  22.         set-face n pick database marker
  23.         set-face a pick database (marker + 1)
  24.         set-face p pick database (marker + 2)
  25.         set-face o pick database (marker + 3)
  26.         show gui
  27.     ]
  28.     text "Part Name:" n: field 400
  29.     text "Manufacturer:" a: field 400
  30.     text "SKU:" p: field 400
  31.     text "Notes:" o: area 400x100
  32.     across
  33.     btn "Save" [
  34.         if empty? n/text [alert "You must enter a Part name." return]
  35.         if find (extract database 4) n/text [
  36.             either true = request "Overwrite existing record?" [
  37.                 remove/part (find database n/text) 4
  38.             ] [
  39.                 return
  40.             ]
  41.         ]
  42.         save %data.txt repend database copy [n/text a/text p/text o/text]
  43.         name-list/data: copy/deep sort (extract database 4)
  44.         show name-list
  45.     ]
  46.     btn "Delete" [
  47.         if true = request rejoin ["Delete " n/text "?"] [
  48.             remove/part (find database n/text) 4
  49.             save %data.txt database
  50.             do-face clear-button
  51.             name-list/data: copy/deep sort (extract database 4)
  52.             show name-list
  53.         ]
  54.     ]
  55.     clear-button: btn "New" [
  56.         clear-values
  57.         show gui
  58.     ]
  59. ]
Advertisement
RAW Paste Data Copied
Advertisement