Example #1
0
        /// <summary>
        ///     Eventos do form
        /// </summary>
        public void Eventos()
        {
            Load += (s, e) =>
            {
                PayVerify = true;

                if (AddPedidos.PDV)
                {
                    // btn NF-e
                    btnNfe.Visible      = false;
                    button21.Visible    = false;
                    pictureBox6.Visible = false;
                }
            };

            Shown += (s, e) =>
            {
                Resolution.SetScreenMaximized(this);

                AddPedidos.BtnFinalizado = false;
                TelaReceber.Visible      = false;

                switch (Home.pedidoPage)
                {
                case "Orçamentos":
                    label13.Text = $@"Dados do Orçamento: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para criar um orçamento!";
                    break;

                case "Consignações":
                    label13.Text = $@"Dados da Consignação: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para criar uma consignãção!";
                    break;

                case "Devoluções":
                    label13.Text = $@"Dados da Devolução: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para criar uma devolução!";
                    break;

                case "Compras":
                    label13.Text = $@"Dados da Compra: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para adicionar uma compra!";

                    label15.Text = @"Á Pagar";
                    label1.Text  = @"Pagamentos";
                    //enviarEmail.Visible = false;
                    btnNfe.Visible    = false;
                    button21.Visible  = false;
                    btnCFeSat.Visible = false;
                    button22.Visible  = false;
                    break;

                default:
                    label13.Text = $@"Dados da Venda: {idPedido}";
                    label10.Text = @"Siga as etapas abaixo para adicionar uma venda!";
                    break;
                }

                if (HideFinalizar)
                {
                    btnCFeSat.Visible = false;
                    button22.Visible  = false;

                    btnNfe.Visible   = false;
                    button21.Visible = false;

                    btnConcluir.Visible = false;
                    button19.Visible    = false;

                    //btnImprimir.Left = 835;
                    //button20.Left = 830;
                    btnImprimir.Visible = false;
                    button20.Visible    = false;
                }

                if (IniFile.Read("Alimentacao", "Comercial") == "True")
                {
                    btnDividir.Visible = true;
                }

                mtxt.Visible  = false;
                mtxt2.Visible = false;

                GridListaFormaPgtos.Controls.Add(mtxt);
                GridListaFormaPgtos.Controls.Add(mtxt2);

                AtualizarDados();

                AddPedidos.BtnFinalizado = false;

                Dinheiro.Focus();
                Dinheiro.Select();

                var taxasSource = new ArrayList();
                var dataTaxa    = new Taxas().FindAll(new[] { "id", "nome" }).WhereFalse("excluir").Get <Taxas>();
                taxasSource.Add(new { Id = 0, Nome = "SELECIONE" });
                if (dataTaxa.Any())
                {
                    foreach (var item in dataTaxa)
                    {
                        taxasSource.Add(new { item.Id, item.Nome });
                    }
                }

                taxas.DataSource    = taxasSource;
                taxas.DisplayMember = "Nome";
                taxas.ValueMember   = "Id";
            };

            FormClosing += (s, e) =>
            {
                if (AddPedidos.BtnFinalizado)
                {
                    Application.OpenForms["AddPedidos"]?.Close();
                }
            };

            KeyDown                     += KeyDowns;
            Dinheiro.KeyDown            += KeyDowns;
            Cheque.KeyDown              += KeyDowns;
            Debito.KeyDown              += KeyDowns;
            Credito.KeyDown             += KeyDowns;
            Crediario.KeyDown           += KeyDowns;
            Boleto.KeyDown              += KeyDowns;
            Desconto.KeyDown            += KeyDowns;
            Acrescimo.KeyDown           += KeyDowns;
            GridListaFormaPgtos.KeyDown += KeyDowns;

            btnCFeSat.KeyDown += (s, e) =>
            {
                if (UserPermission.SetControl(btnCFeSat, pictureBox1, "fiscal_emissaocfe"))
                {
                    return;
                }

                KeyDowns(s, e);
            };

            btnNfe.KeyDown += (s, e) =>
            {
                if (!Support.CheckForInternetConnection())
                {
                    Alert.Message("Opps", "Você está sem conexão com a internet.", Alert.AlertType.warning);
                    return;
                }

                if (UserPermission.SetControl(btnNfe, pictureBox6, "fiscal_emissaonfe"))
                {
                    return;
                }

                KeyDowns(s, e);
            };

            btnImprimir.KeyDown += KeyDowns;
            btnConcluir.KeyDown += KeyDowns;
            btnSalvar.KeyDown   += KeyDowns;
            btnCancelar.KeyDown += KeyDowns;
            valor.KeyDown       += KeyDowns;
            parcelas.KeyDown    += KeyDowns;
            iniciar.KeyDown     += KeyDowns;

            btnImprimir.Click += (s, e) => { new Controller.Pedido().Imprimir(idPedido); };

            Debito.Click    += (s, e) => JanelasRecebimento("Cartão de Débito");
            Credito.Click   += (s, e) => JanelasRecebimento("Cartão de Crédito");
            Dinheiro.Click  += (s, e) => JanelasRecebimento("Dinheiro");
            Boleto.Click    += (s, e) => JanelasRecebimento("Boleto");
            Crediario.Click += (s, e) => JanelasRecebimento("Crediário");
            Cheque.Click    += (s, e) => JanelasRecebimento("Cheque");

            Desconto.Click  += (s, e) => JanelaDesconto();
            Acrescimo.Click += (s, e) => JanelaAcrescimo();
            Devolucao.Click += (s, e) => JanelaDevolucao();

            btnSalvar.Click   += (s, e) => BSalvar();
            btnCancelar.Click += (s, e) =>
            {
                PayVerify           = true;
                TelaReceber.Visible = false;
            };

            btnClose.Click += (s, e) =>
            {
                if (_controllerTitulo.GetLancados(idPedido) > 0)
                {
                    var text    = Home.pedidoPage == "Compras" ? "pagamentos" : "recebimentos";
                    var message = AlertOptions.Message("Atenção",
                                                       $"Os {text} lançados serão apagados,\n deseja continuar?", AlertBig.AlertType.warning,
                                                       AlertBig.AlertBtn.YesNo);
                    if (message)
                    {
                        foreach (DataGridViewRow row in GridListaFormaPgtos.Rows)
                        {
                            if (Convert.ToString(row.Cells[0].Value) != "")
                            {
                                _mTitulo.Remove(Validation.ConvertToInt32(row.Cells[0].Value), "ID", false);
                            }
                        }

                        AtualizarDados();

                        _mPedido        = _mPedido.FindById(idPedido).FirstOrDefault <Model.Pedido>();
                        _mPedido.status = 2;
                        _mPedido.Save(_mPedido);

                        Close();
                    }
                    else
                    {
                        return;
                    }
                }

                AddPedidos.BtnVoltar = true;
                Close();
            };

            btnDividir.Click += (s, e) =>
            {
                var itens = new ArrayList();
                if (PayVerify)
                {
                    var dataItens = _mPedidoItens.FindAll().Where("pedido", idPedido).WhereFalse("excluir")
                                    .Get <PedidoItem>();
                    if (dataItens.Any())
                    {
                        foreach (var item in dataItens)
                        {
                            itens.Add(new
                            {
                                item.Id,
                                item.Item,
                                item.xProd,
                                item.CEan,
                                item.CProd,
                                item.Quantidade,
                                item.Total
                            });
                        }
                    }

                    PedidoModalDividirConta.Itens = itens;
                }

                var form = new PedidoModalDividirConta {
                    TopMost = true
                };
                if (form.ShowDialog() == DialogResult.OK)
                {
                    valor.Text = Validation.FormatPrice(PedidoModalDividirConta.ValorDividido);
                }
            };

            btnConcluir.Click += (s, e) => { Concluir(); };

            iniciar.KeyPress += Masks.MaskBirthday;
            iniciar.KeyPress += Masks.MaskBirthday;
            valor.KeyPress   += (s, e) => Masks.MaskDouble(s, e);

            valor.TextChanged += (s, e) =>
            {
                var txt = (TextBox)s;
                Masks.MaskPrice(ref txt);
            };

            mtxt2.TextChanged += (s, e) =>
            {
                var txt = (TextBox)s;
                Masks.MaskPrice(ref txt);
            };

            GridListaFormaPgtos.CellDoubleClick += (s, e) =>
            {
                if (GridListaFormaPgtos.Columns[e.ColumnIndex].Name == "colExcluir")
                {
                    if (Convert.ToString(GridListaFormaPgtos.CurrentRow.Cells[4].Value) != "")
                    {
                        var id = Validation.ConvertToInt32(GridListaFormaPgtos.CurrentRow.Cells[0].Value);
                        _mTitulo.Remove(id);
                        AtualizarDados();
                    }
                }
            };

            GridListaFormaPgtos.CellBeginEdit += (s, e) =>
            {
                if (e.ColumnIndex == 2)
                {
                    //-----mtxt

                    mtxt.Mask = @"##/##/####";

                    var rec = GridListaFormaPgtos.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
                    mtxt.Location = rec.Location;
                    mtxt.Size     = rec.Size;
                    mtxt.Text     = "";

                    if (GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value != null)
                    {
                        mtxt.Text = GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value.ToString();
                    }

                    mtxt.Visible = true;
                }

                if (e.ColumnIndex == 3)
                {
                    //-----mtxt2

                    var rec = GridListaFormaPgtos.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true);
                    mtxt2.Location = rec.Location;
                    mtxt2.Size     = rec.Size;
                    mtxt2.Text     = "";

                    if (GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value != null)
                    {
                        mtxt2.Text = GridListaFormaPgtos[e.ColumnIndex, e.RowIndex].Value.ToString();
                    }

                    mtxt2.Visible = true;
                }
            };

            GridListaFormaPgtos.CellEndEdit += (s, e) =>
            {
                if (mtxt.Visible)
                {
                    GridListaFormaPgtos.CurrentCell.Value = mtxt.Text;
                    mtxt.Visible = false;
                }

                if (mtxt2.Visible)
                {
                    GridListaFormaPgtos.CurrentCell.Value = mtxt2.Text;
                    mtxt2.Visible = false;
                }

                var ID = Validation.ConvertToInt32(GridListaFormaPgtos.Rows[e.RowIndex].Cells["colID"].Value);
                if (ID == 0)
                {
                    return;
                }

                var titulo = new Model.Titulo().FindById(ID).FirstOrDefault <Model.Titulo>();

                if (titulo == null)
                {
                    return;
                }

                DateTime parsed;
                if (DateTime.TryParse(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value.ToString(),
                                      out parsed))
                {
                    titulo.Vencimento =
                        Validation.ConvertDateToSql(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value);
                }
                else
                {
                    GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column1"].Value =
                        Validation.ConvertDateToForm(titulo.Vencimento);
                }

                titulo.Total    = Validation.ConvertToDouble(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column3"].Value);
                titulo.Recebido =
                    Validation.ConvertToDouble(GridListaFormaPgtos.Rows[e.RowIndex].Cells["Column3"].Value);

                if (titulo.Save(titulo, false))
                {
                    //_controllerTitulo.GetDataTableTitulos(GridListaFormaPgtos, IdPedido);
                    Alert.Message("Pronto!", "Recebimento atualizado com sucesso.", Alert.AlertType.success);
                    AtualizarDados(false);
                }
                else
                {
                    Alert.Message("Opsss!", "Algo deu errado ao atualizar o recebimento.", Alert.AlertType.error);
                }
            };

            GridListaFormaPgtos.Scroll += (s, e) =>
            {
                if (mtxt.Visible)
                {
                    var rec = GridListaFormaPgtos.GetCellDisplayRectangle(GridListaFormaPgtos.CurrentCell.ColumnIndex,
                                                                          GridListaFormaPgtos.CurrentCell.RowIndex, true);
                    mtxt.Location = rec.Location;
                }

                if (mtxt2.Visible)
                {
                    var rec = GridListaFormaPgtos.GetCellDisplayRectangle(GridListaFormaPgtos.CurrentCell.ColumnIndex,
                                                                          GridListaFormaPgtos.CurrentCell.RowIndex, true);
                    mtxt2.Location = rec.Location;
                }
            };

            btnClearRecebimentos.Click += (s, e) =>
            {
                foreach (DataGridViewRow row in GridListaFormaPgtos.Rows)
                {
                    if (Convert.ToString(row.Cells[0].Value) != "")
                    {
                        _mTitulo.Remove(Validation.ConvertToInt32(row.Cells[0].Value), "ID", false);
                    }
                }

                AtualizarDados();

                _mPedido        = _mPedido.FindById(idPedido).FirstOrDefault <Model.Pedido>();
                _mPedido.status = 2;
                _mPedido.Save(_mPedido);
            };

            btnNfe.Click += (s, e) =>
            {
                if (!Support.CheckForInternetConnection())
                {
                    Alert.Message("Opps", "Você está sem conexão com a internet.", Alert.AlertType.warning);
                    return;
                }

                if (UserPermission.SetControl(btnNfe, pictureBox6, "fiscal_emissaonfe"))
                {
                    return;
                }

                Nfe();
            };

            btnCFeSat.Click += (s, e) =>
            {
                if (UserPermission.SetControl(btnCFeSat, pictureBox1, "fiscal_emissaocfe"))
                {
                    return;
                }

                Cfe();
            };
        }
