Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Escreve_Arquivos_Txt()
- {
- string folder = Program.caminhoAplicacao + @"Serializer"; //Cria Pasta para Serialização
- if (!Directory.Exists(folder))
- {
- Directory.CreateDirectory(folder);
- }
- int ContaArquivo = 0;
- int count = dataReader.FieldCount;
- using (file = new StreamWriter(Program.caminhoAplicacao + @"Serializer" + ContaArquivo + "Ser.txt"))
- {
- while (this.dataReader.Read())
- {
- file.AutoFlush = true; // Limpa o buffer pra forçar a escrita
- for (int i = 0; i < count; i++)
- {
- file.WriteLine(this.dataReader.GetValue(i));
- }
- ContaArquivo++;
- file = new StreamWriter(Program.caminhoAplicacao + @"Serializer" + ContaArquivo + @"Ser.txt");
- }
- }
- file.Dispose();
- }
- private DataTable Preenche_Datatable(DataTable dataTable, int ContaArquivo, string diretorio, int quant_coluna)
- {
- do
- {
- int auxiliacount = quant_coluna - 1;
- int colunaIndex = 0;
- string[] totaldelinhas = File.ReadAllLines(diretorio + ContaArquivo + "Ser.txt");
- DataRow dr = dataTable.NewRow();
- foreach (string contalinhas in totaldelinhas)
- {
- dr[colunaIndex] = contalinhas;
- if (colunaIndex == auxiliacount)
- {
- dataTable.Rows.Add(dr);
- dr = dataTable.NewRow();
- colunaIndex = 0;
- }
- else
- {
- colunaIndex++;
- }
- }
- File.Delete(diretorio + ContaArquivo + "Ser.txt");
- ContaArquivo++;
- }
- while (File.Exists(diretorio + ContaArquivo + "Ser.txt"));
- return dataTable;
- }
- string[] totaldelinhas = File.ReadAllLines(diretorio + ContaArquivo + "Ser.txt");
- public DataTable Nova_Serializacao(DataTable dataTable)
- {
- Escreve_Arquivos_Txt();
- string dir = Program.caminhoAplicacao + @"Serializer";
- int count = dataReader.FieldCount;
- Recupera_Colunas(dataReader, count);
- int ContaArquivo = 0;
- Preenche_Datatable(dataTable, ContaArquivo, dir, count);
- return dataTable;
- }
Add Comment
Please, Sign In to add comment