vb.net按钮上的多个评级点击

时间:2016-03-08 04:39:37

标签: asp.net vb.net

我有门户网站,用户可以找到医院列表。现在我希望用户对任何医院进行评级。在这里,我对1家医院有6种不同的评级。我希望用户首先选择所有这些评级&当他们点击提交时,只有它应该插入到数据库中。并且只有登录到网站的用户才能评分。我创建了用户登录/注册页面&用户能够完美地登录网站,但现在如何整合所有这些我不知道。请帮我。这听起来很简单,但由于我是vb开发的新手,我遇到了问题......

评价aspx

 <!--star-left-starts--><div class="star-left">
                        <div class="star-rating1">
                            <strong>Resonability Of Charges</strong><br />
                            <cc1:ToolkitScriptManager ID="ToolkitScriptManager2" runat="server">
                            </cc1:ToolkitScriptManager>
                            <cc1:Rating ID="Rating2" ClientIDMode="Static" AutoPostBack="true" OnChanged="money" runat="server"
                                StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                                FilledStarCssClass="FilledStar" MaxRating="10" CurrentRating="1">
                            </cc1:Rating>
                        </div>


                        <div class="star-rating2">
                            <strong>Staff Behaviour</strong><br />
                            <cc1:Rating ID="Rating3" ClientIDMode="Static" AutoPostBack="true" OnChanged="behaviour" runat="server"
                                StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                                FilledStarCssClass="FilledStar" MaxRating="10" CurrentRating="1">
                            </cc1:Rating>
                        </div>


                        <div class="star-rating3">
                            <strong>Admission Procedure</strong><br />
                            <cc1:Rating ID="Rating4" ClientIDMode="Static" AutoPostBack="true" OnChanged="admission" runat="server"
                                StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                                FilledStarCssClass="FilledStar" MaxRating="10" CurrentRating="1">
                            </cc1:Rating>
                        </div>
                    </div><!--star-left-ends-->



                    <!--star-right-starts--><div class="star-right">
                        <div class="star-rating4">
                            <strong>Proper Information</strong><br />
                            <cc1:Rating ID="Rating5" ClientIDMode="Static" AutoPostBack="true" OnChanged="information" runat="server"
                                StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                                FilledStarCssClass="FilledStar" MaxRating="10" CurrentRating="1">
                            </cc1:Rating>
                        </div>


                        <div class="star-rating5">
                            <strong>Hygine Standards</strong><br />
                            <cc1:Rating ID="Rating6" ClientIDMode="Static" AutoPostBack="true" OnChanged="hygine" runat="server"
                                StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                                FilledStarCssClass="FilledStar" MaxRating="10" CurrentRating="1">
                            </cc1:Rating>
                        </div>


                        <div class="star-rating6">
                            <strong>Treatment Satisfactions</strong><br />
                            <cc1:Rating ID="Rating7" ClientIDMode="Static" AutoPostBack="true" OnChanged="treatment" runat="server"
                                StarCssClass="Star" WaitingStarCssClass="WaitingStar" EmptyStarCssClass="Star"
                                FilledStarCssClass="FilledStar" MaxRating="10" CurrentRating="1">
                            </cc1:Rating>
                        </div>
                    </div><!--star-right-ends-->


                    <div class="clear"></div>
                </div><!--star-rates-ends-->

评级vb

Protected Sub money(sender As Object, e As RatingEventArgs)
        Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
        Using con As New MySqlConnection(constr)
            Using cmd As New MySqlCommand("insert into ratings(charges)values(@Rating)")
                Using sda As New MySqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@Rating", e.Value)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

    Protected Sub Charges(sender As Object, e As RatingEventArgs)
        Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
        Using con As New MySqlConnection(constr)
            Using cmd As New MySqlCommand("insert into ratings(behaviour)values(@Rating)")
                Using sda As New MySqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@Rating", e.Value)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

    Protected Sub admission(sender As Object, e As RatingEventArgs)
        Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
        Using con As New MySqlConnection(constr)
            Using cmd As New MySqlCommand("insert into ratings(admission)values(@Rating)")
                Using sda As New MySqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@Rating", e.Value)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

    Protected Sub behaviour(sender As Object, e As RatingEventArgs)
        Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
        Using con As New MySqlConnection(constr)
            Using cmd As New MySqlCommand("insert into ratings(behaviour)values(@Rating)")
                Using sda As New MySqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@Rating", e.Value)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub
    Protected Sub information(sender As Object, e As RatingEventArgs)
        Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
        Using con As New MySqlConnection(constr)
            Using cmd As New MySqlCommand("insert into ratings(information)values(@Rating)")
                Using sda As New MySqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@Rating", e.Value)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

    Protected Sub hygine(sender As Object, e As RatingEventArgs)
        Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
        Using con As New MySqlConnection(constr)
            Using cmd As New MySqlCommand("insert into ratings(hygine)values(@Rating)")
                Using sda As New MySqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@Rating", e.Value)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

    Protected Sub treatment(sender As Object, e As RatingEventArgs)
        Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
        Using con As New MySqlConnection(constr)
            Using cmd As New MySqlCommand("insert into ratings(treatment)values(@Rating)")
                Using sda As New MySqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@Rating", e.Value)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

