getBusName() public method

public getBusName ( int line, int station ) : Names
line int
station int
return Names
コード例 #1
0
ファイル: Suica.cs プロジェクト: shivashanti/felica2money
        // トランザクション解析
        public override bool analyzeTransaction(Transaction t, byte[] data)
        {
            int ctype   = data[0];          // 端末種
            int proc    = data[1];          // 処理
            int date    = read2b(data, 4);  // 日付
            int balance = read2l(data, 10); // 残高(little endian)
            int seq     = read3b(data, 12); // 連番
            int region  = data[15];         // リージョン

            // 処理
            t.desc = procType(proc);

            // 残高
            t.balance = balance;

            // 金額は CalcValueFromBalance() で計算する
            t.value = 0;

            // 日付
            int yy = (date >> 9) + 2000;
            int mm = (date >> 5) & 0xf;
            int dd = date & 0x1f;

            try
            {
                t.date = new DateTime(yy, mm, dd, 0, 0, 0);
            }
            catch
            {
                // 日付異常(おそらく空エントリ)
                return(false);
            }

            // ID
            t.id = seq;

            // 駅名/店舗名などを調べる
            int in_line = -1;
            int in_sta = -1;
            int out_line, out_sta;

            StationCode.Names in_name = null, out_name = null;
            int in_area = 0, out_area = 0;

            switch (ctype)
            {
            case CT_SHOP:
            case CT_VEND:
                // 物販/自販機
                out_area = Properties.Settings.Default.ShopAreaPriority;

                //time = (data[6] << 8) | data[7];
                out_line = data[8];
                out_sta  = data[9];

                // 優先エリアで検索
                out_name = stCode.getShopName(out_area, ctype, out_line, out_sta);
                if (out_name == null)
                {
                    // 全エリアで検索
                    out_name = stCode.getShopName(-1, ctype, out_line, out_sta);
                }
                break;

            case CT_CAR:
                // 車載端末(バス)
                out_line = read2b(data, 6);
                out_sta  = read2b(data, 8);
                out_name = stCode.getBusName(out_line, out_sta);
                break;

            default:
                // それ以外(運賃、チャージなど)
                in_line  = data[6];
                in_sta   = data[7];
                out_line = data[8];
                out_sta  = data[9];
                if (in_line == 0 && in_sta == 0 && out_line == 0 && out_sta == 0)
                {
                    break;
                }
                in_area  = getAreaCode(in_line, region);
                out_area = getAreaCode(out_line, region);

                in_name  = stCode.getStationName(in_area, in_line, in_sta);
                out_name = stCode.getStationName(out_area, out_line, out_sta);
                break;
            }

            // 備考の先頭には端末種を入れる
            t.memo = consoleType(ctype);

            switch (ctype)
            {
            case CT_SHOP:
            case CT_VEND:
                if (out_name != null)
                {
                    // "物販" の場合は、"物販" は消して店舗名だけにする
                    if (t.desc == "物販")
                    {
                        t.desc = "";
                    }
                    else
                    {
                        t.desc += " ";
                    }
                    // 店舗名追加
                    t.desc += out_name.r1 + " " + out_name.r2;
                }
                else
                {
                    // 店舗名が不明の場合、適用には出線区/出駅順コードをそのまま付与する。
                    // こうしないと Money が過去の履歴から誤って店舗名を補完してしまい
                    // 都合がわるいため
                    t.desc += " 店舗コード:" + out_line.ToString("X02") + out_sta.ToString("X02");
                }
                break;

            case CT_CAR:
                if (out_name != null)
                {
                    // 適用にバス会社名、備考に停留所名を入れる
                    t.desc += " " + out_name.r1;
                    t.memo += " " + out_name.r2;
                }
                break;

            default:
                if (in_line == 0 && in_sta == 0 & out_line == 0 && out_sta == 0)
                {
                    // チャージなどの場合は、何も追加しない
                    break;
                }

                // 適用に入会社または出会社を追加
                if (in_name != null)
                {
                    t.desc += " " + in_name.r1;
                }
                else if (out_name != null)
                {
                    t.desc += " " + out_name.r1;
                }

                // 備考に入出会社/駅名を記載
                t.memo += " ";
                if (in_name != null)
                {
                    t.memo += in_name.r1 + "(" + in_name.r2 + ")";
                }
                else
                {
                    t.memo += string.Format("未登録({0}:{1}:{2})", in_area, in_line, in_sta);
                }
                t.memo += " - ";

                if (out_name != null)
                {
                    t.memo += out_name.r1 + "(" + out_name.r2 + ")";
                }
                else
                {
                    t.memo += string.Format("未登録({0}:{1}:{2})", out_area, out_sta, region);
                }
                break;
            }

            return(true);
        }