Example #1
0
        public static List <Cliente> ConverteParaListaCliente()
        {
            List <Cliente> Clientes = new List <Cliente>();

            try
            {
                ManipuladorArquivo file = new ManipuladorArquivo()
                {
                    Path = @"C:\Arquivos\", Name = "CLIENTE.CSV"
                };
                string[] clienteArquivados = ManipuladorArquivoControle.LerArquivo(file);


                foreach (var cliente in clienteArquivados)
                {
                    if (cliente.Length == 166)
                    {
                        string idcliente   = cliente.Substring(0, 5);
                        string cpf         = cliente.Substring(6, 11);
                        string nome        = cliente.Substring(18, 50);
                        string dnascimento = cliente.Substring(70, 10);
                        string telefone    = cliente.Substring(81, 10);
                        string logradouro  = cliente.Substring(92, 29);
                        string bairro      = cliente.Substring(123, 14);
                        string cidade      = cliente.Substring(139, 14);
                        string estado      = cliente.Substring(155, 2);
                        string cep         = cliente.Substring(158, 8);


                        Endereco novoEndereco = new Endereco()
                        {
                            Logradouro = logradouro,
                            Bairro     = bairro,
                            Cidade     = cidade,
                            Estado     = estado,
                            Cep        = cep,
                        };

                        Cliente Cliente = new Cliente()
                        {
                            IdCliente = long.Parse(idcliente),
                            Cpf       = cpf,
                            Nome      = nome,

                            Telefone = telefone,
                            Endereco = novoEndereco
                        };

                        Clientes.Add(Cliente);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("ERRO!!!!: " + ex.Message);
                Console.ReadKey();
            }

            return(Clientes);
        }
Example #2
0
        //LE O ARQUIVO E TRANSFORMA EM LISTA
        public static List <Livro> ConverterParaLista()
        {
            List <Livro> Livros = new List <Livro>();

            try
            {
                ManipuladorArquivo file = new ManipuladorArquivo()
                {
                    Path = @"C:\Arquivos\", Name = "LIVRO.CSV"
                };
                string[] livroArquivados = ManipuladorArquivoControle.LerArquivo(file);


                foreach (var livro in livroArquivados)
                {
                    if (livro.Length == 149)
                    {
                        string numerotombo    = livro.Substring(0, 5);
                        string isbn           = livro.Substring(6, 13);
                        string titulo         = livro.Substring(20, 50);
                        string genero         = livro.Substring(71, 15);
                        string datapublicacao = livro.Substring(87, 10);
                        string autor          = livro.Substring(98, 50);


                        Livro Livro = new Livro()
                        {
                            NumeroTombo    = long.Parse(numerotombo),
                            Isbn           = isbn,
                            Titulo         = titulo,
                            Genero         = genero,
                            DataPublicacao = Convert.ToDateTime(datapublicacao),
                            Autor          = autor
                        };

                        Livros.Add(Livro);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("ERRO!!!!: " + ex.Message);
                Console.ReadKey();
            }

            return(Livros);
        }
Example #3
0
        public static List <EmprestimoLivro> ConverteParaListaEmprestimo()
        {
            List <EmprestimoLivro> EmprestimoLivro = new List <EmprestimoLivro>();

            try
            {
                ManipuladorArquivo file = new ManipuladorArquivo()
                {
                    Path = @"C:\Arquivos\", Name = "EMPRESTIMO.CSV"
                };
                string[] emprestimoArquivados = ManipuladorArquivoControle.LerArquivo(file);


                foreach (var emprestado in emprestimoArquivados)
                {
                    if (emprestado.Length == 35)
                    {
                        string idcliente        = emprestado.Substring(0, 5);
                        string numerotombo      = emprestado.Substring(6, 5);
                        string dataemprestimo   = emprestado.Substring(12, 10);
                        string datadevolucao    = emprestado.Substring(23, 10);
                        string statusemprestimo = emprestado.Substring(34, 1);



                        EmprestimoLivro novoEmprestimo = new EmprestimoLivro()
                        {
                            IdCliente        = long.Parse(idcliente),
                            NumeroTombo      = long.Parse(numerotombo),
                            DataEmprestimo   = Convert.ToDateTime(dataemprestimo),
                            DataDevolucao    = Convert.ToDateTime(datadevolucao),
                            StatusEmprestimo = int.Parse(statusemprestimo)
                        };


                        EmprestimoLivro.Add(novoEmprestimo);
                    }
                }
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("ERRO!!!!: " + ex.Message);
                Console.ReadKey();
            }

            return(EmprestimoLivro);
        }