登录代码vb

Private Sub hospital_details_Load(sender As Object, e As EventArgs) Handles Me.Load
        Dim var, Type As String
        If Not HttpContext.Current.Request.Cookies("chkusername") Is Nothing Then
            var = Server.HtmlEncode(Request.Cookies("chkusername").Value)
        End If

        If Not HttpContext.Current.Request.Cookies("User_Type") Is Nothing Then
            Type = Server.HtmlEncode(Request.Cookies("User_Type").Value)
        End If

        Dim LogIn, LogOut, listup As Control
        Dim BtnProfile As Button = Page.Master.FindControl("myAccount")

        LogIn = Master.FindControl("login")
        LogOut = Master.FindControl("logout")
        listup = Master.FindControl("list")

        'not login
        If HttpContext.Current.Request.Cookies("chkusername") Is Nothing Then
            listup.Visible = True
            LogIn.Visible = True
            LogOut.Visible = False
            BtnProfile.Visible = False

            'login
        Else
            LogOut.Visible = True
            BtnProfile.Visible = True
            LogIn.Visible = False
            listup.Visible = False

        End If
End Sub

更新错误 enter image description here

按钮上的更新代码单击

Private Sub sendReview_Click(sender As Object, e As EventArgs) Handles sendReview.Click
        Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
        Dim Mrating2, Mrating3, Mrating4, Mrating5, Mrating6, Mrating7 As String
        Mrating2 = Rating2.CurrentRating
        Mrating3 = Rating3.CurrentRating
        Mrating4 = Rating4.CurrentRating
        Mrating5 = Rating5.CurrentRating
        Mrating6 = Rating6.CurrentRating
        Mrating7 = Rating7.CurrentRating
        Using con As New MySqlConnection(constr)
            Using cmd As New MySqlCommand("insert into ratings(hospitalID,charges,behaviour,admission,information,hygine,treatment)values(@hospitalid,@Rating2,@Rating3,@Rating4,@Rating5,@Rating6,@Rating7)")
                Using sda As New MySqlDataAdapter()
                    cmd.CommandType = CommandType.Text
                    cmd.Parameters.AddWithValue("@hospitalID", generalID.Text)
                    cmd.Parameters.AddWithValue("@Rating2", Mrating2)
                    cmd.Parameters.AddWithValue("@Rating3", Mrating3)
                    cmd.Parameters.AddWithValue("@Rating4", Mrating4)
                    cmd.Parameters.AddWithValue("@Rating5", Mrating5)
                    cmd.Parameters.AddWithValue("@Rating6", Mrating6)
                    cmd.Parameters.AddWithValue("@Rating7", Mrating7)
                    cmd.Connection = con
                    con.Open()
                    cmd.ExecuteNonQuery()
                    con.Close()
                End Using
            End Using
        End Using
        Response.Redirect(Request.Url.AbsoluteUri)
    End Sub

1 个答案:

答案 0 :(得分:0)

尝试以下内容,

Dim constr As String = ConfigurationManager.ConnectionStrings("conio").ConnectionString
Using con As New MySqlConnection(constr)
    Using cmd As New MySqlCommand("insert into ratings(userid,hospitalid,charges,behaviour,admission,information,hygine,treatment)values(@userid,@hospitalid,@Rating1,@Rating2,@Rating3,@Rating4,@Rating5,@Rating6)")
        Using sda As New MySqlDataAdapter()
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@userid", userid)
            cmd.Parameters.AddWithValue("@hospitalid", hospitalid)
            cmd.Parameters.AddWithValue("@Rating1", Rating1.value)
            cmd.Parameters.AddWithValue("@Rating2", Rating2.value)
            cmd.Parameters.AddWithValue("@Rating3", Rating3.value)
            cmd.Parameters.AddWithValue("@Rating4", Rating4.value)
            cmd.Parameters.AddWithValue("@Rating5", Rating5.value)
            cmd.Parameters.AddWithValue("@Rating6", Rating6.value)
            cmd.Connection = con
            con.Open()
            cmd.ExecuteNonQuery()
            con.Close()
        End Using
    End Using
End Using