コード例 #1
0
        static void WriteCSVFile(ParseRAKBankStatementResult varParseRAKBankStatementResult, string strFolder)
        {
            var strFileName = $"{varParseRAKBankStatementResult.strAccountName}  - {varParseRAKBankStatementResult.strAccountNumber} ({varParseRAKBankStatementResult.d8From.ToString("ddMMyyyy")} - {varParseRAKBankStatementResult.d8To.ToString("ddMMyyyy")}).csv";

            strFileName = System.IO.Path.Combine(strFolder, strFileName);
            System.IO.TextWriter textWriter = System.IO.File.CreateText(strFileName);
            var csvWriter = new CsvHelper.CsvWriter(textWriter);

            varParseRAKBankStatementResult.bankRecords.Reverse();
            csvWriter.WriteRecords(varParseRAKBankStatementResult.bankRecords);
            textWriter.Flush();
            textWriter.Close();
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //var strFilePath = @"D:\Downloads\Account_Transactions_CSV26-08-2018.csv";
            var strFilePath   = args[0];
            var strFolderPath = System.IO.Path.GetDirectoryName(strFilePath);
            ParseRAKBankStatementResult varParseRAKBankStatementResult = null;

            try
            {
                varParseRAKBankStatementResult             = ParseRAKBankStatement(strFilePath);
                varParseRAKBankStatementResult.bankRecords = GetBankRecordsFromRAKBankCSVRecords(varParseRAKBankStatementResult.CSVRecords);
                WriteCSVFile(varParseRAKBankStatementResult, strFolderPath);
            }
            catch (Exception ex)
            {
                System.Console.WriteLine($"Error: {ex.Message}");
            }
        }
コード例 #3
0
        static ParseRAKBankStatementResult ParseRAKBankStatement(string strFilePath)
        {
            ParseRAKBankStatementResult result = new ParseRAKBankStatementResult();

            var strFileContent      = System.IO.File.ReadAllText(strFilePath);
            var strFileContentLines = strFileContent.Split(new char[] { '\n' });

            result.strAccountName   = strFileContentLines[3].Split(new char[] { ',' })[2];
            result.strAccountNumber = strFileContentLines[4].Split(new char[] { '.' })[1].Split(new char[] { ']' })[0];
            result.strBranchName    = strFileContentLines[6].Split(new char[] { '[' })[1].Split(new char[] { ']' })[0];
            result.d8From           = Convert.ToDateTime(DateTime.ParseExact(strFileContentLines[7].Split(new char[] { ',' })[2], "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture));
            result.d8To             = Convert.ToDateTime(DateTime.ParseExact(strFileContentLines[8].Split(new char[] { ',' })[2], "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture));
            string strCSVContent = string.Empty;

            for (int i = 10; i < strFileContentLines.Length - 2; i++)
            {
                if (i == 10)
                {
                    var Headers = strFileContentLines[i].Split(new char[] { ',' });
                    strCSVContent += $"EmptyHeader1,{Headers[1]},EmptyHeader2,{Headers[3]},{Headers[4]},{Headers[5]},{Headers[6]},{Headers[7]}{Environment.NewLine}";
                }
                else
                {
                    strCSVContent += strFileContentLines[i] + Environment.NewLine;
                }
            }

            var textReader = new System.IO.StringReader(strCSVContent);
            var csvr       = new CsvHelper.CsvReader(textReader);

            csvr.Configuration.PrepareHeaderForMatch = (string header, int index) => header?.Trim();
            csvr.Configuration.PrepareHeaderForMatch = (string header, int index) => header.Replace(" ", string.Empty);
            result.CSVRecords = csvr.GetRecords <RAKBankCSVRecord>();

            return(result);
        }