public void ReadLine(string line) { string[] cols = line.Split(','); if (cols.Length < 8 || cols.Length > 9) { throw new ArgumentException("Invalid line length"); } Account = cols[0]; TransDate = DateTime.Parse(cols[1]); Amount = StringToDecimal(cols[2]); Balance = StringToDecimal(cols[3]); Category = cols[4]; Description = cols[5]; Memo = cols[6]; Notes = cols[7]; TransType = cols.Length == 9 ? (TransactionTypes)Enum.Parse(typeof(TransactionTypes), cols[8]) : TransactionTypes.Unselected; if (TransType == TransactionTypes.Unselected) { TransType = CategoryMatch.GetType(this.ToString()); } if (TransType == TransactionTypes.Unselected && Description.Contains("Check Withdrawal") && Amount < 0) { TransType = TransactionTypes.Bill; } }
private void ReadCitiLine2(string line) { // new format is csv with description quoted. need to split on commas but only ones outside of quotes List <string> colValues = new List <string>(); int start = 0; bool insideQuotes = false; for (int i = 0; i < line.Length; i++) { if (line[i] == ',' && !insideQuotes) { colValues.Add(line.Substring(start, i - start)); start = i + 1; if (start >= line.Length) { colValues.Add(string.Empty); } } if (line[i] != ',' && i == line.Length - 1) { colValues.Add(line.Substring(start, i - start + 1)); } if (line[i] == '"') { insideQuotes = !insideQuotes; } } string[] cols = colValues.Select(s => s.Trim('"').Replace(",", "")).ToArray(); if (cols.Length != 5) { throw new ArgumentException(string.Format("Invalid Citi line length - '{0}'\r\nExpected 5, found {1}", line, cols.Length)); } Account = "CITI"; TransDate = DateTime.Parse(cols[1]); string debit = string.IsNullOrEmpty(cols[3]) ? "0" : cols[3]; string credit = string.IsNullOrEmpty(cols[4]) ? "0" : cols[4]; Amount = StringToDecimal(debit) + StringToDecimal(credit); // Citi splits out the debit and credit columns Balance = 0m; // Citi doesn't include balance -- problematic... Category = ""; // Citi doesn't include category Description = cols[2]; Memo = cols[2]; // Citi doesn't have a memo column so we'll duplicate memo Notes = cols[0]; // Using status as notes - could change TransType = CategoryMatch.GetType(this.ToString()); }
private void ReadCitiLine(string line) { string[] cols = line.Split(new string[] { "\",\"" }, StringSplitOptions.None).Select(s => s.Trim('"').Replace(",", "")).ToArray(); if (cols.Length != 5) { throw new ArgumentException("Invalid Citi line length - " + line); } Account = "CITI"; TransDate = DateTime.Parse(cols[1]); string debit = string.Format("({0})", string.IsNullOrEmpty(cols[3]) ? "0" : cols[3]); string credit = string.IsNullOrEmpty(cols[4]) ? "0" : cols[4]; Amount = StringToDecimal(debit) + StringToDecimal(credit); // Citi splits out the debit and credit columns Balance = 0m; // Citi doesn't include balance -- problematic... Category = ""; // Citi doesn't include category Description = cols[2]; Memo = cols[2]; // Citi doesn't have a memo column so we'll duplicate memo Notes = cols[0]; // Using status as notes - could change TransType = CategoryMatch.GetType(this.ToString()); }