logo
small logo
  • Products
  • Buy
  • Support
  • Articles
  • Customer panel Support
    • en
    • pt
    • es
    • de
    • pl
    • JP
    • ZH
  • Home
  • /
  • Articles
  • /
  • How to make lottery tickets by FastReport .NET
  • How to make wedding invitations from Excel

    August 25, 2017

    Do you have a celebration on the occasion of the wedding? Do you need to

    read more
  • Want to generate tables for a user - Excel or OpenOffice Calc?

    October 8, 2020

    Tables. For centuries, they have been used to present similar data for record-keeping, counting amounts,

    read more
  • How to select the top values in a matrix

    April 22, 2021

    The article is relevant until version 2022.1. FastReport .NET has a great tool for displaying data

    read more
  • How to protect your PDF?

    November 30, 2020

    On the Data protection day, we decided to prepare an article about the PDF documents

    read more
  • Copying the Bands from One Report to Another with All the Contents

    March 31, 2021

    Sometimes there is a need to use parts of one report in another. In simple

    read more

How to make lottery tickets by FastReport .NET

August 23, 2017

Suppose you decided to hold a lottery in the office and you have only FastReport.Net at hand. It is necessary to create two sets of tickets with unique numbers. The first set for users, the second for the lottery.

We will generate unique numbers for the lottery in the report script and use them as data sources. Let's get started.

Run the report designer. Now we do not have data for the report yet. Go to the Code tab (Code).

I made the list of numbers global:

1
private List<int> num = new List<int>();

 We create a method for generating unique numbers:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
private void RandomShaffle()
 {
 const int n = 20; // A series of 20 tickets
 Random r = new Random(10); 
 int curnumber = 0;
 for(int i = 0; i < n ; i ++)
 {
 curnumber = r.Next(100000, 999999); // Generate a number in a given range
 if (!num.Contains(curnumber)) // Check the list of numbers for a match with the current one
 num.Add(curnumber); // Add to list
 else
 i--; // We roll back the iteration backward
 }
 }

 We specify the number of tickets n in the party. And also, the range in which to generate a number. I want six-digit numbers, so I specified a range from 100000 to 999999.

Now, select the Report object in the Property inspector:

 

 For it, we create a ReportStart event:

 

In the event handler, we generate a list of numbers and register it in the report as a data source.

1
2
3
4
5
 private void _StartReport(object sender, EventArgs e)
 {
 RandomShaffle();
 Report.RegisterData(num, "Numbers");
 }

 It's time to create a report template. Now the report still does not know anything about the data source that we are preparing for it. Let's run the report for execution as is. Of course, we will get an empty page. Go back to editing the page. Now we can select the data source:

 

Create a simple template with two tickets on the data band:

Run the report: 

And see the list of tickets. It remains to print them and cut them.

about product download buy
avatar
Dmitriy Fedyashov
Technical Writer
Fast Reports Team: Dmitriy Fedyashov - Technical Writer at Fast Reports
.NET FastReport Desktop

Add comment
logo
  • 800-985-8986 (English, US)
  • +4930568373928 (German)
  • +55 19 98147-8148 (Portuguese)
  • info@fast-report.com
  • 901 N Pitt Str #325 Alexandria VA 22314
  • Buy
  • Download
  • Documentation
  • Testimonials
  • How to uninstall
  • Ticket system
  • FAQ
  • Tutorial Video
  • Forum
  • Articles
  • Our News
  • Press about us
  • Resellers
  • Contact us

© 1998-2022 by Fast Reports Inc.

  • Privacy Policy