示例#1
0
        protected string obtener_correo()
        {
            string usuario = HttpContext.Current.User.Identity.Name;

            PNegocio.CargarFV60 cf = new PNegocio.CargarFV60();
            string sqlstring       = "select email from usuario where usuarioLog = '" + usuario + "'";

            return(cf.otener_correo(sqlstring));
        }
示例#2
0
 private void cargar()
 {
     PEntidades.Proveedor datProveedor = (PEntidades.Proveedor)Session["proveedor"];
     if ((this.file != null) && (this.file.ContentLength > 0))
     {
         this.filName = System.IO.Path.GetFileName(this.file.FileName);
         string absoluteURL = Server.MapPath("Files") + "\\" + this.filName;
         string ext         = System.IO.Path.GetExtension(absoluteURL).ToLower();
         if (ext == ".xml")                    //Cuando si es XML
         {
             try
             {
                 HttpPostedFile file2 = file;
                 this.xmlDoc = new System.Xml.XmlDocument();
                 this.xmlDoc.Load(this.file.InputStream);
                 this.index = buscarIndexByXBLNR(this.xmlDoc);             //Para saber de que item en lista vamos a hacer la validación con SAP y SAT
                 List <string[]> listaDiferentesInstancias = (List <string[]>)Session["listaDiferentesInstancias"];
                 if (this.index != "")                                     //Cuando si se encuentra la factura
                 {
                     string raw = "";
                     if (validarSAT(this.xmlDoc))                          //Cuando es válido en SAT
                     {
                         if (validarSAP())                                 //Cuando es válido en SAP
                         {
                             PNegocio.CargarFV60 cf = new PNegocio.CargarFV60();
                             raw = this.xmlDoc.InnerXml;
                             this.listFV60[int.Parse(index)].UrlXML = this.filName;
                             Session["lstFacturas"] = this.listFV60;
                         }
                         else             //Cuando no es válido en SAP
                         {
                             PNegocio.CargarFV60 cf = new PNegocio.CargarFV60();
                         }
                     }
                     else                //Cuando no es válido en SAT
                     {
                         PNegocio.CargarFV60 cf = new PNegocio.CargarFV60();
                     }
                     //      Para llenar la lista con las facturas que si se encontraron.
                     this.lstResumen.Add(this.listFV60[int.Parse(index)]);
                     Session["lstResumen"] = this.lstResumen;
                 }
                 else//Cuando no se encuentra la factura en la lista
                 {
                     string[] noEnc = new string[2];
                     noEnc[0] = this.filName;
                     noEnc[1] = this.xmlDoc.GetElementsByTagName("cfdi:Comprobante")[0].Attributes["folio"].Value;
                     this.lstNoEnc.Add(noEnc);
                     Session["lstNoEnc"] = this.lstNoEnc;
                 }
             }
             catch (Exception ex)
             {
                 Response.Write("Error: " + ex.Message);
             }
         }
         else//Cuando no es la extención .xml
         {
             this.listFV60[int.Parse(index)].DescripcionErrorSAP = "N/A";
             this.listFV60[int.Parse(index)].DescripcionErrorSAT = "No es XML";
         }
     }
     else//Cuando el Request.Files[0] biene vacio
     {
         this.listFV60[int.Parse(index)].DescripcionErrorSAP = "N/A";
         this.listFV60[int.Parse(index)].DescripcionErrorSAT = "No es XML";
     }
 }
示例#3
0
 protected string obtenerMaxXML()
 {
     PNegocio.CargarFV60 cf = new PNegocio.CargarFV60();
     return(cf.getMaxXML());
 }
