Exemplo n.º 1
0
        private void dgList_DoubleClick(object sender, EventArgs e)
        {
            Finance financeVO = new Finance();

            financeVO.Id             = int.Parse(dgList.CurrentRow.Cells["clId"].Value.ToString());
            financeVO                = FinanceDAO.GetByID(financeVO);
            cmbCategory.SelectedItem = financeVO.FinanceCategorySub.FinanceCategory;
            this.ShowCmbCategorySub();
            cmbCategorySub.SelectedItem = financeVO.FinanceCategorySub;
            cmbPaymentForm.SelectedItem = financeVO.PaymentForm;
            txtValue.Text   = financeVO.Value.ToString();
            dtDateTime.Text = financeVO.Date.ToString();
            if (financeVO.Situation == FinanceU.SITUATION_PAGO)
            {
                rbSituationPago.Checked = true;
            }
            else
            {
                rbSituationPendente.Checked = true;
            }
            cmbPriority.SelectedIndex = financeVO.Priority;
            txtText.Text = financeVO.Text;
            txtId.Text   = financeVO.Id.ToString();

            btnExcluir.Enabled = true;
        }
Exemplo n.º 2
0
        private void showGrid()
        {
            FinanceCategory    financeCategory    = new FinanceCategory();
            FinanceCategorySub financeCategorySub = new FinanceCategorySub();
            Finance            finance            = new Finance();

            if (cmbBuscarCategory.SelectedItem != null)
            {
                financeCategory = (FinanceCategory)cmbBuscarCategory.SelectedItem;
            }
            if (cmbBuscarCategorySub.SelectedItem != null)
            {
                financeCategorySub = (FinanceCategorySub)cmbBuscarCategorySub.SelectedItem;
            }

            financeCategory.Type       = this.Type;
            finance.FinanceCategorySub = financeCategorySub;
            finance.FinanceCategorySub.FinanceCategory = financeCategory;
            dgList.Rows.Clear();
            foreach (Finance x in FinanceDAO.ListAllBy(finance))
            {
                dgList.Rows.Add(x.Id, x.FinanceCategorySub.FinanceCategory.Name + ", " + x.FinanceCategorySub.Name,
                                Util.moneyFormat_ptBR(x.Value), x.Date, FinanceU.ArraySituation[x.Situation],
                                x.PaymentForm.Name, FinanceU.ArrayPriority[x.Priority]);
            }
        }
Exemplo n.º 3
0
        private bool validateForm(Finance finance)
        {
            if (cmbCategory.SelectedItem == null)
            {
                lblErrorCategory.Text = "Campo obrigatório";
                cmbCategory.Focus();
                return(false);
            }
            lblErrorCategory.Text = "";

            if (cmbCategorySub.SelectedItem == null)
            {
                lblErrorCategorySub.Text = "Campo obrigatório";
                cmbCategorySub.Focus();
                return(false);
            }
            lblErrorCategorySub.Text = "";

            if (cmbPaymentForm.SelectedItem == null)
            {
                lblErrorPaymentForm.Text = "Campo obrigatório";
                cmbPaymentForm.Focus();
                return(false);
            }
            lblErrorPaymentForm.Text = "";

            if (txtValue.Text.Trim().Equals(""))
            {
                lblErrorValue.Text = "Campo obrigatório.";
                txtValue.Focus();
                return(false);
            }
            double value;

            if (!double.TryParse(txtValue.Text, out value))
            {
                lblErrorValue.Text = "Preencha um número válido.";
                return(false);
            }
            if (value < 0.01)
            {
                lblErrorValue.Text = "Valor mínimo de R$ 0,01.";
                return(false);
            }
            lblErrorValue.Text = "";
            finance.Value      = value;

            finance.Priority = cmbPriority.SelectedIndex;
            if (finance.Priority.Equals(0) || cmbPriority.Text.Trim().Equals(""))
            {
                lblErrorPriority.Text = "Campo obrigatório";
                cmbPriority.Focus();
                return(false);
            }
            lblErrorPriority.Text = "";

            return(true);
        }
Exemplo n.º 4
0
        public static Finance GetByID(Finance financeVO)
        {
            DBEntities db = SingletonObjectContext.Instance.Context;

            try
            {
                return(db.Finances.FirstOrDefault(x => x.Id.Equals(financeVO.Id) && x.Status > 0));
            }
            catch
            {
                return(null);
            }
        }
Exemplo n.º 5
0
        public static IOrderedEnumerable <Finance> ListAllBy(Finance financeVO)
        {
            DBEntities db = SingletonObjectContext.Instance.Context;

            if (financeVO.FinanceCategorySub.FinanceCategory.Id > 0)
            {
                return(db.Finances.Include("FinanceCategorySub.FinanceCategory").Where(x => x.Status > 0 && x.FinanceCategorySub.FinanceCategory.Id.Equals(financeVO.FinanceCategorySub.FinanceCategory.Id)).ToList().OrderByDescending(x => x.Date));
            }
            if (financeVO.FinanceCategorySub.Id > 0)
            {
                return(db.Finances.Include("FinanceCategorySub.FinanceCategory").Where(x => x.Status > 0 && x.FinanceCategorySub.Id.Equals(financeVO.FinanceCategorySub.Id)).ToList().OrderByDescending(x => x.Date));
            }

            return(db.Finances.Include("PaymentForm").Include("FinanceCategorySub.FinanceCategory").Where(x => x.Status > 0 && x.FinanceCategorySub.FinanceCategory.Type.Equals(financeVO.FinanceCategorySub.FinanceCategory.Type)).ToList().OrderByDescending(x => x.Date));
        }
