| 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 |
// stationcode.mdb アクセスクラス (試作中) |
| 22 |
|
| 23 |
using System; |
| 24 |
using System.Data.OleDb; |
| 25 |
|
| 26 |
namespace FeliCa2Money |
| 27 |
{ |
| 28 |
class StationCode : IDisposable |
| 29 |
{ |
| 30 |
private OleDbConnection conn; |
| 31 |
|
| 32 |
public StationCode() |
| 33 |
{ |
| 34 |
conn = new System.Data.OleDb.OleDbConnection(); |
| 35 |
conn.ConnectionString = Properties.Settings.Default.StationCodeConnectionString; |
| 36 |
conn.Open(); |
| 37 |
} |
| 38 |
|
| 39 |
public void Dispose() |
| 40 |
{ |
| 41 |
conn.Close(); |
| 42 |
} |
| 43 |
|
| 44 |
private string[] doQuery(string sql) |
| 45 |
{ |
| 46 |
OleDbCommand cmd; |
| 47 |
OleDbDataReader dr; |
| 48 |
|
| 49 |
cmd = new OleDbCommand(sql, conn); |
| 50 |
dr = cmd.ExecuteReader(); |
| 51 |
|
| 52 |
string[] result = null; |
| 53 |
if (dr.Read()) |
| 54 |
{ |
| 55 |
result = new string[2]; |
| 56 |
if (dr.IsDBNull(0)) |
| 57 |
{ |
| 58 |
result[0] = ""; |
| 59 |
} |
| 60 |
else |
| 61 |
{ |
| 62 |
result[0] = dr.GetString(0); |
| 63 |
} |
| 64 |
|
| 65 |
if (dr.IsDBNull(1)) |
| 66 |
{ |
| 67 |
result[1] = ""; |
| 68 |
} |
| 69 |
else |
| 70 |
{ |
| 71 |
result[1] = dr.GetString(1); |
| 72 |
} |
| 73 |
} |
| 74 |
dr.Close(); |
| 75 |
return result; |
| 76 |
} |
| 77 |
|
| 78 |
// 駅名を検索する |
| 79 |
public string[] getStationName(int area, int line, int station) |
| 80 |
{ |
| 81 |
if (line == 0 && station == 0) |
| 82 |
{ |
| 83 |
string[] res = new string[2]; |
| 84 |
res[0] = ""; |
| 85 |
res[1] = ""; |
| 86 |
return res; |
| 87 |
} |
| 88 |
string sql = string.Format("SELECT CompanyName,StationName FROM StationCode WHERE" |
| 89 |
+ " AreaCode={0} AND LineCode={1} AND StationCode={2}", area, line, station); |
| 90 |
return doQuery(sql); |
| 91 |
} |
| 92 |
|
| 93 |
// 店舗名を検索する |
| 94 |
// area = -1 として検索すると、area 指定なしとみなす |
| 95 |
public string[] getShopName(int area, int terminal, int line, int station) |
| 96 |
{ |
| 97 |
string sql = string.Format("SELECT CompanyName,ShopName FROM ShopCode WHERE" |
| 98 |
+ " TerminalCode={0} AND LineCode={1} AND StationCode={2}", terminal, line, station); |
| 99 |
if (area >= 0) |
| 100 |
{ |
| 101 |
sql += " AND AreaCode=" + area.ToString(); |
| 102 |
} |
| 103 |
return doQuery(sql); |
| 104 |
} |
| 105 |
|
| 106 |
// バス停留所名を検索する |
| 107 |
public string[] getBusName(int line, int station) |
| 108 |
{ |
| 109 |
string sql = string.Format("SELECT BusCompanyName,BusStationName FROM BusCode WHERE" |
| 110 |
+ " BusLineCode={0} AND BusStationCode={1}", line, station); |
| 111 |
return doQuery(sql); |
| 112 |
} |
| 113 |
} |
| 114 |
} |