private void dgvMaster_SelectionChanged(object sender, EventArgs e) { //Alinhando texto à direita this.dgvDetalhe.Columns["colData"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; this.dgvDetalhe.Columns["colValorDet"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; foreach (DataGridViewRow row in dgvMaster.SelectedRows) { int idTipoGastos = Convert.ToInt32(row.Cells[0].Value.ToString()); var listaFiltradaPorTipo = GetListaDadosDetalhe(idTipoGastos); dgvDetalhe.Rows.Clear(); foreach (var detalhe in listaFiltradaPorTipo) { dgvDetalhe.Rows.Add(detalhe.DATA.ToString("dd/MM/yyyy"), detalhe.LOCAL, Convert.ToDecimal(OutrosUtil.FormatarDecimal(detalhe.VALOR)) ); } var total = listaFiltradaPorTipo.Sum(x => x.VALOR); txtValorTotalDet.Text = FormatarDecimal(total); } }
private void btnSalvar_Click(object sender, EventArgs e) { List <GastosTO> listaGastosSalvar = new List <GastosTO>(); ControlarTelaSalvar(); foreach (DataGridViewRow row in dgvGrid.Rows) { if (row == null) { continue; } GastosTO gasto = new GastosTO(); string local = String.Empty; string valor = String.Empty; string data = String.Empty; string tipoGasto = String.Empty; local = row.Cells["colLocal"].Value.ToString(); valor = row.Cells["colValor"].Value.ToString(); data = row.Cells["colData"].Value.ToString(); tipoGasto = row.Cells["colTipoGasto"].Value.ToString(); gasto.LOCAL = local; gasto.VALOR = Convert.ToDecimal(valor); gasto.DATA = OutrosUtil.StringToDate(data); gasto.ID_TIPO_GASTOS = Convert.ToInt32(tipoGasto); gasto.StatusBD = StatusTransacao.Insert; listaGastosSalvar.Add(gasto); } try { GastosBLL gastosBLL = new GastosBLL(); gastosBLL.Save(listaGastosSalvar); MessageBox.Show("Dados Salvos com Sucesso!"); IniciarTela(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/* * Recebe uma lista de gastos e preenche na grid */ private void preencherGrid(List <GastosTO> listaGastos) { dgvListaGastos.Rows.Clear(); //Alinhando texto à direita this.dgvListaGastos.Columns["colValor"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; this.dgvListaGastos.Columns["colData"].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight; foreach (var gasto in listaGastos) { dgvListaGastos.Rows.Add(gasto.ID_GASTOS, gasto.DATA.ToString("dd/MM/yyyy"), gasto.LOCAL, Convert.ToDecimal(OutrosUtil.FormatarDecimal(gasto.VALOR)), gasto.TIPO ); } }