Exemplo n.º 1
0
 private void ItemAdd(SorteioItemInfo a, Cnx cnz)
 {
     if (a != null)
     {
         cnz.AddMySqlParameterCollection("@id", a.ID);
         cnz.AddMySqlParameterCollection("@prod", a.Prod.produtoid);
         cnz.AddMySqlParameterCollection("@sort", a.Sort.sorteioid);
         cnz.AddMySqlParameterCollection("@quant", a.Quant);
     }
 }
Exemplo n.º 2
0
        private void ContarItens()
        {
            flowLayoutPanelProd.Controls.Clear();
            SorteioItemInfo i = new SorteioItemInfo {
                Sort = infoSort, Prod = new ProdutoInfo()
            };

            if (Form1.Online)
            {
                colItem = (SorteioItemColecao)negSort.ExecutarSorteioItem(enumCRUD.select, i);
            }
            else
            {
                colItem = Form1.colI;
            }

            if (colItem != null)
            {
                foreach (var item in colItem)
                {
                    UserControlProd prod = new UserControlProd(true)
                    {
                        Produto = item.Prod,
                        Quant   = item.Quant
                    };

                    flowLayoutPanelProd.Controls.Add(prod);
                }
            }

            int     totalQuant     = 0;
            decimal totalValorProd = 0;

            foreach (var item in flowLayoutPanelProd.Controls)
            {
                UserControlProd prod = (UserControlProd)item;

                totalQuant     += prod.Quant;
                totalValorProd += (prod.Produto.produtovalor * prod.Quant);
            }

            labelTotalQuant.Text        = "Total de Prêmios: " + string.Format("{0:000}", totalQuant);
            labelTotalValorProd.Text    = "Valor Total de Prêmios: " + string.Format("{0:C2}", totalValorProd);
            labelTotalValorBilhete.Text = "Valor Total de Bilhetes: " + string.Format("{0:C2}", infoSort != null ? infoSort.sorteiobilhetequant * infoSort.sorteiobilhetevalor : 0);

            ListaBilhete();
        }
Exemplo n.º 3
0
        private SorteioItemColecao PreencherSorteioItemColecao(DataTable dataTable)
        {
            var colecao = new SorteioItemColecao();

            foreach (DataRow row in dataTable.Rows)
            {
                var sort = new SorteioItemInfo
                {
                    ID    = Convert.ToInt32(row["itemid"]),
                    Prod  = PreencherProdutoInfo(row),
                    Sort  = PreencherSorteioInfo(row),
                    Quant = Convert.ToInt32(row["itemprodquant"]),
                };

                colecao.Add(sort);
            }

            return(colecao);
        }
Exemplo n.º 4
0
        private void ExProd(List <UserControlProd> l, enumCRUD e)
        {
            if (l.Count > 0)
            {
                foreach (var item in l)
                {
                    UserControlProd uProd = item;
                    SorteioItemInfo it    = new SorteioItemInfo
                    {
                        Prod  = uProd.Produto,
                        Quant = uProd.Quant,
                        Sort  = infoSort
                    };

                    negSort.ExecutarSorteioItem(e, it);
                }

                l.Clear();
            }
        }
Exemplo n.º 5
0
        public object ExecutarSorteioItem(enumCRUD en, SorteioItemInfo item = null)
        {
            if (cnx.Conectar())
            {
                ItemAdd(item, cnx);

                switch (en)
                {
                case enumCRUD.select:

                    DataTable dataTable = (DataTable)cnx.ExecutarComandoMySql("spConsultarItemIdSorteio", enumExecutar.DataTable);
                    if (dataTable != null)
                    {
                        return(PreencherSorteioItemColecao(dataTable));
                    }
                    else
                    {
                        return(null);
                    }

                case enumCRUD.insert:
                    return(Convert.ToInt32(cnx.ExecutarComandoMySql("spInsertSorteioItem", enumExecutar.Scalar)));

                case enumCRUD.update:
                    return(Convert.ToInt32(cnx.ExecutarComandoMySql("spUpdateSorteioItem", enumExecutar.Scalar)));

                case enumCRUD.delete:
                    return(Convert.ToInt32(cnx.ExecutarComandoMySql("spDeleteSorteioItem", enumExecutar.Scalar)));

                default:
                    return(0);
                }
            }
            else
            {
                return(0);
            }
        }
