Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/FeliCa2Money.net/OfxFile.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 190 - (show annotations) (download)
Tue Apr 8 13:08:21 2008 UTC (16 years, 1 month ago) by tmurakam
File size: 6191 byte(s)
ver 2.6.1
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 /*
22 OFX ファイル生成
23 ファイルバージョンは 1.0.2 (SGML)
24 */
25
26 using System;
27 using System.Collections.Generic;
28 using System.Text;
29 using System.IO;
30 using System.Xml;
31
32 namespace FeliCa2Money
33 {
34 class OfxFile
35 {
36 protected string ofxFilePath;
37
38 public OfxFile()
39 {
40 }
41
42 public void SetOfxFilePath(String path)
43 {
44 ofxFilePath = path;
45 }
46
47 protected string dateStr(DateTime d)
48 {
49 string s = String.Format("{0}{1:00}{2:00}", d.Year, d.Month, d.Day);
50 s += String.Format("{0:00}{1:00}{2:00}", d.Hour, d.Minute, d.Second);
51 s += "[+9:JST]";
52 return s;
53 }
54
55 protected string transId(Transaction t)
56 {
57 /* トランザクションの ID は日付と取引番号で生成 */
58 string longId = String.Format("{0:0000}{1:00}{2:00}", t.date.Year, t.date.Month, t.date.Day);
59 longId += String.Format("{0:0000000}", t.id);
60 return longId;
61 }
62
63 protected string quoteString(string s)
64 {
65 s = s.Replace("&", "&");
66 s = s.Replace("<", "&lt;");
67 s = s.Replace(">", "&gt;");
68 //s = s.Replace("'", "&apos;");
69 //s = s.Replace("\"", "&quot;");
70 return s;
71 }
72
73 public virtual void WriteFile(Card card, List<Transaction> transactions)
74 {
75 Transaction first = transactions[0];
76 Transaction last = transactions[transactions.Count - 1];
77
78 StreamWriter w = new StreamWriter(ofxFilePath, false); //, Encoding.UTF8);
79 w.NewLine = "\n";
80
81 w.WriteLine("OFXHEADER:100");
82 w.WriteLine("DATA:OFXSGML");
83 w.WriteLine("VERSION:102");
84 w.WriteLine("SECURITY:NONE");
85 w.WriteLine("ENCODING:UTF-8");
86 w.WriteLine("CHARSET:CSUNICODE");
87 w.WriteLine("COMPRESSION:NONE");
88 w.WriteLine("OLDFILEUID:NONE");
89 w.WriteLine("NEWFILEUID:NONE");
90 w.WriteLine("");
91
92 /* 金融機関情報(サインオンレスポンス) */
93 w.WriteLine("<OFX>");
94 w.WriteLine("<SIGNONMSGSRSV1>");
95 w.WriteLine("<SONRS>");
96 w.WriteLine(" <STATUS>");
97 w.WriteLine(" <CODE>0");
98 w.WriteLine(" <SEVERITY>INFO");
99 w.WriteLine(" </STATUS>");
100 w.WriteLine(" <DTSERVER>{0}", dateStr(last.date));
101
102 w.WriteLine(" <LANGUAGE>JPN");
103 w.WriteLine(" <FI>");
104 w.WriteLine(" <ORG>{0}", card.Ident);
105 w.WriteLine(" </FI>");
106 w.WriteLine("</SONRS>");
107 w.WriteLine("</SIGNONMSGSRSV1>");
108
109 /* 口座情報(バンクメッセージレスポンス) */
110 w.WriteLine("<BANKMSGSRSV1>");
111
112 /* 預金口座型明細情報作成 */
113 w.WriteLine("<STMTTRNRS>");
114 w.WriteLine("<TRNUID>0");
115 w.WriteLine("<STATUS>");
116 w.WriteLine(" <CODE>0");
117 w.WriteLine(" <SEVERITY>INFO");
118 w.WriteLine("</STATUS>");
119
120 w.WriteLine("<STMTRS>");
121 w.WriteLine(" <CURDEF>JPY");
122
123 w.WriteLine(" <BANKACCTFROM>");
124 w.WriteLine(" <BANKID>{0}", card.BankId);
125 w.WriteLine(" <BRANCHID>{0}", card.BranchId);
126 w.WriteLine(" <ACCTID>{0}", card.AccountId);
127 w.WriteLine(" <ACCTTYPE>SAVINGS");
128 w.WriteLine(" </BANKACCTFROM>");
129
130 /* 明細情報開始(バンクトランザクションリスト) */
131 w.WriteLine(" <BANKTRANLIST>");
132 w.WriteLine(" <DTSTART>{0}", dateStr(first.date));
133 w.WriteLine(" <DTEND>{0}", dateStr(last.date));
134
135 /* トランザクション */
136 foreach (Transaction t in transactions)
137 {
138 w.WriteLine(" <STMTTRN>");
139 w.WriteLine(" <TRNTYPE>{0}", t.GetTransString());
140 w.WriteLine(" <DTPOSTED>{0}", dateStr(t.date));
141 w.WriteLine(" <TRNAMT>{0}", t.value);
142
143 /* トランザクションの ID は日付と取引番号で生成 */
144 w.WriteLine(" <FITID>{0}", transId(t));
145 w.WriteLine(" <NAME>{0}", quoteString(t.desc));
146 if (t.memo != null)
147 {
148 w.WriteLine(" <MEMO>{0}", quoteString(t.memo));
149 }
150 w.WriteLine(" </STMTTRN>");
151 }
152
153 w.WriteLine(" </BANKTRANLIST>");
154
155 /* 残高 */
156 w.WriteLine(" <LEDGERBAL>");
157 w.WriteLine(" <BALAMT>{0}", last.balance);
158 w.WriteLine(" <DTASOF>{0}", dateStr(last.date));
159 w.WriteLine(" </LEDGERBAL>");
160
161 /* OFX 終了 */
162 w.WriteLine(" </STMTRS>");
163 w.WriteLine("</STMTTRNRS>");
164 w.WriteLine("</BANKMSGSRSV1>");
165 w.WriteLine("</OFX>");
166
167 w.Close();
168
169 }
170
171 public void Execute()
172 {
173 System.Diagnostics.Process.Start(ofxFilePath);
174 }
175 }
176 }

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