⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 publicsharedir.aspx.vb

📁 是可以运行的电子光盘 有程序与PPT介绍 对于学习VB。NET的有参考意义
💻 VB
字号:
Imports System.Data
Imports System.io
Partial Class Share_PublicShareDir
    Inherits WebDiskBasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then '放在Ispostback中解决 回发或回调参数无效的问题
            '必须进行初始华,因为所有页面均使用该会话进行排序
            Session("SortName") = "Name"
            Session("SortAscending") = "yes"
            FillGridView(False)
        Else
            Me.StatusMessage.Text = String.Empty
        End If
    End Sub
    'SortName排序字段名;direction排序的方式即递增还是递减,"yes"表示递增,"no"表示递减;bFilter为真表示进行过滤;在 bFilter为真时,需要过滤表达式
    Private Sub FillGridView(ByVal bFilter As Boolean, Optional ByVal strFilter As String = Nothing)
        Dim ds As New DataSet
        '将XML文件数据转化为GridView中合适的数据格式
        ShareXmlServer.CheckShareFile(Data.C_ShareDirXmlMapPath, False)
        ds = ShareXmlServer.GetDataSetByXml(Data.C_ShareDirXmlMapPath)
        If IsNothing(ds) Then Return
        Dim dv As DataView = ds.Tables(0).DefaultView
        If bFilter Then
            dv.RowFilter = strFilter ' "EnableUser='" + Session("User") + "'"
        End If

        If Session("SortAscending").ToString = "yes" Then
            dv.Sort = Session("SortName").ToString + " ASC"
        Else
            dv.Sort = Session("SortName").ToString + " DESC"
        End If
        GridView1.DataSource = dv
        GridView1.DataBind()
        '设置girdview脚本为记录总数
        Dim lblFooter As Label = CType(GridView1.FooterRow.FindControl("lblFooter"), Label)
        lblFooter.Text &= ds.Tables(0).DefaultView.Count
        ds = Nothing
    End Sub

#Region "GridView控件事件"

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim location As String
            Dim liName As Literal = CType(e.Row.FindControl("Name"), Literal)
            Dim CurrentPath As String = CType(e.Row.FindControl("Path"), Literal).Text
            location = Path.Combine(CurrentPath, liName.Text)
            If Directory.Exists(location) Then 'location为目录
                '设置是否有密码,根据Pwd为空,则checkbox为false
                Dim chkPwd As CheckBox = CType(e.Row.FindControl("chkPwd"), CheckBox)
                If CType(e.Row.FindControl("Pwd"), Literal).Text = String.Empty Then
                    chkPwd.Checked = False
                Else
                    chkPwd.Checked = True
                End If
            End If

        End If
    End Sub

    Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
        If e.CommandName = "down" Then
            Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim location As String
            Dim CurrentPath As String = CType(GridView1.Rows(Index).FindControl("Path"), Literal).Text
            Dim liName As Literal = CType(GridView1.Rows(Index).FindControl("Name"), Literal)
            location = Path.Combine(CurrentPath, liName.Text)
            '验证密码是否正确
            Dim strPwd As String = CType(GridView1.Rows(Index).FindControl("Pwd"), Literal).Text
            If IsNothing(strPwd) Or strPwd = String.Empty Then
                Session("UserDir") = location
                Session("CurrentPath") = location
                Server.Transfer("~/FileManager/MainFile.aspx?Folder=" & Server.UrlEncode(location))
            Else
                If funcParam.Value = strPwd Then
                    funcParam.Value = String.Empty
                    StatusMessage.Text = ""
                    Session("UserDir") = location
                    Session("CurrentPath") = location
                    Server.Transfer("~/FileManager/MainFile.aspx?Folder=" & Server.UrlEncode(location))
                Else
                    StatusMessage.Text = "密码错误,请重新输入"
                End If
            End If
        ElseIf e.CommandName = "del" Then   '根据用户名和目录名删除共享
            Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
            Dim location As String
            Dim User As String = CType(GridView1.Rows(Index).FindControl("User"), Literal).Text
            Dim CurrentPath As String = CType(GridView1.Rows(Index).FindControl("Path"), Literal).Text
            Dim Name As String = CType(GridView1.Rows(Index).FindControl("Name"), Literal).Text
            location = Path.Combine(CurrentPath, Name)

            ShareXmlServer.DeleteXmlRowByUserAndName(Data.C_ShareDirXmlMapPath, User, Name)
            FillGridView(False)

        End If
    End Sub

    Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles GridView1.PageIndexChanging
        GridView1.PageIndex = e.NewPageIndex

        FillGridView(False)

    End Sub
    '处理GridView的排序事件()
    Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
        WebPageShare.GridViewSort(GridView1, e)
        FillGridView(False)
    End Sub
#End Region
    '仅显示共享给我的文件
    Protected Sub chkMe_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles chkMe.CheckedChanged
        If chkMe.Checked Then
            Dim strFilter As String = "EnableUser='" + Session("User").ToString + "'"
            FillGridView(True, strFilter)
        Else
            FillGridView(False)
        End If
    End Sub
    '根据目录名过滤
    Protected Sub ibutExp_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibutExp.Click
        If txtExp.Text <> String.Empty Then
            Dim strFilter As String = "Name like '" + txtExp.Text + "'"
            FillGridView(True, strFilter)
        End If
    End Sub

    Protected Sub ibutDirName_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibutDirName.Click
        If txtUser.Text <> String.Empty Then
            Dim strFilter As String = "User='" + txtUser.Text + "'"
            FillGridView(True, strFilter)
        End If

    End Sub

End Class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -