FeliCa2Money.CsvRule.parse C# (CSharp) Method

parse() public method

public parse ( string row ) : Transaction
row string
return Transaction
        public Transaction parse(string[] row)
        {
            Transaction t = new Transaction();

            // 日付
            string date = getCol(row, "Date");
            if (date != null)
            {
                t.date = CsvUtil.parseDate(date);
            }
            else {
                int year = getColInt(row, "Year");
                int month = getColInt(row, "Month");
                int day = getColInt(row, "Day");

                if (year == 0 || month == 0 || day == 0) {
                    return null;
                }

                if (year < 100)
                {
                    year += 2000;
                }
                t.date = new DateTime(year, month, day, 0, 0, 0);
            }

            // ID
            string id = getCol(row, "Id");
            if (id != null)
            {
                try
                {
                    t.id = getColInt(row, "Id");
                }
                catch (FormatException)
                {
                    // just ignore : do not use ID
                }
            }

            // 金額
            t.value = getColInt(row, "Income");
            t.value -= getColInt(row, "Outgo");

            // 残高
            t.balance = getColInt(row, "Balance");

            // 適用
            t.desc = getMultiCol(row, "Desc");

            // 備考
            t.memo = getMultiCol(row, "Memo");

            // トランザクションタイプを自動設定
            t.GuessTransType(t.value >= 0);

            return t;
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// CSVデータ読み込み
        /// </summary>
        public override void ReadTransactions()
        {
            skipToFirstLine();

            TransactionList transactions = new TransactionList();
            string          line;
            bool            hasFormatError = false;

            while ((line = mSr.ReadLine()) != null)
            {
                // CSV カラム分割
                string[] row = SplitCsv(line);
                if (row.Length <= 1)
                {
                    continue;                  // ad hoc...
                }
                // パース
                try
                {
                    Transaction t = mRule.parse(row);
                    transactions.Add(t);
                }
                catch (FormatException ex)
                {
                    // ignore transaction

                    // MessageBox.Show(ex.Message, Properties.Resources.Error);
                    hasFormatError = true;
                }
            }

            if (transactions.Count == 0 && hasFormatError)
            {
                // フォーマットエラー例外をスロー
                throw new CsvReadException(Properties.Resources.CsvFormatError);
            }

            // ソート処理
            switch (mRule.sortOrder)
            {
            default:
            case CsvRule.SortOrder.Ascent:
                break;

            case CsvRule.SortOrder.Descent:
                transactions.Reverse();
                break;

            case CsvRule.SortOrder.Auto:
                transactions.list.Sort(compareByDate);
                break;
            }

            mTransactions = transactions;
        }