Exemplo n.º 6
0
        public static bool Update(Finance financeVO)
        {
            DBEntities db = SingletonObjectContext.Instance.Context;

            try
            {
                financeVO.DateUpdate      = DateTime.Now;
                db.Entry(financeVO).State = EntityState.Modified;
                db.SaveChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 7
0
        private void showGrid()
        {
            DateTime dateIn  = DateTime.Parse(dtDateIn.Text);
            DateTime dateEnd = DateTime.Parse(dtDateEnd.Text);
            Finance  finance;
            double   ganhos, gastos, totalGanhos = 0, totalGastos = 0, saldo;

            dgList.Rows.Clear();
            foreach (PaymentForm p in PaymentFormDAO.ListAll())
            {
                finance = new Finance();
                finance.FinanceCategorySub = new FinanceCategorySub();
                finance.FinanceCategorySub.FinanceCategory      = new FinanceCategory();
                finance.FinanceCategorySub.FinanceCategory.Type = FinanceCategoryU.TYPE_GANHO;
                finance.PaymentForm = p;
                ganhos = 0;
                foreach (Finance f in FinanceDAO.ListByFilter(finance, dateIn, dateEnd))
                {
                    ganhos += f.Value;
                }

                finance.FinanceCategorySub.FinanceCategory.Type = FinanceCategoryU.TYPE_GASTO;
                gastos = 0;
                foreach (Finance f in FinanceDAO.ListByFilter(finance, dateIn, dateEnd))
                {
                    gastos += f.Value;
                }

                dgList.Rows.Add(p.Name, Util.moneyFormat_ptBR(ganhos), Util.moneyFormat_ptBR(gastos), Util.moneyFormat_ptBR(FinanceBO.CalcSaldo(ganhos, gastos)));
                totalGanhos += ganhos;
                totalGastos += gastos;
            }

            txtGanhos.Text   = Util.moneyFormat_ptBR(totalGanhos);
            txtGastos.Text   = Util.moneyFormat_ptBR(totalGastos);
            saldo            = FinanceBO.CalcSaldo(totalGanhos, totalGastos);
            txtMeuSaldo.Text = Util.moneyFormat_ptBR(saldo);
            if (saldo > 0)
            {
                txtMeuSaldo.ForeColor = System.Drawing.Color.Green;
            }
            else
            {
                txtMeuSaldo.ForeColor = System.Drawing.Color.Red;
            }
        }
Exemplo n.º 8
0
        public static bool Insert(Finance financeVO)
        {
            DBEntities db = SingletonObjectContext.Instance.Context;

            try
            {
                financeVO.Status     = SystemU.STATUS_ATIVO;
                financeVO.DatePost   = DateTime.Now;
                financeVO.DateUpdate = DateTime.Now;
                db.Finances.Add(financeVO);
                db.SaveChanges();

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 9
0
 private void btnExcluir_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Deseja mesmo este registro?", "Finança", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
     {
         Finance financeVO = new Finance();
         financeVO.Id = int.Parse(txtId.Text);
         financeVO    = FinanceDAO.GetByID(financeVO);
         if (!FinanceDAO.UpdateDisable(financeVO))
         {
             MessageBox.Show("Erro: Ocorreu um erro inesperado excluir.");
         }
         else
         {
             MessageBox.Show("Excluído com sucesso.");
             this.ClearFields();
             this.showGrid();
         }
     }
 }
Exemplo n.º 10
0
        public static List <Finance> ListByFilter(Finance f, DateTime dateIn, DateTime dateEnd)
        {
            DBEntities db = SingletonObjectContext.Instance.Context;

            return(db.Finances.Where(x => x.Status > 0 && x.FinanceCategorySub.FinanceCategory.Type.Equals(f.FinanceCategorySub.FinanceCategory.Type) && x.PaymentForm.Id.Equals(f.PaymentForm.Id) && x.Date >= dateIn && x.Date <= dateEnd).ToList());
        }
Exemplo n.º 11
0
        private void btnSalvar_Click(object sender, EventArgs e)
        {
            Finance finance = new Finance();
            int     Id;

            if (int.TryParse(txtId.Text, out Id))
            {
                finance.Id = Id;
                finance    = FinanceDAO.GetByID(finance);
            }
            FinanceCategorySub financeCategorySub = new FinanceCategorySub();

            financeCategorySub         = (FinanceCategorySub)cmbCategorySub.SelectedItem;
            financeCategorySub         = FinanceCategorySubDAO.GetByID(financeCategorySub);
            finance.FinanceCategorySub = financeCategorySub;

            PaymentForm paymentForm = new PaymentForm();

            paymentForm         = (PaymentForm)cmbPaymentForm.SelectedItem;
            paymentForm         = PaymentFormDAO.GetByID(paymentForm);
            finance.PaymentForm = paymentForm;

            finance.Date = dtDateTime.Value;
            if (rbSituationPago.Checked)
            {
                finance.Situation = FinanceU.SITUATION_PAGO;
                finance.DateClose = finance.Date;
            }
            else
            {
                finance.Situation = FinanceU.SITUATION_PENDENTE;
                finance.DateClose = DateTime.Now;
            }
            finance.Text = txtText.Text;

            if (this.validateForm(finance))
            {
                if (finance.Id > 0)
                {
                    if (FinanceDAO.Update(finance))
                    {
                        MessageBox.Show("Alterado com sucesso.");
                        this.ClearFields();
                        this.showGrid();
                        return;
                    }
                    MessageBox.Show("Erro: Ocorreu um erro inesperado alterar.");
                }
                else
                {
                    if (FinanceDAO.Insert(finance))
                    {
                        MessageBox.Show("Cadastrado com sucesso.");
                        this.ClearFields();
                        this.showGrid();
                        return;
                    }
                    MessageBox.Show("Erro: Ocorreu um erro inesperado cadastrar.");
                }
            }
        }