Пример #1
0
        protected void btnRegistrar_Click(object sender, EventArgs e)
        {
            _log.CustomWriteOnLog("RegistrarMoldura", "-------------------------------------------------------------Evento Click-----------------------");
            _log.CustomWriteOnLog("RegistrarMoldura", "Entró a evento de Registro ");
            try
            {
                if (true)
                {
                    if (txtAncho.Text == "" | txtLargo.Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'Complete las MEDIDAS!!'})", true);
                        return;
                    }
                    else if (txtDescripcion.Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'Inserte una DESCRIPCIÓN!!'})", true);
                        return;
                    }
                    else if (txtPrecio.Text.Contains("e"))
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'No se admiten letras en el Precio!!'})", true);
                        return;
                    }
                    else if (txtAncho.Text.Contains("e") | txtLargo.Text.Contains("e"))
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'No se admiten letras en las medidas!!'})", true);
                        return;
                    }
                    else if (double.Parse(txtPrecio.Text) <= 0)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'Inserte un PRECIO VALIDO!!'})", true);
                        return;
                    }
                    else if (double.Parse(txtAncho.Text) <= 0 | double.Parse(txtLargo.Text) <= 0)
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'Inserte un Medidas VALIDAS!!'})", true);
                        return;
                    }
                    else if (txtPrecio.Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'Inserte un PRECIO!!'})", true);
                        return;
                    }
                    else if (txtStock.Text == "")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'Inserte STOCK!!'})", true);
                        return;
                    }
                    else if (ddlEstadoMoldura.ToString() == "--Seleccione--" | ddlTipoMoldura.ToString() == "Seleccione")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'Selecciones un TIPO DE MOLDURA o ESTADO!!'})", true);
                        return;
                    }
                    else if (hftxtimg.Value.ToString() == "vacio")
                    {
                        ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type:'error',title:'ERROR!',text:'Inserte una IMAGEN!!'})", true);
                        return;
                    }
                    string      cadena  = hftxtimg.Value.ToString();
                    List <byte> imagen  = Array.ConvertAll(cadena.Split(','), byte.Parse).ToList();
                    byte[]      bimagen = imagen.ToArray();

                    _log.CustomWriteOnLog("RegistrarMoldura", "La función es de creación");
                    objDtoMoldura.DM_Precio = double.Parse(txtPrecio.Text);
                    _log.CustomWriteOnLog("RegistrarMoldura", "DM_Precio valor ingresado " + objDtoMoldura.DM_Precio);
                    objDtoMoldura.IM_Estado = int.Parse(ddlEstadoMoldura.SelectedValue);
                    _log.CustomWriteOnLog("RegistrarMoldura", "IM_Estado valor ingresado " + objDtoMoldura.IM_Estado);
                    objDtoMoldura.IM_Stock = int.Parse(txtStock.Text);
                    _log.CustomWriteOnLog("RegistrarMoldura", "IM_Stock valor ingresado " + objDtoMoldura.IM_Stock);
                    objDtoMoldura.FK_ITM_Tipo = int.Parse(ddlTipoMoldura.SelectedValue);
                    _log.CustomWriteOnLog("RegistrarMoldura", "FK_ITM_Tipo valor ingresado " + objDtoMoldura.FK_ITM_Tipo);
                    objDtoMoldura.VM_Descripcion = txtDescripcion.Text;
                    _log.CustomWriteOnLog("RegistrarMoldura", "VM_Descripcion valor ingresado " + objDtoMoldura.VM_Descripcion);
                    objDtoMoldura.DM_Largo = Double.Parse(txtLargo.Text);
                    _log.CustomWriteOnLog("RegistrarMoldura", "DM_Largo valor ingresado " + objDtoMoldura.DM_Largo);
                    objDtoMoldura.DM_Ancho = Double.Parse(txtAncho.Text);
                    _log.CustomWriteOnLog("RegistrarMoldura", "DM_Ancho valor ingresado " + objDtoMoldura.DM_Ancho);
                    objCtrMoldura.InsertMoldura(objDtoMoldura);
                    int ValorDevuelto = objDtoMoldura.PK_IM_Cod;
                    _log.CustomWriteOnLog("RegistrarMoldura", "Registro exitoso de la moldura N° " + objDtoMoldura.PK_IM_Cod);

                    objCtrMoldura.registrarImgMoldura(bimagen, ValorDevuelto);
                    ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "mensaje", "swal({type: 'success',title: 'Moldura registrada!',text: 'Datos ENVIADOS!!'}).then(function(){window.location.href='Gestionar_Catalogo.aspx'})", true);
                }
            }
            catch (Exception ex)
            {
                _log.CustomWriteOnLog("RegistrarMoldura", "Error  = " + ex.Message + "posicion" + ex.StackTrace);
                throw;
            }
        }