Jump to content

GUI Listview iniwrite and iniread


Cozubic
 Share

Recommended Posts

Hello Guys,

I have few things i can't get to work properly

1.  a new entry everytime the "Add Acc" button is clicked the Acc Checkbox on the left checked and the inputs filled, like:

[Acc 1]

Account Name = Test

Username = Test

Password = Test

[Acc 2]

Account Name = Test 2

Username = Test 2

Password = Test 2

2. After clinking on "Delete Acc" and  "Add Acc" afterwards the count should start with the deleted number like:  Acc 3 = deleted and Acc 3 will be added (now Acc 4 will be added and Acc 3 skipped)

3. with a click on "Acc Details i imagine a MsgBox with the Information from the Acc (so Account Name, Username and Password)

my english is not the best but i hope i could describe it good enough to understand ;)

here my code

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <WinAPI.au3>
#include <FontConstants.au3>
#Include <GUiConstants.au3>
#Include <String.au3>

Global $iCount_Right = 1, $vData, $aRet, $hImage
Global $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_SUBITEMIMAGES, $LVS_EDITLABELS)
Global $PictureFolder =  @ScriptDir & "\tmp"
Global $Account = GUICreate("Account's", 425, 277, -1, -1)

$hListView_Right = _GUICtrlListView_Create($Account, "Account's", 5, 5, 100, 270, BitOR($LVS_DEFAULT, $WS_BORDER, $LVS_EX_CHECKBOXES, $LVS_ICON, $LVS_EDITLABELS))
_GUICtrlListView_SetExtendedListViewStyle($hListView_Right, $exStyles)
_GUICtrlListView_SetColumnWidth($hListView_Right, 0, 179)
_GUICtrlListView_SetInsertMarkColor($hListView_Right, 0)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @ScriptDir & "\accpic.ico",0)
_GUICtrlListView_SetImageList($hListView_Right, $hImage, 1)
$iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $LVS_EX_SUBITEMIMAGES)

