Imports System
Imports System.Data
Imports System.Configuration
Imports System.Collections
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

Partial Class SelectToEditNews
    Inherits System.Web.UI.Page

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

        If Integer.Parse(Session("UserTypeID").ToString()) = 1 Then
            dt = db.dbOut("SELECT TOP 100 PERCENT NewsID, NewsTitle FROM tblNews WHERE (ShowPermiss = 1) ORDER BY NewsID DESC")
        Else
            dt = db.dbOut("SELECT TOP 100 PERCENT NewsID, NewsTitle, UserName FROM tblNews WHERE (ShowPermiss = 1) AND (UserName = N'" & Session("UserName").ToString() & "') ORDER BY NewsID DESC")
        End If

        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")
        Response.Redirect("SelectToEditNews.aspx?ID=" & DateTime.Now.Ticks.ToString())
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Dim nwsEdtKey As [String] = GridView1.SelectedValue.ToString()
        Response.Redirect("EditNews.aspx?NewsID=" & nwsEdtKey)
    End Sub

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