以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=82461)

--  作者:sdeaven
--  发布时间:2016/3/18 10:18:00
--  [求助]
 求助大神解决一下问题;我想自制一个ftp文件管理器使用listview按照文件修改日期排序显示出来,上传文件和删除文件后能刷新,昨天求助了客服,他帮我写了全局代码(非常感谢!),排序显示已经实现了,但是刷新listview,就会出错,,,求助大神帮我!!!嘿嘿

以下是全局代码(昨晚找度娘查看了半天,说是泛类接口比较排序方法,感觉还是迷茫!!!)
Public Class ListViewItemComparer
    Implements   System.Collections.IComparer

    Public sort_b As Boolean
    Public order As System.Windows.Forms.SortOrder = System.Windows.Forms.SortOrder.Ascending

    Private Col As Integer

    Public Sub New()
        Col = 0
    End Sub

    Public Sub New(Column As Integer, sort As Boolean)

        Col = Column
        sort_b = sort
    End Sub

    Public Function Compare(x As Object, y As Object) As Integer Implements System.Collections.IComparer.Compare

        If sort_b Then

            Return String.Compare((CType(x, System.Windows.Forms.ListViewItem)).SubItems(Col).Text, (CType(y, System.Windows.Forms.ListViewItem)).SubItems(Col).Text)

        Else

            Return String.Compare((CType(y, System.Windows.Forms.ListViewItem)).SubItems(Col).Text, (CType(x, System.Windows.Forms.ListViewItem)).SubItems(Col).Text)
        End If
    End Function


End Class
---------------------------------------------------------------------------------------------------------------------------------
以下代码放在需要排序的地方:我放在了自制内部函数“新listview”里面
Dim lsv = e.Form.Controls("ListView1").basecontrol
lsv.ListViewItemSorter = new ListViewItemComparer(2, True) \'这里的2改成您日期列在所有列中的顺序,需要倒序True改成False
---------------------------------------------------------------------------------------------------------------------------------
以下是我的 自制内部函数“新listview”:
Dim ftp As new FTPClient  \'定义好ftp账号
\'ftp.Host="192.168.11.51"
ftp.Host="10.46.95.219"
ftp.Account="foxftp"
ftp.Password="123"
ftp.ChangeDir("\\zzsj")  \'进入到zzsj目录,\\绝对目录,没斜杠相对目录

Dim fp As String = "\\zzsj\\" & Tables("日常事务").Current("自制")  \'定义变量来代替动态路径
If ftp.DirExists(fp) = False Then  \'若目录不存在就自增
    ftp.MakeDir(fp)
End If

\'==============以上是设置ftp路径======================
Dim lvw As WinForm.ListView = Forms("日常事务").Controls("ListView1")
lvw.Columns.Clear() \'清除原来的列
lvw.Rows.Clear() \'清除原来的行
lvw.Images.Clear() \'清除原来的图片
lvw.View = ViewMode.Details \'显示模式为详细信息
\'lvw.GridLines = True  \'显示网格
Dim cls() As String = {"文件","修改日期","大小"} \'定义列名
Dim wds() As Integer = {900,200,200} \'定义列宽
For i As Integer = 0 To  cls.Length - 1
    Dim c As WinForm.ListViewColumn = lvw.Columns.Add()
    c.Name = cls(i) \'指定列名
    c.Text = cls(i) \'指定标题,这里标题和列名相同
    c.Width = wds(i) \'指定列宽
Next
lvw.Columns("文件").TextAlign = HorizontalAlignment.left  \'文件列靠左
lvw.Columns("修改日期").TextAlign = HorizontalAlignment.Right \'日期列靠右对齐
lvw.Columns("大小").TextAlign = HorizontalAlignment.Right \'大小列靠右对齐

\'调用全局代码
Dim lsv = Forms("日常事务").Controls("ListView1").basecontrol
lsv.ListViewItemSorter = new ListViewItemComparer(1,False)

\'--------------------------------------------------按照图标显示文件-------------------------------------------------------------
Dim ics() As String={"swf","accdb","mdb","psd","png","xls","xlsx","bmp","rar","jpg","doc","docx","zip","pdf","txt","ppt","exe","7z","dwg","ico","other"}   
Dim kzms As String="swf accdb mdb psd png xls xlsx bmp rar jpg doc docx zip pdf txt ppt exe 7z dwg ico"
For Each ic As String In ics
    lvw.images.addimage(ic,ic & ".png",ic & ".png")
Next
\'Dim sts As List(of String)=ftp.getfilelist(fp)
Dim sts As List(of String)=ftp.GetDetailList(fp)
If sts.count>0 Then
    For Each st As String In sts
        Dim Values() As String
        Values = st.split("*")
        Dim r As WinForm.ListViewRow=lvw.Rows.Add
        Dim Dot As Integer=Values(0).lastindexof(".")
        Dim kzm As String=Values(0).Substring(Dot+1)
        Dim dogx As Integer=CDbl(Values(2))/1024
        Dim cat As String=CStr(dogx) & "K"
        r("文件")=Values(0)
        r("修改日期")=Values(1)
        r("大小")=cat
        If kzms.contains(kzm)=True Then
            r.ImageKey = kzm
        Else
            r.ImageKey ="other"
        End If
    Next
