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
Imports System.Net

Partial Class AddVoteUC
    Inherits System.Web.UI.UserControl

    Protected Sub voteAdd()
        Try
            Label4.Visible = False
            Dim text1 As String = Dns.GetHostName(), text2 As String
            text2 = Dns.GetHostByName(text1).AddressList(0).ToString()
            Dim db As New FirstClass()
            db.cmd.Parameters.Add("@newsID", SqlDbType.Int).Value = Integer.Parse(Request.QueryString("NewsID").ToString())
            db.cmd.Parameters.Add("@SenderIP", SqlDbType.NVarChar).Value = text2
            db.cmd.Parameters.Add("@VoterNameSname", SqlDbType.NVarChar).Value = TextBox1.Text.Trim()
            db.cmd.Parameters.Add("@VoterEmail", SqlDbType.NVarChar).Value = TextBox2.Text.Trim()
            db.cmd.Parameters.Add("@VoteBody", SqlDbType.NVarChar).Value = TextBox3.Text.Trim()
            db.cmd.Parameters.Add("@voterWebSite", SqlDbType.NVarChar).Value = TextBox4.Text.Trim()
            db.cmd.Parameters.Add("@DateOfVoting", SqlDbType.NVarChar).Value = db.dtShamsi()

            If Session("UserName") IsNot Nothing Then
                If Integer.Parse(Session("UserTypeID").ToString()) = 1 Then
                    db.cmd.Parameters.Add("@allowShowBit", SqlDbType.Bit).Value = 1
                Else
                    db.cmd.Parameters.Add("@allowShowBit", SqlDbType.Bit).Value = 0
                End If
            Else
                db.cmd.Parameters.Add("@allowShowBit", SqlDbType.Bit).Value = 0
            End If

            db.exeCommand("sp_tblVotes_Insert")
            texClear()
            'grdFill()
            Label4.Visible = True
            Label4.Text = "نظر شما درج شد و پس از تائید نمایش داده خواهد شد"
        Catch
            Label4.Visible = True
            Label4.Text = "شما قبلا یک بار نظر داده اید"
        End Try
    End Sub

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

        dt = db.dbOut("SELECT TOP 100 PERCENT VoteID, newsID, VoterNameSname, VoteBody, DateOfVoting, voterWebSite, allowShowBit FROM tblVotes WHERE (allowShowBit = 1) AND (newsID = '" & Integer.Parse(Request.QueryString("NewsID").ToString()) & "')")

        GridView1.DataSource = dt
        GridView1.DataBind()
    End Sub

    Protected Sub texClear()
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        grdFill()
    End Sub

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        voteAdd()
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
        texClear()
    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
End Class
