Develop and Download Open Source Software

Browse Subversion Repository

Contents of /tags/FeliCa2Money-2.1/Suica.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 98 - (show annotations) (download)
Thu Mar 6 13:04:43 2008 UTC (16 years, 1 month ago) by tmurakam
File size: 5734 byte(s)
ver 2.1 tags

1 /*
2 * FeliCa2Money
3 *
4 * Copyright (C) 2001-2008 Takuya Murakami
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21 using System;
22 using System.Collections.Generic;
23 using System.Text;
24 using System.Windows.Forms;
25
26 namespace FeliCa2Money
27 {
28 class Suica : Card
29 {
30 private int prevBalance = UndefBalance;
31 private const int UndefBalance = -9999999;
32
33 public Suica()
34 {
35 ident = "Suica";
36 cardName = "Suica";
37 }
38
39 public override List<Transaction> ReadCard()
40 {
41 SfcPeep s = new SfcPeep();
42
43 // IDm ������������
44 List<string> lines = s.Execute("-i");
45 if (!lines[0].StartsWith("IDm:"))
46 {
47 return null;
48 }
49
50 CardId = lines[0].Substring(4);
51
52 // ���������������������������
53 lines = s.Execute("-h");
54 if (lines.Count < 1 || !lines[0].StartsWith("HT00:"))
55 {
56 return null;
57 }
58
59 // ������������
60 lines.Reverse();
61
62 // Parse lines
63 List<Transaction> transactions = new List<Transaction>();
64 foreach (string line in lines)
65 {
66 Transaction t = new Transaction();
67
68 string[] items = ParseLine(line);
69 if (SetTransaction(t, items)) {
70 transactions.Add(t);
71 }
72 }
73 return transactions;
74 }
75
76 private bool SetTransaction(Transaction t, string[] items)
77 {
78 // 0:������������������,1:������,2:������������,
79 // 3:������������������,4:������������������,5:���������,6:���������,
80 // 7:������������������,8:������������������,9:���������,10:���������,
81 // 11:������,12:������������
82
83 // ������
84 t.desc = items[1];
85 if (t.desc == "----") {
86 return false; // ���������������
87 }
88
89 // ������
90 t.balance = int.Parse(items[11]);
91
92 // ���������������
93 // Suica ��������������������������������������������������������� (ouch!)
94 // ���������������������������������������������������������������
95 // ���������������������������������������������������������������������
96 if (prevBalance == UndefBalance)
97 {
98 prevBalance = t.balance;
99 return false;
100 }
101 else
102 {
103 t.value = t.balance - prevBalance;
104 prevBalance = t.balance;
105 }
106
107 // ������
108 string d = items[2];
109 int yy = int.Parse(d.Substring(0, 2)) + 2000;
110 int mm = int.Parse(d.Substring(3, 2));
111 int dd = int.Parse(d.Substring(6, 2));
112
113 t.date = new DateTime(yy, mm, dd, 0, 0, 0);
114
115 // ID
116 t.id = Convert.ToInt32(items[12], 16);
117
118 // ������/������
119 if (items[5] != "")
120 {
121 // ���������������������������������������������
122 appendDesc(t, items[5]);
123
124 // ���������������������/���������������
125 t.memo = items[5] + "(" + items[6] + ")";
126 if (items[9] != "")
127 {
128 t.memo += " - " + items[9] + "(" + items[10] + ")";
129 }
130 }
131 else
132 {
133 // ���������������������������9, 10 ������������������
134 appendDesc(t, items[9]);
135 appendDesc(t, items[10]);
136
137 // ������������
138 if (t.desc == "������")
139 {
140 // ���������������������������������������������������������������������������
141 // ��������� Money ������������������������������������������������������������������
142 // ���������������������������������������������/������������������������������������������������
143 // ���������������������������Money ���������������������������������������������������������
144 t.desc += " " + items[7] + items[8];
145 }
146 }
147
148 // ���������������������������������
149 if (t.value < 0) {
150 t.GuessTransType(false);
151 }
152 else
153 {
154 t.GuessTransType(true);
155 }
156
157 return true;
158 }
159
160 private void appendDesc(Transaction t, string d)
161 {
162 if (d == "" || d == "���������")
163 {
164 return;
165 }
166
167 if (t.desc == "������")
168 {
169 t.desc = d; // "������"������������������������
170 }
171 else
172 {
173 t.desc += " " + d;
174 }
175 }
176 }
177 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26