protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { datosVeterinarios obj = (datosVeterinarios)Session["DataVeterinarios"]; if (obj != null) { txtbId.Text = obj.Id.ToString(); txtbNombre.Text = obj.Nombre; txtbApellidos.Text = obj.Apellidos; txtbEspecialidad.Text = obj.Especialidad; txtbFechaIngreso.Text = obj.Fecha_ingreso; txtbSalario.Text = obj.Salario.ToString(); txtbId.ReadOnly = true; btnInsertar.Text = "Actualizar"; } else { btnInsertar.Text = "Insertar"; } } } catch (Exception ex) { Response.Write("<script language=javascript> alert('" + ex.Message + "'); </script>"); } }
protected void btnInsertar_Click(object sender, EventArgs e) { datosVeterinarios obj = new datosVeterinarios(); obj = null; Session["DataVeterinarios"] = obj; Response.Redirect("veterinarios_insertar-actualizar.aspx"); }
protected void GridView_Veterinarios_RowCommand(object sender, GridViewCommandEventArgs e) { String respuesta; try { int index = Convert.ToInt32(e.CommandArgument); GridViewRow row = GridView_Veterinarios.Rows[index]; if (e.CommandName == "Editar") { datosVeterinarios obj = new datosVeterinarios() { Id = Convert.ToInt32(row.Cells[0].Text), Nombre = row.Cells[1].Text, Apellidos = row.Cells[2].Text, Especialidad = row.Cells[3].Text, Fecha_ingreso = row.Cells[4].Text, Salario = Convert.ToDecimal(row.Cells[5].Text) }; Session["DataVeterinarios"] = obj; Response.Redirect("veterinarios_insertar-actualizar.aspx"); } else if (e.CommandName == "Eliminar") { dynamic myObject = new ExpandoObject(); myObject.id = Convert.ToInt32(row.Cells[0].Text); string json = JsonConvert.SerializeObject(myObject); respuesta = client.eliminarVeterinarios("[" + json + "]"); if (respuesta.Equals("1")) { Response.Redirect("veterinarios.aspx"); } else { Response.Write("<script language=javascript> alert('" + respuesta + "'); </script>"); } } } catch (Exception ex) { Response.Write("<script language=javascript> alert('" + ex.Message + "'); </script>"); } }