protected void btnCadastrar_Click(object sender, EventArgs e) { string nomeCond = txtNome.Text; string idadeCond = txtIdade.Text; string cpfCond = txtCpf.Text; string blocoCond = DDLBloco.Text; string aptoCond = DDLApartamento.Text; TB_MORADOR v = new TB_MORADOR() { nome = nomeCond, idade = idadeCond, cpf = cpfCond, bloco = blocoCond, apto = aptoCond }; ControleCondDBEntities contextCond = new ControleCondDBEntities(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { contextCond.TB_MORADOR.Add(v); lblmsg.Text = "Registro Inserido!"; Clear(); } else { int id = Convert.ToInt32(valor); TB_MORADOR cond = contextCond.TB_MORADOR.First(c => c.id == id); cond.nome = v.nome; cond.idade = v.idade; cond.cpf = v.cpf; cond.bloco = v.bloco; cond.apto = v.apto; lblmsg.Text = "Registro Alterado"; } contextCond.SaveChanges(); CarregarLista(); }
protected void btnCadastrar_Click(object sender, EventArgs e) { string blocoCond = txtBloco.Text; string aptoCond = txtQtdApto.Text; string andarCond = txtQtdAndar.Text; string moradoresCond = txtTotalMoradores.Text; TB_BLOCO v = new TB_BLOCO() { numero_bloco = blocoCond, qtd_apartamentos = aptoCond, qtd_andar = andarCond, total_moradores = moradoresCond }; ControleCondDBEntities contextCond = new ControleCondDBEntities(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { contextCond.TB_BLOCO.Add(v); lblmsg.Text = "Registro Inserido!"; Clear(); } else { int id = Convert.ToInt32(valor); TB_BLOCO cond = contextCond.TB_BLOCO.First(c => c.id == id); cond.numero_bloco = v.numero_bloco; cond.qtd_apartamentos = v.qtd_apartamentos; cond.qtd_andar = v.qtd_andar; cond.total_moradores = v.total_moradores; lblmsg.Text = "Registro Alterado"; } contextCond.SaveChanges(); CarregarLista(); }
protected void btnCadastrar_Click(object sender, EventArgs e) { string aptoCond = txtApto.Text; string moradoresCond = txtMoradores.Text; string blocoCond = DDLBloco.Text; TB_APARTAMENTO v = new TB_APARTAMENTO() { numero_apto = aptoCond, qtd_moradores = moradoresCond, bloco = blocoCond }; ControleCondDBEntities contextCond = new ControleCondDBEntities(); string valor = Request.QueryString["idItem"]; if (String.IsNullOrEmpty(valor)) { contextCond.TB_APARTAMENTO.Add(v); lblmsg.Text = "Registro Inserido!"; Clear(); } else { int id = Convert.ToInt32(valor); TB_APARTAMENTO cond = contextCond.TB_APARTAMENTO.First(c => c.id == id); cond.numero_apto = v.numero_apto; cond.qtd_moradores = v.qtd_moradores; cond.bloco = v.bloco; lblmsg.Text = "Registro Alterado"; } contextCond.SaveChanges(); CarregarLista(); }
protected void GVBloco_RowCommand(object sender, GridViewCommandEventArgs e) { int idItem = Convert.ToInt32(e.CommandArgument.ToString()); ControleCondDBEntities contextBloco = new ControleCondDBEntities(); TB_BLOCO bloco = new TB_BLOCO(); bloco = contextBloco.TB_BLOCO.First(c => c.id == idItem); if (e.CommandName == "ALTERAR") { Response.Redirect("CadastroBloco.aspx?idItem=" + idItem); } else if (e.CommandName == "EXCLUIR") { contextBloco.TB_BLOCO.Remove(bloco); contextBloco.SaveChanges(); string msg = "Excluída com sucesso !"; string titulo = "Informação"; CarregarLista(); DisplayAlert(titulo, msg, this); } }