| 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; |
| 25 |
using System.Windows.Forms; |
| 26 |
|
| 27 |
namespace FeliCa2Money |
| 28 |
{ |
| 29 |
public partial class CsvDialog : Form |
| 30 |
{ |
| 31 |
// CSV 変換ルールセット |
| 32 |
private CsvRules rules; |
| 33 |
|
| 34 |
// 支店番号/口座番号のキャッシュ |
| 35 |
private Hashtable branchIds; |
| 36 |
private Hashtable accountIds; |
| 37 |
|
| 38 |
// 支店番号テキストボックス |
| 39 |
public string BranchId |
| 40 |
{ |
| 41 |
get { return textBranchId.Text; } |
| 42 |
set { textBranchId.Text = value; } |
| 43 |
} |
| 44 |
|
| 45 |
// 口座番号テキストボックス |
| 46 |
public string AccountId |
| 47 |
{ |
| 48 |
get { return textAccountId.Text; } |
| 49 |
set { textAccountId.Text = value; } |
| 50 |
} |
| 51 |
|
| 52 |
// コンストラクタ |
| 53 |
public CsvDialog(CsvRules r) |
| 54 |
{ |
| 55 |
InitializeComponent(); |
| 56 |
|
| 57 |
rules = r; |
| 58 |
|
| 59 |
listBox.Items.Clear(); |
| 60 |
string[] names = rules.names(); |
| 61 |
|
| 62 |
// リストボックスにルール名をリストする |
| 63 |
foreach (string name in names) |
| 64 |
{ |
| 65 |
listBox.Items.Add(name); |
| 66 |
} |
| 67 |
|
| 68 |
// 支店番号/口座番号をユーザ設定から読み出す |
| 69 |
branchIds = new Hashtable(); |
| 70 |
accountIds = new Hashtable(); |
| 71 |
LoadAccountInfo(); |
| 72 |
} |
| 73 |
|
| 74 |
// 支店番号/口座番号をユーザ設定から読み出す |
| 75 |
private void LoadAccountInfo() |
| 76 |
{ |
| 77 |
foreach (string x in Properties.Settings.Default.AccountInfo) |
| 78 |
{ |
| 79 |
// 各行には、Ident,BranchId,AccountId が入っているものとする |
| 80 |
string[] a = x.Split(new char[] { ',' }); |
| 81 |
branchIds[a[0]] = a[1]; |
| 82 |
accountIds[a[0]] = a[2]; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
// 支店番号/口座番号をユーザ設定に書き戻す |
| 87 |
private void SaveAccountInfo() |
| 88 |
{ |
| 89 |
Properties.Settings s = Properties.Settings.Default; |
| 90 |
|
| 91 |
s.AccountInfo.Clear(); |
| 92 |
|
| 93 |
int count = rules.Count; |
| 94 |
for (int i = 0; i < count; i++) |
| 95 |
{ |
| 96 |
CsvRule rule = rules.GetAt(i); |
| 97 |
string org = rule.Ident; |
| 98 |
string x = rule.Ident + ","; |
| 99 |
if (branchIds[org] != null) { |
| 100 |
x += branchIds[org]; |
| 101 |
} |
| 102 |
x += ","; |
| 103 |
if (accountIds[org] != null) |
| 104 |
{ |
| 105 |
x += accountIds[org]; |
| 106 |
} |
| 107 |
s.AccountInfo.Add(x); |
| 108 |
} |
| 109 |
|
| 110 |
s.Save(); |
| 111 |
} |
| 112 |
|
| 113 |
// 引数で指定したルールを選択状態にする |
| 114 |
public void SelectRule(CsvRule selRule) |
| 115 |
{ |
| 116 |
if (selRule == null) return; |
| 117 |
|
| 118 |
int idx = rules.IndexOf(selRule); |
| 119 |
listBox.SelectedIndex = idx; |
| 120 |
} |
| 121 |
|
| 122 |
// 選択アイテムが変更されたときの処理 |
| 123 |
private void listBox_SelectedIndexChanged(object sender, EventArgs e) |
| 124 |
{ |
| 125 |
// 支店番号、口座番号をテキストボックスに設定する |
| 126 |
CsvRule rule = SelectedRule(); |
| 127 |
string ident = rule.Ident; |
| 128 |
if (branchIds[ident] != null) |
| 129 |
{ |
| 130 |
BranchId = (string)branchIds[ident]; |
| 131 |
} |
| 132 |
else |
| 133 |
{ |
| 134 |
BranchId = ""; |
| 135 |
} |
| 136 |
if (accountIds[ident] != null) |
| 137 |
{ |
| 138 |
AccountId = (string)accountIds[ident]; |
| 139 |
} |
| 140 |
else |
| 141 |
{ |
| 142 |
AccountId = ""; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
// 選択中のルールを返す |
| 147 |
public CsvRule SelectedRule() |
| 148 |
{ |
| 149 |
int idx = listBox.SelectedIndex; |
| 150 |
if (idx < 0) |
| 151 |
{ |
| 152 |
return null; |
| 153 |
} |
| 154 |
return rules.GetAt(idx); |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
private void textBranchId_Leave(object sender, EventArgs e) |
| 159 |
{ |
| 160 |
CsvRule rule = SelectedRule(); |
| 161 |
string org = rule.Ident; |
| 162 |
branchIds[org] = textBranchId.Text; |
| 163 |
} |
| 164 |
|
| 165 |
private void textAccountId_Leave(object sender, EventArgs e) |
| 166 |
{ |
| 167 |
CsvRule rule = SelectedRule(); |
| 168 |
string org = rule.Ident; |
| 169 |
accountIds[org] = textAccountId.Text; |
| 170 |
} |
| 171 |
|
| 172 |
private void CsvDialog_FormClosing(object sender, FormClosingEventArgs e) |
| 173 |
{ |
| 174 |
SaveAccountInfo(); |
| 175 |
} |
| 176 |
} |
| 177 |
} |