Damein

Parts / Inventory / Database Manager

1 post in this topic

#1 ·  Posted

Hey, wasn't quite sure what to call it on here so we'll go with that, lol.

 

It's pretty simple but pretty efficient IMO and is going to help me out a lot.

 

When I finish a job I have to present all the part numbers and the serial numbers of whatever I work on. Each facility is different but I can load a database and have it all in one easy location.

 

It started out as something I just made for myself but turned into something more professional and universal. The Listviews and INI's can be pretty much changed to whatever is needed for anything so I thought I'd share. Thanks!

 

Images

gup7vaY.png

 

 

bSZtVz3.png

 

v2OqdvA.png

 

Vtb2QAz.png

 

 

So when you click on the "Manage Database" button it requests a folder with stored Databases. If the folder contains no Parts/Equipment INI's it will automatically create them.

 

The rest is pretty self-explanatory.

 

Sources

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Images\Icon.ico
#AutoIt3Wrapper_Compression=0
#AutoIt3Wrapper_Res_Fileversion=1.3.0.0
#AutoIt3Wrapper_Res_LegalCopyright=R.S.S.
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
; *** End added by AutoIt3Wrapper ***

#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Excel.au3>
#include <ListViewConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include "SearchWorkOrdersModule.au3"
#include "ManageDatabaseModule.au3"

Local $hDLL = DllOpen("user32.dll")

Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 3)
Global $CurrentGUI, $MainGUI, $ManageGUI, $ManagePartsGUI, $ManageUnitsGUI, $DatabasePath, $WorkOrdersGUI, $ViewWorkOrdersGUI

_CreateMainGUI()

Func _CreateMainGUI()
    $CurrentGUI = "Main"
    $MainGUI = GUICreate("Waddell Power Database Manager", 400, 250)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

    GUISetBkColor(0xFFFFFF)

    $ManageDatabasesButton = GUICtrlCreateButton("Manage Databases", 10, 90, 185, 60)
    GUICtrlSetOnEvent(-1, "_CreateManageGUI")
    GUICtrlSetFont(-1, 15)

    $SearchWorkOrdersButton = GUICtrlCreateButton("Search Work Orders", 205, 90, 185, 60)
    GUICtrlSetOnEvent(-1, "_CreateWorkOrdersGUI")
    GUICtrlSetFont(-1, 14.5)

    $ExitButton = GUICtrlCreateButton("Exit", 110, 170, 185, 60)
    GUICtrlSetOnEvent(-1, "_Exit")
    GUICtrlSetFont(-1, 15)

    GUICtrlCreateLabel("© RS Software", 335, 240, 200)
    GUICtrlSetFont(-1, 7)
    GUICtrlCreateLabel("Version 1.2", 1, 240, 200)
    GUICtrlSetFont(-1, 7)

    GUICtrlCreatePic(@ScriptDir & "\Images\Logo.bmp", 50, 5, 300, 70)
    GUISetState()
EndFunc   ;==>_CreateMainGUI

Func _CloseGUI()
    If $CurrentGUI = "Manage" Then
        GUIDelete($ManageGUI)
        GUISetState(@SW_ENABLE, $MainGUI)
        Sleep(100)
        WinActivate($MainGUI)
        $CurrentGUI = "Main"
    EndIf
    If $CurrentGUI = "Parts" Then
        GUIDelete($ManagePartsGUI)
        GUISetState(@SW_ENABLE, $ManageGUI)
        Sleep(100)
        WinActivate($ManageGUI)
        $CurrentGUI = "Manage"
    EndIf
    If $CurrentGUI = "Units" Then
        GUIDelete($ManageUnitsGUI)
        GUISetState(@SW_ENABLE, $ManageGUI)
        Sleep(100)
        WinActivate($ManageGUI)
        $CurrentGUI = "Manage"
    EndIf
    If $CurrentGUI = "Work Orders" Then
        GUIDelete($WorkOrdersGUI)
        GUISetState(@SW_ENABLE, $MainGUI)
        Sleep(100)
        WinActivate($MainGUI)
        $CurrentGUI = "Main"
    EndIf
    If $CurrentGUI = "View Work Orders" Then
        GUIDelete($ViewWorkOrdersGUI)
        GUISetState(@SW_ENABLE, $MainGUI)
        Sleep(100)
        WinActivate($MainGUI)
        $CurrentGUI = "Main"
    EndIf
EndFunc   ;==>_CloseGUI

Func _Exit()
    Exit
EndFunc   ;==>_Exit

While 1
    Sleep(10)
WEnd

 

ManageDatabaseModule

Global $CurrentGUI, $ManageGUI, $ListView, $ManagePartsGUI, $ManageUnitsGUI, $DatabasePath, $SearchPartsInput, $SearchEquipmentInput, $PartList
Global $g_bSortSense = True

