Jump to content

Basic Recipe Keeper


nf67
 Share

Recommended Posts

Heya,

finally a script worth posting (in my opinion, that is)...

A very basic recipe keeper that can store recipes in .txt files which you are able to load by clicking them in the list.

There's not much more to it (unfortunately) :D .

Have a look:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>

$GUI = GUICreate("PieBurn", 470, 650)
$NewRecipeButton = GUICtrlCreateButton("New Recipe", 0, 0, 125, 24, $WS_GROUP)
GUICtrlSetFont(-1, 8, 800, 2, "Lucida Handwriting")
$RecipeListBox = GUICtrlCreateList("", 0, 25, 125, 625)
GUICtrlSetFont(-1, 10, 400, 2, "Times New Roman")

$TitleInput = GUICtrlCreateInput("Title", 130, 5, 335, 21)


Dim $Ing[11]
Dim $Q[11]
Dim $QT[11]

$Ing[1] = GUICtrlCreateInput("Ingredient", 130, 45, 185, 21)
$Q[1] = GUICtrlCreateInput("Qty.", 315, 45, 30, 21)
$QT[1] = GUICtrlCreateInput("Qty. type", 345, 45, 120, 21)

$Ing[2] = GUICtrlCreateInput("Ingredient", 130, 69, 185, 21)
$Q[2] = GUICtrlCreateInput("Qty.", 315, 69, 30, 21)
$QT[2] = GUICtrlCreateInput("Qty. type", 345, 69, 120, 21)

$Ing[3] = GUICtrlCreateInput("Ingredient", 130, 93, 185, 21)
$Q[3] = GUICtrlCreateInput("Qty.", 315, 93, 30, 21)
$QT[3] = GUICtrlCreateInput("Qty. type", 345, 93, 120, 21)

$Ing[4] = GUICtrlCreateInput("Ingredient", 130, 117, 185, 21)
$Q[4] = GUICtrlCreateInput("Qty.", 315, 117, 30, 21)
$QT[4] = GUICtrlCreateInput("Qty. type", 345, 117, 120, 21)

$Ing[5] = GUICtrlCreateInput("Ingredient", 130, 141, 185, 21)
$Q[5] = GUICtrlCreateInput("Qty.", 315, 141, 30, 21)
$QT[5] = GUICtrlCreateInput("Qty. type", 345, 141, 120, 21)

$Ing[6] = GUICtrlCreateInput("Ingredient", 130, 165, 185, 21)
$Q[6] = GUICtrlCreateInput("Qty.", 315, 165, 30, 21)
$QT[6] = GUICtrlCreateInput("Qty. type", 345, 165, 120, 21)

$Ing[7] = GUICtrlCreateInput("Ingredient", 130, 189, 185, 21)
$Q[7] = GUICtrlCreateInput("Qty.", 315, 189, 30, 21)
$QT[7] = GUICtrlCreateInput("Qty. type", 345, 189, 120, 21)

$Ing[8] = GUICtrlCreateInput("Ingredient", 130, 213, 185, 21)
$Q[8] = GUICtrlCreateInput("Qty.", 315, 213, 30, 21)
$QT[8] = GUICtrlCreateInput("Qty. type", 345, 213, 120, 21)

$Ing[9] = GUICtrlCreateInput("Ingredient", 130, 237, 185, 21)
$Q[9] = GUICtrlCreateInput("Qty.", 315, 237, 30, 21)
$QT[9] = GUICtrlCreateInput("Qty. type", 345, 237, 120, 21)

$Ing[10] = GUICtrlCreateInput("Ingredient", 130, 261, 185, 21)
$Q[10] = GUICtrlCreateInput("Qty.", 315, 261, 30, 21)
$QT[10] = GUICtrlCreateInput("Qty. type", 345, 261, 120, 21)

$InstructionBox = GUICtrlCreateEdit("Instructions", 130, 290, 335, 330, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_VSCROLL))

$SaveButton = GUICtrlCreateButton("Save", 130, 625, 165, 25, $WS_GROUP)
GUICtrlSetFont(-1, 8, 800, 2, "Lucida Handwriting")
$DiscardButton = GUICtrlCreateButton("Discard", 295, 625, 165, 25, $WS_GROUP)
GUICtrlSetFont(-1, 8, 800, 2, "Lucida Handwriting")
LoadFirstRecipe()
RecipeListBoxRefresh()
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $RecipeListBox
            LoadRecipe()
        Case $NewRecipeButton
            NewRecipe()
        Case $SaveButton
            SaveRecipe()
        Case $DiscardButton
            Discard()
    EndSwitch
WEnd

