Imports System.Data

Partial Class AcceptNews
    Inherits System.Web.UI.Page

    Protected Sub grdFill()
        Dim db As New FirstClass()
        Dim dt As New DataTable()

        dt = db.dbOut("SELECT tblNews.NewsID, tblNews.NewsTitle, NewsGroups.NewgGroupDescription, Users.UserName, " & vbCr & vbLf & " Users.Name + N' ' + Users.Sname AS Expr1, tblNews.DateOfAdding, Users.EMail1 FROM tblNews INNER JOIN" & vbCr & vbLf & " NewsGroups ON tblNews.NewsGroupID = NewsGroups.NewsGroupID INNER JOIN" & vbCr & vbLf & " Users ON tblNews.UserName = Users.UserName WHERE (tblNews.ShowPermiss = 0)")
        GridView1.DataSource = dt
        GridView1.DataBind()
    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
        grdFill()
    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim nwsEdtKey As Integer = CInt(GridView1.DataKeys(e.RowIndex).Value)
        Dim db As New FirstClass()
        db.cmd.Parameters.Add("@NewsID", SqlDbType.Int).Value = nwsEdtKey

        db.exeCommand("sp_tblNews_DeleteRow")
        grdFill()
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Dim db As New FirstClass()
        Dim nwsEdtKey As [String] = GridView1.SelectedValue.ToString()

        db.cmd.Parameters.Add("@NewsID", SqlDbType.Int).Value = Integer.Parse(nwsEdtKey)
        db.cmd.Parameters.Add("@ShowPermiss", SqlDbType.Bit).Value = 1

        db.exeCommand("sp_tblNews_Update3")
        grdFill()
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Session("UserName") IsNot Nothing Then
            If Integer.Parse(Session("UserTypeID").ToString()) = 1 Then
                grdFill()
            Else
                Response.Redirect("Default.aspx?ID=NotHavePermission" & DateTime.Now.Ticks.ToString())
            End If
        Else
            Response.Redirect("Default.aspx?ID=NotHavePermission" & DateTime.Now.Ticks.ToString())
        End If
    End Sub
End Class
