protected void btnGuardar_Click(object sender, EventArgs e)
    {
        try
        {
            if (FileUpload1.HasFile == false)
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "showNotification", "showNotification('bg-red', 'Debe agregar una imagen valida', 'bottom', 'center', null, null);", true);
            }
            else
            {
                //string FileName = FileUpload1.FileName;
                //UploadDetails.Text = string.Format(
                //        @"Uploaded file: {0}<br />
                // File size (in bytes): {1:N0}<br />
                // Content-type: {2}",
                //          FileName,
                //          FileUpload1.FileBytes.Length,
                //          FileUpload1.PostedFile.ContentType);

                //Save the file
                //string filePath = Server.MapPath("~/Brochures/" + FileUpload1.FileName);
                //FileUpload1.SaveAs(filePath);
                HttpPostedFile postedFile    = FileUpload1.PostedFile;
                string         FileName      = Path.GetFileName(postedFile.FileName);
                string         fileExtension = Path.GetExtension(postedFile.FileName);
                int            fileSize      = postedFile.ContentLength;
                _log.CustomWriteOnLog("PropiedadMoldura_aspx", "txtTipoMoldura = " + ddlTipoMoldura.SelectedValue);
                _log.CustomWriteOnLog("PropiedadMoldura_aspx", "ddlEstadoMoldura = " + ddlEstadoMoldura.SelectedValue);
                _log.CustomWriteOnLog("PropiedadMoldura_aspx", "txtStock = " + txtStock.Text);
                _log.CustomWriteOnLog("PropiedadMoldura_aspx", "txtPrecio = " + txtPrecio.Text);

                if (fileExtension.ToLower() == ".jpg" || fileExtension.ToLower() == ".bmp" || fileExtension.ToLower() == ".gif" || fileExtension.ToLower() == ".png")
                {
                    Stream       stream       = postedFile.InputStream;
                    BinaryReader binaryReader = new BinaryReader(stream);
                    byte[]       bytes        = binaryReader.ReadBytes((int)stream.Length);
                    objDtoMoldura.VBM_Imagen     = bytes;
                    objDtoMoldura.DM_Precio      = Double.Parse(txtPrecio.Text);
                    objDtoMoldura.IM_Estado      = int.Parse(ddlEstadoMoldura.SelectedValue);
                    objDtoMoldura.IM_Stock       = int.Parse(txtStock.Text);
                    objDtoMoldura.FK_ITM_Tipo    = int.Parse(ddlTipoMoldura.SelectedValue);
                    objDtoMoldura.VM_Descripcion = txtDescripcion.Text;
                    objDtoMoldura.DM_Medida      = Double.Parse(txtMedida.Text);

                    objCtrMoldura.registrarNuevaMoldura(objDtoMoldura);
                    _log.CustomWriteOnLog("PropiedadMoldura_aspx", "Agregado");
                    ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "showNotification", "showNotification('bg-red', 'Agregado', 'bottom', 'center', null, null);", true);
                }
            }
        }
        catch (Exception ex)
        {
            _log.CustomWriteOnLog("PropiedadMoldura_aspx", "Error  = " + ex.Message + "posicion" + ex.StackTrace);

            throw;
        }
    }
Пример #2
0
    protected void btnGuardar_Click(object sender, EventArgs e)
    {
        _log.CustomWriteOnLog("PropiedadMoldura", "-------------------------------------------------------------Evento Click-----------------------");
        _log.CustomWriteOnLog("PropiedadMoldura", "Entró a evento de ingreso ");
        try
        {
            if (Request.Params["Id"] != null)
            {
                _log.CustomWriteOnLog("PropiedadMoldura", "La función es de actualización");

                objDtoMoldura.PK_IM_Cod = int.Parse(Request.Params["Id"]);
                _log.CustomWriteOnLog("PropiedadMoldura", "txtTipoMoldura = " + ddlTipoMoldura.SelectedValue);
                _log.CustomWriteOnLog("PropiedadMoldura", "ddlEstadoMoldura = " + ddlEstadoMoldura.SelectedValue);
                _log.CustomWriteOnLog("PropiedadMoldura", "txtStock = " + txtStock.Text);
                _log.CustomWriteOnLog("PropiedadMoldura", "txtPrecio = " + txtPrecio.Text);
                objDtoMoldura.DM_Precio      = Double.Parse(txtPrecio.Text);
                objDtoMoldura.IM_Estado      = int.Parse(ddlEstadoMoldura.SelectedValue);
                objDtoMoldura.IM_Stock       = int.Parse(txtStock.Text);
                objDtoMoldura.FK_ITM_Tipo    = int.Parse(ddlTipoMoldura.SelectedValue);
                objDtoMoldura.VM_Descripcion = txtDescripcion.Text;
                objDtoMoldura.DM_Medida      = Double.Parse(txtMedida.Text);
                objCtrMoldura.ActualizarRegistroMoldura(objDtoMoldura);
                _log.CustomWriteOnLog("PropiedadMoldura", "Actualizado");
                Utils.AddScriptClientUpdatePanel(upBotonEnviar, "uploadFileDocuments(" + Request.Params["Id"] + ");");


                Utils.AddScriptClientUpdatePanel(upBotonEnviar, "showSuccessMessage2()");
            }
            else
            {
                _log.CustomWriteOnLog("PropiedadMoldura", "La función es de creación");
                objDtoMoldura.DM_Precio      = Double.Parse(txtPrecio.Text);
                objDtoMoldura.IM_Estado      = int.Parse(ddlEstadoMoldura.SelectedValue);
                objDtoMoldura.IM_Stock       = int.Parse(txtStock.Text);
                objDtoMoldura.FK_ITM_Tipo    = int.Parse(ddlTipoMoldura.SelectedValue);
                objDtoMoldura.VM_Descripcion = txtDescripcion.Text;
                objDtoMoldura.DM_Medida      = Double.Parse(txtMedida.Text);
                objCtrMoldura.registrarNuevaMoldura(objDtoMoldura);
                int ValorDevuelto = objDtoMoldura.PK_IM_Cod;
                _log.CustomWriteOnLog("PropiedadMoldura", "PK_IM_Cod valor retornado " + objDtoMoldura.PK_IM_Cod);
                Utils.AddScriptClientUpdatePanel(upBotonEnviar, "uploadFileDocuments(" + objDtoMoldura.PK_IM_Cod + ");");
                _log.CustomWriteOnLog("PropiedadMoldura", "Agregado");
                Utils.AddScriptClientUpdatePanel(upBotonEnviar, "showSuccessMessage2()");
                _log.CustomWriteOnLog("PropiedadMoldura", "Completado");
            }
        }
        catch (Exception ex)
        {
            _log.CustomWriteOnLog("PropiedadMoldura", "Error  = " + ex.Message + "posicion" + ex.StackTrace);

            throw;
        }
    }