h-you / trunk / src / ProcessManagement / ProcessManagement / Common / CommonMotions.cs @ 4
履歴 | 表示 | アノテート | ダウンロード (76.1 KB)
| 1 |
using System; |
|---|---|
| 2 |
using System.Collections.Generic; |
| 3 |
using System.Linq; |
| 4 |
using System.Text; |
| 5 |
using System.Diagnostics; |
| 6 |
using System.Windows.Forms; |
| 7 |
using System.Drawing; |
| 8 |
using System.IO; |
| 9 |
using System.Text.RegularExpressions; |
| 10 |
using System.Data; |
| 11 |
using System.Security.Cryptography; |
| 12 |
using System.Globalization; |
| 13 |
using System.Runtime.InteropServices; |
| 14 |
using System.Collections; |
| 15 |
|
| 16 |
using Microsoft.VisualBasic; //for StrConv |
| 17 |
|
| 18 |
using log4net; |
| 19 |
using log4net.Appender; |
| 20 |
using log4net.Repository.Hierarchy; |
| 21 |
|
| 22 |
using ProcessManagement.DB.Core; |
| 23 |
using ProcessManagement.DataModel; |
| 24 |
using ProcessManagement.DB.IOAccess; |
| 25 |
using ProcessManagement.Forms.CustomControls; |
| 26 |
|
| 27 |
namespace ProcessManagement.Common |
| 28 |
{
|
| 29 |
/// <summary> |
| 30 |
/// 工事管理システム共通クラス |
| 31 |
/// </summary> |
| 32 |
public static class CommonMotions |
| 33 |
{
|
| 34 |
#region 定義部 |
| 35 |
/// <summary> |
| 36 |
/// log4netログを使用する |
| 37 |
/// </summary> |
| 38 |
private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); |
| 39 |
#endregion |
| 40 |
|
| 41 |
#region 変数 |
| 42 |
/// <summary> |
| 43 |
/// 定義ファイル読込クラス定義 |
| 44 |
/// </summary> |
| 45 |
private static DefinitionFileRead m_dfr_model = null; |
| 46 |
|
| 47 |
/// <summary> |
| 48 |
/// 管理マスタデータ保持領域 |
| 49 |
/// </summary> |
| 50 |
private static SystemMaster m_systemMaster = new SystemMaster(); |
| 51 |
|
| 52 |
/// <summary> |
| 53 |
/// ログインユーザーデータ |
| 54 |
/// </summary> |
| 55 |
private static PersonInChargeMaster m_LoginUserData = new PersonInChargeMaster(); |
| 56 |
|
| 57 |
/// <summary> |
| 58 |
/// 建築工事費の構成 |
| 59 |
/// </summary> |
| 60 |
//private static Dictionary<int, string> m_StructureTypeName = new Dictionary<int, string>(); |
| 61 |
|
| 62 |
/// <summary> |
| 63 |
/// 製品ファイルバージョン格納エリア |
| 64 |
/// </summary> |
| 65 |
private static FileVersionInfo m_ProductVersionInfo = FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location); |
| 66 |
|
| 67 |
#endregion |
| 68 |
|
| 69 |
#region コンストラクタ |
| 70 |
/// <summary> |
| 71 |
/// 何もしない |
| 72 |
/// </summary> |
| 73 |
#endregion |
| 74 |
|
| 75 |
#region プロパティ |
| 76 |
/// <summary> |
| 77 |
/// 本稼働フラグ |
| 78 |
/// </summary> |
| 79 |
public static bool ProductionExecution |
| 80 |
{
|
| 81 |
get { return CommonDefine.m_ProductionExecution; }
|
| 82 |
} |
| 83 |
/// <summary> |
| 84 |
/// 定義ファイル読込クラス |
| 85 |
/// </summary> |
| 86 |
public static DefinitionFileRead DFRModel |
| 87 |
{
|
| 88 |
get { return m_dfr_model; }
|
| 89 |
} |
| 90 |
|
| 91 |
/// <summary> |
| 92 |
/// 管理マスタデータ |
| 93 |
/// </summary> |
| 94 |
public static SystemMaster SystemMasterData |
| 95 |
{
|
| 96 |
get { return m_systemMaster; }
|
| 97 |
set { m_systemMaster = value; }
|
| 98 |
} |
| 99 |
|
| 100 |
/// <summary> |
| 101 |
/// ログインユーザーデータ |
| 102 |
/// </summary> |
| 103 |
public static PersonInChargeMaster LoginUserData |
| 104 |
{
|
| 105 |
get { return m_LoginUserData; }
|
| 106 |
set { m_LoginUserData = value; }
|
| 107 |
} |
| 108 |
|
| 109 |
/// <summary> |
| 110 |
/// 構成マスタ(大項目マスタ) |
| 111 |
/// </summary> |
| 112 |
//public static Dictionary<int, string> StructureTypeName |
| 113 |
//{
|
| 114 |
// get { return m_StructureTypeName; }
|
| 115 |
// set { m_StructureTypeName = value; }
|
| 116 |
//} |
| 117 |
|
| 118 |
/// <summary> |
| 119 |
/// 製品ファイルバージョン格納エリア |
| 120 |
/// </summary> |
| 121 |
public static FileVersionInfo ProductVersionInfo |
| 122 |
{
|
| 123 |
get { return m_ProductVersionInfo; }
|
| 124 |
} |
| 125 |
|
| 126 |
#endregion |
| 127 |
|
| 128 |
#region 初期化 |
| 129 |
|
| 130 |
/// <summary> |
| 131 |
/// 初期化 |
| 132 |
/// </summary> |
| 133 |
public static void Initialize() |
| 134 |
{
|
| 135 |
try |
| 136 |
{
|
| 137 |
// 定義ファイル読込 |
| 138 |
DefinitionFileInit(); |
| 139 |
|
| 140 |
// 他共通クラス初期化 |
| 141 |
DBCommon.Instance.Initialize(); |
| 142 |
|
| 143 |
// 管理マスタ取得 |
| 144 |
SetSystemMaster(); |
| 145 |
|
| 146 |
} |
| 147 |
catch (Exception ex) |
| 148 |
{
|
| 149 |
logger.ErrorFormat("初期化エラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 150 |
} |
| 151 |
} |
| 152 |
#endregion |
| 153 |
|
| 154 |
#region プライベートメソッド |
| 155 |
/// <summary> |
| 156 |
/// 定義ファイル読込 |
| 157 |
/// </summary> |
| 158 |
private static void DefinitionFileInit() |
| 159 |
{
|
| 160 |
try |
| 161 |
{
|
| 162 |
//定義ファイル読込 |
| 163 |
System.IO.FileStream fs = new System.IO.FileStream(CommonDefine.s_DefinitionFileName, System.IO.FileMode.Open); |
| 164 |
System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(DefinitionFileRead)); |
| 165 |
m_dfr_model = (DefinitionFileRead)serializer.Deserialize(fs); |
| 166 |
} |
| 167 |
catch (Exception ex) |
| 168 |
{
|
| 169 |
logger.ErrorFormat("定義ファイル読込エラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
#endregion |
| 174 |
|
| 175 |
#region 管理マスタ取得 |
| 176 |
/// <summary> |
| 177 |
/// 管理マスタ取得 |
| 178 |
/// </summary> |
| 179 |
public static bool SetSystemMaster() |
| 180 |
{
|
| 181 |
// 管理マスタクラス |
| 182 |
IOMSystem ocDB = new IOMSystem(); |
| 183 |
try |
| 184 |
{
|
| 185 |
// 管理マスタ取得 |
| 186 |
// 1レコードだけなので取り出す |
| 187 |
string strSQL = " Where SystemCode = 1"; |
| 188 |
if (!ocDB.SelectAction(strSQL, ref m_systemMaster)) return false; |
| 189 |
|
| 190 |
return true; |
| 191 |
} |
| 192 |
catch (Exception ex) |
| 193 |
{
|
| 194 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 195 |
return false; |
| 196 |
} |
| 197 |
finally |
| 198 |
{
|
| 199 |
ocDB.close(); |
| 200 |
ocDB = null; |
| 201 |
} |
| 202 |
} |
| 203 |
#endregion |
| 204 |
|
| 205 |
#region メソッド名を取得する |
| 206 |
/// <summary> |
| 207 |
/// メソッド名を取得する |
| 208 |
/// </summary> |
| 209 |
/// <param name="StackCnt"></param> |
| 210 |
/// <returns></returns> |
| 211 |
public static string GetMethodName(int stackCnt = 1) |
| 212 |
{
|
| 213 |
try |
| 214 |
{
|
| 215 |
StringBuilder sb = new StringBuilder(); |
| 216 |
|
| 217 |
// 一つ前のスタック情報 |
| 218 |
StackFrame stackFrame = new StackFrame(stackCnt); |
| 219 |
|
| 220 |
// 呼び出し元メソッドの情報出力 |
| 221 |
System.Reflection.MethodBase method = stackFrame.GetMethod(); |
| 222 |
|
| 223 |
// Method取得失敗は戻る |
| 224 |
if (method == null) return string.Empty; |
| 225 |
|
| 226 |
// 正しく取得できているかの判定 |
| 227 |
if (method.DeclaringType != null && !string.IsNullOrEmpty(method.DeclaringType.Name)) |
| 228 |
{
|
| 229 |
// 型名 |
| 230 |
sb.AppendFormat("[TYPE]{0}", method.DeclaringType.Name);
|
| 231 |
} |
| 232 |
|
| 233 |
if (!string.IsNullOrEmpty(method.Name)) |
| 234 |
{
|
| 235 |
// 編集済みの場合は区切りを入れる |
| 236 |
if (0 < sb.Length) sb.Append('/');
|
| 237 |
|
| 238 |
// メソッド名 |
| 239 |
sb.AppendFormat("[METHOD]{0}", method.Name);
|
| 240 |
} |
| 241 |
return sb.ToString(); |
| 242 |
} |
| 243 |
catch (Exception ex) |
| 244 |
{
|
| 245 |
logger.ErrorFormat(ex.Message); |
| 246 |
} |
| 247 |
return string.Empty; |
| 248 |
} |
| 249 |
#endregion |
| 250 |
|
| 251 |
#region 日付より年を取得する |
| 252 |
/// <summary> |
| 253 |
/// 日付より年を取得する |
| 254 |
/// </summary> |
| 255 |
/// <returns></returns> |
| 256 |
public static int DateToPeriodYear(DateTime TargetDate) |
| 257 |
{
|
| 258 |
try |
| 259 |
{
|
| 260 |
// 今の年を取得する |
| 261 |
int iYear = DateTime.Now.Year; |
| 262 |
// 今年の期首日を取得する |
| 263 |
DateTime BeginninDate = DateTime.Parse(iYear.ToString() + "/" + CommonMotions.SystemMasterData.BusinessBeginningDate); |
| 264 |
// 日付を今年の期首日と比較して小さい場合は今の年より-1して期首年を求める |
| 265 |
if (TargetDate.Date < BeginninDate.Date) |
| 266 |
--iYear; |
| 267 |
|
| 268 |
return iYear; |
| 269 |
} |
| 270 |
catch (Exception ex) |
| 271 |
{
|
| 272 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 273 |
return 0; |
| 274 |
} |
| 275 |
} |
| 276 |
#endregion |
| 277 |
|
| 278 |
#region 期数から期の年を取得する |
| 279 |
/// <summary> |
| 280 |
/// 期数から期の年を取得する |
| 281 |
/// </summary> |
| 282 |
/// <param name="PeriodCount"></param> |
| 283 |
/// <returns></returns> |
| 284 |
public static int PeriodCountToYear(int PeriodCount) |
| 285 |
{
|
| 286 |
try |
| 287 |
{
|
| 288 |
// 今の年を取得する |
| 289 |
int iYear = DateTime.Now.Year; |
| 290 |
// 今年の期首日を取得する |
| 291 |
DateTime BeginninDate = DateTime.Parse(iYear.ToString() + "/" + CommonMotions.SystemMasterData.BusinessBeginningDate); |
| 292 |
// 今日を今年の期首日と比較して小さい場合は今の年より-1して期首年を求める |
| 293 |
if (DateTime.Now.Date < BeginninDate.Date) |
| 294 |
--iYear; |
| 295 |
|
| 296 |
// 管理マスタの期数と比較して年を計算する |
| 297 |
if (PeriodCount < CommonMotions.SystemMasterData.BusinessPeriod) |
| 298 |
{
|
| 299 |
iYear -= (CommonMotions.SystemMasterData.BusinessPeriod - PeriodCount); |
| 300 |
} |
| 301 |
else if (PeriodCount > CommonMotions.SystemMasterData.BusinessPeriod) |
| 302 |
{
|
| 303 |
iYear += (PeriodCount - CommonMotions.SystemMasterData.BusinessPeriod); |
| 304 |
} |
| 305 |
|
| 306 |
return iYear; |
| 307 |
} |
| 308 |
catch (Exception ex) |
| 309 |
{
|
| 310 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 311 |
return 0; |
| 312 |
} |
| 313 |
} |
| 314 |
#endregion |
| 315 |
|
| 316 |
#region 期の最大・最少を取得する |
| 317 |
/// <summary> |
| 318 |
/// 期の最大・最少を取得する |
| 319 |
/// </summary> |
| 320 |
/// <param name="StartDate"></param> |
| 321 |
/// <returns></returns> |
| 322 |
public static void GetPeriodYear(ref int min, ref int max) |
| 323 |
{
|
| 324 |
IOConstructionBaseInfo cbiDB = new IOConstructionBaseInfo(); |
| 325 |
try |
| 326 |
{
|
| 327 |
int StatusCode = CommonDefine.ProjectsStatus.First(x => x.Value.Equals("非 受 注")).Key;
|
| 328 |
|
| 329 |
string strSQL = "SELECT A.CONSTRUCTIONPERIOD FROM CONSTRUCTIONBASEINFO A"; |
| 330 |
strSQL += string.Format(" WHERE A.CONSTRUCTIONSTATUSFLG <> {0}", StatusCode);
|
| 331 |
strSQL += " GROUP BY A.CONSTRUCTIONPERIOD"; |
| 332 |
|
| 333 |
ArrayList arList = new ArrayList(); |
| 334 |
if (!cbiDB.ExecuteReader(strSQL, ref arList)) return; |
| 335 |
|
| 336 |
int[] iNumber = new int[arList.Count]; |
| 337 |
int i = 0; |
| 338 |
foreach (object[] wrkobj in arList) |
| 339 |
{
|
| 340 |
iNumber[i++] = CommonMotions.cnvInt(wrkobj[0].ToString()); |
| 341 |
} |
| 342 |
min = iNumber.Min(); |
| 343 |
max = iNumber.Max(); |
| 344 |
} |
| 345 |
catch (Exception ex) |
| 346 |
{
|
| 347 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 348 |
} |
| 349 |
finally |
| 350 |
{
|
| 351 |
cbiDB.close(); cbiDB = null; |
| 352 |
} |
| 353 |
} |
| 354 |
#endregion |
| 355 |
|
| 356 |
#region データ変換メソッド |
| 357 |
#region 西暦を和暦に変換する |
| 358 |
/// <summary> |
| 359 |
/// 西暦を和暦に変換する |
| 360 |
/// </summary> |
| 361 |
/// <returns></returns> |
| 362 |
public static string cnvJapaneseCalendar(DateTime Terget) |
| 363 |
{
|
| 364 |
try |
| 365 |
{
|
| 366 |
CultureInfo culture = new CultureInfo("ja-JP", true);
|
| 367 |
culture.DateTimeFormat.Calendar = new JapaneseCalendar(); |
| 368 |
|
| 369 |
return Terget.ToString("ggyy年M月d日", culture);
|
| 370 |
} |
| 371 |
catch (Exception ex) |
| 372 |
{
|
| 373 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 374 |
return string.Empty; |
| 375 |
} |
| 376 |
} |
| 377 |
#endregion |
| 378 |
|
| 379 |
#region Int値より文字列に変化して指定位置に指定文字を入れる。(工事番号編集) |
| 380 |
/// <summary> |
| 381 |
/// Int値より文字列に変化して指定位置に指定文字を入れる。 |
| 382 |
/// </summary> |
| 383 |
/// <param name="strCode"></param> |
| 384 |
/// <returns></returns> |
| 385 |
public static string cnvStringCodeFromInt(int IntCode, string strCode, int iPoint) |
| 386 |
{
|
| 387 |
try |
| 388 |
{
|
| 389 |
// 文字列変換 |
| 390 |
string strWork = IntCode.ToString(); |
| 391 |
// 指定位置が文字列長を超えている場合はエラー |
| 392 |
if (strWork.Length <= iPoint) return string.Empty; |
| 393 |
// 文字挿入 |
| 394 |
strWork = strWork.Substring(0, iPoint) + strCode + strWork.Substring(iPoint); |
| 395 |
return strWork; |
| 396 |
} |
| 397 |
catch (System.Exception ex) |
| 398 |
{
|
| 399 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 400 |
return string.Empty; |
| 401 |
} |
| 402 |
} |
| 403 |
#endregion |
| 404 |
|
| 405 |
#region 文字列より指定文字を除去してInt値に変換する |
| 406 |
/// <summary> |
| 407 |
/// 文字列より指定文字を除去してInt値に変換する |
| 408 |
/// </summary> |
| 409 |
/// <param name="strCode"></param> |
| 410 |
/// <returns></returns> |
| 411 |
public static int cnvIntFromStringCode(string strCode, string strRemove) |
| 412 |
{
|
| 413 |
try |
| 414 |
{
|
| 415 |
// 文字列除去後変換 |
| 416 |
return cnvInt(strCode.Replace(strRemove, "")); |
| 417 |
} |
| 418 |
catch (System.Exception ex) |
| 419 |
{
|
| 420 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 421 |
return 0; |
| 422 |
} |
| 423 |
} |
| 424 |
#endregion |
| 425 |
|
| 426 |
#region 日付返還変換 |
| 427 |
/// <summary> |
| 428 |
/// 日付返還変換 |
| 429 |
/// </summary> |
| 430 |
/// <param name="sendData"></param> |
| 431 |
/// <returns></returns> |
| 432 |
public static DateTime cnvDate(object sendData) |
| 433 |
{
|
| 434 |
DateTime dtDateWork = DateTime.MinValue; |
| 435 |
try |
| 436 |
{
|
| 437 |
// 空判定 |
| 438 |
if (sendData == null) return dtDateWork; |
| 439 |
if (sendData.ToString().Length == 0) return dtDateWork; |
| 440 |
|
| 441 |
// 変換 |
| 442 |
bool bRet = DateTime.TryParse(sendData.ToString(), out dtDateWork); |
| 443 |
|
| 444 |
return dtDateWork; |
| 445 |
} |
| 446 |
catch (System.Exception ex) |
| 447 |
{
|
| 448 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 449 |
return dtDateWork; |
| 450 |
} |
| 451 |
} |
| 452 |
#endregion |
| 453 |
|
| 454 |
#region 文字列より数値変換(long) |
| 455 |
/// <summary> |
| 456 |
/// 文字列より数値変換(long) |
| 457 |
/// </summary> |
| 458 |
/// <param name="sendData"></param> |
| 459 |
/// <returns></returns> |
| 460 |
public static long cnvLong(object sendData) |
| 461 |
{
|
| 462 |
try |
| 463 |
{
|
| 464 |
long retData = 0; |
| 465 |
|
| 466 |
// 空判定 |
| 467 |
if (sendData == null) return retData; |
| 468 |
if (sendData.ToString().Trim().Length == 0) return retData; |
| 469 |
|
| 470 |
// 変換 |
| 471 |
long.TryParse(sendData.ToString().Replace(",", "").Replace("\\", "").Trim(), out retData);
|
| 472 |
|
| 473 |
return retData; |
| 474 |
} |
| 475 |
catch (System.Exception ex) |
| 476 |
{
|
| 477 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 478 |
return 0; |
| 479 |
} |
| 480 |
} |
| 481 |
#endregion |
| 482 |
|
| 483 |
#region 文字列より数値変換(int) |
| 484 |
/// <summary> |
| 485 |
/// 文字列より数値変換(int) |
| 486 |
/// </summary> |
| 487 |
/// <param name="sendData"></param> |
| 488 |
/// <returns></returns> |
| 489 |
public static int cnvInt(object sendData) |
| 490 |
{
|
| 491 |
try |
| 492 |
{
|
| 493 |
int retData = 0; |
| 494 |
|
| 495 |
// 空判定 |
| 496 |
if (sendData == null) return retData; |
| 497 |
if (sendData.ToString().Trim().Length == 0) return retData; |
| 498 |
|
| 499 |
// 変換 |
| 500 |
int.TryParse(sendData.ToString().Replace(",", "").Replace("\\", "").Trim(), out retData);
|
| 501 |
|
| 502 |
return retData; |
| 503 |
} |
| 504 |
catch (System.Exception ex) |
| 505 |
{
|
| 506 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 507 |
return 0; |
| 508 |
} |
| 509 |
} |
| 510 |
#endregion |
| 511 |
|
| 512 |
#region 文字列より数値変換(string) |
| 513 |
/// <summary> |
| 514 |
/// 文字列より数値変換(string) |
| 515 |
/// </summary> |
| 516 |
/// <param name="sendData"></param> |
| 517 |
/// <returns></returns> |
| 518 |
public static string cnvString(object sendData) |
| 519 |
{
|
| 520 |
try |
| 521 |
{
|
| 522 |
string retData = string.Empty; |
| 523 |
|
| 524 |
// 空判定 |
| 525 |
if (sendData == null) return retData; |
| 526 |
if (sendData.ToString().Trim().Length == 0) return retData; |
| 527 |
|
| 528 |
|
| 529 |
// 変換 |
| 530 |
retData = sendData.ToString(); |
| 531 |
|
| 532 |
return retData; |
| 533 |
} |
| 534 |
catch (System.Exception ex) |
| 535 |
{
|
| 536 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 537 |
return ""; |
| 538 |
} |
| 539 |
} |
| 540 |
#endregion |
| 541 |
|
| 542 |
#region 文字列より数値変換(double) |
| 543 |
/// <summary> |
| 544 |
/// 文字列より数値変換(double) |
| 545 |
/// </summary> |
| 546 |
/// <param name="sendData"></param> |
| 547 |
/// <returns></returns> |
| 548 |
public static double cnvDouble(object sendData) |
| 549 |
{
|
| 550 |
try |
| 551 |
{
|
| 552 |
double retData = 0; |
| 553 |
|
| 554 |
// 空判定 |
| 555 |
if (sendData == null) return retData; |
| 556 |
if (sendData.ToString().Trim().Length == 0) return retData; |
| 557 |
|
| 558 |
|
| 559 |
// 変換 |
| 560 |
double.TryParse(sendData.ToString().Replace(",", "").Replace("\\", "").Trim(), out retData);
|
| 561 |
|
| 562 |
return retData; |
| 563 |
} |
| 564 |
catch (System.Exception ex) |
| 565 |
{
|
| 566 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 567 |
return 0; |
| 568 |
} |
| 569 |
} |
| 570 |
#endregion |
| 571 |
|
| 572 |
#region 文字列より数値変換(float) |
| 573 |
/// <summary> |
| 574 |
/// 文字列より数値変換(float) |
| 575 |
/// </summary> |
| 576 |
/// <param name="sendData"></param> |
| 577 |
/// <returns></returns> |
| 578 |
public static float cnvFloat(object sendData) |
| 579 |
{
|
| 580 |
try |
| 581 |
{
|
| 582 |
float retData = 0; |
| 583 |
|
| 584 |
// 空判定 |
| 585 |
if (sendData == null) return retData; |
| 586 |
if (sendData.ToString().Trim().Length == 0) return retData; |
| 587 |
|
| 588 |
|
| 589 |
// 変換 |
| 590 |
float.TryParse(sendData.ToString().Replace(",", "").Replace("\\", "").Trim(), out retData);
|
| 591 |
|
| 592 |
return retData; |
| 593 |
} |
| 594 |
catch (System.Exception ex) |
| 595 |
{
|
| 596 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 597 |
return 0; |
| 598 |
} |
| 599 |
} |
| 600 |
#endregion |
| 601 |
|
| 602 |
#region 文字列より数値変換(decimal) |
| 603 |
/// <summary> |
| 604 |
/// 文字列より数値変換(decimal) |
| 605 |
/// </summary> |
| 606 |
/// <param name="sendData"></param> |
| 607 |
/// <returns></returns> |
| 608 |
public static decimal cnvDecimal(object sendData) |
| 609 |
{
|
| 610 |
try |
| 611 |
{
|
| 612 |
decimal retData = 0; |
| 613 |
|
| 614 |
// 空判定 |
| 615 |
if (sendData == null) return retData; |
| 616 |
if (sendData.ToString().Trim().Length == 0) return retData; |
| 617 |
|
| 618 |
|
| 619 |
// 変換 |
| 620 |
decimal.TryParse(sendData.ToString().Replace(",", "").Replace("\\", "").Trim(), out retData);
|
| 621 |
|
| 622 |
return retData; |
| 623 |
} |
| 624 |
catch (System.Exception ex) |
| 625 |
{
|
| 626 |
Console.WriteLine("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 627 |
return 0; |
| 628 |
} |
| 629 |
} |
| 630 |
#endregion |
| 631 |
|
| 632 |
#region 四捨五入 |
| 633 |
/// <summary> |
| 634 |
/// 四捨五入 |
| 635 |
/// </summary> |
| 636 |
/// <param name="InputData"></param> |
| 637 |
/// <returns></returns> |
| 638 |
public static int cnvRound(double InputData) |
| 639 |
{
|
| 640 |
int retRoundData = 0; |
| 641 |
try |
| 642 |
{
|
| 643 |
retRoundData = (int)Math.Round(InputData, MidpointRounding.AwayFromZero); |
| 644 |
|
| 645 |
return retRoundData; |
| 646 |
} |
| 647 |
catch (System.Exception ex) |
| 648 |
{
|
| 649 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 650 |
return retRoundData; |
| 651 |
} |
| 652 |
} |
| 653 |
#endregion |
| 654 |
|
| 655 |
#region 切り上げ |
| 656 |
/// <summary> |
| 657 |
/// 切り上げ |
| 658 |
/// </summary> |
| 659 |
/// <param name="InputData"></param> |
| 660 |
/// <returns></returns> |
| 661 |
public static int cnvRoundUp(double InputData) |
| 662 |
{
|
| 663 |
int retRoundData = 0; |
| 664 |
try |
| 665 |
{
|
| 666 |
retRoundData = (int)Math.Ceiling(InputData); |
| 667 |
|
| 668 |
return retRoundData; |
| 669 |
} |
| 670 |
catch (System.Exception ex) |
| 671 |
{
|
| 672 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 673 |
return retRoundData; |
| 674 |
} |
| 675 |
} |
| 676 |
#endregion |
| 677 |
|
| 678 |
#region 切り捨て |
| 679 |
/// <summary> |
| 680 |
/// 切り捨て |
| 681 |
/// </summary> |
| 682 |
/// <param name="InputData"></param> |
| 683 |
/// <returns></returns> |
| 684 |
public static int cnvTruncate(double InputData) |
| 685 |
{
|
| 686 |
int retRoundData = 0; |
| 687 |
try |
| 688 |
{
|
| 689 |
retRoundData = (int)Math.Truncate(InputData); |
| 690 |
|
| 691 |
return retRoundData; |
| 692 |
} |
| 693 |
catch (System.Exception ex) |
| 694 |
{
|
| 695 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 696 |
return retRoundData; |
| 697 |
} |
| 698 |
} |
| 699 |
#endregion |
| 700 |
|
| 701 |
#region 四捨五入(四捨五入位置指定) |
| 702 |
/// <summary> |
| 703 |
/// 四捨五入(四捨五入位置指定) |
| 704 |
/// </summary> |
| 705 |
/// <param name="value"></param> |
| 706 |
/// <param name="pos"></param> |
| 707 |
/// <returns></returns> |
| 708 |
public static int IntRound(double value, int pos) |
| 709 |
{
|
| 710 |
// 何乗かを求める |
| 711 |
int posion = (int)Math.Pow(10, (pos + 1)); |
| 712 |
|
| 713 |
int upperval = (int)(value / posion); |
| 714 |
upperval *= posion; |
| 715 |
int lowerval = (int)(value % posion); |
| 716 |
int chkval = (int)(lowerval / Math.Pow(10, pos)); |
| 717 |
if (chkval > 4) upperval += (1 * posion); |
| 718 |
|
| 719 |
return upperval; |
| 720 |
} |
| 721 |
#endregion |
| 722 |
|
| 723 |
#region 切り捨て(切り捨て位置指定) |
| 724 |
/// <summary> |
| 725 |
/// 切り捨て(切り捨て位置指定) |
| 726 |
/// </summary> |
| 727 |
/// <param name="value"></param> |
| 728 |
/// <param name="pos"></param> |
| 729 |
/// <returns></returns> |
| 730 |
public static int IntRoundDown(double value, int pos) |
| 731 |
{
|
| 732 |
// 何乗かを求める |
| 733 |
int posion = (int)Math.Pow(10, (pos + 1)); |
| 734 |
|
| 735 |
int upperval = (int)(value / posion); |
| 736 |
upperval *= posion; |
| 737 |
|
| 738 |
return upperval; |
| 739 |
} |
| 740 |
#endregion |
| 741 |
|
| 742 |
#region 切り上げ(切り上げ位置指定) |
| 743 |
/// <summary> |
| 744 |
/// 切り上げ(切り上げ位置指定) |
| 745 |
/// </summary> |
| 746 |
/// <param name="value"></param> |
| 747 |
/// <param name="pos"></param> |
| 748 |
/// <returns></returns> |
| 749 |
public static int IntRoundUp(double value, int pos) |
| 750 |
{
|
| 751 |
// 何乗かを求める |
| 752 |
int posion = (int)Math.Pow(10, (pos + 1)); |
| 753 |
|
| 754 |
int upperval = (int)(value / posion); |
| 755 |
upperval *= posion; |
| 756 |
int lowerval = (int)(value % posion); |
| 757 |
int chkval = (int)(lowerval / Math.Pow(10, pos)); |
| 758 |
if (chkval > 0) upperval += (1 * posion); |
| 759 |
|
| 760 |
return upperval; |
| 761 |
} |
| 762 |
#endregion |
| 763 |
|
| 764 |
#region 0~26までの数字をA~Zに変換する |
| 765 |
/// <summary> |
| 766 |
/// 0~26までの数字をA~Zに変換する |
| 767 |
/// </summary> |
| 768 |
/// <param name="num"></param> |
| 769 |
/// <returns></returns> |
| 770 |
public static string cnvNumberToAlphaCharacter(int num) |
| 771 |
{
|
| 772 |
try |
| 773 |
{
|
| 774 |
// ----- 16進数文字列 -> 数値 |
| 775 |
int CnvCode = Convert.ToInt32("0041", 16); // 'A'
|
| 776 |
int LastCode = Convert.ToInt32("005A", 16); // 'Z'
|
| 777 |
|
| 778 |
// 変換値を加算する |
| 779 |
CnvCode += num; |
| 780 |
// 'Z'を超えたら採番しない |
| 781 |
if (CnvCode > LastCode) return string.Empty; |
| 782 |
|
| 783 |
// 数値(文字コード) -> 文字 |
| 784 |
char c = Convert.ToChar(CnvCode); |
| 785 |
// 英字「文字列」 |
| 786 |
string newChar = c.ToString(); |
| 787 |
|
| 788 |
return newChar; |
| 789 |
} |
| 790 |
catch (System.Exception ex) |
| 791 |
{
|
| 792 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 793 |
return ""; |
| 794 |
} |
| 795 |
} |
| 796 |
#endregion |
| 797 |
|
| 798 |
#region 日付が最小値ならば"未定"文字を返す |
| 799 |
/// <summary> |
| 800 |
/// 日付が最小値ならば"未定"文字を返す |
| 801 |
/// </summary> |
| 802 |
/// <param name="srcDate"></param> |
| 803 |
/// <returns></returns> |
| 804 |
public static string cnvDateToUndecidedString(DateTime srcDate) |
| 805 |
{
|
| 806 |
try |
| 807 |
{
|
| 808 |
string work = ""; |
| 809 |
if (srcDate.Equals(DateTime.MinValue)) |
| 810 |
work = CommonDefine.s_UndecidedString; |
| 811 |
else |
| 812 |
work = srcDate.ToShortDateString(); |
| 813 |
|
| 814 |
return work; |
| 815 |
} |
| 816 |
catch (System.Exception ex) |
| 817 |
{
|
| 818 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 819 |
return ""; |
| 820 |
} |
| 821 |
} |
| 822 |
#endregion |
| 823 |
|
| 824 |
#region 文字列から日付を返す(文字列が"未定"文字ならば日付最小値を返す) |
| 825 |
/// <summary> |
| 826 |
/// 文字列から日付を返す |
| 827 |
/// 文字列が"未定"文字ならば日付最小値を返す |
| 828 |
/// </summary> |
| 829 |
/// <param name="srcDate"></param> |
| 830 |
/// <returns></returns> |
| 831 |
public static DateTime cnvUndecidedStringToDate(object srcDate) |
| 832 |
{
|
| 833 |
DateTime work = DateTime.MinValue; |
| 834 |
try |
| 835 |
{
|
| 836 |
if (!srcDate.Equals(CommonDefine.s_UndecidedString)) |
| 837 |
work = cnvDate(srcDate); |
| 838 |
|
| 839 |
return work; |
| 840 |
} |
| 841 |
catch (System.Exception ex) |
| 842 |
{
|
| 843 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 844 |
return work; |
| 845 |
} |
| 846 |
} |
| 847 |
#endregion |
| 848 |
|
| 849 |
#region 文字列から数値(文字列が"未定"文字ならば0を返す) |
| 850 |
/// <summary> |
| 851 |
/// 文字列から数値 |
| 852 |
/// 文字列が"未定"文字ならば0を返す |
| 853 |
/// </summary> |
| 854 |
/// <param name="srcDate"></param> |
| 855 |
/// <returns></returns> |
| 856 |
public static double cnvUndecidedStringToDouble(object srcDate) |
| 857 |
{
|
| 858 |
double work = 0; |
| 859 |
try |
| 860 |
{
|
| 861 |
if (!srcDate.Equals(CommonDefine.s_UndecidedString)) |
| 862 |
work = cnvDouble(srcDate); |
| 863 |
|
| 864 |
return work; |
| 865 |
} |
| 866 |
catch (System.Exception ex) |
| 867 |
{
|
| 868 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 869 |
return work; |
| 870 |
} |
| 871 |
} |
| 872 |
#endregion |
| 873 |
|
| 874 |
#region 色指定文字列より色を返す |
| 875 |
/// <summary> |
| 876 |
/// 色指定文字列より色を返す |
| 877 |
/// </summary> |
| 878 |
/// <param name="strColor"></param> |
| 879 |
/// <returns></returns> |
| 880 |
public static Color cnvStringToColor(string strColor) |
| 881 |
{
|
| 882 |
Color ColorRet = Color.White; |
| 883 |
try |
| 884 |
{
|
| 885 |
// 色文字列チェック |
| 886 |
if (!CommonMotions.chkObjectIsNull(strColor) && strColor.Length != 0) |
| 887 |
{
|
| 888 |
ColorRet = ColorTranslator.FromHtml(strColor); |
| 889 |
} |
| 890 |
return ColorRet; |
| 891 |
} |
| 892 |
catch (System.Exception ex) |
| 893 |
{
|
| 894 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 895 |
return ColorRet; |
| 896 |
} |
| 897 |
} |
| 898 |
#endregion |
| 899 |
|
| 900 |
#region 色指定文字列より色を返す・設定無しは指定場所のデフォルトを返す |
| 901 |
/// <summary> |
| 902 |
/// 色指定文字列より色を返す・設定無しは指定場所のデフォルトを返す |
| 903 |
/// </summary> |
| 904 |
/// <param name="strColor"></param> |
| 905 |
/// <param name="point"></param> |
| 906 |
/// <returns></returns> |
| 907 |
public static Color getBackForeColor(string strColor, CommonDefine.PalceOfColor point) |
| 908 |
{
|
| 909 |
Color ColorRet = Color.White; |
| 910 |
try |
| 911 |
{
|
| 912 |
// デフォルトセット |
| 913 |
if (point == CommonDefine.PalceOfColor.BackColor) |
| 914 |
{ // 背景
|
| 915 |
ColorRet = Color.White; |
| 916 |
} |
| 917 |
else if (point == CommonDefine.PalceOfColor.ForeColor) |
| 918 |
{ // 文字色
|
| 919 |
ColorRet = Color.Black; |
| 920 |
} |
| 921 |
else |
| 922 |
{
|
| 923 |
ColorRet = Color.Transparent; |
| 924 |
} |
| 925 |
|
| 926 |
if (!chkObjectIsNull(strColor) && strColor.Length != 0) |
| 927 |
{
|
| 928 |
} |
| 929 |
else |
| 930 |
{
|
| 931 |
strColor = String.Format("0x{0:X2}{1:X2}{2:X2}", ColorRet.R, ColorRet.G, ColorRet.B);
|
| 932 |
} |
| 933 |
|
| 934 |
ColorRet = cnvStringToColor(strColor); |
| 935 |
|
| 936 |
return ColorRet; |
| 937 |
} |
| 938 |
catch (System.Exception ex) |
| 939 |
{
|
| 940 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 941 |
return ColorRet; |
| 942 |
} |
| 943 |
} |
| 944 |
#endregion |
| 945 |
#endregion |
| 946 |
|
| 947 |
#region データチェックメソッド |
| 948 |
#region ディレクトリの存在チェック |
| 949 |
/// <summary> |
| 950 |
/// ディレクトリの存在チェック |
| 951 |
/// </summary> |
| 952 |
/// <param name="DirectryName">フォルダパス</param> |
| 953 |
/// <returns></returns> |
| 954 |
public static bool ChkDirPath(string DirectryName, bool CreateFlg = false) |
| 955 |
{
|
| 956 |
try |
| 957 |
{
|
| 958 |
// フォルダ (ディレクトリ) が存在しているかどうか確認する |
| 959 |
if (!Directory.Exists(@DirectryName)) |
| 960 |
{
|
| 961 |
// 作成フラグOffならばエラー |
| 962 |
if (!CreateFlg) return false; |
| 963 |
|
| 964 |
// ディレクトリを作成する |
| 965 |
Directory.CreateDirectory(@DirectryName); |
| 966 |
} |
| 967 |
|
| 968 |
return true; |
| 969 |
} |
| 970 |
catch (Exception ex) |
| 971 |
{
|
| 972 |
logger.ErrorFormat(ex.Message); |
| 973 |
return false; |
| 974 |
} |
| 975 |
} |
| 976 |
#endregion |
| 977 |
|
| 978 |
#region オブジェクトのNullチェック |
| 979 |
/// <summary> |
| 980 |
/// オブジェクトのNullチェック |
| 981 |
/// </summary> |
| 982 |
/// <param name="sendData">オブジェクト</param> |
| 983 |
/// <returns></returns> |
| 984 |
public static bool chkObjectIsNull(Object sendData) |
| 985 |
{
|
| 986 |
try |
| 987 |
{
|
| 988 |
if (sendData == null) return true; |
| 989 |
|
| 990 |
return false; |
| 991 |
} |
| 992 |
catch (System.Exception ex) |
| 993 |
{
|
| 994 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 995 |
return false; |
| 996 |
} |
| 997 |
} |
| 998 |
#endregion |
| 999 |
|
| 1000 |
#region 数値チェック |
| 1001 |
/// <summary> |
| 1002 |
/// 数値チェック |
| 1003 |
/// </summary> |
| 1004 |
/// <param name="data">Long文字列</param> |
| 1005 |
/// <param name="indispensable">入力必須チェック</param> |
| 1006 |
/// <returns>true:正常 false:異常</returns> |
| 1007 |
public static bool chkNumeric(object CheckData, bool indispensable = false) |
| 1008 |
{
|
| 1009 |
try |
| 1010 |
{
|
| 1011 |
if (chkObjectIsNull(CheckData)) return false; |
| 1012 |
|
| 1013 |
string RecvData = cnvString(CheckData); |
| 1014 |
double revData = 0; |
| 1015 |
// 必須入力チェック |
| 1016 |
if (indispensable) |
| 1017 |
{
|
| 1018 |
if (RecvData.Replace(",", "").Replace("\\", "").Trim().Length == 0) return false;
|
| 1019 |
} |
| 1020 |
// Nullが入っていなくてレングスが0は数値として扱う |
| 1021 |
if (RecvData.Replace(",", "").Replace("\\", "").Trim().Length == 0) return true;
|
| 1022 |
|
| 1023 |
return double.TryParse(RecvData.Replace(",", "").Replace("\\", "").Trim(), out revData);
|
| 1024 |
} |
| 1025 |
catch (System.Exception ex) |
| 1026 |
{
|
| 1027 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 1028 |
return false; |
| 1029 |
} |
| 1030 |
} |
| 1031 |
#endregion |
| 1032 |
|
| 1033 |
#region 数値チェック(long) |
| 1034 |
/// <summary> |
| 1035 |
/// 数値チェック(long) |
| 1036 |
/// </summary> |
| 1037 |
/// <param name="data">Long文字列</param> |
| 1038 |
/// <param name="indispensable">入力必須チェック</param> |
| 1039 |
/// <returns>true:正常 false:異常</returns> |
| 1040 |
public static bool chkNumeric(object sendData, ref long retData, bool indispensable = false) |
| 1041 |
{
|
| 1042 |
try |
| 1043 |
{
|
| 1044 |
// 必須入力チェック |
| 1045 |
if (indispensable) |
| 1046 |
{
|
| 1047 |
if (cnvString(sendData).Replace(",", "").Replace("\\", "").Trim().Length == 0) return false;
|
| 1048 |
} |
| 1049 |
|
| 1050 |
return long.TryParse(cnvString(sendData).Replace(",", "").Replace("\\", "").Trim(), out retData);
|
| 1051 |
} |
| 1052 |
catch (System.Exception ex) |
| 1053 |
{
|
| 1054 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 1055 |
return false; |
| 1056 |
} |
| 1057 |
} |
| 1058 |
#endregion |
| 1059 |
|
| 1060 |
#region 数値チェック(int) |
| 1061 |
/// <summary> |
| 1062 |
/// 数値チェック(int) |
| 1063 |
/// </summary> |
| 1064 |
/// <param name="data">Long文字列</param> |
| 1065 |
/// <param name="indispensable">入力必須チェック</param> |
| 1066 |
/// <returns>true:正常 false:異常</returns> |
| 1067 |
public static bool chkNumeric(object sendData, ref int retData, bool indispensable = false) |
| 1068 |
{
|
| 1069 |
try |
| 1070 |
{
|
| 1071 |
// 必須入力チェック |
| 1072 |
if (indispensable) |
| 1073 |
{
|
| 1074 |
if (cnvString(sendData).Replace(",", "").Replace("\\", "").Trim().Length == 0) return false;
|
| 1075 |
} |
| 1076 |
|
| 1077 |
return int.TryParse(cnvString(sendData).Replace(",", "").Replace("\\", "").Trim(), out retData);
|
| 1078 |
} |
| 1079 |
catch (System.Exception ex) |
| 1080 |
{
|
| 1081 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 1082 |
return false; |
| 1083 |
} |
| 1084 |
} |
| 1085 |
#endregion |
| 1086 |
|
| 1087 |
#region 数値チェック(double) |
| 1088 |
/// <summary> |
| 1089 |
/// 数値チェック(double) |
| 1090 |
/// </summary> |
| 1091 |
/// <param name="data">Long文字列</param> |
| 1092 |
/// <param name="indispensable">入力必須チェック</param> |
| 1093 |
/// <returns>true:正常 false:異常</returns> |
| 1094 |
public static bool chkNumeric(object sendData, ref double retData, bool indispensable = false) |
| 1095 |
{
|
| 1096 |
try |
| 1097 |
{
|
| 1098 |
// 必須入力チェック |
| 1099 |
if (indispensable) |
| 1100 |
{
|
| 1101 |
if (cnvString(sendData).Replace(",", "").Replace("\\", "").Trim().Length == 0) return false;
|
| 1102 |
} |
| 1103 |
|
| 1104 |
return double.TryParse(cnvString(sendData).Replace(",", "").Replace("\\", "").Trim(), out retData);
|
| 1105 |
} |
| 1106 |
catch (System.Exception ex) |
| 1107 |
{
|
| 1108 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 1109 |
return false; |
| 1110 |
} |
| 1111 |
} |
| 1112 |
#endregion |
| 1113 |
|
| 1114 |
#region 文字列長さチェック(UTF-8) |
| 1115 |
/// <summary> |
| 1116 |
/// 文字列長さチェック(UTF-8) |
| 1117 |
/// </summary> |
| 1118 |
/// <param name="strData">対象文字列</param> |
| 1119 |
/// <param name="lngMaxLen">最大長</param> |
| 1120 |
/// <param name="indispensable">入力必須チェック</param> |
| 1121 |
/// <returns>true:正常 false:異常</returns> |
| 1122 |
public static bool chkStringLength(string strData, int lngMaxLen, bool indispensable = false) |
| 1123 |
{
|
| 1124 |
bool bRet = true; |
| 1125 |
//int lngLen = 0; |
| 1126 |
try |
| 1127 |
{
|
| 1128 |
|
| 1129 |
//Encoding sjis = Encoding.GetEncoding("shift-jis");
|
| 1130 |
Encoding utf8 = Encoding.GetEncoding("utf-8");
|
| 1131 |
|
| 1132 |
// 必須入力チェック |
| 1133 |
if (indispensable) |
| 1134 |
{
|
| 1135 |
if (strData.Length == 0) bRet = false; |
| 1136 |
} |
| 1137 |
// S-Jisチェック |
| 1138 |
//lngLen = sjis.GetByteCount(strData); |
| 1139 |
// UTF-8チェック |
| 1140 |
//lngLen = utf8.GetByteCount(strData); |
| 1141 |
//if (lngLen > lngMaxLen) bRet = false; |
| 1142 |
// C#内はUTFなので文字長だけをチェックする |
| 1143 |
if (strData.Length > lngMaxLen) bRet = false; |
| 1144 |
} |
| 1145 |
catch (System.Exception ex) |
| 1146 |
{
|
| 1147 |
logger.ErrorFormat("システムエラー:{0}:{1}", GetMethodName(), ex.Message);
|
| 1148 |
bRet = false; |
| 1149 |
} |
| 1150 |
|
| 1151 |
return bRet; |
| 1152 |
} |
| 1153 |
#endregion |
| 1154 |
|
| 1155 |
#region 郵便番号チェック |
| 1156 |
/// <summary> |
| 1157 |
/// 郵便番号チェック |
| 1158 |
/// </summary> |
| 1159 |
/// <param name="strData">郵便番号文字列</param> |
| 1160 |
/// <returns>true:正常 false:異常</returns> |
| 1161 |
public static bool chkZipcode(string strdata) |
| 1162 |
{
|
| 1163 |
bool bRet = false; |
| 1164 |
|
| 1165 |
Regex regex = new Regex("^[0-9]{3}[-][0-9]{4}$");
|
| 1166 |
if (regex.IsMatch(strdata)) |
| 1167 |
{
|
| 1168 |
bRet = true; |
| 1169 |
} |
| 1170 |
return bRet; |
| 1171 |
} |
| 1172 |
#endregion |
| 1173 |
|
| 1174 |
#region 電話番号/FAX番号チェック |
| 1175 |
/// <summary> |
| 1176 |
/// 電話番号/FAX番号チェック |
| 1177 |
/// </summary> |
| 1178 |
/// <param name="data">電話番号文字列</param> |
| 1179 |
/// <returns>true:正常 false:異常</returns> |
| 1180 |
public static bool chkPhoneNumber(string strdata) |
| 1181 |
{
|
| 1182 |
bool bRet = false; |
| 1183 |
|
| 1184 |
Regex regex = new Regex("^[0-9]{2,5}-[0-9]{1,4}-[0-9]{3,4}$");
|
| 1185 |
if (regex.IsMatch(strdata)) |
| 1186 |
{
|
| 1187 |
bRet = true; |
| 1188 |
} |
| 1189 |
return bRet; |
| 1190 |
} |
| 1191 |
#endregion |
| 1192 |
|
| 1193 |
#region メールアドレスチェック |
| 1194 |
/// <summary> |
| 1195 |
/// メールアドレスチェック |
| 1196 |
/// </summary> |
| 1197 |
/// <param name="data">電話番号文字列</param> |
| 1198 |
/// <returns>true:正常 false:異常</returns> |
| 1199 |
public static bool chkMailAddress(string strdata) |
| 1200 |
{
|
| 1201 |
bool bRet = false; |
| 1202 |
|
| 1203 |
Regex regex = new Regex(@"\A\P{Cc}+@\P{Cc}+\z");
|
| 1204 |
if (regex.IsMatch(strdata)) |
| 1205 |
{
|
| 1206 |
bRet = true; |
| 1207 |
} |
| 1208 |
return bRet; |
| 1209 |
} |
| 1210 |
#endregion |
| 1211 |
|
| 1212 |
#region 日付チェック |
| 1213 |
/// <summary> |
| 1214 |
/// 日付チェック |
| 1215 |
/// </summary> |
| 1216 |
/// <param name="data">日付文字列</param> |
| 1217 |
/// <returns>true:正常 false:異常</returns> |
| 1218 |
public static bool chkDate(string strdata) |
| 1219 |
{
|
| 1220 |
bool bRet = true; |
| 1221 |
try |
| 1222 |
{
|
| 1223 |
DateTime dtwork = DateTime.MinValue; |
| 1224 |
|
| 1225 |
return DateTime.TryParse(strdata, out dtwork); |
| 1226 |
} |
| 1227 |
catch (System.Exception ex) |
| 1228 |
{
|
| 1229 |
logger.DebugFormat("chkDate Error message:{0}", ex.Message);
|
| 1230 |
bRet = false; |
| 1231 |
} |
| 1232 |
return bRet; |
| 1233 |
} |
| 1234 |
#endregion |
| 1235 |
|
| 1236 |
#region セルが空かどうかをチェックする |
| 1237 |
/// <summary> |
| 1238 |
/// セルが空かどうかをチェックする |
| 1239 |
/// </summary> |
| 1240 |
/// <param name="objCell"></param> |
| 1241 |
/// <param name="iColumn"></param> |
| 1242 |
/// <returns>true:空 flase:有効</returns> |
| 1243 |
public static bool chkCellBlank(object objCell) |
| 1244 |
{
|
| 1245 |
try |
| 1246 |
{
|
| 1247 |
if (chkObjectIsNull(objCell)) return true; |
| 1248 |
if (objCell.ToString().Length == 0) return true; |
| 1249 |
|
| 1250 |
return false; |
| 1251 |
} |
| 1252 |
catch (System.Exception ex) |
| 1253 |
{
|
| 1254 |
logger.DebugFormat("chkDate Error message:{0}", ex.Message);
|
| 1255 |
return true; |
| 1256 |
} |
| 1257 |
} |
| 1258 |
#endregion |
| 1259 |
|
| 1260 |
#region 画面フィールド入力必須チェック |
| 1261 |
/// <summary> |
| 1262 |
/// 画面フィールド入力必須チェック |
| 1263 |
/// </summary> |
| 1264 |
/// <param name="dispControl">コントロールオブジェクト</param> |
| 1265 |
/// <returns>false:エラー true:エラーなし</returns> |
| 1266 |
public static bool DispFieldIndispensable(Control dispControl) |
| 1267 |
{
|
| 1268 |
bool bAns = true; |
| 1269 |
try |
| 1270 |
{
|
| 1271 |
// 必須入力チェック |
| 1272 |
if (chkObjectIsNull(dispControl)) |
| 1273 |
{
|
| 1274 |
bAns = false; |
| 1275 |
} |
| 1276 |
else |
| 1277 |
{
|
| 1278 |
if (dispControl.Text.ToString().Length == 0) |
| 1279 |
{
|
| 1280 |
bAns = false; |
| 1281 |
} |
| 1282 |
} |
| 1283 |
} |
| 1284 |
catch (Exception ex) |
| 1285 |
{
|
| 1286 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 1287 |
bAns = false; |
| 1288 |
} |
| 1289 |
finally |
| 1290 |
{
|
| 1291 |
// 背景色変更 |
| 1292 |
chgBackColor(dispControl, bAns); |
| 1293 |
} |
| 1294 |
return bAns; |
| 1295 |
} |
| 1296 |
#endregion |
| 1297 |
|
| 1298 |
#region 画面フィールド入力文字数チェック |
| 1299 |
/// <summary> |
| 1300 |
/// 画面フィールド入力文字数チェック |
| 1301 |
/// </summary> |
| 1302 |
/// <param name="dispControl">コントロールオブジェクト</param> |
| 1303 |
/// <param name="sLength">文字列長</param> |
| 1304 |
/// <param name="indispensable">true:必須入力チェック</param> |
| 1305 |
/// <returns>false:エラー true:エラーなし</returns> |
| 1306 |
public static bool DispFieldLengthCheck(Control dispControl, int sLength, bool indispensable = false) |
| 1307 |
{
|
| 1308 |
bool bAns = true; |
| 1309 |
try |
| 1310 |
{
|
| 1311 |
// 必須入力チェック |
| 1312 |
if (indispensable) |
| 1313 |
{
|
| 1314 |
bAns = DispFieldIndispensable(dispControl); |
| 1315 |
} |
| 1316 |
|
| 1317 |
if (dispControl.Text.ToString().Length != 0) |
| 1318 |
{
|
| 1319 |
// レングスチェック |
| 1320 |
bAns = chkStringLength(dispControl.Text.ToString(), sLength); |
| 1321 |
} |
| 1322 |
} |
| 1323 |
catch (Exception ex) |
| 1324 |
{
|
| 1325 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 1326 |
bAns = false; |
| 1327 |
} |
| 1328 |
finally |
| 1329 |
{
|
| 1330 |
// 背景色変更 |
| 1331 |
chgBackColor(dispControl, bAns); |
| 1332 |
} |
| 1333 |
return bAns; |
| 1334 |
} |
| 1335 |
#endregion |
| 1336 |
|
| 1337 |
#region 画面フィールド入力日付チェック |
| 1338 |
/// <summary> |
| 1339 |
/// 画面フィールド入力日付チェック |
| 1340 |
/// </summary> |
| 1341 |
/// <param name="dispControl">コントロールオブジェクト</param> |
| 1342 |
/// <param name="indispensable">true:必須入力チェック</param> |
| 1343 |
/// <returns>false:エラー true:エラーなし</returns> |
| 1344 |
public static bool DispFieldDateCheck(Control dispControl, bool indispensable = false) |
| 1345 |
{
|
| 1346 |
bool bAns = true; |
| 1347 |
try |
| 1348 |
{
|
| 1349 |
// 必須入力チェック |
| 1350 |
if (indispensable) |
| 1351 |
{
|
| 1352 |
bAns = DispFieldIndispensable(dispControl); |
| 1353 |
} |
| 1354 |
|
| 1355 |
if (dispControl.Text.ToString().Length != 0) |
| 1356 |
{
|
| 1357 |
// 未定はエラーにしない |
| 1358 |
if (!indispensable && dispControl.Text.Equals(CommonDefine.s_UndecidedString)) { }
|
| 1359 |
else |
| 1360 |
// 日付チェック |
| 1361 |
bAns = chkDate(dispControl.Text.ToString()); |
| 1362 |
} |
| 1363 |
} |
| 1364 |
catch (Exception ex) |
| 1365 |
{
|
| 1366 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 1367 |
bAns = false; |
| 1368 |
} |
| 1369 |
finally |
| 1370 |
{
|
| 1371 |
// 背景色変更 |
| 1372 |
chgBackColor(dispControl, bAns); |
| 1373 |
} |
| 1374 |
return bAns; |
| 1375 |
} |
| 1376 |
#endregion |
| 1377 |
|
| 1378 |
#region 画面フィールド入力郵便番号チェック |
| 1379 |
/// <summary> |
| 1380 |
/// 画面フィールド入力郵便番号チェック |
| 1381 |
/// </summary> |
| 1382 |
/// <param name="dispControl">コントロールオブジェクト</param> |
| 1383 |
/// <param name="indispensable">true:必須入力チェック</param> |
| 1384 |
/// <returns>false:エラー true:エラーなし</returns> |
| 1385 |
public static bool DispFieldZipCodeCheck(Control dispControl, bool indispensable = false) |
| 1386 |
{
|
| 1387 |
bool bAns = true; |
| 1388 |
try |
| 1389 |
{
|
| 1390 |
// 必須入力チェック |
| 1391 |
if (indispensable) |
| 1392 |
{
|
| 1393 |
bAns = DispFieldIndispensable(dispControl); |
| 1394 |
} |
| 1395 |
|
| 1396 |
if (dispControl.Text.ToString().Length != 0) |
| 1397 |
{
|
| 1398 |
// 郵便番号チェック |
| 1399 |
bAns = chkZipcode(dispControl.Text.ToString()); |
| 1400 |
} |
| 1401 |
} |
| 1402 |
catch (Exception ex) |
| 1403 |
{
|
| 1404 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 1405 |
bAns = false; |
| 1406 |
} |
| 1407 |
finally |
| 1408 |
{
|
| 1409 |
// 背景色変更 |
| 1410 |
chgBackColor(dispControl, bAns); |
| 1411 |
} |
| 1412 |
return bAns; |
| 1413 |
} |
| 1414 |
#endregion |
| 1415 |
|
| 1416 |
#region 画面フィールド入力Intチェック |
| 1417 |
/// <summary> |
| 1418 |
/// 画面フィールド入力Intチェック |
| 1419 |
/// </summary> |
| 1420 |
/// <param name="dispControl">コントロールオブジェクト</param> |
| 1421 |
/// <param name="indispensable">true:必須入力チェック</param> |
| 1422 |
/// <returns>false:エラー true:エラーなし</returns> |
| 1423 |
public static bool DispFieldIntCheck(Control dispControl, bool indispensable = false) |
| 1424 |
{
|
| 1425 |
bool bAns = true; |
| 1426 |
try |
| 1427 |
{
|
| 1428 |
// 必須入力チェック |
| 1429 |
if (indispensable) |
| 1430 |
{
|
| 1431 |
bAns = DispFieldIndispensable(dispControl); |
| 1432 |
} |
| 1433 |
|
| 1434 |
if (dispControl.Text.ToString().Length != 0) |
| 1435 |
{
|
| 1436 |
int work = 0; |
| 1437 |
// 数値チェック |
| 1438 |
//bAns = chkNumeric(dispControl.Text.ToString(), ref work); |
| 1439 |
bAns = int.TryParse(dispControl.Text.ToString(), out work); |
| 1440 |
} |
| 1441 |
} |
| 1442 |
catch (Exception ex) |
| 1443 |
{
|
| 1444 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 1445 |
bAns = false; |
| 1446 |
} |
| 1447 |
finally |
| 1448 |
{
|
| 1449 |
// 背景色変更 |
| 1450 |
chgBackColor(dispControl, bAns); |
| 1451 |
} |
| 1452 |
return bAns; |
| 1453 |
} |
| 1454 |
#endregion |
| 1455 |
|
| 1456 |
#region 画面フィールド入力Doubleチェック |
| 1457 |
/// <summary> |
| 1458 |
/// 画面フィールド入力Doubleチェック |
| 1459 |
/// </summary> |
| 1460 |
/// <param name="dispControl">コントロールオブジェクト</param> |
| 1461 |
/// <param name="indispensable">true:必須入力チェック</param> |
| 1462 |
/// <returns>false:エラー true:エラーなし</returns> |
| 1463 |
public static bool DispFieldDoubleCheck(Control dispControl, bool indispensable = false) |
| 1464 |
{
|
| 1465 |
bool bAns = true; |
| 1466 |
try |
| 1467 |
{
|
| 1468 |
// 必須入力チェック |
| 1469 |
if (indispensable) |
| 1470 |
{
|
| 1471 |
bAns = DispFieldIndispensable(dispControl); |
| 1472 |
} |
| 1473 |
|
| 1474 |
if (dispControl.Text.ToString().Length != 0) |
| 1475 |
{
|
| 1476 |
double work = 0; |
| 1477 |
// 数値チェック |
| 1478 |
bAns = chkNumeric(dispControl.Text.ToString(), ref work); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
catch (Exception ex) |
| 1482 |
{
|
| 1483 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 1484 |
bAns = false; |
| 1485 |
} |
| 1486 |
finally |
| 1487 |
{
|
| 1488 |
// 背景色変更 |
| 1489 |
chgBackColor(dispControl, bAns); |
| 1490 |
} |
| 1491 |
return bAns; |
| 1492 |
} |
| 1493 |
#endregion |
| 1494 |
|
| 1495 |
#region 画面フィールド入力電話番号チェック |
| 1496 |
/// <summary> |
| 1497 |
/// 画面フィールド入力電話番号チェック |
| 1498 |
/// </summary> |
| 1499 |
/// <param name="dispControl">コントロールオブジェクト</param> |
| 1500 |
/// <param name="indispensable">true:必須入力チェック</param> |
| 1501 |
/// <returns>false:エラー true:エラーなし</returns> |
| 1502 |
public static bool DispFieldPhoneNumberCheck(Control dispControl, bool indispensable = false) |
| 1503 |
{
|
| 1504 |
bool bAns = true; |
| 1505 |
try |
| 1506 |
{
|
| 1507 |
// 必須入力チェック |
| 1508 |
if (indispensable) |
| 1509 |
{
|
| 1510 |
bAns = DispFieldIndispensable(dispControl); |
| 1511 |
} |
| 1512 |
|
| 1513 |
if (dispControl.Text.ToString().Length != 0) |
| 1514 |
{
|
| 1515 |
// 電話番号チェック |
| 1516 |
bAns = chkPhoneNumber(dispControl.Text.ToString()); |
| 1517 |
} |
| 1518 |
} |
| 1519 |
catch (Exception ex) |
| 1520 |
{
|
| 1521 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 1522 |
bAns = false; |
| 1523 |
} |
| 1524 |
finally |
| 1525 |
{
|
| 1526 |
// 背景色変更 |
| 1527 |
chgBackColor(dispControl, bAns); |
| 1528 |
} |
| 1529 |
return bAns; |
| 1530 |
} |
| 1531 |
#endregion |
| 1532 |
|
| 1533 |
#region 画面フィールド入力メールアドレスチェック |
| 1534 |
/// <summary> |
| 1535 |
/// 画面フィールド入力メールアドレスチェック |
| 1536 |
/// </summary> |
| 1537 |
/// <param name="dispControl">コントロールオブジェクト</param> |
| 1538 |
/// <param name="indispensable">true:必須入力チェック</param> |
| 1539 |
/// <returns>false:エラー true:エラーなし</returns> |
| 1540 |
public static bool DispFieldMailAddressCheck(Control dispControl, bool indispensable = false) |
| 1541 |
{
|
| 1542 |
bool bAns = true; |
| 1543 |
try |
| 1544 |
{
|
| 1545 |
// 必須入力チェック |
| 1546 |
if (indispensable) |
| 1547 |
{
|
| 1548 |
bAns = DispFieldIndispensable(dispControl); |
| 1549 |
} |
| 1550 |
|
| 1551 |
if (dispControl.Text.ToString().Length != 0) |
| 1552 |
{
|
| 1553 |
// メールアドレスチェック |
| 1554 |
bAns = chkMailAddress(dispControl.Text.ToString()); |
| 1555 |
} |
| 1556 |
} |
| 1557 |
catch (Exception ex) |
| 1558 |
{
|
| 1559 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 1560 |
bAns = false; |
| 1561 |
} |
| 1562 |
finally |
| 1563 |
{
|
| 1564 |
// 背景色変更 |
| 1565 |
chgBackColor(dispControl, bAns); |
| 1566 |
} |
| 1567 |
return bAns; |
| 1568 |
} |
| 1569 |
#endregion |
| 1570 |
|
| 1571 |
#region 指定した日が第何週かを求める |
| 1572 |
/// <summary> |
| 1573 |
/// 指定した日が第何週かを求める |
| 1574 |
/// </summary> |
| 1575 |
/// <param name="date"></param> |
| 1576 |
/// <returns></returns> |
| 1577 |
public static int NthWeek(DateTime date) |
| 1578 |
{
|
| 1579 |
int w = (int)(new DateTime(date.Year, date.Month, 1).DayOfWeek); |
| 1580 |
return (date.Day + w - 1) / 7 + 1; |
| 1581 |
|
| 1582 |
} |
| 1583 |
#endregion |
| 1584 |
#endregion |
| 1585 |
|
| 1586 |
#region フィールドバックカラー変更処理 |
| 1587 |
/// <summary> |
| 1588 |
/// フィールドバックカラー変更処理(あまりカッコ良くない^^;) |
| 1589 |
/// </summary> |
| 1590 |
/// <param name="objCtrl"></param> |
| 1591 |
/// <param name="chgColor"></param> |
| 1592 |
public static void chgBackColor(object objCtrl, bool bPara) |
| 1593 |
{
|
| 1594 |
if (objCtrl.GetType().Equals(typeof(TextBox)) || objCtrl.GetType().Equals(typeof(TextBoxEX))) |
| 1595 |
{
|
| 1596 |
TextBox wrk = (TextBox)objCtrl; |
| 1597 |
if (bPara) |
| 1598 |
{
|
| 1599 |
wrk.BackColor = CommonDefine.s_clrNormal; |
| 1600 |
} |
| 1601 |
else |
| 1602 |
{
|
| 1603 |
wrk.BackColor = CommonDefine.s_clrError; |
| 1604 |
wrk.Focus(); |
| 1605 |
} |
| 1606 |
} |
| 1607 |
else if (objCtrl.GetType().Equals(typeof(DataGridViewTextBoxCell))) |
| 1608 |
{
|
| 1609 |
DataGridViewTextBoxCell wrk = (DataGridViewTextBoxCell)objCtrl; |
| 1610 |
if (bPara) |
| 1611 |
{
|
| 1612 |
wrk.Style.BackColor = CommonDefine.s_clrNormal; |
| 1613 |
} |
| 1614 |
else |
| 1615 |
{
|
| 1616 |
wrk.Style.BackColor = CommonDefine.s_clrError; |
| 1617 |
wrk.Selected = true; |
| 1618 |
} |
| 1619 |
} |
| 1620 |
else if (objCtrl.GetType().Equals(typeof(ComboBoxEX))) |
| 1621 |
{
|
| 1622 |
ComboBox wrk = (ComboBox)objCtrl; |
| 1623 |
if (bPara) |
| 1624 |
{
|
| 1625 |
wrk.BackColor = CommonDefine.s_clrNormal; |
| 1626 |
} |
| 1627 |
else |
| 1628 |
{
|
| 1629 |
wrk.BackColor = CommonDefine.s_clrError; |
| 1630 |
wrk.Focus(); |
| 1631 |
} |
| 1632 |
} |
| 1633 |
else if (objCtrl.GetType().Equals(typeof(ComboBox))) |
| 1634 |
{
|
| 1635 |
ComboBox wrk = (ComboBox)objCtrl; |
| 1636 |
if (bPara) |
| 1637 |
{
|
| 1638 |
wrk.BackColor = CommonDefine.s_clrNormal; |
| 1639 |
} |
| 1640 |
else |
| 1641 |
{
|
| 1642 |
wrk.BackColor = CommonDefine.s_clrError; |
| 1643 |
wrk.Focus(); |
| 1644 |
} |
| 1645 |
} |
| 1646 |
else if (objCtrl.GetType().Equals(typeof(ListBox))) |
| 1647 |
{
|
| 1648 |
ListBox wrk = (ListBox)objCtrl; |
| 1649 |
if (bPara) |
| 1650 |
{
|
| 1651 |
wrk.BackColor = CommonDefine.s_clrNormal; |
| 1652 |
} |
| 1653 |
else |
| 1654 |
{
|
| 1655 |
wrk.BackColor = CommonDefine.s_clrError; |
| 1656 |
wrk.Focus(); |
| 1657 |
} |
| 1658 |
} |
| 1659 |
else if (objCtrl.GetType().Equals(typeof(Label))) |
| 1660 |
{
|
| 1661 |
Label wrk = (Label)objCtrl; |
| 1662 |
if (bPara) |
| 1663 |
{
|
| 1664 |
wrk.BackColor = CommonDefine.s_clrNormal; |
| 1665 |
} |
| 1666 |
else |
| 1667 |
{
|
| 1668 |
wrk.BackColor = CommonDefine.s_clrError; |
| 1669 |
} |
| 1670 |
} |
| 1671 |
} |
| 1672 |
|
| 1673 |
#endregion |
| 1674 |
|
| 1675 |
#region 特殊操作 |
| 1676 |
#region 営業期数より工事年を取得する |
| 1677 |
/// <summary> |
| 1678 |
/// 営業期数より工事年を取得する |
| 1679 |
/// </summary> |
| 1680 |
/// <param name="Period"></param> |
| 1681 |
/// <returns></returns> |
| 1682 |
public static int BusinessPeriodToConstructionYears(int Period) |
| 1683 |
{
|
| 1684 |
try |
| 1685 |
{
|
| 1686 |
int iYears = 0; |
| 1687 |
// 今期との差分を計算する |
| 1688 |
int diff = CommonMotions.SystemMasterData.BusinessPeriod - Period; |
| 1689 |
// 差分を使用して日付を作成する |
| 1690 |
DateTime wrkDate = DateTime.Now.AddYears(diff); |
| 1691 |
// 年を取得する |
| 1692 |
int iwrk = CommonMotions.cnvInt(CommonMotions.SystemMasterData.ConstructionBeginningDate.Substring(0, 2).ToString()); |
| 1693 |
iYears = wrkDate.FiscalYear(iwrk); |
| 1694 |
|
| 1695 |
return iYears; |
| 1696 |
} |
| 1697 |
catch (Exception ex) |
| 1698 |
{
|
| 1699 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 1700 |
return 0; |
| 1701 |
} |
| 1702 |
} |
| 1703 |
#endregion |
| 1704 |
|
| 1705 |
#region 発注者名を法人格を含んだ形で連結する |
| 1706 |
/// <summary> |
| 1707 |
/// 発注者名を法人格を含んだ形で連結する |
| 1708 |
/// </summary> |
| 1709 |
/// <param name="master"></param> |
| 1710 |
/// <returns></returns> |
| 1711 |
public static string OrderersNameUnion(OrderersMaster master) |
| 1712 |
{
|
| 1713 |
try |
| 1714 |
{
|
| 1715 |
string strRet = string.Empty; |
| 1716 |
|
| 1717 |
if (master.CorporateStatusPoint == (int)CommonDefine.StatusNamePoint.Forword) |
| 1718 |
strRet = master.CorporateStatusName + " " + master.OrderersName1 + " " + master.OrderersName2; |
| 1719 |
else if (master.CorporateStatusPoint == (int)CommonDefine.StatusNamePoint.Back) |
| 1720 |
strRet = master.OrderersName1 + " " + master.CorporateStatusName + " " + master.OrderersName2; |
| 1721 |
else |
| 1722 |
strRet = master.OrderersName1 + " " + master.OrderersName2; |
| 1723 |
|
| 1724 |
return strRet; |
| 1725 |
} |
| 1726 |
catch (Exception ex) |
| 1727 |
{
|
| 1728 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 1729 |
return string.Empty; |
| 1730 |
} |
| 1731 |
} |
| 1732 |
#endregion |
| 1733 |
|
| 1734 |
#region メッセージ送信メソッド(テキストボックス背景文字表示用) |
| 1735 |
/// <summary> |
| 1736 |
/// メッセージ送信メソッド |
| 1737 |
/// </summary> |
| 1738 |
/// <param name="hWnd"></param> |
| 1739 |
/// <param name="Msg"></param> |
| 1740 |
/// <param name="wParam"></param> |
| 1741 |
/// <param name="lParam"></param> |
| 1742 |
/// <returns></returns> |
| 1743 |
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
|
| 1744 |
public static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, string lParam); |
| 1745 |
#endregion |
| 1746 |
|
| 1747 |
#region ファイルの時間を取得する |
| 1748 |
/// <summary> |
| 1749 |
/// ファイルの時間を取得する |
| 1750 |
/// </summary> |
| 1751 |
/// <param name="FilePath">ファイルパス</param> |
| 1752 |
/// <param name="flg">取得日付フラグ</param> |
| 1753 |
/// <returns></returns> |
| 1754 |
public static DateTime GetFileTimeStamp(string FilePath, char flg) |
| 1755 |
{
|
| 1756 |
try |
| 1757 |
{
|
| 1758 |
DateTime dtDateTime = DateTime.MinValue; |
| 1759 |
|
| 1760 |
if (flg == 'C') |
| 1761 |
{
|
| 1762 |
// 作成日時を取得する |
| 1763 |
dtDateTime = File.GetCreationTime(@FilePath); |
| 1764 |
} |
| 1765 |
else if (flg == 'U') |
| 1766 |
{
|
| 1767 |
// 更新日時を取得する |
| 1768 |
dtDateTime = File.GetLastWriteTime(@FilePath); |
| 1769 |
} |
| 1770 |
else if (flg == 'A') |
| 1771 |
{
|
| 1772 |
// アクセス日時を取得する |
| 1773 |
dtDateTime = File.GetLastAccessTime(@FilePath); |
| 1774 |
} |
| 1775 |
|
| 1776 |
return dtDateTime; |
| 1777 |
} |
| 1778 |
catch (Exception ex) |
| 1779 |
{
|
| 1780 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 1781 |
return DateTime.Now; |
| 1782 |
} |
| 1783 |
} |
| 1784 |
#endregion |
| 1785 |
|
| 1786 |
#region ファイルパスよりmd5のハッシュ値を返す |
| 1787 |
/// <summary> |
| 1788 |
/// ファイルパスよりmd5のハッシュ値を返す |
| 1789 |
/// </summary> |
| 1790 |
/// <param name="FilePath"></param> |
| 1791 |
/// <returns></returns> |
| 1792 |
public static string GetFileHashData(string FilePath) |
| 1793 |
{
|
| 1794 |
try |
| 1795 |
{
|
| 1796 |
//ファイルを開く |
| 1797 |
FileStream fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read); |
| 1798 |
|
| 1799 |
//MD5CryptoServiceProviderオブジェクトを作成 |
| 1800 |
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); |
| 1801 |
|
| 1802 |
//ハッシュ値を計算する |
| 1803 |
byte[] bs = md5.ComputeHash(fs); |
| 1804 |
|
| 1805 |
//リソースを解放する |
| 1806 |
md5.Clear(); |
| 1807 |
//ファイルを閉じる |
| 1808 |
fs.Close(); |
| 1809 |
|
| 1810 |
return BitConverter.ToString(bs).ToLower().Replace("-", "");
|
| 1811 |
|
| 1812 |
} |
| 1813 |
catch (Exception ex) |
| 1814 |
{
|
| 1815 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 1816 |
return string.Empty; |
| 1817 |
} |
| 1818 |
} |
| 1819 |
#endregion |
| 1820 |
|
| 1821 |
#region 郵便番号より住所を検索する |
| 1822 |
/// <summary> |
| 1823 |
/// 郵便番号より住所を検索する |
| 1824 |
/// </summary> |
| 1825 |
/// <param name="ZipCode">郵便番号</param> |
| 1826 |
public static void SearchZipCode2Address(string ZipCode, ref string Address1, ref string Address2) |
| 1827 |
{
|
| 1828 |
Address1 = ""; //住所 |
| 1829 |
Address2 = ""; //住所 |
| 1830 |
|
| 1831 |
//処理時間を計測 |
| 1832 |
Stopwatch sw = new Stopwatch(); |
| 1833 |
//処理時間計測開始 |
| 1834 |
sw.Start(); |
| 1835 |
|
| 1836 |
// 郵便番号セット |
| 1837 |
string sKey = ZipCode; |
| 1838 |
|
| 1839 |
//文字列の前後のスペースをとる |
| 1840 |
sKey = sKey.Trim(' ');
|
| 1841 |
//Microsoft.VisualBasic名前空間のStrConv関数を使って、全角文字を半角文字に変換 |
| 1842 |
sKey = Strings.StrConv(sKey, VbStrConv.Narrow, 0); |
| 1843 |
|
| 1844 |
// 文字列の長さを取得する |
| 1845 |
int iLength = sKey.Length; |
| 1846 |
// '-'がある場合は先頭文字目の後から '-' を検索し、見つかった位置を取得する |
| 1847 |
int iFind = 0; |
| 1848 |
if ((iFind = sKey.IndexOf('-', 0)) != 0)
|
| 1849 |
{
|
| 1850 |
//左から3文字+"-"文字以降をtmpZip変数に代入 |
| 1851 |
sKey = sKey.Substring(0, 3) + sKey.Substring(iFind + 1); |
| 1852 |
} |
| 1853 |
try |
| 1854 |
{
|
| 1855 |
//StreamReaderオブジェクトの作成 |
| 1856 |
StreamReader sr = new StreamReader(@CommonDefine.s_AddressFilePath, Encoding.Default); |
| 1857 |
|
| 1858 |
//1行ずつ読み込み |
| 1859 |
string dat = ""; |
| 1860 |
while ((dat = sr.ReadLine()) != null) |
| 1861 |
{
|
| 1862 |
string tmpZip = ""; |
| 1863 |
|
| 1864 |
//カンマで区切られた文字列を取得 |
| 1865 |
string[] sbuf = dat.Split(',');
|
| 1866 |
//配列の3番目が郵便番号 |
| 1867 |
tmpZip = sbuf[2].Trim('"');
|
| 1868 |
|
| 1869 |
//入力された郵便番号と比較 |
| 1870 |
if (sKey == tmpZip) |
| 1871 |
{
|
| 1872 |
//住所を作成 |
| 1873 |
//都道府県名+市区町村名+町域名 |
| 1874 |
Address1 = sbuf[6].Trim('"') + sbuf[7].Trim('"');
|
| 1875 |
Address2 = sbuf[8].Trim('"');
|
| 1876 |
|
| 1877 |
sw.Stop(); //処理時間計測終了 |
| 1878 |
|
| 1879 |
// 処理時間をTimeSpan構造体で書式付き表示 |
| 1880 |
TimeSpan ts = sw.Elapsed; |
| 1881 |
// 出力例:00:00:00.9984668 |
| 1882 |
logger.DebugFormat("処理時間:{0}", ts.ToString());
|
| 1883 |
|
| 1884 |
break; //ループを抜ける |
| 1885 |
} |
| 1886 |
Application.DoEvents(); |
| 1887 |
} |
| 1888 |
//ファイルを閉じる |
| 1889 |
sr.Close(); |
| 1890 |
} |
| 1891 |
catch (Exception ex) |
| 1892 |
{
|
| 1893 |
//ファイルエラーが発生した場合 |
| 1894 |
MessageBox.Show(ex.Message, "ファイルエラー", MessageBoxButtons.OK, MessageBoxIcon.Error); |
| 1895 |
//処理を抜ける |
| 1896 |
return; |
| 1897 |
} |
| 1898 |
} |
| 1899 |
#endregion |
| 1900 |
|
| 1901 |
#region 文字列より指定文字から後ろを省いて戻す |
| 1902 |
/// <summary> |
| 1903 |
/// 文字列より指定文字から後ろを省いて戻す |
| 1904 |
/// </summary> |
| 1905 |
/// <param name="Mijiretu"></param> |
| 1906 |
/// <param name="Delimiter"></param> |
| 1907 |
/// <returns></returns> |
| 1908 |
public static string ComentSucstring(string Mijiretu, string Delimiter) |
| 1909 |
{
|
| 1910 |
try |
| 1911 |
{
|
| 1912 |
if (Mijiretu.IndexOf(Delimiter) < 0) return Mijiretu; |
| 1913 |
|
| 1914 |
string strRet = Mijiretu.Substring(0, Mijiretu.IndexOf(Delimiter) - 1); |
| 1915 |
|
| 1916 |
return strRet; |
| 1917 |
} |
| 1918 |
catch (Exception ex) |
| 1919 |
{
|
| 1920 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 1921 |
return string.Empty; |
| 1922 |
} |
| 1923 |
} |
| 1924 |
#endregion |
| 1925 |
|
| 1926 |
#region 今の時間をセパレータを除いた文字列で戻す |
| 1927 |
/// <summary> |
| 1928 |
/// 今の時間をセパレータを除いた文字列で戻す |
| 1929 |
/// </summary> |
| 1930 |
/// <returns></returns> |
| 1931 |
public static string stringNowJikan() |
| 1932 |
{
|
| 1933 |
string[] wrk = DateTime.Now.ToShortDateString().Split('/');
|
| 1934 |
|
| 1935 |
string[] wrk2 = DateTime.Now.ToShortTimeString().Split(':');
|
| 1936 |
|
| 1937 |
return string.Format("{0}{1}{2}{3}{4}{5}"
|
| 1938 |
, wrk[0], wrk[1], wrk[2] |
| 1939 |
, wrk2[0], wrk2[1], wrk2[2]); |
| 1940 |
} |
| 1941 |
#endregion |
| 1942 |
|
| 1943 |
#region 経過時間を工数で返す |
| 1944 |
/// <summary> |
| 1945 |
/// 経過時間を工数で返す |
| 1946 |
/// </summary> |
| 1947 |
/// <param name="StartDate"></param> |
| 1948 |
/// <param name="CompDate"></param> |
| 1949 |
/// <returns></returns> |
| 1950 |
public static double DiffMounthTimes(DateTime StartDate, DateTime CompDate) |
| 1951 |
{
|
| 1952 |
// 差分計算 |
| 1953 |
TimeSpan DiffDate = CompDate.Subtract(StartDate); |
| 1954 |
// 当日までなので+1日する |
| 1955 |
TimeSpan wrkts = new TimeSpan(1, 0, 0, 0); |
| 1956 |
DiffDate = DiffDate + wrkts; |
| 1957 |
// 工数の最小単位で割って10分の1にする |
| 1958 |
return (((double)DiffDate.Days) / CommonDefine.s_ManHourUnitDays) / 10; |
| 1959 |
} |
| 1960 |
#endregion |
| 1961 |
|
| 1962 |
#region 文字列を指定文字で指定レングス分埋める |
| 1963 |
/// <summary> |
| 1964 |
/// 文字列を指定文字で指定レングス分埋める |
| 1965 |
/// </summary> |
| 1966 |
/// <param name="OrgString"></param> |
| 1967 |
/// <param name="SetLength"></param> |
| 1968 |
/// <param name="Before"></param> |
| 1969 |
/// <returns></returns> |
| 1970 |
public static string SetBlankString(string OrgString, string SetString, int SetLength, bool Before) |
| 1971 |
{
|
| 1972 |
try |
| 1973 |
{
|
| 1974 |
string strRet = string.Empty; |
| 1975 |
int stringLength = OrgString.Length; |
| 1976 |
|
| 1977 |
// 文字列を埋める |
| 1978 |
for (int i = 0; i < (SetLength - stringLength); i++) strRet += SetString; |
| 1979 |
|
| 1980 |
// 前か後か |
| 1981 |
if (Before) |
| 1982 |
{
|
| 1983 |
strRet = strRet + OrgString; |
| 1984 |
} |
| 1985 |
else |
| 1986 |
{
|
| 1987 |
strRet = OrgString + strRet; |
| 1988 |
} |
| 1989 |
|
| 1990 |
return strRet; |
| 1991 |
} |
| 1992 |
catch (Exception ex) |
| 1993 |
{
|
| 1994 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 1995 |
return string.Empty; |
| 1996 |
} |
| 1997 |
} |
| 1998 |
#endregion |
| 1999 |
|
| 2000 |
#region 現在年取得 |
| 2001 |
/// <summary> |
| 2002 |
/// 現在年を求める |
| 2003 |
/// </summary> |
| 2004 |
/// <param name="bPeriod"></param> |
| 2005 |
/// <param name="MinCode"></param> |
| 2006 |
/// <param name="MaxCode"></param> |
| 2007 |
public static int GetBaseCounstructionYear(bool bPeriod, int years) |
| 2008 |
{
|
| 2009 |
try |
| 2010 |
{
|
| 2011 |
int Beginning = 0; |
| 2012 |
int diffwork = 0; |
| 2013 |
string strwork = string.Empty; |
| 2014 |
if (bPeriod) |
| 2015 |
{ // ----- 営業期ベースの時
|
| 2016 |
|
| 2017 |
// 現在期との差分を求める |
| 2018 |
diffwork = years - CommonMotions.SystemMasterData.BusinessPeriod; |
| 2019 |
|
| 2020 |
// 期首月を取得する |
| 2021 |
strwork = CommonMotions.SystemMasterData.BusinessBeginningDate; |
| 2022 |
strwork = strwork.Substring(0, strwork.IndexOf("/"));
|
| 2023 |
} |
| 2024 |
else |
| 2025 |
{ // ----- 営業年度ベースの時
|
| 2026 |
|
| 2027 |
// 現在期との差分を求める |
| 2028 |
diffwork = years - CommonMotions.SystemMasterData.ConstructionYear; |
| 2029 |
|
| 2030 |
// 期首月を取得する |
| 2031 |
strwork = CommonMotions.SystemMasterData.ConstructionBeginningDate; |
| 2032 |
strwork = strwork.Substring(0, strwork.IndexOf("/"));
|
| 2033 |
} |
| 2034 |
|
| 2035 |
// 期首月を数値変換 |
| 2036 |
Beginning = CommonMotions.cnvInt(strwork); |
| 2037 |
|
| 2038 |
// 年数を求める |
| 2039 |
DateTime dateWork = DateTime.Now; |
| 2040 |
int nowMounth = DateTime.Now.Month; |
| 2041 |
// 期首月を境に年度を計算する |
| 2042 |
int iYear = 0; |
| 2043 |
if (nowMounth < Beginning) |
| 2044 |
iYear = dateWork.AddYears(-1).Year; |
| 2045 |
else |
| 2046 |
iYear = dateWork.Year; |
| 2047 |
|
| 2048 |
// ベース年を求める |
| 2049 |
return (iYear + diffwork); |
| 2050 |
} |
| 2051 |
catch (System.Exception ex) |
| 2052 |
{
|
| 2053 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 2054 |
return 0; |
| 2055 |
} |
| 2056 |
} |
| 2057 |
#endregion |
| 2058 |
|
| 2059 |
#region 期首の月日を取得する |
| 2060 |
/// <summary> |
| 2061 |
/// 期首の月日を取得する |
| 2062 |
/// </summary> |
| 2063 |
/// <param name="bPeriod"></param> |
| 2064 |
/// <param name="Mounth"></param> |
| 2065 |
/// <param name="Days"></param> |
| 2066 |
public static void GetBeginningMonthDay(bool bPeriod, ref int Mounth, ref int Days) |
| 2067 |
{
|
| 2068 |
try |
| 2069 |
{
|
| 2070 |
string strwork = string.Empty; |
| 2071 |
string strwork2 = string.Empty; |
| 2072 |
string strwork3 = string.Empty; |
| 2073 |
if (bPeriod) |
| 2074 |
{ // 営業期
|
| 2075 |
strwork = CommonMotions.SystemMasterData.BusinessBeginningDate; |
| 2076 |
} |
| 2077 |
else |
| 2078 |
{ // 工事年度
|
| 2079 |
strwork = CommonMotions.SystemMasterData.ConstructionBeginningDate; |
| 2080 |
} |
| 2081 |
strwork2 = strwork.Substring(0, strwork.IndexOf("/"));
|
| 2082 |
strwork3 = strwork.Substring(strwork.IndexOf("/") + 1, 2);
|
| 2083 |
Mounth = CommonMotions.cnvInt(strwork2); |
| 2084 |
Days = CommonMotions.cnvInt(strwork3); |
| 2085 |
|
| 2086 |
} |
| 2087 |
catch (System.Exception ex) |
| 2088 |
{
|
| 2089 |
logger.ErrorFormat("システムエラー:{0}:{1}", CommonMotions.GetMethodName(), ex.Message);
|
| 2090 |
} |
| 2091 |
} |
| 2092 |
#endregion |
| 2093 |
|
| 2094 |
#region TimeSpanから年数を取得する |
| 2095 |
/// <summary> |
| 2096 |
/// TimeSpanから年数を取得する |
| 2097 |
/// </summary> |
| 2098 |
/// <param name="timespan"></param> |
| 2099 |
/// <returns></returns> |
| 2100 |
public static int GetTimeSpanYears(this TimeSpan timespan) |
| 2101 |
{
|
| 2102 |
return (int)((double)timespan.Days / 365.2425); |
| 2103 |
} |
| 2104 |
#endregion |
| 2105 |
|
| 2106 |
#region TimeSpanから月数を取得する |
| 2107 |
/// <summary> |
| 2108 |
/// TimeSpanから月数を取得する |
| 2109 |
/// </summary> |
| 2110 |
/// <param name="timespan"></param> |
| 2111 |
/// <returns></returns> |
| 2112 |
public static int GetTimeSpanMonths(this TimeSpan timespan) |
| 2113 |
{
|
| 2114 |
return (int)((double)timespan.Days / 30.436875); |
| 2115 |
} |
| 2116 |
#endregion |
| 2117 |
#endregion |
| 2118 |
|
| 2119 |
#region Excel向け操作メソッド |
| 2120 |
#region オブジェクト開放 |
| 2121 |
/// <summary> |
| 2122 |
/// Com解放 |
| 2123 |
/// </summary> |
| 2124 |
/// <param name="o"></param> |
| 2125 |
public static void ReleaseCom(ref Object objCom) |
| 2126 |
{
|
| 2127 |
try |
| 2128 |
{
|
| 2129 |
int i = 1; |
| 2130 |
if (objCom != null && System.Runtime.InteropServices.Marshal.IsComObject(objCom)) |
| 2131 |
{
|
| 2132 |
//参照カウントが0より大きい間・・・ |
| 2133 |
do |
| 2134 |
{
|
| 2135 |
//ランタイム呼び出し可能ラッパーの参照カウントをデクリメント |
| 2136 |
i = System.Runtime.InteropServices.Marshal.ReleaseComObject(objCom); |
| 2137 |
} while (i > 0); |
| 2138 |
} |
| 2139 |
} |
| 2140 |
catch (Exception ex) |
| 2141 |
{
|
| 2142 |
logger.ErrorFormat("システムエラー:{0}:{1}:{2}", GetMethodName(), GetMethodName(2), ex.Message);
|
| 2143 |
} |
| 2144 |
finally |
| 2145 |
{
|
| 2146 |
objCom = null; |
| 2147 |
} |
| 2148 |
} |
| 2149 |
|
| 2150 |
#endregion |
| 2151 |
#endregion |
| 2152 |
|
| 2153 |
#region デバッグ用メソッド |
| 2154 |
/// <summary> |
| 2155 |
/// デバッグ用メソッド |
| 2156 |
/// </summary> |
| 2157 |
/// <param name="DebugPrint">表示文字列</param> |
| 2158 |
public static void DebugWriteLine_TimeNow(string DebugPrint) |
| 2159 |
{
|
| 2160 |
string wrkPrint = DateTime.Now.ToLongTimeString() + |
| 2161 |
((double)DateTime.Now.Millisecond / 1000.0000).ToString("#.0000");
|
| 2162 |
|
| 2163 |
Debug.WriteLine(DebugPrint + ":" + wrkPrint); |
| 2164 |
} |
| 2165 |
|
| 2166 |
public static void DebugWriteLine_DateTimeNow(string DebugPrint) |
| 2167 |
{
|
| 2168 |
string wrkPrint = DateTime.Now.ToLongDateString() + " " + |
| 2169 |
DateTime.Now.ToLongTimeString() + "." + |
| 2170 |
DateTime.Now.Millisecond.ToString(); |
| 2171 |
|
| 2172 |
Debug.WriteLine(DebugPrint + ":" + wrkPrint); |
| 2173 |
} |
| 2174 |
#endregion |
| 2175 |
} |
| 2176 |
} |