Func _CreateManageGui()

    $DatabasePath = FileSelectFolder("Select Folder...", @MyDocumentsDir)
    If $DatabasePath = "" Then
        MsgBox(48, "Error", "No database selected, cancelling operation!")
    Else
        GUISetState(@SW_DISABLE, $MainGui)
        $CurrentGUI = "Manage"
        $ManageGUI = GUICreate("Manage Database's", 400, 250)
        GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseGUI")

        GUISetBkColor(0xFFFFFF)

        $ManagePartsButton = GUICtrlCreateButton("Manage Parts", 10, 90, 185, 60)
        GUICtrlSetOnEvent(-1, "_ManageParts")
        GUICtrlSetFont(-1, 15)

        $ManageUnitsButton = GUICtrlCreateButton("Manage Equipment", 205, 90, 185, 60)
        GUICtrlSetOnEvent(-1, "_ManageEquipment")
        GUICtrlSetFont(-1, 15)

        $ExitButton = GUICtrlCreateButton("Close", 100, 180, 185, 60)
        GUICtrlSetOnEvent(-1, "_CloseGUI")
        GUICtrlSetFont(-1, 15)

        GUICtrlCreatePic(@ScriptDir & "\Images\Logo.bmp", 50, 5, 300, 70)
        GUISetState()
    EndIf
EndFunc   ;==>_CreateManageGui

Func _ManageParts()
    GUISetState(@SW_DISABLE, $ManageGUI)
    $CurrentGUI = "Parts"
    If FileExists($DatabasePath & "/Parts Database.ini") Then
        $ReadData = IniReadSection($DatabasePath & "/Parts Database.ini", "Parts")
    Else
        MsgBox(0, "Database Created", "No database was found, creating new database!")
        FileCopy(@ScriptDir & "/Data/Default Parts Database.ini", $DatabasePath & "/Parts Database.ini")
        FileCopy(@ScriptDir & "/Data/Default Equipment Database.ini", $DatabasePath & "/Equipment Database.ini")
        $ReadData = IniReadSection($DatabasePath & "/Parts Database.ini", "Parts")
    EndIf

    $ManagePartsGUI = GUICreate("Parts", 600, 660)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseGUI")
    GUISetBkColor(0xFFFFFF)

    GUICtrlCreateLabel("Search Parts", 12, 20, 130, 40)
    GUICtrlSetFont(-1, 16)

    $SearchPartsInput = GUICtrlCreateInput("", 150, 18, 250, 30)
    GUICtrlSetFont(-1, 16)

    $SearchPartsButton = GUICtrlCreateButton("Search", 450, 5, 100, 50)
    GUICtrlSetOnEvent(-1, "_SearchParts")
    GUICtrlSetFont(-1, 16)

    $ListView = GUICtrlCreateListView("Part Number|Description|Product Line|Bin Number", 10, 60, 580, 500, $LVS_SORTASCENDING)
    _GUICtrlListView_SetColumnWidth(-1, 0, 200)
    _GUICtrlListView_SetColumnWidth(-1, 1, 500)
    _GUICtrlListView_SetColumnWidth(-1, 2, 200)
    _GUICtrlListView_SetColumnWidth(-1, 3, 200)

    For $i = 1 To UBound($ReadData) - 1
        GUICtrlCreateListViewItem($ReadData[$i][0] & "|" & $ReadData[$i][1], $ListView)
    Next

    $AddNewPartButton = GUICtrlCreateButton("Add", 10, 565, 220, 40)
    GUICtrlSetOnEvent(-1, "_AddPart")
    GUICtrlSetFont(-1, 16)

    $EditPartButton = GUICtrlCreateButton("Edit", 370, 565, 220, 40)
    GUICtrlSetOnEvent(-1, "_EditPart")
    GUICtrlSetFont(-1, 16)

    $RemovePartButton = GUICtrlCreateButton("Remove", 10, 615, 220, 40)
    GUICtrlSetOnEvent(-1, "_RemovePart")
    GUICtrlSetFont(-1, 16)

    $CloseButton = GUICtrlCreateButton("Close", 370, 615, 220, 40)
    GUICtrlSetOnEvent(-1, "_CloseGUI")
    GUICtrlSetFont(-1, 16)

    $ExportButton = GUICtrlCreateButton("Export", 250, 590, 100, 50)
    GUICtrlSetOnEvent(-1, "_Export")
    GUICtrlSetFont(-1, 16)

    GUISetState()
    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
EndFunc   ;==>_ManageParts

