リビジョン 97
IOクラスprocessmanagementより参照、注文書明細フィールド追加SQL
branches/ddl/DataConert/DataConert/MySQLDB/MySql/MySqlProcess.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Collections; |
|
4 |
using System.Data; |
|
5 |
using System.Linq; |
|
6 |
using System.Text; |
|
7 |
using System.Threading.Tasks; |
|
8 |
|
|
9 |
using MySql.Data.MySqlClient; |
|
10 |
|
|
11 |
using log4net; |
|
12 |
using log4net.Appender; |
|
13 |
using log4net.Repository.Hierarchy; |
|
14 |
|
|
15 |
using ProcessManagement.MySQLDB.Core; |
|
16 |
|
|
17 |
namespace ProcessManagement.MySQLDB.MySql |
|
18 |
{ |
|
19 |
/// <summary> |
|
20 |
/// MySql使用共通ラッパークラス |
|
21 |
/// </summary> |
|
22 |
public class MySqlProcess : ABaseDBProcessForMySQL |
|
23 |
{ |
|
24 |
#region コンストラクタ |
|
25 |
/// <summary> |
|
26 |
/// コンストラクタ。 |
|
27 |
/// </summary> |
|
28 |
/// <param name="connectionString">接続文字列</param> |
|
29 |
public MySqlProcess(String connectionString) |
|
30 |
: base(connectionString) |
|
31 |
{ |
|
32 |
} |
|
33 |
#endregion |
|
34 |
|
|
35 |
#region メソッド |
|
36 |
/// <summary> |
|
37 |
/// Connectionを取得。 |
|
38 |
/// </summary> |
|
39 |
/// <param name="connectionString"></param> |
|
40 |
/// <returns>Connection</returns> |
|
41 |
public override IDbConnection getConnection(String connectionString) |
|
42 |
{ |
|
43 |
return new MySqlConnection(connectionString); |
|
44 |
} |
|
45 |
|
|
46 |
#endregion |
|
47 |
} |
|
48 |
} |
branches/ddl/DataConert/DataConert/MySQLDB/Core/IBaseDBForMySQL.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Data; |
|
4 |
using System.Linq; |
|
5 |
using System.Text; |
|
6 |
|
|
7 |
namespace ProcessManagement.MySQLDB.Core |
|
8 |
{ |
|
9 |
/// <summary> |
|
10 |
/// データベース共通インターフェースクラス |
|
11 |
/// </summary> |
|
12 |
public interface IBaseDBForMySQL |
|
13 |
{ |
|
14 |
/// <summary> |
|
15 |
/// コネクト処理。 |
|
16 |
/// </summary> |
|
17 |
void connect(); |
|
18 |
|
|
19 |
/// <summary> |
|
20 |
/// クローズ処理。 |
|
21 |
/// </summary> |
|
22 |
bool close(); |
|
23 |
|
|
24 |
/// <summary> |
|
25 |
/// トランザクション開始。 |
|
26 |
/// </summary> |
|
27 |
bool beginTran(); |
|
28 |
|
|
29 |
/// <summary> |
|
30 |
/// コミット。 |
|
31 |
/// </summary> |
|
32 |
bool commit(); |
|
33 |
|
|
34 |
/// <summary> |
|
35 |
/// ロールバック。 |
|
36 |
/// </summary> |
|
37 |
bool rollback(); |
|
38 |
|
|
39 |
} |
|
40 |
} |
branches/ddl/DataConert/DataConert/MySQLDB/Core/DBCommonForMySQL.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
|
|
6 |
using log4net; |
|
7 |
using ProcessManagement.Common; |
|
8 |
|
|
9 |
namespace ProcessManagement.MySQLDB.Core |
|
10 |
{ |
|
11 |
/// <summary> |
|
12 |
/// データベース共通接続クラス |
|
13 |
/// </summary> |
|
14 |
public class DBCommonForMySQL |
|
15 |
{ |
|
16 |
#region 定義部 |
|
17 |
/// <summary> |
|
18 |
/// データベース接続共通クラスインスタンスハンドル |
|
19 |
/// </summary> |
|
20 |
private static DBCommonForMySQL m_instance = new DBCommonForMySQL(); |
|
21 |
/// <summary> |
|
22 |
/// log4netログを使用する |
|
23 |
/// </summary> |
|
24 |
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
|
25 |
#endregion |
|
26 |
|
|
27 |
#region 変数 |
|
28 |
/// <summary> |
|
29 |
/// DB接続情報 |
|
30 |
/// </summary> |
|
31 |
private string m_dbconnectString = string.Empty; |
|
32 |
#endregion |
|
33 |
|
|
34 |
#region コンストラクタ |
|
35 |
/// <summary> |
|
36 |
/// 何もしない |
|
37 |
/// </summary> |
|
38 |
#endregion |
|
39 |
|
|
40 |
#region プロパティ |
|
41 |
/// <summary> |
|
42 |
///インスタンス |
|
43 |
/// </summary> |
|
44 |
public static DBCommonForMySQL Instance |
|
45 |
{ |
|
46 |
get { return m_instance; } |
|
47 |
} |
|
48 |
/// <summary> |
|
49 |
/// 接続文字列取得 |
|
50 |
/// </summary> |
|
51 |
public string DBConnectString |
|
52 |
{ |
|
53 |
get { return m_dbconnectString; } |
|
54 |
} |
|
55 |
#endregion |
|
56 |
|
|
57 |
#region メソッド |
|
58 |
/// <summary> |
|
59 |
/// 初期化メソッド |
|
60 |
/// </summary> |
|
61 |
public void Initialize() |
|
62 |
{ |
|
63 |
// DB接続情報作成 |
|
64 |
m_dbconnectString = string.Format("Server={0};", CommonMySQLDef.DBServer); |
|
65 |
m_dbconnectString += string.Format("Uid={0};", CommonMySQLDef.DBUser); |
|
66 |
m_dbconnectString += string.Format("Pwd={0};", CommonMySQLDef.Password); |
|
67 |
m_dbconnectString += string.Format("Database={0};", CommonMySQLDef.Database); |
|
68 |
} |
|
69 |
|
|
70 |
#endregion |
|
71 |
} |
|
72 |
} |
branches/ddl/DataConert/DataConert/MySQLDB/Core/ABaseDBProcessForMySQL.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Data; |
|
4 |
using System.Linq; |
|
5 |
using System.Text; |
|
6 |
using System.Collections; |
|
7 |
|
|
8 |
using MySql.Data.MySqlClient; |
|
9 |
|
|
10 |
using log4net; |
|
11 |
using log4net.Appender; |
|
12 |
using log4net.Repository.Hierarchy; |
|
13 |
|
|
14 |
using ProcessManagement.Common; |
|
15 |
|
|
16 |
namespace ProcessManagement.MySQLDB.Core |
|
17 |
{ |
|
18 |
/// <summary> |
|
19 |
/// データベース共通抽象クラス |
|
20 |
/// </summary> |
|
21 |
public abstract class ABaseDBProcessForMySQL : IBaseDBForMySQL |
|
22 |
{ |
|
23 |
#region ログ定義 |
|
24 |
/// <summary> |
|
25 |
/// log4netログを使用する |
|
26 |
/// </summary> |
|
27 |
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
|
28 |
#endregion |
|
29 |
|
|
30 |
#region メンバ変数 |
|
31 |
/// <summary> |
|
32 |
/// DB接続 |
|
33 |
/// </summary> |
|
34 |
protected IDbConnection m_connection = null; |
|
35 |
/// <summary> |
|
36 |
/// 接続有無(true:接続中) |
|
37 |
/// </summary> |
|
38 |
protected bool m_isConnect = false; |
|
39 |
/// <summary> |
|
40 |
/// トランザクション |
|
41 |
/// </summary> |
|
42 |
protected IDbTransaction m_transaction = null; |
|
43 |
/// <summary> |
|
44 |
/// 接続文字列 |
|
45 |
/// </summary> |
|
46 |
protected String m_connectionString = null; |
|
47 |
|
|
48 |
#endregion |
|
49 |
|
|
50 |
#region コンストラクタ |
|
51 |
|
|
52 |
/// <summary> |
|
53 |
/// コンストラクタ |
|
54 |
/// </summary> |
|
55 |
/// <param name="connectionString">接続文字列</param> |
|
56 |
public ABaseDBProcessForMySQL(String connectionString) |
|
57 |
{ |
|
58 |
//接続文字列セット |
|
59 |
this.m_connectionString = connectionString; |
|
60 |
} |
|
61 |
#endregion |
|
62 |
|
|
63 |
#region プロパティ |
|
64 |
/// <summary> |
|
65 |
/// DCコネクション |
|
66 |
/// </summary> |
|
67 |
public IDbConnection DBConnection |
|
68 |
{ |
|
69 |
get { return m_connection; } |
|
70 |
set { m_connection = value; } |
|
71 |
} |
|
72 |
#endregion |
|
73 |
|
|
74 |
#region プライベートメソッド |
|
75 |
/// <summary> |
|
76 |
/// 接続の確立判断。 |
|
77 |
/// </summary> |
|
78 |
/// <returns>true:接続確立 false:接続無</returns> |
|
79 |
private bool isConnect() |
|
80 |
{ |
|
81 |
//接続されていない場合 |
|
82 |
if (this.m_connection == null || !this.m_isConnect) return false; |
|
83 |
|
|
84 |
return true; |
|
85 |
} |
|
86 |
|
|
87 |
/// <summary> |
|
88 |
/// パラメータの値を取得する |
|
89 |
/// </summary> |
|
90 |
/// <param name="value">値</param> |
|
91 |
/// <returns>パラメータの値</returns> |
|
92 |
protected object getParamValue(object value) |
|
93 |
{ |
|
94 |
if (value != null) return value; |
|
95 |
|
|
96 |
return DBNull.Value; |
|
97 |
} |
|
98 |
#endregion |
|
99 |
|
|
100 |
#region コネクション接続 |
|
101 |
/// <summary> |
|
102 |
/// Connectionを取得。 |
|
103 |
/// </summary> |
|
104 |
/// <param name="connectionString"></param> |
|
105 |
/// <returns>Connectionのオブジェクト</returns> |
|
106 |
public virtual IDbConnection getConnection(String connectionString) |
|
107 |
{ |
|
108 |
return new MySqlConnection(connectionString); |
|
109 |
} |
|
110 |
|
|
111 |
#endregion |
|
112 |
|
|
113 |
#region connect |
|
114 |
/// <summary> |
|
115 |
/// コネクト処理。 |
|
116 |
/// </summary> |
|
117 |
public void connect() |
|
118 |
{ |
|
119 |
try |
|
120 |
{ |
|
121 |
//接続有無=無に設定 |
|
122 |
this.m_isConnect = false; |
|
123 |
|
|
124 |
//接続済みの場合 |
|
125 |
if (this.m_connection != null) |
|
126 |
{ |
|
127 |
//接続をClose |
|
128 |
this.m_connection.Close(); |
|
129 |
//初期化 |
|
130 |
this.m_connection = null; |
|
131 |
} |
|
132 |
|
|
133 |
//Connectionを取得 |
|
134 |
this.m_connection = getConnection(m_connectionString); |
|
135 |
|
|
136 |
//Open |
|
137 |
this.m_connection.Open(); |
|
138 |
//接続有無=ありに設定 |
|
139 |
this.m_isConnect = true; |
|
140 |
} |
|
141 |
catch (Exception ex) |
|
142 |
{ |
|
143 |
logger.ErrorFormat("{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, m_connectionString); |
|
144 |
} |
|
145 |
} |
|
146 |
#endregion |
|
147 |
|
|
148 |
#region close |
|
149 |
/// <summary> |
|
150 |
/// クローズ処理。 |
|
151 |
/// </summary> |
|
152 |
/// <returns>true:切断成功 false:接続無</returns> |
|
153 |
public bool close() |
|
154 |
{ |
|
155 |
try |
|
156 |
{ |
|
157 |
//接続が確立されていない場合は処理なし |
|
158 |
if (!isConnect()) return false; |
|
159 |
|
|
160 |
//トランザクションを破棄する |
|
161 |
if (this.m_transaction != null) |
|
162 |
{ |
|
163 |
this.m_transaction.Dispose(); |
|
164 |
this.m_transaction = null; |
|
165 |
} |
|
166 |
|
|
167 |
//接続をClose&破棄する |
|
168 |
if (this.m_connection != null) |
|
169 |
{ |
|
170 |
this.m_connection.Close(); |
|
171 |
this.m_connection.Dispose(); |
|
172 |
this.m_connection = null; |
|
173 |
} |
|
174 |
|
|
175 |
//接続有無なしに設定 |
|
176 |
this.m_isConnect = false; |
|
177 |
|
|
178 |
return true; |
|
179 |
} |
|
180 |
catch (Exception ex) |
|
181 |
{ |
|
182 |
logger.ErrorFormat("{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, m_connectionString); |
|
183 |
return false; |
|
184 |
} |
|
185 |
} |
|
186 |
#endregion |
|
187 |
|
|
188 |
#region begintran |
|
189 |
/// <summary> |
|
190 |
/// トランザクション開始。 |
|
191 |
/// </summary> |
|
192 |
/// <returns>true:開始成功 false:接続無</returns> |
|
193 |
public bool beginTran() |
|
194 |
{ |
|
195 |
try |
|
196 |
{ |
|
197 |
//接続が確立されていない場合、処理なし |
|
198 |
if (!isConnect()) return false; |
|
199 |
|
|
200 |
//トランザクション開始 |
|
201 |
this.m_transaction = m_connection.BeginTransaction(); |
|
202 |
|
|
203 |
return true; |
|
204 |
} |
|
205 |
catch (Exception ex) |
|
206 |
{ |
|
207 |
logger.ErrorFormat("{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, m_connectionString); |
|
208 |
return false; |
|
209 |
} |
|
210 |
} |
|
211 |
#endregion |
|
212 |
|
|
213 |
#region commit |
|
214 |
/// <summary> |
|
215 |
/// コミット。 |
|
216 |
/// </summary> |
|
217 |
/// <returns>true:Commit成功 false:トランザクション無・接続無</returns> |
|
218 |
public bool commit() |
|
219 |
{ |
|
220 |
try |
|
221 |
{ |
|
222 |
//接続が確立されていない場合は処理なし |
|
223 |
if (!isConnect()) return false; |
|
224 |
|
|
225 |
//トランザクションが開始されていない場合、処理なし |
|
226 |
if (this.m_transaction == null) return false; |
|
227 |
|
|
228 |
//コミット |
|
229 |
m_transaction.Commit(); |
|
230 |
|
|
231 |
return true; |
|
232 |
} |
|
233 |
catch (Exception ex) |
|
234 |
{ |
|
235 |
//ログ出力 |
|
236 |
logger.ErrorFormat("{0}:{1}", CommonMotions.GetMethodName(2), ex.Message); |
|
237 |
return false; |
|
238 |
} |
|
239 |
finally |
|
240 |
{ |
|
241 |
//トランザクションを破棄する |
|
242 |
if (this.m_transaction != null) |
|
243 |
{ |
|
244 |
this.m_transaction.Dispose(); |
|
245 |
this.m_transaction = null; |
|
246 |
} |
|
247 |
} |
|
248 |
} |
|
249 |
#endregion |
|
250 |
|
|
251 |
#region rollback |
|
252 |
/// <summary> |
|
253 |
/// ロールバック。 |
|
254 |
/// </summary> |
|
255 |
/// <returns>true:Rollback成功 false:トランザクション無・接続無</returns> |
|
256 |
public bool rollback() |
|
257 |
{ |
|
258 |
try |
|
259 |
{ |
|
260 |
//接続が確立されていない場合は処理なし |
|
261 |
if (!isConnect()) return false; |
|
262 |
|
|
263 |
//トランザクションが開始されていない場合は処理なし |
|
264 |
if (this.m_transaction == null) return false; |
|
265 |
|
|
266 |
//ロールバック |
|
267 |
this.m_transaction.Rollback(); |
|
268 |
|
|
269 |
return true; |
|
270 |
} |
|
271 |
catch (Exception ex) |
|
272 |
{ |
|
273 |
//ログ出力 |
|
274 |
logger.ErrorFormat("{0}:{1}", CommonMotions.GetMethodName(2), ex.Message); |
|
275 |
return false; |
|
276 |
} |
|
277 |
finally |
|
278 |
{ |
|
279 |
//トランザクションを破棄する |
|
280 |
if (this.m_transaction != null) |
|
281 |
{ |
|
282 |
this.m_transaction.Dispose(); |
|
283 |
this.m_transaction = null; |
|
284 |
} |
|
285 |
} |
|
286 |
} |
|
287 |
#endregion |
|
288 |
|
|
289 |
#region ExecuteReader |
|
290 |
/// <summary> |
|
291 |
/// MySQLリーダー |
|
292 |
/// </summary> |
|
293 |
/// <param name="strSql">検索SQL</param> |
|
294 |
/// <param name="arData">取得データ</param> |
|
295 |
/// <returns>成功時:true 失敗時:false</returns> |
|
296 |
public bool ExecuteReader(string strSql, ref ArrayList arData, bool bconnect = true) |
|
297 |
{ |
|
298 |
//MySQL インターフェース |
|
299 |
MySqlCommand mycmd = new MySqlCommand(); |
|
300 |
MySqlDataReader myreader = null; |
|
301 |
try |
|
302 |
{ |
|
303 |
//接続 |
|
304 |
if (bconnect) this.connect(); |
|
305 |
|
|
306 |
//MySqlCommand・MySqlDataReader作成 |
|
307 |
mycmd.Connection = (MySqlConnection)m_connection; |
|
308 |
|
|
309 |
//SQLセット |
|
310 |
mycmd.CommandText = strSql; |
|
311 |
|
|
312 |
myreader = mycmd.ExecuteReader(); |
|
313 |
|
|
314 |
int iFeildcnt = myreader.FieldCount; |
|
315 |
//読込 |
|
316 |
while (myreader.Read()) |
|
317 |
{ |
|
318 |
object[] objwrk = new object[iFeildcnt]; |
|
319 |
|
|
320 |
myreader.GetValues(objwrk); |
|
321 |
|
|
322 |
//null抑制 |
|
323 |
int i = 0; |
|
324 |
foreach (object www in objwrk) |
|
325 |
{ |
|
326 |
objwrk[i++] = www.ToString().Equals("null") ? "" : www; |
|
327 |
} |
|
328 |
|
|
329 |
arData.Add(objwrk); |
|
330 |
|
|
331 |
} |
|
332 |
return true; |
|
333 |
} |
|
334 |
catch (MySqlException myex) |
|
335 |
{ |
|
336 |
logger.ErrorFormat("MySQLエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), myex.Message, strSql); |
|
337 |
return false; |
|
338 |
} |
|
339 |
catch (Exception ex) |
|
340 |
{ |
|
341 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strSql); |
|
342 |
return false; |
|
343 |
} |
|
344 |
finally |
|
345 |
{ |
|
346 |
if (myreader != null) |
|
347 |
{ |
|
348 |
myreader.Close(); |
|
349 |
myreader.Dispose(); |
|
350 |
myreader = null; |
|
351 |
} |
|
352 |
mycmd.Dispose(); |
|
353 |
mycmd = null; |
|
354 |
|
|
355 |
//切断 |
|
356 |
if (bconnect) this.close(); |
|
357 |
} |
|
358 |
} |
|
359 |
#endregion |
|
360 |
|
|
361 |
#region ExecuteNonQuery |
|
362 |
/// <summary> |
|
363 |
/// MySQL ExecuteNonQuery |
|
364 |
/// </summary> |
|
365 |
/// <param name="strSql">実行SQL</param> |
|
366 |
/// <returns>成功時:true 失敗時:false</returns> |
|
367 |
public bool ExecuteNonQuery(string strSql, bool bconnect = true) |
|
368 |
{ |
|
369 |
//MySQL インターフェース |
|
370 |
MySqlCommand mycmd = new MySqlCommand(); |
|
371 |
|
|
372 |
try |
|
373 |
{ |
|
374 |
//接続 |
|
375 |
if (bconnect) this.connect(); |
|
376 |
|
|
377 |
//ネクションセット |
|
378 |
mycmd.Connection = (MySqlConnection)m_connection; |
|
379 |
|
|
380 |
//トランザクション |
|
381 |
if (bconnect) |
|
382 |
{ |
|
383 |
if (!this.beginTran()) return false; |
|
384 |
} |
|
385 |
|
|
386 |
//SQLセット |
|
387 |
mycmd.CommandText = strSql; |
|
388 |
//実行 |
|
389 |
if (mycmd.ExecuteNonQuery() == 0) |
|
390 |
{ |
|
391 |
//エラー時rollbackして処理終了 |
|
392 |
if (bconnect) this.rollback(); |
|
393 |
return false; |
|
394 |
} |
|
395 |
//成功時Commit |
|
396 |
if (bconnect) |
|
397 |
{ |
|
398 |
if (!this.commit()) return false; |
|
399 |
} |
|
400 |
|
|
401 |
return true; |
|
402 |
} |
|
403 |
catch (MySqlException myex) |
|
404 |
{ |
|
405 |
logger.ErrorFormat("MySQLエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), myex.Message, strSql); |
|
406 |
return false; |
|
407 |
} |
|
408 |
catch (Exception ex) |
|
409 |
{ |
|
410 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strSql); |
|
411 |
return false; |
|
412 |
} |
|
413 |
finally |
|
414 |
{ |
|
415 |
//切断 |
|
416 |
if (bconnect) this.close(); |
|
417 |
|
|
418 |
mycmd.Dispose(); |
|
419 |
mycmd = null; |
|
420 |
} |
|
421 |
} |
|
422 |
#endregion |
|
423 |
|
|
424 |
#region SetLockWaitime |
|
425 |
/// <summary> |
|
426 |
/// MySQL innodb_lock_wait_timeoutを設定 |
|
427 |
/// </summary> |
|
428 |
/// <param name="seconds">秒</param> |
|
429 |
/// <returns></returns> |
|
430 |
public bool SetLockWaitime(int seconds) |
|
431 |
{ |
|
432 |
MySqlCommand mycmd = new MySqlCommand(); |
|
433 |
string strSql = ""; |
|
434 |
|
|
435 |
try |
|
436 |
{ |
|
437 |
//ネクションセット |
|
438 |
mycmd.Connection = (MySqlConnection)m_connection; |
|
439 |
|
|
440 |
//SQLセット |
|
441 |
strSql = "set innodb_lock_wait_timeout=1"; |
|
442 |
mycmd.CommandText = strSql; |
|
443 |
|
|
444 |
//実行 |
|
445 |
mycmd.ExecuteNonQuery(); |
|
446 |
|
|
447 |
return true; |
|
448 |
} |
|
449 |
catch (MySqlException myex) |
|
450 |
{ |
|
451 |
logger.ErrorFormat("MySQLエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), myex.Message, strSql); |
|
452 |
return false; |
|
453 |
} |
|
454 |
catch (Exception ex) |
|
455 |
{ |
|
456 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strSql); |
|
457 |
return false; |
|
458 |
} |
|
459 |
finally |
|
460 |
{ |
|
461 |
mycmd.Dispose(); |
|
462 |
mycmd = null; |
|
463 |
} |
|
464 |
} |
|
465 |
|
|
466 |
} |
|
467 |
#endregion |
|
468 |
} |
branches/ddl/DataConert/DataConert/MySQLDB/IOAccess/IOConstructionLink.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Data; |
|
6 |
using System.Collections; |
|
7 |
|
|
8 |
using log4net; |
|
9 |
using MySql.Data.MySqlClient; // Data Provider for MySql |
|
10 |
|
|
11 |
using ProcessManagement.MySQLDB.MySql; |
|
12 |
using ProcessManagement.MySQLDB.Core; |
|
13 |
using ProcessManagement.DataModel; |
|
14 |
using ProcessManagement.Common; |
|
15 |
|
|
16 |
namespace ProcessManagement.MySQLDB.IOAccess |
|
17 |
{ |
|
18 |
/// <summary> |
|
19 |
/// 工事増減情報DBアクセス |
|
20 |
/// </summary> |
|
21 |
public class IOConstructionLink : MySqlProcess |
|
22 |
{ |
|
23 |
#region 定義部 |
|
24 |
/// <summary> |
|
25 |
/// log4netログを使用する |
|
26 |
/// </summary> |
|
27 |
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
|
28 |
#endregion |
|
29 |
|
|
30 |
#region 定数 |
|
31 |
/// <summary> |
|
32 |
/// 工事増減情報フィールド並び |
|
33 |
/// </summary> |
|
34 |
public enum TableColumn |
|
35 |
{ |
|
36 |
ConstructionCode = 0, |
|
37 |
FluctuationCode, |
|
38 |
LinkType, |
|
39 |
EntryDate, |
|
40 |
UpdateDate, |
|
41 |
} |
|
42 |
|
|
43 |
#endregion |
|
44 |
|
|
45 |
#region プロパティ |
|
46 |
#endregion |
|
47 |
|
|
48 |
#region コンストラクタ |
|
49 |
/// <summary> |
|
50 |
/// コンストラクタ |
|
51 |
/// </summary> |
|
52 |
/// <param name="ConnectionString"></param> |
|
53 |
public IOConstructionLink() |
|
54 |
: base(DBCommonForMySQL.Instance.DBConnectString) |
|
55 |
{ |
|
56 |
} |
|
57 |
|
|
58 |
#endregion |
|
59 |
|
|
60 |
#region SELECT SQL作成 |
|
61 |
/// <summary> |
|
62 |
/// SQL作成 |
|
63 |
/// </summary> |
|
64 |
private string CreateSelectSQL() |
|
65 |
{ |
|
66 |
// SQL作成(DateTime型が変換できないのでCharに変換しておく) |
|
67 |
string strcmd = "SELECT"; |
|
68 |
strcmd += " ConstructionCode, FluctuationCode, LinkType"; |
|
69 |
strcmd += ", DATE_FORMAT(EntryDate, '%Y/%m/%d %H:%i:%s')"; |
|
70 |
strcmd += ", DATE_FORMAT(UpdateDate, '%Y/%m/%d %H:%i:%s')"; |
|
71 |
strcmd += " FROM ConstructionLink"; |
|
72 |
|
|
73 |
return strcmd; |
|
74 |
} |
|
75 |
#endregion |
|
76 |
|
|
77 |
#region 読込み処理(1件読込み) |
|
78 |
/// <summary> |
|
79 |
/// 工事増減情報検索(1件読込み) |
|
80 |
/// </summary> |
|
81 |
/// <param name="AddSQLString">検索条件SQL文字列</param> |
|
82 |
/// <param name="data">工事増減情報データ</param> |
|
83 |
/// <returns>true:成功 false:失敗</returns> |
|
84 |
public bool SelectAction(string AddSQLString, ref ConstructionLink data, bool bConnect = true) |
|
85 |
{ |
|
86 |
// インターフェース |
|
87 |
string strcmd = ""; |
|
88 |
ArrayList arData = new ArrayList(); |
|
89 |
|
|
90 |
try |
|
91 |
{ |
|
92 |
strcmd = CreateSelectSQL() + AddSQLString; |
|
93 |
|
|
94 |
// SQL実行 |
|
95 |
if (!ExecuteReader(strcmd, ref arData, bConnect)) return false; |
|
96 |
if (arData.Count == 0) return false; |
|
97 |
// データセット |
|
98 |
foreach (object[] objwrk in arData) |
|
99 |
{ |
|
100 |
ConstructionLink work = new ConstructionLink(); |
|
101 |
Reader2Struct(objwrk, ref data); |
|
102 |
break; |
|
103 |
} |
|
104 |
|
|
105 |
return true; |
|
106 |
} |
|
107 |
catch (Exception ex) |
|
108 |
{ |
|
109 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
110 |
return false; |
|
111 |
} |
|
112 |
} |
|
113 |
#endregion |
|
114 |
|
|
115 |
#region 読込み処理(複数件読込み) |
|
116 |
/// <summary> |
|
117 |
/// 工事増減情報検索(複数件読込み) |
|
118 |
/// </summary> |
|
119 |
/// <param name="AddSQLString">検索条件SQL文字列</param> |
|
120 |
/// <param name="data">工事増減情報データ</param> |
|
121 |
/// <returns>true:成功 false:失敗</returns> |
|
122 |
public bool SelectAction(string AddSQLString, ref List<ConstructionLink> data, bool bConnect = true) |
|
123 |
{ |
|
124 |
// インターフェース |
|
125 |
string strcmd = ""; |
|
126 |
ArrayList arData = new ArrayList(); |
|
127 |
|
|
128 |
try |
|
129 |
{ |
|
130 |
strcmd = CreateSelectSQL() + AddSQLString; |
|
131 |
|
|
132 |
// SQL実行 |
|
133 |
if (!ExecuteReader(strcmd, ref arData, bConnect)) return false; |
|
134 |
|
|
135 |
// データセット |
|
136 |
foreach (object[] objwrk in arData) |
|
137 |
{ |
|
138 |
ConstructionLink work = new ConstructionLink(); |
|
139 |
Reader2Struct(objwrk, ref work); |
|
140 |
data.Add(work); |
|
141 |
} |
|
142 |
|
|
143 |
return true; |
|
144 |
} |
|
145 |
catch (Exception ex) |
|
146 |
{ |
|
147 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
148 |
return false; |
|
149 |
} |
|
150 |
} |
|
151 |
#endregion |
|
152 |
|
|
153 |
#region 追加処理(1件追加) |
|
154 |
/// <summary> |
|
155 |
/// 工事増減情報追加(1件追加) |
|
156 |
/// </summary> |
|
157 |
/// <param name="data">工事増減情報データ</param> |
|
158 |
/// <returns>true:成功 false:失敗</returns> |
|
159 |
public bool InsertAction(ConstructionLink data, bool bConnect = true) |
|
160 |
{ |
|
161 |
string strcmd = ""; |
|
162 |
try |
|
163 |
{ |
|
164 |
|
|
165 |
strcmd = "INSERT INTO ConstructionLink"; |
|
166 |
strcmd += " (ConstructionCode,"; |
|
167 |
strcmd += " FluctuationCode,"; |
|
168 |
strcmd += " LinkType,"; |
|
169 |
strcmd += " EntryDate,"; |
|
170 |
strcmd += " UpdateDate)"; |
|
171 |
strcmd += " VALUES ("; |
|
172 |
|
|
173 |
strcmd += string.Format(" {0}", data.ConstructionCode); |
|
174 |
strcmd += string.Format(", {0}", data.FluctuationCode); |
|
175 |
strcmd += string.Format(", {0}", data.LinkType); |
|
176 |
|
|
177 |
strcmd += ", STR_TO_DATE(DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'%Y/%m/%d %H:%i:%s')"; |
|
178 |
strcmd += ", STR_TO_DATE(DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'%Y/%m/%d %H:%i:%s')"; |
|
179 |
strcmd = strcmd + ")"; |
|
180 |
|
|
181 |
if (!ExecuteNonQuery(strcmd, bConnect)) return false; |
|
182 |
|
|
183 |
return true; |
|
184 |
} |
|
185 |
catch (Exception ex) |
|
186 |
{ |
|
187 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
188 |
return false; |
|
189 |
} |
|
190 |
} |
|
191 |
#endregion |
|
192 |
|
|
193 |
#region 追加処理(複数件追加) |
|
194 |
/// <summary> |
|
195 |
/// 工事増減情報追加(複数件追加) |
|
196 |
/// </summary> |
|
197 |
/// <param name="data">工事増減情報データ</param> |
|
198 |
/// <returns>true:成功 false:失敗</returns> |
|
199 |
/// <summary> |
|
200 |
/// 工事増減情報追加 |
|
201 |
/// </summary> |
|
202 |
/// <param name="data">工事増減情報データ</param> |
|
203 |
/// <returns>true:成功 false:失敗</returns> |
|
204 |
public bool InsertAction(List<ConstructionLink> data, bool bConnect = true) |
|
205 |
{ |
|
206 |
string strcmd = ""; |
|
207 |
try |
|
208 |
{ |
|
209 |
|
|
210 |
foreach (ConstructionLink work in data) |
|
211 |
{ |
|
212 |
if (!InsertAction(work, bConnect)) return false; |
|
213 |
} |
|
214 |
return true; |
|
215 |
} |
|
216 |
catch (Exception ex) |
|
217 |
{ |
|
218 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
219 |
return false; |
|
220 |
} |
|
221 |
} |
|
222 |
#endregion |
|
223 |
|
|
224 |
#region 更新処理 |
|
225 |
/// <summary> |
|
226 |
/// 工事増減情報更新 |
|
227 |
/// </summary> |
|
228 |
/// <param name="AddSQLString">更新条件SQL文字列</param> |
|
229 |
/// <param name="data">工事増減情報データ</param> |
|
230 |
/// <returns>true:成功 false:失敗</returns> |
|
231 |
public bool UpdateAction(string AddSQLString, ConstructionLink data, bool bConnect = true) |
|
232 |
{ |
|
233 |
string strcmd = ""; |
|
234 |
try |
|
235 |
{ |
|
236 |
|
|
237 |
strcmd = "UPDATE ConstructionLink"; |
|
238 |
|
|
239 |
strcmd += " SET"; |
|
240 |
|
|
241 |
strcmd += string.Format(" ConstructionCode = {0}", data.ConstructionCode); |
|
242 |
strcmd += string.Format(", DetailNo = {0}", data.FluctuationCode); |
|
243 |
strcmd += string.Format(", LinkType = {0}", data.LinkType); |
|
244 |
|
|
245 |
strcmd += ", UpdateDate = STR_TO_DATE(DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'%Y/%m/%d %H:%i:%s')"; |
|
246 |
strcmd += AddSQLString; |
|
247 |
|
|
248 |
if (!ExecuteNonQuery(strcmd, bConnect)) return false; |
|
249 |
|
|
250 |
return true; |
|
251 |
} |
|
252 |
catch (Exception ex) |
|
253 |
{ |
|
254 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
255 |
return false; |
|
256 |
} |
|
257 |
} |
|
258 |
#endregion |
|
259 |
|
|
260 |
#region 削除処理 |
|
261 |
/// <summary> |
|
262 |
/// 工事増減情報削除 |
|
263 |
/// </summary> |
|
264 |
/// <param name="AddSQLString">削除条件SQL文字列</param> |
|
265 |
/// <param name="data">工事増減情報データ</param> |
|
266 |
/// <returns>true:成功 false:失敗</returns> |
|
267 |
public bool DeleteAction(string AddSQLString, bool bConnect = true) |
|
268 |
{ |
|
269 |
// インターフェース |
|
270 |
string strcmd = ""; |
|
271 |
try |
|
272 |
{ |
|
273 |
strcmd = string.Format("{0}{1}", "DELETE FROM ConstructionLink", AddSQLString); |
|
274 |
|
|
275 |
if (!ExecuteNonQuery(strcmd, bConnect)) return false; |
|
276 |
|
|
277 |
return true; |
|
278 |
} |
|
279 |
catch (Exception ex) |
|
280 |
{ |
|
281 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
282 |
return false; |
|
283 |
} |
|
284 |
} |
|
285 |
#endregion |
|
286 |
|
|
287 |
#region データセット処理 |
|
288 |
/// <summary> |
|
289 |
/// OracleDataReaderより構造体へセットする |
|
290 |
/// </summary> |
|
291 |
/// <param name="reader">OracleDataReader</param> |
|
292 |
/// <param name="wrk">構造体</param> |
|
293 |
public void Reader2Struct(object[] objwrk, ref ConstructionLink wrk) |
|
294 |
{ |
|
295 |
try |
|
296 |
{ |
|
297 |
// データ取得 |
|
298 |
wrk.ConstructionCode = int.Parse(objwrk[(int)TableColumn.ConstructionCode].ToString()); |
|
299 |
wrk.FluctuationCode = int.Parse(objwrk[(int)TableColumn.FluctuationCode].ToString()); |
|
300 |
wrk.LinkType = int.Parse(objwrk[(int)TableColumn.LinkType].ToString()); |
|
301 |
|
|
302 |
wrk.EntryDate = DateTime.Parse(objwrk[(int)TableColumn.EntryDate].ToString()); |
|
303 |
wrk.UpdateDate = DateTime.Parse(objwrk[(int)TableColumn.UpdateDate].ToString()); |
|
304 |
} |
|
305 |
catch (MySqlException myex) |
|
306 |
{ |
|
307 |
logger.ErrorFormat("MySQLエラー:{0}:{1}", CommonMotions.GetMethodName(2), myex.Message); |
|
308 |
} |
|
309 |
catch (Exception ex) |
|
310 |
{ |
|
311 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(2), ex.Message); |
|
312 |
} |
|
313 |
} |
|
314 |
|
|
315 |
|
|
316 |
#endregion |
|
317 |
|
|
318 |
#region 1項目更新処理(親コードでの更新) |
|
319 |
/// <summary> |
|
320 |
/// 1項目の更新を行う(親コードでの更新) |
|
321 |
/// </summary> |
|
322 |
/// <returns></returns> |
|
323 |
public bool UpdateFeild(int ConstructionCode, int FeildNo, object value, bool bConnect = true) |
|
324 |
{ |
|
325 |
string strcmd = ""; |
|
326 |
try |
|
327 |
{ |
|
328 |
strcmd = "UPDATE ConstructionLink"; |
|
329 |
|
|
330 |
strcmd += " SET"; |
|
331 |
switch (FeildNo) |
|
332 |
{ |
|
333 |
case (int)TableColumn.ConstructionCode: |
|
334 |
strcmd += string.Format(" ConstructionCode = {0}", ((int)value).ToString()); |
|
335 |
break; |
|
336 |
case (int)TableColumn.FluctuationCode: |
|
337 |
strcmd += string.Format(" FluctuationCode = {0}", ((int)value).ToString()); |
|
338 |
break; |
|
339 |
} |
|
340 |
|
|
341 |
strcmd += ", UpdateDate = STR_TO_DATE(DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'%Y/%m/%d %H:%i:%s')"; |
|
342 |
strcmd += CreatePrimarykeyString(ConstructionCode); |
|
343 |
|
|
344 |
if (!ExecuteNonQuery(strcmd, bConnect)) return false; |
|
345 |
|
|
346 |
return true; |
|
347 |
} |
|
348 |
catch (Exception ex) |
|
349 |
{ |
|
350 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
351 |
return false; |
|
352 |
} |
|
353 |
} |
|
354 |
#endregion |
|
355 |
|
|
356 |
#region 1項目更新処理(子コードでの更新) |
|
357 |
/// <summary> |
|
358 |
/// 1項目の更新を行う(子コードでの更新) |
|
359 |
/// </summary> |
|
360 |
/// <returns></returns> |
|
361 |
public bool UpdateFeild2(int FluctuationCode, int FeildNo, object value, bool bConnect = true) |
|
362 |
{ |
|
363 |
string strcmd = ""; |
|
364 |
try |
|
365 |
{ |
|
366 |
strcmd = "UPDATE ConstructionLink"; |
|
367 |
|
|
368 |
strcmd += " SET"; |
|
369 |
switch (FeildNo) |
|
370 |
{ |
|
371 |
case (int)TableColumn.ConstructionCode: |
|
372 |
strcmd += string.Format(" ConstructionCode = {0}", ((int)value).ToString()); |
|
373 |
break; |
|
374 |
case (int)TableColumn.FluctuationCode: |
|
375 |
strcmd += string.Format(" FluctuationCode = {0}", ((int)value).ToString()); |
|
376 |
break; |
|
377 |
} |
|
378 |
|
|
379 |
strcmd += ", UpdateDate = STR_TO_DATE(DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'%Y/%m/%d %H:%i:%s')"; |
|
380 |
strcmd += string.Format(" WHERE FluctuationCode = {0}", FluctuationCode); |
|
381 |
|
|
382 |
if (!ExecuteNonQuery(strcmd, bConnect)) return false; |
|
383 |
|
|
384 |
return true; |
|
385 |
} |
|
386 |
catch (Exception ex) |
|
387 |
{ |
|
388 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
389 |
return false; |
|
390 |
} |
|
391 |
} |
|
392 |
#endregion |
|
393 |
|
|
394 |
#region 検索の文字列を返す |
|
395 |
|
|
396 |
/// <summary> |
|
397 |
/// 主キー検索の文字列を返す |
|
398 |
/// </summary> |
|
399 |
/// <param name="ComponentCode"></param> |
|
400 |
/// <param name="DetailNo"></param> |
|
401 |
/// <returns></returns> |
|
402 |
public string CreatePrimarykeyString(int ConstructionCode, int FluctuationCode = 0) |
|
403 |
{ |
|
404 |
string strWork = ""; |
|
405 |
try |
|
406 |
{ |
|
407 |
strWork = string.Format(" Where ConstructionCode = {0}", ConstructionCode); |
|
408 |
if (FluctuationCode != 0) |
|
409 |
strWork += string.Format(" And FluctuationCode = {0}", FluctuationCode); |
|
410 |
} |
|
411 |
catch (Exception ex) |
|
412 |
{ |
|
413 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strWork); |
|
414 |
} |
|
415 |
|
|
416 |
return strWork; |
|
417 |
} |
|
418 |
#endregion |
|
419 |
|
|
420 |
} |
|
421 |
} |
branches/ddl/DataConert/DataConert/MySQLDB/IOAccess/IOBillingData.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Collections; |
|
6 |
|
|
7 |
using log4net; |
|
8 |
using MySql.Data.MySqlClient; |
|
9 |
|
|
10 |
using ProcessManagement.MySQLDB.MySql; |
|
11 |
using ProcessManagement.MySQLDB.Core; |
|
12 |
using ProcessManagement.DataModel; |
|
13 |
|
|
14 |
using ProcessManagement.Common; |
|
15 |
|
|
16 |
namespace ProcessManagement.MySQLDB.IOAccess |
|
17 |
{ |
|
18 |
/// <summary> |
|
19 |
/// 業者請求データアクセスクラス |
|
20 |
/// </summary> |
|
21 |
public class IOBillingData : MySqlProcess |
|
22 |
{ |
|
23 |
#region 定義部 |
|
24 |
/// <summary> |
|
25 |
/// log4netログを使用する |
|
26 |
/// </summary> |
|
27 |
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
|
28 |
#endregion |
|
29 |
|
|
30 |
#region 定数 |
|
31 |
/// <summary> |
|
32 |
/// フィールド並び |
|
33 |
/// </summary> |
|
34 |
public enum NameColumn |
|
35 |
{ |
|
36 |
CompanyCode = 0, |
|
37 |
TargetDate, |
|
38 |
SeqNo, |
|
39 |
BillPrice, |
|
40 |
EntryDate, |
|
41 |
UpdateDate, |
|
42 |
} |
|
43 |
#endregion |
|
44 |
|
|
45 |
#region コンストラクタ |
|
46 |
/// <summary> |
|
47 |
/// コンストラクタ |
|
48 |
/// </summary> |
|
49 |
/// <param name="ConnectionString"></param> |
|
50 |
public IOBillingData() |
|
51 |
: base(DBCommonForMySQL.Instance.DBConnectString) |
|
52 |
{ |
|
53 |
} |
|
54 |
|
|
55 |
#endregion |
|
56 |
|
|
57 |
|
|
58 |
#region パブリックメソッド |
|
59 |
/// <summary> |
|
60 |
/// データ検索 |
|
61 |
/// </summary> |
|
62 |
/// <param name="AddSQLString"></param> |
|
63 |
/// <param name="data"></param> |
|
64 |
/// <param name="bConnect"></param> |
|
65 |
/// <returns></returns> |
|
66 |
public bool SelectAction(string AddSQLString, ref List<BillingData> data, bool bConnect = true) |
|
67 |
{ |
|
68 |
// インターフェース |
|
69 |
string strcmd = ""; |
|
70 |
ArrayList arData = new ArrayList(); |
|
71 |
|
|
72 |
try |
|
73 |
{ |
|
74 |
// SQL作成(DateTime型が変換できないのでCharに変換しておく) |
|
75 |
strcmd = "SELECT"; |
|
76 |
strcmd += " CompanyCode,TargetDate,SeqNo,BillPrice"; |
|
77 |
strcmd += " ,DATE_FORMAT(EntryDate, '%Y/%m/%d %H:%i:%s')"; |
|
78 |
strcmd += " ,DATE_FORMAT(UpdateDate, '%Y/%m/%d %H:%i:%s')"; |
|
79 |
strcmd += " FROM BillingData"; |
|
80 |
strcmd += AddSQLString; |
|
81 |
|
|
82 |
// SQL実行 |
|
83 |
if (!ExecuteReader(strcmd, ref arData, bConnect)) return false; |
|
84 |
|
|
85 |
// データセット |
|
86 |
foreach (object[] objwrk in arData) |
|
87 |
{ |
|
88 |
BillingData work = new BillingData(); |
|
89 |
Reader2Struct(objwrk, ref work); |
|
90 |
data.Add(work); |
|
91 |
} |
|
92 |
|
|
93 |
return true; |
|
94 |
} |
|
95 |
catch (Exception ex) |
|
96 |
{ |
|
97 |
logger.ErrorFormat("システムエラー::{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
98 |
return false; |
|
99 |
} |
|
100 |
|
|
101 |
} |
|
102 |
|
|
103 |
/// <summary> |
|
104 |
/// 新規登録 |
|
105 |
/// </summary> |
|
106 |
/// <param name="data"></param> |
|
107 |
/// <param name="bConnect"></param> |
|
108 |
/// <returns></returns> |
|
109 |
public bool InsertAction(List<BillingData> data, bool bConnect = true) |
|
110 |
{ |
|
111 |
string strcmd = ""; |
|
112 |
try |
|
113 |
{ |
|
114 |
|
|
115 |
foreach (BillingData work in data) |
|
116 |
{ |
|
117 |
strcmd = "INSERT INTO BillingData"; |
|
118 |
|
|
119 |
strcmd += " VALUES ("; |
|
120 |
|
|
121 |
strcmd += string.Format(" {0}", work.CompanyCode.ToString()); |
|
122 |
strcmd += string.Format(", {0}", work.TargetDate.ToString()); |
|
123 |
strcmd += string.Format(", {0}", work.SeqNo.ToString()); |
|
124 |
strcmd += string.Format(", {0}", work.BillPrice.ToString()); |
|
125 |
|
|
126 |
strcmd += ", DATE_FORMAT(DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'%Y/%m/%d %H:%i:%s')"; |
|
127 |
strcmd += ", DATE_FORMAT(DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'%Y/%m/%d %H:%i:%s')"; |
|
128 |
strcmd = strcmd + ")"; |
|
129 |
|
|
130 |
if (!ExecuteNonQuery(strcmd, bConnect)) return false; |
|
131 |
} |
|
132 |
return true; |
|
133 |
} |
|
134 |
catch (Exception ex) |
|
135 |
{ |
|
136 |
logger.ErrorFormat("システムエラー::{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
137 |
return false; |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
/// <summary> |
|
142 |
/// 更新登録 |
|
143 |
/// </summary> |
|
144 |
/// <param name="AddSQLString"></param> |
|
145 |
/// <param name="data"></param> |
|
146 |
/// <param name="bConnect"></param> |
|
147 |
/// <returns></returns> |
|
148 |
public bool UpdateAction(string AddSQLString, BillingData data, bool bConnect = true) |
|
149 |
{ |
|
150 |
string strcmd = ""; |
|
151 |
try |
|
152 |
{ |
|
153 |
|
|
154 |
strcmd = "UPDATE BillingData"; |
|
155 |
|
|
156 |
strcmd += " SET"; |
|
157 |
|
|
158 |
strcmd += string.Format(" BillPrice = {0}", data.BillPrice.ToString()); |
|
159 |
|
|
160 |
strcmd += ", UpdateDate = DATE_FORMAT(DATE_FORMAT(NOW(),'%Y/%m/%d %H:%i:%s'),'%Y/%m/%d %H:%i:%s')"; |
|
161 |
strcmd += AddSQLString; |
|
162 |
|
|
163 |
if (!ExecuteNonQuery(strcmd, bConnect)) return false; |
|
164 |
|
|
165 |
return true; |
|
166 |
} |
|
167 |
catch (Exception ex) |
|
168 |
{ |
|
169 |
logger.ErrorFormat("システムエラー::{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
170 |
return false; |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
/// <summary> |
|
175 |
/// 削除 |
|
176 |
/// </summary> |
|
177 |
/// <param name="AddSQLString"></param> |
|
178 |
/// <param name="bConnect"></param> |
|
179 |
/// <returns></returns> |
|
180 |
public bool DeleteAction(string AddSQLString, bool bConnect = true) |
|
181 |
{ |
|
182 |
// インターフェース |
|
183 |
string strcmd = ""; |
|
184 |
try |
|
185 |
{ |
|
186 |
strcmd = string.Format("{0}{1}", "DELETE FROM BillingData", AddSQLString); |
|
187 |
|
|
188 |
if (!ExecuteNonQuery(strcmd, bConnect)) return false; |
|
189 |
|
|
190 |
return true; |
|
191 |
} |
|
192 |
catch (Exception ex) |
|
193 |
{ |
|
194 |
logger.ErrorFormat("システムエラー::{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
195 |
return false; |
|
196 |
} |
|
197 |
} |
|
198 |
|
|
199 |
/// <summary> |
|
200 |
/// 構造体へセット |
|
201 |
/// </summary> |
|
202 |
/// <param name="objwrk"></param> |
|
203 |
/// <param name="wrk"></param> |
|
204 |
public void Reader2Struct(object[] objwrk, ref BillingData wrk) |
|
205 |
{ |
|
206 |
try |
|
207 |
{ |
|
208 |
// データ取得 |
|
209 |
wrk.CompanyCode = int.Parse(objwrk[(int)NameColumn.CompanyCode].ToString()); |
|
210 |
wrk.TargetDate = int.Parse(objwrk[(int)NameColumn.TargetDate].ToString()); |
|
211 |
wrk.SeqNo = int.Parse(objwrk[(int)NameColumn.SeqNo].ToString()); |
|
212 |
wrk.BillPrice = long.Parse(objwrk[(int)NameColumn.BillPrice].ToString()); |
|
213 |
|
|
214 |
wrk.EntryDate = DateTime.Parse(objwrk[(int)NameColumn.EntryDate].ToString()); |
|
215 |
wrk.UpdateDate = DateTime.Parse(objwrk[(int)NameColumn.UpdateDate].ToString()); |
|
216 |
} |
|
217 |
catch (MySqlException oraex) |
|
218 |
{ |
|
219 |
logger.ErrorFormat("MySQLエラー:{0}:{1}", CommonMotions.GetMethodName(), oraex.Message); |
|
220 |
} |
|
221 |
catch (Exception ex) |
|
222 |
{ |
|
223 |
logger.ErrorFormat("システムエラー::{0}:{1}:{2}", CommonMotions.GetMethodName(), ex.Message); |
|
224 |
} |
|
225 |
} |
|
226 |
|
|
227 |
|
|
228 |
#endregion |
|
229 |
|
|
230 |
|
|
231 |
#region パブリックメソッド(特殊処理) |
|
232 |
|
|
233 |
/// <summary> |
|
234 |
/// 主キー検索の文字列を返す |
|
235 |
/// </summary> |
|
236 |
/// <param name="BusinessTypeCode"></param> |
|
237 |
/// <returns>Where文字列</returns> |
|
238 |
public string CreatePrimarykeyString(int CompanyCode, int TargetDate, int SeqNo) |
|
239 |
{ |
|
240 |
string strWork = string.Empty; |
|
241 |
try |
|
242 |
{ |
|
243 |
strWork = string.Format(" Where CompanyCode = {0} and TargetDate = {1} and SeqNo = {2}", CompanyCode, TargetDate, SeqNo); |
|
244 |
|
|
245 |
} |
|
246 |
catch (Exception ex) |
|
247 |
{ |
|
248 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strWork); |
|
249 |
} |
|
250 |
|
|
251 |
return strWork; |
|
252 |
} |
|
253 |
|
|
254 |
/// <summary> |
|
255 |
/// 行ロック |
|
256 |
/// </summary> |
|
257 |
/// <param name="MaterialItemCode"></param> |
|
258 |
/// <param name="bConnect"></param> |
|
259 |
/// <returns></returns> |
|
260 |
public bool RowLock(int CompanyCode, int TargetDate, int SeqNo, bool bConnect = true) |
|
261 |
{ |
|
262 |
|
|
263 |
//インターフェース |
|
264 |
string strcmd = ""; |
|
265 |
ArrayList arData = new ArrayList(); |
|
266 |
|
|
267 |
try |
|
268 |
{ |
|
269 |
strcmd = string.Format("select * from BillingData where CompanyCode = {0} and TargetDate = {1} and SeqNo = {2} for update;", |
|
270 |
CompanyCode, TargetDate, SeqNo); |
|
271 |
|
|
272 |
// SQL実行 |
|
273 |
if (!ExecuteReader(strcmd, ref arData, bConnect)) return false; |
|
274 |
|
|
275 |
return true; |
|
276 |
} |
|
277 |
catch (Exception ex) |
|
278 |
{ |
|
279 |
logger.ErrorFormat("システムエラー::{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
280 |
return false; |
|
281 |
} |
|
282 |
|
|
283 |
|
|
284 |
} |
|
285 |
|
|
286 |
|
|
287 |
#endregion |
|
288 |
|
|
289 |
} |
|
290 |
} |
branches/ddl/DataConert/DataConert/MySQLDB/IOAccess/IOOrdersPriceData.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Data; |
|
6 |
using System.Collections; |
|
7 |
|
|
8 |
using log4net; |
|
9 |
using MySql.Data.MySqlClient; // Data Provider for MySql |
|
10 |
|
|
11 |
using ProcessManagement.MySQLDB.MySql; |
|
12 |
using ProcessManagement.MySQLDB.Core; |
|
13 |
using ProcessManagement.DataModel; |
|
14 |
using ProcessManagement.Common; |
|
15 |
|
|
16 |
namespace ProcessManagement.MySQLDB.IOAccess |
|
17 |
{ |
|
18 |
/// <summary> |
|
19 |
/// 受注金額データDBアクセス |
|
20 |
/// </summary> |
|
21 |
public class IOOrdersPriceData : MySqlProcess |
|
22 |
{ |
|
23 |
#region 定義部 |
|
24 |
/// <summary> |
|
25 |
/// log4netログを使用する |
|
26 |
/// </summary> |
|
27 |
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
|
28 |
#endregion |
|
29 |
|
|
30 |
#region 定数 |
|
31 |
/// <summary> |
|
32 |
/// 担当者毎経費データフィールド並び |
|
33 |
/// </summary> |
|
34 |
public enum TableColumn |
|
35 |
{ |
|
36 |
ConstructionCode = 0, // 工事コード |
|
37 |
ChangeNo, // 変更番号 |
|
38 |
ChangeDate, // 変更日 |
|
39 |
ChangePersonCode, // 変更者コード |
|
40 |
ChangePersonName, // 変更者名 |
|
41 |
BeforeValue, // 変更前税抜受注金額 |
|
42 |
BeforeValueInTax, // 〃 税込受注金額 |
|
43 |
AfterValue, // 変更後税抜受注金額 |
|
44 |
AfterValueInTax, // 〃 税込受注金額 |
|
45 |
ChangeComment, // 変更理由 |
|
46 |
|
|
47 |
EntryDate, |
|
48 |
UpdateDate, |
|
49 |
} |
|
50 |
#endregion |
|
51 |
|
|
52 |
#region コンストラクタ |
|
53 |
/// <summary> |
|
54 |
/// コンストラクタ |
|
55 |
/// </summary> |
|
56 |
/// <param name="ConnectionString"></param> |
|
57 |
public IOOrdersPriceData() |
|
58 |
: base(DBCommonForMySQL.Instance.DBConnectString) |
|
59 |
{ |
|
60 |
} |
|
61 |
|
|
62 |
#endregion |
|
63 |
|
|
64 |
#region SQL作成 |
|
65 |
/// <summary> |
|
66 |
/// SQL作成 |
|
67 |
/// </summary> |
|
68 |
private string CreateSelectSQL() |
|
69 |
{ |
|
70 |
// SQL作成 |
|
71 |
string strcmd = "SELECT"; |
|
72 |
|
|
73 |
strcmd += " ConstructionCode"; // 工事コード |
|
74 |
strcmd += " ,ChangeNo"; // 変更番号 |
|
75 |
strcmd += " ,DATE_FORMAT(ChangeDate, '%Y/%m/%d')"; // 変更日 |
|
76 |
strcmd += " ,ChangePersonCode"; // 変更者コード |
|
77 |
strcmd += " ,ChangePersonName"; // 変更者名 |
|
78 |
strcmd += " ,BeforeValue"; // 変更前税抜受注金額 |
|
79 |
strcmd += " ,BeforeValueInTax"; // 〃 税込受注金額 |
|
80 |
strcmd += " ,AfterValue"; // 変更後税抜受注金額 |
|
81 |
strcmd += " ,AfterValueInTax"; // 〃 税込受注金額 |
|
82 |
strcmd += " ,ChangeComment"; // 変更理由 |
|
83 |
|
|
84 |
strcmd += ", DATE_FORMAT(EntryDate, '%Y/%m/%d %H:%i:%s')"; |
|
85 |
strcmd += ", DATE_FORMAT(UpdateDate, '%Y/%m/%d %H:%i:%s')"; |
|
86 |
strcmd += " FROM OrdersPriceData"; |
|
87 |
|
|
88 |
return strcmd; |
|
89 |
} |
|
90 |
#endregion |
|
91 |
|
|
92 |
#region 複数読込み処理 |
|
93 |
public bool SelectAction(string AddSQLString, ref List<OrdersPriceData> data, bool bConnect = true) |
|
94 |
{ |
|
95 |
// インターフェース |
|
96 |
string strcmd = ""; |
|
97 |
ArrayList arData = new ArrayList(); |
|
98 |
|
|
99 |
try |
|
100 |
{ |
|
101 |
// SQL作成 |
|
102 |
strcmd = CreateSelectSQL() + AddSQLString; |
|
103 |
|
|
104 |
// SQL実行 |
|
105 |
if (!ExecuteReader(strcmd, ref arData, bConnect)) return false; |
|
106 |
|
|
107 |
// データセット |
|
108 |
foreach (object[] objwrk in arData) |
|
109 |
{ |
|
110 |
OrdersPriceData work = new OrdersPriceData(); |
|
111 |
Reader2Struct(objwrk, ref work); |
|
112 |
data.Add(work); |
|
113 |
} |
|
114 |
|
|
115 |
return true; |
|
116 |
} |
|
117 |
catch (Exception ex) |
|
118 |
{ |
|
119 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", CommonMotions.GetMethodName(2), ex.Message, strcmd); |
|
120 |
return false; |
|
121 |
} |
|
122 |
} |
|
123 |
#endregion |
|
124 |
|
|
125 |
#region 1件読込み処理 |
|
126 |
public bool SelectAction(string AddSQLString, ref OrdersPriceData data, bool bConnect = true) |
他の形式にエクスポート: Unified diff