コード例 #1
0
        public LibroGuias lectura()
        {
            LibroGuias lib = new LibroGuias();


            fileAdmin file     = new fileAdmin();
            String    fileName = file.nextFile(@"" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/file/", "*.json");

            if (fileName != null)
            {
                //Paso la ruta del fichero al constructor
                StreamReader objReader = new StreamReader(fileName, System.Text.Encoding.Default, true);
                objReader.ToString();
                String data = objReader.ReadToEnd();

                DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(LibroGuias));

                MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(data));

                try
                {
                    lib = (LibroGuias)js.ReadObject(ms);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    MessageBox.Show("Error de lectura JSON" + e.Message);
                }


                objReader.Close();
                ms.Close();
                file.mvFile(fileName, "" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/file/libroguia/", "" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/fileProcess/");
                return(lib);
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        public void doLibroGuias()
        {
            String signLibroGuias = String.Empty;

            // inatancia txt_Libro
            TxtLibroGuias lib = new TxtLibroGuias();

            LibroGuias libroC = lib.lectura();

            xmlLibroGuias xml = new xmlLibroGuias();

            signLibroGuias = xml.do_libroGuias(libroC);



            signLibroGuias = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\r\n" + signLibroGuias;

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"" + Microsoft.Win32.Registry.GetValue(@"HKEY_CURRENT_USER\Iat", "unidadIat", null).ToString() + ":/IatFiles/file/xml/Libroguias" + "1" + ".xml", false, Encoding.GetEncoding("ISO-8859-1")))
            {
                file.WriteLine(signLibroGuias);
            }
            Console.WriteLine(signLibroGuias);
        }
コード例 #3
0
        public String do_libroGuias(LibroGuias libro)
        {
            Documento doc     = new Documento();
            Empresa   empresa = new Empresa();

            empresa = empresa.getEmpresa();
            if (libro != null)
            {
                String cabeceraLibro =
                    " <LibroGuia xmlns=\"http://www.sii.cl/SiiDte\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" version=\"1.0\" xsi:schemaLocation=\"http://www.sii.cl/SiiDte LibroGuia_v10.xsd\">"
                    + "<EnvioLibro ID=\"IECV201312\">"
                    + "<Caratula>"
                    + "<RutEmisorLibro>" + libro.RutEmisorLibro + "</RutEmisorLibro>"
                    + "<RutEnvia>" + libro.RutEnvia + "</RutEnvia>"
                    + "<PeriodoTributario>" + libro.PeriodoTributario + "</PeriodoTributario>"
                    + "<FchResol>" + libro.FchResol + "</FchResol>"
                    + "<NroResol>" + libro.NroResol + "</NroResol>"
                    + "<TipoLibro>ESPECIAL</TipoLibro>"
                    + "<TipoEnvio>TOTAL</TipoEnvio>"
                    + "<FolioNotificacion>1</FolioNotificacion>"
                    + "</Caratula>";


                String resumen = "<ResumenPeriodo>";


                foreach (var totPer in libro.ResumenPeriodo)
                {
                    resumen += "<TotFolAnulado>" + totPer.TotFolAnulado + "</TotFolAnulado>" +
                               "<TotGuiaAnulada>" + totPer.TotGuiaAnulada + "</TotGuiaAnulada>" +
                               "<TotGuiaVenta>" + totPer.TotGuiaVenta + "</TotGuiaVenta>" +
                               "<TotMntGuiaVta>" + totPer.TotMntGuiaVta + "</TotMntGuiaVta>" +
                               "<TotMntModificado>" + totPer.TotMntModificado + "</TotMntModificado>";

                    foreach (var tras in totPer.TotTraslado)
                    {
                        resumen += "<TotTraslado>" +
                                   "<TpoTraslado>" + tras.TpoTraslado + "</TpoTraslado>" +
                                   "<CantGuia>" + tras.CantGuia + "</CantGuia>" +
                                   "<MntGuia>" + tras.MntGuia + "</MntGuia>" +
                                   "</TotTraslado>";
                    }
                }

                String finResumen = "</ResumenPeriodo>";

                String detall = String.Empty;

                foreach (var det in libro.Detalle)
                {
                    String anulado = "<Anulado>" + det.Anulado + "</Anulado>";
                    if (det.Anulado == 0)
                    {
                        anulado = "";
                    }

                    detall += "<Detalle>" +
                              "<Folio>" + det.Folio + "</Folio>" +
                              anulado +
                              "<Operacion>" + det.Operacion + "</Operacion>" +
                              "<TpoOper>" + det.TpoOper + "</TpoOper>" +
                              "<FchDoc>" + det.FchDoc + "</FchDoc>" +
                              "<RUTDoc>" + det.RUTDoc + "</RUTDoc>" +
                              "<RznSoc>" + det.RznSoc + "</RznSoc>" +
                              "<MntNeto>" + det.MntNeto + "</MntNeto>" +
                              "<TasaImp>" + det.TasaImp + "</TasaImp>" +
                              "<IVA>" + det.IVA + "</IVA>" +
                              "<MntTotal>" + det.MntTotal + "</MntTotal>" +
                              "<MntModificado>" + det.MntModificado + "</MntModificado>" +
                              "</Detalle>";
                }

                DateTime thisDay = DateTime.Now;
                String   fch     = String.Format("{0:yyyy-MM-ddTHH:mm:ss}", thisDay);

                String finLibro =
                    "<TmstFirma>" + fch + "</TmstFirma>" +
                    "</EnvioLibro>" +
                    "</LibroGuia>";

                String libroGuia = cabeceraLibro + resumen + finResumen + detall + finLibro;


                X509Certificate2 cert = FuncionesComunes.obtenerCertificado(empresa.NomCertificado);

                String signLibro = firmarLibroGuias(libroGuia, cert);

                return(signLibro);
            }
            else
            {
                return(null);
            }
        }