End If

窗口界面上的刷新按钮:click事件:Functions.Execute("新ListView")

点击按钮出错,如图:

图片点击可在新窗口打开查看

点击存在调用“新listview”的按钮都出错
图片点击可在新窗口打开查看
上传按钮click事件代码:
Dim dlg As new OpenFileDialog
If dlg.ShowDialog = DialogResult.OK Then
Dim xg As Integer = dlg.FileName.LastIndexOf("\\")
Dim fname As String = dlg.FileName.SubString(xg+1)  \'获取所选文件名

Dim ftp As new FTPClient  \'定义好ftp账号
\'ftp.Host="192.168.11.51"
ftp.Host="10.46.95.219"
ftp.Account="foxftp"
ftp.Password="123"

Dim fp As String ="\\zzsj\\" & Tables("日常事务").Current("自制")
Dim sts As List(of String)=ftp.GetDetailList(fp)
If sts.Count > 0 Then
For Each st As String In sts
If st = fname Then
If MessageBox.Show("服务器上存在同名文件,是否覆盖!","提醒",MessageBoxButtons.YesNo,MessageBoxIcon.Question)=DialogResult.Yes Then
If ftp.DeleteFile(fp & "\\" & fname)=True Then
ftp.Upload(dlg.FileName,fp & "\\" & fname)
Functions.Execute("新listview")  \'上传后刷新
End If
\'Return  \'简化操作,可以添加是否覆盖功能
End If
End If
Next
e.Form.text="文件上传中......"
If ftp.Upload(dlg.FileName,fp & "\\" & fname)=True Then
e.Form.text="日常事务"
MessageBox.Show("上传成功!","提醒")
Functions.Execute("新listview")  \'上传后刷新
Else
MessageBox.Show("上传失败!","提醒")
e.Form.text="日常事务"
End If
End If
End If



求大神解决下,555555555.。。。


非常感谢狐表的专家老师们热心解答帮我解决了两天来纠结的问题,以后有问题了还要经常来请教哈,嘿嘿。。。
把结果公布出来,方便更多朋友查阅,希望能帮助到更多的正在学习狐表的朋友们。
最后还是感谢小黄老师,感谢专家。
更改“新listview”内部函数为
\'==============以上是设置ftp路径======================
Dim lvw As WinForm.ListView = Forms("日常事务").Controls("ListView1")
\'添加清空原排序值
Dim lsvt = lvw.BaseControl
lsvt.ListViewItemSorter = Nothing


\'将排序代码放在最后,
Dim lsv = Forms("日常事务").Controls("ListView1").basecontrol
lsv.ListViewItemSorter = new ListViewItemComparer(1,False)

[此贴子已经被作者于2016/3/18 11:43:12编辑过]

--  作者:狐狸爸爸
--  发布时间:2016/3/18 10:22:00
--  

这些扩展问题,官方提供不了技术支持。

看看有没有其他用户能帮到你吧。


--  作者:Hyphen
--  发布时间:2016/3/18 10:28:00
--  
\'==============以上是设置ftp路径======================
Dim lvw As WinForm.ListView = Forms("日常事务").Controls("ListView1")
Dim lsv = lvw.BaseControl
lsv.ListViewItemSorter = Nothing
lvw.Columns.Clear() \'清除原来的列
lvw.Rows.Clear() \'清除原来的行
lvw.Images.Clear() \'清除原来的图片
lvw.View = ViewMode.Details \'显示模式为详细信息
\'lvw.GridLines = True  \'显示网格
Dim cls() As String = {"文件","修改日期","大小"} \'定义列名
Dim wds() As Integer = {900,200,200} \'定义列宽
For i As Integer = 0 To  cls.Length - 1
    Dim c As WinForm.ListViewColumn = lvw.Columns.Add()
    c.Name = cls(i) \'指定列名
    c.Text = cls(i) \'指定标题,这里标题和列名相同
    c.Width = wds(i) \'指定列宽
Next
lvw.Columns("文件").TextAlign = HorizontalAlignment.left  \'文件列靠左
lvw.Columns("修改日期").TextAlign = HorizontalAlignment.Right \'日期列靠右对齐
lvw.Columns("大小").TextAlign = HorizontalAlignment.Right \'大小列靠右对齐

\'调用全局代码
lsv.ListViewItemSorter = new ListViewItemComparer(1,False)

--  作者:sdeaven
--  发布时间:2016/3/18 10:39:00
--  [求助]
 不行,还是出一样的错
--  作者:Hyphen
--  发布时间:2016/3/18 10:51:00
--  
测试没有问题,跟排序么有关系