Jump to content

Databuzz


czardas
 Share

Recommended Posts

This is simply an application for storing your contacts. It has a simple search feature, and it is also possible to paste table contents into MS Excel or Access. The source is written in AutoIt version 3.2.6.0, so the current version of AutoIt probably won't recognize some of the old UDFs. The compiled version in the attachment should work fine.

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>

$parent = GUICreate(" Databuzz . . .",@DesktopWidth,@DesktopHeight-50, 0,0,-1)
GuiSetIcon(@ScriptDir & "\databuzz.ico", 0)
GUISetBkColor (0x7090A0)

;Themes
$buttonColor = 0x7090A0
$buttonText = 0xFFFFFF
$buttonFont = "MS Reference Sans Serif"
$green = 0x667733
$darkRed = 0x800000
$nLabelColor = 0x800000
$newGUIcolor = 0xC0CCCC
$addBtn = 0xF08080
$addBtnFont = 0xFFFFFFF
$flag = 0
$kontax = @ScriptDir & "/data/kontax.txt"

$listview = GuiCtrlCreateListView ("Name|Phone|Mobile|Email|House/Street|Town|Postcode|Details|Notes",1,24,@DesktopWidth-2,@DesktopHeight-74);,$LVS_SORTDESCENDING)
GUICtrlSetBkColor ($listview,$green)
GUICtrlSetFont($listview, 12, 500)
GUICtrlSetColor($listview,0xFFFFFF)
$listViewStyle = BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)
GUICtrlSetStyle($listview, $LVS_REPORT, $listViewStyle)
For $i = 0 To 7 Step 1
    _GUICtrlListViewSetColumnWidth ($listview, $i, @DesktopWidth/9)
Next
_GUICtrlListViewSetColumnWidth ($listview, 8, @DesktopWidth*8/9)

$button1 = GuiCtrlCreateButton ("List",1,1,@DesktopWidth/10,22, $BS_FLAT)
$button2 = GuiCtrlCreateButton ("Add",@DesktopWidth/10 +2,1,@DesktopWidth/10 ,22, $BS_FLAT)
$button3 = GuiCtrlCreateButton ("Modify",@DesktopWidth*2/10 +3,1,@DesktopWidth/10,22, $BS_FLAT)
$button4 = GuiCtrlCreateButton ("Copy",@DesktopWidth*3/10 +4,1,@DesktopWidth/10,22, $BS_FLAT)
$button5 = GuiCtrlCreateButton ("Sort",@DesktopWidth*4/10 +5,1,@DesktopWidth/10,22, $BS_FLAT)
$button6 = GuiCtrlCreateButton ("Search",@DesktopWidth*5/10 +6,1,@DesktopWidth/10,22, $BS_FLAT)
$button7 = GuiCtrlCreateButton ("Select None",@DesktopWidth*6/10 +7,1,@DesktopWidth/10,22, $BS_FLAT)
$button8 = GuiCtrlCreateButton ("Delete",@DesktopWidth*7/10 +8,1,@DesktopWidth/10,22, $BS_FLAT)

GUICtrlSetBkColor($button1,$buttonColor)
GUICtrlSetBkColor($button2,$buttonColor)
GUICtrlSetBkColor($button3,$buttonColor)
GUICtrlSetBkColor($button4,$buttonColor)
GUICtrlSetBkColor($button5,$buttonColor)
GUICtrlSetBkColor($button6,$buttonColor)
GUICtrlSetBkColor($button7,$buttonColor)
GUICtrlSetBkColor($button8,$buttonColor)

GUICtrlSetColor($button1,$buttonText)
GUICtrlSetColor($button2,$buttonText)
GUICtrlSetColor($button3,$buttonText)
GUICtrlSetColor($button4,$buttonText)
GUICtrlSetColor($button5,$buttonText)
GUICtrlSetColor($button6,$buttonText)
GUICtrlSetColor($button7,$buttonText)
GUICtrlSetColor($button8,$buttonText)

GUICtrlSetFont($button1, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button2, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button3, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button4, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button5, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button6, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button7, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button8, 9, 500, 2, $buttonFont)

GuiSetState()

While 1
  $msg = GuiGetMsg ()
   Select
    Case $msg = $GUI_EVENT_CLOSE
        Exit
    Case $msg = $button1
        _getContactsList()
    Case $msg = $button6
         _search()
    Case $msg = $button7
         _GUICtrlListViewSetItemSelState ( $listview, -1 , 0)
    Case $msg = $button2     
          _new()
    Case $msg = $button3
        $string = GUICtrlRead(GUICtrlRead($listview))
        $index = _GUICtrlListViewGetCurSel($listview)
        If StringLen($string) > 8 Then
            $flag = 1
            _new()
            $flag = 0
        Else
            MsgBox(32, "???", "Nothing selected!", 5) 
        EndIf
    Case $msg = $button4
        _copy()
    Case $msg = $button8
        $selected =  _GUICtrlListViewGetSelectedCount ($listview)
        If $selected > 0 Then
             $confirm = MsgBox(262420, "Confirm Delete", "Are you sure you want to delete the selected items?" & @CRLF & "This action can't be undone.")
             If $confirm = 6 Then
                 _delete()
             Else
                 GUICtrlSetState ( $listview, $GUI_FOCUS )
             EndIf
         Else
            MsgBox(32, "???", "Nothing selected!", 5) 
        EndIf
    Case $msg = $button5
        Dim $B_DESCENDING[_GUICtrlListViewGetSubItemsCount ($listview) ]
        _GUICtrlListViewSort ( $listview, $B_DESCENDING, 0 )
        _GUICtrlListViewSetItemSelState ( $listview, -1 , 0)
        
   EndSelect
WEnd

