Esempio n. 1
0
        /// <summary>
        ///     Manipula todos os eventos do form
        /// </summary>
        private void Eventos()
        {
            Shown += (s, e) =>
            {
                KeyDown   += KeyDowns;
                KeyPreview = true;

                if (IdProduto > 0)
                {
                    _mItem = _mItem.FindById(IdProduto).FirstOrDefault <Item>();
                }
                else
                {
                    return;
                }

                Combos.DataSource    = _mItemCombo.GetCombos(_mItem.Combos);
                Combos.DisplayMember = "Nome";
                Combos.ValueMember   = "Id";

                SetHeadersTableItens(GridListaItens);
                SetHeadersTableItensCategoria(GridListaSelectItens);
            };

            btnCombo.Click += (s, e) =>
            {
                if (Combos.SelectedValue.ToString() == "0")
                {
                    Alert.Message("Opps", "Selecione um combo válido.", Alert.AlertType.error);
                    return;
                }

                listProdutos.Clear();
                listProdutosSelecionados.Clear();
                GridListaItens.Rows.Clear();
                GridListaSelectItens.Rows.Clear();
                SepareIds();
                LoadDataTableItens();
            };

            btnInserir.Click += (s, e) =>
            {
                if (GridListaItens.Rows.Count < 0)
                {
                    return;
                }

                var count = GridListaItens.Rows.Cast <DataGridViewRow>().Count(row => (bool)row.Cells["Incluir"].Value) - 1;

                listProdutosIncluir.Clear();
                foreach (DataGridViewRow row in GridListaItens.Rows)
                {
                    if (!(bool)row.Cells["Incluir"].Value)
                    {
                        continue;
                    }

                    var idItem   = Validation.ConvertToInt32(row.Cells["ID"].Value.ToString());
                    var dataItem = _mItem.FindById(idItem).FirstOrDefault <Item>();

                    var valorVenda = dataItem.ValorVenda - 1.00;

                    var pedidoItem = new PedidoItem();
                    pedidoItem.SetId(0)
                    .SetTipo(dataItem.Tipo)
                    .SetPedidoId(IdPedido)
                    .SetItem(dataItem)
                    .SetQuantidade(1)
                    .SetMedida(dataItem.Medida);
                    pedidoItem.Adicional = row.Cells["AddonSelected"].Value.ToString();

                    if (IdProduto == dataItem.Id)
                    {
                        var valorCombo = Validation.ConvertToDouble(txtComboValor.Text.Replace("Valor do Combo: R$ ", ""));

                        pedidoItem.ValorVenda = valorCombo - count;
                        pedidoItem.Total      = valorCombo - count;
                        pedidoItem.TotalVenda = valorCombo - count;
                    }
                    else
                    {
                        pedidoItem.ValorVenda = dataItem.ValorVenda - valorVenda;
                        pedidoItem.Total      = dataItem.ValorVenda - valorVenda;
                        pedidoItem.TotalVenda = dataItem.ValorVenda - valorVenda;
                    }

                    switch (Home.pedidoPage)
                    {
                    case "Remessas":
                        pedidoItem.Status = "Remessa";
                        break;

                    case "Delivery":
                    case "Balcao":
                        pedidoItem.Status = "FAZENDO";
                        break;
                    }

                    pedidoItem.Save(pedidoItem);

                    listProdutosIncluir.Add(pedidoItem);

                    new Controller.Estoque(pedidoItem.GetLastId(), Home.pedidoPage, "Adicionar Produto").Remove().Item();
                }

                DialogResult = DialogResult.OK;
                Close();
            };

            btnContinuar.Click += (s, e) =>
            {
                DialogResult = DialogResult.Ignore;
                Close();
            };

            GridListaSelectItens.CellClick += (s, e) =>
            {
                if (GridListaSelectItens.Columns[e.ColumnIndex].Name == "Incluir")
                {
                    GridListaItens.Rows.Add(
                        true,
                        GridListaSelectItens.SelectedRows[0].Cells["Photo"].Value,
                        GridListaSelectItens.SelectedRows[0].Cells["ID"].Value,
                        GridListaSelectItens.SelectedRows[0].Cells["Item"].Value,
                        GridListaSelectItens.SelectedRows[0].Cells["Valor"].Value,
                        $"{Validation.FormatPrice(0, true)}",
                        GridListaSelectItens.SelectedRows[0].Cells["Estoque Atual"].Value,
                        "",
                        GridListaSelectItens.SelectedRows[0].Cells["Valor"].Value,
                        Resources.menu20x
                        );

                    GridListaSelectItens.Rows.Clear();
                    LoadDataTableItens();

                    Alert.Message("Pronto", "Item adicionado.", Alert.AlertType.success);
                }
            };

            GridListaSelectItens.CellMouseEnter += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridListaSelectItens.Columns[e.ColumnIndex].Name == "Incluir")
                {
                    dataGridView.Cursor = Cursors.Hand;
                }
            };

            GridListaSelectItens.CellMouseLeave += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridListaSelectItens.Columns[e.ColumnIndex].Name == "Incluir")
                {
                    dataGridView.Cursor = Cursors.Default;
                }
            };

            GridListaItens.CellClick += (s, e) =>
            {
                if (GridListaItens.Columns[e.ColumnIndex].Name == "Incluir")
                {
                    GridListaItens.SelectedRows[0].Cells["Incluir"].Value = (bool)GridListaItens.SelectedRows[0].Cells["Incluir"].Value == false;
                }

                if (GridListaItens.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    AdicionaisDispon.ValorAddon    = 0;
                    AdicionaisDispon.AddonSelected = GridListaItens.SelectedRows[0].Cells["AddonSelected"].Value != null
                        ? GridListaItens.SelectedRows[0].Cells["AddonSelected"].Value.ToString()
                        : "";
                    AdicionaisDispon.IdPedidoItem = 0;
                    AdicionaisDispon.IdItem       = Validation.ConvertToInt32(GridListaItens.SelectedRows[0].Cells["ID"].Value);
                    var form = new AdicionaisDispon {
                        TopMost = true
                    };
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        var getValor = Validation.ConvertToDouble(GridListaItens.SelectedRows[0].Cells["Unitario"].Value
                                                                  .ToString().Replace("R$ ", ""));
                        GridListaItens.SelectedRows[0].Cells["Valor Adicional"].Value = Validation.FormatPrice(AdicionaisDispon.ValorAddon, true);
                        GridListaItens.SelectedRows[0].Cells["AddonSelected"].Value   = AdicionaisDispon.AddonSelected;

                        txtComboValor.Text = $"Valor do Combo: {Validation.FormatPrice(ValorCombo + AdicionaisDispon.ValorAddon, true)}";
                    }
                }
            };

            GridListaItens.CellMouseEnter += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridListaItens.Columns[e.ColumnIndex].Name == "Incluir" ||
                    GridListaItens.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    dataGridView.Cursor = Cursors.Hand;
                }
            };

            GridListaItens.CellMouseLeave += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridListaItens.Columns[e.ColumnIndex].Name == "Incluir" ||
                    GridListaItens.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    dataGridView.Cursor = Cursors.Default;
                }
            };
        }