Exemplo n.º 6
0
        private void Salvar()
        {
            this.Cursor = Cursors.WaitCursor;
            if (string.IsNullOrEmpty(textBoxDescricaoSort.Text))
            {
                MessageBox.Show("Defina uma descrição para o sorteio!");
                textBoxDescricaoSort.Select();
                return;
            }

            int id;

            negSort = new SorteioNegocio();

            if (infoSort == null)
            {
                infoSort = new SorteioInfo
                {
                    sorteiodata         = dateTimePicker1.Value,
                    sorteiodescricao    = textBoxDescricaoSort.Text,
                    sorteiobilhetequant = Convert.ToInt32(numericUpDown1.Value),
                    sorteiobilhetevalor = Convert.ToDecimal(textBoxValor.Text)
                };

                id = (int)negSort.ExecutarSorteio(enumCRUD.insert, infoSort);

                if (id > 0)
                {
                    infoSort.sorteioid = id;
                    if (flowLayoutPanelProd.Controls.Count > 0)
                    {
                        foreach (Control item in flowLayoutPanelProd.Controls)
                        {
                            UserControlProd uProd = (UserControlProd)item;
                            SorteioItemInfo it    = new SorteioItemInfo
                            {
                                Prod  = uProd.Produto,
                                Quant = uProd.Quant,
                                Sort  = infoSort
                            };
                            negSort.ExecutarSorteioItem(enumCRUD.insert, it);
                        }

                        FormMessage.ShowMessageSave();

                        if (this.Modal)
                        {
                            this.DialogResult = DialogResult.Yes;
                        }
                        else
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Nenhum produto foi lançado!");
                    }
                }
                else
                {
                    FormMessage.ShowMessageFalha();
                }
            }
            else
            {
                id = infoSort.sorteioid;

                infoSort = new SorteioInfo
                {
                    sorteiodata         = dateTimePicker1.Value,
                    sorteiodescricao    = textBoxDescricaoSort.Text,
                    sorteiobilhetequant = Convert.ToInt32(numericUpDown1.Value),
                    sorteiobilhetevalor = Convert.ToDecimal(textBoxValor.Text),
                    sorteioid           = id
                };

                negSort.ExecutarSorteio(enumCRUD.update, infoSort);

                ExProd(listProdRem, enumCRUD.delete);
                ExProd(listProdAdd, enumCRUD.insert);
                ExProd(listProdAlt, enumCRUD.update);


                this.Cursor = Cursors.Default;
                FormMessage.ShowMessageSave();
            }
        }
Exemplo n.º 7
0
        private void buttonSort_Click(object sender, EventArgs e)
        {
            negSort = new SorteioNegocio();
            SorteioColecao colSort = (SorteioColecao)negSort.ExecutarSorteio(enumCRUD.select);

            if (colSort != null)
            {
                var colecao = new Form_ConsultarColecao();
                foreach (var item in colSort)
                {
                    Form_Consultar form = new Form_Consultar
                    {
                        Cod       = string.Format("{0:00000}", item.sorteioid),
                        Descricao = item.sorteiodescricao,
                        Objeto    = item,
                    };

                    colecao.Add(form);
                }

                using (FormConsultar_Cod_Descricao consult = new FormConsultar_Cod_Descricao(colecao, "SORTEIO"))
                {
                    if (consult.ShowDialog(this) == DialogResult.Yes)
                    {
                        this.Cursor = Cursors.WaitCursor;
                        infoSort    = (SorteioInfo)consult.Selecionado.Objeto;
                        textBoxDescricaoSort.Text = consult.Selecionado.Descricao;
                        dateTimePicker1.Value     = infoSort.sorteiodata;
                        numericUpDown1.Value      = infoSort.sorteiobilhetequant;
                        textBoxValor.Text         = Convert.ToString(infoSort.sorteiobilhetevalor);

                        flowLayoutPanelProd.Controls.Clear();
                        SorteioItemInfo i = new SorteioItemInfo {
                            Sort = infoSort, Prod = new ProdutoInfo()
                        };
                        SorteioItemColecao colItem = (SorteioItemColecao)negSort.ExecutarSorteioItem(enumCRUD.select, i);

                        if (colItem != null)
                        {
                            foreach (var item in colItem)
                            {
                                UserControlProd prod = new UserControlProd
                                {
                                    Produto = item.Prod,
                                    Quant   = item.Quant
                                };

                                flowLayoutPanelProd.Controls.Add(prod);
                            }

                            ContarItens();
                        }


                        PreencherTree();
                        buttonSalvar.Enabled  = true;
                        buttonRemover.Enabled = true;
                        this.Cursor           = Cursors.Default;
                    }
                }
            }
        }