Func _new()
    If $flag = 0 Then
        $GUI_Name = "Add Contact"
        $action = "Add"
    ElseIf $flag = 1 Then
        $GUI_Name = "Modify"
        $action = "Modify"
    EndIf
    
    $newGUI = GUICreate ( $GUI_Name , 488 , 238 , 100 , 100 , -1 , -1 , $parent )
    GUISetBkColor($newGUIcolor, $newGUI)
    $nName = GUICtrlCreateInput("", 80, 7, 400, 20)
    GUICtrlSetColor($nName, $darkRed)
    GUICtrlSetFont($nName, 10, 500)
    $label_nName = GUICtrlCreateLabel("Name", 10, 10, 70, 20)
    GUICtrlSetColor($label_nName, $nLabelColor)
    GUICtrlSetFont($label_nName, 10,500)
    $nPhone = GUICtrlCreateInput("", 80, 29, 400, 20)
    GUICtrlSetColor($nPhone, $darkRed)
    GUICtrlSetFont($nPhone, 10, 500)
    $label_nPhone = GUICtrlCreateLabel("Phone", 10, 32, 70, 20)
    GUICtrlSetColor($label_nPhone, $nLabelColor)
    GUICtrlSetFont($label_nPhone, 10,500)
    $nMobile = GUICtrlCreateInput("", 80, 51, 400, 20)
    GUICtrlSetColor($nMobile, $darkRed)
    GUICtrlSetFont($nMobile, 10, 500)
    $label_nMobile = GUICtrlCreateLabel("Mobile", 10, 54, 70, 20)
    GUICtrlSetColor($label_nMobile, $nLabelColor)
    GUICtrlSetFont($label_nMobile, 10,500)
    $nEmail = GUICtrlCreateInput("", 80, 73, 400, 20)
    GUICtrlSetColor($nEmail, $darkRed)
    GUICtrlSetFont($nEmail, 10, 500)
    $label_nEmail = GUICtrlCreateLabel("Email", 10, 76, 70, 20)
    GUICtrlSetColor($label_nEmail, $nLabelColor)
    GUICtrlSetFont($label_nEmail, 10,500)
    $nHouse = GUICtrlCreateInput("", 80, 95, 400, 20)
    GUICtrlSetColor($nHouse, $darkRed)
    GUICtrlSetFont($nHouse, 10, 500)
    $label_nHouse = GUICtrlCreateLabel("House", 10, 98, 70, 20)
    GUICtrlSetColor($label_nHouse, $nLabelColor)
    GUICtrlSetFont($label_nHouse, 10,500)
    $nTown = GUICtrlCreateInput("", 80, 117, 400, 20)
    GUICtrlSetColor($nTown, $darkRed)
    GUICtrlSetFont($nTown, 10, 500)
    $label_nTown = GUICtrlCreateLabel("Town", 10, 120, 70, 20)
    GUICtrlSetColor($label_nTown, $nLabelColor)
    GUICtrlSetFont($label_nTown, 10,500)
    $nPostCode = GUICtrlCreateInput("", 80, 139, 400, 20)
    GUICtrlSetFont($nPostCode, 10, 500)
    GUICtrlSetColor($nPostCode, $darkRed)
    $label_nPostCode = GUICtrlCreateLabel("Postcode", 10, 142, 65, 20)
    GUICtrlSetColor($label_nPostCode, $nLabelColor)
    GUICtrlSetFont($label_nPostCode, 10,500)
    $nDetails = GUICtrlCreateInput("", 80, 161, 400, 20)
    GUICtrlSetColor($nDetails, $darkRed)
    GUICtrlSetFont($nDetails, 10, 500)
    $label_nDetails = GUICtrlCreateLabel("Details", 10, 164, 70, 20)
    GUICtrlSetColor($label_nDetails, $nLabelColor)
    GUICtrlSetFont($label_nDetails, 10,500)
    $nNotes = GUICtrlCreateInput("", 80, 183, 400, 20)
    GUICtrlSetColor($nNotes, $darkRed)
    GUICtrlSetFont($nNotes, 10, 500)
    $label_nNotes = GUICtrlCreateLabel("Notes", 10, 186, 70, 20)
    GUICtrlSetColor($label_nNotes, $nLabelColor)
    GUICtrlSetFont($label_nNotes, 10,500)
    $btn_clear = GuiCtrlCreateButton ("Clear",150,210,90,22, $BS_FLAT)
    $btn_add = GuiCtrlCreateButton ($action,259,210,90,22, $BS_FLAT)
    $btn_close = GuiCtrlCreateButton ("Close",368,210,90,22, $BS_FLAT)
    
    If $flag = 1 Then
        $data = StringSplit($string, "|")
        GUICtrlSetData($nName ,$data[1])
        GUICtrlSetData($nPhone ,$data[2])
        GUICtrlSetData($nMobile ,$data[3])
        GUICtrlSetData($nEmail ,$data[4])
        GUICtrlSetData($nHouse ,$data[5])
        GUICtrlSetData($nTown ,$data[6])
        GUICtrlSetData($nPostCode ,$data[7])
        GUICtrlSetData($nDetails ,$data[8])
        GUICtrlSetData($nNotes ,$data[9])
    EndIf
    
    GUISetState(@SW_SHOW)
    GUISwitch($parent)
    While 1 
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $btn_close Then
            GUISwitch($newGUI)
            GUIDelete()
            ExitLoop
        EndIf
        If $msg = $btn_clear Then
            GUICtrlSetData($nName ,"")
            GUICtrlSetData($nPhone ,"")
            GUICtrlSetData($nMobile ,"")
            GUICtrlSetData($nEmail ,"")
            GUICtrlSetData($nHouse ,"")
            GUICtrlSetData($nTown ,"")
            GUICtrlSetData($nPostCode ,"")
            GUICtrlSetData($nDetails ,"")
            GUICtrlSetData($nNotes ,"")
        EndIf
        If $msg = $btn_add Then
            $nItem = GUICtrlRead($nName) & "|"
            $nItem &= GUICtrlRead($nPhone) & "|"
            $nItem &= GUICtrlRead($nMobile) & "|"
            $nItem &= GUICtrlRead($nEmail) & "|"
            $nItem &= GUICtrlRead($nHouse) & "|"
            $nItem &= GUICtrlRead($nTown) & "|"
            $nItem &= GUICtrlRead($nPostCode) & "|"
            $nItem &= GUICtrlRead($nDetails) & "|"
            $nItem &= GUICtrlRead($nNotes)
            If StringLen($nItem) > 8 And $flag = 0 Then
                _GUICtrlListViewSetItemSelState ( $listview, -1 , 0)
                GuiCtrlCreateListViewItem($nItem ,$listview)
                FileWriteLine($kontax, $nItem)
            ElseIf StringLen($nItem) > 8 Then
                Dim $fileArray
                $modified = StringSplit($nItem, "|")
                _FileReadToArray($kontax, $fileArray)
                $n = _ArraySearch($fileArray, $string, 0, 0, 1, True)
                $fileArray[$n] = $nItem
                _FileWriteFromArray($kontax, $fileArray, 1)
                For $i = 0 To 8 Step 1
                        _GUICtrlListViewSetItemText ( $listview, $index, $i, $modified[$i+1] )
                Next
                $string = $nItem
            EndIf
        EndIf
    WEnd
    GUICtrlSetState ( $listview, $GUI_FOCUS )
EndFunc

Func _getContactsList()
    Dim $av_Array
    _FileReadToArray($kontax, $av_Array)
    _GUICtrlListViewDeleteAllItems($listview)
    For $i = 1 To UBound($av_Array) - 1 Step 1
        GuiCtrlCreateListViewItem($av_Array[$i] ,$listview)
    Next
EndFunc

Func _delete()
    Local $a_indices = _GUICtrlListViewGetSelectedIndices($listview,1), $tempFile
    _FileReadToArray($kontax, $tempFile)
    If(IsArray($a_indices))Then
        Local $i
        For $i = 1 To $a_indices[0]
            $kIndex = _ArraySearch($tempFile, _GUICtrlListViewGetItemText ($listview, $a_indices[$i]), 1, 0, 1, True)
            _ArrayDelete($tempFile, $kIndex)
        Next
        _FileWriteFromArray($kontax, $tempFile, 1)
        _GUICtrlListViewDeleteItemsSelected ($listview)
    EndIf
EndFunc

Func _search()
    $GUI_Name = "Search"
    $newGUI = GUICreate ( $GUI_Name , 360 , 105 , 100 , 100 , -1 , -1 , $parent )
    GUISetBkColor($newGUIcolor, $newGUI)
    $label_1 = GUICtrlCreateLabel("Find what?", 10, 7, 200, 20)
    GUICtrlSetColor($label_1, $nLabelColor)
    GUICtrlSetFont($label_1, 10,500)
    $sRecords = GUICtrlCreateInput("", 10, 32, 340, 20)
    GUICtrlSetColor($sRecords, $darkRed)
    GUICtrlSetFont($sRecords, 10, 500)
    $checkBox = GUICtrlCreateCheckbox(" Match case", 10, 65, 110)
    GUICtrlSetColor($checkBox, $darkRed)
    GUICtrlSetFont($checkBox, 10, 500)
    $btn_search = GuiCtrlCreateButton ("Search",130,65,100,24, $BS_FLAT)
    $btn_close = GuiCtrlCreateButton ("Close",250,65,100,24, $BS_FLAT)
    
    GUISetState(@SW_SHOW)
    GUISwitch($parent)
    
    While 1 
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $btn_close Then
            GUISwitch($newGUI)
            GUIDelete()
            GUICtrlSetState ( $listview, $GUI_FOCUS )
            ExitLoop
        EndIf
        If $msg = $btn_search Then
            $find = GUICtrlRead($sRecords)
            $tick = GUICtrlRead($checkBox)
            If $tick = 1 Then
                $case = 1
            Else
                $case = 0
            EndIf
            
            Dim $records, $sResult[1]
            _FileReadToArray($kontax, $records)
            For $i = 1 To UBound($records) -1 Step 1
                If StringInStr($records[$i], $find, $case) Then
                    _ArrayAdd($sResult, $records[$i])
                EndIf
            Next
            
            If UBound($sResult) > 1 Then
                _GUICtrlListViewDeleteAllItems($listview)
                For $i = 1 To UBound($sResult) - 1 Step 1
                    GuiCtrlCreateListViewItem($sResult[$i] ,$listview)
                Next
            Else
                MsgBox(262208, "Search Result", "Could not find" &@CRLF &$find)
            EndIf
            
        EndIf
    WEnd
EndFunc

Func _copy()
    Dim $selection = _GUICtrlListViewGetSelectedIndices ($listview , 1), $clipboard
    If UBound($selection) > 1 Then
        For $i = 1 To $selection[0] Step 1
            $return = _GUICtrlListViewGetItemText ( $listview , $selection[$i])
            $return = StringReplace($return, "|", @TAB)
            $clipboard &= $return &@CRLF
        Next
        ClipPut($clipboard)
    Else
        MsgBox(32, "???", "Nothing selected!", 5) 
    EndIf
    GUICtrlSetState ( $listview, $GUI_FOCUS )
