protected void btnGrabar_Click(object sender, EventArgs e)
        {
            Bobina b = new Bobina();

            try
            {
                b.NumeroOp = Request.QueryString["OT"].ToString();
            }
            catch
            {
                b.NumeroOp = txtOT.Text.ToString();
            }
            try
            {
                b.Codigo = txtCodigoB.Text;
            }
            catch
            {
                b.Codigo = txtCodigoB.Text.Substring(1, txtCodigoB.Text.Length - 1);
            }
            try
            {
                b.pliego = Request.QueryString["Pliego"].ToString();
            }
            catch
            {
                b.pliego = ddlPliego.SelectedValue.ToString();
            }
            for (int i = 0; i < RadGrid1.Items.Count; i++)
            {
                GridDataItem item = (GridDataItem)RadGrid1.Items[i];
                b.Proveedor = item["Proveedor"].Text;
                b.Marca     = item["Marca"].Text;
                b.Tipo      = item["Tipo"].Text;
                string PBruto = item["Peso_Original"].Text;
                if (PBruto.Length >= 4)
                {
                    //b.Peso_Original = Convert.ToInt32(Convert.ToDouble(PBruto.ToString()).ToString().Replace(',','.'));
                    b.Peso_Original = Convert.ToInt32(PBruto.ToString().Replace(",", string.Empty));
                }
                else
                {
                    b.Peso_Original = Convert.ToInt32(PBruto);
                }
                string PGr = item["Gramage"].Text;
                if (PGr.Length >= 4)
                {
                    b.Gramage = Convert.ToInt32(PGr.Replace(",", string.Empty));
                }
                else
                {
                    b.Gramage = Convert.ToInt32(PGr);
                }
                string PAncho = item["Ancho"].Text;
                if (PAncho.Length >= 4)
                {
                    b.Ancho = Convert.ToInt32(PAncho.Replace(",", string.Empty));
                }
                else
                {
                    b.Ancho = Convert.ToInt32(PAncho);
                }
            }
            if (Convert.ToInt32(ddlEstado.SelectedValue) == 1)
            {
                b.Responsable   = 1;
                b.Estado_Bobina = 100;
            }
            else
            {
                b.Responsable   = Convert.ToInt32(ddlResponsable.SelectedValue);
                b.Estado_Bobina = Convert.ToInt32(ddlCausa.SelectedValue);
            }
            b.Peso_Tapa       = Convert.ToDouble(txtTapa.Text);
            b.Peso_emboltorio = Convert.ToDouble(txtEmboltorio.Text);
            b.PesoEscarpe     = Convert.ToDouble(txtEscarpe.Text);
            string Fecha = "";

            if (txtFecha.Text != "")
            {
                Fecha = txtFecha.Text + " " + ddlTurno.SelectedValue;
            }
            if (b.Codigo != "")
            {
                if (b.PesoEscarpe <= (30) || txtobs.Visible == true)
                {
                    string Maquina = controlbo.BuscarMaquinaUser(GetDireccionIp(Request));
                    if (Maquina != "")
                    {
                        b.Ubicacion = Maquina;
                    }
                    else if (ddlMaquina.SelectedItem.ToString() != "Selecione...")
                    {
                        b.Ubicacion = ddlMaquina.SelectedItem.ToString();
                        Maquina     = b.Ubicacion;
                    }

                    if (Maquina == "Dimensionadora")
                    {
                        b.pliego = "&nbsp;";
                    }
                    if (Maquina != "")
                    {
                        if (controlbo.AgregarBobina(b, lblUsuario.Text, Maquina, Fecha))
                        {
                            if ((b.Peso_Tapa < 15) && (b.Peso_emboltorio < 15))
                            {
                                if (b.PesoEscarpe >= (20))
                                {
                                    EnvioCorreo(b, lblUsuario.Text, txtobs.Text.ToString());
                                }
                                try
                                {
                                    int bdg = Convert.ToInt32(Request.QueryString["Bodega"].ToString());

                                    string popupScript4 = "<script language='JavaScript'>opener.location.reload();window.close();</script>";
                                    Page.RegisterStartupScript("PopupScript", popupScript4);
                                }
                                catch
                                {
                                    string popupScript4 = "<script language='JavaScript'>window.opener.location='Pliego_Bobina_Cons.aspx?id=13&cat=3&OT=" + b.NumeroOp + "&Pliego=" + b.pliego + "';window.close();</script>";
                                    //string popupScript4 = "<script language='JavaScript'>opener.location.reload();window.close();</script>";
                                    Page.RegisterStartupScript("PopupScript", popupScript4);
                                }
                            }
                            else
                            {
                                Validacion.Visible      = true;
                                Image.ImageUrl          = "../../Images/cross.png";
                                lblvalidacion.Text      = "Peso de Tapa y de Envoltura no debe ser mayor a 15KG.";
                                lblvalidacion.ForeColor = Color.White;
                                Validacion.Attributes.Add("style", "background-color:red");
                            }
                        }
                        else
                        {
                            Validacion.Visible      = true;
                            Image.ImageUrl          = "../../Images/cross.png";
                            lblvalidacion.Text      = "Error al Ingresar Registro a Base de Datos.";
                            lblvalidacion.ForeColor = Color.White;
                            Validacion.Attributes.Add("style", "background-color:red");
                        }
                    }
                }
                else
                {
                    Validacion.Visible      = true;
                    Image.Visible           = false;
                    lblvalidacion.Text      = "Obs.";
                    lblvalidacion.ForeColor = Color.White;
                    Validacion.Attributes.Add("style", "background-color:red");
                    txtobs.Visible = true;
                }
            }
            else
            {
                Validacion.Visible      = true;
                Image.ImageUrl          = "../../Images/cross.png";
                lblvalidacion.Text      = "Codigo de Bobina es un campo obligatorio.";
                lblvalidacion.ForeColor = Color.White;
                Validacion.Attributes.Add("style", "background-color:red");
            }
        }