public static List <DocFV> Make(string[] files) { List <DocFV> docFvList = new List <DocFV>(); Microsoft.Office.Interop.Word.Application winword = new Microsoft.Office.Interop.Word.Application(); Microsoft.Office.Interop.Word.Document doc; List <string> stringList1 = new List <string>(); List <string> stringList2 = new List <string>(); int num = files.Count(); for (int index = 0; index < num; ++index) { try { doc = winword.Documents.Open(files[index]); List <string> list = ((IEnumerable <string>)doc.Content.Text.Replace('\a', ' ').Split('\r')).ToList <string>(); int count = doc.Tables.Count; string nr = ReaderDocFV.FindFVNumber(ref list).Trim(); string nabywca1 = ReaderDocFV.FindNabywca(ref list); string[] strArray = ReaderDocFV.ReadFirstTable(doc.Tables[1]); List <List <string> > stringListList = ReaderDocFV.ReadSecondTable(doc.Tables[2]); string nabywca2 = nabywca1; string[] dane = strArray; List <List <string> > data = stringListList; DocFV docFv = ReaderDocFV.ReadDocFV(nr, nabywca2, dane, data); docFv.filename = files[index]; docFvList.Add(docFv); doc.Close(); stringList2.Add("Przeczytano plik " + files[index]); } catch { stringList1.Add("Błąd czytania pliku (ReaderDocFV.Make) " + files[index]); } } winword.Quit(); StreamWriter streamWriter1 = new StreamWriter("errors\\WordErrors.txt"); foreach (string str in stringList1) { streamWriter1.WriteLine(str); } streamWriter1.Close(); StreamWriter streamWriter2 = new StreamWriter("errors\\WordRaport.txt"); foreach (string str in stringList2) { streamWriter2.WriteLine(str); } streamWriter2.Close(); return(docFvList); }
public void AddNewClients(string[] filenames, string XMLfilename = "BazaKlientow.xml") { List <string> stringList1 = new List <string>(); List <string> stringList2 = new List <string>(); List <DocFV> docFvList = ReaderDocFV.Make(filenames); this.version = DateTime.Now.ToFileTime().ToString(); foreach (DocFV docFv in docFvList) { try { Klient nowy = ClientFromDocFV.KlientParserFromString(docFv.nabywca, docFv.termin_zaplaty, docFv.sposob_zaplaty, docFv.filename); if (this.Baza.Where <Klient>((Func <Klient, bool>)(n => n.NIP == nowy.NIP)).Count <Klient>() == 0) { this.Baza.Add(nowy); stringList2.Add("Dodano do bazy firmę o skrócie " + nowy.skrot + " z pliku " + docFv.filename); } else { stringList2.Add("Pominięto firmę o skrócie " + nowy.skrot + ", ponieważ jest w bazie. Badany plik to " + docFv.filename); } } catch { stringList1.Add("Błąd parsowania danych do klasy Klient (BazaKlientow.CreateBazaFromDocFiles) z pliku " + docFv.filename); } } StreamWriter streamWriter1 = new StreamWriter("errors\\WordErrors" + this.version + ".txt"); foreach (string str in stringList1) { streamWriter1.WriteLine(str); } streamWriter1.Close(); StreamWriter streamWriter2 = new StreamWriter("errors\\WordRaport" + this.version + ".txt"); foreach (string str in stringList2) { streamWriter2.WriteLine(str); } streamWriter2.Close(); this.SaveXML(XMLfilename); }