Example #1
0
 protected void btnAceptar_Click(object sender, EventArgs e)
 {
     Page.Validate();
     if (Page.IsValid)
     {
         try
         {
             if (CaptchaControl1.IsValid)
             {
                 string  pass = txtNombre.Text.Trim().ToLower() + DateTime.Now.GetHashCode().ToString().Replace("-", "").Trim();
                 Cliente cli  = new Cliente();
                 cli.Nombre       = txtNombre.Text.Trim();
                 cli.Apellido     = txtApellido.Text.Trim();
                 cli.CuitDni      = txtDNI.Text.Trim();
                 cli.Proveedor    = new Proveedor();
                 cli.Proveedor.Id = ((Proveedor)(Session["Proveedor"])).Id;
                 cli.Domicilio    = txtDomicilio.Text.Trim();
                 cli.Email        = txtEmail.Text.Trim();
                 cli.Telefonos    = txtTelefonos.Text.Trim();
                 Usuario usu = new Usuario();
                 usu.Nombre   = cli.CuitDni;
                 usu.Password = pass;
                 usu.Email    = cli.Email;
                 if (!String.IsNullOrEmpty(txtIdCliente.Value))
                 {
                     cli.Id = Convert.ToInt32(txtIdCliente.Value);
                     int result = FacadeDao.ActualizarCliente(cli);
                     if (result == 1)
                     {
                         Response.Redirect("MisClientes.aspx");
                     }
                     else if (result == -1 || result == -4)
                     {
                         throw (new Exception("Email existente"));
                     }
                     else if (result == -2 || result == -3)
                     {
                         throw (new Exception("Cuit ya registrado"));
                     }
                     else
                     {
                         throw (new Exception("Ocurrió un error en la actualización de clientes"));
                     }
                 }
                 else
                 {
                     int result = FacadeDao.CrearCliente(cli, usu);
                     if (result == 1)
                     {
                         FacadeDao.EnviarMail(cli.Email, "Alta de usuario en TravelPay", "Datos de ingreso a TravelPay web:<br><br>Usuario: " + usu.Nombre + "<br>Password: "******"Logo"], true);
                         Response.Redirect("MisClientes.aspx");
                     }
                     else if (result == -1 || result == -4)
                     {
                         throw (new Exception("Email existente"));
                     }
                     else if (result == -2 || result == -3)
                     {
                         throw (new Exception("Cuit ya registrado"));
                     }
                     else
                     {
                         throw (new Exception("Ocurrió un error en el alta de clientes"));
                     }
                 }
             }
             else
             {
                 throw (new Exception(CaptchaControl1.ErrorMessage));
             }
         }
         catch (Exception ex)
         {
             //Logger.EscribirEventLog(ex);
             string script = "<script>alert('" + ex.Message + "');</script>";
             ClientScript.RegisterStartupScript(this.GetType(), DateTime.Now.ToFileTime().ToString(), script);
         }
     }
 }
Example #2
0
 protected void btnDarDeAlta_Click(object sender, EventArgs e)
 {
     Page.Validate();
     if (Page.IsValid)
     {
         try
         {
             if (CaptchaControl1.IsValid)
             {
                 Usuario usu = new Usuario();
                 int     idProveedor;
                 string  redirect = "MisUsuarios.aspx";
                 if (Request.QueryString["Back"] == null)
                 {
                     idProveedor = ((Proveedor)(Session["Proveedor"])).Id;
                 }
                 else
                 {
                     redirect    = Request.QueryString["Back"] + ".aspx?IdProveedor=" + Request.QueryString["IdProveedor"];
                     idProveedor = Convert.ToInt32(Request.QueryString["IdProveedor"]);
                 }
                 string pass = txtNombre.Text.Trim().ToLower() + DateTime.Now.GetHashCode().ToString().Replace("-", "").Trim();
                 usu.Nombre      = txtNombre.Text.Trim();
                 usu.Password    = pass;
                 usu.Email       = txtEmail.Text.Trim();
                 usu.Rol         = Convert.ToInt32(cboRol.SelectedValue);
                 usu.IdProveedor = idProveedor;
                 int result = FacadeDao.CrearUsuario(usu);
                 if (result == 1)
                 {
                     FacadeDao.EnviarMail(usu.Email, "Alta de usuario en TravelPay", "Datos de ingreso a TravelPay web:<br><br>Usuario: " + usu.Nombre + "<br>Password: "******"Logo"], true);
                     if (Request.QueryString["Back"] == null)
                     {
                         Response.Redirect(redirect);
                     }
                     else
                     {
                         Response.Redirect(redirect);
                     }
                 }
                 else if (result == -1 || result == -4)
                 {
                     throw (new Exception("Email existente"));
                 }
                 else if (result == -2 || result == -3)
                 {
                     throw (new Exception("Cuit ya registrado"));
                 }
                 else
                 {
                     throw (new Exception("Ocurrió un error en el alta de usuarios"));
                 }
             }
             else
             {
                 throw (new Exception(CaptchaControl1.ErrorMessage));
             }
         }
         catch (Exception ex)
         {
             string script = "<script>alert('" + ex.Message + "');</script>";
             ClientScript.RegisterStartupScript(this.GetType(), DateTime.Now.ToFileTime().ToString(), script);
             //Logger.EscribirEventLog(ex);
         }
     }
 }