Func _Export()
    SplashTextOn("Exporting...", "Exporting... please wait...", 300, 50, Default, Default, 33)
    Local $oExcel = _Excel_Open()
    If @error Then Exit MsgBox(16, "Excel UDF: _Excel_BookOpenText Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended)

    ; *****************************************************************************
    ; Open a text file as delimited, separator = |, pass fieldinfo and set
    ; DecimalSeparator and ThousandsSeparator.
    ; *****************************************************************************
    _FileReadToArray($DatabasePath & "/Parts Database.ini", $PartList)
    FileDelete(@TempDir & "/Temp Part Database.txt")
    FileWrite(@TempDir & "/Temp Part Database.txt", "Part Number|Part Description|Product Line|Bin Number|Count" & @CRLF)
    For $i = 2 To UBound($PartList) - 1
        If StringInStr($PartList[$i], "=") Then
            $PartList[$i] = StringReplace($PartList[$i], "=", "|")
        EndIf
        FileWrite(@TempDir & "/Temp Part Database.txt", $PartList[$i] & @CRLF)
    Next
    Local $sTextFile = @TempDir & "/Temp Part Database.txt"
    $oWorkbook = _Excel_BookOpenText($oExcel, $sTextFile, Default, $xlGeneralFormat, Default, Default, "|")
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_BookOpenText Example 1", "Error opening '" & $sTextFile & "'." & @CRLF & "@error = " & @error & ", @extended = " & @extended)
        Exit
    Else
    EndIf
    SplashOff()
EndFunc   ;==>_Export

Func _AddPart()
    GUISetState(@SW_DISABLE, $ManagePartsGUI)
    $Stop = 0
    $NewPartNumber = InputBox("Add Part", "Please input the part number you wish to add.")
    If $NewPartNumber = "" Then
        MsgBox(48, "Error", "No part number input, cancelling addition of a new part!")
        $Stop = 1
    EndIf

    If $Stop = 0 Then
        $NewPartDescription = InputBox("Add Part", "Please input the part description you wish to add.")
        If $NewPartDescription = "" Then
            MsgBox(48, "Error", "No part description was inputted, cancelling addition of a new part!")
            $Stop = 1
        EndIf
    EndIf

    If $Stop = 0 Then
        $NewPartProductLine = InputBox("Add Part", "Please input the product line associated with this part that you wish to add.")
        If $NewPartProductLine = "" Then
            MsgBox(48, "Error", "No product line was inputted, cancelling addition of a new part!")
            $Stop = 1
        EndIf
    EndIf

    If $Stop = 0 Then
        $NewPartBin = InputBox("Add Part", "Please input the part bin number you wish to add.")
        If $NewPartBin = "" Then
            MsgBox(48, "Error", "No part bin number was inputted, cancelling addition of a new part!")
            $Stop = 1
        EndIf
    EndIf

    If $Stop = 0 Then
        $CheckMsgBox = MsgBox(4, "Add Part", "Are you sure you wish to add the following part?" & @CRLF & @CRLF & "Part Number: " & $NewPartNumber & @CRLF & "Part Description: " & $NewPartDescription & @CRLF & "Product Line: " & $NewPartProductLine & @CRLF & "Bin Number: " & $NewPartBin)
        If $CheckMsgBox = 6 Then
            IniWrite($DatabasePath & "/Parts Database.ini", "Parts", $NewPartNumber, $NewPartDescription & "|" & $NewPartProductLine & "|" & $NewPartBin)
            MsgBox(0, "Add Part", "Part number: " & $NewPartNumber & " has been added!")
            GUICtrlCreateListViewItem($NewPartNumber & "|" & $NewPartDescription & "|" & $NewPartProductLine & "|" & $NewPartBin, $ListView)
        Else
            MsgBox(48, "Add Part", "You have chosen to cancel the addition of a new part!")
        EndIf
    EndIf
    GUISetState(@SW_ENABLE, $ManagePartsGUI)
    Sleep(100)
    WinActivate($ManagePartsGUI)
EndFunc   ;==>_AddPart

Func _EditPart()
    GUISetState(@SW_DISABLE, $ManagePartsGUI)
    $ListViewGetSelection = _GUICtrlListView_GetSelectionMark($ListView)
    $GetPartNumber = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 0)
    $GetPartDescription = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 1)
    $GetPartProductLine = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 2)
    $GetPartBin = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 3)
    If $GetPartNumber[3] = "" Then
        MsgBox(48, "Error", "No part was selected, cancelling operation!")
    Else
        $Stop = 0
        $EditPartNumber = InputBox("Edit Part", "Please input a new part number or leave the part number the same.", $GetPartNumber[3])
        If $EditPartNumber = "" Then
            MsgBox(48, "Error", "No part number input, cancelling edit of part!")
            $Stop = 1
        EndIf

        If $Stop = 0 Then
            $EditPartDescription = InputBox("Edit Part", "Please input a new part description or leave the description the same.", $GetPartDescription[3])
            If $EditPartDescription = "" Then
                MsgBox(48, "Error", "No part description was inputted, cancelling edit of part!")
                $Stop = 1
            EndIf
        EndIf

        If $Stop = 0 Then
            $EditPartProductLine = InputBox("Edit Part", "Please input a new product line associated with this part that you wish to edit or leave it the same.", $GetPartProductLine[3])
            If $EditPartProductLine = "" Then
                MsgBox(48, "Error", "No product line was inputted, cancelling edit of part!")
                $Stop = 1
            EndIf
        EndIf

        If $Stop = 0 Then
            $EditPartBin = InputBox("Edit Part", "Please input a new part bin number or leave the number the same.", $GetPartBin[3])
            If $EditPartDescription = "" Then
                MsgBox(48, "Error", "No part bin number was inputted, cancelling edit of part!")
                $Stop = 1
            EndIf
        EndIf

        If $Stop = 0 Then
            $CheckMsgBox = MsgBox(4, "Edit Part", "Are you sure you wish to edit the following part?" & @CRLF & @CRLF & "Part Number: " & $EditPartNumber & @CRLF & "Part Description: " & $EditPartDescription & @CRLF & "Product Line: " & $EditPartProductLine & @CRLF & "Bin Number: " & $EditPartBin)
            If $CheckMsgBox = 6 Then
                IniDelete($DatabasePath & "/Parts Database.ini", "Parts", $GetPartNumber[3])
                IniWrite($DatabasePath & "/Parts Database.ini", "Parts", $EditPartNumber, $EditPartDescription & "|" & $EditPartProductLine & "|" & $EditPartBin)
                MsgBox(0, "Edit Part", "Part number: " & $EditPartNumber & " has been changed!")
                _GUICtrlListView_DeleteItem($ListView, $ListViewGetSelection)
                GUICtrlCreateListViewItem($EditPartNumber & "|" & $EditPartDescription & "|" & $EditPartProductLine & "|" & $EditPartBin, $ListView)
            Else
                MsgBox(48, "Edit Part", "You have chosen to cancel the edit of the part!")
            EndIf
        EndIf
    EndIf
    GUISetState(@SW_ENABLE, $ManagePartsGUI)
    Sleep(100)
    WinActivate($ManagePartsGUI)