EndFunc

I hope you like it.

databuzz.zip

Edited by czardas
Link to comment
Share on other sites

I took a moment to update your code. Here is the updates to 3.3.0.0 Posted Image

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <ButtonConstants.au3>

;Global Const $LVS_EX_GRIDLINES = 0x00000001
;Global Const $LVS_EX_FULLROWSELECT = 0x00000020
;Global Const $LVS_REPORT = 0x0001
;Global Const $BS_FLAT = 0x8000

$parent = GUICreate(" Databuzz . . .",@DesktopWidth,@DesktopHeight-50, 0,0,-1)
GuiSetIcon(@ScriptDir & "\databuzz.ico", 0)
GUISetBkColor (0x7090A0)

;Themes
$buttonColor = 0x7090A0
$buttonText = 0xFFFFFF
$buttonFont = "MS Reference Sans Serif"
$green = 0x667733
$darkRed = 0x800000
$nLabelColor = 0x800000
$newGUIcolor = 0xC0CCCC
$softRed = 0xF08080
$addBtn = 0xF08080
$addBtnFont = 0xFFFFFFF
$flag = 0
$kontax = @ScriptDir & "/data/kontax.txt"

$listview = GuiCtrlCreateListView ("Name|Phone|Mobile|Email|House/Street|Town|Postcode|Details|Notes",1,24,@DesktopWidth-2,@DesktopHeight-74);,$LVS_SORTDESCENDING)
GUICtrlSetBkColor ($listview,$green)
GUICtrlSetFont($listview, 12, 500)
GUICtrlSetColor($listview,0xFFFFFF)
$listViewStyle = BitOR($LVS_EX_GRIDLINES,$LVS_EX_FULLROWSELECT)
GUICtrlSetStyle($listview, $LVS_REPORT, $listViewStyle)
For $i = 0 To 7 Step 1
 _GUICtrlListView_SetColumnWidth ($listview, $i, @DesktopWidth/9)
Next
_GUICtrlListView_SetColumnWidth ($listview, 8, @DesktopWidth*8/9)

$button1 = GuiCtrlCreateButton ("List",1,1,@DesktopWidth/10,22, $BS_FLAT)
$button2 = GuiCtrlCreateButton ("Add",@DesktopWidth/10 +2,1,@DesktopWidth/10 ,22, $BS_FLAT)
$button3 = GuiCtrlCreateButton ("Modify",@DesktopWidth*2/10 +3,1,@DesktopWidth/10,22, $BS_FLAT)
$button4 = GuiCtrlCreateButton ("Copy",@DesktopWidth*3/10 +4,1,@DesktopWidth/10,22, $BS_FLAT)
$button5 = GuiCtrlCreateButton ("Sort",@DesktopWidth*4/10 +5,1,@DesktopWidth/10,22, $BS_FLAT)
$button6 = GuiCtrlCreateButton ("Search",@DesktopWidth*5/10 +6,1,@DesktopWidth/10,22, $BS_FLAT)
$button7 = GuiCtrlCreateButton ("Select None",@DesktopWidth*6/10 +7,1,@DesktopWidth/10,22, $BS_FLAT)
$button8 = GuiCtrlCreateButton ("Delete",@DesktopWidth*7/10 +8,1,@DesktopWidth/10,22, $BS_FLAT)

GUICtrlSetBkColor($button1,$buttonColor)
GUICtrlSetBkColor($button2,$buttonColor)
GUICtrlSetBkColor($button3,$buttonColor)
GUICtrlSetBkColor($button4,$buttonColor)
GUICtrlSetBkColor($button5,$buttonColor)
GUICtrlSetBkColor($button6,$buttonColor)
GUICtrlSetBkColor($button7,$buttonColor)
GUICtrlSetBkColor($button8,$buttonColor)

GUICtrlSetColor($button1,$buttonText)
GUICtrlSetColor($button2,$buttonText)
GUICtrlSetColor($button3,$buttonText)
GUICtrlSetColor($button4,$buttonText)
GUICtrlSetColor($button5,$buttonText)
GUICtrlSetColor($button6,$buttonText)
GUICtrlSetColor($button7,$buttonText)
GUICtrlSetColor($button8,$buttonText)

GUICtrlSetFont($button1, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button2, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button3, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button4, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button5, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button6, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button7, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button8, 9, 500, 2, $buttonFont)

GuiSetState()

While 1
  $msg = GuiGetMsg ()
   Select
 Case $msg = $GUI_EVENT_CLOSE
  Exit
 Case $msg = $button1
  _getContactsList()
 Case $msg = $button6
   _search()
 Case $msg = $button7
   _GUICtrlListView_SetItemSelected ( $listview, -1 , 0)
 Case $msg = $button2
    _new()
 Case $msg = $button3
  $string = GUICtrlRead(GUICtrlRead($listview))
  $index = _GUICtrlListView_GetNextItem($listview)
  If StringLen($string) > 8 Then
   $flag = 1
   _new()
   $flag = 0
  Else
   MsgBox(32, "???", "Nothing selected!", 5)
  EndIf
 Case $msg = $button4
  _copy()
 Case $msg = $button8
  $selected =  _GUICtrlListView_GetSelectedCount ($listview)
  If $selected > 0 Then
    $confirm = MsgBox(262420, "Confirm Delete", "Are you sure you want to delete the selected items?" & @CRLF & "This action can't be undone.")
    If $confirm = 6 Then
     _delete()
    Else
     GUICtrlSetState ( $listview, $GUI_FOCUS )
    EndIf
   Else
   MsgBox(32, "???", "Nothing selected!", 5)
  EndIf
 Case $msg = $button5
  Dim $B_DESCENDING[_GUICtrlListView_GetColumnCount ($listview) ]
  _GUICtrlListView_SimpleSort ( $listview, $B_DESCENDING, 0 )
  _GUICtrlListView_SetItemSelected ( $listview, -1 , 0)

   EndSelect
WEnd

