【已解决】ListView排序0开头的数据会被去除,如何保持原始数值不变
本帖最后由 koflion 于 2011-10-23 04:26 编辑使用_GUICtrlListView_SimpleSort函数对ListView排序时,0开头的数据会被去除,不想让它处理掉0,如何解决啊??
正常情况时:
点击列名排序后:
函数用法:Case $ListView
_GUICtrlListView_SimpleSort($ListView, $ListViewPX, GUICtrlGetState($ListView)) ;<==$ListView的排序尝试:想用StringFormat处理格式问题,但是不知道在那个位置处理,郁闷啊!!!
解决:采用happy兄修改函数的方法。。。简单实用。。呵呵!!
最后谢谢大家!!!好有爱啊。。
回复koflion
把_GUICtrlListView_SimpleSort()函数定义稍稍修改下,在GuiListView.au3文件里的 ...
happytc 发表于 2011-10-23 00:47 http://www.autoitx.com/images/common/back.gif 可以看看GUICtrlRegisterListViewSort() 用GUICtrlRegisterListViewSort
拿帮助文件的例子稍微修改做个例子#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
Opt('MustDeclareVars', 1)
Global $nCurCol = -1
Global $nSortDir = 1
Global $bSet = 0
Global $nCol = -1
Example1()
Func Example1()
Local $hGUI, $lv, $lvi1, $lvi2, $lvi3, $msg
$hGUI = GUICreate("Test", 300, 200)
$lv = GUICtrlCreateListView("Column1|Col2|Col3", 10, 10, 280, 180)
GUICtrlRegisterListViewSort(-1, "LVSort") ; Register the function "SortLV" for the sorting callback
$lvi1 = GUICtrlCreateListViewItem("ABC|666|012", $lv)
GUICtrlSetImage(-1, "shell32.dll", 7)
$lvi2 = GUICtrlCreateListViewItem("DEF|444|133", $lv)
GUICtrlSetImage(-1, "shell32.dll", 12)
$lvi3 = GUICtrlCreateListViewItem("CDE|444|0874", $lv)
GUICtrlSetImage(-1, "shell32.dll", 3)
GUISetState()
While 1
$msg = GUIGetMsg()
Switch $msg
Case $GUI_EVENT_CLOSE
ExitLoop
Case $lv
$bSet = 0
$nCurCol = $nCol
GUICtrlSendMsg($lv, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($lv), 0)
DllCall("user32.dll", "int", "InvalidateRect", "hwnd", GUICtrlGetHandle($lv), "int", 0, "int", 1)
EndSwitch
WEnd
GUIDelete()
EndFunc ;==>Example1
; Our sorting callback funtion
Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
Local $nSort, $val1, $val2, $nResult
; Switch the sorting direction
If $nColumn = $nCurCol Then
If Not $bSet Then
$nSortDir = $nSortDir * - 1
$bSet = 1
EndIf
Else
$nSortDir = 1
EndIf
$nCol = $nColumn
$val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
$val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
; If it is the 3rd colum (column starts with 0) then compare the dates
If $nColumn = 2 Then
$val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2)
$val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2)
EndIf
$nResult = 0 ; No change of item1 and item2 positions
If $val1 < $val2 Then
$nResult = -1 ; Put item2 before item1
ElseIf $val1 > $val2 Then
$nResult = 1 ; Put item2 behind item1
EndIf
$nResult = $nResult * $nSortDir
Return $nResult
EndFunc ;==>LVSort
; Retrieve the text of a listview item in a specified column
Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
Local $stLvfi = DllStructCreate("uint;ptr;int;int;int")
Local $nIndex, $stBuffer, $stLvi, $sItemText
DllStructSetData($stLvfi, 1, $LVFI_PARAM)
DllStructSetData($stLvfi, 3, $nItemID)
$stBuffer = DllStructCreate("char")
$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
$stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
DllStructSetData($stLvi, 1, $LVIF_TEXT)
DllStructSetData($stLvi, 2, $nIndex)
DllStructSetData($stLvi, 3, $nColumn)
DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
DllStructSetData($stLvi, 7, 260)
GUICtrlSendMsg($nCtrlID, $LVM_GETITEMA, 0, DllStructGetPtr($stLvi));
$sItemText = DllStructGetData($stBuffer, 1)
$stLvi = 0
$stLvfi = 0
$stBuffer = 0
Return $sItemText
EndFunc ;==>GetSubItemText
; Our sorting callback funtion
Func LVSort2($hWnd, $nItem1, $nItem2, $nColumn)
Local $nSort, $val1, $val2, $nResult
; Switch the sorting direction
If $nColumn = $nCurCol Then
If Not $bSet Then
$nSortDir = $nSortDir * - 1
$bSet = 1
EndIf
Else
$nSortDir = 1
EndIf
$nCol = $nColumn
$val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
$val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
; If it is the 3rd colum (column starts with 0) then compare the dates
If $nColumn = 2 Then
$val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2)
$val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2)
EndIf
$nResult = 0 ; No change of item1 and item2 positions
If $val1 < $val2 Then
$nResult = -1 ; Put item2 before item1
ElseIf $val1 > $val2 Then
$nResult = 1 ; Put item2 behind item1
EndIf
$nResult = $nResult * $nSortDir
Return $nResult
EndFunc ;==>LVSort2
; Retrieve the text of a listview item in a specified column
Func GetSubItemText2($nCtrlID, $nItemID, $nColumn)
Local $stLvfi = DllStructCreate("uint;ptr;int;int;int")
Local $stBuffer, $nIndex, $stLvi, $sItemText
DllStructSetData($stLvfi, 1, $LVFI_PARAM) ; Find the item by our saved index
DllStructSetData($stLvfi, 3, $nItemID)
$stBuffer = DllStructCreate("char")
$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
$stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
DllStructSetData($stLvi, 1, $LVIF_TEXT)
DllStructSetData($stLvi, 2, $nIndex)
DllStructSetData($stLvi, 3, $nColumn)
DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
DllStructSetData($stLvi, 7, 260)
GUICtrlSendMsg($nCtrlID, $LVM_GETITEMA, 0, DllStructGetPtr($stLvi));
$sItemText = DllStructGetData($stBuffer, 1)
$stLvi = 0
$stLvfi = 0
$stBuffer = 0
Return $sItemText
EndFunc ;==>GetSubItemText2
; Create and insert items directly into the listview
Func MyGUICtrlCreateListViewItem($sText, $nCtrlID, $nIndex)
Local $stLvItem = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int;")
Local $stText = DllStructCreate("char")
Local $arText = StringSplit($sText, "|")
If $nIndex = -1 Then $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_GETITEMCOUNT, 0, 0)
DllStructSetData($stText, 1, $arText) ; Save the item text in the struct
DllStructSetData($stLvItem, 1, BitOR($LVIF_TEXT, $LVIF_PARAM))
DllStructSetData($stLvItem, 2, $nIndex)
DllStructSetData($stLvItem, 6, DllStructGetPtr($stText))
; Set the lParam of the struct to the line index - unique within the listview
DllStructSetData($stLvItem, 9, $nIndex)
$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_INSERTITEMA, 0, DllStructGetPtr($stLvItem))
If $nIndex > -1 Then
; Insert now the rest of the column text
For $i = 2 To $arText
DllStructSetData($stText, 1, $arText[$i])
DllStructSetData($stLvItem, 3, $i - 1) ; Store the subitem index
GUICtrlSendMsg($nCtrlID, $LVM_SETITEMTEXTA, $nIndex, DllStructGetPtr($stLvItem))
Next
EndIf
$stText = 0
$stLvItem = 0
; Change the column width to fit the item text
For $i = 0 To 2
GUICtrlSendMsg($nCtrlID, $LVM_SETCOLUMNWIDTH, $i, -1)
GUICtrlSendMsg($nCtrlID, $LVM_SETCOLUMNWIDTH, $i, -2)
Next
EndFunc ;==>MyGUICtrlCreateListViewItem 可以看看GUICtrlRegisterListViewSort()
afan 发表于 2011-10-22 23:52 http://www.autoitx.com/images/common/back.gif
谢谢斑竹。。。之前也有想到,看了半天没理解,所以来这里问问看,有米更好更简单的方案 = =! 回复 3# lynfr8
灰常感谢,看了原版的帮助,就是没理解。。。。这个是符合我的要求。。就是。。。要一句一句去理解。。才能搬过去。。。 这样也行#include <GuiListView.au3>
GUICreate("ListView 简单排序", 400, 300)
$hListView = GUICtrlCreateListView("列1|列2|列3", 2, 2, 394, 268)
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES)
GUICtrlSendMsg($hListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT)
GUICtrlCreateListViewItem("031696||", $hListView)
GUICtrlCreateListViewItem("052722||", $hListView)
GUICtrlCreateListViewItem("056188||", $hListView)
GUICtrlCreateListViewItem("060540||", $hListView)
GUICtrlCreateListViewItem("074733||", $hListView)
GUICtrlCreateListViewItem("079041||", $hListView)
GUICtrlCreateListViewItem("060055||", $hListView)
GUICtrlCreateListViewItem("060253||", $hListView)
GUICtrlCreateListViewItem("060423||", $hListView)
_GUICtrlListView_SetColumnWidth($hListView, 0, 75)
GUISetState()
GUIRegisterMsg(0x004E, "WM_NOTIFY")
_GUICtrlListView_RegisterSortCallBack($hListView)
Do
Until GUIGetMsg() = -3
_GUICtrlListView_UnRegisterSortCallBack($hListView)
GUIDelete()
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
#forceref $hWnd, $iMsg, $iwParam
Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
$hWndListView = $hListView
If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
$tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
$hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
$iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
$iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
Case $LVN_COLUMNCLICK
$tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
If DllStructGetData($tInfo, "SubItem") = 0 Then _GUICtrlListView_SortItems($hListView, 0)
EndSwitch
EndSwitch
EndFunc ;==>WM_NOTIFY
本帖最后由 happytc 于 2011-10-23 01:00 编辑
回复 1# koflion
把_GUICtrlListView_SimpleSort()函数定义稍稍修改下,在GuiListView.au3文件里的6876行开始,把那个for循环改成下面的:
For $Y = 0 To UBound($a_lv, 2) - 2 Step 1
$v_item = StringStripWS(_GUICtrlListView_GetItemText($hWnd, $x, $Y), 2)
;If (StringIsFloat($v_item) Or StringIsInt($v_item)) Then
; $a_lv[$x][$Y] = Number($v_item)
;Else
$a_lv[$x][$Y] = $v_item
;EndIf
Next
看你的‘住院号’位数都是相同的,别的列也没有需要进行数字比较的地方,就没有必要进行数字比较了,直接字符比较就可以了
若你觉得改Include里的文件不大好,可以把拷出来放在你的脚本里,改个函数名为_GUICtrlListView_SimpleSortA()
Func _GUICtrlListView_SimpleSortA($hWnd, ByRef $vDescending, $iCol)
If $Debug_LV Then __UDF_ValidateClassName($hWnd, $__LISTVIEWCONSTANT_ClassName)
If _GUICtrlListView_GetItemCount($hWnd) Then
Local $b_desc
If (IsArray($vDescending)) Then
$b_desc = $vDescending[$iCol]
Else
$b_desc = $vDescending
EndIf
Local $columns = _GUICtrlListView_GetColumnCount($hWnd)
Local $items = _GUICtrlListView_GetItemCount($hWnd)
Local $temp_item = ""
Local $SeparatorChar = Opt('GUIDataSeparatorChar')
For $x = 1 To $columns
$temp_item = $temp_item & " " & $SeparatorChar
Next
$temp_item = StringTrimRight($temp_item, 1)
Local $a_lv[$items][$columns + 1]
Local $i_selected = StringSplit(_GUICtrlListView_GetSelectedIndices($hWnd), $SeparatorChar)
Local $i_checked = StringSplit(__GUICtrlListView_GetCheckedIndices($hWnd), $SeparatorChar)
Local $v_item, $iFocused = -1
For $x = 0 To UBound($a_lv) - 1 Step 1
If $iFocused = -1 Then
If _GUICtrlListView_GetItemFocused($hWnd, $x) Then $iFocused = $x
EndIf
_GUICtrlListView_SetItemSelected($hWnd, $x, False)
_GUICtrlListView_SetItemChecked($hWnd, $x, False)
For $Y = 0 To UBound($a_lv, 2) - 2 Step 1
$v_item = StringStripWS(_GUICtrlListView_GetItemText($hWnd, $x, $Y), 2)
$a_lv[$x][$Y] = $v_item
Next
$a_lv[$x][$Y] = $x
Next
_ArraySort($a_lv, $b_desc, 0, 0, $iCol)
For $x = 0 To UBound($a_lv) - 1 Step 1
For $Y = 0 To UBound($a_lv, 2) - 2 Step 1
_GUICtrlListView_SetItemText($hWnd, $x, $a_lv[$x][$Y], $Y)
Next
For $Z = 1 To $i_selected
If $a_lv[$x] = $i_selected[$Z] Then
If $a_lv[$x] = $iFocused Then
_GUICtrlListView_SetItemSelected($hWnd, $x, True, True)
Else
_GUICtrlListView_SetItemSelected($hWnd, $x, True)
EndIf
ExitLoop
EndIf
Next
For $Z = 1 To $i_checked
If $a_lv[$x] = $i_checked[$Z] Then
_GUICtrlListView_SetItemChecked($hWnd, $x, True)
ExitLoop
EndIf
Next
Next
If (IsArray($vDescending)) Then
$vDescending[$iCol] = Not $b_desc
Else
$vDescending = Not $b_desc
EndIf
EndIf
EndFunc
测试了半天。。发现2个问题:
1、GUICtrlCreateListViewItem函数在指定ListView控件ID时,变量用数组的话会失败,换成普通变量就OK了。。
2、使用数组添加至ListView时:_GUICtrlListView_AddArray时,GUICtrlRegisterListViewSort(-1, "LVSort")函数返回
2 lParam1 第一个项目的 lParam 值(默认为项目控件ID).
3 lParam2 第二个项目的 lParam 值(默认为项目控件ID).
这2个值都是0,导致排序函数无法正常工作,难道要循环用GUICtrlCreateListViewItem写入么?数据多了会不会很慢啊。。。郁闷了。。。不知道各位还有什么办法没??
测试效果图:
代码如下:#include <Array.au3>
#include <GuiStatusBar.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>
#include <GuiListView.au3>
#include <GuiIPAddress.au3>
#include <ListViewConstants.au3>
#include <StaticConstants.au3>
#include <Timers.au3>
Opt("GUIOnEventMode", 1)
Opt("GUICoordMode", 1)
;SplashImageOn("", @TempDir & "\HISTools\Login.jpg", 500, 180, -1, -1, 1)
Global $Label, $ListView, $ListViewPX, $Group = 0, $GroupName, $StatusBar, $sip, $pic, $ZYH, $ZYHCF, $BHID, $YBH, $ZXYW, $Progress, $Edit;定义全局变量
Global $nCurCol = -1, $nSortDir = 1, $bSet = 0, $nCol = -1
$sip = @IPAddress1;获取本机ip
If $sip = "0.0.0.0" Then $sip = @IPAddress2
If $sip = "0.0.0.0" Then $sip = @IPAddress3
If $sip = "0.0.0.0" Then $sip = @IPAddress4
If $sip = "0.0.0.0" Then $sip = "IP地址获取失败"
Global $LoginMain, $Mail, $Button, $LoginName, $LoginPassword, $UserGroup, $TabShell, $Tab, $Tool, $Bom, $iFOCUS, $ListView, $Arry, $MailTool, $ToolMail, $error, $loginout = 0, $Tooll
#endregion ### 连接数据库 ###
bl()
While 1
Sleep(1000)
WEnd
Func bl()
Dim $Tool, $Label, $ListView, $TabTools, $pic, $error = 0, $Tooll
Global $errorBox, $OK = 3, $Bak = 0
$MailTool = GUICreate("病历管理", 740, 680, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "BLGL")
GUISetIcon(@TempDir & "\HISTools\12.ico")
$Group1 = GUICtrlCreateGroup("", 8, 0, 721, 177)
$Tool = GUICtrlCreateButton("所有病历", 56, 300, 73, 25)
$Tool = GUICtrlCreateButton("问题病历", 168, 300, 73, 25)
$Tool = GUICtrlCreateButton("退调病历", 280, 300, 73, 25)
$Tool = GUICtrlCreateButton("病历统计", 392, 300, 73, 25)
$Tool = GUICtrlCreateButton("病历日志", 504, 300, 73, 25)
$Tool = GUICtrlCreateButton("返 回", 616, 300, 73, 25)
$List = GUICtrlCreateListView("", 8, 335, 725, 280, $LVS_EX_CHECKBOXES, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlRegisterListViewSort(-1, "LVSort")
GUICtrlSetFont($ListView, 10)
_GUICtrlListView_AddColumn($List, "住院号", 70, 2, 0)
_GUICtrlListView_AddColumn($List, "姓名", 110, 2, 1)
_GUICtrlListView_AddColumn($List, "病历状态", 80, 2, 2)
_GUICtrlListView_AddColumn($List, "详细信息", 135, 2, 3)
_GUICtrlListView_AddColumn($List, "科室信息", 80, 2, 4)
_GUICtrlListView_AddColumn($List, "操作人员", 80, 2, 5)
_GUICtrlListView_AddColumn($List, "操作日期", 85, 2, 6)
_GUICtrlListView_AddColumn($List, "操作时间", 80, 2, 7)
GUICtrlCreateListViewItem("073871|测试1|状态1|信息2|1科室|02|2011年10月23日|02:45:52", $list)
GUICtrlCreateListViewItem("073872|测试3状态2|信息1|4科室|00|2011年10月22日|03:45:52", $list)
GUICtrlCreateListViewItem("073873|测试2|状态14|信息12|2科室|00|2011年10月23日|02:45:52", $list)
GUICtrlCreateListViewItem("073879|测试8|状态4|信息1|科室|02|2011年10月23日|02:45:52", $list)
$lv = GUICtrlCreateListView("", 8, 10, 725, 280, $LVS_EX_CHECKBOXES, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))
GUICtrlRegisterListViewSort(-1, "LVSort") ; Register the function "SortLV" for the sorting callback
_GUICtrlListView_AddColumn($lv, "住院号", 70, 2, 0)
_GUICtrlListView_AddColumn($lv, "姓名", 110, 2, 1)
_GUICtrlListView_AddColumn($lv, "病历状态", 80, 2, 2)
_GUICtrlListView_AddColumn($lv, "详细信息", 135, 2, 3)
_GUICtrlListView_AddColumn($lv, "科室信息", 80, 2, 4)
_GUICtrlListView_AddColumn($lv, "操作人员", 80, 2, 5)
_GUICtrlListView_AddColumn($lv, "操作日期", 85, 2, 6)
_GUICtrlListView_AddColumn($lv, "操作时间", 80, 2, 7)
Dim $Arry
$Arry="07871"
$Arry="Tes1"
$Arry="03232"
$Arry="Tes2"
_GUICtrlListView_AddArray($lv, $Arry)
;~ GUICtrlCreateListViewItem("073871|测试1|状态1|信息2|1科室|02|2011年10月23日|02:45:52", $lv)
;~ GUICtrlCreateListViewItem("073872|测试3状态2|信息1|4科室|00|2011年10月22日|03:45:52", $lv)
;~ GUICtrlCreateListViewItem("073873|测试2|状态14|信息12|2科室|00|2011年10月23日|02:45:52", $lv)
;~ GUICtrlCreateListViewItem("073879|测试8|状态4|信息1|科室|02|2011年10月23日|02:45:52", $lv)
;~
;_GUICtrlListView_SetColumnWidth($ListView, 0, 80)
;_GUICtrlListView_SetColumnWidth($ListView, 1, 120)
;_GUICtrlListView_SetColumnWidth($ListView, 2, 80)
;_GUICtrlListView_SetColumnWidth($ListView, 3, 195)
;_GUICtrlListView_SetColumnWidth($ListView, 4, 80)
;_GUICtrlListView_SetColumnWidth($ListView, 5, 80)
;_GUICtrlListView_SetColumnWidth($ListView, 6, 80)
;_GUICtrlListView_SetItemCount($ListView, 9999)
; Dim $ListViewPX)]
GUICtrlCreateLabel("所有病历:", 16, 627, 84, 20)
GUICtrlSetFont(-1, 12, 400, 0, "新宋体")
$Label = GUICtrlCreateLabel("0", 88, 625, 48, 27, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 2, "Arial")
GUICtrlCreateLabel("接收病历:", 168, 627, 84, 20)
GUICtrlSetFont(-1, 12, 400, 0, "新宋体")
$Label = GUICtrlCreateLabel("0", 240, 625, 48, 27, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 2, "Arial")
GUICtrlCreateLabel("正常病历:", 312, 627, 84, 20)
GUICtrlSetFont(-1, 12, 400, 0, "新宋体")
$Label = GUICtrlCreateLabel("0", 384, 625, 48, 27, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 2, "Arial")
GUICtrlCreateLabel("问题病历:", 456, 627, 84, 20)
GUICtrlSetFont(-1, 12, 400, 0, "新宋体")
$Label = GUICtrlCreateLabel("0", 528, 625, 48, 27, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 2, "Arial")
GUICtrlCreateLabel("退调病历:", 600, 627, 84, 20)
GUICtrlSetFont(-1, 12, 400, 0, "新宋体")
$Label = GUICtrlCreateLabel("0", 672, 625, 48, 27, $SS_CENTER)
GUICtrlSetFont(-1, 12, 400, 2, "Arial")
GUICtrlCreateTabItem("")
;~ $TabTools = GUICtrlCreateTabItem("问题病历")
;~ $ListView = GUICtrlCreateListView("", 8, 335, 720, 280)
Dim $aParts = , $StatusBar
$StatusBar = _GUICtrlStatusBar_Create($MailTool)
_GUICtrlStatusBar_SetMinHeight($StatusBar, 20)
_GUICtrlStatusBar_SetParts($StatusBar, $aParts)
_GUICtrlStatusBar_SetText($StatusBar, "操作员:" & $LoginName)
_GUICtrlStatusBar_SetText($StatusBar, "本机IP:" & $sip, 1)
_GUICtrlStatusBar_SetText($StatusBar, "日期:" , 2)
_GUICtrlStatusBar_SetText($StatusBar, "北京时间:" & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 3)
_GUICtrlStatusBar_SetText($StatusBar, "新疆时间:" & StringFormat("%02d:%02d:%02d", @HOUR - 2, @MIN, @SEC), 4)
_Timer_SetTimer($MailTool, 1000, "_UpdateBJClock")
_Timer_SetTimer($MailTool, 1000, "_UpdateXJClock")
For $i = 1 To 15
GUICtrlSetOnEvent($Tool[$i], "BLGL")
Next
GUICtrlSetOnEvent($ListView, "BLGL")
GUICtrlSendMsg($ListView, $LVM_DeleteALLITEMS, 0, 0)
GUISetState(@SW_SHOW)
EndFunc
Func BLGL()
Switch @GUI_CtrlId
Case $GUI_EVENT_CLOSE
If MsgBox(1, "提示", "是否退出程序?") = 1 Then
Exit
EndIf
Case $Tool
MsgBox(0, "错误!", "嘿嘿!操作判断失误o(╯□╰)o,8好意思。。!")
Case $Tool ;==>解除欠费
MsgBox(4160, "", "正在开发!")
Case $Tool ;==>正常接收
For $i = 1 To 6
GUICtrlSetState($Label[$i], $GUI_HIDE)
Next
Case $Tool ;==>结算出错
For $i = 3 To 6
GUICtrlSetState($Label[$i], $GUI_HIDE)
Next
For $i = 1 To 2
GUICtrlSetState($Label[$i], $GUI_SHOW)
Next
Case $Tool ;==>病历退调
For $i = 1 To 2
GUICtrlSetState($Label[$i], $GUI_HIDE)
Next
For $i = 3 To 4
GUICtrlSetState($Label[$i], $GUI_SHOW)
Next
Case $Tool ;==>正常结算
For $i = 1 To 6
GUICtrlSetState($Label[$i], $GUI_HIDE)
Next
Case $Tool ;==>其 他
For $i = 1 To 6
GUICtrlSetState($Label[$i], $GUI_HIDE)
Next
$errorBox = InputBox("其他", "请输入其他原因!", $errorBox, "", -1, -1, 850, 250)
Case $Tool ;==>锁定
MsgBox(4160, "", "正在开发!")
Case $Tool ;==>解锁
MsgBox(4160, "", "正在开发!")
Case $Tool ;==>所有病历
_ArrayDisplay($ListView)
$iIndex = _GUICtrlListView_AddItem($ListView, "1")
;_GUICtrlListView_AddSubItem($ListView, $iIndex, $BLXM, 1)
MsgBox(0, "", $iIndex)
Case $Tool ;==>问题病历
MsgBox(4160, "", "正在开发!")
Case $Tool ;==>其他病历
MsgBox(4160, "", "正在开发!")
Case $Tool ;==>退调病历
MsgBox(4160, "", "正在开发!")
Case $Tool ;==>病历日志
MsgBox(4160, "", "正在开发!")
Case $Tool ;==>返回
GUIDelete(@GUI_WinHandle)
GUISwitch($Mail)
GUISetState(@SW_SHOW)
GUISetCursor(2, 1)
GUISetState(@SW_ENABLE)
_WinAPI_SetWindowPos($Mail, -1, 0, 0, 0, 0, 3)
_WinAPI_SetWindowPos($Mail, -2, 0, 0, 0, 0, 3)
Case $ListView
;_GUICtrlListView_SimpleSort($ListView, $ListViewPX, GUICtrlGetState($ListView)) ;<==$ListView的排序
$bSet = 0
$nCurCol = $nCol
GUICtrlSendMsg($ListView, $LVM_SETSELECTEDCOLUMN, GUICtrlGetState($ListView), 0)
EndSwitch
EndFunc ;==>BLGL
Func LVSort($hWnd, $nItem1, $nItem2, $nColumn)
MsgBox(0, "", "调用了自定义函数," & $hWnd & "," & $nItem1 & "," & $nItem2 & "," & $nColumn)
Local $nSort, $val1, $val2, $nResult
; Switch the sorting direction
If $nColumn = $nCurCol Then
If Not $bSet Then
$nSortDir = $nSortDir * - 1
$bSet = 1
EndIf
Else
$nSortDir = 1
EndIf
$nCol = $nColumn
$val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
$val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
; If it is the 3rd colum (column starts with 0) then compare the dates
If $nColumn = 2 Then
$val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2)
$val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2)
EndIf
$nResult = 0 ; No change of item1 and item2 positions
If $val1 < $val2 Then
$nResult = -1 ; Put item2 before item1
ElseIf $val1 > $val2 Then
$nResult = 1 ; Put item2 behind item1
EndIf
$nResult = $nResult * $nSortDir
Return $nResult
EndFunc ;==>LVSort
; Retrieve the text of a listview item in a specified column
Func GetSubItemText($nCtrlID, $nItemID, $nColumn)
Local $stLvfi = DllStructCreate("uint;ptr;int;int;int")
Local $nIndex, $stBuffer, $stLvi, $sItemText
DllStructSetData($stLvfi, 1, $LVFI_PARAM)
DllStructSetData($stLvfi, 3, $nItemID)
$stBuffer = DllStructCreate("char")
$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
$stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
DllStructSetData($stLvi, 1, $LVIF_TEXT)
DllStructSetData($stLvi, 2, $nIndex)
DllStructSetData($stLvi, 3, $nColumn)
DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
DllStructSetData($stLvi, 7, 260)
GUICtrlSendMsg($nCtrlID, $LVM_GETITEMA, 0, DllStructGetPtr($stLvi));
$sItemText = DllStructGetData($stBuffer, 1)
$stLvi = 0
$stLvfi = 0
$stBuffer = 0
Return $sItemText
EndFunc ;==>GetSubItemText
; Our sorting callback funtion
Func LVSort2($hWnd, $nItem1, $nItem2, $nColumn)
Local $nSort, $val1, $val2, $nResult
; Switch the sorting direction
If $nColumn = $nCurCol Then
If Not $bSet Then
$nSortDir = $nSortDir * - 1
$bSet = 1
EndIf
Else
$nSortDir = 1
EndIf
$nCol = $nColumn
$val1 = GetSubItemText($hWnd, $nItem1, $nColumn)
$val2 = GetSubItemText($hWnd, $nItem2, $nColumn)
; If it is the 3rd colum (column starts with 0) then compare the dates
If $nColumn = 2 Then
$val1 = StringRight($val1, 4) & StringMid($val1, 4, 2) & StringLeft($val1, 2)
$val2 = StringRight($val2, 4) & StringMid($val2, 4, 2) & StringLeft($val2, 2)
EndIf
$nResult = 0 ; No change of item1 and item2 positions
If $val1 < $val2 Then
$nResult = -1 ; Put item2 before item1
ElseIf $val1 > $val2 Then
$nResult = 1 ; Put item2 behind item1
EndIf
$nResult = $nResult * $nSortDir
Return $nResult
EndFunc ;==>LVSort2
; Retrieve the text of a listview item in a specified column
Func GetSubItemText2($nCtrlID, $nItemID, $nColumn)
Local $stLvfi = DllStructCreate("uint;ptr;int;int;int")
Local $stBuffer, $nIndex, $stLvi, $sItemText
DllStructSetData($stLvfi, 1, $LVFI_PARAM) ; Find the item by our saved index
DllStructSetData($stLvfi, 3, $nItemID)
$stBuffer = DllStructCreate("char")
$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_FINDITEM, -1, DllStructGetPtr($stLvfi));
$stLvi = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int")
DllStructSetData($stLvi, 1, $LVIF_TEXT)
DllStructSetData($stLvi, 2, $nIndex)
DllStructSetData($stLvi, 3, $nColumn)
DllStructSetData($stLvi, 6, DllStructGetPtr($stBuffer))
DllStructSetData($stLvi, 7, 260)
GUICtrlSendMsg($nCtrlID, $LVM_GETITEMA, 0, DllStructGetPtr($stLvi));
$sItemText = DllStructGetData($stBuffer, 1)
$stLvi = 0
$stLvfi = 0
$stBuffer = 0
Return $sItemText
EndFunc ;==>GetSubItemText2
; Create and insert items directly into the listview
Func MyGUICtrlCreateListViewItem($sText, $nCtrlID, $nIndex)
Local $stLvItem = DllStructCreate("uint;int;int;uint;uint;ptr;int;int;int;int;")
Local $stText = DllStructCreate("char")
Local $arText = StringSplit($sText, "|")
If $nIndex = -1 Then $nIndex = GUICtrlSendMsg($nCtrlID, $LVM_GETITEMCOUNT, 0, 0)
DllStructSetData($stText, 1, $arText) ; Save the item text in the struct
DllStructSetData($stLvItem, 1, BitOR($LVIF_TEXT, $LVIF_PARAM))
DllStructSetData($stLvItem, 2, $nIndex)
DllStructSetData($stLvItem, 6, DllStructGetPtr($stText))
; Set the lParam of the struct to the line index - unique within the listview
DllStructSetData($stLvItem, 9, $nIndex)
$nIndex = GUICtrlSendMsg($nCtrlID, $LVM_INSERTITEMA, 0, DllStructGetPtr($stLvItem))
If $nIndex > -1 Then
; Insert now the rest of the column text
For $i = 2 To $arText
DllStructSetData($stText, 1, $arText[$i])
DllStructSetData($stLvItem, 3, $i - 1) ; Store the subitem index
GUICtrlSendMsg($nCtrlID, $LVM_SETITEMTEXTA, $nIndex, DllStructGetPtr($stLvItem))
Next
EndIf
$stText = 0
$stLvItem = 0
; Change the column width to fit the item text
For $i = 0 To 2
GUICtrlSendMsg($nCtrlID, $LVM_SETCOLUMNWIDTH, $i, -1)
GUICtrlSendMsg($nCtrlID, $LVM_SETCOLUMNWIDTH, $i, -2)
Next
EndFunc ;==>MyGUICtrlCreateListViewItem
回复 6# afan
很感谢啊。。A大这么晚了还不休息么??
辛苦写这么多测试数据了,不过我是读的数据库,然后用数组的方式写入的,这样的情况貌似高级排序无效,貌似你的方法更另类点,只有明天试试了。。。谢谢了啊。。顺便谢谢大家。。。呵呵 回复 7# happytc
哈哈。。。老兄你这个办法貌似最简单实用。。。修改函数的源文件我经常改。。我咋没这样想过。。哇哈哈。。。我一会试试。。。灰常感谢!!! 楼主,你的软件是用什么做数据库的? 本帖最后由 koflion 于 2011-10-23 16:41 编辑
回复 11# hzxymkb
用的MSSQL啊。。怎么了???主要是依托在医院HIS业务数据库上面,服务器性能很强大的。。呵呵。。2000和2008都无所谓。。我只用到基本语法,函数都自己写,通用性很高,oracle和MYSQL之类的应该不行,应为连接函数用的是MSSQL的。。。 这里的方法真多,谢谢分享,留这 多谢楼主提供 學習了 都是高手啊
页:
[1]
2