Click here to Skip to main content
15,901,949 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hello everyone,

I am developing a web project in C #. I have a number consists of 6 digits. is like a lottery. my problem is how to present these numbers to the end user. I'm thinking of getting a form to submit as if the numbers were being generated at the time randomly. or having to go to one of the numbers. but I have not the slightest idea of how to do this and what tool to use to help me in this process. already heard of jquery that allows us many graphic illustrations beautiful, but do not know where from. the base is to get this number I have saved in my DB and present the best possible for the end user ..
Posted
Updated 14-Oct-13 0:40am
v2
Comments
Andreas Gieriet 14-Oct-13 6:55am    
Why graphics? Is this a requirement? Fill 6 text boxes with a number to start with. If this is not a nice enough presentation, you can improve later. First you need the round-trip implemented: request new number - get new number - show new number.
Cheers
Andi
Ankur\m/ 14-Oct-13 7:42am    
[copied from direct comment]
Dude, I'm working to show the end user something quite enjoyable. I do not just want to show the numbers in some textbox. I want to present the numbers in a different way, something illustrative purposes. an example is like some random numbers generator to run the numbers showing on the screen and then stop the winning number. but in my case I would use the value of my 6 digits stored in the database for display after the end. wanted something, or something different.
fasher_the_one - 13 mins ago
Andreas Gieriet 14-Oct-13 10:00am    
Oops, wrong place ;-)
I've removed the reply and posted it now to the other place since otherwise you get involved without cause... ;-)
Sorry for the confusion.
Cheers
Andi
Ankur\m/ 15-Oct-13 6:01am    
I didn't delete the original comment so that you can continue the discussion there. So thank you for moving it. :)
Cheers!
fasher_the_one 14-Oct-13 7:25am    
Dude,
I'm working to show the end user something quite enjoyable. I do not just want to show the numbers in some textbox. I want to present the numbers in a different way, something illustrative purposes. an example is like some random numbers generator to run the numbers showing on the screen and then stop the winning number. but in my case I would use the value of my 6 digits stored in the database for display after the end. wanted something, or something different.

you can use jquery timer for this kind of functionality.

When user click on the start button, using jquery methods like slideDown, slideUp and timer change all the 6 digits from zero to nine (like we see in Casinos) and till that time using asynchronous call you can retrieve number from database and split it into array.

Now when user click on the stop button,
increase the timer interval of first digit so that first digit starts moving very slowly and keep moving till the first digit does not match the first item of the array.

whenever it matches the first item of the array. stop the timer and show first digit and go to the second digit and do the same process upto 6 digist.

See Below Sample Application :

1. Add aspx page : Lotary.aspx
2. Add Generic handler : DigitHandler.ashx

1. Lotary.aspx :

XML
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Lotary.aspx.cs" Inherits="TestApplication.Lotary" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <style type="text/css">
        .DigitContainer {
            border: 1px solid blueviolet;
            padding: 3px;
        }
    </style>
    <script type="text/javascript" src="Scripts/jquery-1.8.2.js"></script>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager runat="server" EnablePageMethods="True"></asp:ScriptManager>
        <div style="float: left">
            <div style="float: left" >
                <div id="digit1" class="DigitContainer">0</div>
            </div>
            <div style="float: left">
                <div id="digit2" class="DigitContainer">0</div>
            </div>
            <div style="float: left">
                <div id="digit3" class="DigitContainer">0</div>
            </div>
            <div style="float: left">
                <div id="digit4" class="DigitContainer">0</div>
            </div>
            <div style="float: left">
                <div id="digit5" class="DigitContainer">0</div>
            </div>
            <div style="float: left">
                <div id="digit6" class="DigitContainer">0</div>
            </div>
        </div>
        <br/><br/>
        <asp:Button runat="server" ID="buttonStart" Text="Start" OnClientClick="return StartRolling();" />
        <asp:Button runat="server" ID="button1" Text="Stop" OnClientClick="return StopRolling();" />
    </form>
