-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFirst_Time.cs
84 lines (76 loc) · 2.81 KB
/
First_Time.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using Excel = Microsoft.Office.Interop.Excel;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using DataTable = System.Data.DataTable;
using System.Windows.Forms;
using System.Net.Http;
using System.Text.Json;
using System;
using System.Collections.Generic;
using ExcelDataReader;
using System.Data;
namespace Project
{
public class First_Time
{
private readonly string arquivo = "config.txt";
public static DataTable DT { get; set; }
private static DataSet DS { get; set; }
public First_Time()
{
Atual.User = new Cliente();
Config();
}
private void Config()
{
DirectoryInfo Directoryinfo;
Directoryinfo = Directory.CreateDirectory(@"ClientesBase");
Directoryinfo.Attributes |= FileAttributes.Hidden;
if (!File.Exists(arquivo))
{
// criando todos os diretorios Para futuro uso
Arquivo.SetArquive();
StartDataTable();
File.Create(arquivo).Close();
File.SetAttributes(arquivo, File.GetAttributes(arquivo) | FileAttributes.Hidden);
Directory.CreateDirectory(@"caminho").Attributes |= FileAttributes.Hidden; // |= : se diferente, seta para o valor da direita, se nao, não altera
Directory.CreateDirectory(@"Nota").Attributes |= FileAttributes.Hidden;
ExcelClass.Run(true, Directoryinfo.FullName).Wait();
}
else
{
Arquivo.SetCaminhoDoArquivo(File.ReadAllText(@"caminho\exel.txt"));//arquivo de base
ExcelClass.Run(false, Directoryinfo.FullName).Wait();
}
}
public static Task StartDataTable()
{
// Configurar DataTable
DT = new DataTable();
DS = new DataSet();
var stream = new FileStream(Project.Arquivo.GetCaminhoDoArquivo(), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
DT.Columns.Add("Produto");
DT.Columns.Add("Preço");
IExcelDataReader reader = ExcelReaderFactory.CreateReader(stream);
DS = reader.AsDataSet(new ExcelDataSetConfiguration
{
UseColumnDataType = false,
ConfigureDataTable = (tablereader) => new ExcelDataTableConfiguration()
{
UseHeaderRow = false
}
});
GetTablenames(DS.Tables);
reader.Close();
return Task.CompletedTask;
}
private static void GetTablenames(DataTableCollection tables)
{
foreach (DataRow table in tables[0].Rows)
{
DT.Rows.Add(table[0].ToString(), table[1].ToString());
}
}
}
}