Beispiel #1
0
        //────────────────────────────────────────

        /// <summary>
        /// 「E■@where」属性を解析します。
        ///
        /// 該当しないレコードは除去していきます。
        /// </summary>
        /// <param name="srcRow"></param>
        /// <param name="tableH_Source"></param>
        /// <param name="groupLogic"></param>
        /// <param name="reccondList"></param>
        /// <param name="log_Reports"></param>
        /// <returns>ロジックの真偽。</returns>
        private static bool ApplyReccond(
            DataRow srcRow,
            Table_Humaninput tableH_Source,
            EnumLogic parent_EnumLogic,
            List <Recordcondition> list_Reccond,//「E■@where」または「E■rec-cond」。子要素を持たないか、子要素に「E■rec-cond」を持つものとする。
            int nCount_Recursive_Debug,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

            log_Method.BeginMethod(Info_Table.Name_Library, "Util_Table", "ApplyReccond", log_Reports);

            //
            //
            //
            //

            bool   bResult;
            string err_SField;
            int    nDebug_ChildIndex = 0;

            if (EnumLogic.Or == parent_EnumLogic)
            {
                // 1つも真がなければ、偽。
                bResult = false;
            }
            else if (EnumLogic.And == parent_EnumLogic)
            {
                // 1つも偽がなければ、真。
                bResult = true;
            }
            else
            {
                // 条件による。条件が1つもなければ真。
                bResult = true;
            }

            foreach (Recordcondition childReccond in list_Reccond)
            {
                //
                // "and" と有れば、条件に合わなかった場合 false。
                // "or" と有れば、
                //

                if (EnumLogic.None != childReccond.EnumLogic)
                {
                    // andグループ、orグループなら。

                    bool bChildHit = Utility_Table.ApplyReccond(srcRow, tableH_Source, childReccond.EnumLogic, childReccond.List_Child, nCount_Recursive_Debug + 1, log_Reports);

                    if (EnumLogic.And == parent_EnumLogic)
                    {
                        if (bChildHit)
                        {
                            // そのまま。
                            //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件内のグループで真 [" + bChildHit + "→真なのでそのまま " + bResult + "=True] Reccond=[" + childReccond.ToString() + "] 子が真なので変化なし。");
                        }
                        else
                        {
                            // 1つでも偽があれば、偽。
                            //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件内のグループで偽 [" + bChildHit + "→偽なので確定偽に " + bResult + "=False] Reccond=[" + childReccond.ToString() + "] 子に偽があるので偽。");
                            bResult = false;
                            goto gt_EndMethod;
                        }
                    }
                    else if (EnumLogic.Or == parent_EnumLogic)
                    {
                        if (bChildHit)
                        {
                            // 1つでも真があれば、真。
                            //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") OR条件内のグループで真 [" + bChildHit + "→真なので確定真に " + bResult + "=True] Reccond=[" + childReccond.ToString() + "] 子に真があるので真。");
                            bResult = true;
                            goto gt_EndMethod;
                        }
                        else
                        {
                            // そのまま。
                            //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") OR条件内のグループで偽 [" + bChildHit + "→偽なのでそのまま "+ bResult + "=False] Reccond=[" + childReccond.ToString() + "] 子が偽なので変化なし。");
                        }
                    }
                    else
                    {
                        // #TODO:エラー
                        System.Console.WriteLine(Info_Table.Name_Library + ":Util_Table.ApplyWhere: 不明ロジック[" + parent_EnumLogic + "]");
                    }
                }
                else
                {
                    // 条件なら。



                    // このレコードについて判定。
                    if (!tableH_Source.DataTable.Columns.Contains(childReccond.Name_Field))
                    {
                        // エラー
                        err_SField = childReccond.Name_Field;
                        goto gt_Error_MissField;
                    }

                    int              nFieldIx = tableH_Source.DataTable.Columns.IndexOf(childReccond.Name_Field);
                    Fielddefinition  o_FldDef = tableH_Source.RecordFielddefinition.ValueAt(nFieldIx);
                    Value_Humaninput o_Value  = (Value_Humaninput)srcRow[nFieldIx];


                    // 型に合わせて値取得。
                    if (o_Value is Int_HumaninputImpl)
                    {
                        //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyWhere: intフィールド [" + sLogic + " " + sField + " " + sOpe + " " + sValue + "]");

                        int nFieldInt;
                        {
                            Int_HumaninputImpl.TryParse(
                                o_Value,
                                out nFieldInt,
                                EnumOperationIfErrorvalue.Spaces_To_Alt_Value,
                                -1,
                                log_Reports
                                );
                        }

                        int nExpectedInt;
                        {
                            bool bHit2 = int.TryParse(childReccond.Value, out nExpectedInt);
                            if (!bHit2 && log_Reports.CanCreateReport)
                            {
                                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                                r.SetTitle("▲エラー502!", log_Method);
                                r.Message = "int型に変換できませんでした。sValue=[" + childReccond.Value + "]";
                                log_Reports.EndCreateReport();
                            }
                        }


                        if (EnumLogic.Or == parent_EnumLogic)
                        {
                            switch (childReccond.EnumOpe)
                            {
                            case EnumOpe.Gteq:
                                // 「>=」

                                if (nFieldInt >= nExpectedInt)
                                {
                                    // セーフ

                                    // 1つでも真が確定なら、真。
                                    bResult = true;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "] 1つでも真なら真。");
                                    goto gt_EndMethod;
                                }
                                else
                                {
                                    // アウト

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "]");
                                }
                                break;

                            case EnumOpe.Gt:
                                // 「>」

                                if (nFieldInt > nExpectedInt)
                                {
                                    // セーフ

                                    // 1つでも真が確定なら、真。
                                    bResult = true;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "] 1つでも真なら真。");
                                    goto gt_EndMethod;
                                }
                                else
                                {
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "]");
                                }
                                break;

                            case EnumOpe.Lteq:
                                // 「<=」

                                if (nFieldInt <= nExpectedInt)
                                {
                                    // セーフ

                                    // 1つでも真が確定なら、真。
                                    bResult = true;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "] 1つでも真なら真。");
                                    goto gt_EndMethod;
                                }
                                else
                                {
                                    // アウト

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "]");
                                }
                                break;

                            case EnumOpe.Lt:
                                // 「<」

                                if (nFieldInt < nExpectedInt)
                                {
                                    // セーフ

                                    // 1つでも真が確定なら、真。
                                    bResult = true;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "] 1つでも真なら真。");
                                    goto gt_EndMethod;
                                }
                                else
                                {
                                    // アウト

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "]");
                                }
                                break;

                            case EnumOpe.Neq:
                                // 「!=」

                                if (nFieldInt != nExpectedInt)
                                {
                                    // セーフ

                                    // 1つでも真が確定なら、真。
                                    bResult = true;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "] 1つでも真なら真。");
                                    goto gt_EndMethod;
                                }
                                else
                                {
                                    // アウト

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "]");
                                }
                                break;

                            case EnumOpe.Eq:
                                // ""、"eq"、は eq扱い。

                                // 「=」
                                if (nFieldInt == nExpectedInt)
                                {
                                    // セーフ

                                    // 1つでも真が確定なら、真。
                                    bResult = true;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "] 1つでも真なら真。");
                                    goto gt_EndMethod;
                                }
                                else
                                {
                                    // アウト

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ")  OR条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "]");
                                }
                                break;
                            }
                        }
                        else if (EnumLogic.And == parent_EnumLogic)
                        {
                            switch (childReccond.EnumOpe)
                            {
                            case EnumOpe.Gteq:
                                // 「>=」

                                if (nFieldInt >= nExpectedInt)
                                {
                                    // セーフ

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "]");
                                }
                                else
                                {
                                    // アウト

                                    // 1つでも偽が確定なら、偽。
                                    bResult = false;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "] 1つでも偽なら偽。");
                                    goto gt_EndMethod;
                                }
                                break;

                            case EnumOpe.Gt:
                                // 「>」

                                if (nFieldInt > nExpectedInt)
                                {
                                    // セーフ

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "]");
                                }
                                else
                                {
                                    // アウト

                                    // 1つでも偽が確定なら、偽。
                                    bResult = false;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "] 1つでも偽なら偽。");
                                    goto gt_EndMethod;
                                }
                                break;

                            case EnumOpe.Lteq:
                                // 「<=」

                                if (nFieldInt <= nExpectedInt)
                                {
                                    // セーフ

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "]");
                                }
                                else
                                {
                                    // アウト

                                    // 1つでも偽が確定なら、偽。
                                    bResult = false;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "] 1つでも偽なら偽。");
                                    goto gt_EndMethod;
                                }
                                break;

                            case EnumOpe.Lt:
                                // 「<」

                                if (nFieldInt < nExpectedInt)
                                {
                                    // セーフ

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "]");
                                }
                                else
                                {
                                    // アウト

                                    // 1つでも偽が確定なら、偽。
                                    bResult = false;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "] 1つでも偽なら偽。");
                                    goto gt_EndMethod;
                                }
                                break;

                            case EnumOpe.Neq:
                                // 「!=」

                                if (nFieldInt != nExpectedInt)
                                {
                                    // セーフ

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "]");
                                }
                                else
                                {
                                    // アウト

                                    // 1つでも偽が確定なら、偽。
                                    bResult = false;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "] 1つでも偽なら偽。");
                                    goto gt_EndMethod;
                                }
                                break;

                            case EnumOpe.Eq:
                                // ""、"eq"、は eq扱い。

                                // 「=」
                                if (nFieldInt == nExpectedInt)
                                {
                                    // セーフ

                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=True] Reccond=[" + childReccond.ToString() + "]");
                                }
                                else
                                {
                                    // アウト

                                    // 1つでも偽が確定なら、偽。
                                    bResult = false;
                                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.ApplyRecord: (" + debug_RecursiveCount + "." + debug_ChildIndex + ") AND条件[" + bResult + "=False] Reccond=[" + childReccond.ToString() + "] 1つでも偽なら偽。");
                                    goto gt_EndMethod;
                                }
                                break;
                            }
                        }
                        else
                        {
                            // #TODO:エラー
                            System.Console.WriteLine(Info_Table.Name_Library + ":Util_Table.ApplyWhere: 不明ロジック[" + parent_EnumLogic + "] nFieldIx=[" + nFieldIx + "] フィールド名=[" + o_FldDef.Name_Humaninput + "] [" + parent_EnumLogic + "][" + childReccond.Name_Field + " " + childReccond.EnumOpe + " " + childReccond.Value + "] objValueの型=[" + o_Value.GetType().Name + "]");
                        }
                    }
                    else
                    {
                        // #TODO:エラー
                        System.Console.WriteLine(Info_Table.Name_Library + ":Util_Table.ApplyWhere: 不明フィールド nFieldIx=[" + nFieldIx + "] フィールド名=[" + o_FldDef.Name_Humaninput + "] [" + parent_EnumLogic + "][" + childReccond.Name_Field + " " + childReccond.EnumOpe + " " + childReccond.Value + "] objValueの型=[" + o_Value.GetType().Name + "]");
                    }
                }//or,and,条件


                nDebug_ChildIndex++;
            }//for


            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
