public static string Click_Save(string CWAR, string ITEM, string CLOT, string LOCA, string QTYS, string UNIT)
        {
            //int consecutivoPalletID = 0;
            //DataTable DTPalletContinue = twhcol130DAL.PaidMayorwhcol130("INITIAPOP-P");
            //string SecuenciaPallet = "001";
            //if (DTPalletContinue.Rows.Count > 0)
            //{
            //    foreach (DataRow item in DTPalletContinue.Rows)
            //    {
            //        string paid = item["T$PAID"].ToString().Trim();
            //        int indesSep = item["T$PAID"].ToString().Trim().IndexOf("-P");
            //        string secuence = paid.Substring(indesSep + 1);
            //        consecutivoPalletID = Convert.ToInt32(secuence)+1;
            //        if (consecutivoPalletID.ToString().Length == 1)
            //        {
            //            SecuenciaPallet = "P00" + consecutivoPalletID;
            //        }
            //        if (consecutivoPalletID.ToString().Length == 2)
            //        {
            //            SecuenciaPallet = "P0" + consecutivoPalletID;
            //        }
            //        if (consecutivoPalletID.ToString().Length == 3)
            //        {
            //            SecuenciaPallet = "P"+consecutivoPalletID.ToString();
            //        }

            //    }

            //}
            Ent_ttwhcol016 data016  = new Ent_ttwhcol016();;
            string         retorno  = string.Empty;
            string         strError = string.Empty;

            data016.zone = serieLabelRM;
            DataTable dat016      = ITtwhcol016.VerificaCons_Serie_Label(ref data016, ref strError);
            int       actcontador = ITtwhcol016.actualizarContadores(ref data016, ref strError);
            //string SecuenciaPallet = "C";
            string consecutivo = dat016.Rows[0]["CONSEC"].ToString().PadLeft(3, '0');
            string serie       = dat016.Rows[0]["SEQ"].ToString();

            if (consecutivo == "990")
            {
                data016.serietemp = Convert.ToInt32(dat016.Rows[0]["SEQ"].ToString()) + 1;
                int retconser = ITtwhcol016.ActualizarSerie_Consecutivo(ref data016, ref strError);
            }
            if (consecutivo == "998")
            {
                data016.serietemp = Convert.ToInt32(dat016.Rows[0]["SEQ"].ToString());
                int retconser = ITtwhcol016.DesactivarSerie_Consecutivo(ref data016, ref strError);
            }
            string id   = CLOT.Trim() == "" ? cyclecountLabelRM : CLOT.Trim();
            string sqnb = cyclecountLabelRM.Trim() + serie.Trim() + "-" + consecutivo;

            Ent_twhcol130131 MyObj = new Ent_twhcol130131
            {
                OORG = "2",// Order type escaneada view
                //ORNO = "INITIAPOP",
                ORNO = cyclecountLabelRM.Trim() + serie.Trim(),
                ITEM = ITEM.ToUpper(),
                //PAID = "INITIAPOP" + "-" + SecuenciaPallet,
                PAID  = sqnb,
                PONO  = "1",
                SEQN  = "1",
                CLOT  = CLOT.ToUpper(),                                 // lote VIEW
                CWAR  = CWAR.ToUpper(),
                QTYS  = QTYS,                                           // cantidad escaneada view
                QTYA  = QTYS,
                UNIT  = UNIT,                                           //unit escaneada view
                QTYC  = QTYS,                                           //cantidad escaneada view aplicando factor
                UNIC  = UNIT,                                           //unidad view stock
                DATE  = DateTime.Now.ToString("dd/MM/yyyy").ToString(), //fecha de confirmacion
                CONF  = "1",
                RCNO  = " ",                                            //llena baan
                DATR  = DateTime.Now.ToString("dd/MM/yyyy").ToString(), //llena baan
                LOCA  = LOCA.ToUpper(),                                 // enviamos vacio
                DATL  = DateTime.Now.ToString("dd/MM/yyyy").ToString(), //llenar con fecha de hoy
                PRNT  = "1",                                            // llenar en 1
                DATP  = DateTime.Now.ToString("dd/MM/yyyy").ToString(), //llena baan
                NPRT  = "1",                                            //conteo de reimpresiones
                LOGN  = HttpContext.Current.Session["user"].ToString(), // nombre de ususario de la session
                LOGT  = " ",                                            //llena baan
                STAT  = "3",                                            // LLENAR EN 3
                DSCA  = " ",
                COTP  = " ",
                FIRE  = "2",
                PSLIP = " ",
                ALLO  = "0",
                //PAID_URL = UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + "INITIAPOP" + "-" + SecuenciaPallet + "&code=Code128&dpi=96",
                PAID_URL = UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + "INITIAPOP" + "-" + sqnb + "&code=Code128&dpi=96",
                ORNO_URL = UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + "DTOrdencompra.Rows[0][].ToString()" + "&code=Code128&dpi=96",
                ITEM_URL = UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + ITEM + "&code=Code128&dpi=96",
                CLOT_URL = CLOT.ToString().Trim() != "" ? UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + CLOT + "&code=Code128&dpi=96" : "",
                QTYC_URL = UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + QTYS + "&code=Code128&dpi=96",
                UNIC_URL = UrlBaseBarcode + "/Barcode/BarcodeHandler.ashx?data=" + UNIT + "&code=Code128&dpi=96"
            };

            string StrError     = string.Empty;
            bool   Insertsucces = twhcol130DAL.Insertartwhcol131(MyObj, ref StrError);

            if (Insertsucces)
            {
                HttpContext.Current.Session["MaterialDesc"] = "XXXXX XXX XXX XX";
                HttpContext.Current.Session["MaterialCode"] = MyObj.ITEM;
                HttpContext.Current.Session["codePaid"]     = MyObj.PAID;
                HttpContext.Current.Session["Lot"]          = MyObj.CLOT;
                HttpContext.Current.Session["Quantity"]     = MyObj.QTYS + " " + UNIT;
                HttpContext.Current.Session["Origin"]       = MyObj.CLOT;
                HttpContext.Current.Session["Supplier"]     = "";
                HttpContext.Current.Session["RecibedBy"]    = MyObj.LOGN;
                HttpContext.Current.Session["RecibedOn"]    = DateTime.Now.ToString("MM/dd/yyyy");
                HttpContext.Current.Session["Reprint"]      = "no";
            }
            else
            {
                MyObj.error     = true;
                MyObj.TypeMsgJs = "label";
                MyObj.errorMsg  = "Error insert";
            }


            return(JsonConvert.SerializeObject(MyObj));
        }
        protected void Save_Click(object sender, EventArgs e)
        {
            string        ITEM = HttpContext.Current.Session["ITEM"].ToString();
            string        CWAR = HttpContext.Current.Session["CWAR"].ToString();
            string        CLOT = HttpContext.Current.Session["CLOT"].ToString();
            string        LOCA = HttpContext.Current.Session["LOCA"].ToString();
            string        QTYS = HttpContext.Current.Session["QTYS"].ToString();
            string        UNIT = HttpContext.Current.Session["UNIT"].ToString();
            string        CUNI = HttpContext.Current.Session["CUNI"].ToString();
            Ent_tticol022 data022;
            Ent_tticol042 data042;
            string        strError = string.Empty;
            //JC 020801 Conseguir el último consecutivo de la serie NFP definida en baan
            Ent_ttwhcol016 data016 = new Ent_ttwhcol016();;
            string         retorno = string.Empty;

            data016.zone = serieLabelFP;
            DataTable dat016      = _idaltwhcol016.VerificaCons_Serie_Label(ref data016, ref strError);
            int       actcontador = _idaltwhcol016.actualizarContadores(ref data016, ref strError);
            //string SecuenciaPallet = "C";
            string consecutivo = dat016.Rows[0]["CONSEC"].ToString().PadLeft(3, '0');
            string serie       = dat016.Rows[0]["SEQ"].ToString();

            if (consecutivo == "990")
            {
                data016.serietemp = Convert.ToInt32(dat016.Rows[0]["SEQ"].ToString()) + 1;
                int retconser = _idaltwhcol016.ActualizarSerie_Consecutivo(ref data016, ref strError);
            }
            if (consecutivo == "998")
            {
                data016.serietemp = Convert.ToInt32(dat016.Rows[0]["SEQ"].ToString());
                int retconser = _idaltwhcol016.DesactivarSerie_Consecutivo(ref data016, ref strError);
            }
            string id   = CLOT.Trim() == "" ? cyclecountLabel : CLOT.Trim();
            string sqnb = cyclecountLabel.Trim() + serie.Trim() + "-" + consecutivo;

            //if (HttpContext.Current.Session["myItemType"].ToString().Trim() != "RET")
            //{
            //string id = cyclecountLabel;
            //JC 020821 Conseguir el último consecutivo de la serie NFP ya no se buscará el consecutivo por orden
            //DataTable Dtticol022 = _idaltticol022.SecuenciaMayor(id);
            //if (Dtticol022.Rows.Count > 0)
            //{

            //int res;
            //string sqnb = Dtticol022.Rows[0]["T$SQNB"].ToString().Trim() == "" ? SecuenciaPallet : Dtticol022.Rows[0]["T$SQNB"].ToString().Trim();
            //int iSep = sqnb.IndexOf("-");
            //string CurrentSecuence = sqnb.Substring(iSep + 1).Replace("C","");
            // //consecutivo = Convert.ToInt32(CurrentSecuence)+1;
            //consecutivo = CurrentSecuence + 1;
            //}
            //else
            //{
            //    //consecutivo = 1;
            //    consecutivo = "1";
            //}
            //}
            //else
            //{
            //    //string id = CLOT.Trim() == "" ? ITEM.Trim() : CLOT.Trim();
            //    //string id = cyclecountLabel;
            //    DataTable Dtticol042 = _idaltticol042.SecuenciaMayor(id);
            //    if (Dtticol042.Rows.Count > 0)
            //    {
            //        int res;
            //        string sqnb = Dtticol042.Rows[0]["T$SQNB"].ToString().Trim();
            //        int iSep = sqnb.IndexOf("-");
            //        string CurrentSecuence = sqnb.Substring(iSep + 1).Replace("C", "");
            //        //consecutivo = Convert.ToInt32(CurrentSecuence)+1;
            //        consecutivo = CurrentSecuence + 1;
            //    }
            //    else
            //    {
            //        //consecutivo = 1;
            //        consecutivo = "1";
            //    }
            //}

            //JC 020821 Conseguir el último consecutivo de la serie NFP ya no se buscará el consecutivo por orden
            //if (consecutivo.ToString().Length == 1)
            //{
            //    SecuenciaPallet = "C00" + consecutivo.ToString();
            //}
            //if (consecutivo.ToString().Length == 2)
            //{
            //    SecuenciaPallet = "C0" + consecutivo.ToString();
            //}
            //if (consecutivo.ToString().Length == 3)
            //{
            //    SecuenciaPallet = "C0" + consecutivo.ToString();
            //}


            if (HttpContext.Current.Session["myItemType"].ToString().Trim() != "RET")
            {
                data022      = new Ent_tticol022();
                data022.pdno = CLOT == "" ? cyclecountLabel.Trim() + serie.Trim() : CLOT.Trim();
                //data022.sqnb = (CLOT == "" ? cyclecountLabel : CLOT.Trim()) + "-" + SecuenciaPallet;
                data022.sqnb    = sqnb;
                data022.proc    = 2;
                data022.logn    = HttpContext.Current.Session["user"].ToString();
                data022.mitm    = ITEM.Trim();
                data022.qtdl    = Convert.ToDecimal(QTYS);
                data022.cuni    = CUNI;
                data022.log1    = "NONE";
                data022.qtd1    = Convert.ToInt32(Convert.ToDecimal(QTYS));
                data022.pro1    = 2;
                data022.log2    = "NONE";
                data022.qtd2    = Convert.ToInt32(Convert.ToDecimal(QTYS));
                data022.pro2    = 2;
                data022.loca    = " ";
                data022.norp    = 1;
                data022.dele    = 7;
                data022.logd    = "NONE";
                data022.refcntd = 0;
                data022.refcntu = 0;
                data022.drpt    = DateTime.Now;
                data022.urpt    = HttpContext.Current.Session["user"].ToString();
                data022.acqt    = Convert.ToDecimal(QTYS);
                data022.cwaf    = CWAR;
                data022.cwat    = CWAR;
                data022.aclo    = LOCA;
                data022.allo    = 0;

                HttpContext.Current.Session["strOrden"]  = data022.pdno;
                HttpContext.Current.Session["strSecuen"] = data022.sqnb;
                HttpContext.Current.Session["itemId"]    = data022.mitm;
                HttpContext.Current.Session["cantidad"]  = data022.acqt;
                HttpContext.Current.Session["bodega"]    = data022.cwaf;
                HttpContext.Current.Session["usuario"]   = data022.urpt;
                HttpContext.Current.Session["fecha"]     = data022.drpt;
                HttpContext.Current.Session["descItem"]  = data022.mitm;
                HttpContext.Current.Session["unidad"]    = data022.cuni;
                HttpContext.Current.Session["strTagId"]  = "";

                var validateSave         = _idaltticol022.insertarRegistroSimple(ref data022, ref strError);
                var validateSaveTicol222 = _idaltticol022.InsertarRegistroTicol222(ref data022, ref strError);

                //return JsonConvert.SerializeObject(data022);
                if (Convert.ToBoolean(validateSave) && Convert.ToBoolean(validateSaveTicol222))
                {
                    HttpContext.Current.Session["MaterialDesc"] = data022.mitm;
                    HttpContext.Current.Session["codeMaterial"] = data022.mitm;
                    HttpContext.Current.Session["codePaid"]     = data022.sqnb;
                    HttpContext.Current.Session["Lot"]          = CLOT;
                    HttpContext.Current.Session["Quantity"]     = data022.acqt + " " + data022.cuni;
                    HttpContext.Current.Session["Date"]         = DateTime.Now.ToString("MM/dd/yyyy");
                    HttpContext.Current.Session["Pallet"]       = data022.sqnb;
                    HttpContext.Current.Session["Machine"]      = _idaltticol022.getMachine(CLOT, ITEM.Trim().ToUpper(), ref strError);
                    HttpContext.Current.Session["Operator"]     = _operator;
                    HttpContext.Current.Session["Reprint"]      = "no";


                    StringBuilder script = new StringBuilder();
                    if (HttpContext.Current.Session["navigator"].ToString() == "EDG")
                    {
                        script.Append("myLabelFrame = document.getElementById('myLabelFrame'); myLabelFrame.src ='../Labels/RedesingLabels/4FinishedCupsME.aspx'; ");
                    }
                    else
                    {
                        script.Append("myLabelFrame = document.getElementById('myLabelFrame'); myLabelFrame.src ='../Labels/RedesingLabels/4FinishedCups.aspx'; ");
                    }

                    ScriptManager.RegisterStartupScript(this, this.GetType(), "printTag", script.ToString(), true);

                    //StringBuilder script = new StringBuilder();
                    //script.Append("ventanaImp = window.open('../Labels/RedesingLabels/4FinishedCups.aspx', ");
                    //script.Append("'ventanaImp', 'menubar=0,resizable=0,width=700,height=450');");
                    //script.Append("ventanaImp.moveTo(30, 0);");
                    ////script.Append("setTimeout (ventanaImp.close(), 20000);");
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "printTag", script.ToString(), true);

                    //StringBuilder script = new StringBuilder();
                    //script.Append("ventanaImp = window.open('../Labels/whInvLabelFinishProduct.aspx', ");
                    //script.Append("'ventanaImp', 'menubar=0,resizable=0,width=580,height=450');");
                    //script.Append("ventanaImp.moveTo(30, 0);");
                    ////script.Append("setTimeout (ventanaImp.close(), 20000);");
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "printTag", script.ToString(), true);
                }
                else
                {
                    StringBuilder script = new StringBuilder();
                    string        alert  = "alert('" + strError.Replace("\n", "") + "')";
                    script.Append(alert);
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "printTag", script.ToString(), true);
                }
            }
            else
            {
                data042 = new Ent_tticol042()
                {
                    pdno = CLOT == "" ? cyclecountLabel.Trim() + serie.Trim() : CLOT,
                    //sqnb = (CLOT == "" ? cyclecountLabel : CLOT) + "-" + SecuenciaPallet,
                    sqnb    = sqnb,
                    proc    = 2,
                    logn    = HttpContext.Current.Session["user"].ToString(),
                    mitm    = ITEM.Trim(),
                    qtdl    = Convert.ToDouble(QTYS),
                    cuni    = CUNI,
                    log1    = "NONE",
                    qtd1    = Convert.ToDecimal(QTYS),
                    pro1    = 2,
                    log2    = "NONE",
                    qtd2    = Convert.ToDecimal(QTYS),
                    pro2    = 2,
                    loca    = " ",
                    norp    = 1,
                    dele    = 7,
                    logd    = "NONE",
                    refcntd = 0,
                    refcntu = 0,
                    drpt    = DateTime.Now,
                    urpt    = HttpContext.Current.Session["user"].ToString(),
                    acqt    = Convert.ToDouble(QTYS),
                    cwaf    = CWAR,
                    cwat    = CWAR,
                    aclo    = LOCA,
                    allo    = 0
                };

                HttpContext.Current.Session["strOrden"]  = data042.pdno;
                HttpContext.Current.Session["strSecuen"] = data042.sqnb;
                HttpContext.Current.Session["itemId"]    = data042.mitm;
                HttpContext.Current.Session["cantidad"]  = data042.acqt;
                HttpContext.Current.Session["bodega"]    = data042.cwaf;
                HttpContext.Current.Session["usuario"]   = data042.urpt;
                HttpContext.Current.Session["fecha"]     = data042.drpt;
                HttpContext.Current.Session["descItem"]  = data042.mitm;
                HttpContext.Current.Session["unidad"]    = data042.cuni;
                HttpContext.Current.Session["strTagId"]  = "";

                var validateSave         = _idaltticol042.insertarRegistroSimpleD(ref data042, ref strError);
                var validateSaveTicol242 = _idaltticol042.InsertarRegistroTicol242(ref data042, ref strError);

                //return JsonConvert.SerializeObject(data042);
                if (Convert.ToBoolean(validateSave) && Convert.ToBoolean(validateSaveTicol242))
                {
                    HttpContext.Current.Session["MaterialDesc"] = data042.mitm;
                    HttpContext.Current.Session["codeMaterial"] = data042.mitm;
                    HttpContext.Current.Session["codePaid"]     = data042.sqnb;
                    HttpContext.Current.Session["Lot"]          = CLOT;
                    HttpContext.Current.Session["Quantity"]     = data042.acqt + " " + data042.cuni;
                    HttpContext.Current.Session["Date"]         = DateTime.Now.ToString("MM/dd/yyyy");
                    HttpContext.Current.Session["Pallet"]       = data042.sqnb;
                    HttpContext.Current.Session["Machine"]      = _idaltticol022.getMachine(CLOT, ITEM.Trim().ToUpper(), ref strError);;
                    HttpContext.Current.Session["Operator"]     = _operator;
                    HttpContext.Current.Session["Reprint"]      = "no";

                    StringBuilder script = new StringBuilder();
                    if (HttpContext.Current.Session["navigator"].ToString() == "EDG")
                    {
                        script.Append("myLabelFrame = document.getElementById('myLabelFrame'); myLabelFrame.src ='../Labels/RedesingLabels/4FinishedCupsME.aspx'; ");
                    }
                    else
                    {
                        script.Append("myLabelFrame = document.getElementById('myLabelFrame'); myLabelFrame.src ='../Labels/RedesingLabels/4FinishedCups.aspx'; ");
                    }
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "printTag", script.ToString(), true);

                    //StringBuilder script = new StringBuilder();
                    //script.Append("ventanaImp = window.open('../Labels/whInvLabelFinishProduct.aspx', ");
                    //script.Append("'ventanaImp', 'menubar=0,resizable=0,width=580,height=450');");
                    //script.Append("ventanaImp.moveTo(30, 0);");
                    ////script.Append("setTimeout (ventanaImp.close(), 20000);");
                    //ScriptManager.RegisterStartupScript(this, this.GetType(), "printTag", script.ToString(), true);
                }
            }
        }