EndFunc   ;==>_EditPart

Func _RemovePart()
    GUISetState(@SW_DISABLE, $ManagePartsGUI)
    $ListViewGetSelection = _GUICtrlListView_GetSelectionMark($ListView)
    $GetPartNumber = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 0)
    If $GetPartNumber[3] = "" Then
        MsgBox(48, "Error", "No part was selected, cancelling operation!")
    Else
        $CheckMsgBox = MsgBox(4, "Remove Part", "Are you sure you wish to remove the following part?" & @CRLF & @CRLF & $GetPartNumber[3])
        If $CheckMsgBox = 6 Then
            _GUICtrlListView_DeleteItem($ListView, $ListViewGetSelection)
            IniDelete($DatabasePath & "/Parts Database.ini", "Parts", $GetPartNumber[3])
            MsgBox(0, "Remove Part", "The part has been removed from the database!")
        Else
            MsgBox(48, "Remove Part", "You have chosen to cancel the removal of the part!")
        EndIf
    EndIf
    GUISetState(@SW_ENABLE, $ManagePartsGUI)
    Sleep(100)
    WinActivate($ManagePartsGUI)
EndFunc   ;==>_RemovePart

Func _ManageEquipment()
    GUISetState(@SW_DISABLE, $ManageGUI)
    $CurrentGUI = "Units"
    If FileExists($DatabasePath & "/Equipment Database.ini") Then
        $ReadData = IniReadSection($DatabasePath & "/Equipment Database.ini", "Equipment")
    Else
        MsgBox(0, "Database Created", "No database was found, creating new database!")
        FileCopy(@ScriptDir & "/Data/Default Parts Database.ini", $DatabasePath & "/Parts Database.ini")
        FileCopy(@ScriptDir & "/Data/Default Equipment Database.ini", $DatabasePath & "/Equipment Database.ini")
        $ReadData = IniReadSection($DatabasePath & "/Equipment Database.ini", "Equipment")
    EndIf

    $ManageUnitsGUI = GUICreate("Equipment", 600, 660)
    GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseGUI")

    GUISetBkColor(0xFFFFFF)

    GUICtrlCreateLabel("Search Equipment", 12, 20, 170, 40)
    GUICtrlSetFont(-1, 16)

    $SearchEquipmentInput = GUICtrlCreateInput("", 200, 18, 250, 30)
    GUICtrlSetFont(-1, 16)

    $SearchEquipmentButton = GUICtrlCreateButton("Search", 480, 5, 100, 50)
    GUICtrlSetOnEvent(-1, "_SearchEquipment")
    GUICtrlSetFont(-1, 16)

    $ListView = GUICtrlCreateListView("Unit Number|Model Number|Serial Number", 10, 60, 580, 500, $LVS_SORTASCENDING)
    _GUICtrlListView_SetColumnWidth(-1, 0, 100)
    _GUICtrlListView_SetColumnWidth(-1, 1, 250)
    _GUICtrlListView_SetColumnWidth(-1, 2, 250)

    For $i = 1 To UBound($ReadData) - 1
        GUICtrlCreateListViewItem($ReadData[$i][0] & "|" & $ReadData[$i][1], $ListView)
    Next

    $AddNewUnitButton = GUICtrlCreateButton("Add", 10, 565, 220, 40)
    GUICtrlSetOnEvent(-1, "_AddUnit")
    GUICtrlSetFont(-1, 16)

    $EditUnitButton = GUICtrlCreateButton("Edit", 370, 565, 220, 40)
    GUICtrlSetOnEvent(-1, "_EditUnit")
    GUICtrlSetFont(-1, 16)

    $RemoveUnitButton = GUICtrlCreateButton("Remove", 10, 615, 220, 40)
    GUICtrlSetOnEvent(-1, "_RemoveUnit")
    GUICtrlSetFont(-1, 16)

    $CloseButton = GUICtrlCreateButton("Close", 370, 615, 220, 40)
    GUICtrlSetOnEvent(-1, "_CloseGUI")
    GUICtrlSetFont(-1, 16)

    GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

    GUISetState()
