protected void btnCadastrar_Click(object sender, EventArgs e) { string descricaoProjeto = txtDescricao.Text; DateTime datainicio = Convert.ToDateTime(txtdatainicio.Text); DateTime dataimplantacao = Convert.ToDateTime(txtdataimplantacao.Text); DateTime datateste = Convert.ToDateTime(txtdatateste.Text); int qtdpessoa = Convert.ToInt32(txtQtdPessoas.Text); string telefone1 = txtTelefone1.Text; string telefone2 = txtTelefone2.Text; string observacao = txtobservacao.Text; TB_PROJETO v = new TB_PROJETO() { descricao = descricaoProjeto, dt_implantacao = dataimplantacao, dt_ini_proj = datainicio, dt_teste = datateste, observacao = observacao, contato_tel1 = telefone1, contato_tel2 = telefone2, qtd_pessoas = qtdpessoa }; TarefasDBEntities contextProjeto = new TarefasDBEntities(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { contextProjeto.TB_PROJETO.Add(v); lblmsg.Text = "Registro Inserido!"; Clear(); } else { int id = Convert.ToInt32(valor); TB_PROJETO projeto = contextProjeto.TB_PROJETO.First(c => c.id == id); projeto.descricao = v.descricao; projeto.dt_ini_proj = v.dt_ini_proj; projeto.dt_implantacao = v.dt_implantacao; projeto.dt_teste = v.dt_teste; projeto.contato_tel1 = v.contato_tel1; projeto.contato_tel2 = v.contato_tel2; projeto.observacao = v.observacao; projeto.qtd_pessoas = v.qtd_pessoas; lblmsg.Text = "Registro Alterado!"; } contextProjeto.SaveChanges(); }
private void CarregarDadosPagina() { string valor = Request.QueryString["idItem"]; int idItem = 0; TB_PROJETO v = new TB_PROJETO(); TarefasDBEntities contextProjeto = new TarefasDBEntities(); if (!String.IsNullOrEmpty(valor)) { idItem = Convert.ToInt32(valor); v = contextProjeto.TB_PROJETO.First(c => c.id == idItem); txtdataimplantacao.Text = v.dt_implantacao.ToString(); txtdatainicio.Text = v.dt_ini_proj.ToString(); txtdatateste.Text = v.dt_teste.ToString(); txtQtdPessoas.Text = Convert.ToString(v.qtd_pessoas); txtTelefone1.Text = v.contato_tel1; txtTelefone2.Text = v.contato_tel2; txtDescricao.Text = v.descricao; } }
protected void GVProjeto_RowCommand(object sender, GridViewCommandEventArgs e) { int idItem = Convert.ToInt32(e.CommandArgument.ToString()); TarefasDBEntities context = new TarefasDBEntities(); TB_PROJETO projeto = new TB_PROJETO(); projeto = context.TB_PROJETO.First(c => c.id == idItem); if (e.CommandName == "ALTERAR") { Response.Redirect("Projeto.aspx?idItem=" + idItem); } else if (e.CommandName == "EXCLUIR") { context.TB_PROJETO.Remove(projeto); context.SaveChanges(); string msg = "Projeto excluida com sucesso!"; string titulo = "Informação"; CarregarLista(); DisplayAlert(titulo, msg, this); } }