private void PreencherDados()
        {
            try {
                Connection.Financeiro financeiro = new Connection.Financeiro();
                financeiro.Id = Id;
                financeiro.Get();

                dynamic fin = financeiro.Results[0];

                textNome.Text                    = fin.Nome;
                combTipo.SelectedValue           = Convert.ToInt32(fin.Tipo);
                combCentroCusto.SelectedValue    = Convert.ToInt32(fin.CentroCusto);
                combFormaPagamento.SelectedValue = Convert.ToInt32(fin.FormaPagamento);
                combStatus.SelectedValue         = Convert.ToInt32(fin.Status);
                timeDataEmissao.Text             = fin.DataEmissao;
                timeDataVencimento.Text          = fin.DataVencimento;
                textValor.Text                   = Converter.ToReais(fin.Valor);
                textDocumento.Text               = fin.Documento;
                combOcorrencia.SelectedValue     = Convert.ToInt32(fin.Ocorrencia);
                textQtdParcelas.Text             = Convert.ToString(fin.QtdParcelas);

                PreencherGrids(Convert.ToString(fin.Parcelas));

                if (!string.IsNullOrEmpty(Convert.ToString(fin.Referencia)) && fin.Referencia > 0)
                {
                    combTipo.Enabled        = false;
                    combCentroCusto.Enabled = false;
                    Referencia = fin.Id;
                }
            }
            catch (Exception e) {
                MessageBox.Show("Houve um erro ao preencher os dados (" + e.Message + ").");
            }
        }
Esempio n. 2
0
        private void OnSelectExcluir(object sender, EventArgs e)
        {
            try {
                if (mouseLocation.RowIndex >= 0)
                {
                    int Id = Convert.ToInt32(gridDados.Rows[mouseLocation.RowIndex].Cells[0].Value);

                    DialogResult Excluir = MessageBox.Show("Tem certeza que excluir este Financeiro?", "Excluir Financeiro", MessageBoxButtons.YesNo);

                    if (Excluir == DialogResult.Yes)
                    {
                        Connection.Financeiro financeiro = new Connection.Financeiro();
                        financeiro.Id = Id;
                        financeiro.Delete();

                        if (financeiro.Success)
                        {
                            MessageBox.Show(financeiro.Message);
                            LoadList();
                        }
                        else
                        {
                            throw new Exception("Houver um erro ao excluir o financeiro. (" + financeiro.Message + ")");
                        }
                    }
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }
        private void OnEnviar(object sender, EventArgs e)
        {
            try {
                Validate Validate = new Validate(this, ErrorProvider);

                Validate.AddRule(textNome, "Nome", "required|max:30");
                Validate.AddRule(combTipo, "Tipo", "required|numeric|exact:1");
                Validate.AddRule(combCentroCusto, "Centro de Custo", "required|max:2");
                Validate.AddRule(combFormaPagamento, "Forma de Pagamento", "required|max:2");
                Validate.AddRule(combStatus, "Status", "required|numeric|exact:1");
                Validate.AddRule(timeDataEmissao, "Data Emissão", "required|data:dd/MM/yyyy");
                Validate.AddRule(timeDataVencimento, "Data Vencimento", "required|data:dd/MM/yyyy");
                Validate.AddRule(textValor, "Valor", "required|reais|max:11");
                Validate.AddRule(textDocumento, "Nº Document", "max:30");
                Validate.AddRule(combOcorrencia, "Ocorrencia", "required|numeric|exact:1");
                Validate.AddRule(textQtdParcelas, "Qtd. Parcelas", "required_if:combOcorrencia,2|max:3");
                Validate.Validation();

                if (Validate.IsValid())
                {
                    PreencherJson();

                    Connection.Financeiro financeiro = new Connection.Financeiro();

                    financeiro.Nome           = textNome.Text;
                    financeiro.Tipo           = combTipo.SelectedValue.ToString();
                    financeiro.Referencia     = Referencia;
                    financeiro.CentroCusto    = combCentroCusto.SelectedValue.ToString();
                    financeiro.FormaPagamento = combFormaPagamento.SelectedValue.ToString();
                    financeiro.Status         = combStatus.SelectedValue.ToString();
                    financeiro.DataEmissao    = timeDataEmissao.Text;
                    financeiro.DataVencimento = timeDataVencimento.Text;
                    financeiro.Valor          = Converter.ToDecimal(textValor.Text, true);
                    financeiro.Documento      = textDocumento.Text;
                    financeiro.Ocorrencia     = combOcorrencia.SelectedValue.ToString();
                    financeiro.QtdParcelas    = textQtdParcelas.Text;
                    financeiro.Parcelas       = jsonParcelas;

                    if (Id > 0)
                    {
                        financeiro.Id = Convert.ToInt32(Id);
                        financeiro.Update();
                    }
                    else
                    {
                        financeiro.Create();
                    }

                    if (financeiro.Success)
                    {
                        DialogResult SuccessBox = MessageBox.Show(financeiro.Message, "CADASTRADO");
                        if (SuccessBox == DialogResult.OK)
                        {
                            if (fmPrincipal != null)
                            {
                                fmPrincipal.AtivarForm(new TMSForms.List.FormFinanceiro(fmPrincipal));
                            }
                            else
                            {
                                Close();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Houve um erro ao salvar o financeiro (" + financeiro.Message + ")");
                    }
                }
                else
                {
                    Validate.ErrorProviderShow();
                }
            }
            catch (Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }