Kolejny dzień walki... Dodałem sobie do klasy tak jak sugerowałeś nie wiem czy dobrze ale tak to ogarnąłem jak poniżej... i mam taki problem że chce mieć 5 kolumn tak jak jest 5 właściwości.
Kombinuje i ciągle mi wyświetla jeden pod drugim ;( a chce by z każdego pliku wchodziło tylko 5 wartości i przechodziło do następnego wierszu. Czyli jedna faktura = 1 wiersz.
Ale jak zrobię jak poniżej to oczekuje results.Add(new ShowResults(...)) 5 parametrów bo takie zdefiniowane są public ShowResults. A jak zrobić żeby był 1 parametr dla 1 kolumny ?? ;)
Z góry dziękuję za pomoc...
Teraz mam takie coś:
https://naforum.zapodaj.net/eda9f58324b7.jpg.html
public class ShowResults
{
public string NrFaktury { get; set; }
public string Data_wystawienia { get; set; }
public double Netto { get; set; }
public double Brutto { get; set; }
public double Vat { get; set; }
public ShowResults(string nf, string dw, string nt, string bt, string vt)
{
this.NrFaktury = nf;
this.Data_wystawienia = dw;
this.Netto = nt;
this.Brutto = bt;
this.Vat = vt;
}
}
I button:
private void button2_Click(object sender, EventArgs e)
{
string newPath = (Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\faktury\\");
string[] filePaths = Directory.GetFiles(newPath, "*.txt");
List<ShowResults> results = new List<ShowResults>();
foreach (string fp in filePaths)
{
string[] lines = File.ReadAllLines(fp);
// Iterate through lines
foreach (string line in lines)
{
foreach (Match match in Regex.Matches(line, @"(Numer Faktury:|Numer faktury korygującej: )(.*?)$", RegexOptions.IgnoreCase))
{
results.Add(new ShowResults(match.Groups[2].Value));
}
foreach (Match match in Regex.Matches(line, @"(Data wystawienia:|Data wystawienia korekty:)(.*?)$", RegexOptions.IgnoreCase))
{
results.Add(new ShowResults(match.Groups[2].Value));
}
foreach (Match match in Regex.Matches(line, @"Wartość netto (.*?) PLN", RegexOptions.IgnoreCase))
{
results.Add(new ShowResults(match.Groups[1].Value));
}
foreach (Match match in Regex.Matches(line, @"Wartość całkowita VAT 8 % (.*?) PLN", RegexOptions.IgnoreCase))
{
results.Add(new ShowResults(match.Groups[1].Value));
}
foreach (Match match in Regex.Matches(line, @"Wartość brutto (.*?) PLN", RegexOptions.IgnoreCase))
{
results.Add(new ShowResults(match.Groups[1].Value));
}
}
}
dataGridView1.DataSource = results;
}