/// <summary> /// チェックサム /// </summary> /// <param name="chkInfo">検査情報</param> /// <param name="item">検査対象</param> private bool checkSum(ChecklistInfo chkInfo, OcrEdit item) { if (chkInfo.DataType != Definition.DataType.Numeric) { return(true); } int result; if (!int.TryParse(item.CorrectedString, out result)) { return(true); } if (chkInfo.ChecksumInspectionFlag == true) { int sum = 0; int itemLength = item.CorrectedString.Length; int checkSum = int.Parse(item.CorrectedString.Substring(itemLength - 1)); // 末尾桁以外の数字の合計値を求める for (int i = 0; i < itemLength - 1; i++) { int x = int.Parse(item.CorrectedString.Substring(i, 1)); sum += x; } if (sum % 10 != checkSum) { setErrMessage(item, DenshowCommon.Message.EP089); return(false); } } return(true); }
/// <summary> /// OMR範囲検査 /// </summary> /// <param name="chkInfo">検査情報</param> /// <param name="ocrEdit">検査対象</param> private bool checkOmrRange(ChecklistInfo chkInfo, OcrEdit ocrEdit) { bool result = true; if (ocrEdit.ItemKind == Definition.ItemKind.OMR) { int count = this.getOmrGroupCount(ocrEdit); //0,1以外の値の入力チェック bool isNotBitOnly = ocrEdit.CorrectedString.Any(x => x != '0' && x != '1'); //0,1の値がある或いは桁数不正の場合 if (isNotBitOnly || ocrEdit.CorrectedString.Length != count) { setErrMessage(ocrEdit, DenshowCommon.Message.EC002); result = false; } //マック数を取得する int markCount = ocrEdit.CorrectedString.Count(x => x == '1'); if (chkInfo.MarkCheckMinValue > 0 || chkInfo.MarkCheckMaxValue > 0) {//最小・最大範囲値がどちらも0の場合は、チェック対象外。 if (markCount < chkInfo.MarkCheckMinValue || markCount > chkInfo.MarkCheckMaxValue) { setErrMessage(ocrEdit, DenshowCommon.Message.EP087); result = false; } } } return(result); }
/// <summary> /// 範囲チェック /// </summary> /// <param name="chkInfo">検査情報</param> /// <param name="item">検査対象</param> /// <returns></returns> private bool checkRange(ChecklistInfo chkInfo, OcrEdit item) { //両方とも設定されていない場合、チェック対象外 if (!chkInfo.RangeCheckMinValue.HasValue && !chkInfo.RangeCheckMaxValue.HasValue) { return(true); } //両方とも0の場合、チェック対象外 if (chkInfo.RangeCheckMinValue == 0 && chkInfo.RangeCheckMaxValue == 0) { return(true); } //型変換失敗する場合、他のチェックで行うので、範囲チェックを通る int value = 0; if (int.TryParse(item.CorrectedString, out value)) { if (value < chkInfo.RangeCheckMinValue || value > chkInfo.RangeCheckMaxValue) { setErrMessage(item, DenshowCommon.Message.EP147); return(false); } } return(true); }
/// <summary> /// 該当帳票認識結果項目のチェックリストグループ情報を取得する /// </summary> /// <param name="editItem"></param> /// <returns></returns> private ChecklistInfo getChecklistInfo(OcrEdit editItem) { ChecklistInfo clItem = (from x in this.checklistInfoList where x.ClId == editItem.ClId && x.ClGroupId == editItem.ClGroupId select x).First(); return(clItem); }
/// <summary> /// グループ項目の件数を取得する /// </summary> /// <returns></returns> private int getOmrGroupCount(OcrEdit editItem) { int count = (from x in this.ocrEditList where (x.PageNo == editItem.PageNo) && (x.ClId == editItem.ClId) && (x.ClGroupId == editItem.ClGroupId) && (x.ItemKind == Definition.ItemKind.PICTURE) select x).Count(); return(count); }
/// <summary> /// 該当帳票認識結果項目のマスタ参照情報を取得する /// </summary> /// <param name="editItem"></param> /// <returns></returns> private List <MasterReference> GetMasterReference(OcrEdit editItem) { List <MasterReference> masterInfos = (from x in this.masterReferenceList where x.ClId == editItem.ClId && x.ClGroupId == editItem.ClGroupId orderby x.RowNo select x).ToList(); return(masterInfos); }
/// <summary> /// エラーメッセージを設定する /// </summary> /// <param name="ocrEdit">検査対象</param> /// <param name="errMessage">エラーメッセージ</param> private void setErrMessage(OcrEdit ocrEdit, string errMessage) { if (string.IsNullOrEmpty(ocrEdit.ErrMessage)) { ocrEdit.ErrMessage = errMessage; } else { ocrEdit.ErrMessage += Environment.NewLine; ocrEdit.ErrMessage += errMessage; } }
/// <summary> /// 未記入検査 /// </summary> /// <param name="chkInfo">検査情報</param> /// <param name="ocrEdit">検査対象</param> /// <returns> /// 戻り値:True:OK / False:NG /// </returns> private bool checkBlank(ChecklistInfo chkInfo, OcrEdit ocrEdit) { if (chkInfo.BlankInspectionFlag.HasValue && chkInfo.BlankInspectionFlag.Value) { if (string.IsNullOrEmpty(ocrEdit.CorrectedString)) { setErrMessage(ocrEdit, DenshowCommon.Message.EC001); return(false); } } return(true); }
/// <summary> /// グループ項目の桁数の合計値を取得する /// </summary> /// <returns></returns> private int getRcDigit(OcrEdit editItem) { int rcDigit = (from x in this.checklistInfoList where x.ClId == editItem.ClId && x.ClGroupId == editItem.ClGroupId && x.ItemKind == Definition.ItemKind.PICTURE select x.RcDigit).Sum(digit => { int ret = 0; return(int.TryParse(digit, out ret) ? ret : 0); }); return(rcDigit); }
/// <summary> /// 桁数検査 /// </summary> /// <param name="chkInfo">検査情報</param> /// <param name="ocrEdit">検査対象</param> private bool checkDigit(ChecklistInfo chkInfo, OcrEdit ocrEdit) { if (chkInfo.DigitInspectionFlag.HasValue && chkInfo.DigitInspectionFlag.Value) { int rcDigit = this.getRcDigit(ocrEdit); if (ocrEdit.CorrectedString.Length != rcDigit) { setErrMessage(ocrEdit, DenshowCommon.Message.EP088); return(false); } } return(true); }
/// <summary> /// マスタ参照検査 /// </summary> /// <param name="chkInfo">検査情報</param> /// <param name="ocrEdit">検査対象</param> private bool checkMasterReference(ChecklistInfo chkInfo, OcrEdit ocrEdit) { if (!ocrEdit.MasterReferenceFlag) { return(true); } //条件項目のコレクション List <OcrEdit> conditionItemList = new List <OcrEdit>(); try { //関連するマスタ参照設定を取得する List <MasterReference> conditions = this.GetMasterReference(ocrEdit); //マスタ参照コントロールのインスタンスを生成する MasterReferenceControl masterCtrl = new MasterReferenceControl(); //参照値を取得する string referValue = masterCtrl.GetReference(chkInfo, conditions, //グループ項目の値を取得するデリゲートを渡す new MasterReferenceControl.GetValueHandler((clId, groupId) => { OcrEdit targetItem = this.getEditItem(ocrEdit.PageNo, clId, groupId); if (!conditionItemList.Contains(targetItem)) { conditionItemList.Add(targetItem); } return(getValueForSql(targetItem)); }) ); //マスタ参照値を設定する ocrEdit.CorrectedString = referValue; ocrEdit.changeFlag = true; return(true); } catch (DenshowBusinessException ex) { if (conditionItemList.Count > 0) { //条件項目がある場合、条件項目にエラーメッセージを設定する foreach (OcrEdit editItem in conditionItemList) { setErrMessage(editItem, ex.Message); } } else { //条件項目がない場合、対象項目にエラーメッセージを設定する setErrMessage(ocrEdit, ex.Message); } return(false); } }
/// <summary> /// 指定グループIDの検査項目を取得する /// </summary> /// <param name="pageNo">ページ番号</param> /// <param name="clId">チェックリストID</param> /// <param name="groupId">グループID</param> /// <returns>指定グループIDの検査項目の値</returns> private OcrEdit getEditItem(int pageNo, string clId, string groupId) { try { OcrEdit value = (from x in this.ocrEditList where (x.PageNo == pageNo) && (x.ClId == clId) && (x.ClGroupId == groupId) && (x.IsCheckItem) select x).Single(); return(value); } catch { //定義式に存在しないグループコードがある場合 throw new DenshowBusinessException(string.Format(Message.EP130, groupId)); } }
/// <summary> /// SQL検索用項目の値を取得する /// </summary> /// <returns></returns> private string getValueForSql(OcrEdit item) { switch (item.DataType) { case Definition.DataType.Numeric: //数値型 int?intVal = this.getNumValue(item.CorrectedString); if (intVal.HasValue) { return(intVal.Value.ToString()); } return(item.CorrectedString); case Definition.DataType.Date: //日付型 DateTime?dateVal = getDateValue(item.CorrectedString); if (dateVal.HasValue) { return(dateVal.Value.ToString("yyyy/MM/dd")); } else { return(item.CorrectedString); } case Definition.DataType.Time: //時間型 DateTime?timeVal = getTimeValue(item.CorrectedString); if (timeVal.HasValue) { return(timeVal.Value.ToString("HH:mm")); } else { return(item.CorrectedString); } default: //文字型 return(item.CorrectedString); } }
/// <summary> /// 型検査 /// </summary> /// <param name="chkInfo">検査情報</param> /// <param name="ocrEdit">検査対象</param> private bool checkDataType(ChecklistInfo chkInfo, OcrEdit ocrEdit) { if (string.IsNullOrEmpty(ocrEdit.CorrectedString)) { return(true); } if (chkInfo.DataType == Definition.DataType.Numeric) { // 数値形式検査 if (!checkNum(ocrEdit.CorrectedString)) { setErrMessage(ocrEdit, DenshowCommon.Message.EP084); return(false); } } if (chkInfo.DataType == Definition.DataType.Date) { // 日付形式検査 if (!checkDate(ocrEdit.CorrectedString)) { setErrMessage(ocrEdit, DenshowCommon.Message.EP085); return(false); } } if (chkInfo.DataType == Definition.DataType.Time) { // 時刻形式検査 if (!checkTime(ocrEdit.CorrectedString)) { setErrMessage(ocrEdit, DenshowCommon.Message.EP086); return(false); } } return(true); }
/// <summary> /// 論理式を解析する /// </summary> /// <param name="expressType">論理演算式の種別</param> /// <param name="expression">論理演算式</param> /// <param name="ocrEdit">検査対象</param> /// <returns>解析した結果</returns> private FormulaResult createFormula(ExpressionChecker.ExpressType expressType, string expression, OcrEdit ocrEdit) { FormulaResult result = new FormulaResult(); ExpressionChecker expressChecker = new ExpressionChecker(expression, expressType, new ExpressionChecker.GetValueHandler(groupId => { return(this.getGroupValue(ocrEdit.PageNo, ocrEdit.ClId, groupId)); })); try { result.Value = expressChecker.Compute(); result.HasInput = expressChecker.HasInput; return(result); } catch (Exception) { //エラーの場合NULLで設定する result.Value = null; result.HasInput = expressChecker.HasInput; return(result); } }
/// <summary> /// 論理演算検査 /// </summary> /// <param name="chkInfo">検査情報</param> /// <param name="ocrEdit">検査対象</param> private bool checkLogicalOperation(ChecklistInfo chkInfo, OcrEdit ocrEdit) { FormulaResult expressResult = null; if (string.IsNullOrEmpty(chkInfo.DefinitionExpression)) { return(true); } // 日付妥当性検査 if (chkInfo.DateValidationFlag.HasValue && chkInfo.DateValidationFlag.Value) { //定義式(日付計算) expressResult = this.createFormula(ExpressionChecker.ExpressType.CalcDate, chkInfo.DefinitionExpression, ocrEdit); // 結果式を解析 FormulaResult resultExpression = createFormula(ExpressionChecker.ExpressType.CalcNumeric, chkInfo.ResultExpression, ocrEdit); if (!expressResult.HasInput && !resultExpression.HasInput) { //未入力場合通る return(true); } //演算結果null及び一致しない場合エラーになる if ((expressResult.Value == null) || (resultExpression == null) || (expressResult.Value != resultExpression.Value)) { string result = string.Format(ValidateResultMsg, expressResult.Value, resultExpression.Value); string errMsg = string.Format(DenshowCommon.Message.EP091, result); setErrMessage(ocrEdit, errMsg); return(false); } return(true); } // 時間妥当性検査 if (chkInfo.TimeValidationFlag.HasValue && chkInfo.TimeValidationFlag.Value) { //定義式(時間計算) expressResult = this.createFormula(ExpressionChecker.ExpressType.CalcTime, chkInfo.DefinitionExpression, ocrEdit); // 結果式を解析 FormulaResult resultExpression = createFormula(ExpressionChecker.ExpressType.CalcNumeric, chkInfo.ResultExpression, ocrEdit); if (!expressResult.HasInput && !resultExpression.HasInput) { //未入力場合通る return(true); } //演算結果null及び一致しない場合エラーになる if ((expressResult.Value == null) || (resultExpression == null) || (expressResult.Value != resultExpression.Value)) { string result = string.Format(ValidateResultMsg, expressResult.Value, resultExpression.Value); string errMsg = string.Format(DenshowCommon.Message.EP091, result); setErrMessage(ocrEdit, errMsg); return(false); } return(true); } // 数値妥当性検査 if (chkInfo.NumberValidationFlag.HasValue && chkInfo.NumberValidationFlag.Value) { //定義式(時間計算) expressResult = this.createFormula(ExpressionChecker.ExpressType.CalcNumeric, chkInfo.DefinitionExpression, ocrEdit); // 結果式を解析 FormulaResult resultExpression = createFormula(ExpressionChecker.ExpressType.CalcNumeric, chkInfo.ResultExpression, ocrEdit); if (!expressResult.HasInput && !resultExpression.HasInput) { //未入力場合通る return(true); } //演算結果null及び一致しない場合エラーになる if ((expressResult.Value == null) || (resultExpression == null) || (expressResult.Value != resultExpression.Value)) { string result = string.Format(ValidateResultMsg, expressResult.Value, resultExpression.Value); string errMsg = string.Format(DenshowCommon.Message.EP091, result); setErrMessage(ocrEdit, errMsg); return(false); } return(true); } // 日付形式検査 if (chkInfo.DateFormatCheckFlag.HasValue && chkInfo.DateFormatCheckFlag.Value) { expressResult = this.createFormula(ExpressionChecker.ExpressType.CheckDate, chkInfo.DefinitionExpression, ocrEdit); if (expressResult.HasInput && !checkDate(expressResult.Value)) { string result = string.Format(CheckExpResultMsg, expressResult.Value); string errMsg = string.Format(DenshowCommon.Message.EP091, result); setErrMessage(ocrEdit, errMsg); return(false); } return(true); } // 時刻形式検査 if (chkInfo.TimeFormatCheckFlag.HasValue && chkInfo.TimeFormatCheckFlag.Value) { expressResult = this.createFormula(ExpressionChecker.ExpressType.CheckTime, chkInfo.DefinitionExpression, ocrEdit); if (expressResult.HasInput && !checkTime(expressResult.Value)) { string result = string.Format(CheckExpResultMsg, expressResult.Value); string errMsg = string.Format(DenshowCommon.Message.EP091, result); setErrMessage(ocrEdit, errMsg); return(false); } return(true); } // 数値形式検査 if (chkInfo.NumberFormatCheckFlag.HasValue && chkInfo.NumberFormatCheckFlag.Value) { expressResult = this.createFormula(ExpressionChecker.ExpressType.CheckNumeric, chkInfo.DefinitionExpression, ocrEdit); if (expressResult.HasInput && !checkNum(expressResult.Value)) { string result = string.Format(CheckExpResultMsg, expressResult.Value); string errMsg = string.Format(DenshowCommon.Message.EP091, result); setErrMessage(ocrEdit, errMsg); return(false); } return(true); } return(true); }