protected void btnEditar_Click(object sender, EventArgs e) { if (numero.Text == "") { mensagem = "O Numero do ramal é obrigatorio"; ClientScript.RegisterStartupScript(GetType(), "Popup", "erroGeral();", true); numero.Focus(); } else { try { int cod = int.Parse(ramalID); tarifadorEntities ctx = new tarifadorEntities(); ramal ra = ctx.ramals.First(p => p.id == cod); ra.numero = numero.Text.Trim(); ra.grupoRamalID = int.Parse(cboxGrupoRamais.SelectedValue); ra.usuarioID = int.Parse(cboxUsuario.SelectedValue); ra.observacao = observacao.Text.Trim(); ctx.SaveChanges(); ClientScript.RegisterStartupScript(GetType(), "Popup", "sucesso();", true); } catch (Exception) { ClientScript.RegisterStartupScript(GetType(), "Popup", "erro();", true); throw; } } }
protected void btnExcluir_Click(object sender, EventArgs e) { if (Session["perfil"].ToString() != "administrador") { ScriptManager.RegisterStartupScript(this, GetType(), "Popup", "acessoNegado();", true); } else { try { ramalID = int.Parse((sender as LinkButton).CommandArgument); tarifadorEntities ctx = new tarifadorEntities(); ramal ra = ctx.ramals.First(p => p.id == ramalID); ctx.ramals.Remove(ra); ctx.SaveChanges(); getRamais(); ClientScript.RegisterStartupScript(GetType(), "Popup", "sucesso();", true); } catch (Exception) { ClientScript.RegisterStartupScript(GetType(), "Popup", "erro();", true); throw; } } }
private void getRamais(int cod) { tarifadorEntities ctx = new tarifadorEntities(); ramal ra = ctx.ramals.First(p => p.id == cod); numero.Text = ra.numero; cboxGrupoRamais.SelectedValue = Convert.ToString(ra.grupoRamalID); cboxUsuario.SelectedValue = Convert.ToString(ra.usuarioID); }