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

📄 myshare.aspx.vb

📁 是可以运行的电子光盘 有程序与PPT介绍 对于学习VB。NET的有参考意义
💻 VB
字号:
Imports System.IO
Imports System.data
Partial Class Share_MyShare
    Inherits WebDiskBasePage
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then '放在Ispostback中解决 回发或回调参数无效的问题
            '通过DataSet检查 ShareFile.xml中数据的正确性和完备性
            ShareXmlServer.CheckShareFile(Server.MapPath(Data.C_ShareFileXmlMapPath), True)
            'ID=1表示显示共享目录,ID=2表示显示共享文件
            ViewState("ID") = Me.Request("ID")
            If ViewState("ID").ToString = "1" Then
                lblHead.Text = "我的共享目录"
            Else
                lblHead.Text = "我的共享文件"
            End If
            '必须进行初始华,因为所有页面均使用该会话进行排序
            Session("SortName") = "Name"
            Session("SortAscending") = "yes"
            FillGridView()
        Else
            Me.StatusMessage.Text = String.Empty
        End If
    End Sub
    'SortName排序字段名;direction排序的方式即递增还是递减,"yes"表示递增,"no"表示递减;bFilter为真表示进行过滤;在 bFilter为真时,需要过滤表达式
    Private Sub FillGridView()
        Dim ds As New DataSet
        Dim tempGif As String
        '将XML文件数据转化为GridView中合适的数据格式
        If ViewState("ID").ToString = "1" Then
            ds = ShareXmlServer.GetDataSetByXml(Data.C_ShareDirXmlMapPath)
        Else
            ds = ShareXmlServer.GetDataSetByXml(Data.C_ShareFileXmlMapPath)
        End If
        If IsNothing(ds) Then Return '没有文件或没有记录时,ds为nothing
        '显示扩展名类型图标,在ds数据表中增加Extension,再根据FileName列设置Extension列的值
        ds.Tables(0).Columns.Add(New DataColumn("Extension", System.Type.GetType("System.String")))
        If ViewState("ID").ToString = "1" Then
            For Each row As DataRow In ds.Tables(0).Rows
                row("Extension") = Data.C_foldergifMapPath
            Next
        Else
            For Each row As DataRow In ds.Tables(0).Rows
                tempGif = FileDirServer.GetGifByFileName(row("Name").ToString)
                If File.Exists(Server.MapPath(tempGif)) Then
                    row("Extension") = tempGif
                Else
                    row("Extension") = Data.C_smilefacegifMapPath
                End If
            Next
        End If

        Dim dv As DataView = ds.Tables(0).DefaultView
        dv.RowFilter = "User='" + Session("User") + "'"

        If Session("SortAscending") = "yes" Then
            dv.Sort = Session("SortName") + " ASC"
        Else
            dv.Sort = Session("SortName") + " DESC"
        End If
        GridView1.DataSource = dv
        GridView1.DataBind()
        ds = Nothing
    End Sub

    Protected Sub GridView1_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles GridView1.RowCancelingEdit
        GridView1.EditIndex = -1
        e.Cancel = True
        FillGridView()
    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim Index As Integer = e.RowIndex
        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)
        If ViewState("ID").ToString = "1" Then
            ShareXmlServer.DeleteXmlRowByUserAndName(Data.C_ShareDirXmlMapPath, User, Name)
        Else
            ShareXmlServer.DeleteXmlRowByUserAndName(Data.C_ShareFileXmlMapPath, User, Name)
        End If
        FillGridView()
    End Sub

    Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
        GridView1.EditIndex = e.NewEditIndex
        GridView1.EditRowStyle.BackColor = System.Drawing.Color.FromName("#f7ce90")
        'Dim txtToUse As TextBox = CType(GridView1.Rows(e.NewEditIndex).FindControl("txtToUserEdit"), TextBox)
        'Dim liToUse As Literal = CType(GridView1.Rows(e.NewEditIndex).FindControl("ToUser"), Literal)
        'txtToUse.Text = liToUse.Text
        FillGridView()
    End Sub

    Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating
        Dim index As Integer = e.RowIndex
        Dim User As String = CType(GridView1.Rows(e.RowIndex).FindControl("User"), Literal).Text
        Dim Name As String = CType(GridView1.Rows(e.RowIndex).FindControl("Name"), Literal).Text
        Dim bDel As Boolean = CType(GridView1.Rows(e.RowIndex).FindControl("chkDelEdit"), CheckBox).Checked
        Dim bEdit As Boolean = CType(GridView1.Rows(e.RowIndex).FindControl("chkEditEdit"), CheckBox).Checked

        Dim strPwd As String = CType(GridView1.Rows(e.RowIndex).FindControl("txtPwdEdit"), TextBox).Text
        Dim strToUser As String = CType(GridView1.Rows(e.RowIndex).FindControl("txtToUserEdit"), TextBox).Text
        '根据User和Name在XML文件中查找相应记录,修改之
        If ViewState("ID").ToString = "1" Then
            ShareXmlServer.ModifyXmlRowByUserAndName(Data.C_ShareDirXmlMapPath, User, Name, strPwd, bEdit, bDel, strToUser)
        Else
            ShareXmlServer.ModifyXmlRowByUserAndName(Data.C_ShareFileXmlMapPath, User, Name, strPwd, bEdit, bDel, strToUser)
        End If
        FillGridView()
        GridView1.EditIndex = -1
        FillGridView()

    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()
    End Sub
End Class

⌨️ 快捷键说明

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