Develop and Download Open Source Software

Browse Subversion Repository

Contents of /tags/FeliCa2Money-2.2/OfxFile.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 109 - (show annotations) (download)
Sun Mar 9 06:14:50 2008 UTC (16 years, 1 month ago) by tmurakam
File size: 5717 byte(s)
ver 2.2

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.IO;
25
26 namespace FeliCa2Money
27 {
28 class OfxFile
29 {
30 private string ofxFilePath;
31
32 public OfxFile()
33 {
34 }
35
36 public void SetOfxFilePath(String path)
37 {
38 ofxFilePath = path;
39 }
40
41 private string dateStr(DateTime d)
42 {
43 string s = String.Format("{0}{1:00}{2:00}", d.Year, d.Month, d.Day);
44 s += String.Format("{0:00}{1:00}{2:00}", d.Hour, d.Minute, d.Second);
45 s += "[+9:JST]";
46 return s;
47 }
48
49 private string transId(Transaction t)
50 {
51 /* ��������������������������� ID ��������������������������������� */
52 string longId = String.Format("{0:0000}{1:00}{2:00}", t.date.Year, t.date.Month, t.date.Day);
53 longId += String.Format("{0:0000000}", t.id);
54 return longId;
55 }
56
57 public void WriteFile(Card card, List<Transaction> transactions)
58 {
59 Transaction first = transactions[0];
60 Transaction last = transactions[transactions.Count - 1];
61
62 StreamWriter w = new StreamWriter(ofxFilePath, false); //, Encoding.UTF8);
63 w.NewLine = "\n";
64
65 w.WriteLine("OFXHEADER:100");
66 w.WriteLine("DATA:OFXSGML");
67 w.WriteLine("VERSION:102");
68 w.WriteLine("SECURITY:NONE");
69 w.WriteLine("ENCODING:UTF-8");
70 w.WriteLine("CHARSET:CSUNICODE");
71 w.WriteLine("COMPRESSION:NONE");
72 w.WriteLine("OLDFILEUID:NONE");
73 w.WriteLine("NEWFILEUID:NONE");
74 w.WriteLine("");
75
76 /* ������������������(������������������������������) */
77 w.WriteLine("<OFX>");
78 w.WriteLine("<SIGNONMSGSRSV1>");
79 w.WriteLine("<SONRS>");
80 w.WriteLine(" <STATUS>");
81 w.WriteLine(" <CODE>0");
82 w.WriteLine(" <SEVERITY>INFO");
83 w.WriteLine(" </STATUS>");
84 w.WriteLine(" <DTSERVER>{0}", dateStr(last.date));
85
86 w.WriteLine(" <LANGUAGE>JPN");
87 w.WriteLine(" <FI>");
88 w.WriteLine(" <ORG>{0}", card.Ident);
89 w.WriteLine(" </FI>");
90 w.WriteLine("</SONRS>");
91 w.WriteLine("</SIGNONMSGSRSV1>");
92
93 /* ������������(���������������������������������������) */
94 w.WriteLine("<BANKMSGSRSV1>");
95
96 /* ��������������������������������� */
97 w.WriteLine("<STMTTRNRS>");
98 w.WriteLine("<TRNUID>0");
99 w.WriteLine("<STATUS>");
100 w.WriteLine(" <CODE>0");
101 w.WriteLine(" <SEVERITY>INFO");
102 w.WriteLine("</STATUS>");
103
104 w.WriteLine("<STMTRS>");
105 w.WriteLine(" <CURDEF>JPY");
106
107 w.WriteLine(" <BANKACCTFROM>");
108 w.WriteLine(" <BANKID>{0}", card.Ident);
109 w.WriteLine(" <BRANCHID>000");
110 w.WriteLine(" <ACCTID>{0}", card.CardId);
111 w.WriteLine(" <ACCTTYPE>SAVINGS");
112 w.WriteLine(" </BANKACCTFROM>");
113
114 /* ������������������(������������������������������������������) */
115 w.WriteLine(" <BANKTRANLIST>");
116 w.WriteLine(" <DTSTART>{0}", dateStr(first.date));
117 w.WriteLine(" <DTEND>{0}", dateStr(last.date));
118
119 /* ������������������������ */
120 foreach (Transaction t in transactions)
121 {
122 w.WriteLine(" <STMTTRN>");
123 w.WriteLine(" <TRNTYPE>{0}", t.GetTransString());
124 w.WriteLine(" <DTPOSTED>{0}", dateStr(t.date));
125 w.WriteLine(" <TRNAMT>{0}", t.value);
126
127 /* ��������������������������� ID ��������������������������������� */
128 w.WriteLine(" <FITID>{0}", transId(t));
129 w.WriteLine(" <NAME>{0}", t.desc);
130 if (t.memo != null)
131 {
132 w.WriteLine(" <MEMO>{0}", t.memo);
133 }
134 w.WriteLine(" </STMTTRN>");
135 }
136
137 w.WriteLine(" </BANKTRANLIST>");
138
139 /* ������ */
140 w.WriteLine(" <LEDGERBAL>");
141 w.WriteLine(" <BALAMT>{0}", last.balance);
142 w.WriteLine(" <DTASOF>{0}", dateStr(last.date));
143 w.WriteLine(" </LEDGERBAL>");
144
145 /* OFX ������ */
146 w.WriteLine(" </STMTRS>");
147 w.WriteLine("</STMTTRNRS>");
148 w.WriteLine("</BANKMSGSRSV1>");
149 w.WriteLine("</OFX>");
150
151 w.Close();
152
153 }
154
155 public void Execute()
156 {
157 System.Diagnostics.Process.Start(ofxFilePath);
158 }
159 }
160 }

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