All pastes #594505 Raw Edit

Unnamed

public text v1 · immutable
#594505 ·published 2007-06-28 23:44 UTC
rendered paste body
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
File 5 : players.aspx
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////


<%@ Page Language="VB" MasterPageFile="~/default.master" AutoEventWireup="false" CodeFile="players.aspx.vb" Inherits="players" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <asp:GridView ID="gridEvent" runat="server" AutoGenerateColumns="False" DataSourceID="dataEvents" DataKeyNames="Event.player_id"
        Style="z-index: 100; left: 574px; position: absolute; top: 134px" Width="372px" CellPadding="2" ForeColor="White" GridLines="Vertical" AllowSorting="True" BackColor="#333333" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" EmptyDataText="There are currently no players entered into the tournament." Font-Size="10pt" Caption="Players Entered into Tournament">
        <Columns>
            <asp:BoundField DataField="Event.player_id" HeaderText="Event.player_id" SortExpression="Event.player_id"
                Visible="False" />
            <asp:BoundField DataField="player_name" HeaderText="Player" SortExpression="player_name" />
            <asp:BoundField DataField="seat" HeaderText="Seat" SortExpression="seat" />
            <asp:TemplateField HeaderText="Remove">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton2" runat="server" CommandName="QDelete" Style="position: static">Delete</asp:LinkButton>
                </ItemTemplate>
                <ControlStyle Font-Underline="False" ForeColor="White" />
                <ItemStyle Font-Underline="False" ForeColor="White" />
            </asp:TemplateField>
        </Columns>
        <RowStyle BackColor="#404040" ForeColor="White" HorizontalAlign="Center" VerticalAlign="Middle" />
        <AlternatingRowStyle BackColor="#333333" ForeColor="White" />
        
        
    </asp:GridView>
    <br />
    <br />
    <br />
    Click on a player's name to add them to the tournament.<br />
    <br />
    <asp:GridView ID="gridPlayers" runat="server" AutoGenerateColumns="False" DataKeyNames="player_id"
        DataSourceID="dataPlayers" Style="z-index: 101; left: 26px; position: absolute;
        top: 134px" Width="531px" CellPadding="2" ForeColor="White" GridLines="Vertical" AllowSorting="True" BackColor="#333333" BorderColor="White" BorderStyle="Solid" BorderWidth="1px" Caption="Player Database" Font-Size="10pt" HorizontalAlign="Center">
        <Columns>
            <asp:BoundField DataField="player_id" HeaderText="Player ID" InsertVisible="False"
                ReadOnly="True" SortExpression="player_id" Visible="False" />
            <asp:TemplateField HeaderText="Player" SortExpression="player_name">
                <EditItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("player_name") %>'></asp:TextBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="CopyQ"
                        Style="position: static" Text='<%# Bind("player_name") %>' Font-Underline="False" ForeColor="White"></asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="nickname" HeaderText="Nickname" SortExpression="nickname" />
            <asp:CommandField ShowEditButton="True" >
                <ItemStyle Font-Underline="False" />
                <ControlStyle Font-Underline="False" />
            </asp:CommandField>
            <asp:TemplateField HeaderText="Delete Player">
                <ItemTemplate>
                    <asp:LinkButton ID="LinkButton3" runat="server" CommandName="QDelete" Font-Underline="False"
                        ForeColor="White" Style="position: static">Delete</asp:LinkButton>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="New Player">
            <ItemTemplate>
                  <asp:LinkButton ID="lblNew" runat="server" CausesValidation="false" 
                  CommandName="Insert"
                  Text="New" style="vertical-align: top; text-align: 
                  center" Font-Bold="False" ForeColor="White" 
                  Height="0px" Width="49px"
                  OnClick="GridViewInsert" Font-Underline="False"></asp:LinkButton>
                </ItemTemplate> 
                </asp:TemplateField>
        </Columns>
        <RowStyle BackColor="#404040" Font-Underline="False" HorizontalAlign="Center" VerticalAlign="Middle" />
        <AlternatingRowStyle BackColor="#333333" />
        <EmptyDataTemplate>
            There are currently no players in the database. Please
            <asp:LinkButton ID="lblNew" runat="server" CausesValidation="false" CommandName="Insert"
                Font-Bold="False" Font-Underline="False" ForeColor="White" Height="0px" OnClick="GridViewInsert"
                Style="vertical-align: top; position: static; text-align: center" Text="add a player"
                Width="86px"></asp:LinkButton>.
        </EmptyDataTemplate>
    </asp:GridView>
    &nbsp; &nbsp;
    <br />
    <asp:Panel ID="Panel1" runat="server" Height="50px" Style="z-index: 104; left: 573px;
        position: absolute; top: 292px" Width="125px">
    <asp:Button ID="Button1" runat="server" Style="z-index: 100; left: 0px; position: absolute;
        top: 0px" Text="Assign Seats" />
    </asp:Panel>
    <br />
    <br />
    <br />
    <br />
    &nbsp;&nbsp;
    <asp:AccessDataSource ID="dataEvents" runat="server" DataFile="~/App_Data/blindsbase.mdb"
        SelectCommand="SELECT * &#13;&#10;FROM [Event], [Players]&#13;&#10;WHERE [Players].[player_id] = [Event].[player_id]&#13;&#10;" DeleteCommand="DELETE *&#13;&#10;FROM [Event]&#13;&#10;WHERE [player_id] = ?"></asp:AccessDataSource>
    <asp:AccessDataSource ID="dataPlayers" runat="server" DataFile="~/App_Data/blindsbase.mdb"
        DeleteCommand="DELETE FROM Event WHERE (player_id = ?)" InsertCommand="INSERT INTO [Players] ([player_name], [nickname]) VALUES (?, ?)"
        SelectCommand="SELECT * FROM [Players]" UpdateCommand="UPDATE [Players] SET [player_name] = ?, [nickname] = ? WHERE [player_id] = ?">
        <DeleteParameters>
            <asp:Parameter Name="player_id" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="player_name" Type="String" />
            <asp:Parameter Name="nickname" Type="String" />
            <asp:Parameter Name="player_id" Type="Int32" />
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="player_id" Type="Int32" />
            <asp:Parameter Name="player_name" Type="String" />
            <asp:Parameter Name="nickname" Type="String" />
        </InsertParameters>
    </asp:AccessDataSource>
