static public void FixMasterCardPDFCSV() { ModalForm.PromptPathBox prbForm = new ModalForm.PromptPathBox(); if (prbForm.ShowDialog() == DialogResult.OK) { int year = prbForm.Year; TextFieldParser csvReader = new TextFieldParser(prbForm.ImportFilePath + ".csv"); csvReader.SetDelimiters(new string[] { "," }); csvReader.HasFieldsEnclosedInQuotes = true; string month = ""; string day = ""; decimal amount = 0; string name = ""; string csv = "Account Type,Account Number,Transaction Date,Cheque Number,Description 1,Description 2,CAD$,USD$,\r\n"; while (!csvReader.EndOfData) { string[] fieldData = csvReader.ReadFields(); string monthDay = fieldData[0]; month = monthDay.Substring(0, 3); day = monthDay.Replace(month + ".", "").Replace(" ", ""); if (day.Length == 1) { day = "0" + day; } name = fieldData[1]; decimal.TryParse(fieldData[2], out amount); //Trace.WriteLine(year + "\\" + month + "\\" + day + " " + amount + " " + name); //"Account Type,Account Number,Transaction Date,Cheque Number,Description 1,Description 2,CAD$,USD$,\r\n"; int monthNumber = GetMonthNumber(month); csv += "MasterCard,4510000000000000," + monthNumber + "/" + day + "/" + year + ",," + name + "," + "" + "," + (amount).ToString() + ",,\r\n"; month = ""; day = ""; amount = 0; name = ""; } // while Trace.WriteLine(csv); System.IO.StreamWriter file = new System.IO.StreamWriter(prbForm.OutputFilePath + ".csv"); file.WriteLine(csv); file.Close(); } }
static public void FixRoyalBankPDFCSV() { ModalForm.PromptPathBox prbForm = new ModalForm.PromptPathBox(); if (prbForm.ShowDialog() == DialogResult.OK) { int year = prbForm.Year; TextFieldParser csvReader = new TextFieldParser(prbForm.ImportFilePath + ".csv"); csvReader.SetDelimiters(new string[] { "," }); csvReader.HasFieldsEnclosedInQuotes = true; string month = ""; string day = ""; decimal amount = 0; string name = ""; int count = 0; string csv = "Account Type,Account Number,Transaction Date,Cheque Number,Description 1,Description 2,CAD$,USD$,\r\n"; while (!csvReader.EndOfData) { string[] fieldData = csvReader.ReadFields(); //Making empty value as null for (int i = 0; i < fieldData.Length; i++) { if (!ContainsMonth(fieldData[i]).Equals("") && !fieldData[i].ToLower().Contains("statement") && !fieldData[i].ToLower().Contains("payment")) { count++; month = ContainsMonth(fieldData[i]); string removedAlphanumberic = Regex.Replace(fieldData[i], "[^0-9.]", ""); day = removedAlphanumberic.Substring(0, 2); name = fieldData[i].Substring(14); } if (fieldData[i].Contains("$") && !fieldData[i].Contains("-") && !month.Equals("") && !name.Equals("")) { string removedAlphanumberic = Regex.Replace(fieldData[i], "[^0-9.]", ""); decimal cad; if (Decimal.TryParse(removedAlphanumberic.Replace(" ", ""), out cad)) { amount = cad; count++; } else { MessageBox.Show("Error " + fieldData[i]); } } if (count == 2) { //Trace.WriteLine(year + "\\" + month + "\\" + day + " " + amount + " " + name); //"Account Type,Account Number,Transaction Date,Cheque Number,Description 1,Description 2,CAD$,USD$,\r\n"; int monthNumber = GetMonthNumber(month); csv += "Visa,4510000000000000," + monthNumber + "/" + day + "/" + year + ",," + name + "," + "" + "," + (-1 * amount).ToString() + ",,\r\n"; month = ""; day = ""; amount = 0; name = ""; count = 0; } } } // while Trace.WriteLine(csv); System.IO.StreamWriter file = new System.IO.StreamWriter(prbForm.OutputFilePath + ".csv"); file.WriteLine(csv); file.Close(); } }