public Schenker(string fileNameTXT, string fileLogName) { conf Config = new conf(); FileStream fs = new FileStream(fileNameTXT, FileMode.Open, FileAccess.ReadWrite); DataTable docNames = new DataTable(); docNames.Columns.Add("WZ", typeof(string)); string pdfName = fileNameTXT.Replace(".txt", ".pdf"); StreamReader sr = new StreamReader(fs); DateTime thisTime = DateTime.Now; string year = (thisTime.ToString().Replace(" ", "_").Replace("-", "").Replace(":", "")).Remove(4).Replace("20", ""); string yearBack = Convert.ToString((Convert.ToInt32(year) - 1)); string yearNext = Convert.ToString((Convert.ToInt32(year) + 1)); String[] documents; while (!sr.EndOfStream) { string text1 = sr.ReadLine().Replace(" ", ""); compilerDocName.All allCompiler = new ocr_wz.compilerDocName.All(text1); string text = allCompiler.resultText; if ( text.Contains("WZ/" + yearBack + "/") || text.Contains("WZ/" + year + "/") || text.Contains("WZ/" + yearNext + "/") || text.Contains("WW" + yearBack + "/") || text.Contains("WW" + year + "/") || text.Contains("WW" + yearNext + "/") ) { compilerDocName.Schenker SchenkerName = new ocr_wz.compilerDocName.Schenker(text); documents = SchenkerName.resultSchenker.Split(','); documents = SchenkerName.resultSchenker.Split(';'); foreach (string row in documents) { if (row.Contains("WZ/")) { compilerDocName.Wz WzName = new ocr_wz.compilerDocName.Wz(row); counter.Wz licznikWz = new ocr_wz.counter.Wz(WzName.resultWZ); if (licznikWz.result0 != null) { docNames.Rows.Add(licznikWz.result0); } } else if (row.Contains("WW")) { compilerDocName.Ww WwName = new ocr_wz.compilerDocName.Ww(row); counter.Ww licznikWw = new ocr_wz.counter.Ww(WwName.resultWW); if (licznikWw.result0 != null) { docNames.Rows.Add(licznikWw.result0); } } } } } if (docNames.Rows.Count == 0) { string docName = pdfName.Replace(Config.inPath + "\\!ocr\\po_ocr\\", ""); Copy CopyNewName = new Copy(pdfName, "0", docName, fileLogName); CopyNewName.CopyOther(); } else { var UniqueRows = docNames.AsEnumerable().Distinct(DataRowComparer.Default); DataTable uniqDocNames = UniqueRows.CopyToDataTable(); StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("Tablica dokumentów:"); SW.Close(); foreach (DataRow row in uniqDocNames.Rows) { StreamWriter SW1; SW1 = File.AppendText(fileLogName); SW1.WriteLine(row.Field<string>(0)); SW1.Close(); if (row.Field<string>(0).Contains("WZ_")) { yearDocs WZ = new yearDocs(row.Field<string>(0)); WZ.yearWZ(); Copy CopyNewName = new Copy(pdfName, WZ.year, row.Field<string>(0), fileLogName); CopyNewName.CopyWZdeliveryDoc(); } else if (row.Field<string>(0).Contains("WW")) { yearDocs WW = new yearDocs(row.Field<string>(0)); WW.yearWW(); Copy CopyNewName = new Copy(pdfName, WW.year, row.Field<string>(0), fileLogName); CopyNewName.CopyWWdeliveryDoc(); } } fs.Close(); } }
public Wz(string fileNameTXT, string fileLogName) { conf Config = new conf(); FileStream fs = new FileStream(fileNameTXT, FileMode.Open, FileAccess.ReadWrite); DataTable docNames = new DataTable(); docNames.Columns.Add("WZ", typeof(string)); StreamReader sr = new StreamReader(fs); while (!sr.EndOfStream) { string text1 = sr.ReadLine().Replace(" ", ""); compilerDocName.All allCompiler = new ocr_wz.compilerDocName.All(text1); string text = allCompiler.resultText; if ( text.Contains("mówienie") || (text.Contains("am") && text.Contains("wi") && text.Contains("nie") && text.Contains("AS")) || text.Contains("ZAS") || (text.Contains("ze") && text.Contains("wn") && text.Contains("me")) || (text.Contains("trz") && text.Contains("num")) || text.Contains("ydanie") || text.Contains("numer:") || text.Contains("WZ/") ) { if (text.Contains("WZ")) { compilerDocName.Wz WzName = new ocr_wz.compilerDocName.Wz(text); counter.Wz licznikWz = new ocr_wz.counter.Wz(WzName.resultWZ); if (licznikWz.result0 != null) { docNames.Rows.Add(licznikWz.result0); } } else if (text.Contains("ZAS")) { compilerDocName.Zas ZasName = new ocr_wz.compilerDocName.Zas(text); counter.Zas licznikZas = new ocr_wz.counter.Zas(ZasName.resultZas); if (licznikZas.result0 != null) { docNames.Rows.Add(licznikZas.result0); } } } } if (docNames.Rows.Count == 0) { string docName = pdfName.Replace(Config.inPath + "\\!ocr\\po_ocr\\", ""); Copy CopyNewName = new Copy(pdfName, "0", docName, fileLogName); CopyNewName.CopyOther(); } else { var UniqueRows = docNames.AsEnumerable().Distinct(DataRowComparer.Default); DataTable uniqDocNames = UniqueRows.CopyToDataTable(); StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("Tablica dokumentów:"); SW.Close(); int ileWZ = 0; int ileZAS = 0; foreach (DataRow row in uniqDocNames.Rows) { StreamWriter SW1; SW1 = File.AppendText(fileLogName); SW1.WriteLine(row.Field <string>(0)); SW1.Close(); if (row.Field <string>(0).Contains("WZ_")) { ileWZ++; } else if (row.Field <string>(0).Contains("ZAS_")) { ileZAS++; } } pdfName = fileNameTXT.Replace(".txt", ".pdf"); if (ileWZ == ileZAS || ileWZ > ileZAS) { foreach (DataRow row in uniqDocNames.Rows) { if (row.Field <string>(0).Contains("WZ_")) { yearDocs WZ = new yearDocs(row.Field <string>(0)); WZ.yearWZ(); Copy CopyNewName = new Copy(pdfName, WZ.year, row.Field <string>(0), fileLogName); CopyNewName.CopyWZ(); } } } else { int tableElements = uniqDocNames.Rows.Count; for (int i = 0; i < tableElements; i++) { string docName = Convert.ToString(uniqDocNames.Rows[i]["WZ"]); if (i == 0 && docName.Contains("WZ_")) { yearDocs readYear = new yearDocs(docName); readYear.yearWZ(); Copy CopyNewName = new Copy(pdfName, readYear.year, docName, fileLogName); CopyNewName.CopyWZ(); } else if (i == 0 && docName.Contains("ZAS_") && tableElements < 2) { yearDocs readYear = new yearDocs(docName); readYear.yearZas(); Copy CopyNewName = new Copy(pdfName, readYear.year, docName, fileLogName); CopyNewName.CopyZAS(); } else if (i > 0 && docName.Contains("ZAS_") && (Convert.ToString(uniqDocNames.Rows[i - 1]["WZ"])).Contains("ZAS_")) { yearDocs readYear = new yearDocs(docName); readYear.yearZas(); Copy CopyNewName = new Copy(pdfName, readYear.year, docName, fileLogName); CopyNewName.CopyZAS(); } else if (i > 0 && docName.Contains("WZ")) { yearDocs readYear = new yearDocs(docName); readYear.yearWZ(); Copy CopyNewName = new Copy(pdfName, readYear.year, docName, fileLogName); CopyNewName.CopyWZ(); } } } } fs.Close(); }
public Fv(string fileNameTXT, string fileLogName) { string pdfName = fileNameTXT.Replace(".txt", ".pdf"); conf Config = new conf(); FileStream fs = new FileStream(fileNameTXT, FileMode.Open, FileAccess.ReadWrite); DataTable docNames = new DataTable(); docNames.Columns.Add("WZ", typeof(string)); StreamReader sr = new StreamReader(fs); while (!sr.EndOfStream) { string text1 = sr.ReadLine().Replace(" ", ""); compilerDocName.All allCompiler = new ocr_wz.compilerDocName.All(text1); string text = allCompiler.resultText; if ( text.Contains("F/") || (text.Contains("Nu") && text.Contains("dow") && text.Contains("du")) ) { if (text.Contains("F/")) { compilerDocName.Fv FvName = new ocr_wz.compilerDocName.Fv(text); counter.Fv licznikFv = new ocr_wz.counter.Fv(FvName.resultFV); if (licznikFv.result0 != null) { docNames.Rows.Add(licznikFv.result0); } } else if (text.Contains("Nu") && text.Contains("dow") && text.Contains("du")) { compilerDocName.Wz WzName = new ocr_wz.compilerDocName.Wz(text); counter.Wz licznikWz = new ocr_wz.counter.Wz(WzName.resultWZ); if (licznikWz.result0 != null) { docNames.Rows.Add(licznikWz.result0); } } } } if (docNames.Rows.Count == 0) { string docName = pdfName.Replace(Config.inPath + "\\!ocr\\po_ocr\\", ""); Copy CopyNewName = new Copy(pdfName, "0", docName, fileLogName); CopyNewName.CopyOther(); } else { var UniqueRows = docNames.AsEnumerable().Distinct(DataRowComparer.Default); DataTable uniqDocNames = UniqueRows.CopyToDataTable(); StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("Tablica dokumentów:"); SW.Close(); int ileFV = 0; int ileWZ = 0; foreach (DataRow row in uniqDocNames.Rows) { StreamWriter SW2; SW2 = File.AppendText(fileLogName); SW2.WriteLine(row.Field <string>(0)); SW2.Close(); string docName = row.Field <string>(0); if (docName.Contains("F_")) { ileFV++; } else if (docName.Contains("WZ_")) { ileWZ++; } } if (ileFV == ileWZ || ileWZ > ileFV) { foreach (DataRow row in uniqDocNames.Rows) { if (row.Field <string>(0).Contains("WZ_")) { yearDocs WZ = new yearDocs(row.Field <string>(0)); WZ.yearWZ(); Copy CopyNewName = new Copy(pdfName, WZ.year, row.Field <string>(0), fileLogName); CopyNewName.CopyWZFV(); } } } else { foreach (DataRow row in uniqDocNames.Rows) { string docName = row.Field <string>(0); if (docName.Contains("F_")) { yearDocs readYear = new yearDocs(docName); readYear.yearFV(); Copy CopyNewName = new Copy(pdfName, readYear.year, docName, fileLogName); CopyNewName.CopyFV(); } } } fs.Close(); } }
public ReadTxt(string fileNameTXT, string fileLogName) { try { if (File.Exists(fileNameTXT)) { FileStream fs = new FileStream(fileNameTXT, FileMode.Open, FileAccess.ReadWrite); StreamReader sr = new StreamReader(fs); int wz = 0; int ww = 0; int fv = 0; int rw = 0; int raben = 0; int schenker = 0; while (!sr.EndOfStream) { string text1 = sr.ReadLine().Replace(" ", ""); compilerDocName.All allCompiler = new ocr_wz.compilerDocName.All(text1); string text = allCompiler.resultText; if (text.Contains("FAKTURA") && !text.Contains("KORYGUJ") && text.Contains("F/")) { fv++; } else if (((text.Contains("yda") || text.Contains("ani")) && text.Contains("mer")) && (text.Contains("WZ") || text.Contains("WŻ") || text.Contains("wz") || text.Contains("Wz") || text.Contains("W2/") || text.Contains("WZ/"))) { wz++; } else if (text.Contains("yda") && text.Contains("mer") && text.Contains("WW")) { ww++; } else if (text.Contains("rku") && text.Contains("LP/")) { rw++; } else if ((text.Contains("ZA") && text.Contains("CZO") && text.Contains("DOKU")) || text.Contains("Raben")) { raben++; } else if ((text.Contains("oku") && text.Contains("nt") && text.Contains("WZ"))) { schenker++; } } fs.Close(); if (wz > 0) { if (ww > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się dokumenty WZ i dokument WW"); SW.Close(); documents.Wz Wz = new documents.Wz(fileNameTXT, fileLogName); documents.Ww Ww = new documents.Ww(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (fv > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się dokumenty WZ i FV"); SW.Close(); documents.Wz Wz = new documents.Wz(fileNameTXT, fileLogName); documents.Fv Fv = new documents.Fv(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (rw > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się dokumenty WZ i RW"); documents.Wz Wz = new documents.Wz(fileNameTXT, fileLogName); documents.Rw Rw = new documents.Rw(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (raben > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się dokumenty WZ i dokument dostawy Raben"); SW.Close(); documents.Wz Wz = new documents.Wz(fileNameTXT, fileLogName); documents.Raben Raben = new documents.Raben(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (schenker > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się dokumenty WZ i dokument dostawy Schenker"); SW.Close(); documents.Wz Wz = new documents.Wz(fileNameTXT, fileLogName); documents.Schenker Schenker = new documents.Schenker(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się tylko dokumenty WZ"); SW.Close(); documents.Wz Wz = new ocr_wz.documents.Wz(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } } else if (fv < 1 && wz < 1 && ww < 1 && rw < 1 && raben < 1 && schenker < 1) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!! Nie mogę odczytać dokumentu !!! dokument nazwany ZAS"); SW.Close(); documents.Zas Zas = new ocr_wz.documents.Zas(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (wz < 1) { if (ww > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się tylko dokumenty WW"); SW.Close(); documents.Ww Ww = new ocr_wz.documents.Ww(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (fv > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się tylko dokumenty FV"); SW.Close(); documents.Fv Fv = new ocr_wz.documents.Fv(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (raben > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się tylko dokumenty dostawy Raben"); SW.Close(); documents.Raben Raben = new ocr_wz.documents.Raben(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (schenker > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się tylko dokumenty dostawy Schenker"); SW.Close(); documents.Schenker Schenker = new ocr_wz.documents.Schenker(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } else if (rw > 0) { try { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("W pliku znajdują się tylko dokumenty RW"); SW.Close(); documents.Rw RW = new ocr_wz.documents.Rw(fileNameTXT, fileLogName); PdfOcrDone pdfDone = new PdfOcrDone(fileNameTXT); } catch { StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("!!Przetwarzanie zakończono błędem!!"); SW.Close(); } } } } } catch (Exception ex) { Console.WriteLine("Nie odnaleziono pliku txt!" + ex); } }
public Zas(string fileNameTXT, string fileLogName) { conf Config = new conf(); FileStream fs = new FileStream(fileNameTXT, FileMode.Open, FileAccess.ReadWrite); DataTable docNames = new DataTable(); docNames.Columns.Add("WZ", typeof(string)); try { StreamReader sr = new StreamReader(fs); while (!sr.EndOfStream) { string text1 = sr.ReadLine().Replace(" ", ""); compilerDocName.All allCompiler = new ocr_wz.compilerDocName.All(text1); string text = allCompiler.resultText; if ( text.Contains("mówienie") || (text.Contains("za") && text.Contains("wie") && text.Contains("mer")) ) { if (text.Contains("ZAS")) { compilerDocName.Zas ZasName = new ocr_wz.compilerDocName.Zas(text); counter.Zas licznikZas = new ocr_wz.counter.Zas(ZasName.resultZas); if (licznikZas.result0 != null) { docNames.Rows.Add(licznikZas.result0); } } } } var UniqueRows = docNames.AsEnumerable().Distinct(DataRowComparer.Default); DataTable uniqDocNames = UniqueRows.CopyToDataTable(); StreamWriter SW; SW = File.AppendText(fileLogName); SW.WriteLine("Tablica dokumentów:"); SW.Close(); int ileZAS = 0; foreach (DataRow row in uniqDocNames.Rows) { StreamWriter SW1; SW1 = File.AppendText(fileLogName); SW1.WriteLine(row.Field <string>(0)); SW1.Close(); if (row.Field <string>(0).Contains("ZAS_")) { ileZAS++; } } pdfName = fileNameTXT.Replace(".txt", ".pdf"); if (ileZAS > 0) { foreach (DataRow row in uniqDocNames.Rows) { if (row.Field <string>(0).Contains("ZAS_")) { yearDocs readYear = new yearDocs(Convert.ToString(row.Field <string>(0))); readYear.yearZas(); Copy CopyNewName = new Copy(pdfName, readYear.year, row.Field <string>(0), fileLogName); CopyNewName.CopyZAS(); } } } else { int tableElements = uniqDocNames.Rows.Count; string tableRow = Convert.ToString(uniqDocNames.Rows[0]["WZ"]); for (int i = 0; i < tableElements; i++) { yearDocs readYear = new yearDocs(Convert.ToString(uniqDocNames.Rows[i]["WZ"])); readYear.yearZas(); Copy CopyNewName = new Copy(pdfName, readYear.year, Convert.ToString(uniqDocNames.Rows[i]["WZ"]), fileLogName); CopyNewName.CopyZAS(); } } fs.Close(); } catch { fs.Close(); string year = "0"; pdfName = fileNameTXT.Replace(".txt", ".pdf"); string docName = pdfName.Replace(Config.inPath + "\\!ocr\\po_ocr\\", ""); Copy CopyNewName = new Copy(pdfName, year, docName, fileLogName); CopyNewName.CopyOther(); } }