Loc Posted August 25, 2020 Share Posted August 25, 2020 (edited) (Đã giải quyết) Edited September 7, 2020 by Loc Link to comment Share on other sites More sharing options...
Zedna Posted August 25, 2020 Share Posted August 25, 2020 Post (sample of) content of your INI file ... Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 25, 2020 Share Posted August 25, 2020 (edited) expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $Gui_M = GUICreate("HISTORY", 573, 438, 342, 109) $ListView_HTR = GUICtrlCreateListView("Date|Money", 24, 8, 513, 353) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 250) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 250) $Input_money = GUICtrlCreateInput("", 72, 392, 201, 25, $ES_NUMBER) $Button_set = GUICtrlCreateButton("SET", 360, 384, 137, 33) GUISetState(@SW_SHOW) _Load_History() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button_set _Load_Date() EndSwitch WEnd Func _Load_Date() Local $Date_History = @ScriptDir & "\DateHistorySell.ini" Local $currentamount = IniRead($Date_History, "History", @MDAY&@MON&@YEAR, "") If GUICtrlRead($Input_money) <> "" Then IniWrite($Date_History, "History", @MDAY&@MON&@YEAR, GUICtrlRead($Input_money) + $currentamount) _Load_History() EndIf EndFunc Func _Load_History() _GUICtrlListView_DeleteAllItems($ListView_HTR) Local $Date_History = @ScriptDir & "\DateHistorySell.ini" $var = IniReadSection($Date_History, "History") If @error Then Return For $i = 1 To $var[0][0] GUICtrlCreateListViewItem($var[$i][0] & "|" & $var[$i][1], $ListView_HTR) Next EndFunc Edited August 25, 2020 by Zedna robertocm 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Loc Posted August 25, 2020 Author Share Posted August 25, 2020 thank you very much Link to comment Share on other sites More sharing options...
Loc Posted August 25, 2020 Author Share Posted August 25, 2020 (edited) (Solved) Edited September 7, 2020 by Loc Link to comment Share on other sites More sharing options...
Zedna Posted August 25, 2020 Share Posted August 25, 2020 (edited) fixed first evident bug/bad code: Func _ShowHistory() Local $Date_HistoryTXT = @ScriptDir & "\DateHistorySell.txt" ;~ $History_read = FileReadToArray($Date_HistoryTXT) $History_read = FileRead($Date_HistoryTXT) GUICtrlSetData($Edit_HTR, $History_read) ; & @CRLF, 1) EndFunc ;==>_ShowHistory Edited August 25, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Loc Posted August 26, 2020 Author Share Posted August 26, 2020 (edited) (Solved) Edited September 7, 2020 by Loc Link to comment Share on other sites More sharing options...
Zedna Posted August 26, 2020 Share Posted August 26, 2020 (edited) expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> $Gui_M = GUICreate("HISTORY", 573, 438, 342, 109) $ListView_HTR = GUICtrlCreateListView("Date|Money", 24, 8, 230, 353) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100) Local $Listview_HW = GUICtrlGetHandle($ListView_HTR) $Input_money = GUICtrlCreateInput("", 72, 392, 201, 25, $ES_NUMBER) $Button_set = GUICtrlCreateButton("SET", 300, 384, 100, 33) $Button_del = GUICtrlCreateButton("Delete", 420, 384, 100, 33) $Edit_HTR = GUICtrlCreateEdit("", 280, 8, 290, 353) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ;~ AdlibRegister('_ReduceMemory', 60000) _Load_History() ;~ Global $aValues[1][2] ;~ $aValues[0][0] = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button_set _Load_Date() Case $Button_del _Delete_Date_HTR() EndSwitch WEnd Func _Load_Date() $day = @MDAY & '.' & @MON & '.' & @YEAR Local $Date_History = @ScriptDir & "\DateHistorySell.ini" Local $Date_HistoryTXT = @ScriptDir & "\DateHistorySell_"&$day&".txt" Local $currentamount = IniRead($Date_History, "History", $day, "") $input_amount = GUICtrlRead($Input_money) If $input_amount <> "" Then GUICtrlSetData($Input_money, "") IniWrite($Date_History, "History", $day, $input_amount + $currentamount) FileWriteLine($Date_HistoryTXT, $input_amount + $currentamount) _Load_History() EndIf EndFunc ;==>_Load_Date Func _Load_History() _GUICtrlListView_DeleteAllItems($ListView_HTR) Local $Date_History = @ScriptDir & "\DateHistorySell.ini" $var = IniReadSection($Date_History, "History") If @error Then Return For $i = 1 To $var[0][0] GUICtrlCreateListViewItem($var[$i][0] & "|" & $var[$i][1], $ListView_HTR) Next EndFunc ;==>_Load_History Func _Delete_Date_HTR() ;~ Local $x ;~ For $x = $aValues[0][0] To 0 Step -1 ;~ If _GUICtrlListView_GetItemSelected($ListView_HTR, $x) Then ;~ _ArrayDelete($aValues, $x + 1) ;~ $aValues[0][0] = $aValues[0][0] - 1 ;~ _GUICtrlListView_DeleteItem($ListView_HTR, $x) ;~ EndIf ;~ Next EndFunc ;==>_Delete_Date_HTR Func WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam) Local $stNmhdr = DllStructCreate("dword;int;int", $lParam), $hWndFrom = DllStructGetData($stNmhdr, 1) Local $nNotifyCode = DllStructGetData($stNmhdr, 3) Local $hWndListView = $Listview_HW Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK $item = _GUICtrlListView_GetNextItem($ListView_HTR) ; current selected $day = _GUICtrlListView_GetItemText($ListView_HTR,$item,0) ; first column (zero based index) _ShowHistory($day) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Func _ShowHistory($day) Local $Date_HistoryTXT = @ScriptDir & "\DateHistorySell_"&$day&".txt" $History_read = FileRead($Date_HistoryTXT) GUICtrlSetData($Edit_HTR, $History_read) EndFunc ;==>_ShowHistory Edited August 26, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Loc Posted August 28, 2020 Author Share Posted August 28, 2020 (edited) (Solved) Edited September 7, 2020 by Loc Link to comment Share on other sites More sharing options...
Zedna Posted August 28, 2020 Share Posted August 28, 2020 Func _Delete_Date_HTR() $item = _GUICtrlListView_GetNextItem($ListView_HTR) ; current selected If $item = -1 Then Return $day = _GUICtrlListView_GetItemText($ListView_HTR,$item,0) ; first column (zero based index) If $day == '' Then Return Local $Date_History = @ScriptDir & "\DateHistorySell.ini" IniDelete($Date_History, "History", $day) Local $Date_HistoryTXT = @ScriptDir & "\DateHistorySell_"&$day&".txt" FileDelete($Date_HistoryTXT) _Load_History() EndFunc ;==>_Delete_Date_HTR Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 28, 2020 Share Posted August 28, 2020 (edited) Here is improved version with confirmation dialog before deleting and _GUICtrlListView_DeleteItem() instead of _Load_History() : Func _Delete_Date_HTR() $item = _GUICtrlListView_GetNextItem($ListView_HTR) ; current selected If $item = -1 Then Return $day = _GUICtrlListView_GetItemText($ListView_HTR,$item,0) ; first column (zero based index) If $day == '' Then Return $ans = MsgBox(3+32+256,"Confirm",'Are you sure to delete "' & $day & '"?') If $ans <> 6 Then Return Local $Date_History = @ScriptDir & "\DateHistorySell.ini" IniDelete($Date_History, "History", $day) Local $Date_HistoryTXT = @ScriptDir & "\DateHistorySell_"&$day&".txt" FileDelete($Date_HistoryTXT) _GUICtrlListView_DeleteItem($ListView_HTR, $item) EndFunc ;==>_Delete_Date_HTR Edited August 28, 2020 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Zedna Posted August 28, 2020 Share Posted August 28, 2020 Here is polished/optimized whole script less code, reusing code, ... expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> Global $ini = @ScriptDir & "\DateHistorySell.ini" $Gui_M = GUICreate("HISTORY", 573, 438, 342, 109) $ListView_HTR = GUICtrlCreateListView("Date|Money", 24, 8, 230, 353) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 100) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 100) $Listview_HW = GUICtrlGetHandle($ListView_HTR) $Input_money = GUICtrlCreateInput("", 72, 392, 201, 25, $ES_NUMBER) $Button_set = GUICtrlCreateButton("SET", 300, 384, 100, 33) $Button_del = GUICtrlCreateButton("Delete", 420, 384, 100, 33) $Edit_HTR = GUICtrlCreateEdit("", 280, 8, 290, 353) GUISetState(@SW_SHOW) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _Load_History() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button_set _Load_Date() Case $Button_del _Delete_Date_HTR() EndSwitch WEnd Func _Load_Date() $input_amount = GUICtrlRead($Input_money) If $input_amount == "" Then Return $day = @MDAY & '.' & @MON & '.' & @YEAR $currentamount = IniRead($ini, "History", $day, "") $currentamount += $input_amount GUICtrlSetData($Input_money, "") IniWrite($ini, "History", $day, $currentamount) FileWriteLine(_GetTxtName($day), $currentamount) _Load_History() EndFunc ;==>_Load_Date Func _Load_History() _GUICtrlListView_DeleteAllItems($ListView_HTR) $var = IniReadSection($ini, "History") If @error Then Return For $i = 1 To $var[0][0] GUICtrlCreateListViewItem($var[$i][0] & "|" & $var[$i][1], $ListView_HTR) Next EndFunc ;==>_Load_History Func _Delete_Date_HTR() $item = _GUICtrlListView_GetNextItem($ListView_HTR) ; current selected If $item = -1 Then Return $day = _GUICtrlListView_GetItemText($ListView_HTR,$item,0) ; first column (zero based index) If $day == '' Then Return $ans = MsgBox(3+32+256,"Confirm",'Are you sure to delete "' & $day & '"?') If $ans <> 6 Then Return IniDelete($ini, "History", $day) FileDelete(_GetTxtName($day)) _GUICtrlListView_DeleteItem($ListView_HTR, $item) EndFunc ;==>_Delete_Date_HTR Func WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam) Local $stNmhdr = DllStructCreate("dword;int;int", $lParam), $hWndFrom = DllStructGetData($stNmhdr, 1) Local $nNotifyCode = DllStructGetData($stNmhdr, 3) Local $hWndListView = $Listview_HW Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam) Local $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_DBLCLK $item = _GUICtrlListView_GetNextItem($ListView_HTR) ; current selected $day = _GUICtrlListView_GetItemText($ListView_HTR,$item,0) ; first column (zero based index) _ShowHistory($day) EndSwitch EndSwitch EndFunc ;==>WM_NOTIFY Func _ShowHistory($day) $History_read = FileRead(_GetTxtName($day)) GUICtrlSetData($Edit_HTR, $History_read) EndFunc ;==>_ShowHistory Func _GetTxtName($day) Return @ScriptDir & "\DateHistorySell_"&$day&".txt" EndFunc ;==>_GetTxtName Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Loc Posted August 28, 2020 Author Share Posted August 28, 2020 Thank you very much ❤️ problem solved Link to comment Share on other sites More sharing options...
zeenmakr Posted September 25, 2020 Share Posted September 25, 2020 is he allow to do this? removed the original title, questions and other comments he made? thought im supposed to learn something between the interactions Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted September 26, 2020 Moderators Share Posted September 26, 2020 @Loc Please don't delete your posts in the future. First, it serves no purpose and is a silly thing to do. More importantly, it leaves a thread with great big gaps in it like this one, and doesn't help anyone in the future that might have a similar question. In the future, just edit your first post and add (Solved) to the title. "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Loc Posted September 26, 2020 Author Share Posted September 26, 2020 Yes. from now on I will Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now