| 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 |
// OFX ver 2.0 (XML) |
| 22 |
|
| 23 |
using System; |
| 24 |
using System.Collections.Generic; |
| 25 |
using System.Text; |
| 26 |
using System.IO; |
| 27 |
using System.Xml; |
| 28 |
|
| 29 |
namespace FeliCa2Money |
| 30 |
{ |
| 31 |
class OfxFile2 : OfxFile |
| 32 |
{ |
| 33 |
private XmlDocument doc; |
| 34 |
|
| 35 |
public override void WriteFile(Card card, List<Transaction> transactions) |
| 36 |
{ |
| 37 |
XmlDocument d = Generate(card, transactions); |
| 38 |
d.Save(ofxFilePath); |
| 39 |
} |
| 40 |
|
| 41 |
// OFX 2 ������������������������ |
| 42 |
private XmlDocument Generate(Card card, List<Transaction> transactions) |
| 43 |
{ |
| 44 |
Transaction first = transactions[0]; |
| 45 |
Transaction last = transactions[transactions.Count - 1]; |
| 46 |
|
| 47 |
// XML ������������������������ |
| 48 |
doc = new XmlDocument(); |
| 49 |
|
| 50 |
XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "UTF-8", "yes"); |
| 51 |
doc.AppendChild(decl); |
| 52 |
|
| 53 |
// OFX ������ |
| 54 |
XmlProcessingInstruction pi = doc.CreateProcessingInstruction("OFX", |
| 55 |
"OFXHEADER=\"200\" VERSION=\"200\" SECURITY=\"NONE\" OLDFILEUID=\"NONE\" NEWFILEUID=\"NONE\""); |
| 56 |
doc.AppendChild(pi); |
| 57 |
|
| 58 |
XmlElement root = doc.CreateElement("OFX"); |
| 59 |
doc.AppendChild(root); |
| 60 |
|
| 61 |
// ��������������� |
| 62 |
XmlElement signOnMsgSrsv1 = appendElement(root, "SIGNONMSGSRSV1"); |
| 63 |
XmlElement sonrs = appendElement(signOnMsgSrsv1, "SONRS"); |
| 64 |
XmlElement status = appendElement(sonrs, "STATUS"); |
| 65 |
appendElementWithText(status, "CODE", "0"); |
| 66 |
appendElementWithText(status, "SEVERITY", "INFO"); |
| 67 |
appendElementWithText(sonrs, "DTSERVER", dateStr(last.date)); |
| 68 |
appendElementWithText(sonrs, "LANGUAGE", "JPN"); |
| 69 |
XmlElement fi = appendElement(sonrs, "FI"); |
| 70 |
appendElementWithText(fi, "ORG", card.Ident); |
| 71 |
// FITID������ |
| 72 |
|
| 73 |
/* ������������(���������������������������������������) */ |
| 74 |
XmlElement bankMsgSrsv1 = appendElement(root, "BANKMSGSRSV1"); |
| 75 |
|
| 76 |
/* ��������������������������������� */ |
| 77 |
XmlElement stmttrnrs = appendElement(bankMsgSrsv1, "STMTTRNRS"); |
| 78 |
appendElementWithText(stmttrnrs, "TRNUID", "0"); |
| 79 |
|
| 80 |
status = appendElement(stmttrnrs, "STATUS"); |
| 81 |
appendElementWithText(status, "CODE", "0"); |
| 82 |
appendElementWithText(status, "SEVERITY", "INFO"); |
| 83 |
|
| 84 |
/* STMTRS */ |
| 85 |
XmlElement stmtrs = appendElement(stmttrnrs, "STMTRS"); |
| 86 |
appendElementWithText(stmtrs, "CURDEF", "JPY"); |
| 87 |
|
| 88 |
// ������������������ |
| 89 |
XmlElement bankacctfrom = doc.CreateElement("BANKACCTFROM"); |
| 90 |
stmtrs.AppendChild(bankacctfrom); |
| 91 |
|
| 92 |
appendElementWithText(bankacctfrom, "BANKID", card.BankId.ToString()); |
| 93 |
appendElementWithText(bankacctfrom, "BRANCHID", card.BranchId); |
| 94 |
appendElementWithText(bankacctfrom, "ACCTID", card.AccountId); |
| 95 |
appendElementWithText(bankacctfrom, "ACCTTYPE", "SAVINGS"); |
| 96 |
|
| 97 |
/* ������������������(������������������������������������������) */ |
| 98 |
XmlElement banktranlist = appendElement(stmtrs, "BANKTRANLIST"); |
| 99 |
|
| 100 |
appendElementWithText(banktranlist, "DTSTART", dateStr(first.date)); |
| 101 |
appendElementWithText(banktranlist, "DTEND", dateStr(last.date)); |
| 102 |
|
| 103 |
/* ������������������������ */ |
| 104 |
foreach (Transaction t in transactions) |
| 105 |
{ |
| 106 |
XmlElement stmttrn = appendElement(banktranlist, "STMTTRN"); |
| 107 |
|
| 108 |
appendElementWithText(stmttrn, "TRNTYPE", t.GetTransString()); |
| 109 |
appendElementWithText(stmttrn, "DTPOSTED", dateStr(t.date)); |
| 110 |
appendElementWithText(stmttrn, "TRNAMT", t.value.ToString()); |
| 111 |
|
| 112 |
// ��������������������������� ID ��������������������������������� |
| 113 |
appendElementWithText(stmttrn, "FITID", transId(t)); |
| 114 |
appendElementWithText(stmttrn, "NAME", quoteString(t.desc)); |
| 115 |
if (t.memo != null) |
| 116 |
{ |
| 117 |
appendElementWithText(stmttrn, "MEMO", quoteString(t.memo)); |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
/* ������ */ |
| 122 |
XmlElement ledgerbal = appendElement(stmtrs, "LEDGERBAL"); |
| 123 |
|
| 124 |
appendElementWithText(ledgerbal, "BALAMT", last.balance.ToString()); |
| 125 |
appendElementWithText(ledgerbal, "DTASOF", dateStr(last.date)); |
| 126 |
|
| 127 |
return doc; |
| 128 |
} |
| 129 |
|
| 130 |
// ������������ |
| 131 |
private XmlElement appendElement(XmlElement parent, string elem) |
| 132 |
{ |
| 133 |
XmlElement e = doc.CreateElement(elem); |
| 134 |
parent.AppendChild(e); |
| 135 |
return e; |
| 136 |
} |
| 137 |
|
| 138 |
// ������������ (���������������������������) |
| 139 |
private void appendElementWithText(XmlElement parent, string elem, string text) |
| 140 |
{ |
| 141 |
XmlElement e = doc.CreateElement(elem); |
| 142 |
e.AppendChild(doc.CreateTextNode(text)); |
| 143 |
parent.AppendChild(e); |
| 144 |
} |
| 145 |
} |
| 146 |
} |