Func _new()
 If $flag = 0 Then
  $GUI_Name = "Add Contact"
  $action = "Add"
 ElseIf $flag = 1 Then
  $GUI_Name = "Modify"
  $action = "Modify"
 EndIf

 $newGUI = GUICreate ( $GUI_Name , 488 , 238 , 100 , 100 , -1 , -1 , $parent )
 GUISetBkColor($newGUIcolor, $newGUI)
 $nName = GUICtrlCreateInput("", 80, 7, 400, 20)
 GUICtrlSetColor($nName, $darkRed)
 GUICtrlSetFont($nName, 10, 500)
 $label_nName = GUICtrlCreateLabel("Name", 10, 10, 70, 20)
 GUICtrlSetColor($label_nName, $nLabelColor)
 GUICtrlSetFont($label_nName, 10,500)
 $nPhone = GUICtrlCreateInput("", 80, 29, 400, 20)
 GUICtrlSetColor($nPhone, $darkRed)
 GUICtrlSetFont($nPhone, 10, 500)
 $label_nPhone = GUICtrlCreateLabel("Phone", 10, 32, 70, 20)
 GUICtrlSetColor($label_nPhone, $nLabelColor)
 GUICtrlSetFont($label_nPhone, 10,500)
 $nMobile = GUICtrlCreateInput("", 80, 51, 400, 20)
 GUICtrlSetColor($nMobile, $darkRed)
 GUICtrlSetFont($nMobile, 10, 500)
 $label_nMobile = GUICtrlCreateLabel("Mobile", 10, 54, 70, 20)
 GUICtrlSetColor($label_nMobile, $nLabelColor)
 GUICtrlSetFont($label_nMobile, 10,500)
 $nEmail = GUICtrlCreateInput("", 80, 73, 400, 20)
 GUICtrlSetColor($nEmail, $darkRed)
 GUICtrlSetFont($nEmail, 10, 500)
 $label_nEmail = GUICtrlCreateLabel("Email", 10, 76, 70, 20)
 GUICtrlSetColor($label_nEmail, $nLabelColor)
 GUICtrlSetFont($label_nEmail, 10,500)
 $nHouse = GUICtrlCreateInput("", 80, 95, 400, 20)
 GUICtrlSetColor($nHouse, $darkRed)
 GUICtrlSetFont($nHouse, 10, 500)
 $label_nHouse = GUICtrlCreateLabel("House", 10, 98, 70, 20)
 GUICtrlSetColor($label_nHouse, $nLabelColor)
 GUICtrlSetFont($label_nHouse, 10,500)
 $nTown = GUICtrlCreateInput("", 80, 117, 400, 20)
 GUICtrlSetColor($nTown, $darkRed)
 GUICtrlSetFont($nTown, 10, 500)
 $label_nTown = GUICtrlCreateLabel("Town", 10, 120, 70, 20)
 GUICtrlSetColor($label_nTown, $nLabelColor)
 GUICtrlSetFont($label_nTown, 10,500)
 $nPostCode = GUICtrlCreateInput("", 80, 139, 400, 20)
 GUICtrlSetFont($nPostCode, 10, 500)
 GUICtrlSetColor($nPostCode, $darkRed)
 $label_nPostCode = GUICtrlCreateLabel("Postcode", 10, 142, 65, 20)
 GUICtrlSetColor($label_nPostCode, $nLabelColor)
 GUICtrlSetFont($label_nPostCode, 10,500)
 $nDetails = GUICtrlCreateInput("", 80, 161, 400, 20)
 GUICtrlSetColor($nDetails, $darkRed)
 GUICtrlSetFont($nDetails, 10, 500)
 $label_nDetails = GUICtrlCreateLabel("Details", 10, 164, 70, 20)
 GUICtrlSetColor($label_nDetails, $nLabelColor)
 GUICtrlSetFont($label_nDetails, 10,500)
 $nNotes = GUICtrlCreateInput("", 80, 183, 400, 20)
 GUICtrlSetColor($nNotes, $darkRed)
 GUICtrlSetFont($nNotes, 10, 500)
 $label_nNotes = GUICtrlCreateLabel("Notes", 10, 186, 70, 20)
 GUICtrlSetColor($label_nNotes, $nLabelColor)
 GUICtrlSetFont($label_nNotes, 10,500)
 $btn_clear = GuiCtrlCreateButton ("Clear",150,210,90,22, $BS_FLAT)
 $btn_add = GuiCtrlCreateButton ($action,259,210,90,22, $BS_FLAT)
 $btn_close = GuiCtrlCreateButton ("Close",368,210,90,22, $BS_FLAT)

 If $flag = 1 Then
  $data = StringSplit($string, "|")
  GUICtrlSetData($nName ,$data[1])
  GUICtrlSetData($nPhone ,$data[2])
  GUICtrlSetData($nMobile ,$data[3])
  GUICtrlSetData($nEmail ,$data[4])
  GUICtrlSetData($nHouse ,$data[5])
  GUICtrlSetData($nTown ,$data[6])
  GUICtrlSetData($nPostCode ,$data[7])
  GUICtrlSetData($nDetails ,$data[8])
  GUICtrlSetData($nNotes ,$data[9])
 EndIf

 GUISetState(@SW_SHOW)
 GUISwitch($parent)
 While 1
  $msg = GUIGetMsg()
  If $msg = $GUI_EVENT_CLOSE Or $msg = $btn_close Then
   GUISwitch($newGUI)
   GUIDelete()
   ExitLoop
  EndIf
  If $msg = $btn_clear Then
   GUICtrlSetData($nName ,"")
   GUICtrlSetData($nPhone ,"")
   GUICtrlSetData($nMobile ,"")
   GUICtrlSetData($nEmail ,"")
   GUICtrlSetData($nHouse ,"")
   GUICtrlSetData($nTown ,"")
   GUICtrlSetData($nPostCode ,"")
   GUICtrlSetData($nDetails ,"")
   GUICtrlSetData($nNotes ,"")
  EndIf
  If $msg = $btn_add Then
   $nItem = GUICtrlRead($nName) & "|"
   $nItem &= GUICtrlRead($nPhone) & "|"
   $nItem &= GUICtrlRead($nMobile) & "|"
   $nItem &= GUICtrlRead($nEmail) & "|"
   $nItem &= GUICtrlRead($nHouse) & "|"
   $nItem &= GUICtrlRead($nTown) & "|"
   $nItem &= GUICtrlRead($nPostCode) & "|"
   $nItem &= GUICtrlRead($nDetails) & "|"
   $nItem &= GUICtrlRead($nNotes)
   If StringLen($nItem) > 8 And $flag = 0 Then
    _GUICtrlListView_SetItemSelected ( $listview, -1 , 0)
    GuiCtrlCreateListViewItem($nItem ,$listview)
    FileWriteLine($kontax, $nItem)
   ElseIf StringLen($nItem) > 8 Then
    Dim $fileArray
    $modified = StringSplit($nItem, "|")
    _FileReadToArray($kontax, $fileArray)
    $n = _ArraySearch($fileArray, $string, 0, 0, 1, True)
    $fileArray[$n] = $nItem
    _FileWriteFromArray($kontax, $fileArray, 1)
    For $i = 0 To 8 Step 1
      _GUICtrlListView_SetItemText ( $listview, $index, $i, $modified[$i+1] )
    Next
    $string = $nItem
   EndIf
  EndIf
 WEnd
 GUICtrlSetState ( $listview, $GUI_FOCUS )
EndFunc

Func _getContactsList()
 Dim $av_Array
 _FileReadToArray($kontax, $av_Array)
 _GUICtrlListView_DeleteAllItems($listview)
 For $i = 1 To UBound($av_Array) - 1 Step 1
  GuiCtrlCreateListViewItem($av_Array[$i] ,$listview)
 Next
EndFunc

Func _delete()
 Local $a_indices = _GUICtrlListView_GetSelectedIndices($listview,1), $tempFile
 _FileReadToArray($kontax, $tempFile)
 If(IsArray($a_indices))Then
  Local $i
  For $i = 1 To $a_indices[0]
   $kIndex = _ArraySearch($tempFile, _GUICtrlListView_GetItemTextString ($listview, $a_indices[$i]), 1, 0, 1, True)
   _ArrayDelete($tempFile, $kIndex)
  Next
  _FileWriteFromArray($kontax, $tempFile, 1)
  _GUICtrlListView_DeleteItemsSelected ($listview)
 EndIf
EndFunc

Func _search()
 $GUI_Name = "Search"
 $newGUI = GUICreate ( $GUI_Name , 360 , 105 , 100 , 100 , -1 , -1 , $parent )
 GUISetBkColor($newGUIcolor, $newGUI)
 $label_1 = GUICtrlCreateLabel("Find what?", 10, 7, 200, 20)
 GUICtrlSetColor($label_1, $nLabelColor)
 GUICtrlSetFont($label_1, 10,500)
 $sRecords = GUICtrlCreateInput("", 10, 32, 340, 20)
 GUICtrlSetColor($sRecords, $darkRed)
 GUICtrlSetFont($sRecords, 10, 500)
 $checkBox = GUICtrlCreateCheckbox(" Match case", 10, 65, 110)
 GUICtrlSetColor($checkBox, $darkRed)
 GUICtrlSetFont($checkBox, 10, 500)
 $btn_search = GuiCtrlCreateButton ("Search",130,65,100,24, $BS_FLAT)
 $btn_close = GuiCtrlCreateButton ("Close",250,65,100,24, $BS_FLAT)

 GUISetState(@SW_SHOW)
 GUISwitch($parent)

 While 1
  $msg = GUIGetMsg()
  If $msg = $GUI_EVENT_CLOSE Or $msg = $btn_close Then
   GUISwitch($newGUI)
   GUIDelete()
   GUICtrlSetState ( $listview, $GUI_FOCUS )
   ExitLoop
  EndIf
  If $msg = $btn_search Then
   $find = GUICtrlRead($sRecords)
   $tick = GUICtrlRead($checkBox)
   If $tick = 1 Then
    $case = 1
   Else
    $case = 0
   EndIf

   Dim $records, $sResult[1]
   _FileReadToArray($kontax, $records)
   For $i = 1 To UBound($records) -1 Step 1
    If StringInStr($records[$i], $find, $case) Then
     _ArrayAdd($sResult, $records[$i])
    EndIf
   Next

   If UBound($sResult) > 1 Then
    _GUICtrlListView_DeleteAllItems($listview)
    For $i = 1 To UBound($sResult) - 1 Step 1
     GuiCtrlCreateListViewItem($sResult[$i] ,$listview)
    Next
   Else
    MsgBox(262208, "Search Result", "Could not find" [email="&@CRLF"]&@CRLF[/email] &$find)
   EndIf

  EndIf
 WEnd
EndFunc

