Exemplo n.º 1
0
        public void CriarJson()
        {
            string pathJson = "JSON.txt";

            using (var repo = new DBProvaFortesEntities())
            {
                IList <tbPrestador> prestador = repo.tbPrestador.ToList();
                IList <tbTomador>   tomador   = repo.tbTomador.ToList();
                IList <tbNota>      nota      = repo.tbNota.ToList();
                IList <tbItem>      item      = repo.tbItem.ToList();

                foreach (var p in prestador)
                {
                    string x = "";
                    x = "Prestador   {" + Environment.NewLine

                        + "\"CNPJ\" : \"" + p.CNPJ + "\"," + Environment.NewLine
                        + "\"Nome\" : \"" + p.NOME + "\"," + Environment.NewLine
                        + "\"RazaoSocial\" : \"" + p.RAZAOSOCIAL + "\"," + Environment.NewLine
                        + "\"Rua\" : \"" + p.RUA + "\"," + Environment.NewLine
                        + "\"Numero\" : \"" + p.NUMERO + "\"," + Environment.NewLine
                        + "\"Bairro\" : \"" + p.BAIRRO + "\"," + Environment.NewLine
                        + "\"UF\": \"" + p.UF + "\"," + Environment.NewLine
                        + "\"CEP\" : \"" + p.CEP + "\"," + Environment.NewLine
                        + "\"Telefone\" : \"" + p.TELEFONE + "\"," + Environment.NewLine + "}";

                    using (StreamWriter sw = File.AppendText(pathJson))
                    {
                        sw.WriteLine(x);
                    }
                }

                foreach (var t in tomador)
                {
                    string x = "";
                    x = "Tomador   {" + Environment.NewLine
                        + "\"CNPJ\" : \"" + t.CNPJ + "\"," + Environment.NewLine
                        + "\"Nome\" : \"" + t.NOME + "\"," + Environment.NewLine
                        + "\"Rua\" : \"" + t.RUA + "\"," + Environment.NewLine
                        + "\"Numero\" : \"" + t.NUMERO + "\"," + Environment.NewLine
                        + "\"Bairro\" : \"" + t.BAIRRO + "\"," + Environment.NewLine
                        + "\"UF\": \"" + t.UF + "\"," + Environment.NewLine
                        + "\"Telefone\" : \"" + t.TELEFONE + "\"," + Environment.NewLine
                        + "\"Email\" : \"" + t.EMAIL + "\"," + Environment.NewLine + "}";
                    using (StreamWriter sw = File.AppendText(pathJson))
                    {
                        sw.WriteLine(x);
                    }
                }

                foreach (var n in nota)
                {
                    string x = "";
                    x = "Nota   {" + Environment.NewLine
                        + "\"Numero\" : \"" + n.NUMERO + "\"," + Environment.NewLine
                        + "\"Data\" : \"" + n.DATA + "\"," + Environment.NewLine
                        + "\"Valor\" : \"" + n.VALOR + "\"," + Environment.NewLine + "}";

                    using (StreamWriter sw = File.AppendText(pathJson))
                    {
                        sw.WriteLine(x);
                    }
                }

                foreach (var i in item)
                {
                    string x = "";
                    x = "Item   {" + Environment.NewLine
                        + "\"Matricula\" : \"" + i.MATRICULA + "\"," + Environment.NewLine
                        + "\"Numero\" : \"" + i.NUMERO + "\"," + Environment.NewLine
                        + "\"Nome\" : \"" + i.NOME + "\"," + Environment.NewLine
                        + "\"Quantidade\" : \"" + i.QUANTIDADE + "\"," + Environment.NewLine
                        + "\"Valor\" : \"" + i.VALOR + "\"," + Environment.NewLine + "}";
                    ;

                    using (StreamWriter sw = File.AppendText(pathJson))
                    {
                        sw.WriteLine(x);
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void CriarXML()
        {
            string pathJson = "XML.txt";

            using (var repo = new DBProvaFortesEntities())
            {
                IList <tbPrestador> prestador = repo.tbPrestador.ToList();
                IList <tbTomador>   tomador   = repo.tbTomador.ToList();
                IList <tbNota>      nota      = repo.tbNota.ToList();
                IList <tbItem>      item      = repo.tbItem.ToList();

                foreach (var p in prestador)
                {
                    string x = "";
                    x = "<Prestador Id=\"" + p.ID + "\">\"" + Environment.NewLine
                        + "  <Prestador>" + Environment.NewLine
                        + "    <CNPJ>" + p.CNPJ + "</CNPJ>" + Environment.NewLine
                        + "    <Nome>" + p.NOME + "</Nome>" + Environment.NewLine
                        + "    <RazaoSocial>" + p.RAZAOSOCIAL + "</RazaoSocial>" + Environment.NewLine
                        + "    <Rua>" + p.RUA + "</Rua>" + Environment.NewLine
                        + "    <Numero>" + p.NUMERO + "</Numero>" + Environment.NewLine
                        + "    <Bairro>: " + p.BAIRRO + "</Bairro>: " + Environment.NewLine
                        + "    <UF>" + p.UF + "</UF>" + Environment.NewLine
                        + "    <CEP>" + p.CEP + "</CEP>" + Environment.NewLine
                        + "    <Telefone>" + p.TELEFONE + "</Telefone>" + Environment.NewLine
                        + "  </Prestador>" + Environment.NewLine
                        + "</Prestador>";

                    using (StreamWriter sw = File.AppendText(pathJson))
                    {
                        sw.WriteLine(x);
                    }
                }

                foreach (var p in tomador)
                {
                    string x = "";
                    x = "<Tomador Id=\"" + p.ID + "\">\"" + Environment.NewLine
                        + "  <Tomador>" + Environment.NewLine
                        + "    <CNPJ>" + p.CNPJ + "</CNPJ>" + Environment.NewLine
                        + "    <Nome>" + p.NOME + "</Nome>" + Environment.NewLine
                        + "    <Rua>" + p.RUA + "</Rua>" + Environment.NewLine
                        + "    <Numero>" + p.NUMERO + "</Numero>" + Environment.NewLine
                        + "    <Bairro>: " + p.BAIRRO + "</Bairro>: " + Environment.NewLine
                        + "    <UF>" + p.UF + "</UF>" + Environment.NewLine
                        + "    <Telefone>" + p.TELEFONE + "</Telefone>" + Environment.NewLine
                        + "    <Email>" + p.EMAIL + "</Email>" + Environment.NewLine
                        + "  </Tomador>" + Environment.NewLine
                        + "</Tormador>";
                    using (StreamWriter sw = File.AppendText(pathJson))
                    {
                        sw.WriteLine(x);
                    }
                }

                foreach (var n in nota)
                {
                    string x = "";
                    x = "<Nota Id=\"" + n.ID + "\">\"" + Environment.NewLine
                        + "  <Nota>" + Environment.NewLine
                        + "    <Numero>" + n.NUMERO + "</Numero>" + Environment.NewLine
                        + "    <Data>" + n.DATA + "</Data>" + Environment.NewLine
                        + "    <Valor>" + n.VALOR + "</Valor>" + Environment.NewLine
                        + "  </Nota>" + Environment.NewLine
                        + "</Nota>";

                    using (StreamWriter sw = File.AppendText(pathJson))
                    {
                        sw.WriteLine(x);
                    }
                }

                foreach (var i in item)
                {
                    string x = "";
                    x = "<Item Id=\"" + i.ID + "\">\"" + Environment.NewLine
                        + "  <Item>" + Environment.NewLine
                        + "    <Matricula>" + i.MATRICULA + "</Matricula>" + Environment.NewLine
                        + "    <Numero>" + i.NUMERO + "</Numero>" + Environment.NewLine
                        + "    <Nome>" + i.NOME + "</Nome>" + Environment.NewLine
                        + "    <Quantidade>" + i.QUANTIDADE + "</Quantidade>" + Environment.NewLine
                        + "    <Valor>" + i.VALOR + "</Valor>" + Environment.NewLine
                        + "  </Item>" + Environment.NewLine
                        + "</Item>";

                    using (StreamWriter sw = File.AppendText(pathJson))
                    {
                        sw.WriteLine(x);
                    }
                }
            }
        }