Example #2
0
        public void AtualizarDados(Boolean grid = true)
        {
            Dinheiro.Select();

            _mPedido = _mPedido.FindById(IdPedido).FirstOrDefault <Model.Pedido>();

            if (grid)
            {
                _controllerTitulo.GetDataTableTitulos(GridListaFormaPgtos, IdPedido);
            }

            dynamic devolucoes = _mPedido.Query()
                                 .SelectRaw("SUM(total) as total")
                                 .Where("excluir", 0)
                                 .Where("tipo", "Devoluções")
                                 .Where("Venda", IdPedido)
                                 .FirstOrDefault <Model.Pedido>();

            acrescimos.Text = Validation.FormatPrice(_controllerTitulo.GetTotalFrete(IdPedido), true);
            discount.Text   = Validation.FormatPrice((_controllerTitulo.GetTotalDesconto(IdPedido) + Validation.ConvertToDouble(devolucoes.Total ?? 0)), true);
            troco.Text      = Validation.FormatPrice(_controllerTitulo.GetTroco(IdPedido), true).Replace("-", "");
            pagamentos.Text = Validation.FormatPrice(_controllerTitulo.GetLancados(IdPedido), true);
            total.Text      = Validation.FormatPrice(_controllerTitulo.GetTotalPedido(IdPedido), true);

            var aPagar = Validation.RoundTwo(_controllerTitulo.GetTotalPedido(IdPedido) - _controllerTitulo.GetLancados(IdPedido));

            if (_controllerTitulo.GetLancados(IdPedido) < _controllerTitulo.GetTotalPedido(IdPedido))
            {
                aPagartxt.Text = Validation.FormatPrice(aPagar, true);
            }
            else
            {
                aPagartxt.Text = "R$ 0,00";
            }

            if (_controllerTitulo.GetLancados(IdPedido) > 0)
            {
                Desconto.Enabled = false;
            }
            else
            {
                Desconto.Enabled = true;
            }

            if (aPagar <= 0)
            {
                label15.BackColor   = Color.FromArgb(46, 204, 113);
                aPagartxt.BackColor = Color.FromArgb(46, 204, 113);
                visualPanel1.BackColorState.Enabled = Color.FromArgb(46, 204, 113);
                visualPanel1.Border.Color           = Color.FromArgb(39, 192, 104);
                Refresh();
            }
            else
            {
                label15.BackColor   = Color.FromArgb(255, 40, 81);
                aPagartxt.BackColor = Color.FromArgb(255, 40, 81);
                visualPanel1.BackColorState.Enabled = Color.FromArgb(255, 40, 81);
                visualPanel1.Border.Color           = Color.FromArgb(241, 33, 73);
                Refresh();
            }
        }