Func _copy()
 Dim $selection = _GUICtrlListView_GetSelectedIndices ($listview , 1), $clipboard
 If UBound($selection) > 1 Then
  For $i = 1 To $selection[0] Step 1
   $return = _GUICtrlListView_GetItemTextString ( $listview , $selection[$i])
   $return = StringReplace($return, "|", @TAB)
   $clipboard &= $return [email="&@CRLF"]&@CRLF[/email]
  Next
  ClipPut($clipboard)
 Else
  MsgBox(32, "???", "Nothing selected!", 5)
 EndIf
 GUICtrlSetState ( $listview, $GUI_FOCUS )
EndFunc
Link to comment
Share on other sites

I took a moment to update your code. Here is the updates to 3.3.0.0 Posted Image

Wow that's really kind of you. I'm going to have to do a fair amount of code updating myself. Thank you for talking time to do this. BTW, I forgot to remove an unecessary line from the source code. The following line can be deleted.

$softRed = 0xF08080
Edited by czardas
Link to comment
Share on other sites

  • 4 months later...

I have made one or two small modifications to my Databuzz script. Since I have finally updated to AutoIt Version: 3.3.0.0 ;)

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <ButtonConstants.au3>

If Not FileExists(@ScriptDir & "/data") Then
    DirCreate(@ScriptDir & "/data")
EndIf

$parent = GUICreate(" Databuzz . . .", @DesktopWidth, @DesktopHeight - 50, 0, 0, -1)
GUISetIcon(@ScriptDir & "\databuzz.ico", 0)
GUISetBkColor(0x7090A0)

;Themes
$buttonColor = 0x7090A0
$buttonText = 0xFFFFFF
$buttonFont = "MS Reference Sans Serif"
$green = 0x667733
$darkRed = 0x800000
$nLabelColor = 0x800000
$newGUIcolor = 0xC0CCCC
$addBtn = 0xF08080
$addBtnFont = 0xFFFFFFF
$flag = 0
$kontax = @ScriptDir & "/data/kontax.txt"

$listview = GUICtrlCreateListView("Name|Phone|Mobile|Email|House/Street|Town|Postcode|Details|Notes", 1, 24, @DesktopWidth - 2, @DesktopHeight - 74)
GUICtrlSetBkColor($listview, $green)
GUICtrlSetFont($listview, 12, 500)
GUICtrlSetColor($listview, 0xFFFFFF)
$listViewStyle = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)
GUICtrlSetStyle($listview, $LVS_REPORT, $listViewStyle)
For $i = 0 To 7 Step 1
    _GUICtrlListView_SetColumnWidth($listview, $i, @DesktopWidth / 9)
Next
_GUICtrlListView_SetColumnWidth($listview, 8, @DesktopWidth * 8 / 9)

