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]); } }
private bool validateForm(FinanceCategory financeCategory) { financeCategory.Type = cmbType.SelectedIndex; if (financeCategory.Type.Equals(0) || cmbType.Text.Trim().Equals("")) { lblErrorType.Text = "Campo obrigatório"; cmbType.Focus(); return(false); } lblErrorType.Text = ""; financeCategory.Name = txtName.Text.Trim(); if (financeCategory.Name.Equals("")) { lblErrorName.Text = "Campo obrigatório."; txtName.Focus(); return(false); } if (FinanceCategoryDAO.CountByName(financeCategory) > 0) { lblErrorName.Text = "Já consta cadastrado."; return(false); } lblErrorName.Text = ""; return(true); }
private void showChart() { DateTime dateIn = DateTime.Parse(dtDateIn.Text); DateTime dateEnd = DateTime.Parse(dtDateEnd.Text); bool check = false; double gastos = 0; int i = 1; for (int j = 0; j < chtCategorias.Series.Count; j++) { chtCategorias.Series.RemoveAt(j); } chtCategorias.Titles.Clear(); chtCategorias.Titles.Add("Gastos no perído de " + dateIn.ToShortDateString() + " até " + dateEnd.ToShortDateString()); FinanceCategory fc = new FinanceCategory(); fc.Type = FinanceCategoryU.TYPE_GASTO; foreach (FinanceCategory x in FinanceCategoryDAO.ListFinanceByType(fc)) { if (x.Status > 0) { gastos = 0; check = false; foreach (FinanceCategorySub y in x.collFinanceCategorySub) { if (y.Status > 0) { foreach (Finance z in y.collFinance) { if (z.Status > 0 && DateTime.Compare(z.Date, dateIn) >= 0 && DateTime.Compare(z.Date, dateEnd) <= 0) { gastos += z.Value; check = true; } } } } } if (check) { if (chtCategorias.Series.IsUniqueName("s" + x.Id)) { chtCategorias.Series.Add("s" + x.Id); } chtCategorias.Series["s" + x.Id].LegendText = x.Name; chtCategorias.Series["s" + x.Id].Points.AddXY(i, gastos); i++; } } chtCategorias.Update(); }
private void dgList_DoubleClick(object sender, EventArgs e) { FinanceCategory financeCategoryVO = new FinanceCategory(); financeCategoryVO.Id = int.Parse(dgList.CurrentRow.Cells["clId"].Value.ToString()); financeCategoryVO = FinanceCategoryDAO.GetByID(financeCategoryVO); cmbType.SelectedIndex = financeCategoryVO.Type; txtName.Text = financeCategoryVO.Name; txtId.Text = financeCategoryVO.Id.ToString(); btnExcluir.Enabled = true; }
public static FinanceCategory GetByID(FinanceCategory financeCategoryVO) { DBEntities db = SingletonObjectContext.Instance.Context; try { return(db.FinanceCategories.FirstOrDefault(x => x.Id.Equals(financeCategoryVO.Id) && x.Status > 0)); } catch { return(null); } }
public static int CountByName(FinanceCategory financeCategoryVO) { DBEntities db = SingletonObjectContext.Instance.Context; try { return(db.FinanceCategories.Count(x => x.Id != financeCategoryVO.Id && x.Status > 0 && x.Type.Equals(financeCategoryVO.Type) && x.Name.Equals(financeCategoryVO.Name))); } catch { return(0); } }
private void cmbBuscarType_SelectedValueChanged(object sender, EventArgs e) { FinanceCategory financeCategory = new FinanceCategory(); financeCategory.Type = cmbBuscarType.SelectedIndex; cmbBuscarCategory.Items.Clear(); cmbBuscarCategory.Items.Add("Carregando ..."); cmbBuscarCategory.Items.Clear(); foreach (FinanceCategory x in FinanceCategoryDAO.ListByType(financeCategory)) { cmbBuscarCategory.Items.Add(x); } cmbBuscarCategory.ValueMember = "Id"; cmbBuscarCategory.DisplayMember = "Name"; }
private void ShowCmbCategory() { FinanceCategory financeCategory = new FinanceCategory(); financeCategory.Type = cmbType.SelectedIndex; cmbCategory.Items.Clear(); cmbCategory.Items.Add("Carregando ..."); cmbCategory.Items.Clear(); foreach (FinanceCategory x in FinanceCategoryDAO.ListByType(financeCategory)) { cmbCategory.Items.Add(x); } cmbCategory.ValueMember = "Id"; cmbCategory.DisplayMember = "Name"; }
private void cmbCategory_Start() { FinanceCategory fc = new FinanceCategory(); cmbCategory.Items.Add(fc); fc.Type = this.Type; foreach (FinanceCategory x in FinanceCategoryDAO.ListByType(fc)) { cmbCategory.Items.Add(x); cmbBuscarCategory.Items.Add(x); } cmbCategory.ValueMember = "Id"; cmbCategory.DisplayMember = "Name"; cmbBuscarCategory.ValueMember = "Id"; cmbBuscarCategory.DisplayMember = "Name"; }
public static bool Update(FinanceCategory financeCategoryVO) { DBEntities db = SingletonObjectContext.Instance.Context; try { financeCategoryVO.DateUpdate = DateTime.Now; db.Entry(financeCategoryVO).State = EntityState.Modified; db.SaveChanges(); return(true); } catch { return(false); } }
private void btnExcluir_Click(object sender, EventArgs e) { if (MessageBox.Show("Deseja mesmo este registro?", "Categoria", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { FinanceCategory financeCategoryVO = new FinanceCategory(); financeCategoryVO.Id = int.Parse(txtId.Text); financeCategoryVO = FinanceCategoryDAO.GetByID(financeCategoryVO); if (!FinanceCategoryDAO.UpdateDisable(financeCategoryVO)) { MessageBox.Show("Erro: Ocorreu um erro inesperado excluir."); } else { MessageBox.Show("Excluído com sucesso."); this.ClearFields(); this.showGrid(); } } }
public static bool Insert(FinanceCategory financeCategoryVO) { DBEntities db = SingletonObjectContext.Instance.Context; try { financeCategoryVO.Status = SystemU.STATUS_ATIVO; financeCategoryVO.DatePost = DateTime.Now; financeCategoryVO.DateUpdate = DateTime.Now; db.FinanceCategories.Add(financeCategoryVO); db.SaveChanges(); return(true); } catch { return(false); } }
private void btnSalvar_Click(object sender, EventArgs e) { FinanceCategorySub financeCategorySub = new FinanceCategorySub(); int Id; if (int.TryParse(txtId.Text, out Id)) { financeCategorySub.Id = Id; financeCategorySub = FinanceCategorySubDAO.GetByID(financeCategorySub); } FinanceCategory financeCategory = new FinanceCategory(); financeCategory = (FinanceCategory)cmbCategory.SelectedItem; financeCategory = FinanceCategoryDAO.GetByID(financeCategory); financeCategorySub.FinanceCategory = financeCategory; if (this.validateForm(financeCategorySub)) { if (financeCategorySub.Id > 0) { if (FinanceCategorySubDAO.Update(financeCategorySub)) { MessageBox.Show("Alterado com sucesso."); this.ClearFields(); this.showGrid(); return; } MessageBox.Show("Erro: Ocorreu um erro inesperado alterar."); } else { if (FinanceCategorySubDAO.Insert(financeCategorySub)) { MessageBox.Show("Cadastrado com sucesso."); this.ClearFields(); this.showGrid(); return; } MessageBox.Show("Erro: Ocorreu um erro inesperado cadastrar."); } } }
private void showGrid() { FinanceCategory financeCategory = new FinanceCategory(); FinanceCategorySub financeCategorySub = new FinanceCategorySub(); if (cmbBuscarType.SelectedIndex != 0) { financeCategory.Type = cmbBuscarType.SelectedIndex; } if (cmbBuscarCategory.SelectedItem != null) { financeCategory = (FinanceCategory)cmbBuscarCategory.SelectedItem; } financeCategorySub.FinanceCategory = financeCategory; dgList.Rows.Clear(); foreach (FinanceCategorySub x in FinanceCategorySubDAO.ListAllBy(financeCategorySub)) { dgList.Rows.Add(x.Id, x.Name, x.FinanceCategory.Name); } }
public static IOrderedEnumerable <FinanceCategory> ListFinanceByType(FinanceCategory financeCategoryVO) { DBEntities db = SingletonObjectContext.Instance.Context; return(db.FinanceCategories.Include("collFinanceCategorySub").Include("collFinanceCategorySub.collFinance").Where(x => x.Status > 0 && x.Type.Equals(financeCategoryVO.Type)).ToList().OrderBy(x => x.Name)); }