/// <summary> /// 開始ボタン押下時 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStart_Click(object sender, EventArgs e) { if (this.chkExt.CheckedItems.Count == 0) { MessageBox.Show("検証する拡張子を1つ以上選択してください", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (System.IO.Directory.Exists(this.txtSrcFolder.Text) == false) { MessageBox.Show("対象のフォルダを指定してください", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (MessageBox.Show("テキストファイル内の全角・半角変換を行います" + Environment.NewLine + "(0~9→0~9、A~Z→A~Z、()→()、/→/)" + Environment.NewLine + "よろしいですか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } EnableControl(false); try { DateTime dtDate = DateTime.Now; string[] strExts = new string[0]; int iCount = 0; foreach (var strExt in this.chkExt.CheckedItems) { // CheckedListbox内のチェックの付いた値のみ配列に代入する iCount += 1; Array.Resize(ref strExts, iCount); strExts[iCount - 1] = (string)strExt; } var strFiles = DefaultModule.GetFilesMostDeep(this.txtSrcFolder.Text, strExts); foreach (var strFile in strFiles) { Application.DoEvents(); string strOutFile = System.IO.Path.GetDirectoryName(strFile) + "\\" + System.IO.Path.GetFileNameWithoutExtension(strFile) + "_" + dtDate.ToString("yyyyMMdd_HHmmss") + System.IO.Path.GetExtension(strFile); using (var sr = new System.IO.StreamReader(strFile, System.Text.Encoding.GetEncoding("Shift-JIS"))) { string strValue = sr.ReadToEnd(); using (var sw = new System.IO.StreamWriter(strOutFile, false, System.Text.Encoding.GetEncoding("Shift-JIS"))) { sw.Write(ConvertToNarrow(strValue)); } } } MessageBox.Show("テキストファイル内の全角・半角変換が終了しました", "確認", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { DefaultModule.OutputLogFile("発生場所:" + System.Reflection.MethodBase.GetCurrentMethod() + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace); MessageBox.Show("発生場所:" + System.Reflection.MethodBase.GetCurrentMethod() + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { EnableControl(true); } }
/// <summary> /// 開始ボタン押下時 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnStart_Click(object sender, EventArgs e) { try { if (this.chkExt.CheckedItems.Count == 0) { MessageBox.Show("検証する拡張子を1つ以上選択してください", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (System.IO.Directory.Exists(this.txtSrcFolder.Text) == false) { MessageBox.Show("対象の画像フォルダを指定してください", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (System.IO.Directory.Exists(this.txtLogFolder.Text) == false) { MessageBox.Show("対象のログフォルダを指定してください", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (MessageBox.Show("イメージ破損チェックを開始します" + Environment.NewLine + "よろしいですか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No) { return; } EnableControl(false); this.lstResult.Items.Clear(); DefaultModule.WriteLstResult(this.lstResult, "画像フォルダ:" + this.txtSrcFolder.Text); DefaultModule.WriteLstResult(this.lstResult, "ログフォルダ:" + this.txtLogFolder.Text); DefaultModule.WriteLstResult(this.lstResult, "対象色:" + this.cpTargetColor.Value.ToString()); DefaultModule.WriteLstResult(this.lstResult, "エラーとするピクセル数:" + this.numPixel.Value); DefaultModule.WriteLstResult(this.lstResult, "走査方向:" + this.cmbDirection.SelectedItem); if (this.cmbDirection.SelectedIndex == 0) { // 縦 DefaultModule.WriteLstResult(this.lstResult, "起点横:" + this.numPointX.Value); } else { // 縦 DefaultModule.WriteLstResult(this.lstResult, "起点縦:" + this.numPointY.Value); } DefaultModule.WriteLstResult(this.lstResult, "イメージ破損チェック開始:" + this.txtLogFolder.Text); string dtDateTime = DateTime.Now.ToString("yyyyMMdd_HHmmss"); string strLogFile = this.txtLogFolder.Text + "\\" + dtDateTime + ".log"; string[] strExts = new string[0]; int iCount = 0; foreach (var strExt in this.chkExt.CheckedItems) { // CheckedListbox内のチェックの付いた値のみ配列に代入する iCount += 1; Array.Resize(ref strExts, iCount); strExts[iCount - 1] = (string)strExt; DefaultModule.WriteLstResult(this.lstResult, "対象画像形式:" + (string)strExt); } var strFiles = DefaultModule.GetFilesMostDeep(this.txtSrcFolder.Text, strExts); DefaultModule.WriteLstResult(this.lstResult, strFiles.Count() + "ファイル存在確認"); foreach (var strFile in strFiles) { Application.DoEvents(); if (blnAbort == true) { if (MessageBox.Show("処理を中止しますか?", "確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes) { blnAbort = false; DefaultModule.WriteLstResult(this.lstResult, "処理中断"); DefaultModule.OutputListLog(this.lstResult, strLogFile, System.Text.Encoding.GetEncoding("Shift-JIS")); return; } else { blnAbort = false; } } if (CheckCorrupt(strFile) == false) { DefaultModule.WriteLstResult(this.lstResult, "破損している可能性あり:" + strFile, DefaultModule.ResultMark.ErrorMark); continue; } else { DefaultModule.WriteLstResult(this.lstResult, "正常:" + strFile); } } DefaultModule.WriteLstResult(this.lstResult, "イメージ破損チェック終了"); DefaultModule.OutputListLog(this.lstResult, strLogFile, System.Text.Encoding.GetEncoding("Shift-JIS")); MessageBox.Show("イメージ破損チェックが終了しました", "確認", MessageBoxButtons.OK, MessageBoxIcon.Information); EnableControl(true); } catch (Exception ex) { DefaultModule.OutputLogFile("発生場所:" + System.Reflection.MethodBase.GetCurrentMethod() + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace); MessageBox.Show("発生場所:" + System.Reflection.MethodBase.GetCurrentMethod() + Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { EnableControl(true); } }