$button1 = GUICtrlCreateButton("List", 1, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button2 = GUICtrlCreateButton("Add", @DesktopWidth / 10 + 2, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button3 = GUICtrlCreateButton("Modify", @DesktopWidth * 2 / 10 + 3, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button4 = GUICtrlCreateButton("Copy", @DesktopWidth * 3 / 10 + 4, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button5 = GUICtrlCreateButton("Sort", @DesktopWidth * 4 / 10 + 5, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button6 = GUICtrlCreateButton("Search", @DesktopWidth * 5 / 10 + 6, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button7 = GUICtrlCreateButton("Select None", @DesktopWidth * 6 / 10 + 7, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button8 = GUICtrlCreateButton("Delete", @DesktopWidth * 7 / 10 + 8, 1, @DesktopWidth / 10, 22, $BS_FLAT)

GUICtrlSetBkColor($button1, $buttonColor)
GUICtrlSetBkColor($button2, $buttonColor)
GUICtrlSetBkColor($button3, $buttonColor)
GUICtrlSetBkColor($button4, $buttonColor)
GUICtrlSetBkColor($button5, $buttonColor)
GUICtrlSetBkColor($button6, $buttonColor)
GUICtrlSetBkColor($button7, $buttonColor)
GUICtrlSetBkColor($button8, $buttonColor)

GUICtrlSetColor($button1, $buttonText)
GUICtrlSetColor($button2, $buttonText)
GUICtrlSetColor($button3, $buttonText)
GUICtrlSetColor($button4, $buttonText)
GUICtrlSetColor($button5, $buttonText)
GUICtrlSetColor($button6, $buttonText)
GUICtrlSetColor($button7, $buttonText)
GUICtrlSetColor($button8, $buttonText)

GUICtrlSetFont($button1, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button2, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button3, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button4, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button5, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button6, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button7, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button8, 9, 500, 2, $buttonFont)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button1
            _getContactsList()
        Case $msg = $button6
            _search()
        Case $msg = $button7
            _GUICtrlListView_SetItemSelected($listview, -1, 0)
        Case $msg = $button2
            _new()
        Case $msg = $button3
            $string = GUICtrlRead(GUICtrlRead($listview))
            $index = _GUICtrlListView_GetNextItem($listview)
            If StringLen($string) > 8 Then
                $flag = 1
                _new()
                $flag = 0
            Else
                MsgBox(32, "???", "Nothing selected!", 5)
            EndIf
        Case $msg = $button4
            _copy()
        Case $msg = $button8
            $selected = _GUICtrlListView_GetSelectedCount($listview)
            If $selected > 0 Then
                $confirm = MsgBox(262420, "Confirm Delete", "Are you sure you want to delete the selected items?" & @CRLF & "This action can't be undone.")
                If $confirm = 6 Then
                    _delete()
                Else
                    GUICtrlSetState($listview, $GUI_FOCUS)
                EndIf
            Else
                MsgBox(32, "???", "Nothing selected!", 5)
            EndIf
        Case $msg = $button5
            Dim $B_DESCENDING[_GUICtrlListView_GetColumnCount($listview)]
            _GUICtrlListView_SimpleSort($listview, $B_DESCENDING, 0)
            _GUICtrlListView_SetItemSelected($listview, -1, 0)

    EndSelect
WEnd

Func _new()
    If $flag = 0 Then
        $GUI_Name = "Add Contact"
        $action = "Add"
    ElseIf $flag = 1 Then
        $GUI_Name = "Modify"
        $action = "Modify"
    EndIf

    $newGUI = GUICreate($GUI_Name, 488, 238, 100, 100, -1, -1, $parent)
    GUISetBkColor($newGUIcolor, $newGUI)
    $nName = GUICtrlCreateInput("", 80, 7, 400, 20)
    GUICtrlSetColor($nName, $darkRed)
    GUICtrlSetFont($nName, 10, 500)
    $label_nName = GUICtrlCreateLabel("Name", 10, 10, 70, 20)
    GUICtrlSetColor($label_nName, $nLabelColor)
    GUICtrlSetFont($label_nName, 10, 500)
    $nPhone = GUICtrlCreateInput("", 80, 29, 400, 20)
    GUICtrlSetColor($nPhone, $darkRed)
    GUICtrlSetFont($nPhone, 10, 500)
    $label_nPhone = GUICtrlCreateLabel("Phone", 10, 32, 70, 20)
    GUICtrlSetColor($label_nPhone, $nLabelColor)
    GUICtrlSetFont($label_nPhone, 10, 500)
    $nMobile = GUICtrlCreateInput("", 80, 51, 400, 20)
    GUICtrlSetColor($nMobile, $darkRed)
    GUICtrlSetFont($nMobile, 10, 500)
    $label_nMobile = GUICtrlCreateLabel("Mobile", 10, 54, 70, 20)
    GUICtrlSetColor($label_nMobile, $nLabelColor)
    GUICtrlSetFont($label_nMobile, 10, 500)
    $nEmail = GUICtrlCreateInput("", 80, 73, 400, 20)
    GUICtrlSetColor($nEmail, $darkRed)
    GUICtrlSetFont($nEmail, 10, 500)
    $label_nEmail = GUICtrlCreateLabel("Email", 10, 76, 70, 20)
    GUICtrlSetColor($label_nEmail, $nLabelColor)
    GUICtrlSetFont($label_nEmail, 10, 500)
    $nHouse = GUICtrlCreateInput("", 80, 95, 400, 20)
    GUICtrlSetColor($nHouse, $darkRed)
    GUICtrlSetFont($nHouse, 10, 500)
    $label_nHouse = GUICtrlCreateLabel("House", 10, 98, 70, 20)
    GUICtrlSetColor($label_nHouse, $nLabelColor)
    GUICtrlSetFont($label_nHouse, 10, 500)
    $nTown = GUICtrlCreateInput("", 80, 117, 400, 20)
    GUICtrlSetColor($nTown, $darkRed)
    GUICtrlSetFont($nTown, 10, 500)
    $label_nTown = GUICtrlCreateLabel("Town", 10, 120, 70, 20)
    GUICtrlSetColor($label_nTown, $nLabelColor)
    GUICtrlSetFont($label_nTown, 10, 500)
    $nPostCode = GUICtrlCreateInput("", 80, 139, 400, 20)
    GUICtrlSetFont($nPostCode, 10, 500)
    GUICtrlSetColor($nPostCode, $darkRed)
    $label_nPostCode = GUICtrlCreateLabel("Postcode", 10, 142, 65, 20)
    GUICtrlSetColor($label_nPostCode, $nLabelColor)
    GUICtrlSetFont($label_nPostCode, 10, 500)
    $nDetails = GUICtrlCreateInput("", 80, 161, 400, 20)
    GUICtrlSetColor($nDetails, $darkRed)
    GUICtrlSetFont($nDetails, 10, 500)
    $label_nDetails = GUICtrlCreateLabel("Details", 10, 164, 70, 20)
    GUICtrlSetColor($label_nDetails, $nLabelColor)
    GUICtrlSetFont($label_nDetails, 10, 500)
    $nNotes = GUICtrlCreateInput("", 80, 183, 400, 20)
    GUICtrlSetColor($nNotes, $darkRed)
    GUICtrlSetFont($nNotes, 10, 500)
    $label_nNotes = GUICtrlCreateLabel("Notes", 10, 186, 70, 20)
    GUICtrlSetColor($label_nNotes, $nLabelColor)
    GUICtrlSetFont($label_nNotes, 10, 500)
    $btn_clear = GUICtrlCreateButton("Clear", 150, 210, 90, 22, $BS_FLAT)
    $btn_add = GUICtrlCreateButton($action, 259, 210, 90, 22, $BS_FLAT)
    $btn_close = GUICtrlCreateButton("Close", 368, 210, 90, 22, $BS_FLAT)

    If $flag = 1 Then
        $data = StringSplit($string, "|")
        GUICtrlSetData($nName, $data[1])
        GUICtrlSetData($nPhone, $data[2])
        GUICtrlSetData($nMobile, $data[3])
        GUICtrlSetData($nEmail, $data[4])
        GUICtrlSetData($nHouse, $data[5])
        GUICtrlSetData($nTown, $data[6])
        GUICtrlSetData($nPostCode, $data[7])
        GUICtrlSetData($nDetails, $data[8])
        GUICtrlSetData($nNotes, $data[9])
    EndIf

    GUISetState(@SW_SHOW)
    GUISwitch($parent)
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $btn_close Then
            GUISwitch($newGUI)
            GUIDelete()
            ExitLoop
        EndIf
        If $msg = $btn_clear Then
            GUICtrlSetData($nName, "")
            GUICtrlSetData($nPhone, "")
            GUICtrlSetData($nMobile, "")
            GUICtrlSetData($nEmail, "")
            GUICtrlSetData($nHouse, "")
            GUICtrlSetData($nTown, "")
            GUICtrlSetData($nPostCode, "")
            GUICtrlSetData($nDetails, "")
            GUICtrlSetData($nNotes, "")
        EndIf
        If $msg = $btn_add Then
            $nItem = GUICtrlRead($nName) & "|"
            $nItem &= GUICtrlRead($nPhone) & "|"
            $nItem &= GUICtrlRead($nMobile) & "|"
            $nItem &= GUICtrlRead($nEmail) & "|"
            $nItem &= GUICtrlRead($nHouse) & "|"
            $nItem &= GUICtrlRead($nTown) & "|"
            $nItem &= GUICtrlRead($nPostCode) & "|"
            $nItem &= GUICtrlRead($nDetails) & "|"
            $nItem &= GUICtrlRead($nNotes)
            If StringLen($nItem) > 8 And $flag = 0 Then
                _GUICtrlListView_SetItemSelected($listview, -1, 0)
                GUICtrlCreateListViewItem($nItem, $listview)
                FileWriteLine($kontax, $nItem)
            ElseIf StringLen($nItem) > 8 Then
                Dim $fileArray
                $modified = StringSplit($nItem, "|")
                _FileReadToArray($kontax, $fileArray)
                $n = _ArraySearch($fileArray, $string, 0, 0, 1, True)
                $fileArray[$n] = $nItem
                _FileWriteFromArray($kontax, $fileArray, 1)
                For $i = 0 To 8 Step 1
                    _GUICtrlListView_SetItemText($listview, $index, $i, $modified[$i + 1])
                Next
                $string = $nItem
            EndIf
        EndIf
    WEnd
    GUICtrlSetState($listview, $GUI_FOCUS)
EndFunc   ;==>_new

Func _getContactsList()
    Dim $av_Array
    _FileReadToArray($kontax, $av_Array)
    _GUICtrlListView_DeleteAllItems($listview)
    For $i = 1 To UBound($av_Array) - 1 Step 1
        GUICtrlCreateListViewItem($av_Array[$i], $listview)
    Next
EndFunc   ;==>_getContactsList

Func _delete()
    Local $a_indices = _GUICtrlListView_GetSelectedIndices($listview, 1), $tempFile
    _FileReadToArray($kontax, $tempFile)
    If (IsArray($a_indices)) Then
        Local $i
        For $i = 1 To $a_indices[0]
            $kIndex = _ArraySearch($tempFile, _GUICtrlListView_GetItemTextString($listview, $a_indices[$i]), 1, 0, 1, True)
            _ArrayDelete($tempFile, $kIndex)
        Next
        _FileWriteFromArray($kontax, $tempFile, 1)
        _GUICtrlListView_DeleteItemsSelected($listview)
    EndIf
EndFunc   ;==>_delete

Func _search()
    $GUI_Name = "Search"
    $newGUI = GUICreate($GUI_Name, 360, 105, 100, 100, -1, -1, $parent)
    GUISetBkColor($newGUIcolor, $newGUI)
    $label_1 = GUICtrlCreateLabel("Find what?", 10, 7, 200, 20)
    GUICtrlSetColor($label_1, $nLabelColor)
    GUICtrlSetFont($label_1, 10, 500)
    $sRecords = GUICtrlCreateInput("", 10, 32, 340, 20)
    GUICtrlSetColor($sRecords, $darkRed)
    GUICtrlSetFont($sRecords, 10, 500)
    $checkBox = GUICtrlCreateCheckbox(" Match case", 10, 65, 110)
    GUICtrlSetColor($checkBox, $darkRed)
    GUICtrlSetFont($checkBox, 10, 500)
    $btn_search = GUICtrlCreateButton("Search", 130, 65, 100, 24, $BS_FLAT)
    $btn_close = GUICtrlCreateButton("Close", 250, 65, 100, 24, $BS_FLAT)

    GUISetState(@SW_SHOW)
    GUISwitch($parent)

    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $btn_close Then
            GUISwitch($newGUI)
            GUIDelete()
            GUICtrlSetState($listview, $GUI_FOCUS)
            ExitLoop
        EndIf
        If $msg = $btn_search Then
            $find = GUICtrlRead($sRecords)
            $tick = GUICtrlRead($checkBox)
            If $tick = 1 Then
                $case = 1
            Else
                $case = 0
            EndIf

            Dim $records, $sResult[1]
            _FileReadToArray($kontax, $records)
            For $i = 1 To UBound($records) - 1 Step 1
                If StringInStr($records[$i], $find, $case) Then
                    _ArrayAdd($sResult, $records[$i])
                EndIf
            Next

            If UBound($sResult) > 1 Then
                _GUICtrlListView_DeleteAllItems($listview)
                For $i = 1 To UBound($sResult) - 1 Step 1
                    GUICtrlCreateListViewItem($sResult[$i], $listview)
                Next
            Else
                MsgBox(262208, "Search Result", "Could not find" & @CRLF & $find)
            EndIf

        EndIf
    WEnd
EndFunc   ;==>_search

Func _copy()
    Dim $selection = _GUICtrlListView_GetSelectedIndices($listview, 1), $clipboard
    If UBound($selection) > 1 Then
        For $i = 1 To $selection[0] Step 1
            $return = _GUICtrlListView_GetItemTextString($listview, $selection[$i])
            $return = StringReplace($return, "|", @TAB)
            $clipboard &= $return & @CRLF
        Next
        ClipPut($clipboard)
    Else
        MsgBox(32, "???", "Nothing selected!", 5)
    EndIf
    GUICtrlSetState($listview, $GUI_FOCUS)
EndFunc   ;==>_copy
Edited by czardas
Link to comment
Share on other sites

I have made one or two small modifications to my Databuzz script. Since I have finally updated to AutoIt Version: 3.3.0.0 ;)

#include <GUIConstants.au3>
#include <File.au3>
#include <Array.au3>
#include <GuiListView.au3>
#include <ButtonConstants.au3>

If Not FileExists(@ScriptDir & "/data") Then
    DirCreate(@ScriptDir & "/data")
EndIf

$parent = GUICreate(" Databuzz . . .", @DesktopWidth, @DesktopHeight - 50, 0, 0, -1)
GUISetIcon(@ScriptDir & "\databuzz.ico", 0)
GUISetBkColor(0x7090A0)

;Themes
$buttonColor = 0x7090A0
$buttonText = 0xFFFFFF
$buttonFont = "MS Reference Sans Serif"
$green = 0x667733
$darkRed = 0x800000
$nLabelColor = 0x800000
$newGUIcolor = 0xC0CCCC
$addBtn = 0xF08080
$addBtnFont = 0xFFFFFFF
$flag = 0
$kontax = @ScriptDir & "/data/kontax.txt"

$listview = GUICtrlCreateListView("Name|Phone|Mobile|Email|House/Street|Town|Postcode|Details|Notes", 1, 24, @DesktopWidth - 2, @DesktopHeight - 74)
GUICtrlSetBkColor($listview, $green)
GUICtrlSetFont($listview, 12, 500)
GUICtrlSetColor($listview, 0xFFFFFF)
$listViewStyle = BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)
GUICtrlSetStyle($listview, $LVS_REPORT, $listViewStyle)
For $i = 0 To 7 Step 1
    _GUICtrlListView_SetColumnWidth($listview, $i, @DesktopWidth / 9)
Next
_GUICtrlListView_SetColumnWidth($listview, 8, @DesktopWidth * 8 / 9)

$button1 = GUICtrlCreateButton("List", 1, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button2 = GUICtrlCreateButton("Add", @DesktopWidth / 10 + 2, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button3 = GUICtrlCreateButton("Modify", @DesktopWidth * 2 / 10 + 3, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button4 = GUICtrlCreateButton("Copy", @DesktopWidth * 3 / 10 + 4, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button5 = GUICtrlCreateButton("Sort", @DesktopWidth * 4 / 10 + 5, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button6 = GUICtrlCreateButton("Search", @DesktopWidth * 5 / 10 + 6, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button7 = GUICtrlCreateButton("Select None", @DesktopWidth * 6 / 10 + 7, 1, @DesktopWidth / 10, 22, $BS_FLAT)
$button8 = GUICtrlCreateButton("Delete", @DesktopWidth * 7 / 10 + 8, 1, @DesktopWidth / 10, 22, $BS_FLAT)

GUICtrlSetBkColor($button1, $buttonColor)
GUICtrlSetBkColor($button2, $buttonColor)
GUICtrlSetBkColor($button3, $buttonColor)
GUICtrlSetBkColor($button4, $buttonColor)
GUICtrlSetBkColor($button5, $buttonColor)
GUICtrlSetBkColor($button6, $buttonColor)
GUICtrlSetBkColor($button7, $buttonColor)
GUICtrlSetBkColor($button8, $buttonColor)

GUICtrlSetColor($button1, $buttonText)
GUICtrlSetColor($button2, $buttonText)
GUICtrlSetColor($button3, $buttonText)
GUICtrlSetColor($button4, $buttonText)
GUICtrlSetColor($button5, $buttonText)
GUICtrlSetColor($button6, $buttonText)
GUICtrlSetColor($button7, $buttonText)
GUICtrlSetColor($button8, $buttonText)

GUICtrlSetFont($button1, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button2, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button3, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button4, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button5, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button6, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button7, 9, 500, 2, $buttonFont)
GUICtrlSetFont($button8, 9, 500, 2, $buttonFont)

GUISetState()

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            Exit
        Case $msg = $button1
            _getContactsList()
        Case $msg = $button6
            _search()
        Case $msg = $button7
            _GUICtrlListView_SetItemSelected($listview, -1, 0)
        Case $msg = $button2
            _new()
        Case $msg = $button3
            $string = GUICtrlRead(GUICtrlRead($listview))
            $index = _GUICtrlListView_GetNextItem($listview)
            If StringLen($string) > 8 Then
                $flag = 1
                _new()
                $flag = 0
            Else
                MsgBox(32, "???", "Nothing selected!", 5)
            EndIf
        Case $msg = $button4
            _copy()
        Case $msg = $button8
            $selected = _GUICtrlListView_GetSelectedCount($listview)
            If $selected > 0 Then
                $confirm = MsgBox(262420, "Confirm Delete", "Are you sure you want to delete the selected items?" & @CRLF & "This action can't be undone.")
                If $confirm = 6 Then
                    _delete()
                Else
                    GUICtrlSetState($listview, $GUI_FOCUS)
                EndIf
            Else
                MsgBox(32, "???", "Nothing selected!", 5)
            EndIf
        Case $msg = $button5
            Dim $B_DESCENDING[_GUICtrlListView_GetColumnCount($listview)]
            _GUICtrlListView_SimpleSort($listview, $B_DESCENDING, 0)
            _GUICtrlListView_SetItemSelected($listview, -1, 0)

    EndSelect
WEnd

Func _new()
    If $flag = 0 Then
        $GUI_Name = "Add Contact"
        $action = "Add"
    ElseIf $flag = 1 Then
        $GUI_Name = "Modify"
        $action = "Modify"
    EndIf

    $newGUI = GUICreate($GUI_Name, 488, 238, 100, 100, -1, -1, $parent)
    GUISetBkColor($newGUIcolor, $newGUI)
    $nName = GUICtrlCreateInput("", 80, 7, 400, 20)
    GUICtrlSetColor($nName, $darkRed)
    GUICtrlSetFont($nName, 10, 500)
    $label_nName = GUICtrlCreateLabel("Name", 10, 10, 70, 20)
    GUICtrlSetColor($label_nName, $nLabelColor)
    GUICtrlSetFont($label_nName, 10, 500)
    $nPhone = GUICtrlCreateInput("", 80, 29, 400, 20)
    GUICtrlSetColor($nPhone, $darkRed)
    GUICtrlSetFont($nPhone, 10, 500)
    $label_nPhone = GUICtrlCreateLabel("Phone", 10, 32, 70, 20)
    GUICtrlSetColor($label_nPhone, $nLabelColor)
    GUICtrlSetFont($label_nPhone, 10, 500)
    $nMobile = GUICtrlCreateInput("", 80, 51, 400, 20)
    GUICtrlSetColor($nMobile, $darkRed)
    GUICtrlSetFont($nMobile, 10, 500)
    $label_nMobile = GUICtrlCreateLabel("Mobile", 10, 54, 70, 20)
    GUICtrlSetColor($label_nMobile, $nLabelColor)
    GUICtrlSetFont($label_nMobile, 10, 500)
    $nEmail = GUICtrlCreateInput("", 80, 73, 400, 20)
    GUICtrlSetColor($nEmail, $darkRed)
    GUICtrlSetFont($nEmail, 10, 500)
    $label_nEmail = GUICtrlCreateLabel("Email", 10, 76, 70, 20)
    GUICtrlSetColor($label_nEmail, $nLabelColor)
    GUICtrlSetFont($label_nEmail, 10, 500)
    $nHouse = GUICtrlCreateInput("", 80, 95, 400, 20)
    GUICtrlSetColor($nHouse, $darkRed)
    GUICtrlSetFont($nHouse, 10, 500)
    $label_nHouse = GUICtrlCreateLabel("House", 10, 98, 70, 20)
    GUICtrlSetColor($label_nHouse, $nLabelColor)
    GUICtrlSetFont($label_nHouse, 10, 500)
    $nTown = GUICtrlCreateInput("", 80, 117, 400, 20)
    GUICtrlSetColor($nTown, $darkRed)
    GUICtrlSetFont($nTown, 10, 500)
    $label_nTown = GUICtrlCreateLabel("Town", 10, 120, 70, 20)
    GUICtrlSetColor($label_nTown, $nLabelColor)
    GUICtrlSetFont($label_nTown, 10, 500)
    $nPostCode = GUICtrlCreateInput("", 80, 139, 400, 20)
    GUICtrlSetFont($nPostCode, 10, 500)
    GUICtrlSetColor($nPostCode, $darkRed)
    $label_nPostCode = GUICtrlCreateLabel("Postcode", 10, 142, 65, 20)
    GUICtrlSetColor($label_nPostCode, $nLabelColor)
    GUICtrlSetFont($label_nPostCode, 10, 500)
    $nDetails = GUICtrlCreateInput("", 80, 161, 400, 20)
    GUICtrlSetColor($nDetails, $darkRed)
    GUICtrlSetFont($nDetails, 10, 500)
    $label_nDetails = GUICtrlCreateLabel("Details", 10, 164, 70, 20)
    GUICtrlSetColor($label_nDetails, $nLabelColor)
    GUICtrlSetFont($label_nDetails, 10, 500)
    $nNotes = GUICtrlCreateInput("", 80, 183, 400, 20)
    GUICtrlSetColor($nNotes, $darkRed)
    GUICtrlSetFont($nNotes, 10, 500)
    $label_nNotes = GUICtrlCreateLabel("Notes", 10, 186, 70, 20)
    GUICtrlSetColor($label_nNotes, $nLabelColor)
    GUICtrlSetFont($label_nNotes, 10, 500)
    $btn_clear = GUICtrlCreateButton("Clear", 150, 210, 90, 22, $BS_FLAT)
    $btn_add = GUICtrlCreateButton($action, 259, 210, 90, 22, $BS_FLAT)
    $btn_close = GUICtrlCreateButton("Close", 368, 210, 90, 22, $BS_FLAT)

    If $flag = 1 Then
        $data = StringSplit($string, "|")
        GUICtrlSetData($nName, $data[1])
        GUICtrlSetData($nPhone, $data[2])
        GUICtrlSetData($nMobile, $data[3])
        GUICtrlSetData($nEmail, $data[4])
        GUICtrlSetData($nHouse, $data[5])
        GUICtrlSetData($nTown, $data[6])
        GUICtrlSetData($nPostCode, $data[7])
        GUICtrlSetData($nDetails, $data[8])
        GUICtrlSetData($nNotes, $data[9])
    EndIf

    GUISetState(@SW_SHOW)
    GUISwitch($parent)
    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $btn_close Then
            GUISwitch($newGUI)
            GUIDelete()
            ExitLoop
        EndIf
        If $msg = $btn_clear Then
            GUICtrlSetData($nName, "")
            GUICtrlSetData($nPhone, "")
            GUICtrlSetData($nMobile, "")
            GUICtrlSetData($nEmail, "")
            GUICtrlSetData($nHouse, "")
            GUICtrlSetData($nTown, "")
            GUICtrlSetData($nPostCode, "")
            GUICtrlSetData($nDetails, "")
            GUICtrlSetData($nNotes, "")
        EndIf
        If $msg = $btn_add Then
            $nItem = GUICtrlRead($nName) & "|"
            $nItem &= GUICtrlRead($nPhone) & "|"
            $nItem &= GUICtrlRead($nMobile) & "|"
            $nItem &= GUICtrlRead($nEmail) & "|"
            $nItem &= GUICtrlRead($nHouse) & "|"
            $nItem &= GUICtrlRead($nTown) & "|"
            $nItem &= GUICtrlRead($nPostCode) & "|"
            $nItem &= GUICtrlRead($nDetails) & "|"
            $nItem &= GUICtrlRead($nNotes)
            If StringLen($nItem) > 8 And $flag = 0 Then
                _GUICtrlListView_SetItemSelected($listview, -1, 0)
                GUICtrlCreateListViewItem($nItem, $listview)
                FileWriteLine($kontax, $nItem)
            ElseIf StringLen($nItem) > 8 Then
                Dim $fileArray
                $modified = StringSplit($nItem, "|")
                _FileReadToArray($kontax, $fileArray)
                $n = _ArraySearch($fileArray, $string, 0, 0, 1, True)
                $fileArray[$n] = $nItem
                _FileWriteFromArray($kontax, $fileArray, 1)
                For $i = 0 To 8 Step 1
                    _GUICtrlListView_SetItemText($listview, $index, $i, $modified[$i + 1])
                Next
                $string = $nItem
            EndIf
        EndIf
    WEnd
    GUICtrlSetState($listview, $GUI_FOCUS)
EndFunc   ;==>_new

Func _getContactsList()
    Dim $av_Array
    _FileReadToArray($kontax, $av_Array)
    _GUICtrlListView_DeleteAllItems($listview)
    For $i = 1 To UBound($av_Array) - 1 Step 1
        GUICtrlCreateListViewItem($av_Array[$i], $listview)
    Next
EndFunc   ;==>_getContactsList

Func _delete()
    Local $a_indices = _GUICtrlListView_GetSelectedIndices($listview, 1), $tempFile
    _FileReadToArray($kontax, $tempFile)
    If (IsArray($a_indices)) Then
        Local $i
        For $i = 1 To $a_indices[0]
            $kIndex = _ArraySearch($tempFile, _GUICtrlListView_GetItemTextString($listview, $a_indices[$i]), 1, 0, 1, True)
            _ArrayDelete($tempFile, $kIndex)
        Next
        _FileWriteFromArray($kontax, $tempFile, 1)
        _GUICtrlListView_DeleteItemsSelected($listview)
    EndIf
EndFunc   ;==>_delete

Func _search()
    $GUI_Name = "Search"
    $newGUI = GUICreate($GUI_Name, 360, 105, 100, 100, -1, -1, $parent)
    GUISetBkColor($newGUIcolor, $newGUI)
    $label_1 = GUICtrlCreateLabel("Find what?", 10, 7, 200, 20)
    GUICtrlSetColor($label_1, $nLabelColor)
    GUICtrlSetFont($label_1, 10, 500)
    $sRecords = GUICtrlCreateInput("", 10, 32, 340, 20)
    GUICtrlSetColor($sRecords, $darkRed)
    GUICtrlSetFont($sRecords, 10, 500)
    $checkBox = GUICtrlCreateCheckbox(" Match case", 10, 65, 110)
    GUICtrlSetColor($checkBox, $darkRed)
    GUICtrlSetFont($checkBox, 10, 500)
    $btn_search = GUICtrlCreateButton("Search", 130, 65, 100, 24, $BS_FLAT)
    $btn_close = GUICtrlCreateButton("Close", 250, 65, 100, 24, $BS_FLAT)

    GUISetState(@SW_SHOW)
    GUISwitch($parent)

    While 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE Or $msg = $btn_close Then
            GUISwitch($newGUI)
            GUIDelete()
            GUICtrlSetState($listview, $GUI_FOCUS)
            ExitLoop
        EndIf
        If $msg = $btn_search Then
            $find = GUICtrlRead($sRecords)
            $tick = GUICtrlRead($checkBox)
            If $tick = 1 Then
                $case = 1
            Else
                $case = 0
            EndIf

            Dim $records, $sResult[1]
            _FileReadToArray($kontax, $records)
            For $i = 1 To UBound($records) - 1 Step 1
                If StringInStr($records[$i], $find, $case) Then
                    _ArrayAdd($sResult, $records[$i])
                EndIf
            Next

            If UBound($sResult) > 1 Then
                _GUICtrlListView_DeleteAllItems($listview)
                For $i = 1 To UBound($sResult) - 1 Step 1
                    GUICtrlCreateListViewItem($sResult[$i], $listview)
                Next
            Else
                MsgBox(262208, "Search Result", "Could not find" & @CRLF & $find)
            EndIf

        EndIf
    WEnd
EndFunc   ;==>_search

Func _copy()
    Dim $selection = _GUICtrlListView_GetSelectedIndices($listview, 1), $clipboard
    If UBound($selection) > 1 Then
        For $i = 1 To $selection[0] Step 1
            $return = _GUICtrlListView_GetItemTextString($listview, $selection[$i])
            $return = StringReplace($return, "|", @TAB)
            $clipboard &= $return & @CRLF
        Next
        ClipPut($clipboard)
    Else
        MsgBox(32, "???", "Nothing selected!", 5)
    EndIf
    GUICtrlSetState($listview, $GUI_FOCUS)
EndFunc   ;==>_copy

nice! really useful!
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...