protected void ButtonEnviar_Click(object sender, EventArgs e) { if (Page.IsValid) { ENClientes en = new ENClientes(); en.Nombre = TextBoxNombre.Text; en.Apellido1 = TextBoxApellido1.Text; en.Nif = TextBoxNif.Text; en.IdProvincia = int.Parse(DropDownList2.SelectedValue); en.IdPais = int.Parse(DropDownList1.SelectedValue); en.Email = TextBoxEmail.Text; en.Contrasena = TextBoxContrasena.Text; en.Puntos = 0; en.Apellido2 = TextBoxApellido2.Text; en.Direccion = TextBoxDireccion.Text; en.Cp = TextBoxCp.Text; en.Poblacion = TextBoxPoblacion.Text; if (en.InsertarCliente()) { Session["usuario"] = en.Email; Session["Nombre"] = en.Nombre; Session["Apellido1"] = en.Apellido1; Session["Apellido2"] = en.Apellido2; Session["IdUsuario"] = en.Id; Response.Redirect("registro-correcto.aspx"); } } }
protected void ButtonModificar_Click(object sender, EventArgs e) { if (Page.IsValid) { ENClientes a = new ENClientes(); a.Nombre = TextBoxNombre.Text; a.Apellido1 = TextBoxApellido1.Text; a.Apellido2 = TextBoxApellido2.Text; a.Nif = TextBoxNif.Text; a.Direccion = TextBoxDireccion.Text; a.Cp = TextBoxCp.Text; a.Poblacion = TextBoxPoblacion.Text; a.IdProvincia = int.Parse(DropDownList2.SelectedValue); a.IdPais = int.Parse(DropDownList1.SelectedValue); a.Email = TextBoxEmail.Text; a.Contrasena = TextBoxContrasena.Text; if (a.ModificarCliente(int.Parse(Session["IdUsuario"].ToString()))) { Session["usuario"] = a.Email; Session["Nombre"] = a.Nombre; Session["Apellido1"] = a.Apellido1; Session["Apellido2"] = a.Apellido2; Response.Redirect("registro-correcto.aspx"); } } }
protected void ButtonPedido_Click(object sender, EventArgs e) { if (Session["IdUsuario"]==null) { Response.Redirect("registro-cliente.aspx"); } else if (int.Parse(Session["IdUsuario"].ToString()) == 0) { Response.Redirect("registro-cliente.aspx"); } ENClientes c = new ENClientes(); c = c.ObtenerClientePorId(int.Parse(Session["IdUsuario"].ToString())); ENPedidos p = new ENPedidos(); p.IdCliente=int.Parse(Session["IdUsuario"].ToString()); p.Nombre=c.Nombre; p.NIF=c.Nif; p.Direccion=c.Direccion; p.CP=c.Cp; p.Poblacion=c.Poblacion; p.IdProvincia=c.IdProvincia; p.IdPais=c.IdPais; p.BaseImp=subtotal; p.Impiva=IVA; p.Total=total; p.Fecha = DateTime.Now; ENCarro carro=new ENCarro(); p.InsertarPedido(p, carro.ObtenerLineasCarro(Session.SessionID), Session.SessionID); carro.BorrarCarroCliente(Session.SessionID); Response.Redirect("listado-compras.aspx"); }
protected void ComprobarUsuario(object sender, ServerValidateEventArgs e) { ENClientes en = new ENClientes(); en.Email = TextBoxEmail.Text; if (en.ExisteCliente(en)) e.IsValid = false; else e.IsValid = true; }
public bool ExisteCliente(ENClientes cli) { bool a = false; SqlConnection r = new SqlConnection(cadenaConexion()); try { r.Open(); SqlCommand com = new SqlCommand("Select * from clientes where Email='" + cli.Email + "'", r); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { cli.Id = int.Parse(dr["Id"].ToString()); cli.Nombre = dr["Nombre"].ToString(); cli.Apellido1 = dr["Apellido1"].ToString(); cli.Apellido2 = dr["Apellido2"].ToString(); cli.Nif = dr["NIF"].ToString(); cli.Direccion = dr["Direccion"].ToString(); cli.Poblacion = dr["Poblacion"].ToString(); cli.IdProvincia = int.Parse(dr["IdProvincia"].ToString()); cli.IdPais = int.Parse(dr["IdPais"].ToString()); cli.Email = dr["Email"].ToString(); cli.Cp = dr["CP"].ToString(); cli.Puntos = int.Parse(dr["Puntos"].ToString()); cli.Contrasena = dr["Contrasena"].ToString(); a = true; } else { a = false; } dr.Close(); } catch (Exception ex) { a = false; } finally { r.Close(); } return a; }
public int CogerId(ENClientes c) { int auxs = -1; SqlConnection a = new SqlConnection(cadenaConexion()); a.Open(); SqlCommand com = new SqlCommand("Select Id from clientes where Email='" + c.Email + "' and Nombre='" + c.Nombre + "' and Apellido1='" + c.Apellido1 + "' and Apellido2='" + c.Apellido2 + "' and Contrasena='" + c.Contrasena + "' and NIF='" + c.Nif + "'", a); SqlDataReader dr = com.ExecuteReader(); if(dr.Read()) { auxs = int.Parse(dr["Id"].ToString()); } dr.Close(); a.Close(); return auxs; }
protected void ButtonBaja_Click(object sender, EventArgs e) { if ((string)Session["usuario"] != null) { ENClientes auz = new ENClientes(); auz = auz.ObtenerClientePorId(int.Parse(Session["IdUsuario"].ToString())); if (auz.BorrarCliente(auz.Id)) { Session["IdUsuario"] = null; Session["usuario"] = null; Session["Nombre"] = null; Session["Apellido1"] = null; Session["Apellido2"] = null; Response.Redirect("index.aspx"); } } else { Response.Redirect("modificar-cliente.aspx"); } }
public bool BorrarCliente(ENClientes c,int i) { bool a; SqlConnection r = new SqlConnection(cadenaConexion()); try { r.Open(); SqlCommand com = new SqlCommand("Delete from clientes where Id=" + i, r); com.ExecuteNonQuery(); a = true; } catch (Exception ex) { a = false; } finally { r.Close(); } return a; }
protected void ButtonEnviar_Click(object sender, EventArgs e) { Aplicacion.Idiomas id = new Aplicacion.Idiomas((string)Session["idioma"]); ENClientes en = new ENClientes(); en.Email = TextBoxEmail.Text; if (en.ExisteCliente(en)) { SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 587); MailMessage message = new MailMessage(); try { MailAddress fromAddress = new MailAddress("*****@*****.**", "BicisUA"); MailAddress toAddress = new MailAddress(en.Email.ToString(), en.Nombre.ToString()); message.From = fromAddress; message.To.Add(toAddress); message.Subject = "Recuperar contraseña/Recover Password"; message.Body = "Hola, " + en.Nombre.ToString() + ", " + en.Apellido1.ToString() + " ha solicitado el recordatorio de su contraseña. Su contraseña es: " + en.Contrasena.ToString() + "/Hello, " + en.Nombre.ToString() + ", " + en.Apellido1.ToString() + " has requested the password reminder. Your password is: " + en.Contrasena.ToString(); smtpClient.EnableSsl = true; smtpClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "universidadalicante"); smtpClient.Send(message); LabelInEmailE.Text = id.Traducir("enviocorrecto"); } catch (Exception ex) { LabelInEmailE.Text = id.Traducir("envioincorrecto"); } } else { LabelInEmailE.Text = id.Traducir("envioincorrecto"); } }
public ENClientes ObtenerClientePorId(int id) { SqlConnection a = new SqlConnection(cadenaConexion()); ENClientes cli = new ENClientes(); try { a.Open(); SqlCommand com = new SqlCommand("Select * from clientes where Id='" + id + "'", a); SqlDataReader dr = com.ExecuteReader(); if (dr.Read()) { cli.Id = int.Parse(dr["Id"].ToString()); cli.Nombre = dr["Nombre"].ToString(); cli.Apellido1 = dr["Apellido1"].ToString(); cli.Apellido2 = dr["Apellido2"].ToString(); cli.Nif = dr["NIF"].ToString(); cli.Direccion = dr["Direccion"].ToString(); cli.Poblacion = dr["Poblacion"].ToString(); cli.IdProvincia = int.Parse(dr["IdProvincia"].ToString()); cli.IdPais = int.Parse(dr["IdPais"].ToString()); cli.Email = dr["Email"].ToString(); cli.Cp = dr["CP"].ToString(); cli.Puntos = int.Parse(dr["Puntos"].ToString()); cli.Contrasena = dr["Contrasena"].ToString(); } dr.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { a.Close(); } return cli; }
public ENClientes ObtenerClientePorEmail(string email) { SqlConnection a = new SqlConnection(cadenaConexion()); ENClientes cli = new ENClientes(); try { System.Diagnostics.Debug.WriteLine("estamos den del try en el cad y el email es " + email); a.Open(); SqlCommand com = new SqlCommand("Select * from clientes where Email='" + email + "'", a); SqlDataReader dr = com.ExecuteReader(); //System.Diagnostics.Debug.WriteLine("Select * from clientes where Email='" + email + "'"); if (dr.Read()) { //System.Diagnostics.Debug.WriteLine("siii hay resultado "); cli.Id = int.Parse(dr["Id"].ToString()); cli.Nombre = dr["Nombre"].ToString(); cli.Apellido1 = dr["Apellido1"].ToString(); cli.Apellido2 = dr["Apellido2"].ToString(); cli.Nif = dr["NIF"].ToString(); cli.Direccion = dr["Direccion"].ToString(); cli.Poblacion = dr["Poblacion"].ToString(); cli.IdProvincia = int.Parse(dr["IdProvincia"].ToString()); cli.IdPais = int.Parse(dr["IdPais"].ToString()); cli.Email = dr["Email"].ToString(); cli.Contrasena = dr["Contrasena"].ToString(); //System.Diagnostics.Debug.WriteLine("hay resultado " + email); } else { System.Diagnostics.Debug.WriteLine("no hay resultado " + cli.Email); } dr.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { a.Close(); } return cli; }
public bool ModificarCliente(ENClientes c,int i) { bool a; SqlConnection r = new SqlConnection(cadenaConexion()); try { r.Open(); SqlCommand com = new SqlCommand("Update clientes set Nombre='" + c.Nombre + "', Apellido1='" + c.Apellido1 + "', Apellido2='" + c.Apellido2 + "', NIF='" + c.Nif + "', Direccion='" + c.Direccion + "', CP='" + c.Cp + "', Poblacion='" + c.Poblacion + "', IdProvincia=" + c.IdProvincia + ", IdPais=" + c.IdPais + ", Puntos=" + c.Puntos + ", Email='" + c.Email + "', Contrasena='" + c.Contrasena + "' where Id=" + i, r); com.ExecuteNonQuery(); a = true; } catch (Exception ex) { a = false; } finally { r.Close(); } return a; }
public bool InsertarCliente(ENClientes c) { bool correct; DataSet bdvirtual = new DataSet(); SqlConnection a = new SqlConnection(cadenaConexion()); try { SqlDataAdapter da = new SqlDataAdapter("select * from clientes", a); da.Fill(bdvirtual, "clientes"); DataTable t = new DataTable(); t = bdvirtual.Tables["clientes"]; DataRow nuevafila = t.NewRow(); nuevafila[1] = c.Nombre; nuevafila[2] = c.Apellido1; nuevafila[3] = c.Apellido2; nuevafila[4] = c.Nif; nuevafila[5] = c.Direccion; nuevafila[6] = c.Cp; nuevafila[7] = c.Poblacion; nuevafila[8] = c.IdProvincia; nuevafila[9] = c.IdPais; nuevafila[10] = c.Puntos; nuevafila[11] = c.Email; nuevafila[12] = c.Contrasena; t.Rows.Add(nuevafila); SqlCommandBuilder cbuilder = new SqlCommandBuilder(da); da.Update(bdvirtual, "clientes"); correct = true; } catch (Exception ex) { correct = false; } return correct; }
protected void Page_Load(object sender, EventArgs e) { Aplicacion.Idiomas id = new Aplicacion.Idiomas((string)Session["idioma"]); //Taducciones Normales LabelNombre.Text = id.Traducir("nombre"); LabelNombreV.Text = id.Traducir("nombreV"); LabelApellido1.Text = id.Traducir("apellido1"); LabelApellido1V.Text = id.Traducir("apellido1V"); LabelApellido2V.Text = id.Traducir("apellido2"); LabelApellido2.Text = id.Traducir("apellido2"); LabelDirreccionV.Text = id.Traducir("direccion"); LabelPoblacionV.Text = id.Traducir("poblacion"); LabelDirreccion.Text = id.Traducir("direccion"); LabelPoblacion.Text = id.Traducir("poblacion"); LabelProvincia.Text = id.Traducir("provincia"); LabelPais.Text = id.Traducir("pais"); LabelContrasena3.Text = id.Traducir("contrasena3"); LabelContrasena.Text = id.Traducir("contrasena1"); LabelContrasena2.Text = id.Traducir("contrasena2"); LabelAviso.Text = id.Traducir("aviso"); //Traducciones de control de Validacion CompareValidatorContrasena.ErrorMessage = id.Traducir("errorcontrasena"); RequiredFieldValidatorContrasena.ErrorMessage = id.Traducir("errorcontrasena2"); RequiredFieldValidatorContrasena2.ErrorMessage = id.Traducir("errorcontrasena2"); RequiredFieldValidatorEmail.ErrorMessage = id.Traducir("erroremail2"); RequiredFieldValidatorNombre.ErrorMessage = id.Traducir("errornombre"); RequiredFieldValidatorApellido.ErrorMessage = id.Traducir("errorapellido"); RequiredFieldValidatorNif.ErrorMessage = id.Traducir("errornif"); RegularExpressionValidatorEmail.ErrorMessage = id.Traducir("erroremail"); RegularExpressionValidatorCp.ErrorMessage = id.Traducir("errorcp"); //Taducciones de botones ButtonEnviarRegistro.Text = id.Traducir("botonmodificar"); ButtonBaja.Text = id.Traducir("baja"); if ((string)Session["usuario"] != null) { ENClientes auz = new ENClientes(); auz = auz.ObtenerClientePorId(int.Parse(Session["IdUsuario"].ToString())); LabelNombreV1.Text = auz.Nombre; LabelApellido1V1.Text = auz.Apellido1; LabelApellido2V1.Text = auz.Apellido2; LabelNifV1.Text = auz.Nif; LabelEmailV1.Text = auz.Email; LabelContrasena3V1.Text = auz.Contrasena; LabelDirreccionV1.Text = auz.Direccion; LabelCpV1.Text = auz.Cp; LabelPoblacionV1.Text = auz.Poblacion; } else { Response.Redirect("registro-incorrecto.aspx"); } }
public bool ExisteCliente(ENClientes c) { CADClientes aux = new CADClientes(); return aux.ExisteCliente(c); }