Develop and Download Open Source Software

Browse Subversion Repository

Contents of /tags/FeliCa2Money-2.4/CsvRules.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 150 - (show annotations) (download)
Sun Mar 16 10:36:07 2008 UTC (16 years ago) by tmurakam
File size: 6540 byte(s)
ver 2.4 tag

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 // CSV 変換ルールセット
22
23 using System;
24 using System.Collections.Generic;
25 using System.Text;
26 using System.Xml;
27 using System.Windows.Forms;
28 using System.Net;
29 using System.IO;
30
31 namespace FeliCa2Money
32 {
33 public class CsvRules
34 {
35 private List<CsvRule> ruleList;
36
37 public CsvRules()
38 {
39 ruleList = new List<CsvRule>();
40 }
41
42 public int Count
43 {
44 get { return ruleList.Count; }
45 }
46
47 // 全 CSV 変換ルールを読み出す
48 public bool LoadAllRules()
49 {
50 // ユーザ設定フォルダのほうから読み出す
51 String path = getRulesPath();
52 //String path = Path.GetDirectoryName(Application.ExecutablePath);
53
54 string[] xmlFiles = Directory.GetFiles(path, "*.xml");
55 if (xmlFiles.Length == 0)
56 {
57 if (MessageBox.Show("CSV変換定義がありません。今すぐダウンロードしますか?", "確認",
58 MessageBoxButtons.OKCancel) != DialogResult.OK) return false;
59
60 if (!DownloadRule()) return false;
61
62 xmlFiles = Directory.GetFiles(path, "*.xml");
63 }
64
65 foreach (string xmlFile in xmlFiles)
66 {
67 try
68 {
69 LoadFromFile(xmlFile);
70 }
71 catch (Exception)
72 {
73 MessageBox.Show("定義ファイルエラー in " + xmlFile, "エラー");
74 }
75 }
76 return true;
77 }
78
79 // 定義ファイルを1つ読み込む
80 public void LoadFromFile(string path)
81 {
82 XmlDocument doc = new XmlDocument();
83 doc.Load(path);
84 XmlElement root = doc.DocumentElement;
85
86 // Rule 子要素について処理
87 XmlNodeList list = root.GetElementsByTagName("Rule");
88
89 for (int i = 0; i < list.Count; i++)
90 {
91 // rule 生成
92 CsvRule rule = new CsvRule();
93
94 // rule の各メンバを設定
95 foreach (XmlElement e in list[i].ChildNodes)
96 {
97 string value = "";
98 if (e.FirstChild == null)
99 {
100 // 空要素
101 }
102 else
103 {
104 value = e.FirstChild.Value;
105 }
106
107 switch (e.Name)
108 {
109 case "Ident":
110 rule.Ident = value;
111 break;
112 case "Name":
113 rule.Name = value;
114 break;
115 case "BankId":
116 rule.BankId = int.Parse(value);
117 break;
118 case "FirstLine":
119 rule.FirstLine = value;
120 break;
121 case "Format":
122 rule.Format = value;
123 break;
124 case "Order":
125 rule.Order = value;
126 break;
127 default:
128 // ignore
129 break;
130 }
131 }
132
133 ruleList.Add(rule);
134 }
135 }
136
137 // 名前一覧を返す
138 public string[] names()
139 {
140 string[] names = new string[ruleList.Count];
141 int i = 0;
142 foreach (CsvRule rule in ruleList)
143 {
144 names[i] = rule.Name;
145 i++;
146 }
147 return names;
148 }
149
150 // 指定したインデックスのルールを返す
151 public CsvRule GetAt(int idx)
152 {
153 return ruleList[idx];
154 }
155
156 // 指定したルールのインデックスを返す
157 public int IndexOf(CsvRule rule)
158 {
159 return ruleList.IndexOf(rule);
160 }
161
162 // firstLine に一致するルールを探す
163 public CsvRule FindRule(string firstLine)
164 {
165 foreach (CsvRule rule in ruleList)
166 {
167 if (rule.FirstLine == firstLine)
168 {
169 return rule;
170 }
171 }
172 return null;
173 }
174
175 // 定義ファイルをダウンロードする
176 public static bool DownloadRule()
177 {
178 string path = getRulesPath() + "\\CsvRules.xml";
179 //string url = "http://moneyimport.sourceforge.jp/CsvRules.xml";
180 string url = "http://svn.sourceforge.jp/svnroot/moneyimport/trunk/FeliCa2Money.net/CsvRules.xml";
181
182 WebClient w = new WebClient();
183 try
184 {
185 w.DownloadFile(url, path);
186 }
187 catch (Exception ex)
188 {
189 MessageBox.Show(ex.Message, "エラー");
190 return false;
191 }
192 return true;
193 }
194
195 // 定義ファイルのディレクトリを返す
196 // UserAppDataPath からバージョン番号を除いたもの
197 private static string getRulesPath()
198 {
199 string path = Application.LocalUserAppDataPath;
200 path = System.IO.Path.GetDirectoryName(path);
201 return path;
202 }
203 }
204 }

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