示例#4
0
        private void cargar()
        {
            if ((File1.PostedFile != null) &&
                (File1.PostedFile.ContentLength > 0) && (File2.PostedFile != null) &&
                (File2.PostedFile.ContentLength > 0))
            {
                string fn           = System.IO.Path.GetFileName(File2.PostedFile.FileName);
                string SaveLocation = Server.MapPath("Files") + "\\" + fn;
                string nombrePdf    = Path.GetFileName(SaveLocation);
                string extPDF       = Path.GetExtension(SaveLocation).ToLower();
                fn           = System.IO.Path.GetFileName(File1.PostedFile.FileName);
                SaveLocation = Server.MapPath("Files") + "\\" + fn;
                string extXML             = Path.GetExtension(SaveLocation).ToLower();
                string tipoArchivo        = "";
                string extencionValidaXML = "";
                string extencionValidaPDF = "";
                string error        = "";
                string fecha_xml    = "";
                string referencia   = "";
                string impRetencion = "";
                string rfc          = Session["rfc"].ToString();
                //this.lblIdEstatus.Text = " ";

                if (String.IsNullOrEmpty(rfc) == false)
                {
                    extencionValidaXML = ".xml";
                    tipoArchivo        = "XML";
                }
                extencionValidaPDF = ".pdf";
                extencionValidaPDF = extencionValidaPDF.ToUpper();
                extPDF             = extPDF.ToUpper();
                extencionValidaXML = extencionValidaXML.ToUpper();
                extXML             = extXML.ToUpper();
                if (extXML == extencionValidaXML && extPDF == extencionValidaPDF)
                {
                    byte[] rawByte    = new byte[0];
                    byte[] rawBytePDF = new byte[0];
                    try
                    {
                        if (tipoArchivo == "XML")
                        {
                            this.xmlDoc = new System.Xml.XmlDocument();
                            this.xmlDoc.Load(File1.PostedFile.InputStream);
                            rawByte = Encoding.UTF8.GetBytes(this.xmlDoc.InnerXml.ToString());
                            //this.lblIdEstatus.Text = lblIdEstatus.Text + " rawByte XML  ";  //mgv
                        }
                        int fileLen;
                        fileLen    = File2.PostedFile.ContentLength;
                        rawBytePDF = new Byte[fileLen];
                        File2.PostedFile.InputStream.Read(rawBytePDF, 0, fileLen);
                        //this.lblIdEstatus.Text = lblIdEstatus.Text + " rawByte PDF  ";  //mgv

                        List <PEntidades.FV60XVerificar> listFV60 = new List <PEntidades.FV60XVerificar>();
                        listFV60 = (List <PEntidades.FV60XVerificar>)Session["lstFacturas2"];
                        //List<string[]> listaDiferentesInstancias = (List<string[]>)Session["listaDiferentesInstancias"];

                        bool continuar = false;
                        if (tipoArchivo == "XML")
                        {
                            continuar = validarSAT(ref impRetencion);
                        }
                        if (continuar)
                        {
                            if (tipoArchivo == "XML")
                            {   //mgv - si NO valida entra al envio directo
                                continuar = validarSAP(ref fecha_xml, ref referencia, impRetencion, listFV60[int.Parse(indexs[0])].XBLNR, listFV60[int.Parse(indexs[0])].WAERS, listFV60[int.Parse(indexs[0])].WRBTR, listFV60[int.Parse(indexs[0])].BLDAT, listFV60[int.Parse(indexs[0])].WMWST);
                            }
                            if (String.IsNullOrEmpty(impRetencion))
                            {
                                impRetencion = "0";
                            }
                            if (continuar)
                            {
                                PNegocio.CargarFV60 cf = new PNegocio.CargarFV60();
                                for (int i = 0; i < indexs.Length; i++)
                                {
                                    //mgv                                   //if ((listFV60[int.Parse(indexs[i])].DescripcionErrorSAP.Contains("SAP : Cargada correctamente") || tipoArchivo == "PDF") &&
                                    //mgv                                   //    listFV60[int.Parse(indexs[i])].ZCOUNT <= maxXML)
                                    if (listFV60[int.Parse(indexs[i])].ZCOUNT <= maxXML)
                                    {
                                        int contadorres = 0;
                                        //int indexInstanciaCorrespondiente = Gen.Util.CS.Gen.buscarIndexUbicacionInstanciaCorrres(listaDiferentesInstancias, listFV60[int.Parse(indexs[i])].IDINSTANCIA);

                                        try
                                        {
                                            error       = "3";
                                            contadorres =
                                                cf.setFV60cargadasNew(listFV60[int.Parse(indexs[i])].BUKRS,
                                                                      listFV60[int.Parse(indexs[i])].GJAHR,
                                                                      listFV60[int.Parse(indexs[i])].BELNR,
                                                                      listFV60[int.Parse(indexs[i])].uuid,
                                                                      emisor,
                                                                      receptor,
                                                                      listFV60[int.Parse(indexs[i])].WRBTR,
                                                                      listFV60[int.Parse(indexs[i])].WAERS,
                                                                      listFV60[int.Parse(indexs[i])].KURSF,
                                                                      listFV60[int.Parse(indexs[i])].BLDAT,
                                                                      rawByte,
                                                                      rawBytePDF,
                                                                      fn
                                                                      );
                                            //this.lblIdEstatus.Text = lblIdEstatus.Text + "ERR3 ->" + contadorres.ToString();
                                            error = "4";
                                            listFV60[int.Parse(indexs[i])].UrlXML = fn;

                                            complementoMsgError  = "XML: " + fn.ToString();
                                            complementoMsgError += "</br>";
                                            complementoMsgError += "UUID: " + listFV60[int.Parse(indexs[i])].uuid;
                                            complementoMsgError += "</br>";
                                            complementoMsgError += listFV60[int.Parse(indexs[i])].DescripcionErrorSAT;
                                            complementoMsgError += "</br>";
                                            if (contadorres != 0)
                                            {
                                                complementoMsgError += listFV60[int.Parse(indexs[i])].DescripcionErrorSAP;
                                                listFV60[int.Parse(indexs[i])].ZCOUNT  = contadorres;
                                                listFV60[int.Parse(indexs[i])].consola = listFV60[int.Parse(index)].DescripcionErrorSAP.Replace("SAP : ", "");
                                            }
                                            else
                                            {
                                                listFV60[int.Parse(indexs[i])].consola = "SAP: Error al guardar el " + tipoArchivo;
                                                complementoMsgError += "SAP: Error al guardar el " + tipoArchivo + " " + cf.msg;
                                            }
                                            //mgv - no se manejan detalles, solo encabezados   if (i == 0)
                                            //{
                                            //    listFV60[int.Parse(indexs2[i])].consola = listFV60[int.Parse(indexs[i])].consola;
                                            //}
                                            complementoMsgError += "</br>";
                                            complementoMsgError += "</br>";

                                            if (listFV60[int.Parse(indexs[i])].msgVarios == "")
                                            {
                                                listFV60[int.Parse(indexs[i])].esPrimerCarga = true;
                                            }
                                            else
                                            {
                                                listFV60[int.Parse(indexs[i])].esPrimerCarga = false;
                                            }
                                            listFV60[int.Parse(indexs[i])].msgVarios += complementoMsgError;
                                        }
                                        catch (Exception z)
                                        {
                                            listFV60[int.Parse(indexs[i])].consola             = "Error al momento de adjuntar el archivo al sistema SAP.";
                                            listFV60[int.Parse(indexs[i])].DescripcionErrorSAP = "N/A";
                                            listFV60[int.Parse(indexs[i])].DescripcionErrorSAT = "";
                                            listFV60[int.Parse(indexs[i])].ErrorMostrar        = "N/A";
                                        }
                                    }
                                    else if (listFV60[int.Parse(indexs[i])].ZCOUNT > maxXML)
                                    {
                                        listFV60[int.Parse(indexs[i])].consola = "Limite de archivos alcanzado";
                                    }
                                }
                                Session["lstFacturas"] = listFV60;
                                cargarDatosTabla();
                            }
                            else
                            {
                                PNegocio.CargarFV60 cf = new PNegocio.CargarFV60();
                                for (int i = 0; i < indexs.Length; i++)
                                {
                                    if (listFV60[int.Parse(indexs[i])].ZCOUNT <= maxXML)
                                    {
                                        complementoMsgError  = "DIFERENCIAS CON EL XML: " + fn.ToString();
                                        complementoMsgError += "</br>";
                                        complementoMsgError += "UUID: " + listFV60[int.Parse(indexs[i])].uuid;
                                        complementoMsgError += "</br>";
                                        complementoMsgError += listFV60[int.Parse(indexs[i])].DescripcionErrorSAT;
                                        complementoMsgError += "</br>";
                                        complementoMsgError += listFV60[int.Parse(indexs[i])].DescripcionErrorSAP;
                                        complementoMsgError += "</br>";
                                        complementoMsgError += "</br>";

                                        if (listFV60[int.Parse(indexs[i])].msgVarios == "")
                                        {
                                            listFV60[int.Parse(indexs[i])].esPrimerCarga = true;
                                        }
                                        else
                                        {
                                            listFV60[int.Parse(indexs[i])].esPrimerCarga = false;
                                        }
                                        listFV60[int.Parse(indexs[i])].msgVarios += complementoMsgError;
                                        listFV60[int.Parse(indexs[i])].consola    = listFV60[int.Parse(indexs[i])].DescripcionErrorSAP;
                                        //mgv - no se manejan detalles, solo encabezados       if (i == 0)
                                        //{
                                        //    listFV60[int.Parse(indexs2[i])].consola = listFV60[int.Parse(indexs[i])].DescripcionErrorSAP;
                                        //}
                                    }
                                }
                                cargarDatosTabla();
                            }
                        }
                        else
                        {
                            PNegocio.CargarFV60 cf = new PNegocio.CargarFV60();

                            for (int i = 0; i < indexs.Length; i++)
                            {
                                if (listFV60[int.Parse(indexs[i])].ZCOUNT <= maxXML)
                                {
                                    listFV60[int.Parse(indexs[i])].consola = listFV60[int.Parse(indexs[i])].DescripcionErrorSAT;
                                    complementoMsgError += "UUID: " + listFV60[int.Parse(indexs[i])].uuid;
                                    complementoMsgError += "</br>";
                                    complementoMsgError  = "XML: " + fn.ToString();
                                    complementoMsgError += "</br>";
                                    complementoMsgError += listFV60[int.Parse(indexs[i])].DescripcionErrorSAT;
                                    complementoMsgError += "</br>";
                                    complementoMsgError += listFV60[int.Parse(indexs[i])].DescripcionErrorSAP;
                                    complementoMsgError += "</br>";
                                    complementoMsgError += "</br>";

                                    if (listFV60[int.Parse(indexs[i])].msgVarios == "")
                                    {
                                        listFV60[int.Parse(indexs[i])].esPrimerCarga = true;
                                    }
                                    else
                                    {
                                        listFV60[int.Parse(indexs[i])].esPrimerCarga = false;
                                    }
                                    listFV60[int.Parse(indexs[i])].msgVarios += complementoMsgError;
                                    //mgv - no se manejan detalles, solo encabezados       if (i == 0)
                                    //{
                                    //    listFV60[int.Parse(indexs2[i])].consola = listFV60[int.Parse(indexs[i])].DescripcionErrorSAT;
                                    //}
                                }
                            }
                            cargarDatosTabla();
                        }
                    }
                    catch (Exception ex)
                    {
                        this.lblConsola.Text = "Error al cargar el archivo verifique que el XML este generado correctamente";
                        Response.Write("Error: " + ex.Message); //Nota: Exception.Message devuelve un mensaje detallado que describe la excepción actual. //Por motivos de seguridad, no se recomienda devolver Exception.Message a los usuarios finales de //entornos de producción. Sería más aconsejable poner un mensaje de error genérico. } } else { Response.Write("Seleccione un archivo que cargar.");
                    }
                }
                else
                {
                    string mesajeerr = "";
                    List <PEntidades.FV60XVerificar> listFV60 = new List <PEntidades.FV60XVerificar>();
                    listFV60 = (List <PEntidades.FV60XVerificar>)Session["lstFacturas2"];
                    if ((extXML == extencionValidaXML) == false)
                    {
                        mesajeerr += "El formato del campo de achivos XML es incorrecto.</br>";
                    }
                    if ((extPDF == extencionValidaPDF) == false)
                    {
                        mesajeerr += "El formato del campo de achivos PDF es incorrecto.</br>";
                    }

                    for (int i = 0; i < indexs.Length; i++)
                    {
                        listFV60[int.Parse(indexs[i])].DescripcionErrorSAP = "N/A";
                        listFV60[int.Parse(indexs[i])].DescripcionErrorSAT = mesajeerr; //No es XML
                        listFV60[int.Parse(indexs[i])].consola             = mesajeerr; //No es XML
//mgv - no se manejan detalles, solo encabezados                           if (i == 0)
                        //{
                        //    listFV60[int.Parse(indexs2[i])].consola = listFV60[int.Parse(indexs[i])].consola;
                        //}
                    }
                    cargarDatosTabla();
                }
            }
            else
            {
                string mesajeerr = "";
                if ((File1.PostedFile == null) ||
                    (File1.PostedFile.ContentLength == 0))
                {
                    mesajeerr += "Ingrese un archivo XML.</br>";
                }
                if ((File2.PostedFile == null) ||
                    (File2.PostedFile.ContentLength == 0))
                {
                    mesajeerr += "Ingrese un archivo PDF.</br>";
                }
                List <PEntidades.FV60XVerificar> listFV60 = new List <PEntidades.FV60XVerificar>();
                listFV60 = (List <PEntidades.FV60XVerificar>)Session["lstFacturas2"];
                for (int i = 0; i < indexs.Length; i++)
                {
                    listFV60[int.Parse(indexs[i])].DescripcionErrorSAP = "N/A";
                    listFV60[int.Parse(indexs[i])].DescripcionErrorSAT = mesajeerr; //No es XML
                    listFV60[int.Parse(indexs[i])].consola             = mesajeerr; //No es XML
//mgv - no se manejan detalles, solo encabezados               if (i == 0)
                    //{
                    //    listFV60[int.Parse(indexs2[i])].consola = listFV60[int.Parse(indexs[i])].consola;
                    //}
                }
                cargarDatosTabla();
            }
        }