public int desvincularConn(List <string[]> listaDiferentesInstancias, string[] uuid)
        {
            PEntidades.SrvSAPUProv.ZEDATA_UUID[]   objetoUui = PEntidades.Utiles.objetoUuid(uuid);
            PEntidades.SrvSAPUProv.Z_UFAC_CARGADAS cargadas  = new PEntidades.SrvSAPUProv.Z_UFAC_CARGADAS();
            //PEntidades.SrvSAPUProv.Z_UFAC_CARGADASResponse result;
            int res = 0;

            PEntidades.SrvSAPUProv.ZWS_UPROVEEDORESClient srv = new PPersistencia.WebServices().getZWS_UPROVEEDORESInstanceNew(
                listaDiferentesInstancias[0][1].ToString().Trim(),
                listaDiferentesInstancias[0][4].Split(new Char[] { ',' })
                );

            PPersistencia.SAPConn psc    = new PPersistencia.SAPConn(); //cambio del llamado hacia SAP
            List <ParamsCallSAP>  listPA = new List <ParamsCallSAP>();
            ParamsCallSAP         pr     = new ParamsCallSAP();

            pr         = new ParamsCallSAP(); //cargadas.BELNR = "";
            pr.NameVar = "BELNR";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.BUKRS = "";
            pr.NameVar = "BUKRS";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.BWTAR = "";
            pr.NameVar = "BWTAR";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.CORREO = "";
            pr.NameVar = "CORREO";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.DESADJUNTAR = "X";
            pr.NameVar = "DESADJUNTAR";
            pr.ValVar  = "X";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); // cargadas.EBELN = "";
            pr.NameVar = "EBELN";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); // cargadas.EBELP = "";
            pr.NameVar = "EBELP";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); // cargadas.FECHA_XML = "";
            pr.NameVar = "FECHA_XML";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.IMP_RETEN = 0;
            pr.NameVar = "IMP_RETEN";
            pr.ValVard = 0;
            pr.TipVar  = "D";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.KSCHL = "";
            pr.NameVar = "KSCHL";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.LIFNR = "";
            pr.NameVar = "LIFNR";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.MSJ_SAP = "";
            pr.NameVar = "MSJ_SAP";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.MSJ_SAT = "";
            pr.NameVar = "MSJ_SAT";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.PDFFILE = "";
            pr.NameVar = "PDFFILE";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.RAW = null;
            pr.NameVar = "RAW";
            pr.ValVarb = null;
            pr.TipVar  = "Y";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.RAWPDF = null;
            pr.NameVar = "RAWPDF";
            pr.ValVarb = null;
            pr.TipVar  = "Y";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.STATUS = "";
            pr.NameVar = "STATUS";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.TIPO = "";
            pr.NameVar = "TIPO";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.TIPOARCHIVO = "";
            pr.NameVar = "TIPOARCHIVO";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.WERKS = "";
            pr.NameVar = "WERKS";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.XBLNR = "";
            pr.NameVar = "XBLNR";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.XMLFILE = "";
            pr.NameVar = "XMLFILE";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.ZCFDI_UUID = "";
            pr.NameVar = "ZCFDI_UUID";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            List <TablasCallSAP> listT  = new List <TablasCallSAP>();
            TablasCallSAP        tr     = new TablasCallSAP();
            List <ParamsCallSAP> listTb = new List <ParamsCallSAP>();
            int cont = 0;

            foreach (string uui in uuid)
            {
                pr         = new ParamsCallSAP();
                pr.NameVar = "UUID_XML";
                pr.ValVar  = uui;
                pr.TipVar  = "S";
                listTb.Add(pr);
                cont++;
            }
            tr.TablaVar  = "PROVEEDOR_TB";
            tr.CamposVar = listTb;
            listT.Add(tr);

            srv.Open();
            srv.InnerChannel.OperationTimeout = new TimeSpan(0, 10, 0);

            string msg;

            msg = psc.conSAP2("Z_DFAC_CARGADAS", listPA, listT);      //result = srv.Z_UFAC_CARGADAS(cargadas);
            srv.Close();
            if (msg != "" && msg != null)
            {
                res = int.Parse(msg.Trim());
            }
            return(res);
        }
        public int setFV60cargadasNew(string bukrs, string gjahr, string belnr, string uuid_cfdi, string rfc_emisor,
                                      string rfc_receptor, decimal wrbtr, string waers, decimal kursf, string bldat, byte[] rawxml, byte[] rawpdf, string fileName)
        {
            int res = 0;

            PPersistencia.SAPConn psc  = new PPersistencia.SAPConn();
            List <ParamsCallSAP>  list = new List <ParamsCallSAP>();
            ParamsCallSAP         pr   = new ParamsCallSAP();

            pr         = new ParamsCallSAP();
            pr.NameVar = "BUKRS";
            pr.ValVar  = bukrs;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "GJAHR";
            pr.ValVar  = gjahr;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "BELNR";
            pr.ValVar  = belnr;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "UUID_CFDI";
            pr.ValVar  = uuid_cfdi;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "RFC_EMISOR";
            pr.ValVar  = rfc_emisor;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "RFC_RECEPTOR";
            pr.ValVar  = rfc_receptor;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "WRBTR";
            pr.ValVar  = wrbtr.ToString();
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "WAERS";
            pr.ValVar  = waers;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "KURSF";
            pr.ValVar  = kursf.ToString();
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "BLDAT";
            pr.ValVar  = bldat;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "FILE_NAME";
            pr.ValVar  = fileName;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "RAWPDF";
            pr.ValVarb = rawpdf;
            pr.TipVar  = "Y";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "RAWXML";
            pr.ValVarb = rawxml;
            pr.TipVar  = "Y";
            list.Add(pr);

            List <TablasCallSAP> listT  = new List <TablasCallSAP>(); // no lleva Tablas, solo para el llamado
            TablasCallSAP        tr     = new TablasCallSAP();
            List <ParamsCallSAP> listTb = new List <ParamsCallSAP>();

            string rescon = psc.conSAP2("Z_DFAC_CARGA_FV60", list, listT);

            if (rescon != "" && rescon != null)
            {
                try
                {
                    res = int.Parse(rescon.Trim());
                }
                catch (Exception)
                {
                    msg = rescon.Trim();
                }
            }
            return(res);
        }
        public int setFacturascargadasNewConn(string bukrs, string correo, string ebeln, string lifnr, string msjsap, string msgsat, string estatus, string tipo,
                                              string werks, string xblnr, string fecha_xml, string xmlfile, string endpoint, string[] userPass, byte[] raw, string uuid, decimal total,
                                              string numeroItem, string BELNR, string BWTAR, string KSCHL, string tipoarchivo, byte[] rawpdf, string pdffile, decimal retencion)
        {
            //PEntidades.SrvSAPUProv.Z_UFAC_CARGADASResponse result;
            PEntidades.SrvSAPUProv.Z_UFAC_CARGADAS cargadas = new PEntidades.SrvSAPUProv.Z_UFAC_CARGADAS();
            int res = 0;

            //PEntidades.SrvSAPUProv.ZWS_UPROVEEDORESClient srv = new PPersistencia.WebServices().getZWS_UPROVEEDORESInstanceNew(endpoint, userPass);

            PPersistencia.SAPConn psc    = new PPersistencia.SAPConn(); //cambio del llamado hacia SAP
            List <ParamsCallSAP>  listPA = new List <ParamsCallSAP>();
            ParamsCallSAP         pr     = new ParamsCallSAP();

            pr         = new ParamsCallSAP(); //cargadas.BELNR = BELNR;
            pr.NameVar = "BELNR";
            pr.ValVar  = BELNR;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.BUKRS = bukrs;
            pr.NameVar = "BUKRS";
            pr.ValVar  = bukrs;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.BWTAR = BWTAR;
            pr.NameVar = "BWTAR";
            pr.ValVar  = BWTAR;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.CORREO = correo;
            pr.NameVar = "CORREO";
            pr.ValVar  = correo;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.DESADJUNTAR = "";
            pr.NameVar = "DESADJUNTAR";
            pr.ValVar  = "";
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.EBELN = ebeln;
            pr.NameVar = "EBELN";
            pr.ValVar  = ebeln;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.EBELP = numeroItem;
            pr.NameVar = "EBELP";
            pr.ValVar  = numeroItem;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.FECHA_XML = fecha_xml;
            pr.NameVar = "FECHA_XML";
            pr.ValVar  = fecha_xml;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.IMP_RETEN = retencion;
            pr.NameVar = "IMP_RETEN";
            pr.ValVard = retencion;
            pr.TipVar  = "D";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.KSCHL = KSCHL;
            pr.NameVar = "KSCHL";
            pr.ValVar  = KSCHL;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.LIFNR = lifnr;
            pr.NameVar = "LIFNR";
            pr.ValVar  = lifnr;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.MSJ_SAP = msjsap;
            pr.NameVar = "MSJ_SAP";
            pr.ValVar  = msjsap;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.MSJ_SAT = msgsat;
            pr.NameVar = "MSJ_SAT";
            pr.ValVar  = msgsat;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.PDFFILE = pdffile;
            pr.NameVar = "PDFFILE";
            pr.ValVar  = pdffile;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.RAW = raw;
            pr.NameVar = "RAW";
            pr.ValVarb = raw;
            pr.TipVar  = "Y";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.RAWPDF = rawpdf;
            pr.NameVar = "RAWPDF";
            pr.ValVarb = rawpdf;
            pr.TipVar  = "Y";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.STATUS = estatus;
            pr.NameVar = "STATUS";
            pr.ValVar  = estatus;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.TIPO = tipo;
            pr.NameVar = "TIPO";
            pr.ValVar  = tipo;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.TIPOARCHIVO = tipoarchivo;
            pr.NameVar = "TIPOARCHIVO";
            pr.ValVar  = tipoarchivo;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.UUID_XML = null;
            pr.NameVar = "UUID_XML";
            pr.ValVar  = null;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.WERKS = werks;
            pr.NameVar = "WERKS";
            pr.ValVar  = werks;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.XBLNR = xblnr;
            pr.NameVar = "XBLNR";
            pr.ValVar  = xblnr;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.XMLFILE = xmlfile;
            pr.NameVar = "XMLFILE";
            pr.ValVar  = xmlfile;
            pr.TipVar  = "S";
            listPA.Add(pr);

            pr         = new ParamsCallSAP(); //cargadas.ZCFDI_UUID = uuid;
            pr.NameVar = "ZCFDI_UUID";
            pr.ValVar  = uuid;
            pr.TipVar  = "S";
            listPA.Add(pr);

            List <TablasCallSAP> listT  = new List <TablasCallSAP>(); // no lleva tablas, solo para la llamada
            TablasCallSAP        tr     = new TablasCallSAP();
            List <ParamsCallSAP> listTb = new List <ParamsCallSAP>();

            string msg;

            msg = psc.conSAP2("Z_DFAC_CARGADAS", listPA, listT);                //result = srv.Z_UFAC_CARGADAS(cargadas);

            if (msg != "" && msg != null)
            {
                try
                {
                    res = int.Parse(msg.Trim());
                }
                catch (Exception)
                {
                    res = 1;
                }
            }
            return(res);
        }
        public int desvincularFV60(string uuid_cfdi, string bukrs, string gjahr, string belnr)
        {
            int res = 0;

            PPersistencia.SAPConn psc  = new PPersistencia.SAPConn();
            List <ParamsCallSAP>  list = new List <ParamsCallSAP>();
            ParamsCallSAP         pr   = new ParamsCallSAP();

            pr         = new ParamsCallSAP();
            pr.NameVar = "P_BELNR";
            pr.ValVar  = belnr;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "P_GJAHR";
            pr.ValVar  = gjahr;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "P_BUKRS";
            pr.ValVar  = bukrs;
            pr.TipVar  = "S";
            list.Add(pr);

            pr         = new ParamsCallSAP();
            pr.NameVar = "P_UUID";
            pr.ValVar  = uuid_cfdi;
            pr.TipVar  = "S";
            list.Add(pr);

            List <TablasCallSAP> listT  = new List <TablasCallSAP>(); // no lleva Tablas, solo para el llamado
            TablasCallSAP        tr     = new TablasCallSAP();
            List <ParamsCallSAP> listTb = new List <ParamsCallSAP>();

            string rescon = psc.conSAP2("Z_UFAC_FV60_DESADJUNTAR", list, listT);

            if (rescon != "" && rescon != null)
            {
                try
                {
                    int    Start, End;  //buscar # de archivos desadjuntados
                    string xCuantos;
                    if (rescon.Contains("P_RETURN=") && rescon.Contains(", IMPORT"))
                    {
                        Start    = rescon.IndexOf("P_RETURN=", 0) + "P_RETURN=".Length;
                        End      = rescon.IndexOf(", IMPORT", Start);
                        xCuantos = rescon.Substring(Start, End - Start);
                        res      = int.Parse(xCuantos.Trim());
                        return(res);
                    }
                    else
                    {
                        return(0);
                    }
                }
                catch (Exception)
                {
                    msg = rescon.Trim();
                }
            }
            return(res);
        }