// //別の場所にフォーカス移動された時 // public Boolean updCalendarLeave(string updCalendarLeave) { //日付チェック用 DateTime dateCheck = new DateTime(); bool modDay = true; strY = DateTime.Today.Year.ToString(); strM = "01"; Boolean blnDateCheck = false; //テキストデータの格納 string strDate = ""; //格納(エラー時に元に戻す用) string strDataPi = ""; //文字チェック,チェック用のLISTを作成 List <string> checklist = new List <string>(); //データを入れる配列 string[] strInData; //背景色を白にする this.BackColor = Color.White; //フォーカスが外れたのでリセット blnFirstClick = true; //何も書かれていない場合戻る if (updCalendarLeave == "") { blnDateCheck = true; return(blnDateCheck); } // //コピーペーストされた時のための数値チェック // if (!DateTime.TryParse(this.Text, out dateCheck)) // { // if (this.Parent is BaseForm) // { // //データ存在なしメッセージ(OK) // BaseMessageBox basemessagebox_Nodata = new BaseMessageBox(this.Parent, "", "数値を入力してください。", CommonTeisu.BTN_OK, CommonTeisu.DIAG_ERROR); // basemessagebox_Nodata.ShowDialog(); // } // else if (this.Parent.Parent is BaseForm) // { // //データ存在なしメッセージ(OK) // BaseMessageBox basemessagebox_Nodata = new BaseMessageBox(this.Parent.Parent, "", "数値を入力してください。", CommonTeisu.BTN_OK, CommonTeisu.DIAG_ERROR); // basemessagebox_Nodata.ShowDialog(); // } // blnDateCheck = true; ////ラベルセットのカーソル色が残るのを防ぐ ////しかしShift + Tabで移動した場合は二重になるため対応策が必要(加藤Prj_問題点課題管理表 No29) // SendKeys.Send("+{TAB}"); // return (blnDateCheck); // } //リストに追加 checklist.Add(this.Text); //テキストボックス内のチェック foreach (string Listvalue in checklist) { //「,]があった場合一度取り除く if (this.Text.Contains('.')) { strDataPi = this.Text; this.Text = this.Text.Replace(".", "/"); } } strInData = this.Text.Split('/'); if (strInData.Count() == 2) { strY = strInData[0]; modDay = false; //20~と付けるか否か if (strY.Length == 3) { strY = 2 + strY; } else if (strY.Length == 2) { int intY = int.Parse(strY); if (intY < 50) { strY = 20 + strY; } else { strY = 19 + strY; } } else if (strY.Length == 1) { strY = 200 + strY; } strM = strInData[1]; if (strM.Length == 1) { strM = strM.PadLeft(2, '0'); } } else if (strInData.Count() == 1) { if (strInData[0].Length > 4) { // 年部分取得 strY = strInData[0].Substring(0, strInData[0].Length - 2); modDay = false; //20~と付けるか否か if (strY.Length == 3) { strY = 2 + strY; } else if (strY.Length == 2) { int intY = int.Parse(strY); if (intY < 50) { strY = 20 + strY; } else { strY = 19 + strY; } } else if (strY.Length == 1) { strY = 200 + strY; } //月部のみを取り出す strM = strInData[0].Substring(strInData[0].Length - 2, 2); } else if (strInData[0].Length > 2) { //月部のみを取り出す strM = strInData[0].Substring(0, strInData[0].Length - 2); } else { //月部のみを取り出す strM = strInData[0].ToString(); if (strM.Length == 1) { strM = strM.PadLeft(2, '0'); } } } strDate = strY + "/" + strM; blnDateCheck = StringUtl.JudCalenderCheck(strDate); if (blnDateCheck == true) { this.Text = strDate; } else { if (strDataPi != "") { this.Text = strDataPi; } } if (modDay && !string.IsNullOrWhiteSpace(this.Text)) { this.Text = chkModDay(this.Text); } return(blnDateCheck); }
///<summary> /// chkDateYMDataFormat /// テキストボックス内の日付フォーマットをチェック及び再生成 /// 引数:日付フォーマット再生成済み日付文字列 エラーの場合、空を返す。 ///</summary> public string chkDateYMDataFormat(string strDateData) { bool modDay = true; strY = DateTime.Today.Year.ToString(); strM = "01"; Boolean blnDateCheck = false; //テキストデータの格納 string strDate = ""; //格納(エラー時に元に戻す用) string strDataPi = ""; //文字チェック,チェック用のLISTを作成 List <string> checklist = new List <string>(); //データを入れる配列 string[] strInData; //リストに追加 checklist.Add(strDateData); //テキストボックス内のチェック foreach (string Listvalue in checklist) { //「,]があった場合一度取り除く if (strDateData.Contains('.')) { strDataPi = strDateData; strDateData = strDateData.Replace(".", "/"); } } strInData = strDateData.Split('/'); if (strInData.Count() == 2) { strY = strInData[0]; modDay = false; //20~と付けるか否か if (strY.Length == 3) { strY = 2 + strY; } else if (strY.Length == 2) { int intY = int.Parse(strY); if (intY < 50) { strY = 20 + strY; } else { strY = 19 + strY; } } else if (strY.Length == 1) { strY = 200 + strY; } strM = strInData[1]; if (strM.Length == 1) { strM = strM.PadLeft(2, '0'); } } else if (strInData.Count() == 1) { if (strInData[0].Length > 4) { //月部のみを取り出す strY = strInData[0].Substring(0, strInData[0].Length - 2); modDay = false; //20~と付けるか否か if (strY.Length == 3) { strY = 2 + strY; } else if (strY.Length == 2) { int intY = int.Parse(strY); if (intY < 50) { strY = 20 + strY; } else { strY = 19 + strY; } } else if (strY.Length == 1) { strY = 200 + strY; } //月部のみを取り出す strM = strInData[0].Substring(strInData[0].Length - 2, 2); } else if (strInData[0].Length > 2) { //月部のみを取り出す strM = strInData[0].Substring(0, strInData[0].Length - 2); } else { //月部のみを取り出す strM = strInData[0].ToString(); if (strM.Length == 1) { strM = strM.PadLeft(2, '0'); } } } strDate = strY + "/" + strM; blnDateCheck = StringUtl.JudCalenderCheck(strDate); if (blnDateCheck == true) { strDateData = strDate; } else { if (strDataPi != "") { strDateData = strDataPi; } else { strDateData = ""; } } if (modDay && !string.IsNullOrWhiteSpace(strDateData)) { strDateData = chkModDay(strDateData); } return(strDateData); }
///<summary> /// chkDateDataFormat /// テキストボックス内の日付フォーマットをチェック及び再生成 /// 引数:日付フォーマット再生成済み日付文字列 エラーの場合、空を返す。 ///</summary> public string chkDateDataFormat(string strDateData) { strY = DateTime.Today.Year.ToString(); strM = DateTime.Today.Month.ToString(); strD = DateTime.Today.Day.ToString(); Boolean blnDateCheck = false; //テキストデータの格納 string strDate = ""; //格納(エラー時に元に戻す用) string strDataPi = ""; //文字チェック,チェック用のLISTを作成 List <string> checklist = new List <string>(); //データを入れる配列 string[] strInData; //リストに追加 checklist.Add(strDateData); //テキストボックス内のチェック foreach (string Listvalue in checklist) { //「,]があった場合一度取り除く if (strDateData.Contains('.')) { strDataPi = strDateData; strDateData = strDateData.Replace(".", "/"); } } strInData = strDateData.Split('/'); if (strInData.Count() == 3) { strY = strInData[0]; modDay = false; //20~と付けるか否か if (strY.Length == 3) { strY = 2 + strY; } else if (strY.Length == 2) { int intY = int.Parse(strY); if (intY < 50) { strY = 20 + strY; } else { strY = 19 + strY; } } else if (strY.Length == 1) { strY = 200 + strY; } strM = strInData[1]; if (strM.Length == 1) { strM = strM.PadLeft(2, '0'); } strD = strInData[2]; if (strD.Length == 1) { strD = strD.PadLeft(2, '0'); } } else if (strInData.Count() == 2) { strM = strInData[0]; if (strM.Length == 1) { strM = strM.PadLeft(2, '0'); } strD = strInData[1]; if (strD.Length == 1) { strD = strD.PadLeft(2, '0'); } } else if (strInData.Count() == 1) { if (strInData[0].Length > 4) { //月部のみを取り出す strY = strInData[0].Substring(0, strInData[0].Length - 4); modDay = false; //20~と付けるか否か if (strY.Length == 3) { strY = 2 + strY; } else if (strY.Length == 2) { int intY = int.Parse(strY); if (intY < 50) { strY = 20 + strY; } else { strY = 19 + strY; } } else if (strY.Length == 1) { strY = 200 + strY; } //月部のみを取り出す strM = strInData[0].Substring(strInData[0].Length - 4, 2); //日部のみを取り出す strD = strInData[0].Substring(strInData[0].Length - 2, 2); } else if (strInData[0].Length > 2) { //月部のみを取り出す strM = strInData[0].Substring(0, strInData[0].Length - 2); //日部のみを取り出す strD = strInData[0].Substring(strInData[0].Length - 2, 2); } else { //日部のみを取り出す strD = strInData[0].PadLeft(2, '0'); } } strDate = strY + "/" + strM + "/" + strD; blnDateCheck = StringUtl.JudCalenderCheck(strDate); if (blnDateCheck == true) { strDateData = strDate; } else { strDateData = ""; } if (modDay && !string.IsNullOrWhiteSpace(strDateData)) { strDateData = chkModDay(strDateData); //if (strDateData.CompareTo(DateTime.Now.ToString("yyyy/MM/dd")) < 0) //{ // DateTime d = DateTime.ParseExact(strDateData, "yyyy/MM/dd", null).AddYears(1); // if (d.ToString("yyyy/MM/01").CompareTo(DateTime.Now.AddMonths(6).ToString("yyyy/MM/01")) > 0) // { // d = d.AddYears(-1); // } // strDateData = d.ToString("yyyy/MM/dd"); //} } modDay = true; return(strDateData); }