</body>

<script type="text/javascript" language="javascript">
    var myDigits = new Array();
    var isStop = false;
    function StartRolling() {
        isStop = false;
        for (var i = 1; i <= 6; i++) {
            StartDigitRolling('digit' + i, i);
        }
        return false;
    }

    function StartDigitRolling(digitId, digitIndex) {
        var time = Math.floor(Math.random() * 150) + 100;
        myDigits[digitIndex] = setInterval(function () {


            setTimeout(function() {
                if (!isStop) {
                    var number = parseInt(document.getElementById(digitId).innerText);
                    if (number == 9) {
                        number = -1;
                    }
                    document.getElementById(digitId).innerText = number + 1;
                }
            }, 50);

        }, time);
    }

    function StopRolling() {
        var numbers;
        isStop = true;
        $.ajax({
            url: 'DigitHandler.ashx',
            async: true,
            cache: false,
            data: {},
            success: function (response) {

                if (response != null) {
                    numbers = response.split('');
                    isSuccess = true;

                    for (var i = 1; i < 100; i++)
                        window.clearInterval(i);

                    var counter = 1;
                    do {
                        document.getElementById('digit' + counter).innerText = numbers[counter - 1];
                        counter++;
                    } while (counter != 7)
                }
            },
        });

        return false;
    }
</script>
</html>


2. DigitHandler.ashx.cs

C#
using System.Web;

namespace TestApplication
{
    /// <summary>
    /// Summary description for DigitHandler
    /// </summary>
    public class DigitHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("123456");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}



Note : In ProcessRequest of handler, retrieve random number from database and insetead of 123456 put retrieved random number.

Regards,
CodeBlack
 
Share this answer
 
v2
Comments
fasher_the_one 15-Oct-13 6:40am    
CodeBlack,

this is a great idea for what I need. the only problem is that I have no idea where to start. the idea of the casino is good for my need. I keep my number of 6 digits in a vector, but I need to know how to begin to solve this problem. I appreciate your idea, but it would be too much to ask a help where to start? I I thank
CodeBlack 15-Oct-13 10:00am    
don't forget to mark this solution as an answer so that other user who are facing the same issue can easily find the solution.
fasher_the_one 15-Oct-13 10:01am    
dude,

I will test the sample and calmly fit my needs. but right now I thank you for your help. appear if any doubt can put it without problems.
i'll rate the solution :)
fasher_the_one 16-Oct-13 9:04am    
Dude,

this example is helping me a lot . but other things I'm implementing it and found a difficulty that I still do not know how to solve . this is the case : this HttpHandler class I want to show some data in a gridview . if the codebehind , I know implement the code to retrieve data from the DB using StoredProcedure and present them in gridview . but as I'm working in ashx file , I do not know how to bind the gird .

I have a simple function that is responsible for displaying data in grid .
private void MostrarVenc (string refurb )
        {
            SqlDataAdapter da = new SqlDataAdapter ( " Winner " , CS_Sorteio ) ;
            da.SelectCommand.CommandType = CommandType.StoredProcedure ;
            da.SelectCommand.Parameters.AddWithValue ( " @ nro_cupao " refurb ) ;

            DataSet ds = new DataSet ( ) ;
            da.Fill ( ds ) ;
            GridViewVencedor.DataSource = ds ;
            GridViewVencedor.DataBind ();
        }

how can I modify so that it can function properly
CodeBlack 16-Oct-13 9:35am    
you can simply bind grid in your aspx.cs page.
Try something like the below link which uses Jquery plugin for the number animation effects.

http://stackoverflow.com/questions/2540277/jquery-counter-to-count-up-to-a-target-number[^]

http://jsfiddle.net/YWn9t/[^]

You can start with this and may be have the code tweaked as per your needs or else you have many more such plugins available

Hope this helps
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900