Example #1
0
        private void AddCompra()
        {
            _mPedido.Id            = 0;
            _mPedido.Tipo          = "Compras";
            _mPedido.Emissao       = DateTime.Parse(Emissao.Text);
            _mPedido.Chavedeacesso = Id.Text;
            _mPedido.Cliente       = idFornecedor;
            _mPedido.Colaborador   = Settings.Default.user_id;
            //_mPedido.status = 1;
            if (!_mPedido.Save(_mPedido))
            {
                return;
            }

            foreach (dynamic item in produtosID)
            {
                _mPedidoItem.Id          = 0;
                _mPedidoItem.Tipo        = "Produtos";
                _mPedidoItem.Pedido      = _mPedido.GetLastId();
                _mPedidoItem.CProd       = item.Referencia;
                _mPedidoItem.CEan        = item.CodeBarras;
                _mPedidoItem.xProd       = item.Nome;
                _mPedidoItem.Ncm         = item.NCM;
                _mPedidoItem.Item        = item.Id;
                _mPedidoItem.ValorCompra = 0;
                _mPedidoItem.ValorVenda  = item.ValorCompra;
                _mPedidoItem.Medida      = item.Medida;
                _mPedidoItem.Quantidade  = item.EstoqueCompra;
                _mPedidoItem.Total       = item.EstoqueCompra * item.ValorCompra;
                _mPedidoItem.TotalVenda  = item.EstoqueCompra * item.ValorCompra;
                _mPedidoItem.Save(_mPedidoItem, false);
                new Estoque(_mPedidoItem.GetLastId(), Home.pedidoPage, $"Importação de compra").Add().Item();
            }

            foreach (dynamic item in ImportarPagamentos.titulos)
            {
                _mTitulo.Id           = 0;
                _mTitulo.Tipo         = "Pagar";
                _mTitulo.Emissao      = Validation.ConvertDateToSql(Emissao.Text);
                _mTitulo.Id_FormaPgto = Validation.ConvertToInt32(item.FormaPgto) == 15 ? 6 : Validation.ConvertToInt32(item.FormaPgto);
                _mTitulo.Id_Pedido    = _mPedido.GetLastId();
                _mTitulo.Vencimento   = item.Data;
                _mTitulo.Total        = Validation.ConvertToDouble(item.Valor.Replace(".", ","));
                _mTitulo.Recebido     = Validation.ConvertToDouble(item.Valor.Replace(".", ","));
                _mTitulo.Id_Pessoa    = idFornecedor;
                _mTitulo.Obs          = $"Pagamento gerado a partir da importação de compra. Chave de acesso: {item.id} | Número da nota: {item.nr}";
                _mTitulo.Save(_mTitulo, false);

                if (_mPedido.GetLastId() > 0)
                {
                    _mPedido.Id     = _mPedido.GetLastId();
                    _mPedido.status = 1;
                    _mPedido.Save(_mPedido);
                }
            }

            var data = _mPedido.SaveTotais(_mPedidoItem.SumTotais(_mPedido.GetLastId()));

            _mPedido.Save(data);
        }
Example #2
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;
                }
            };
        }
Example #3
0
        private void ActionEnviar()
        {
            if (IniFile.Read("MesasPreCadastrada", "Comercial") == "False")
            {
                if (string.IsNullOrEmpty(nrMesa.Text))
                {
                    Alert.Message("Oppss", "É necessário informar uma mesa", Alert.AlertType.warning);
                    return;
                }
            }
            else
            {
                if (Mesas.SelectedValue == null)
                {
                    if (nrMesa.Text == "")
                    {
                        Alert.Message("Oppss", "É necessário informar uma mesa", Alert.AlertType.warning);
                        return;
                    }
                }
                else if (Mesas.SelectedValue.ToString() == "0")
                {
                    Alert.Message("Oppss", "É necessário informar uma mesa", Alert.AlertType.warning);
                    return;
                }
            }

            if (GridLista.Rows.Count > 0)
            {
                foreach (DataGridViewRow row in GridLista.Rows)
                {
                    var id       = Validation.ConvertToInt32(row.Cells["ID"].Value);
                    var dataItem = _mItem.FindById(id).WhereFalse("excluir").FirstOrDefault <Item>();
                    if (dataItem != null)
                    {
                        var obs = row.Cells["Observação"].Value.ToString();

                        _mPedidoItem.Id             = 0;
                        _mPedidoItem.Tipo           = "Produtos";
                        _mPedidoItem.Excluir        = 0;
                        _mPedidoItem.Pedido         = 0;
                        _mPedidoItem.Item           = dataItem.Id;
                        _mPedidoItem.CEan           = dataItem.CodeBarras;
                        _mPedidoItem.CProd          = dataItem.Referencia;
                        _mPedidoItem.xProd          = dataItem.Nome;
                        _mPedidoItem.ValorVenda     = Validation.ConvertToDouble(row.Cells["Valor"].Value);
                        _mPedidoItem.Total          = Validation.ConvertToDouble(row.Cells["Valor"].Value);
                        _mPedidoItem.Quantidade     = 1;
                        _mPedidoItem.TotalVenda     = Validation.ConvertToDouble(row.Cells["Valor"].Value);
                        _mPedidoItem.Info_Adicional = obs;
                        _mPedidoItem.Adicional      = row.Cells["AddonSelected"].Value.ToString();
                        _mPedidoItem.Mesa           = IniFile.Read("MesasPreCadastrada", "Comercial") == "True" ? Mesas.Text : nrMesa.Text;
                        _mPedidoItem.Status         = "FAZENDO";
                        _mPedidoItem.Usuario        = Settings.Default.user_id;
                        _mPedidoItem.Save(_mPedidoItem, false);
                    }
                }

                new Controller.Pedido().ImprimirItens(0, _mPedidoItem.GetLastId());

                Alert.Message("Pronto", "Pedido enviado com sucesso.", Alert.AlertType.success);
                DialogResult = DialogResult.OK;
                Close();
            }
        }