</asp:Content>










/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
File 6 : players.aspx.vb
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////




Partial Class players
    Inherits System.Web.UI.Page

    Dim QCount As Integer
    

    Protected Sub GridViewInsert(ByVal sender As Object, ByVal e As System.EventArgs)
        dataPlayers.Insert()
    End Sub





    Protected Sub gridPlayers_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridPlayers.PreRender
        Dim index As Integer = gridPlayers.Rows.Count

        For index = 0 To (gridPlayers.Rows.Count - 2)

            gridPlayers.Rows(index).Cells(5).Controls(1).Visible = False


        Next index

    End Sub





    'Protected Sub gridEvent_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles gridEvent.PreRender
    '    Dim index As Integer = gridEvent.Rows.Count

    '    For index = 0 To (gridPlayers.Rows.Count - 2)

    '        gridPlayers.Rows(index).Cells(3).Controls(1).Visible = False


    '    Next index
    'End Sub






    Protected Sub gridPlayers_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridPlayers.RowCommand

        If e.CommandName = "CopyQ" Then

            'Get Item_ID from Row Index

            Dim QRow As GridViewRow = e.CommandSource.Parent.Parent
            Dim QIndex = QRow.RowIndex



            'Dim QRow As GridViewRow = gridPlayers.Rows(CInt(e.CommandArgument))
            Dim QPlayerID = gridPlayers.DataKeys(QIndex).Value()


            dataEvents.InsertCommand = "INSERT INTO [Event] ([player_id]) VALUES (" & QPlayerID & ")"
            dataEvents.Insert()

            gridPlayers.DataBind()


        End If


        If e.CommandName = "QDelete" Then

            Dim QRow As GridViewRow = e.CommandSource.Parent.Parent
            Dim QIndex = QRow.RowIndex

            'Dim QRow As GridViewRow = gridPlayers.Rows(CInt(e.CommandArgument))
            Dim QPlayerID = gridPlayers.DataKeys(QIndex).Value()


            dataEvents.DeleteCommand = "DELETE FROM [Event] WHERE [player_id] = " & QPlayerID
            dataEvents.Delete()
            dataEvents.DeleteCommand = "DELETE FROM [Players] WHERE [player_id] = " & QPlayerID
            dataEvents.Delete()

            gridPlayers.DataBind()
        End If
    End Sub






    Protected Sub gridEvent_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridEvent.RowCommand

        If e.CommandName = "QDelete" Then

            Dim QRow As GridViewRow = e.CommandSource.Parent.Parent
            Dim QIndex = QRow.RowIndex



            'Dim QRow As GridViewRow = gridPlayers.Rows(CInt(e.CommandArgument))
            Dim QPlayerID = gridEvent.DataKeys(QIndex).Value()
           

            dataEvents.DeleteCommand = "DELETE FROM [Event] WHERE [player_id] = " & QPlayerID
            dataEvents.Delete()

            QPlayerID = 0

            gridEvent.DataBind()



        End If

    End Sub








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

        Dim SQLStr As String = "SELECT COUNT(*) AS QC FROM [Event]"
        Dim LoginConn As New Data.OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/blindsbase.mdb"))
        Dim LoginCommand As New Data.OleDb.OleDbCommand(SQLStr, LoginConn)
        LoginConn.Open()
        Dim LoginReader As Data.OleDb.OleDbDataReader = LoginCommand.ExecuteReader()
        LoginReader.Read()

        QCount = LoginReader.Item("QC")
        MsgBox("QCount = user count = " & QCount)

        LoginReader.Close()
        LoginConn.Close()









        Dim QArray(0 To QCount - 1) 'Ordered array
        Dim QRandom As Integer
        Dim QMyArray(QCount) 'Shuffled array

        For i As Integer = 0 To (QCount - 1)

            QArray(i) = i + 1 'Populate ordered array
            MsgBox("QArray(" & i & ") = " & QArray(i))

        Next

        MsgBox("Quick check : " & QArray(0) & " " & QArray(1))


        For i As Integer = 0 To (QCount - 1)

            Randomize()
            QRandom = CInt((Rnd() * (QArray.Length - 1)))
            MsgBox("QRandom = " & QRandom)
            QMyArray(i) = QArray(QRandom)
            MsgBox("QMyArray(" & i & ") = " & QMyArray(i))
            MsgBox("QArray.Length = " & QArray.Length)
            Array.Clear(QArray, QRandom, 1)

        Next











        SQLStr = "SELECT [player_id] FROM [Event]"
        LoginConn.Open()
        Dim LoginReader2 As Data.OleDb.OleDbDataReader = LoginCommand.ExecuteReader
        LoginReader2.Read()

        

        Dim QIndex = 1
        Dim QUserID As Integer



        While LoginReader2.HasRows()
            QUserID = LoginReader2.Item("player_id")
            MsgBox("QUserID = " & QUserID)
            dataEvents.UpdateCommand = "UPDATE [Event] SET [seat] = " & QMyArray(QIndex) & " WHERE [player_id] = " & QUserID
            MsgBox("Seat = " & QMyArray(QIndex))
            dataEvents.Update()
            LoginReader2.Read()
            QIndex = QIndex + 1

        End While


        LoginReader.Close()
        LoginConn.Close()

        gridEvent.DataBind()




    End Sub

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



    Public Sub QShuffleArray()


    

    End Sub
End Class