Exemple #1
0
        private void buttonSelecionar_Click(object sender, EventArgs e)
        {
            if (numericUpDown1.Value == 0)
            {
                return;
            }

            //lista de bilhetes livres para seleção
            List <UserControlBilhete> numBilhetes = new List <UserControlBilhete>();

            //preencher a lista de bilhestes livres
            foreach (Control item in flowLayoutPanel1.Controls)
            {
                UserControlBilhete b = (UserControlBilhete)item;
                if (b.Botao.Enabled && b.Botao.BackColor != Color.GreenYellow)
                {
                    numBilhetes.Add(b);
                }
            }

            if (numBilhetes.Count < (int)numericUpDown1.Value)
            {
                if (numBilhetes.Count == 0)
                {
                    FormMessage.ShowMessegeWarning("Todos os bilhetes já foram vendidos!");
                }
                else
                {
                    if (FormMessage.ShowMessegeQuestion("Há somente " + numBilhetes.Count + " bilhetes para serem vendidos, deseja selecionar todos?") == DialogResult.Yes)
                    {
                        foreach (var item in numBilhetes)
                        {
                            Button b = item.Botao;
                            BotaoSelcionado(b);
                        }
                    }
                }

                return;
            }

            //lista dos numeros aleatórios
            List <int> numA = Aleatorio.Gerar(numBilhetes.Count, (int)numericUpDown1.Value);

            //seleciona da lista com bilhetes sorteado
            foreach (var item in numA)
            {
                Button b = numBilhetes[item].Botao;
                BotaoSelcionado(b);
            }
            numericUpDown1.Value = 0;


            ContarVerde();
        }
Exemple #2
0
        private void buttonSortear_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            flowLayoutPanelBilhete.Controls.Clear();
            NumSorteio(infoSort.sorteiobilhetequant, true);

            //gera uma lista de numeros sorteados baseado na quantidade de prêmios
            List <int> num = Aleatorio.Gerar(colBilhete.Count + 1, colItens.Sum(i => i.Quant));

            //gera uma lista de número não repetido baseado na quantidade produto
            List <int>         num2  = Aleatorio.Gerar(colItens.Sum(i => i.Quant) + 1, colItens.Sum(i => i.Quant));
            List <ProdutoInfo> lProd = new List <ProdutoInfo>();

            //adiciona os prêmios retidas vezes baseado na quantidade do mesmo
            foreach (var item in colItens)
            {
                for (int i = 0; i < item.Quant; i++)
                {
                    lProd.Add(item.Prod);
                }
            }

            int cont = 0;

            colSorteado = new SorteadoColecao();
            for (int i = 0; i < num.Count; i++)
            {
                UserControlBilhete b = (UserControlBilhete)flowLayoutPanelBilhete.Controls[num[i] - 1];

                SorteadoInfo s = new SorteadoInfo
                {
                    Prod    = lProd[num2[cont++] - 1], //seleciona o prêmio de forma aleatória e vincula a um sorteado
                    Bilhete = colBilhete.Where(w => w.bilhetenum == colBilhete[num[i] - 1].bilhetenum).FirstOrDefault(),
                };

                colSorteado.Add(s);
                b.Sorteado(s);
                b.Botao.BackColor = Color.Blue;
                b.Botao.ForeColor = Color.Blue;
            }

            SalvarTxt();
            this.Cursor = Cursors.Default;
        }