Global $add = GUICtrlCreateButton("Add Acc", 110, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $delete = GUICtrlCreateButton("Delete Acc", 215, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $edit = GUICtrlCreateButton("Edit Acc", 320, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $moveup = GUICtrlCreateButton("Move-Up Acc", 110, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $movedown = GUICtrlCreateButton("Move-Down Acc", 215, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $details = GUICtrlCreateButton("Acc Details", 320, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
$ok = GUICtrlCreateButton ("OK", 165, 200, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $close = GUICtrlCreateButton("Close", 270, 200, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")

GUISetState()
$aIniFile = @ScriptDir & "\Accounts.ini"
$ReadCount = IniRead($aIniFile, "Accounts", "Acc", "")

$IniFile = @ScriptDir & "\acclogin.ini"
$ReadAcc = IniRead($IniFile, "Acc 1", "Account Name", "")
$ReadEmail = IniRead($IniFile, "Acc 1", "E-Mail Adress", "")
$ReadPassword = IniRead($IniFile, "Acc 1", "Password", "")

$nameacc = GUICtrlCreateInput($ReadAcc,220,110,150,25)
$accname = GUICtrlCreateLabel('Account Name',140,118)
$email = GUICtrlCreateInput($ReadEmail, 220,140,150,25)
$emaillabel = GUICtrlCreateLabel('Email Adress',140,148)
$password = GUICtrlCreateInput($ReadPassword,220,170,150,25,$ES_PASSWORD)
$passwordlabel = GUICtrlCreateLabel('Password',140,178)

While 1
  Switch GUIGetMsg()
    Case $close
      Exit
        Case $add
            Global $vData[1] = ["Acc  " & $iCount_Right]
                    $iCount_Right += 1
                    _GUIListViewEx_Insert($vData)
            IniWrite($aIniFile, "Accounts ", "Acc", 1)

        Case $ok
            GLOBAL $collectname = GUICtrlRead($nameacc)
            WinSetState('Collect Account Name and Username and Password','',@SW_HIDE)
            GLOBAL $collectemail = GUICtrlRead($email)
            GLOBAL $collectpassword = GUICtrlRead($password)
            ExitLoop

        Case $delete
            _GUIListViewEx_Delete()

        Case $moveup
            _GUIListViewEx_Up()

        Case $movedown
            _GUIListViewEx_Down()

        Case $edit


        Case $details


    EndSwitch
WEnd

            IniWrite($IniFile, "Acc ", "Account Name", $collectname)
            IniWrite($IniFile, "Acc ", "Username", $collectemail)
            IniWrite($IniFile, "Acc ", "Password", $collectpassword)

Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

 

 

Link to comment
Share on other sites

I have a few questions:

1. Why don't you use the account name on the left side instead of listing them as Acc 1, Acc 2, etc?

2. Shouldn't this information be password protected and encrypted inside the ini file?

3. Why are you using two ini files? All the information can be put into one file.

I will take a look at your script.

Link to comment
Share on other sites

OK, I worked on this a bit and made some changes. It's not complete, but I don't want to go any further unless you like the changes.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <WinAPI.au3>
#include <FontConstants.au3>
#Include <GUiConstants.au3>
#Include <String.au3>

Global $iCount_Right = 1, $vData, $aRet, $hImage
Global $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_SUBITEMIMAGES, $LVS_EDITLABELS)
Global $PictureFolder =  @ScriptDir & "\tmp"
Global $Account = GUICreate("Account's", 425, 277, -1, -1)
Global $aIniFile = @ScriptDir & "\Accounts.ini"

$hListView_Right = _GUICtrlListView_Create($Account, "Account's", 5, 5, 100, 270, BitOR($LVS_DEFAULT, $WS_BORDER, $LVS_EX_CHECKBOXES, $LVS_ICON, $LVS_EDITLABELS))
_GUICtrlListView_SetExtendedListViewStyle($hListView_Right, $exStyles)
_GUICtrlListView_SetColumnWidth($hListView_Right, 0, 179)
_GUICtrlListView_SetInsertMarkColor($hListView_Right, 0)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @ScriptDir & "\accpic.ico",0)
_GUICtrlListView_SetImageList($hListView_Right, $hImage, 1)
$iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $LVS_EX_SUBITEMIMAGES)

Global $add = GUICtrlCreateButton("Add Acc", 110, 5, 100, 40)
GUICtrlSetState(-1, $gui_hide)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $delete = GUICtrlCreateButton("Delete Acc", 215, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $edit = GUICtrlCreateButton("Edit Acc", 320, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $moveup = GUICtrlCreateButton("Move-Up Acc", 110, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $movedown = GUICtrlCreateButton("Move-Down Acc", 215, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $details = GUICtrlCreateButton("Acc Details", 320, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
$ok = GUICtrlCreateButton ("Save", 165, 230, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $close = GUICtrlCreateButton("Close", 270, 230, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
$accname = GUICtrlCreateInput("",220,110,150,25)
$accnamelabel = GUICtrlCreateLabel('Account Name',140,118)
$username = GUICtrlCreateInput("",220,140,150,25)
$usernamelabel = GUICtrlCreateLabel('User Name',140,148)
$email = GUICtrlCreateInput("", 220,170,150,25)
$emaillabel = GUICtrlCreateLabel('Email Adress',140,178)
$password = GUICtrlCreateInput("",220,200,150,25,$ES_PASSWORD)
$passwordlabel = GUICtrlCreateLabel('Password',140,208)
GUISetState()

_LoadACC()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GetItemsOrder()
            Exit
        Case $ok
            $ReadAccountName = GUICtrlRead($accname)
            If $ReadAccountName = "" Then
                MsgBox(0, "Error", "An account name must be entered.")
            Else
                $ReadUserName = GUICtrlRead($username)
                $ReadEmail = GUICtrlRead($email)
                $ReadPassword = GUICtrlRead($password)
                IniWrite($aIniFile, $ReadAccountName, "Username", $ReadUserName)
                IniWrite($aIniFile, $ReadAccountName, "EmailAddress", $ReadEmail)
                IniWrite($aIniFile, $ReadAccountName, "Password", $ReadPassword)
                _GUIListViewEx_Insert($ReadAccountName)
                GUICtrlSetData($accname, "")
                GUICtrlSetData($username, "")
                GUICtrlSetData($email, "")
                GUICtrlSetData($password, "")
            EndIf
        Case $delete
            $sAccountName = _GUICtrlListView_GetItemTextString($hListView_Right)
            IniDelete($aIniFile, $sAccountName)
            _GUIListViewEx_Delete()
        Case $moveup
            _GUIListViewEx_Up()

        Case $movedown
            _GUIListViewEx_Down()

        Case $edit
            $sAccountName = _GUICtrlListView_GetItemTextString($hListView_Right)
            _EditRecord($sAccountName)

        Case $details

        Case $close
            GUICtrlSetData($accname, "")
            GUICtrlSetData($username, "")
            GUICtrlSetData($email, "")
            GUICtrlSetData($password, "")

    EndSwitch
WEnd

Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

Func _LoadACC()
    $aAccounts = IniReadSectionNames($aIniFile)
    Local $aAccountOrder[$aAccounts[0]][2]
    For $i = 1 To $aAccounts[0]
        $aAccountOrder[$i - 1][0] = IniRead($aIniFile, $aAccounts[$i], "Order", 1)
        $aAccountOrder[$i - 1][1] = $aAccounts[$i]
    Next
    _ArraySort($aAccountOrder)
    For $i = 1 To UBound($aAccountOrder)
        _GUIListViewEx_Insert($aAccountOrder[$i - 1][1])
    Next
EndFunc

Func _LoadRecord()
    $aAccounts = IniReadSectionNames($aIniFile)
    $ReadUserName = IniRead($aIniFile, $aAccounts[$i], "Username", "")
    $ReadEmail = IniRead($aIniFile, $aAccounts[$i], "EmailAddress", "")
    $ReadPassword = IniRead($aIniFile, $aAccounts[$i], "Password", "")
    GUICtrlSetData($username, $ReadUserName)
    GUICtrlSetData($email, $ReadEmail)
    GUICtrlSetData($password, $ReadPassword)
EndFunc

Func _EditRecord($sAccountName)
    $ReadUserName = IniRead($aIniFile, $sAccountName, "Username", "")
    $ReadEmail = IniRead($aIniFile, $sAccountName, "EmailAddress", "")
    $ReadPassword = IniRead($aIniFile, $sAccountName, "Password", "")
    GUICtrlSetData($accname, $sAccountName)
    GUICtrlSetData($username, $ReadUserName)
    GUICtrlSetData($email, $ReadEmail)
    GUICtrlSetData($password, $ReadPassword)
EndFunc

Func _GetItemsOrder() ; when you close the GUI, this gets the current order of the Accounts.
    $iItemCount = _GUICtrlListView_GetItemCount($hListView_Right)
    For $i = 1 To $iItemCount
        IniWrite($aIniFile, _GUICtrlListView_GetItemText($hListView_Right, $i - 1), "Order", $i)
    Next
EndFunc

And a sample INI file:

[Maverick Corp]
Username=John
EmailAddress=noway@aol.com
Password=Password
Order=1
[Omni Corp]
Username=Mary
EmailAddress=mary@omnicorp.com
Password=Testing
Order=3
[Pascal Enterprises]
Username=Louis
EmailAddress=louis@pascal.com
Password=PascalRulz
Order=2

 

Link to comment
Share on other sites

thats great ty abberration

i get a error message 

 warning: $i: possibly used before declaration.
    $ReadUserName = IniRead($aIniFile, $aAccounts[$i]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
error: $i: undeclared global variable.
    $ReadUserName = IniRead($aIniFile, $aAccounts[$i]
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^

but it also worked without the LoadRecord Func

appreciate your help

Link to comment
Share on other sites

Yes, try this code. You can search for just a partial word like Maverick or Omni (if you are using the ini I made) and it will highlight the account. I think this would be very useful if you have a very long list.

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <WinAPI.au3>
#include <FontConstants.au3>
#Include <GUiConstants.au3>
#Include <String.au3>

Global $iCount_Right = 1, $vData, $aRet, $hImage
Global $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_SUBITEMIMAGES, $LVS_EDITLABELS)
Global $PictureFolder =  @ScriptDir & "\tmp"
Global $Account = GUICreate("Account's", 425, 277, -1, -1)
Global $aIniFile = @ScriptDir & "\Accounts.ini"

$hListView_Right = _GUICtrlListView_Create($Account, "Account's", 5, 5, 100, 270, BitOR($LVS_DEFAULT, $WS_BORDER, $LVS_EX_CHECKBOXES, $LVS_ICON, $LVS_EDITLABELS))
_GUICtrlListView_SetExtendedListViewStyle($hListView_Right, $exStyles)
_GUICtrlListView_SetColumnWidth($hListView_Right, 0, 179)
_GUICtrlListView_SetInsertMarkColor($hListView_Right, 0)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @ScriptDir & "\accpic.ico",0)
_GUICtrlListView_SetImageList($hListView_Right, $hImage, 1)
$iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $LVS_EX_SUBITEMIMAGES)

Global $search = GUICtrlCreateButton("Search", 110, 5, 100, 40)
;~ GUICtrlSetState(-1, $gui_hide)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $delete = GUICtrlCreateButton("Delete Acc", 215, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $edit = GUICtrlCreateButton("Edit Acc", 320, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $moveup = GUICtrlCreateButton("Move-Up Acc", 110, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $movedown = GUICtrlCreateButton("Move-Down Acc", 215, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $details = GUICtrlCreateButton("Acc Details", 320, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
$ok = GUICtrlCreateButton ("Save", 165, 230, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $close = GUICtrlCreateButton("Close", 270, 230, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
$accname = GUICtrlCreateInput("",220,110,150,25)
$accnamelabel = GUICtrlCreateLabel('Account Name',140,118)
$username = GUICtrlCreateInput("",220,140,150,25)
$usernamelabel = GUICtrlCreateLabel('User Name',140,148)
$email = GUICtrlCreateInput("", 220,170,150,25)
$emaillabel = GUICtrlCreateLabel('Email Adress',140,178)
$password = GUICtrlCreateInput("",220,200,150,25,$ES_PASSWORD)
$passwordlabel = GUICtrlCreateLabel('Password',140,208)
GUISetState()

_LoadACC()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GetItemsOrder()
            Exit
        Case $ok
            $ReadAccountName = GUICtrlRead($accname)
            If $ReadAccountName = "" Then
                MsgBox(0, "Error", "An account name must be entered.")
            Else
                $ReadUserName = GUICtrlRead($username)
                $ReadEmail = GUICtrlRead($email)
                $ReadPassword = GUICtrlRead($password)
                IniWrite($aIniFile, $ReadAccountName, "Username", $ReadUserName)
                IniWrite($aIniFile, $ReadAccountName, "EmailAddress", $ReadEmail)
                IniWrite($aIniFile, $ReadAccountName, "Password", $ReadPassword)
                _GUIListViewEx_Insert($ReadAccountName)
                GUICtrlSetData($accname, "")
                GUICtrlSetData($username, "")
                GUICtrlSetData($email, "")
                GUICtrlSetData($password, "")
            EndIf
        Case $delete
            $sAccountName = _GUICtrlListView_GetItemTextString($hListView_Right)
            IniDelete($aIniFile, $sAccountName)
            _GUIListViewEx_Delete()
        Case $moveup
            _GUIListViewEx_Up()

        Case $movedown
            _GUIListViewEx_Down()

        Case $edit
            $sAccountName = _GUICtrlListView_GetItemTextString($hListView_Right)
            _EditRecord($sAccountName)

        Case $details

        Case $close
            GUICtrlSetData($accname, "")
            GUICtrlSetData($username, "")
            GUICtrlSetData($email, "")
            GUICtrlSetData($password, "")
        Case $search
            $sTerm = InputBox("Search", "Search:")
            $iSearchResult = _GUICtrlListView_FindText($hListView_Right, $sTerm, Default, True)
            If $iSearchResult > -1 Then
                _GUICtrlListView_SetItemSelected($hListView_Right, $iSearchResult)
            Else
                MsgBox(0, "Search result", "No results for your search term: " & $sTerm)
            EndIf
    EndSwitch
WEnd

Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

Func _LoadACC()
    $aAccounts = IniReadSectionNames($aIniFile)
    Local $aAccountOrder[$aAccounts[0]][2]
    For $i = 1 To $aAccounts[0]
        $aAccountOrder[$i - 1][0] = IniRead($aIniFile, $aAccounts[$i], "Order", 1)
        $aAccountOrder[$i - 1][1] = $aAccounts[$i]
    Next
    _ArraySort($aAccountOrder)
    For $i = 1 To UBound($aAccountOrder)
        _GUIListViewEx_Insert($aAccountOrder[$i - 1][1])
    Next
EndFunc

Func _LoadRecord()
    Local $i
    $aAccounts = IniReadSectionNames($aIniFile)
    $ReadUserName = IniRead($aIniFile, $aAccounts[$i], "Username", "")
    $ReadEmail = IniRead($aIniFile, $aAccounts[$i], "EmailAddress", "")
    $ReadPassword = IniRead($aIniFile, $aAccounts[$i], "Password", "")
    GUICtrlSetData($username, $ReadUserName)
    GUICtrlSetData($email, $ReadEmail)
    GUICtrlSetData($password, $ReadPassword)
EndFunc

Func _EditRecord($sAccountName)
    $ReadUserName = IniRead($aIniFile, $sAccountName, "Username", "")
    $ReadEmail = IniRead($aIniFile, $sAccountName, "EmailAddress", "")
    $ReadPassword = IniRead($aIniFile, $sAccountName, "Password", "")
    GUICtrlSetData($accname, $sAccountName)
    GUICtrlSetData($username, $ReadUserName)
    GUICtrlSetData($email, $ReadEmail)
    GUICtrlSetData($password, $ReadPassword)
EndFunc

Func _GetItemsOrder() ; when you close the GUI, this gets the current order of the Accounts.
    $iItemCount = _GUICtrlListView_GetItemCount($hListView_Right)
    For $i = 1 To $iItemCount
        IniWrite($aIniFile, _GUICtrlListView_GetItemText($hListView_Right, $i - 1), "Order", $i)
    Next
EndFunc

 

Link to comment
Share on other sites

hey thank you for your help, but there is something wrong with the getitemsorder function, because the order is random everytime i close and run the script

Edit: after the tenth added acc it is getting random

Edited by Cozubic
Link to comment
Share on other sites

Ok, I figured out what the issue was. It had precisely to do with there being more than 9 items. The array holding the account names had a column with $i from the loop (numbers 1 to 14, for example). Well, the script sorted them this way:

1
10
11
12
13
14
2
3
4... etc

So, I used StringFormat to force all numbers to be 5 digits. Now it will see them as 00001, 00002, 00003, etc. This will allow you up to 99,999 accounts before you have an issue again. If you want more than that, simply change StringFormat("%.5d"... to StringFormat("%.6d"... (or 7, 8 or 9).

#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include "GUIListViewEx.au3"
#include <WinAPI.au3>
#include <FontConstants.au3>
#Include <GUiConstants.au3>
#Include <String.au3>

Global $iCount_Right = 1, $vData, $aRet, $hImage
Global $exStyles = BitOR($LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_SUBITEMIMAGES, $LVS_EDITLABELS)
Global $PictureFolder =  @ScriptDir & "\tmp"
Global $Account = GUICreate("Account's", 425, 277, -1, -1)
Global $aIniFile = @ScriptDir & "\Accounts.ini"

$hListView_Right = _GUICtrlListView_Create($Account, "Account's", 5, 5, 100, 270, BitOR($LVS_DEFAULT, $WS_BORDER, $LVS_EX_CHECKBOXES, $LVS_ICON, $LVS_EDITLABELS))
_GUICtrlListView_SetExtendedListViewStyle($hListView_Right, $exStyles)
_GUICtrlListView_SetColumnWidth($hListView_Right, 0, 179)
_GUICtrlListView_SetInsertMarkColor($hListView_Right, 0)
$hImage = _GUIImageList_Create(16, 16, 5, 3)
_GUIImageList_AddIcon($hImage, @ScriptDir & "\accpic.ico",0)
_GUICtrlListView_SetImageList($hListView_Right, $hImage, 1)
$iLV_Right_Index = _GUIListViewEx_Init($hListView_Right, $LVS_EX_SUBITEMIMAGES)

Global $search = GUICtrlCreateButton("Search", 110, 5, 100, 40)
;~ GUICtrlSetState(-1, $gui_hide)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $delete = GUICtrlCreateButton("Delete Acc", 215, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $edit = GUICtrlCreateButton("Edit Acc", 320, 5, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $moveup = GUICtrlCreateButton("Move-Up Acc", 110, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $movedown = GUICtrlCreateButton("Move-Down Acc", 215, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $details = GUICtrlCreateButton("Acc Details", 320, 50, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
$ok = GUICtrlCreateButton ("Save", 165, 230, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
Global $close = GUICtrlCreateButton("Close", 270, 230, 100, 40)
GUICtrlSetFont(-1, 10, 800, 0, "Calibri")
$accname = GUICtrlCreateInput("",220,110,150,25)
$accnamelabel = GUICtrlCreateLabel('Account Name',140,118)
$username = GUICtrlCreateInput("",220,140,150,25)
$usernamelabel = GUICtrlCreateLabel('User Name',140,148)
$email = GUICtrlCreateInput("", 220,170,150,25)
$emaillabel = GUICtrlCreateLabel('Email Adress',140,178)
$password = GUICtrlCreateInput("",220,200,150,25,$ES_PASSWORD)
$passwordlabel = GUICtrlCreateLabel('Password',140,208)
GUISetState()

_LoadACC()

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _GetItemsOrder()
            Exit
        Case $ok
            $ReadAccountName = GUICtrlRead($accname)
            If $ReadAccountName = "" Then
                MsgBox(0, "Error", "An account name must be entered.")
            Else
                $ReadUserName = GUICtrlRead($username)
                $ReadEmail = GUICtrlRead($email)
                $ReadPassword = GUICtrlRead($password)
                IniWrite($aIniFile, $ReadAccountName, "Username", $ReadUserName)
                IniWrite($aIniFile, $ReadAccountName, "EmailAddress", $ReadEmail)
                IniWrite($aIniFile, $ReadAccountName, "Password", $ReadPassword)
                _GUIListViewEx_Insert($ReadAccountName)
                GUICtrlSetData($accname, "")
                GUICtrlSetData($username, "")
                GUICtrlSetData($email, "")
                GUICtrlSetData($password, "")
            EndIf
        Case $delete
            $sAccountName = _GUICtrlListView_GetItemTextString($hListView_Right)
            IniDelete($aIniFile, $sAccountName)
            _GUIListViewEx_Delete()
        Case $moveup
            _GUIListViewEx_Up()

        Case $movedown
            _GUIListViewEx_Down()

        Case $edit
            $sAccountName = _GUICtrlListView_GetItemTextString($hListView_Right)
            _EditRecord($sAccountName)

        Case $details

        Case $close
            GUICtrlSetData($accname, "")
            GUICtrlSetData($username, "")
            GUICtrlSetData($email, "")
            GUICtrlSetData($password, "")
        Case $search
            $sTerm = InputBox("Search", "Search:")
            $iSearchResult = _GUICtrlListView_FindText($hListView_Right, $sTerm, Default, True)
            If $iSearchResult > -1 Then
                _GUICtrlListView_SetItemSelected($hListView_Right, $iSearchResult)
            Else
                MsgBox(0, "Search result", "No results for your search term: " & $sTerm)
            EndIf
    EndSwitch
WEnd

Func IsChecked($control)
    Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

Func _LoadACC()
    $aAccounts = IniReadSectionNames($aIniFile)
    Local $aAccountOrder[$aAccounts[0]][2]
    For $i = 1 To $aAccounts[0]
        $aAccountOrder[$i - 1][0] = StringFormat("%.5d", IniRead($aIniFile, $aAccounts[$i], "Order", 1))
        $aAccountOrder[$i - 1][1] = $aAccounts[$i]
    Next
    _ArraySort($aAccountOrder)
    _ArrayDisplay($aAccountOrder)
    For $i = 1 To UBound($aAccountOrder)
        _GUIListViewEx_Insert($aAccountOrder[$i - 1][1])
    Next
EndFunc

Func _LoadRecord()
    Local $i
    $aAccounts = IniReadSectionNames($aIniFile)
    $ReadUserName = IniRead($aIniFile, $aAccounts[$i], "Username", "")
    $ReadEmail = IniRead($aIniFile, $aAccounts[$i], "EmailAddress", "")
    $ReadPassword = IniRead($aIniFile, $aAccounts[$i], "Password", "")
    GUICtrlSetData($username, $ReadUserName)
    GUICtrlSetData($email, $ReadEmail)
    GUICtrlSetData($password, $ReadPassword)
EndFunc

Func _EditRecord($sAccountName)
    $ReadUserName = IniRead($aIniFile, $sAccountName, "Username", "")
    $ReadEmail = IniRead($aIniFile, $sAccountName, "EmailAddress", "")
    $ReadPassword = IniRead($aIniFile, $sAccountName, "Password", "")
    GUICtrlSetData($accname, $sAccountName)
    GUICtrlSetData($username, $ReadUserName)
    GUICtrlSetData($email, $ReadEmail)
    GUICtrlSetData($password, $ReadPassword)
EndFunc

Func _GetItemsOrder() ; when you close the GUI, this gets the current order of the Accounts.
    $iItemCount = _GUICtrlListView_GetItemCount($hListView_Right)
    For $i = 1 To $iItemCount
        IniWrite($aIniFile, _GUICtrlListView_GetItemText($hListView_Right, $i - 1), "Order", $i)
    Next
EndFunc

 

Edited by abberration
Edited to fix some numbers.
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...