예제 #1
0
 protected void btnCrearCliente_Click(object sender, EventArgs e)
 {
     if (GestionEmpleado.existeEmpleado(txtCrearIDEmpleadoCliente.Text))
     {
         if (!gestion.existeCliente(txtNumDocumentoCliente.Text))
         {
             Cliente nuevoCliente = new Cliente();
             nuevoCliente.DocumentoCliente           = txtNumDocumentoCliente.Text;
             nuevoCliente.NombreCliente              = txtNombreCliente.Text;
             nuevoCliente.ApellidoCliente            = txtApellidoCliente.Text;
             nuevoCliente.DireccionResidenciaCliente = txtDireccionResidenciaCliente.Text;
             if (txtTelefonoFijoCliente.Text == "")
             {
                 nuevoCliente.TelefonoFijoCliente = "Null";
             }
             else
             {
                 nuevoCliente.TelefonoFijoCliente = txtTelefonoFijoCliente.Text;
             }
             nuevoCliente.TelefonoCelularCliente          = txtTelefonoCelularCliente.Text;
             nuevoCliente.TipoDocumentoCliente            = listTipoDocumento.Text;
             nuevoCliente.FechaExpedicionDocumentoCliente = Convert.ToDateTime(txtFechaExpedicionCliente.Text);
             nuevoCliente.GeneroCliente           = listGeneroCliente.Text;
             nuevoCliente.CiudadNacimientoCliente = listCiudadNacimientoCliente.Text;
             if (txtDireccionTrabajoCliente.Text == "")
             {
                 nuevoCliente.DireccionTrabajoCliente = "Null";
             }
             else
             {
                 nuevoCliente.DireccionTrabajoCliente = txtDireccionTrabajoCliente.Text;
             }
             if (txtTelefonoTrabajoCliente.Text == "")
             {
                 nuevoCliente.TelefonoTrabajoCliente = "Null";
             }
             else
             {
                 nuevoCliente.TelefonoTrabajoCliente = txtTelefonoTrabajoCliente.Text;
             }
             nuevoCliente.EmpleoCliente = txtProfesionCliente.Text;
             nuevoCliente.IDEmpleado    = txtCrearIDEmpleadoCliente.Text;
             Login nuevoLogin = new Login();
             nuevoLogin.Usuario = txtNumDocumentoCliente.Text;
             nuevoLogin.Clave   = txtNumDocumentoCliente.Text;
             string tipoUsuario = "Cliente";
             if (gestion.InsertarCliente(nuevoCliente))
             {
                 if (gestionLogin.InsertarLogin(nuevoLogin, tipoUsuario))
                 {
                     ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "swal({title: 'Creado!', text: 'El Cliente se creo correctamente' ,icon: 'success', type: 'success'}).then(function() {window.location = 'BaseClientes.aspx';});", true);
                 }
                 else
                 {
                     ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "swal({title: 'Error!',text: 'No se pudo crear el Cliente, inténtalo más tarde', icon: 'error', timer: 1500,button: false}).then(function() { },function(dismiss) {if (dismiss === 'timer'){console.log('I was closed by the timer')}})", true);
                 }
             }
             else
             {
                 ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "swal({title: 'Error!',text: 'No se pudo crear el Cliente, inténtalo más tarde', icon: 'error', timer: 1500,button: false}).then(function() { },function(dismiss) {if (dismiss === 'timer'){console.log('I was closed by the timer')}})", true);
             }
         }
         else
         {
             ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "swal({title: 'Verifica!',text: 'El Número del Documento ya existe', icon: 'warning', timer: 2000,button: false}).then(function() { },function(dismiss) {if (dismiss === 'timer'){console.log('I was closed by the timer')}})", true);
             txtNumDocumentoCliente.Focus();
         }
     }
     else
     {
         ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert", "swal({title: 'Verifica!',text: 'El ID del Asesor no existe', icon: 'warning', timer: 2000,button: false}).then(function() { },function(dismiss) {if (dismiss === 'timer'){console.log('I was closed by the timer')}})", true);
         txtCrearIDEmpleadoCliente.Focus();
     }
 }