EndFunc   ;==>_ManageEquipment

Func _AddUnit()
    GUISetState(@SW_DISABLE, $ManageUnitsGUI)
    $Stop = 0
    $NewUnitNumber = InputBox("Add Equipment", "Please input the unit number you wish to add.")
    If $NewUnitNumber = "" Then
        MsgBox(48, "Error", "No unit number input, cancelling addition of a new unit!")
        $Stop = 1
    EndIf

    If $Stop = 0 Then
        $NewUnitModelNumber = InputBox("Add Equipment", "Please input the model number of this unit.")
        If $NewUnitModelNumber = "" Then
            MsgBox(48, "Error", "No model number was inputted, cancelling addition of a new unit!")
            $Stop = 1
        EndIf
    EndIf

    If $Stop = 0 Then
        $NewUnitBatterySerial = InputBox("Add Unit", "Please input the serial number with this unit.")
        If $NewUnitBatterySerial = "" Then
            MsgBox(48, "Error", "No serial number was inputted, cancelling addition of a new unit!")
            $Stop = 1
        EndIf
    EndIf

    If $Stop = 0 Then
        $CheckMsgBox = MsgBox(4, "Add Unit", "Are you sure you wish to add the following unit?" & @CRLF & @CRLF & "Unit Number: " & $NewUnitNumber & @CRLF & "Model Number: " & $NewUnitModelNumber & @CRLF & "Serial Number: " & $NewUnitBatterySerial)
        If $CheckMsgBox = 6 Then
            IniWrite($DatabasePath & "/Equipment Database.ini", "Equipment", $NewUnitNumber, $NewUnitModelNumber & "|" & $NewUnitBatterySerial)
            MsgBox(0, "Add Unit", "Unit number: " & $NewUnitNumber & " has been added!")
            GUICtrlCreateListViewItem($NewUnitNumber & "|" & $NewUnitModelNumber & "|" & $NewUnitBatterySerial, $ListView)
        Else
            MsgBox(48, "Add Unit", "You have chosen to cancel the addition of a new unit!")
        EndIf
    EndIf
    GUISetState(@SW_ENABLE, $ManageUnitsGUI)
    Sleep(100)
    WinActivate($ManageUnitsGUI)
EndFunc   ;==>_AddUnit

Func _EditUnit()
    GUISetState(@SW_DISABLE, $ManageUnitsGUI)
    $ListViewGetSelection = _GUICtrlListView_GetSelectionMark($ListView)
    $GetUnitNumber = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 0)
    $GetUnitModelNumber = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 1)
    $GetUnitBatterySerial = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 2)
    $Stop = 0
    If $GetUnitNumber[3] = "" Then
        MsgBox(48, "Error", "No unit was selected, cancelling operation!")
    Else
        $EditUnitNumber = InputBox("Edit Unit", "Please input the unit number you wish to edit.", $GetUnitNumber[3])
        If $EditUnitNumber = "" Then
            MsgBox(48, "Error", "No unit number input, cancelling edit of the unit!")
            $Stop = 1
        EndIf

        If $Stop = 0 Then
            $EditUnitModelNumber = InputBox("Edit Unit", "Please input the model number with this unit.", $GetUnitModelNumber[3])
            If $EditUnitModelNumber = "" Then
                MsgBox(48, "Error", "No model number was inputted, cancelling edit of the unit!")
                $Stop = 1
            EndIf
        EndIf

        If $Stop = 0 Then
            $EditUnitBatterySerial = InputBox("Edit Unit", "Please input the serial number with this unit.", $GetUnitBatterySerial[3])
            If $EditUnitBatterySerial = "" Then
                MsgBox(48, "Error", "No serial number was inputted, cancelling edit of the unit!")
                $Stop = 1
            EndIf
        EndIf

        If $Stop = 0 Then
            $CheckMsgBox = MsgBox(4, "Edit Unit", "Are you sure you wish to edit the following Unit?" & @CRLF & @CRLF & "Unit Number: " & $EditUnitNumber & @CRLF & "Model Number: " & $EditUnitModelNumber & @CRLF & "Serial Number: " & $EditUnitBatterySerial)
            If $CheckMsgBox = 6 Then
                IniDelete($DatabasePath & "/Equipment Database.ini", "Equipment", $GetUnitNumber[3])
                IniWrite($DatabasePath & "/Equipment Database.ini", "Equipment", $EditUnitNumber, $EditUnitModelNumber & "|" & $EditUnitBatterySerial)
                MsgBox(0, "Edit Unit", "Unit number: " & $EditUnitNumber & " has been changed!")
                _GUICtrlListView_DeleteItem($ListView, $ListViewGetSelection)
                GUICtrlCreateListViewItem($EditUnitNumber & "|" & $EditUnitModelNumber & "|" & $EditUnitBatterySerial, $ListView)
            Else
                MsgBox(48, "Edit Part", "You have chosen to cancel the edit of the unit!")
            EndIf
        EndIf
    EndIf
    GUISetState(@SW_ENABLE, $ManageUnitsGUI)
    Sleep(100)
    WinActivate($ManageUnitsGUI)
