private void BtnAgregar_Click(object sender, EventArgs e)
        {
            var BL = new tb_ta_prodrolloBL();
            var BE = new tb_ta_prodrollo();
            try
            {
                if (rollodesde.Text.Trim().Length > 0)
                {
                    BE.rollodesde = rollodesde.Text.Trim().PadLeft(10, '0');
                }

                if (rollohasta.Text.Trim().Length > 0)
                {
                    BE.rollohasta = rollohasta.Text.Trim().PadLeft(10, '0');
                }

                if (chkActivar.Checked)
                {
                    if (precio.Text == string.Empty)
                    {
                        MessageBox.Show("Ingrese Precio !!!");
                        return;
                    }
                }

                Data = BL.GetAll_prod(EmpresaID, BE).Tables[0];

                if (Data.Rows.Count > 0)
                {
                    for (var i = 0; i < Data.Rows.Count; i++)
                    {
                        row = Tabladet.NewRow();
                        row["productid"] = Data.Rows[i]["productid"].ToString();
                        row["productname"] = Data.Rows[i]["productname"].ToString();
                        row["rollo"] = Data.Rows[i]["rollo"].ToString();
                        if (chkActivar.Checked)
                        {
                            row["precio"] = Convert.ToDecimal(precio.Text);
                        }
                        row["check"] = Convert.ToBoolean(chkActivar.Checked);

                        Tabladet.Rows.Add(row);
                    }

                    PasaRollos(Tabladet);
                }
            }
            catch (Exception)
            {
            }

            Close();
        }
        private void ValidaRollo()
        {
            if (rollo.Text.Trim().Length == 10)
            {
                var BL = new tb_ta_prodrolloBL();
                var BE = new tb_ta_prodrollo();
                var dt = new DataTable();

                BE.modulo = modulo;
                BE.rollo = rollo.Text.Trim();

                dt = BL.GetDatos_Reporte(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    lineaid.Text = dt.Rows[0]["lineaid"].ToString().Trim();
                    lineaname.Text = dt.Rows[0]["lineaname"].ToString().Trim();
                    grupoid.Text = dt.Rows[0]["grupoid"].ToString().Trim();
                    gruponame.Text = dt.Rows[0]["gruponame"].ToString().Trim();
                    subgrupoid.Text = dt.Rows[0]["subgrupoid"].ToString().Trim();
                    subgruponame.Text = dt.Rows[0]["subgruponame"].ToString().Trim();
                    productid.Text = dt.Rows[0]["productid"].ToString().Trim();
                    productname.Text = dt.Rows[0]["productname"].ToString().Trim();
                    colorid.Text = dt.Rows[0]["colorid"].ToString().Trim();
                    colorname.Text = dt.Rows[0]["colorname"].ToString().Trim();
                }
                else
                {
                    productid.Text = string.Empty;
                    productname.Text = string.Empty;
                    lineaid.Text = string.Empty;
                    lineaname.Text = string.Empty;
                    grupoid.Text = string.Empty;
                    gruponame.Text = string.Empty;
                    subgrupoid.Text = string.Empty;
                    subgruponame.Text = string.Empty;
                    colorid.Text = string.Empty;
                    colorname.Text = string.Empty;
                }
            }
            else
            {
                rollo.Text = string.Empty;
            }
        }
        private void ValidaTabladetallemovmov(String valrollo)
        {
            var xrollo = string.Empty;
            var xproductid = string.Empty;
            Decimal xpreciorollo = 0, xprecunit = 0, xcantidad = 0, xcostoprom = 0, tipcamb = 0;
            Decimal desct1 = 0;
            Decimal imporfac = 0;
            Decimal import = 0;
            Decimal totimpx = 0;

            xrollo = valrollo.Trim();

            var rowrollo = Tabladetallemov.Select("rollo='" + xrollo + "'");
            if (rowrollo.Length > 0)
            {
                MessageBox.Show("Rollo ya existe !!!!!!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            txt_stock.Text = "0";
            txt_valor.Text = "0";

            var BLR = new tb_ta_prodrolloBL();
            var DTR = new DataTable();
            DTR = BLR.GetOne(EmpresaID, xrollo).Tables[0];
            if (DTR.Rows.Count > 0)
            {
                xproductid = DTR.Rows[0]["productid"].ToString();
                if (xproductid.Trim().Length == 13)
                {
                    var BL = new tb_60local_stockBL();
                    var BE = new tb_60local_stock();
                    var DT = new DataTable();
                    BE.moduloid = modulo;
                    BE.productid = xproductid;
                    DT = BL.GetAll(EmpresaID, BE).Tables[0];
                    var nrow = griddetallemov.CurrentCell.RowIndex;
                    if (DT.Rows.Count > 0)
                    {

                        griddetallemov.Rows[nrow].Cells["productid"].Value = DT.Rows[0]["productid"].ToString().Trim();
                        griddetallemov.Rows[nrow].Cells["productname"].Value = DT.Rows[0]["productname"].ToString().Trim();
                        griddetallemov.Rows[nrow].Cells["rollo"].Value = DTR.Rows[0]["rollo"].ToString().Trim();
                        griddetallemov.Rows[nrow].Cells["stock"].Value = Convert.ToDecimal(DTR.Rows[0]["rollostock"].ToString().Trim().PadLeft(1, '0'));
                        griddetallemov.Rows[nrow].Cells["dalmacaccionid"].Value = almacaccionid.ToString().Trim();
                        txt_stock.Text = Math.Round(Convert.ToDecimal(DTR.Rows[0]["rollostock"].ToString().Trim().PadLeft(1, '0')), 2).ToString();

                        if (almacaccionid.Substring(0, 1) == "2")
                        {
                            xprecventa = Convert.ToDecimal(Convert.ToDecimal(DT.Rows[0]["precventa"]).ToString("###,###,##0.000000"));
                            xpreciorollo = Convert.ToDecimal(Convert.ToDecimal(DT.Rows[0]["costoultimo"]).ToString("###,###,##0.000000"));
                            txt_valor.Text = Convert.ToDecimal(DT.Rows[0]["costopromed"].ToString().Trim().PadLeft(1, '0')).ToString("###,###,##0.0000");
                            xcostoprom = Convert.ToDecimal(DT.Rows[0]["costopromed"].ToString().Trim().PadLeft(1, '0'));
                        }
                        else
                        {
                            if (almacaccionid.Substring(0, 1) == "1")
                            {
                                xcostoultimo = Convert.ToDecimal(Convert.ToDecimal(DT.Rows[0]["costoultimo"]).ToString("###,###,##0.000000"));
                                xpreciorollo = Convert.ToDecimal(Convert.ToDecimal(DT.Rows[0]["costoultimo"]).ToString("###,###,##0.000000"));
                                txt_valor.Text = Convert.ToDecimal(DT.Rows[0]["costoultimo"].ToString().Trim().PadLeft(1, '0')).ToString("###,###,##0.0000");
                            }
                        }

                        griddetallemov.Rows[nrow].Cells["precventa"].Value = xprecventa;
                        griddetallemov.Rows[nrow].Cells["costoultimo"].Value = xcostoultimo;
                        griddetallemov.Rows[nrow].Cells["costopromed"].Value = xcostoprom;

                        var BL_ = new tb_60movimientosBL();
                        var BE_ = new tb_60movimientoscab();
                        DataTable dt = new DataTable();
                        BE_.tip_op = "OP";
                        BE_.ser_op = ser_op.Text.Trim().PadLeft(4, '0');
                        BE_.num_op = num_op.Text.Trim().PadLeft(10, '0');
                        BE_.productoid = DT.Rows[0]["productid"].ToString().Trim();
                        BE_.moduloid = modulo.Trim().ToString();
                        BE_.idx = "ONE";

                        dt = BL_.GetvalidaMov(EmpresaID, BE_).Tables[0];
                        string arows = dt.Rows[0].Field<string>("Idx");

                        //if (arows == "0")
                        //{
                        //    MessageBox.Show("El Producto seleccionado no pertenece a la OP N°: " + ser_op.Text + "-" + num_op.Text +
                        //        ", \n Verificar OP ", "Confirmación",
                        //        MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                        //}

                        if (tipoperacionid.SelectedValue.ToString() == "02")
                        {
                            xcantidad = Convert.ToDecimal(DTR.Rows[0]["rollomedcompra"].ToString().Trim().PadLeft(1, '0'));
                        }
                        else
                        {
                            xcantidad = Convert.ToDecimal(DTR.Rows[0]["rollostock"].ToString().Trim().PadLeft(1, '0'));
                        }

                        tipcamb = Convert.ToDecimal(tcamb.Text.Trim());
                        if (tipcamb <= 0)
                        {
                            tipcamb = 1;
                        }

                        if (moneda.SelectedValue.ToString() == "S")
                        {
                            xprecunit = xpreciorollo;
                        }
                        else
                        {
                            xprecunit = xpreciorollo / tipcamb;
                        }

                        if (tipoperacionid.SelectedValue.ToString() == "02" && Convert.ToDecimal(DTR.Rows[0]["rollovaloractual"].ToString().Trim().PadLeft(1, '0')) > 0)
                        {
                            xprecunit = Convert.ToDecimal(DTR.Rows[0]["rollovaloractual"].ToString().Trim().PadLeft(1, '0'));
                        }

                        imporfac = Math.Round(xcantidad * Convert.ToDecimal(xprecunit), 6);

                        _cal_Igv();

                        desct1 = 0;
                        import = imporfac * (1 - (desct1 / 100));
                        if (incprec.Trim() == "S")
                        {
                            totimpx = Math.Round(import * (Convert.ToDecimal(igv) / (100 + Convert.ToDecimal(igv))), 6);
                        }
                        else
                        {
                            totimpx = Math.Round(import * (Convert.ToDecimal(igv) / 100), 6);
                        }

                        griddetallemov.Rows[nrow].Cells["valor"].Value = xpreciorollo;
                        griddetallemov.Rows[nrow].Cells["importe"].Value = Math.Round(xcantidad * xpreciorollo, 6);
                        griddetallemov.Rows[nrow].Cells["dtotimpto"].Value = totimpx;

                        griddetallemov.Rows[nrow].Cells["cantidad"].Value = xcantidad;
                        griddetallemov.Rows[nrow].Cells["precunit"].Value = xprecunit;
                        griddetallemov.Rows[nrow].Cells["importfac"].Value = Math.Round(imporfac, 2);
                        Tabladetallemov.AcceptChanges();
                        griddetallemov.CurrentCell = griddetallemov.Rows[nrow].Cells["cantidad"];
                    }
                    else
                    {
                        MessageBox.Show("Producto no existe en tabla LOCAL_STOCK !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Producto no existe !!! ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Rollo no Existe !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void ValidaTablaDetalle(String valrollo, Decimal xPrecio)
        {
            var xrollo = string.Empty;
            var xproductid = string.Empty;
            Decimal xpreciorollo = 0, xprecunit = 0, xcantidad = 0, xcostoprom = 0, tipcamb = 0;
            Decimal desct1 = 0;
            Decimal imporfac = 0;
            Decimal import = 0;
            Decimal totimpx = 0;

            xrollo = valrollo.Trim();

            var rowrollo = Tabladetallemov.Select("rollo='" + xrollo + "'");
            if (rowrollo.Length > 0)
            {
                MessageBox.Show("Rollo ya existe !!!!!!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["productname"].Value = string.Empty;
            txt_stock.Text = "0";
            txt_valor.Text = "0";
            griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["cantidad"].Value = "0";
            griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["precunit"].Value = "0";
            griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["importfac"].Value = "0";

            var BLR = new tb_ta_prodrolloBL();
            var DTR = new DataTable();
            DTR = BLR.GetOne(EmpresaID, xrollo).Tables[0];
            if (DTR.Rows.Count > 0)
            {
                xproductid = DTR.Rows[0]["productid"].ToString();
                if (xproductid.Trim().Length == 13)
                {
                    var BL = new tb_60local_stockBL();
                    var BE = new tb_60local_stock();
                    var DT = new DataTable();
                    BE.moduloid = modulo;
                    BE.productid = xproductid;
                    DT = BL.GetAll(EmpresaID, BE).Tables[0];
                    if (DT.Rows.Count > 0)
                    {
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["productid"].Value = DT.Rows[0]["productid"].ToString().Trim();
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["productname"].Value = DT.Rows[0]["productname"].ToString().Trim();
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["rollo"].Value = DTR.Rows[0]["rollo"].ToString().Trim();
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["stock"].Value = Convert.ToDecimal(DTR.Rows[0]["rollostock"].ToString().Trim().PadLeft(1, '0'));
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["dalmacaccionid"].Value = almacaccionid.ToString().Trim();
                        txt_stock.Text = Math.Round(Convert.ToDecimal(DTR.Rows[0]["rollostock"].ToString().Trim().PadLeft(1, '0')), 2).ToString();

                        if (almacaccionid.Substring(0, 1) == "2")
                        {
                            xprecventa = Convert.ToDecimal(Convert.ToDecimal(DT.Rows[0]["precventa"]).ToString("###,###,##0.000000"));
                            xpreciorollo = Convert.ToDecimal(Convert.ToDecimal(DT.Rows[0]["costoultimo"]).ToString("###,###,##0.000000"));
                            txt_valor.Text = Convert.ToDecimal(DT.Rows[0]["costopromed"].ToString().Trim().PadLeft(1, '0')).ToString("###,###,##0.0000");
                            xcostoprom = Convert.ToDecimal(DT.Rows[0]["costopromed"].ToString().Trim().PadLeft(1, '0'));
                        }
                        else
                        {
                            if (almacaccionid.Substring(0, 1) == "1")
                            {
                                xcostoultimo = Convert.ToDecimal(Convert.ToDecimal(DT.Rows[0]["costoultimo"]).ToString("###,###,##0.000000"));
                                xpreciorollo = Convert.ToDecimal(Convert.ToDecimal(DT.Rows[0]["costoultimo"]).ToString("###,###,##0.000000"));
                                txt_valor.Text = Convert.ToDecimal(DT.Rows[0]["costoultimo"].ToString().Trim().PadLeft(1, '0')).ToString("###,###,##0.0000");
                            }
                        }
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["precventa"].Value = xprecventa;
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["costoultimo"].Value = xcostoultimo;
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["costopromed"].Value = xcostoprom;

                        if (tipoperacionid.SelectedValue.ToString() == "02")
                        {
                            xcantidad = Convert.ToDecimal(DTR.Rows[0]["rollomedcompra"].ToString().Trim().PadLeft(1, '0'));
                        }
                        else
                        {
                            xcantidad = Convert.ToDecimal(DTR.Rows[0]["rollostock"].ToString().Trim().PadLeft(1, '0'));
                        }

                        tipcamb = Convert.ToDecimal(tcamb.Text.Trim());
                        if (tipcamb <= 0)
                        {
                            tipcamb = 1;
                        }

                        if (moneda.SelectedValue.ToString() == "S")
                        {
                            xprecunit = xpreciorollo;
                        }
                        else
                        {
                            xprecunit = xpreciorollo / tipcamb;
                        }

                        if (tipoperacionid.SelectedValue.ToString() == "02" && Convert.ToDecimal(DTR.Rows[0]["rollovaloractual"].ToString().Trim().PadLeft(1, '0')) > 0)
                        {
                            xprecunit = Convert.ToDecimal(DTR.Rows[0]["rollovaloractual"].ToString().Trim().PadLeft(1, '0'));
                        }

                        imporfac = Math.Round(xcantidad * Convert.ToDecimal(xPrecio), 6);

                        _cal_Igv();

                        desct1 = 0;
                        import = imporfac * (1 - (desct1 / 100));
                        if (incprec.Trim() == "S")
                        {
                            totimpx = Math.Round(import * (Convert.ToDecimal(igv) / (100 + Convert.ToDecimal(igv))), 6);
                        }
                        else
                        {
                            totimpx = Math.Round(import * (Convert.ToDecimal(igv) / 100), 6);
                        }

                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["valor"].Value = xpreciorollo;
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["importe"].Value = Math.Round(xcantidad * xPrecio, 6);
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["dtotimpto"].Value = totimpx;

                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["cantidad"].Value = xcantidad;
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["precunit"].Value = xPrecio;
                        griddetallemov.Rows[griddetallemov.CurrentCell.RowIndex].Cells["importfac"].Value = Math.Round(imporfac, 2);
                        Tabladetallemov.AcceptChanges();
                        griddetallemov.CurrentCell = griddetallemov.Rows[griddetallemov.RowCount - 1].Cells["cantidad"];
                    }
                    else
                    {
                        MessageBox.Show("Producto no existe en tabla LOCAL_STOCK !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else
                {
                    MessageBox.Show("Producto no Existe !!! ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Rollo no Existe !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_Tabladetallemovmov()
        {
            try
            {
                Decimal xxprecventa = 0, xxcostoultimo = 0, xxstock = 0, xxcostopromed = 0;
                griddetallemov.AutoGenerateColumns = false;
                var BL = new tb_60movimientosdetBL();
                var BE = new tb_60movimientosdet();
                var dt = new DataTable();

                BE.moduloid = modulo;
                BE.local = local;
                BE.tipodoc = tipodoc.SelectedValue.ToString().Trim();
                BE.serdoc = serdoc.Text.Trim().PadLeft(4, '0');
                BE.numdoc = numdoc.Text.Trim().PadLeft(10, '0');

                dt = BL.GetAll_datosdetalle(EmpresaID, BE).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    statcostopromed = dt.Rows[0]["statcostopromed"].ToString();
                    tiptransac = dt.Rows[0]["tiptransac"].ToString();
                    incprec = dt.Rows[0]["incprec"].ToString().Trim();
                }

                if (Tabladetallemov != null)
                {
                    Tabladetallemov.Clear();
                }
                foreach (DataRow fila in dt.Rows)
                {
                    var BL2 = new tb_60local_stockBL();
                    var BE2 = new tb_60local_stock();
                    var dt2 = new DataTable();
                    BE2.moduloid = modulo;
                    BE2.productid = fila["productid"].ToString();
                    dt2 = BL2.GetAll(EmpresaID, BE2).Tables[0];
                    if (dt2.Rows.Count > 0)
                    {
                        if (almacaccionid.Trim() == "20" || almacaccionid.Trim() == "21")
                        {
                            lbl_valor.Text = "Cost.Prom";
                            xxprecventa = Convert.ToDecimal(dt2.Rows[0]["precventa"]);
                            xxcostopromed = Convert.ToDecimal(dt2.Rows[0]["costopromed"]);
                        }
                        else
                        {
                            if (almacaccionid.Trim() == "10" || almacaccionid.Trim() == "11")
                            {
                                lbl_valor.Text = "Cost.Ultm";
                                xxcostoultimo = Convert.ToDecimal(dt2.Rows[0]["costoultimo"]);
                            }
                        }
                    }
                    var BLR = new tb_ta_prodrolloBL();
                    var DTR = new DataTable();
                    DTR = BLR.GetOne(EmpresaID, fila["rollo"].ToString()).Tables[0];
                    if (DTR.Rows.Count > 0)
                    {
                        xxstock = Convert.ToDecimal(DTR.Rows[0]["rollostock"]);
                    }
                    row = Tabladetallemov.NewRow();
                    row["itemref"] = fila["itemref"].ToString();
                    row["items"] = fila["items"].ToString();
                    row["productid"] = fila["productid"].ToString().Trim();
                    row["productname"] = fila["productname"].ToString().Trim();
                    row["rollo"] = fila["rollo"].ToString();
                    row["stock"] = xxstock;
                    row["stock_old"] = xxstock;
                    row["precventa"] = xxprecventa;
                    row["costoultimo"] = xxcostoultimo;
                    row["costopromed"] = xxcostopromed;

                    var cantidad = Math.Round(Convert.ToDecimal(fila["cantidad"]), 4);
                    var cantidadcta = Math.Round(Convert.ToDecimal(fila["cantidadcta"]), 4);
                    Decimal total;
                    total = cantidad - cantidadcta;

                    row["cantidad"] = total;

                    row["cantidad_old"] = Math.Round(Convert.ToDecimal(fila["cantidad"]), 4);

                    row["precunit"] = Math.Round(Convert.ToDecimal(Convert.ToDecimal(fila["precunit"]).ToString("###,###,##0.000000")), 6);
                    row["importfac"] = Math.Round(Convert.ToDecimal(fila["importfac"]), 2);
                    row["valor"] = Math.Round(Convert.ToDecimal(fila["valor"]), 6);
                    row["importe"] = Math.Round(Convert.ToDecimal(fila["importe"]), 6);
                    row["totimpto"] = Math.Round(Math.Round(Convert.ToDecimal(fila["importe"]), 6) * (Convert.ToDecimal(18) / 100), 6);
                    row["almacaccionid"] = almacaccionid.Trim();

                    row["unmed"] = fila["unmed"].ToString().Trim();
                    row["ubicacion"] = fila["ubicacion"].ToString().Trim();
                    row["nserie"] = fila["nserie"].ToString().Trim();
                    Tabladetallemov.Rows.Add(row);
                }
                griddetallemov.DataSource = Tabladetallemov;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void get_nuevorollo()
 {
     var BL = new tb_ta_prodrolloBL();
     var BE = new tb_ta_prodrollo();
     var DT = new DataTable();
     DT = BL.GetAll_numgenerado(EmpresaID, BE).Tables[0];
     if (DT.Rows.Count > 0)
     {
         rollo.Text = (Convert.ToDecimal(DT.Rows[0]["numgenerado"]) + 1).ToString().Trim().PadLeft(10, '0');
         productid.Enabled = true;
     }
 }
        private void Imprimir_barcode_datamax()
        {
            var BL = new tb_ta_prodrolloBL();
            var BE = new tb_ta_prodrollo();
            var dt = new DataTable();
            if (rollodesde.Text.Trim().Length == 0)
            {
                MessageBox.Show("Ingrese ROLLO DESDE !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rollohasta.Text.Trim().Length == 0)
            {
                MessageBox.Show("Ingrese ROLLO HASTA !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (Convert.ToInt32(rollohasta.Text) < Convert.ToInt32(rollodesde.Text))
            {
                MessageBox.Show("ROLLO HASTA < ROLLO DESDE !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            BE.rollodesde = rollodesde.Text.PadLeft(10, '0');
            BE.rollohasta = rollohasta.Text.PadLeft(10, '0');

            dt = BL.GetAll_codbarra(EmpresaID, BE).Tables[0];

            var CRTLF = Convert.ToString(Equivalencias.Chr(13)) + Convert.ToString(Equivalencias.Chr(10));

            var X11 = Convert.ToString(Equivalencias.Chr(2)) + "qC";
            var X12 = Convert.ToString(Equivalencias.Chr(2)) + "n";
            var X13 = Convert.ToString(Equivalencias.Chr(2)) + "e";
            var X14 = Convert.ToString(Equivalencias.Chr(2)) + "c0000";
            var X15 = Convert.ToString(Equivalencias.Chr(2)) + "RN";
            var X16 = Convert.ToString(Equivalencias.Chr(2)) + "Kf0000";
            var X17 = Convert.ToString(Equivalencias.Chr(2)) + "V0";
            var X18 = Convert.ToString(Equivalencias.Chr(2)) + "M0500";
            var X19 = Convert.ToString(Equivalencias.Chr(2)) + "L";
            var X20 = "A2";
            var X21 = "D11";
            var X22 = "z";
            var X23 = "PD";
            var X24 = "SD";
            var X25 = "H01";

            var X77 = "^01";
            var X88 = "Q0001";
            var X99 = "E";

            var TW101 = "4911S000014002000280018";
            var TW102 = "4911S000014003400230020";
            var TW103 = "4911S000101003400230018";
            var TW104 = "4911S000014005000230016";
            var TW105 = "4o2203400130085";
            var TW106 = "4911S000060009900340034";
            var TW107 = "4911S000014011200230018";
            var TW108 = "4911S000014012800230018";
            var TW109 = "4911S000014014200230018";
            var TW110 = "4911S000014017100230018";
            var TW111 = "4911S000109014300230020";
            var TW112 = "4911S000014015700230018";
            var TW113 = "4911S000109015700230018";
            var TW114 = "4911S000104018000390040";
            var TW115 = "4911S000014018600230018";

            var TW201 = "4911S000014022900280018";
            var TW202 = "4911S000014024300230020";
            var TW203 = "4911S000101024300230018";
            var TW204 = "4911S000014025900230016";
            var TW205 = "4o2203400130294";
            var TW206 = "4911S000060030800340034";
            var TW207 = "4911S000014032100230018";
            var TW208 = "4911S000014033600230018";
            var TW209 = "4911S000014035100230018";
            var TW210 = "4911S000014038000230018";
            var TW211 = "4911S000109035100230020";
            var TW212 = "4911S000014036600230018";
            var TW213 = "4911S000109036600230018";
            var TW214 = "4911S000104038900390040";
            var TW215 = "4911S000014039500230018";

            var pTEXTO = string.Empty;
            var xStick = 0;
            var xComa = string.Empty;

            xStick = xStick + 1;

            foreach (DataRow fila in dt.Rows)
            {
                var xTW01 = string.Empty;
                var xTW02 = string.Empty;
                var xTW03 = string.Empty;
                var xTW04 = string.Empty;
                var xTW05 = string.Empty;
                var xTW06 = string.Empty;
                var xTW07 = string.Empty;
                var xTW08 = string.Empty;
                var xTW09 = string.Empty;
                var xTW10 = string.Empty;
                var xTW11 = string.Empty;
                var xTW12 = string.Empty;
                var xTW13 = string.Empty;
                var xTW14 = string.Empty;
                var xTW15 = string.Empty;

                xTW01 = fila["productid"].ToString() + " " + fila["etiquetaname"].ToString().PadRight(30, ' ').Substring(0, 30).Trim() + xComa;
                xTW02 = "ART: " + fila["subgrupoartic"].ToString().PadRight(10, ' ').Substring(0, 10).Trim() + xComa;
                if (fila["rollolote"].ToString().Trim().Length > 0)
                {
                    xTW03 = "LOTE...: " + fila["rollolote"].ToString().PadRight(10, ' ').Substring(0, 10).Trim() + xComa;
                }
                else
                {
                    xTW03 = string.Empty + xComa;
                }
                if (fila["compo"].ToString().Trim().Length > 0)
                {
                    xTW04 = "COMPOS: " + fila["compo"].ToString().PadRight(10, ' ').Substring(0, 10).Trim() + xComa;
                }
                else
                {
                    xTW04 = string.Empty + xComa;
                }
                fila["rollostock"].ToString().Replace(".", string.Empty);
                xTW05 = fila["rollo"].ToString() + Convert.ToDecimal(fila["rollostock"].ToString().Replace(".", string.Empty)).ToString().Trim().PadLeft(5, '0') + xComa;
                xTW06 = fila["rollo"].ToString() + Convert.ToDecimal(fila["rollostock"].ToString().Replace(".", string.Empty)).ToString("00000").Trim().PadLeft(5, '0') + xComa;
                xTW07 = "PROVE: " + fila["gruponame"].ToString().PadRight(30, ' ').Substring(0, 30).Trim() + xComa;
                xTW08 = "CLIEN: " + VariablesPublicas.EmpresaName.ToString().PadRight(30, ' ').Substring(0, 30).Trim() + xComa;
                xTW09 = "ROLLO: " + fila["rollo"].ToString().Trim() + xComa;
                xTW10 = "ONZAJ: " + fila["titulo"].ToString().Trim() + xComa;
                xTW11 = "MED.INICI: " + Convert.ToDecimal(fila["rollomedcompra"].ToString()).ToString("##0.00").Trim() + xComa;
                xTW12 = "COLOR: " + fila["colorname"].ToString().PadRight(10, ' ').Substring(0, 10).Trim() + xComa;
                xTW13 = "MED.DESPA: " + Convert.ToDecimal(fila["rolloegres"].ToString()).ToString("##0.00").Trim() + xComa;
                xTW14 = Convert.ToDecimal(fila["rollostock"].ToString()).ToString("##0.00").Trim() + xComa;
                xTW15 = DateTime.Today.Date.ToString().Substring(0, 10);

                switch (xStick)
                {
                    case 1:
                        pTEXTO = pTEXTO + X11 + CRTLF;
                        pTEXTO = pTEXTO + X12 + CRTLF;
                        pTEXTO = pTEXTO + X13 + CRTLF;
                        pTEXTO = pTEXTO + X14 + CRTLF;
                        pTEXTO = pTEXTO + X15 + CRTLF;
                        pTEXTO = pTEXTO + X16 + CRTLF;
                        pTEXTO = pTEXTO + X17 + CRTLF;
                        pTEXTO = pTEXTO + X18 + CRTLF;
                        pTEXTO = pTEXTO + X19 + CRTLF;
                        pTEXTO = pTEXTO + X20 + CRTLF;
                        pTEXTO = pTEXTO + X21 + CRTLF;
                        pTEXTO = pTEXTO + X22 + CRTLF;
                        pTEXTO = pTEXTO + X23 + CRTLF;
                        pTEXTO = pTEXTO + X24 + CRTLF;
                        pTEXTO = pTEXTO + X25 + CRTLF;

                        pTEXTO = pTEXTO + TW101 + xTW01 + CRTLF;
                        pTEXTO = pTEXTO + TW102 + xTW02 + CRTLF;
                        pTEXTO = pTEXTO + TW103 + xTW03 + CRTLF;
                        pTEXTO = pTEXTO + TW104 + xTW04 + CRTLF;
                        pTEXTO = pTEXTO + TW105 + xTW05 + CRTLF;
                        pTEXTO = pTEXTO + TW106 + xTW06 + CRTLF;
                        pTEXTO = pTEXTO + TW107 + xTW07 + CRTLF;
                        pTEXTO = pTEXTO + TW108 + xTW08 + CRTLF;
                        pTEXTO = pTEXTO + TW109 + xTW09 + CRTLF;
                        pTEXTO = pTEXTO + TW110 + xTW10 + CRTLF;
                        pTEXTO = pTEXTO + TW111 + xTW11 + CRTLF;
                        pTEXTO = pTEXTO + TW112 + xTW12 + CRTLF;
                        pTEXTO = pTEXTO + TW113 + xTW13 + CRTLF;
                        pTEXTO = pTEXTO + TW114 + xTW14 + CRTLF;
                        pTEXTO = pTEXTO + TW115 + xTW15 + CRTLF;
                        xStick = xStick + 1;
                        break;
                    case 2:
                        pTEXTO = pTEXTO + TW201 + xTW01 + CRTLF;
                        pTEXTO = pTEXTO + TW202 + xTW02 + CRTLF;
                        pTEXTO = pTEXTO + TW203 + xTW03 + CRTLF;
                        pTEXTO = pTEXTO + TW204 + xTW04 + CRTLF;
                        pTEXTO = pTEXTO + TW205 + xTW05 + CRTLF;
                        pTEXTO = pTEXTO + TW206 + xTW06 + CRTLF;
                        pTEXTO = pTEXTO + TW207 + xTW07 + CRTLF;
                        pTEXTO = pTEXTO + TW208 + xTW08 + CRTLF;
                        pTEXTO = pTEXTO + TW209 + xTW09 + CRTLF;
                        pTEXTO = pTEXTO + TW210 + xTW10 + CRTLF;
                        pTEXTO = pTEXTO + TW211 + xTW11 + CRTLF;
                        pTEXTO = pTEXTO + TW212 + xTW12 + CRTLF;
                        pTEXTO = pTEXTO + TW213 + xTW13 + CRTLF;
                        pTEXTO = pTEXTO + TW214 + xTW14 + CRTLF;
                        pTEXTO = pTEXTO + TW215 + xTW15 + CRTLF;

                        pTEXTO = pTEXTO + X77 + CRTLF;
                        pTEXTO = pTEXTO + X88 + CRTLF;
                        pTEXTO = pTEXTO + X99 + CRTLF;

                        xStick = 1;
                        break;
                }
            }
            if (xStick == 2)
            {
                pTEXTO = pTEXTO + X77 + CRTLF;
                pTEXTO = pTEXTO + X88 + CRTLF;
                pTEXTO = pTEXTO + X99 + CRTLF;
            }

            try
            {
                if (File.Exists(@"C:\\reportebarcode.txt"))
                {
                    File.Delete(@"C:\\reportebarcode.txt");
                }

                var escritor = new StreamWriter(@"C:\\reportebarcode.txt");
                escritor.WriteLine(pTEXTO);
                escritor.Close();

                try
                {
                    var buffer = new byte[pTEXTO.Length];
                    buffer = System.Text.Encoding.ASCII.GetBytes(pTEXTO);

                    var printer = CreateFile("LPT1:", FileAccess.Write, 0, IntPtr.Zero, FileMode.OpenOrCreate, 0, IntPtr.Zero);
                    if (!printer.IsInvalid)
                    {
                        var lpt1 = new FileStream(printer, FileAccess.ReadWrite);
                        lpt1.Write(buffer, 0, buffer.Length);
                        lpt1.Close();
                    }
                }
                catch (Exception ex)
                {
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message.ToString());
            }
        }
        private void Delete()
        {
            try
            {
                if (rollo.Text.Trim().Length != 10)
                {
                    MessageBox.Show("Falta Codigo Rollo !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (productid.Text.Trim().Length != 13)
                    {
                        MessageBox.Show("Falta Codigo Producto !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        if (Equivalencias.IsNumeric(rollomedcompra.Text) && Convert.ToDecimal(rollomedcompra.Text) <= 0)
                        {
                            MessageBox.Show("Medida de compra debe ser mayor a  CERO !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            var BL = new tb_ta_prodrolloBL();
                            var BE = new tb_ta_prodrollo();

                            BE.rollo = rollo.Text.Trim().PadLeft(10, '0');

                            if (BL.Delete(EmpresaID, BE))
                            {
                                SEGURIDAD_LOG("E");
                                MessageBox.Show("Rollo eliminado correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                limpiar_documento();
                                form_bloqueado(false);

                                btn_nuevo.Enabled = true;

                                btn_primero.Enabled = true;
                                btn_anterior.Enabled = true;
                                btn_siguiente.Enabled = true;
                                btn_ultimo.Enabled = true;

                                btn_salir.Enabled = true;
                                ;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void form_cargar_datos(String posicion)
        {
            try
            {
                var BL = new tb_ta_prodrolloBL();
                var BE = new tb_ta_prodrollo();
                var dt = new DataTable();

                if (rollo.Text.Trim().Length > 0)
                {
                    BE.rollo = rollo.Text.Trim().PadLeft(10, '0');
                }
                BE.posicion = posicion.Trim();

                dt = BL.GetAll_paginacion(EmpresaID, BE).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    limpiar_documento();
                    ssModo = "EDIT";

                    rollofecompra.Text = dt.Rows[0]["rollofecompra"].ToString().Trim();
                    productid.Text = dt.Rows[0]["productid"].ToString().Trim();
                    productname.Text = dt.Rows[0]["productname"].ToString().Trim();
                    rollo.Text = dt.Rows[0]["rollo"].ToString().Trim();

                    rollolote.Text = dt.Rows[0]["rollolote"].ToString().Trim();
                    rolloancho.Text = dt.Rows[0]["rolloancho"].ToString().Trim();
                    rolloencog.Text = dt.Rows[0]["rolloencog"].ToString().Trim();
                    tipofallasid.SelectedValue = dt.Rows[0]["tipofallasid"].ToString().Trim();
                    docuref.Text = dt.Rows[0]["docuref"].ToString().Trim();
                    rollostockini.Text = dt.Rows[0]["rollostockini"].ToString().Trim();
                    rollovalorini.Text = dt.Rows[0]["rollovalorini"].ToString().Trim();
                    rollostock.Text = dt.Rows[0]["rollostock"].ToString().Trim();
                    rollovaloractual.Text = dt.Rows[0]["rollovaloractual"].ToString().Trim();
                    rollomedcompra.Text = dt.Rows[0]["rollomedcompra"].ToString().Trim();
                    rolloingre.Text = dt.Rows[0]["rolloingre"].ToString().Trim();
                    rolloegres.Text = dt.Rows[0]["rolloegres"].ToString().Trim();

                    btn_editar.Enabled = true;
                    btn_eliminar.Enabled = true;
                    btn_imprimir.Enabled = true;

                    btn_primero.Enabled = true;
                    btn_anterior.Enabled = true;
                    btn_siguiente.Enabled = true;
                    btn_ultimo.Enabled = true;

                    btn_log.Enabled = true;
                    btn_salir.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Update()
        {
            try
            {
                if (rollo.Text.Trim().Length != 10)
                {
                    MessageBox.Show("Falta Codigo Rollo !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (productid.Text.Trim().Length != 13)
                    {
                        MessageBox.Show("Falta Codigo Producto !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        if (Equivalencias.IsNumeric(rollomedcompra.Text) && Convert.ToDecimal(rollomedcompra.Text) <= 0)
                        {
                            MessageBox.Show("Medida de compra debe ser mayor a  CERO !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            var BL = new tb_ta_prodrolloBL();
                            var BE = new tb_ta_prodrollo();

                            BE.rollo = rollo.Text.Trim().PadLeft(10, '0');
                            BE.productid = productid.Text;
                            BE.rollolote = rollolote.Text.Trim().ToUpper();
                            BE.rollofecompra = Convert.ToDateTime(rollofecompra.Text.Trim().PadLeft(1, '0'));
                            BE.rolloingre = Convert.ToDecimal(rolloingre.Text.Trim().PadLeft(1, '0'));
                            BE.rolloegres = Convert.ToDecimal(rolloegres.Text.Trim().PadLeft(1, '0'));
                            BE.rolloancho = Convert.ToDecimal(rolloancho.Text.Trim().PadLeft(1, '0'));
                            BE.rolloencog = Convert.ToDecimal(rolloencog.Text.Trim().PadLeft(1, '0'));
                            BE.rollomedcompra = Convert.ToDecimal(rollomedcompra.Text.Trim().PadLeft(1, '0'));
                            BE.rollovaloractual = Convert.ToDecimal(rollovaloractual.Text.Trim().PadLeft(1, '0'));
                            if (tipofallasid.SelectedIndex != -1)
                            {
                                BE.tipofallasid = tipofallasid.SelectedValue.ToString();
                            }
                            BE.usuar = VariablesPublicas.Usuar.Trim();

                            if (BL.Update(EmpresaID, BE))
                            {
                                SEGURIDAD_LOG("M");
                                MessageBox.Show("Datos modificado correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                procesado = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_Tablaproductorollomov()
        {
            try
            {
                var BL = new tb_ta_prodrolloBL();
                var BE = new tb_ta_prodrollo();

                var dt = new DataTable();

                switch (cbo_buscar.SelectedValue.ToString())
                {
                    case "01":
                        BE.productid = txt_criterio.Text.Trim().ToUpper();
                        break;
                    case "02":
                        BE.productname = txt_criterio.Text.Trim().ToUpper();
                        break;
                    case "03":
                        if (txt_criterio.Text.Trim().Length > 0)
                        {
                            BE.rollo = txt_criterio.Text.Trim().ToUpper().PadLeft(10, '0');
                        }
                        break;
                    default:
                        break;
                }

                if (rollodesde.Text.Trim().Length > 0)
                {
                    BE.rollodesde = rollodesde.Text.Trim().PadLeft(10, '0');
                }

                if (rollohasta.Text.Trim().Length > 0)
                {
                    BE.rollohasta = rollohasta.Text.Trim().PadLeft(10, '0');
                }

                dt = BL.GetAll_prod(EmpresaID, BE).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    Tablaproductorollo = dt;
                    gridproductorollo.DataSource = Tablaproductorollo;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void btn_busqueda_Click(object sender, EventArgs e)
        {
            try
            {
                if (Tablaproductorollo.Rows.Count > 0)
                {
                    Tablaproductorollo.Rows.Clear();
                }
                var BL = new tb_ta_prodrolloBL();
                var BE = new tb_ta_prodrollo();

                switch (cbo_buscar.SelectedIndex)
                {
                    case 0:
                        if (txt_criterio.Text.Trim().Length > 0)
                        {
                            BE.rollo = txt_criterio.Text.Trim().ToUpper().PadLeft(10, '0');
                        }
                        break;
                    case 1:
                        BE.productid = txt_criterio.Text.Trim().ToUpper();
                        break;
                    case 2:
                        BE.productname = txt_criterio.Text.Trim().ToUpper();
                        break;
                    default:
                        break;
                }

                if (rollodesde.Text.Trim().Length > 0)
                {
                    BE.rollodesde = rollodesde.Text.Trim().PadLeft(10, '0');
                }

                if (rollohasta.Text.Trim().Length > 0)
                {
                    BE.rollohasta = rollohasta.Text.Trim().PadLeft(10, '0');
                }

                Tablaproductorollo = BL.GetAll_prod(EmpresaID, BE).Tables[0];

                if (Tablaproductorollo.Rows.Count > 0)
                {
                    gridproductorollo.DataSource = Tablaproductorollo;
                    gridproductorollo.Rows[0].Selected = false;
                    gridproductorollo.Focus();
                }

                double sumatoria = 0, sumatoria2 = 0;
                foreach (DataGridViewRow row in gridproductorollo.Rows)
                {
                    sumatoria += Convert.ToDouble(row.Cells["grollostock"].Value);
                    sumatoria2 += Convert.ToDouble(row.Cells["grollomedcompra"].Value);
                }

                txt_metraje.Text = Convert.ToString(sumatoria.ToString("##,###,##0.00"));
                txt_metraje2.Text = Convert.ToString(sumatoria2.ToString("##,###,##0.00"));
                txtnum_rollos.Text = Convert.ToString(gridproductorollo.Rows.Count.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Imprimir_barcode_zebra()
        {
            var BL = new tb_ta_prodrolloBL();
            var BE = new tb_ta_prodrollo();
            var dt = new DataTable();
            if (rollodesde.Text.Trim().Length == 0)
            {
                MessageBox.Show("Ingrese ROLLO DESDE !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (rollohasta.Text.Trim().Length == 0)
            {
                MessageBox.Show("Ingrese ROLLO HASTA !!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (Convert.ToInt32(rollohasta.Text) < Convert.ToInt32(rollodesde.Text))
            {
                MessageBox.Show("ROLLO HASTA < ROLLO DESDE !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            BE.rollodesde = rollodesde.Text.PadLeft(10, '0');
            BE.rollohasta = rollohasta.Text.PadLeft(10, '0');

            dt = BL.GetAll_codbarra(EmpresaID, BE).Tables[0];

            var CRTLF = Convert.ToString(Equivalencias.Chr(13)) + Convert.ToString(Equivalencias.Chr(10));

            var X11 = "^XA";
            var X12 = "^MCY";
            var X13 = "^XZ";
            var X14 = "^XA";
            var X15 = "^FWN^CFD,24^PW863^LH0,0";
            var X16 = "^CI0^PR2^MNY^MTT^MMT^MD0^PON^PMN^LRN";
            var X17 = "^XZ";
            var X18 = "^XA";
            var X19 = "^MCY";
            var X20 = "^XZ";
            var X21 = "^XA";
            var X22 = "^DFR:TEMP_FMT.ZPL";
            var X23 = "^LRN";

            var X44 = "^XZ";
            var X55 = "^XA";
            var X66 = "^XFR:TEMP_FMT.ZPL";
            var X77 = "^PQ1,0,1,Y";
            var X88 = "^XZ";
            var X99 = "^XA";

            var TW101 = "^A0B,28,18^FO28,43^FD";
            var TW102 = "^A0B,23,20^FO63,186^FD";
            var TW103 = "^A0B,23,18^FO62,33^FD";
            var TW104 = "^A0B,23,16^FO94,66^FD";
            var TW105 = "^BY2^FO118,43^BAB,67,N,N,N^FD";
            var TW106 = "^A0B,34,34^FO185,93^FD";
            var TW107 = "^A0B,23,18^FO220,39^FD";
            var TW108 = "^A0B,23,18^FO253,46^FD";
            var TW109 = "^A0B,23,18^FO281,240^FD";
            var TW110 = "^A0B,23,18^FO341,303^FD";
            var TW111 = "^A0B,23,20^FO283,52^FD";
            var TW112 = "^A0B,23,18^FO311,238^FD";
            var TW113 = "^A0B,23,18^FO312,56^FD";
            var TW114 = "^A0B,39,40^FO345,65^FD";
            var TW115 = "^A0B,23,18^FO371,318^FD";

            var TW201 = "^A0B,28,18^FO452,43^FD";
            var TW202 = "^A0B,23,20^FO487,186^FD";
            var TW203 = "^A0B,23,18^FO486,33^FD";
            var TW204 = "^A0B,23,16^FO518,66^FD";
            var TW205 = "^BY2^FO542,43^BAB,67,N,N,N^FD";
            var TW206 = "^A0B,34,34^FO609,93^FD";
            var TW207 = "^A0B,23,18^FO644,39^FD";
            var TW208 = "^A0B,23,18^FO676,46^FD";
            var TW209 = "^A0B,23,18^FO705,240^FD";
            var TW210 = "^A0B,23,18^FO764,303^FD";
            var TW211 = "^A0B,23,20^FO706,52^FD";
            var TW212 = "^A0B,23,18^FO735,238^FD";
            var TW213 = "^A0B,23,18^FO735,56^FD";
            var TW214 = "^A0B,39,40^FO768,65^FD";
            var TW215 = "^A0B,23,18^FO794,318^FD";

            var pTEXTO = string.Empty;
            var xStick = 0;
            var xComa = "^FS";

            xStick = xStick + 1;

            foreach (DataRow fila in dt.Rows)
            {
                var xTW01 = string.Empty;
                var xTW02 = string.Empty;
                var xTW03 = string.Empty;
                var xTW04 = string.Empty;
                var xTW05 = string.Empty;
                var xTW06 = string.Empty;
                var xTW07 = string.Empty;
                var xTW08 = string.Empty;
                var xTW09 = string.Empty;
                var xTW10 = string.Empty;
                var xTW11 = string.Empty;
                var xTW12 = string.Empty;
                var xTW13 = string.Empty;
                var xTW14 = string.Empty;
                var xTW15 = string.Empty;

                xTW01 = fila["productid"].ToString() + fila["etiquetaname"].ToString().PadRight(30, ' ').Substring(0, 30).Trim() + xComa;
                xTW02 = "ART: " + fila["subgrupoartic"].ToString().PadRight(10, ' ').Substring(0, 10).Trim() + xComa;
                if (fila["rollolote"].ToString().Trim().Length > 0)
                {
                    xTW03 = "LOTE...: " + fila["rollolote"].ToString().PadRight(10, ' ').Substring(0, 10).Trim() + xComa;
                }
                else
                {
                    xTW03 = string.Empty + xComa;
                }
                if (fila["compo"].ToString().Trim().Length > 0)
                {
                    xTW04 = "COMPOS: " + fila["compo"].ToString().PadRight(10, ' ').Substring(0, 10).Trim() + xComa;
                }
                else
                {
                    xTW04 = string.Empty + xComa;
                }
                fila["rollostock"].ToString().Replace(".", string.Empty);
                xTW05 = fila["rollo"].ToString() + Convert.ToDecimal(fila["rollostock"].ToString().Replace(".", string.Empty)).ToString().Trim().PadLeft(5, '0') + xComa;
                xTW06 = fila["rollo"].ToString() + Convert.ToDecimal(fila["rollostock"].ToString().Replace(".", string.Empty)).ToString().Trim().PadLeft(5, '0') + xComa;
                xTW07 = "PROVE: " + fila["gruponame"].ToString().PadRight(30, ' ').Substring(0, 30).Trim() + xComa;
                xTW08 = "CLIEN: " + VariablesPublicas.EmpresaName.ToString().PadRight(30, ' ').Substring(0, 30).Trim() + xComa;
                xTW09 = "ROLLO: " + fila["rollo"].ToString().Trim() + xComa;
                xTW10 = "ONZAJ: " + fila["titulo"].ToString().Trim() + xComa;
                xTW11 = "MED.INICI: " + Convert.ToDecimal(fila["rollomedcompra"].ToString()).ToString("##0.00").Trim() + xComa;
                xTW12 = "COLOR: " + fila["colorname"].ToString().PadRight(10, ' ').Substring(0, 10).Trim() + xComa;
                xTW13 = "MED.DESPA: " + Convert.ToDecimal(fila["rolloegres"].ToString()).ToString("##0.00").Trim() + xComa;
                xTW14 = Convert.ToDecimal(fila["rollostock"].ToString()).ToString("##0.00").Trim() + xComa;
                xTW15 = DateTime.Today.Date.ToString();

                switch (xStick)
                {
                    case 1:
                        pTEXTO = pTEXTO + X11 + CRTLF;
                        pTEXTO = pTEXTO + X12 + CRTLF;
                        pTEXTO = pTEXTO + X13 + CRTLF;
                        pTEXTO = pTEXTO + X14 + CRTLF;
                        pTEXTO = pTEXTO + X15 + CRTLF;
                        pTEXTO = pTEXTO + X16 + CRTLF;
                        pTEXTO = pTEXTO + X17 + CRTLF;
                        pTEXTO = pTEXTO + X18 + CRTLF;
                        pTEXTO = pTEXTO + X19 + CRTLF;
                        pTEXTO = pTEXTO + X20 + CRTLF;
                        pTEXTO = pTEXTO + X21 + CRTLF;
                        pTEXTO = pTEXTO + X22 + CRTLF;
                        pTEXTO = pTEXTO + X23 + CRTLF;

                        pTEXTO = pTEXTO + TW101 + xTW01 + CRTLF;
                        pTEXTO = pTEXTO + TW102 + xTW02 + CRTLF;
                        pTEXTO = pTEXTO + TW103 + xTW03 + CRTLF;
                        pTEXTO = pTEXTO + TW104 + xTW04 + CRTLF;
                        pTEXTO = pTEXTO + TW105 + xTW05 + CRTLF;
                        pTEXTO = pTEXTO + TW106 + xTW06 + CRTLF;
                        pTEXTO = pTEXTO + TW107 + xTW07 + CRTLF;
                        pTEXTO = pTEXTO + TW108 + xTW08 + CRTLF;
                        pTEXTO = pTEXTO + TW109 + xTW09 + CRTLF;
                        pTEXTO = pTEXTO + TW110 + xTW10 + CRTLF;
                        pTEXTO = pTEXTO + TW111 + xTW11 + CRTLF;
                        pTEXTO = pTEXTO + TW112 + xTW12 + CRTLF;
                        pTEXTO = pTEXTO + TW113 + xTW13 + CRTLF;
                        pTEXTO = pTEXTO + TW114 + xTW14 + CRTLF;
                        pTEXTO = pTEXTO + TW115 + xTW15 + CRTLF;
                        xStick = xStick + 1;
                        break;
                    case 2:
                        pTEXTO = pTEXTO + TW201 + xTW01 + CRTLF;
                        pTEXTO = pTEXTO + TW202 + xTW02 + CRTLF;
                        pTEXTO = pTEXTO + TW203 + xTW03 + CRTLF;
                        pTEXTO = pTEXTO + TW204 + xTW04 + CRTLF;
                        pTEXTO = pTEXTO + TW205 + xTW05 + CRTLF;
                        pTEXTO = pTEXTO + TW206 + xTW06 + CRTLF;
                        pTEXTO = pTEXTO + TW207 + xTW07 + CRTLF;
                        pTEXTO = pTEXTO + TW208 + xTW08 + CRTLF;
                        pTEXTO = pTEXTO + TW209 + xTW09 + CRTLF;
                        pTEXTO = pTEXTO + TW210 + xTW10 + CRTLF;
                        pTEXTO = pTEXTO + TW211 + xTW11 + CRTLF;
                        pTEXTO = pTEXTO + TW212 + xTW12 + CRTLF;
                        pTEXTO = pTEXTO + TW213 + xTW13 + CRTLF;
                        pTEXTO = pTEXTO + TW214 + xTW14 + CRTLF;
                        pTEXTO = pTEXTO + TW215 + xTW15 + CRTLF;

                        pTEXTO = pTEXTO + X44 + CRTLF;
                        pTEXTO = pTEXTO + X55 + CRTLF;
                        pTEXTO = pTEXTO + X66 + CRTLF;
                        pTEXTO = pTEXTO + X77 + CRTLF;
                        pTEXTO = pTEXTO + X88 + CRTLF;
                        pTEXTO = pTEXTO + X99 + CRTLF;

                        xStick = 1;
                        break;
                }
            }
            if (xStick == 2)
            {
                pTEXTO = pTEXTO + X44 + CRTLF;
                pTEXTO = pTEXTO + X55 + CRTLF;
                pTEXTO = pTEXTO + X66 + CRTLF;
                pTEXTO = pTEXTO + X77 + CRTLF;
                pTEXTO = pTEXTO + X88 + CRTLF;
                pTEXTO = pTEXTO + X99 + CRTLF;
            }

            try
            {
                try
                {
                    if (File.Exists(@"C:\\reportebarcode.txt"))
                    {
                        File.Delete(@"C:\\reportebarcode.txt");
                    }

                    var escritor = new StreamWriter(@"C:\\reportebarcode.txt");
                    escritor.WriteLine(pTEXTO);
                    escritor.Close();
                }
                catch
                {
                }
            }
            catch
            {
            }
        }
        private void data_Tablaproductorollomov()
        {
            try
            {
                var BL = new tb_ta_prodrolloBL();
                var BE = new tb_ta_prodrollo();

                var dt = new DataTable();
                BE.productid = productid.Text.Trim().ToUpper();
                if (rollodesde.Text.Trim().Length > 0)
                {
                    BE.rollodesde = rollodesde.Text.Trim().PadLeft(10, '0');
                }

                if (rollohasta.Text.Trim().Length > 0)
                {
                    BE.rollohasta = rollohasta.Text.Trim().PadLeft(10, '0');
                }

                dt = BL.GetAll_prod(EmpresaID, BE).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    Tablaproductorollo = dt;
                    gridproductorollo.DataSource = Tablaproductorollo;
                    gridproductorollo.Rows[0].Selected = false;
                    gridproductorollo.Focus();
                    btn_impcodbar.Enabled = true;
                    btn_nuevo.Enabled = true;
                }
                else
                {
                    Tablaproductorollo = dt;
                    gridproductorollo.DataSource = Tablaproductorollo;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void cargaData2()
        {
            var xprodrollo = string.Empty;
            Decimal xcantidad = 0, xpreciorollo = 0, xprecventa = 0, xcostoultimo = 0, xcostoprom = 0, txtvalor = 0, xprecunit = 0, xtotimp = 0;
            String input;
            Int16 i = 1;
            while ((input = sr.ReadLine()) != null)
            {
                var DT = new DataTable();
                var BL = new tb_ta_prodrolloBL();
                var BE = new tb_ta_prodrollo();

                var valores = input.Split(new char[] { ',' });

                if (!(valores.Length == 2))
                {
                    MessageBox.Show("::: NUMERO DE VALORES ERRONEO !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                xprodrollo = valores[0].Substring(0, 10);
                xprecunit = Convert.ToDecimal(valores[1].ToString());
                if (valores[0].Trim().Length == 15)
                {
                    xcantidad = Convert.ToDecimal(input.Trim().Substring(10, 3) + "." + input.Trim().Substring(13, 2));
                }
                else
                {
                    xcantidad = Convert.ToDecimal(input.Trim().Substring(10, 4) + "." + input.Trim().Substring(14, 2));
                }

                BE.local = VariablesPublicas.Local.Trim();
                BE.rollo = xprodrollo;
                DT = BL.GetAll_Localstock(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];

                if (DT.Rows.Count > 0)
                {
                    DT.Rows[0]["productid"].ToString();

                    if (Equivalencias.IsNumeric(valores[0].Trim().PadRight(16, '0').Substring(10, 6)))
                    {
                        if (almacaccionid.Trim().Substring(0, 1) == "2")
                        {
                            xpreciorollo = Convert.ToDecimal(DT.Rows[0]["precventa"]);
                            xprecventa = Convert.ToDecimal(DT.Rows[0]["precventa"].ToString().PadLeft(1, '0'));
                            xcostoprom = Convert.ToDecimal(DT.Rows[0]["costopromed"].ToString().Trim().PadLeft(1, '0'));
                        }
                        else
                        {
                            xpreciorollo = Convert.ToDecimal(DT.Rows[0]["costoultimo"]);
                            xcostoultimo = Convert.ToDecimal(DT.Rows[0]["costoultimo"].ToString().PadLeft(1, '0'));
                        }

                        if (preciorollo.Text.Trim().Length > 0 & Equivalencias.IsNumeric(preciorollo.Text.Trim()))
                        {
                            xpreciorollo = Convert.ToDecimal(preciorollo.Text);
                            if (moneda == "$")
                            {
                                txtvalor = xpreciorollo * Convert.ToDecimal(tcamb.Trim());
                            }
                            else
                            {
                                txtvalor = xpreciorollo;
                            }
                        }
                        else
                        {
                            txtvalor = xpreciorollo;
                        }

                        if (incprec == "S")
                        {
                            xtotimp = Math.Round((xcantidad * xprecunit) * (igv / (100 + igv)), 2);
                        }
                        else
                        {
                            xtotimp = Math.Round((xcantidad * xprecunit) * (igv / 100), 2);
                        }

                        if (tipoperacionid.Trim() == "02" && Convert.ToDecimal(DT.Rows[0]["rollovaloractual"].ToString().Trim().PadLeft(1, '0')) > 0)
                        {
                            xprecunit = Convert.ToDecimal(DT.Rows[0]["rollovaloractual"].ToString().Trim().PadLeft(1, '0'));
                            txtvalor = xprecunit * Convert.ToDecimal(tcamb.Trim());
                        }

                        var datosfila = detallemov.Select("[rollo]='" + xprodrollo + "'");
                        if (datosfila.Count() == 0)
                        {
                            row = detallemov.NewRow();
                            string xitems;

                            try
                            {
                                xitems = (string)detallemov.Compute("Max(items)", "true");
                            }
                            catch
                            {
                                xitems = "0";
                            }

                            row["itemref"] = string.Empty;
                            row["items"] = (Convert.ToInt16(xitems) + 1).ToString().PadLeft(5, '0');
                            row["productid"] = DT.Rows[0]["productid"].ToString();
                            row["productname"] = DT.Rows[0]["productname"].ToString();
                            row["rollo"] = xprodrollo;
                            row["stock"] = DT.Rows[0]["rollostock"];

                            row["precventa"] = xprecventa;
                            row["costoultimo"] = xcostoultimo;
                            row["costopromed"] = xcostoprom;

                            row["valor"] = txtvalor;
                            row["importe"] = xcantidad * txtvalor;
                            row["totimpto"] = xtotimp;

                            row["cantidad"] = xcantidad;
                            row["precunit"] = xprecunit;
                            row["importfac"] = xcantidad * xprecunit;

                            row["almacaccionid"] = almacaccionid.Trim();
                            detallemov.Rows.Add(row);
                        }
                        else
                        {
                            var xfila = 0;

                            xfila = detallemov.Rows.IndexOf(datosfila[0]);

                            detallemov.Rows[xfila]["productid"] = DT.Rows[0]["productid"].ToString();
                            detallemov.Rows[xfila]["productname"] = DT.Rows[0]["productname"].ToString();
                            detallemov.Rows[xfila]["rollo"] = xprodrollo;
                            detallemov.Rows[xfila]["stock"] = DT.Rows[0]["rollostock"].ToString().Trim().PadLeft(1, '0');

                            detallemov.Rows[xfila]["valor"] = txtvalor;
                            detallemov.Rows[xfila]["importe"] = xcantidad * txtvalor;
                            detallemov.Rows[xfila]["totimpto"] = xtotimp;

                            detallemov.Rows[xfila]["cantidad"] = xcantidad;
                            detallemov.Rows[xfila]["precunit"] = xprecunit;
                            detallemov.Rows[xfila]["importfac"] = xcantidad * xprecunit;

                            detallemov.Rows[xfila]["almacaccionid"] = almacaccionid.Trim().ToString();
                        }

                        Thread.Sleep(1);
                        Int16 percent = i;
                        RefreshProgress(percent);
                        i++;
                    }
                    else
                    {
                        roweror = dataerror.NewRow();
                        roweror["idrollo"] = input.Trim();
                        roweror["msgdataerror"] = "CANTIDAD en formato incorrecto !!!";
                        dataerror.Rows.Add(roweror);
                    }
                }
                else
                {
                    roweror = dataerror.NewRow();
                    roweror["idrollo"] = xprodrollo;
                    roweror["msgdataerror"] = "Codigo ROLLO no existe en tabla TA_PRODROLLO y/o TB_TA_PRODUCTOS. !";
                    dataerror.Rows.Add(roweror);
                }
            }
            sr.Close();
            Refresh_gridgeneral(detallemov);
            Refresh_controles();
        }
        private void cargaData1()
        {
            var xrollo = string.Empty;
            Decimal xcantidad = 0, xstocklibros = 0;
            String input2;
            Int16 i = 1;

            while ((input2 = sr2.ReadLine()) != null)
            {
                var valor = input2.Split(new char[] { ',' });

                if (!(valor.Length == 1))
                {
                    MessageBox.Show("::: NUMERO DE VALORES ERRONEO !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (input2.Trim().Length == 15 || input2.Trim().Length == 16)
                {
                    xrollo = input2.Trim().ToUpper().Substring(0, 10);

                    if (Equivalencias.IsNumeric(input2.Trim().PadRight(16, '0').Substring(10, 6)))
                    {
                        if (input2.Trim().Length == 15)
                        {
                            xcantidad = Convert.ToDecimal(input2.Trim().Substring(10, 3) + "." + input2.Trim().Substring(13, 2));
                        }
                        else
                        {
                            xcantidad = Convert.ToDecimal(input2.Trim().Substring(10, 4) + "." + input2.Trim().Substring(14, 2));
                        }
                    }

                    var rowdt = Datrollos.NewRow();
                    rowdt["rollo"] = xrollo.ToString();
                    rowdt["cantidad"] = xcantidad.ToString();
                    Datrollos.Rows.Add(rowdt);
                }
                else
                {
                    roweror = dataerror.NewRow();
                    roweror["idrollo"] = input2;
                    roweror["msgdataerror"] = "Formato de Dato Incorrecto. !";
                    dataerror.Rows.Add(roweror);
                }
            }

            sr2.Close();

            var szColumns = new String[Datrollos.Columns.Count];
            for (var index = 0; index < Datrollos.Columns.Count; index++)
            {
                szColumns[index] = Datrollos.Columns[index].ColumnName;
            }
            Datrollos = Datrollos.DefaultView.ToTable(true, szColumns);

            var BL = new tb_ta_prodrolloBL();
            var BE = new tb_ta_prodrollo();
            var DT = new DataTable();
            foreach (DataRow fila in Datrollos.Rows)
            {
                BE.local = VariablesPublicas.Local.Trim();
                BE.rollo = fila["rollo"].ToString();
                var xstockfisico = Convert.ToDecimal(fila["cantidad"].ToString());

                DT = BL.GetAll_stock(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                if (DT.Rows.Count > 0)
                {
                    var rowdt = detallemov.NewRow();
                    rowdt["rollo"] = DT.Rows[0]["rollo"].ToString();
                    rowdt["productid"] = DT.Rows[0]["productid"].ToString();
                    rowdt["productname"] = DT.Rows[0]["productname"].ToString();
                    xstocklibros = Convert.ToDecimal(DT.Rows[0]["stocklibros"].ToString());
                    rowdt["stocklibros"] = Convert.ToDecimal(DT.Rows[0]["stocklibros"].ToString());
                    rowdt["stockfisico"] = xstockfisico;
                    rowdt["diferencia"] = Convert.ToDecimal(xstocklibros - xstockfisico);
                    detallemov.Rows.Add(rowdt);

                    Thread.Sleep(1);
                    Int16 percent = i;
                    RefreshProgress(percent);
                    i++;
                }
            }
            Refresh_gridgeneral(detallemov);
            Refresh_controles();
        }