Esempio n. 2
0
        private void Eventos()
        {
            KeyDown   += KeyDowns;
            KeyPreview = true;
            Masks.SetToUpper(this);

            Load += (s, e) =>
            {
                Categorias.DataSource    = new Categoria().GetAll("Produtos");
                Categorias.DisplayMember = "Nome";
                Categorias.ValueMember   = "Id";
            };

            Shown += (s, e) =>
            {
                // Autocomplete de produtos
                collection = _mItem.AutoComplete("Produtos");
                BuscarProduto.AutoCompleteCustomSource = collection;

                SetHeadersTable(GridLista);
                SetHeadersTableProdutos(GridProdutos);

                if (IniFile.Read("MesasPreCadastrada", "Comercial") == "True")
                {
                    nrMesa.Visible = false;
                    Mesas.Visible  = true;

                    var listMesas = new ArrayList {
                        new { Id = "0", Nome = "SELECIONE" }
                    };
                    var getMesas = new Model.Mesas().FindAll().WhereFalse("excluir").Get <Model.Mesas>();
                    if (getMesas.Any())
                    {
                        foreach (var mesas in getMesas)
                        {
                            listMesas.Add(new { Id = $"{mesas.Id}", Nome = $"{mesas.Mesa}" });
                        }
                    }

                    Mesas.DataSource    = listMesas;
                    Mesas.DisplayMember = "Nome";
                    Mesas.ValueMember   = "Id";
                }
            };

            BuscarProduto.KeyDown += (s, e) =>
            {
                if (e.KeyCode != Keys.Enter)
                {
                    return;
                }

                var item = _mItem.FindById(collection.Lookup(BuscarProduto.Text)).FirstOrDefault <Item>();
                if (item == null)
                {
                    return;
                }

                if (!string.IsNullOrEmpty(item.Combos))
                {
                    var comboExits = false;
                    var idsCombo   = item.Combos.Split(',');
                    foreach (var id in idsCombo)
                    {
                        var checkCombo = new Model.ItemCombo().FindById(Validation.ConvertToInt32(id)).WhereFalse("excluir").FirstOrDefault <ItemCombo>();
                        if (checkCombo != null)
                        {
                            comboExits = true;
                        }
                    }

                    if (comboExits)
                    {
                        AddCombo.IdProduto = item.Id;
                        AddCombo.IdPedido  = 0;
                        var form = new AddCombo {
                            TopMost = true
                        };
                        if (form.ShowDialog() == DialogResult.OK)
                        {
                            foreach (PedidoItem data in AddCombo.listProdutosIncluir)
                            {
                                GridLista.Rows.Add(
                                    false,
                                    data.Item,
                                    data.xProd,
                                    Validation.FormatPrice(Validation.ConvertToDouble(data.ValorVenda)),
                                    "",
                                    data.Adicional,
                                    Validation.ConvertToDouble(data.ValorVenda),
                                    Resources.menu20x
                                    );
                            }

                            txtValorTotal.Text = $@"Valor Total: {Validation.FormatPrice(SumTotalGrid(), true)}";
                            BuscarProduto.Text = "";
                            BuscarProduto.Select();
                            return;
                        }
                    }
                }

                GridLista.Rows.Add(
                    false,
                    item.Id,
                    item.Nome,
                    Validation.FormatPrice(Validation.ConvertToDouble(item.ValorVenda)),
                    "",
                    "",
                    Validation.ConvertToDouble(item.ValorVenda),
                    Resources.menu20x
                    );

                txtValorTotal.Text = $@"Valor Total: {Validation.FormatPrice(SumTotalGrid(), true)}";
                BuscarProduto.Text = "";
                BuscarProduto.Select();
            };

            btnFiltrar.Click += (s, e) => LoadProdutos();
            btnEnviar.Click  += (s, e) => ActionEnviar();

            GridProdutos.CellClick += (s, e) =>
            {
                if (GridProdutos.Columns[e.ColumnIndex].Name == "Adicionar")
                {
                    var idItem = Validation.ConvertToInt32(GridProdutos.SelectedRows[0].Cells["ID"].Value);
                    var item   = _mItem.FindById(idItem).FirstOrDefault <Item>();
                    if (item == null)
                    {
                        return;
                    }

                    if (!string.IsNullOrEmpty(item.Combos))
                    {
                        var comboExits = false;
                        var idsCombo   = item.Combos.Split(',');
                        foreach (var id in idsCombo)
                        {
                            var checkCombo = new Model.ItemCombo().FindById(Validation.ConvertToInt32(id)).WhereFalse("excluir").FirstOrDefault <ItemCombo>();
                            if (checkCombo != null)
                            {
                                comboExits = true;
                            }
                        }

                        if (comboExits)
                        {
                            AddCombo.IdProduto = item.Id;
                            AddCombo.IdPedido  = 0;
                            var form = new AddCombo {
                                TopMost = true
                            };
                            if (form.ShowDialog() == DialogResult.OK)
                            {
                                foreach (PedidoItem data in AddCombo.listProdutosIncluir)
                                {
                                    GridLista.Rows.Add(
                                        false,
                                        data.Item,
                                        data.xProd,
                                        Validation.FormatPrice(Validation.ConvertToDouble(data.ValorVenda)),
                                        "",
                                        data.Adicional,
                                        Validation.ConvertToDouble(data.ValorVenda),
                                        Resources.menu20x
                                        );
                                }

                                BuscarProduto.Text = "";
                                BuscarProduto.Select();
                                Alert.Message("Pronto", "Item adicionado.", Alert.AlertType.success);
                                return;
                            }
                        }
                    }

                    GridLista.Rows.Add(
                        false,
                        GridProdutos.SelectedRows[0].Cells["ID"].Value,
                        GridProdutos.SelectedRows[0].Cells["Item"].Value,
                        GridProdutos.SelectedRows[0].Cells["Valor"].Value,
                        "",
                        "",
                        GridProdutos.SelectedRows[0].Cells["Valor"].Value,
                        Resources.menu20x
                        );

                    txtValorTotal.Text = $@"Valor Total: {Validation.FormatPrice(SumTotalGrid(), true)}";
                    Alert.Message("Pronto", "Item adicionado.", Alert.AlertType.success);
                }
            };

            GridProdutos.CellMouseEnter += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridProdutos.Columns[e.ColumnIndex].Name == "Adicionar")
                {
                    dataGridView.Cursor = Cursors.Hand;
                }
            };

            GridProdutos.CellMouseLeave += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridProdutos.Columns[e.ColumnIndex].Name == "Adicionar")
                {
                    dataGridView.Cursor = Cursors.Default;
                }
            };

            btnRemover.Click += (s, e) =>
            {
                var toBeDeleted = new List <DataGridViewRow>();
                toBeDeleted.Clear();

                var result = AlertOptions.Message("Atenção!",
                                                  "Você está prestes a deletar os PRODUTOS selecionados, continuar?", AlertBig.AlertType.warning,
                                                  AlertBig.AlertBtn.YesNo);
                if (result)
                {
                    foreach (DataGridViewRow item in GridLista.Rows)
                    {
                        Console.WriteLine(item.Cells["Selecione"].Value);
                        if ((bool)item.Cells["Selecione"].Value)
                        {
                            toBeDeleted.Add(item);
                        }
                    }

                    toBeDeleted.ForEach(d => GridLista.Rows.Remove(d));
                }

                txtValorTotal.Text = $@"Valor Total: {Validation.FormatPrice(SumTotalGrid(), true)}";
                btnRemover.Visible = false;
            };

            GridLista.CellClick += (s, e) =>
            {
                if (GridLista.Columns[e.ColumnIndex].Name == "Selecione")
                {
                    if ((bool)GridLista.SelectedRows[0].Cells["Selecione"].Value == false)
                    {
                        GridLista.SelectedRows[0].Cells["Selecione"].Value = true;
                        btnRemover.Visible = true;
                    }
                    else
                    {
                        GridLista.SelectedRows[0].Cells["Selecione"].Value = false;

                        var hideBtns = false;
                        foreach (DataGridViewRow item in GridLista.Rows)
                        {
                            if ((bool)item.Cells["Selecione"].Value)
                            {
                                hideBtns = true;
                            }
                        }

                        btnRemover.Visible = hideBtns;
                    }
                }

                if (GridLista.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    AdicionaisDispon.ValorAddon    = 0;
                    AdicionaisDispon.AddonSelected = GridLista.SelectedRows[0].Cells["AddonSelected"].Value != null
                        ? GridLista.SelectedRows[0].Cells["AddonSelected"].Value.ToString()
                        : "";
                    AdicionaisDispon.IdPedidoItem = 0;
                    AdicionaisDispon.IdItem       = Validation.ConvertToInt32(GridLista.SelectedRows[0].Cells["ID"].Value);
                    var form = new AdicionaisDispon();
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        var getValor = Validation.ConvertToDouble(GridLista.SelectedRows[0].Cells["Unitario"].Value
                                                                  .ToString().Replace("R$ ", ""));
                        GridLista.SelectedRows[0].Cells["Valor"].Value         = Validation.FormatPrice(getValor + AdicionaisDispon.ValorAddon);
                        GridLista.SelectedRows[0].Cells["AddonSelected"].Value = AdicionaisDispon.AddonSelected;
                    }
                }
            };

            GridLista.CellMouseEnter += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridLista.Columns[e.ColumnIndex].Name == "Selecione" ||
                    GridLista.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    dataGridView.Cursor = Cursors.Hand;
                }
            };

            GridLista.CellMouseLeave += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridLista.Columns[e.ColumnIndex].Name == "Selecione" ||
                    GridLista.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    dataGridView.Cursor = Cursors.Default;
                }
            };
        }