Func NewRecipe()
    $SaveTitleData = GUICtrlRead($TitleInput)
     If FileExists(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt") Then
    ResetInputs()
    Else
        $ForgotSaveMsgBox = MsgBox(4, "Save?", "Before you go on, do you want to save this " & $SaveTitleData & " recipe?")
            If $ForgotSaveMsgBox = 6 then
                WriteSaveFile()
                ResetInputs()
            Else
                ResetInputs()
            EndIf
    EndIf
EndFunc

Func ResetInputs()
        GUICtrlSetData($TitleInput, "Title")
        For $Number = 1 to 10
            GUICtrlSetData($Ing[$Number], "Ingredient")
            GUICtrlSetData($Q[$Number], "Qty.")
            GUICtrlSetData($QT[$Number], "Qty. type")
        Next
        GUICtrlSetData($InstructionBox, "Instructions")
EndFunc

Func SaveRecipe()
    $SaveTitleData = GUICtrlRead($TitleInput)
    If FileExists(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt") Then
         $OverwriteMsgBox = MsgBox(4, "Overwrite?", "Do you want to overwrite your other " & $SaveTitleData & " recipe?")
            If $OverwriteMsgBox = 6 then
                FileDelete(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt")
                WriteSaveFile()
            EndIf
    Else
        WriteSaveFile()
    EndIf
EndFunc

Func WriteSaveFile()
                $SaveTitleData = GUICtrlRead($TitleInput)
                FileWrite(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt", $SaveTitleData & @TAB)

                For $Number = 1 to 10
                $SaveIngData = GUICtrlRead($Ing[$Number])
                FileWrite(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt", $SaveIngData & @TAB)
                $SaveQData = GUICtrlRead($Q[$Number])
                FileWrite(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt", $SaveQData & @TAB)
                $SaveQTData = GUICtrlRead($QT[$Number])
                FileWrite(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt", $SaveQTData & @TAB)
                Next

                $SaveInstructionData = GUICtrlRead($InstructionBox)
                FileWrite(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt", $SaveInstructionData)

                If FileExists(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt") Then
                    MsgBox(0, "Success!", "Your " & $SaveTitleData & " recipe has been saved.")
                    RecipeListBoxRefresh()
                EndIf
EndFunc

Func RecipeListBoxRefresh()
    GUICtrlSetData($RecipeListBox, "")
    $FileSearch = FileFindFirstFile("PB-*.*")
    While 1
        $RecipeFile = FileFindNextFile($FileSearch)
            If @Error Then ExitLoop
        GUICtrlSetData($RecipeListBox, $RecipeFile & "|")
    WEnd
    FileClose($FileSearch)
EndFunc

Func LoadFirstRecipe()
    GUICtrlSetData($RecipeListBox, "")
    $FileSearch = FileFindFirstFile("PB-*.*")
    $RecipeFile = FileFindNextFile($FileSearch)
        If @Error Then
        MsgBox(0, "No recipes!", "You don't have any recipes yet.")
        Else
            $LoadData=FileRead(@ScriptDir & "\" & $RecipeFile )
            $LoadData = StringSplit($LoadData, @TAB)

            GUICtrlSetData($TitleInput, $LoadData[1])
            For $Number = 1 to 10
                $ArrayNumber=3 * $Number - 1
                GUICtrlSetData($Ing[$Number], $LoadData[$ArrayNumber])
                $ArrayNumber=3 * $Number
                GUICtrlSetData($Q[$Number], $LoadData[$ArrayNumber])
                $ArrayNumber=3 * $Number + 1
                GUICtrlSetData($QT[$Number], $LoadData[$ArrayNumber])
            Next
            GUICtrlSetData($InstructionBox, $LoadData[32])
        EndIf
EndFunc

Func LoadRecipe()
     $SaveTitleData = GUICtrlRead($TitleInput)
     If FileExists(@ScriptDir & "\PB-" & $SaveTitleData &  ".txt") Then
    LoadSaveFile()
    Else
        $ForgotSaveMsgBox = MsgBox(4, "Save?", "Before you go on, do you want to save this " & $SaveTitleData & " recipe?")
            If $ForgotSaveMsgBox = 6 then
                SaveRecipe()
                LoadSaveFile()
            Else
                LoadSaveFile()
            EndIf
    EndIf
EndFunc

Func LoadSaveFile()
        $RecipePressed = GUICtrlRead($RecipeListBox)
        $LoadData=FileRead(@ScriptDir & "\" & $RecipePressed )
        $LoadData = StringSplit($LoadData, @TAB)

        GUICtrlSetData($TitleInput, $LoadData[1])
        For $Number = 1 to 10
            $ArrayNumber=3 * $Number - 1
            GUICtrlSetData($Ing[$Number], $LoadData[$ArrayNumber])
            $ArrayNumber=3 * $Number
            GUICtrlSetData($Q[$Number], $LoadData[$ArrayNumber])
            $ArrayNumber=3 * $Number + 1
            GUICtrlSetData($QT[$Number], $LoadData[$ArrayNumber])
        Next
        GUICtrlSetData($InstructionBox, $LoadData[32])
EndFunc

Func Discard()
    $SaveTitleData = GUICtrlRead($TitleInput)
    $DeleteMsgBox = MsgBox(4, "Delete?", "Are you sure you want to delete your " & $SaveTitleData & " recipe?")
        If $DeleteMsgBox = 6 Then
            ResetInputs()
            If FileExists(@ScriptDir & "\PB-" & $SaveTitleData & ".txt") then FileDelete(@ScriptDir & "\PB-" & $SaveTitleData & ".txt")
            RecipeListBoxRefresh()
        EndIf
EndFunc

Take the attachment for a .zip including the executable, some example recipes and the script.

:D

PieBurn.zip

Edited by nf67
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...