/// <summary> /// EVento que nos permite agregar un contacto a la BD /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void addContac(object sender, EventArgs e) { if (this.IsPostBack) { this.Validate(); if (this.IsValid) { ServicioGestionClient proxy = new ServicioGestionClient(); /** Objeto Contacto **/ ContactoData objetoContacto = new ContactoData(); objetoContacto.nombre = this.nomb.Text; objetoContacto.nif = this.nf.Text; objetoContacto.idEmpresa = Convert.ToInt32(Request.QueryString["id"]); /** Fin objeto Contacto **/ ContactoData contacto = proxy.getContactoNif(objetoContacto.nif); if (contacto == null) { int res=proxy.AddContacto(objetoContacto); if (res != -1) { int idEmpresa = Convert.ToInt32(Request.QueryString["id"]); Response.Redirect("gestionContacto.aspx?id=" + idEmpresa); } else { this.lblError.Visible = true; this.lblError.Text = "No se guardaron los datos, error de acceso al servicio"; } } else { this.lblError.Visible = true; this.lblError.Text = "No se puede insertar este contacto. El N.I.F. ya existe en la base de datos."; } } // Fin del if (this.IsValid) }// Fin del if (this.IsPostBack) }
protected void Page_Load(object sender, EventArgs e) { usu = new Usuario(); usuData = new UsuarioData(); conData = new ContactoData(); usu = usuData.getUsuarioById(Int16.Parse(Request.QueryString["id"])); if (usu.Id == 0) { Response.Redirect("Default.aspx"); } else { lblUsuario.InnerText = usu.Apellido + " " + usu.Nombre; hdfId.Value = Request.QueryString["id"]; contactos = conData.consultarByUserId(Int16.Parse(Request.QueryString["id"])); Contacto[] cons = contactos.ToArray(); Response.Write("<table border=1>"); Response.Write("<tr>"); Response.Write("<th>Primer Apellido</th>"); Response.Write("<th>Primer Nombre</th>"); Response.Write("<th>Direccion</th>"); Response.Write("<th>Telefono</th>"); Response.Write("<th>Mail</th>"); Response.Write("<th colspan=2>Acciones</th>"); Response.Write("</tr>"); for (int x = 0; x < contactos.Count; x++) { Response.Write("<tr>"); Response.Write("<td>" + cons[x].PrimerApellido + "</td>"); Response.Write("<td>" + cons[x].PrimerNombre + "</td>"); Response.Write("<td>" + cons[x].Direccion + "</td>"); Response.Write("<td>" + cons[x].Telefono + "</td>"); Response.Write("<td>" + cons[x].Mail + "</td>"); Response.Write("<td><a href='Editar.aspx?id=" + cons[x].Id + "'>Editar</a></td>"); Response.Write("<td><a href='Borrar.aspx?id=" + cons[x].Id + "'>Borrar</a></td>"); Response.Write("</tr>"); } Response.Write("<tr>"); Response.Write("<td colspan=8><a href='Agregar.aspx'>Agregar</a></td>"); Response.Write("</tr>"); Response.Write("<table>"); } }