gt_Error_MissField:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー501!", log_Method);

                StringBuilder s = new StringBuilder();
                s.Append("<rec-cond>要素のfield属性エラー");
                s.Append(Environment.NewLine);
                s.Append("field=[");
                s.Append(err_SField);
                s.Append("]");

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(bResult);
        }
Beispiel #2
0
        //────────────────────────────────────────

        public void Judge(
            out bool isJudge,
            string name_KeyField,
            string value_Expected,
            bool isRequired_ExpectedValue,
            DataRow row,
            Configuration_Node parent_Query,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

            log_Method.BeginMethod(Info_Table.Name_Library, this, "Judge", log_Reports);

            //

            try
            {
                object obj = row[name_KeyField];

                if (obj is DBNull)
                {
                    isJudge = false;
                    goto gt_Error_DBNull;
                }

                Value_Humaninput valueH = (Value_Humaninput)obj;

                // (5)キーが空欄で、検索ヒット必須でなければ、無視します。【int型フィールドの場合】
                if (Int_HumaninputImpl.IsSpaces(valueH))
                {
                    isJudge = false;
                    goto gt_EndMethod;
                }


                // (6)この行の、キー_フィールドの値を取得。
                int keyValue;

                bool bParsedSuccessful = Int_HumaninputImpl.TryParse(
                    valueH,
                    out keyValue,
                    EnumOperationIfErrorvalue.Error,
                    null,
                    log_Reports
                    );

                if (log_Reports.Successful)
                {
                    if (!bParsedSuccessful)
                    {
                        isJudge = false;
                        if (log_Reports.CanCreateReport)
                        {
                            Log_RecordReports d_Report = log_Reports.BeginCreateReport(EnumReport.Error);
                            d_Report.SetTitle("▲エラー698!", log_Method);
                            d_Report.Message = "int型パース失敗。";
                            log_Reports.EndCreateReport();
                        }
                        goto gt_EndMethod;
                    }
                }



                // (7)キー値をint型に変換します。
                int expectedValue;
                if (log_Reports.Successful)
                {
                    bool bParseSuccessful2 = int.TryParse(value_Expected, out expectedValue);
                    if (!bParseSuccessful2)
                    {
                        isJudge = false;
                        if (isRequired_ExpectedValue)
                        {
                            goto gt_Error_Parse;
                        }

                        goto gt_EndMethod;
                    }
                }
                else
                {
                    expectedValue = 0;
                }



                if (log_Reports.Successful)
                {
                    // (8)該当行をレコードセットに追加。
                    if (keyValue == expectedValue)
                    {
                        //
                        // 該当行なら。
                        isJudge = true;
                    }
                    else
                    {
                        isJudge = false;
                    }
                }
                else
                {
                    isJudge = false;
                }
            }
            catch (RowNotInTableException)
            {
                // (9)指定行がなかった場合は、スルー。
                isJudge = false;

                //
                // 指定の行は、テーブルの中にありませんでした。
                // 再描画と、行の削除が被ったのかもしれません。
                // いわゆる「処理中」です。
                //

                //.WriteLine(this.GetType().Name+"#GetValueStringList: ["+refTable.Name+"]テーブルには、["+ttbwIndex+"]行が存在しませんでした。もしかすると、削除されたのかもしれません。エラー:"+e.Message);
            }

            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
gt_Error_DBNull:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー244!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Append("検索キーに指定した[");
                s.Append(name_KeyField);
                s.Append("]というフィールドは無いです。");
                s.Newline();

                // ヒント
                parent_Query.ToText_Locationbreadcrumbs(s);

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_Parse:
            // 空値ではダメという設定の場合。
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー287!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.AppendI(0, "<Select_KeyIntImplクラス>");
                s.Newline();

                s.AppendI(1, "これはint型値のプログラムです。他の型のプログラムを使ってください。");
                s.Newline();

                s.AppendI(1, "・ヒント:変数が見つからなかった場合もここに来ます。例えば、変数名「$aaa」を書こうとして、「aaa」と書いていませんか?");
                s.Newline();

                s.AppendI(1, "・ヒント:数値が大きすぎた場合もここに来ます。");
                s.Newline();

                s.AppendI(1, "sExpectedValue=[");
                s.Append(value_Expected);
                s.Append("]");
                s.Newline();
                s.Newline();

                //
                // ヒント
                parent_Query.ToText_Locationbreadcrumbs(s);

                s.AppendI(0, "</Select_KeyIntImplクラス>");
                s.Newline();

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
        }