EndFunc   ;==>_EditUnit

Func _RemoveUnit()
    GUISetState(@SW_DISABLE, $ManageUnitsGUI)
    $ListViewGetSelection = _GUICtrlListView_GetSelectionMark($ListView)
    $GetUnitNumber = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 0)
    If $GetUnitNumber[3] = "" Then
        MsgBox(48, "Error", "No unit was selected, cancelling operation!")
    Else
        $CheckMsgBox = MsgBox(4, "Remove Part", "Are you sure you wish to remove the following unit?" & @CRLF & @CRLF & $GetUnitNumber[3])
        If $CheckMsgBox = 6 Then
            _GUICtrlListView_DeleteItem($ListView, $ListViewGetSelection)
            IniDelete($DatabasePath & "/Equipment Database.ini", "Equipment", $GetUnitNumber[3])
            MsgBox(0, "Remove Unit", "The unit has been removed from the database!")
        Else
            MsgBox(48, "Remove Unit", "You have chosen to cancel the removal of the unit!")
        EndIf
    EndIf
    GUISetState(@SW_ENABLE, $ManageUnitsGUI)
    Sleep(100)
    WinActivate($ManageUnitsGUI)
EndFunc   ;==>_RemoveUnit

Func _SearchParts()
    Dim $FoundEntries[1]
    $ReadPartLookupInput = GUICtrlRead($SearchPartsInput)
    $Found = 0
    $SearchAll = 0
    $ReadPartsData = IniReadSection($DatabasePath & "/Parts Database.ini", "Parts")

    If $ReadPartLookupInput = "all" Then
        $SearchAll = 1
        _GUICtrlListView_DeleteAllItems($ListView)
        For $i = 1 To UBound($ReadPartsData) - 1
            GUICtrlCreateListViewItem($ReadPartsData[$i][0] & "|" & $ReadPartsData[$i][1], $ListView)
        Next
    Else


        For $i = 1 To UBound($ReadPartsData) - 1
            If StringInStr($ReadPartsData[$i][0], $ReadPartLookupInput) Then
                $PartInfo = $ReadPartsData[$i][0] & "|" & $ReadPartsData[$i][1]
                _ArrayInsert($FoundEntries, 0, $PartInfo, 0)
                $Found = 1
            EndIf
        Next

        If $Found = 0 Then
            MsgBox(0, "Searching...", "No parts found matching that part number, searching part descriptions!")
            For $i = 1 To UBound($ReadPartsData) - 1
                $SplitData = StringSplit($ReadPartsData[$i][1], "|")
                If StringInStr($SplitData[1], $ReadPartLookupInput) Then
                    $PartInfo = $ReadPartsData[$i][0] & "|" & $ReadPartsData[$i][1]
                    _ArrayInsert($FoundEntries, 0, $PartInfo, 0)
                    $Found = 1
                EndIf
            Next
        EndIf

        If $Found = 0 Then
            MsgBox(0, "Searching...", "No parts found matching that part description, searching product lines!")
            For $i = 1 To UBound($ReadPartsData) - 1
                $SplitData = StringSplit($ReadPartsData[$i][1], "|")
                If StringInStr($SplitData[2], $ReadPartLookupInput) Then
                    $PartInfo = $ReadPartsData[$i][0] & "|" & $ReadPartsData[$i][1]
                    _ArrayInsert($FoundEntries, 0, $PartInfo, 0)
                    $Found = 1
                EndIf
            Next
        EndIf

        If $Found = 0 Then
            MsgBox(0, "Searching...", "No parts found matching that product line, searching part bin numbers!")
            For $i = 1 To UBound($ReadPartsData) - 1
                $SplitData = StringSplit($ReadPartsData[$i][1], "|")
                If StringInStr($SplitData[3], $ReadPartLookupInput) Then
                    $PartInfo = $ReadPartsData[$i][0] & "|" & $ReadPartsData[$i][1]
                    _ArrayInsert($FoundEntries, 0, $PartInfo, 0)
                    $Found = 1
                EndIf
            Next
        EndIf

        If $Found = 0 Then
            MsgBox(48, "Error", "No parts found matching your input in the database!")
        Else
            _ArrayInsert($FoundEntries, 0, "RDaughertyPlaceHolder")
            _GUICtrlListView_DeleteAllItems($ListView)
            For $i = 1 To UBound($FoundEntries) - 1
                For $a = 1 To UBound($ReadPartsData) - 1
                    If StringInStr($FoundEntries[$i], $ReadPartsData[$a][0]) Then
                        GUICtrlCreateListViewItem($FoundEntries[$i] & "|" & $ReadPartsData[$a][1], $ListView)
                    EndIf
                Next
            Next
        EndIf
    EndIf
    GUICtrlSetData($SearchPartsInput, "")
