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 EditVotes
    Inherits System.Web.UI.Page

    Protected Sub grdFill()
        Dim db As New FirstClass()
        Dim dt As New DataTable()
        Image1.Visible = False

        If Integer.Parse(Session("UserTypeID").ToString()) = 1 Then
            dt = db.dbOut("SELECT TOP 100 PERCENT VoteID, newsID, VoterNameSname, VoteBody, DateOfVoting, voterWebSite, allowShowBit FROM tblVotes WHERE (allowShowBit = 0)")
        Else
            dt = db.dbOut("SELECT TOP 100 PERCENT tblVotes.VoteID, tblVotes.newsID, tblVotes.VoterNameSname, tblVotes.VoteBody, tblVotes.DateOfVoting, " & vbCr & vbLf & " tblVotes.voterWebSite, tblVotes.allowShowBit, tblNews.UserName FROM tblVotes INNER JOIN tblNews ON tblVotes.newsID = tblNews.NewsID WHERE (tblVotes.allowShowBit = 0) AND (tblNews.UserName = N'" & Session("UserName").ToString() & "')")
        End If
        If dt.Rows.Count <= 0 Then
            GridView1.DataSource = dt
            GridView1.DataBind()
            Image1.Visible = True
        Else
            GridView1.DataSource = dt
            GridView1.DataBind()
        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
        grdFill()
    End Sub

    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        Dim votDelKey As Integer = CInt(GridView1.DataKeys(e.RowIndex).Value)
        Dim db As New FirstClass()

        db.cmd.Parameters.Add("@VoteID", SqlDbType.Int).Value = votDelKey

        db.exeCommand("sp_tblVotes_DeleteRow")
        Response.Redirect("EditVotes.aspx?" & DateTime.Now.Ticks.ToString())
    End Sub

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.SelectedIndexChanged
        Dim votDelKey As Integer = Integer.Parse(GridView1.SelectedValue.ToString())
        Dim db As New FirstClass()

        db.cmd.Parameters.Add("@VoteID", SqlDbType.Int).Value = votDelKey
        db.cmd.Parameters.Add("@allowShowBit", SqlDbType.Bit).Value = 1

        db.exeCommand("sp_tblVotes_Update")
        'grdFill()
        Response.Redirect("EditVotes.aspx?" & DateTime.Now.Ticks.ToString())
    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
