private void btn_salvar_Click(object sender, EventArgs e) { this.EtapaBLL = new EtapaBLL(); //Alterar e cadastrar etapa = new Etapa(); if (txt_codigo.Text != "") { etapa.IdEtapa = int.Parse(txt_codigo.Text); } //Para calendario: value etapa.DataInicio = dt_datainicio.Value; etapa.DataFim = dt_datafinal.Value; //SelectValue para caixa de seleção etapa.IdTipoEntrega = (int)cb_tipoentrega.SelectedValue; //Text para caixa de texto //Se o tipo for object (int) //Se for text int.Parse(texto) try { etapa.NotaMinima = decimal.Parse(txt_notaminima.Text); }catch (Exception ex) { MessageBox.Show("Nota miníma deve ser um decimal"); return; } var erro = EtapaBLL.Salvar(etapa); if (erro != null) { MessageBox.Show("Erro ao salvar: " + erro); } else { MessageBox.Show("Salvo com sucesso."); CarregarTabela(); //Limpa os campos txt_notaminima.Clear(); dt_datainicio.ResetText(); dt_datafinal.ResetText(); cb_tipoentrega.SelectedIndex = 0; } this.UsuarioBLL.Dispose(); }
public void CarregarTabela() { this.EtapaBLL = new EtapaBLL(); tabela.DataSource = EtapaBLL.Todas().Select(x => new { x.IdEtapa, TipoEntrega = x.TipoEntrega.Descricao, x.DataInicio, x.DataFim, x.NotaMinima }).ToList(); this.EtapaBLL.Dispose(); }
private void btn_editar_Click(object sender, EventArgs e) { this.UsuarioBLL = new EtapaBLL(); int idEtapa = (int)tabela.CurrentRow.Cells[0].Value; Etapa etapa = EtapaBLL.ObterPorId(idEtapa); dt_datafinal.Value = etapa.DataFim; dt_datainicio.Value = etapa.DataInicio; cb_tipoentrega.SelectedValue = etapa.IdTipoEntrega; txt_notaminima.Text = etapa.NotaMinima.ToString(); txt_codigo.Text = etapa.IdEtapa.ToString(); this.UsuarioBLL.Dispose(); }