EndFunc   ;==>_SearchParts

Func _SearchEquipment()
    Dim $FoundEntries[1]
    $ReadUnitNumberInput = GUICtrlRead($SearchEquipmentInput)
    $Found = 0
    $SearchAll = 0
    $ReadUnitsData = IniReadSection($DatabasePath & "/Equipment Database.ini", "Equipment")

    If $ReadUnitNumberInput = "all" Then
        $SearchAll = 1
        _GUICtrlListView_DeleteAllItems($ListView)
        For $i = 1 To UBound($ReadUnitsData) - 1
            GUICtrlCreateListViewItem($ReadUnitsData[$i][0] & "|" & $ReadUnitsData[$i][1], $ListView)
        Next
    Else

        For $i = 1 To UBound($ReadUnitsData) - 1
            If StringInStr($ReadUnitsData[$i][0], $ReadUnitNumberInput) Then
                $UnitsInfo = $ReadUnitsData[$i][0] & "|" & $ReadUnitsData[$i][1]
                _ArrayInsert($FoundEntries, 0, $UnitsInfo, 0)
                $Found = 1
            EndIf
        Next



        If $Found = 0 Then
            MsgBox(0, "Searching...", "No units found matching that number, searching model numbers!")
            For $i = 1 To UBound($ReadUnitsData) - 1
                $SplitData = StringSplit($ReadUnitsData[$i][1], "|")
                If StringInStr($SplitData[1], $ReadUnitNumberInput) Then
                    $UnitsInfo = $ReadUnitsData[$i][0] & "|" & $ReadUnitsData[$i][1]
                    _ArrayInsert($FoundEntries, 0, $UnitsInfo, 0)
                    $Found = 1
                EndIf
            Next
        EndIf

        If $Found = 0 Then
            MsgBox(0, "Searching...", "No units found matching that model number, searching serial numbers!")
            For $i = 1 To UBound($ReadUnitsData) - 1
                $SplitData = StringSplit($ReadUnitsData[$i][1], "|")
                If StringInStr($SplitData[2], $ReadUnitNumberInput) Then
                    $UnitsInfo = $ReadUnitsData[$i][0] & "|" & $ReadUnitsData[$i][1]
                    _ArrayInsert($FoundEntries, 0, $UnitsInfo, 0)
                    $Found = 1
                EndIf
            Next
        EndIf

        If $Found = 0 Then
            MsgBox(48, "Error", "No units, model numbers or serial numbers found matching that search criteria!")
        Else
            _ArrayInsert($FoundEntries, 0, "RDaughertyPlaceHolder")
            _GUICtrlListView_DeleteAllItems($ListView)
            For $i = 1 To UBound($FoundEntries) - 1
                For $a = 1 To UBound($ReadUnitsData) - 1
                    If StringInStr($FoundEntries[$i], $ReadUnitsData[$a][0]) Then
                        GUICtrlCreateListViewItem($FoundEntries[$i] & "|" & $ReadUnitsData[$a][1], $ListView)
                    EndIf
                Next
            Next
        EndIf
    EndIf
    GUICtrlSetData($SearchEquipmentInput, "")
EndFunc   ;==>_SearchEquipment

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam

    Local $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)
    Local $tNMHDR = DllStructCreate($tagNMLISTVIEW, $lParam)
    Local $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_COLUMNCLICK ; A column was clicked
                    _GUICtrlListView_SimpleSort($hWndListView, $g_bSortSense, DllStructGetData($tNMHDR, "SubItem")) ; Sort direction for next sort toggled by default
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_NOTIFY

 

SearchWorkOrdersModule

Global $Found, $ReadSerialNumberInput, $FoundCount = 0, $WorkOrdersGUI, $MainGUI, $DatabasePath, $SerialNumberInput, $SearchOrdersInput
Global $SearchAll = 0, $ListView, $ViewWorkOrdersGUI, $MainGUI
Global $g_bSortSense = True
Dim $FoundEntries[1][4]

Func _CreateWorkOrdersGui()
    Dim $FoundEntries[1]
    $Found = 0
    $FoundCount = 0
    $SearchAll = 0
    $DatabasePath = FileSelectFolder("Select Folder...", @MyDocumentsDir)
    If $DatabasePath = "" Then
        MsgBox(48, "Error", "No database selected, cancelling operation!")
    Else
        GUISetState(@SW_DISABLE, $MainGUI)
        $CurrentGUI = "View Work Orders"

        $ViewWorkOrdersGUI = GUICreate("Work Orders", 600, 660)
        GUISetOnEvent($GUI_EVENT_CLOSE, "_CloseGUI")
        GUISetBkColor(0xFFFFFF)

        GUICtrlCreateLabel("Search Orders", 12, 20, 150, 40)
        GUICtrlSetFont(-1, 16)

        $SearchOrdersInput = GUICtrlCreateInput("", 160, 18, 250, 30)
        GUICtrlSetFont(-1, 16)

        $SearchOrdersButton = GUICtrlCreateButton("Search", 470, 5, 100, 50)
        GUICtrlSetOnEvent(-1, "_SearchWorkOrders")
        GUICtrlSetFont(-1, 16)

        $ListView = GUICtrlCreateListView("Work Orders", 10, 60, 580, 500, $LVS_SORTASCENDING)
        _GUICtrlListView_SetColumnWidth(-1, 0, 575)

        $ReadWorkOrders = _FileListToArray($DatabasePath, Default, 1)

        For $i = 1 To UBound($ReadWorkOrders) - 1
            $SplitData = StringSplit($ReadWorkOrders[$i], ".")
            GUICtrlCreateListViewItem($SplitData[1], $ListView)
        Next

        $ViewWorkOrderButton = GUICtrlCreateButton("View", 60, 590, 220, 40)
        GUICtrlSetOnEvent(-1, "_ViewWorkOrder")
        GUICtrlSetFont(-1, 16)

        $CloseButton = GUICtrlCreateButton("Close", 320, 590, 220, 40)
        GUICtrlSetOnEvent(-1, "_CloseGUI")
        GUICtrlSetFont(-1, 16)

        GUISetState()
    EndIf
EndFunc   ;==>_CreateWorkOrdersGui

Func _SearchWorkOrders()
    $SearchAll = 0
    $Found = 0
    Dim $FoundEntries[1]
    $ReadWorkOrderInput = GUICtrlRead($SearchOrdersInput)
    $ReadWorkOrders = _FileListToArray($DatabasePath, Default, 1)

    If $ReadWorkOrderInput = "all" Then
        $SearchAll = 1
        _GUICtrlListView_DeleteAllItems($ListView)
        For $i = 1 To UBound($ReadWorkOrders) - 1
            $SplitData = StringSplit($ReadWorkOrders[$i], ".")
            GUICtrlCreateListViewItem($SplitData[1], $ListView)
        Next
    Else


        For $i = 1 To UBound($ReadWorkOrders) - 1
            $SplitData = StringSplit($ReadWorkOrders[$i], ".")
            If StringInStr($SplitData[1], $ReadWorkOrderInput) Then
                _ArrayInsert($FoundEntries, 0, $SplitData[1], 0)
                $Found = 1
                $FoundCount += 1
            EndIf
        Next

        If $Found = 0 Then
            MsgBox(48, "Error", "No work orders found with those search criterias!")
        Else
            _ArrayInsert($FoundEntries, 0, $FoundCount)
            _GUICtrlListView_DeleteAllItems($ListView)
            $ReadWorkOrders = _FileListToArray($DatabasePath, Default, 1)
            For $i = 1 To UBound($FoundEntries) - 1
                For $a = 1 To UBound($ReadWorkOrders) - 1
                    $SplitData = StringSplit($ReadWorkOrders[$a], ".")
                    If StringInStr($FoundEntries[$i], $SplitData[1]) Then
                        GUICtrlCreateListViewItem($SplitData[1], $ListView)
                    EndIf
                Next
            Next
        EndIf
    EndIf
    GUICtrlSetData($SearchOrdersInput, "")

EndFunc   ;==>_SearchWorkOrders

Func _ViewWorkOrder()
    $ListViewGetSelection = _GUICtrlListView_GetSelectionMark($ListView)
    $GetSelectionInfo = _GUICtrlListView_GetItem($ListView, $ListViewGetSelection, 0)
    $ReadWorkOrders = _FileListToArray($DatabasePath & "\" & $ReadSerialNumberInput, Default, 1)

    For $i = 1 To UBound($ReadWorkOrders) - 1
        If StringInStr($ReadWorkOrders[$i], $GetSelectionInfo[3]) Then
            ShellExecute($DatabasePath & "\" & $ReadSerialNumberInput & "\" & $ReadWorkOrders[$i])
        EndIf
    Next
EndFunc   ;==>_ViewWorkOrder

 

1 person likes this

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Share this post


Link to post
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