Example #1
0
        /// <summary>
        /// セレクト文を指定することで、レコードセットを取得。
        /// </summary>
        /// <param name="log_Reports"></param>
        /// <returns>該当がなければヌル。</returns>
        private RecordSet E_Execute_P2_Select(
            bool isExists_Awhr,
            Selectstatement selectSt,
            Configuration_Node parent_Conf_Query,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);
            log_Method.BeginMethod(Info_Expr.Name_Library, this, "E_Execute_P2_Select",log_Reports);
            //
            //

            RecordSet reslt_Rs;

            bool bLoad = false;

            // 一時記憶から、レコードセットのロードをするか否か。
            {
                {
                    Expression_Node_String ec_Awhr_RecordSetLoadFrom;//ソース情報利用
                    bool bHit = this.TrySelectAttribute(
                         out ec_Awhr_RecordSetLoadFrom,
                        NamesNode.S_RECORD_SET_LOAD_FROM,
                        EnumHitcount.One_Or_Zero,
                        log_Reports //null
                        );

                    selectSt.Expression_Where_RecordSetLoadFrom = ec_Awhr_RecordSetLoadFrom;
                }

                if ("" != selectSt.Expression_Where_RecordSetLoadFrom.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim())
                {
                    bLoad = true;
                }
            }

            // レコードセットの取得。
            if (bLoad)
            {
                // 一時記憶からロード。
                P1_RecordSetLoader sel1 = new P1_RecordSetLoader(this.Owner_MemoryApplication);
                reslt_Rs = sel1.P1_Load(
                    selectSt.Expression_Where_RecordSetLoadFrom,
                    this.Cur_Configuration,
                    log_Reports
                    );

                // ★空になってる。一時記憶から取り出したい。★★★★★★★★★★★★★★★★★★★★
                //p3_Selectstatement = recordSet.Selectstatement;
                // new SelectStateImpl(s_ParentNode);

                //
                // データベースからレコード検索。
                //p3_Selectstatement = this.E_Execute_P0(
                //    nWhere_recordSetLoadFrom,
                //    s_ParentNode,
                //    log_Reports
                //    );

                // debug: 一時記憶から読み取った、レコードセットの内容。
                //if (false)
                //{
                //    StringBuilder txt = new StringBuilder();

                //    txt.Append(Info_E.LibraryName + ":" + this.GetType().Name + "#E_Execute: (30_<f-cell>)【一時記憶から読み取った、レコードセットの内容(A)】");
                //    txt.Append(" fld=[" + recordSet.Selectstatement.E_Field.E_Execute( log_Reports) + "]");
                //    txt.Append(" lookup-value=[" + recordSet.Selectstatement.E_Value.E_Execute( log_Reports) + "]");
                //    txt.Append(" required=[" + recordSet.Selectstatement.E_Required.E_Execute( log_Reports) + "]");
                //    txt.Append(" from=[" + recordSet.Selectstatement.Expression_From.E_Execute( log_Reports) + "]");
                //    txt.Append(" description=[" + recordSet.Selectstatement.Expression_Description.E_Execute( log_Reports) + "]");
                //    txt.Append(" Storage=[" + recordSet.Selectstatement.Expression_Storage.E_Execute( log_Reports) + "]");
                //    txt.Append(" ヒット件数=[" + recordSet.O_Items.Count + "]");

                //    // レコードの内容
                //    foreach (Dictionary<string, Value_Humaninput> oRecord in recordSet.O_Items)
                //    {
                //        txt.Append(" フィールド数=[" + oRecord.Count + "]");
                //        foreach (string sKey in oRecord.Keys)
                //        {
                //            Value_Humaninput oValue = oRecord[sKey];
                //            txt.Append(" 要素=[" + sKey + ":"+ oValue.Humaninput + "]");
                //        }
                //    }

                //    //ystem.Console.WriteLine( txt.ToString() );
                //}

            }
            else
            {
                Table_Humaninput tableH = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(selectSt.Expression_From, true, log_Reports);
                if (null == tableH)
                {
                    // エラー。
                    reslt_Rs = null;
                    goto gt_Error_NullTable;
                }
                // レコードセットを用意。
                reslt_Rs = new RecordSetImpl(tableH);

                bool isRequired_ExpectedValue;
                {
                    bool parseSuccessful = bool.TryParse(selectSt.Required, out isRequired_ExpectedValue);
                }

                //
                // 検索実行。
                {
                    List<DataRow> dst_Row = new List<DataRow>();

                    //
                    // 条件
                    //
                    if (0 < selectSt.List_Recordcondition.Count)
                    {
                        // 条件が指定されている場合。

                        string name_KeyField;
                        Fielddefinition fielddefinition_Key;
                        string value_Expected;
                        P2_ReccondImpl sel2 = new P2_ReccondImpl();
                        sel2.GetFirstAwhrReccond(
                            out name_KeyField,
                            out fielddefinition_Key,
                            out value_Expected,
                            selectSt.List_Recordcondition,
                            tableH,
                            log_Reports
                            );

                        if (log_Reports.Successful)
                        {
                            // TODO:セル型でない場合、キーフィールド名がないこともある。

                            SelectPerformerImpl sp = new SelectPerformerImpl();
                            sp.Select(
                                out dst_Row,
                                name_KeyField,
                                value_Expected,
                                isRequired_ExpectedValue,
                                fielddefinition_Key,
                                tableH.DataTable,
                                parent_Conf_Query,
                                log_Reports
                                );
                        }
                    }
                    else
                    {
                        // 条件が指定されていない場合。

                        SelectPerformerImpl sp = new SelectPerformerImpl();
                        sp.Select(
                            out dst_Row,
                            isRequired_ExpectedValue,
                            tableH.DataTable,
                            parent_Conf_Query,
                            log_Reports
                            );
                    }

                    if (log_Reports.Successful)
                    {
                        reslt_Rs.AddList(dst_Row, log_Reports);
                    }

                    if (!log_Reports.Successful)
                    {
                        // 既エラー。
                        goto gt_EndMethod;
                    }

                }
            }

            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
            gt_Error_NullTable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Conf_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6019;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
            gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return reslt_Rs;
        }
Example #2
0
        //────────────────────────────────────────
        #endregion



        #region アクション
        //────────────────────────────────────────

        /// <summary>
        /// フィールドから値を取得。
        ///
        /// TODO:セルタイプ以外にも対応したい。
        /// </summary>
        /// <param name="RecordSet_toSave">ヌル不可</param>
        /// <param name="eSelectedFldName">選択フィールド</param>
        /// <param name="RecordSetSaveTo_or_null"></param>
        /// <param name="log_Reports"></param>
        /// <returns>行リスト<列リスト></returns>
        public List <List <string> > P5_Select_CellType(
            RecordSet dst_Rs_toSave,
            Selectstatement selectSt_ToSave,
            Expressionv_4ASelectRecord ecv_selRec_OrNull, //where
            Configuration_Node parent_Cf_Query,           //this
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);

            log_Method.BeginMethod(Info_Expr.Name_Library, this, "P5_Select", log_Reports);
            //
            //

            List <List <string> > reslt_sFieldListList = new List <List <string> >();



            //
            // (1)テーブル
            Table_Humaninput o_Table;

            {
                o_Table = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(
                    selectSt_ToSave.Expression_From, true, log_Reports);

                if (null == o_Table)
                {
                    // エラー。
                    goto gt_Error_NullTable;
                }
            }
            if (!log_Reports.Successful)
            {
                //
                // エラーが出ていたら、さっさと抜ける。
                goto gt_EndMethod;
            }


            //
            //
            //
            //
            // 条件
            //
            //
            //
            //
            Fielddefinition keyFldDefinition     = null;
            string          err_SSelectedFldName = null;
            Exception       err_Exception        = null;
            Recordcondition err_Recordcondition  = null;

            foreach (Recordcondition recCond in selectSt_ToSave.List_Recordcondition)
            {
                err_Recordcondition = recCond;

                //
                // (2)検索のキーフィールドの定義を調べます。

                // キーフィールド定義
                {
                    List <string> sList_KeyFldName;
                    {
                        // 要素数1個。
                        sList_KeyFldName = new List <string>();
                        sList_KeyFldName.Add(recCond.Name_Field);
                    }

                    RecordFielddefinition recordFielddefinition;
                    bool bHit = o_Table.TryGetFieldDefinitionByName(
                        out recordFielddefinition,
                        sList_KeyFldName,
                        false,
                        log_Reports
                        );
                    if (!log_Reports.Successful || !bHit)
                    {
                        // エラー
                        goto gt_EndMethod;
                    }

                    keyFldDefinition = recordFielddefinition.ValueAt(0);
                }



                //
                // (3)選択対象のフィールドの定義を調べます。
                RecordFielddefinition recordFieldDefinition_Selected;
                {
                    bool bHit = o_Table.TryGetFieldDefinitionByName(
                        out recordFieldDefinition_Selected,
                        selectSt_ToSave.List_SName_SelectField,
                        true,
                        log_Reports
                        );
                    if (!log_Reports.Successful)
                    {
                        // エラー
                        goto gt_EndMethod;
                    }
                }



                //
                // (4)
                if (null == keyFldDefinition)
                {
                    // エラー。
                    goto gt_Error_NullKeyFldDefinition;
                }


                List <string> list_FldImpl3 = new List <string>();

                recordFieldDefinition_Selected.ForEach(delegate(Fielddefinition fielddefinition_Selected, ref bool isBreak2, Log_Reports log_Reports2)
                {
                    string sSelectField = fielddefinition_Selected.Name_Trimupper;

                    //
                    // (5)
                    if (null == fielddefinition_Selected)
                    {
                        // エラー。
                        isBreak2 = true;
                        goto gt_Error_NullSelectedFldDefinition;
                    }

                    //
                    // (6)欠番

                    //
                    // (7)
                    if (null == dst_Rs_toSave || dst_Rs_toSave.List_Field.Count < 1)
                    {
                        bool bExpectedValueRequired;
                        {
                            bool parseSuccessful = bool.TryParse(selectSt_ToSave.Required, out bExpectedValueRequired);
                        }

                        //
                        // 条件
                        //
                        string name_KeyField;
                        Fielddefinition fielddefinition_Key;
                        string value_Expected;
                        P2_ReccondImpl sel2 = new P2_ReccondImpl();
                        sel2.GetFirstAwhrReccond(
                            out name_KeyField,
                            out fielddefinition_Key,
                            out value_Expected,
                            selectSt_ToSave.List_Recordcondition,
                            o_Table,
                            log_Reports
                            );
                        List <DataRow> dst_Row = new List <DataRow>();

                        SelectPerformerImpl sp = new SelectPerformerImpl();
                        sp.Select(
                            out dst_Row,
                            name_KeyField,
                            value_Expected,
                            bExpectedValueRequired,
                            fielddefinition_Key,
                            o_Table.DataTable,
                            parent_Cf_Query,
                            log_Reports
                            );

                        dst_Rs_toSave.AddList(dst_Row, log_Reports);
                        if (!log_Reports.Successful)
                        {
                            // 既エラー。
                            isBreak2 = true;
                            goto gt_EndInnermethod;
                        }

                        if (null == dst_Rs_toSave)
                        {
                            // (7-2)

                            isBreak2 = true;
                            goto gt_Error_UndefinedPrimitiveType;
                        }
                    }
                    else
                    {
                        // レコードセットは、一時記憶から取得済み。
                    }


                    // (8)
                    if (log_Reports.Successful)
                    {
                        // キー_フィールドの型別に、処理。
                        switch (keyFldDefinition.Type_Field)
                        {
                        case EnumTypeFielddefinition.String:
                            {
                                // (8-1)キーが string型フィールドなら

                                // この行の、選択対象のフィールドの値。

                                foreach (Dictionary <string, Value_Humaninput> record in dst_Rs_toSave.List_Field)
                                {
                                    // 値。

                                    Value_Humaninput selectedCellData;
                                    try
                                    {
                                        selectedCellData = (Value_Humaninput)record[sSelectField];
                                    }
                                    catch (KeyNotFoundException ex)
                                    {
                                        selectedCellData     = null;
                                        err_SSelectedFldName = sSelectField;
                                        err_Exception        = ex;
                                        isBreak2             = true;
                                        goto gt_Error_NotFoundFld;
                                    }

                                    Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue(
                                        fielddefinition_Selected,
                                        selectedCellData,
                                        parent_Cf_Query,
                                        log_Reports
                                        );

                                    list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));
                                }
                            }
                            break;

                        case EnumTypeFielddefinition.Int:
                            {
                                //
                                // (8-2) キー・フィールドが int型の場合。

                                foreach (Dictionary <string, Value_Humaninput> record in dst_Rs_toSave.List_Field)
                                {
                                    // この行の、選択対象のフィールドの値。

                                    if (null != log_Reports && !log_Reports.Successful)    //無限ループ防止
                                    {
                                        // エラー発生時は無視。
                                    }
                                    else
                                    {
                                        Value_Humaninput selectedCellData;
                                        try
                                        {
                                            selectedCellData = record[sSelectField];
                                        }
                                        catch (KeyNotFoundException ex)
                                        {
                                            selectedCellData     = null;
                                            err_SSelectedFldName = sSelectField;
                                            err_Exception        = ex;
                                            isBreak2             = true;
                                            goto gt_Error_NotFoundFld;
                                        }

                                        {
                                            // 値。
                                            Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue(
                                                fielddefinition_Selected,
                                                selectedCellData,
                                                parent_Cf_Query,
                                                log_Reports
                                                );

                                            list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));
                                        }
                                    }
                                }
                            }
                            break;

                        case EnumTypeFielddefinition.Bool:
                            {
                                // (8-3) キーが、bool型フィールド

                                // 値。
                                foreach (Dictionary <string, Value_Humaninput> record in dst_Rs_toSave.List_Field)
                                {
                                    // この行の、選択対象のフィールドの値。
                                    Value_Humaninput selectedCellData;
                                    try
                                    {
                                        selectedCellData = (Value_Humaninput)record[sSelectField];
                                    }
                                    catch (KeyNotFoundException ex)
                                    {
                                        selectedCellData     = null;
                                        err_SSelectedFldName = sSelectField;
                                        err_Exception        = ex;
                                        isBreak2             = true;
                                        goto gt_Error_NotFoundFld;
                                    }

                                    Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue(
                                        fielddefinition_Selected,
                                        selectedCellData,
                                        parent_Cf_Query,
                                        log_Reports
                                        );

                                    list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));
                                }
                            }
                            break;

                        default:
                            {
                                //
                                // (8-4)

                                //
                                // 既にエラー対策済み。

                                if (null != log_Reports)    //無限ループ防止
                                {
                                    //
                                    // エラー。
                                    isBreak2 = true;
                                    goto gt_Error_UndefinedPrimitiveType;
                                }

                                //
                                // 非エラー中断。
                                isBreak2 = true;
                                goto gt_EndInnermethod;
                            }
                            break;
                        }
                    }

                    goto gt_EndInnermethod;
                    //
                    #region 異常系
                    //────────────────────────────────────────
                    gt_Error_NullSelectedFldDefinition:
                    {
                        Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                        tmpl.SetParameter(1, o_Table.Name, log_Reports);                                                //テーブル名
                        tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports); //設定位置パンくずリスト

                        this.Owner_MemoryApplication.CreateErrorReport("Er:6026;", tmpl, log_Reports);
                    }
                    goto gt_EndInnermethod;
                    //────────────────────────────────────────
                    gt_Error_UndefinedPrimitiveType:
                    {
                        Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                        tmpl.SetParameter(1, keyFldDefinition.ToString_Type(), log_Reports);                            //キー・フィールド定義型名
                        tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports); //設定位置パンくずリスト

                        this.Owner_MemoryApplication.CreateErrorReport("Er:6027;", tmpl, log_Reports);
                    }
                    goto gt_EndInnermethod;
                    //────────────────────────────────────────
                    gt_Error_NotFoundFld:
                    {
                        Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                        tmpl.SetParameter(1, err_SSelectedFldName, log_Reports);                                        //選択フィールド名
                        tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports); //設定位置パンくずリスト
                        tmpl.SetParameter(3, Log_RecordReportsImpl.ToText_Exception(err_Exception), log_Reports);       //例外メッセージ

                        this.Owner_MemoryApplication.CreateErrorReport("Er:6028;", tmpl, log_Reports);
                    }
                    goto gt_EndInnermethod;
                    //────────────────────────────────────────
                    #endregion
                    //
                    gt_EndInnermethod:
                    ;
                }, log_Reports);//select列1つ

                if (0 < list_FldImpl3.Count)
                {
                    // フィールドがあれば追加。
                    reslt_sFieldListList.Add(list_FldImpl3);
                }
            }

            goto gt_EndMethod;
            //
            #region 異常系
            //────────────────────────────────────────
gt_Error_NullTable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();

                this.Owner_MemoryApplication.CreateErrorReport("Er:6024;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_NullKeyFldDefinition:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6025;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(reslt_sFieldListList);
        }
        //────────────────────────────────────────
        /// <summary>
        /// レコードセットを、名前を付けて一時記憶します。
        /// </summary>
        public void Execute_SaveRecordset(Log_Reports log_Reports)
        {
            Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);
            log_Method.BeginMethod(Info_Expr.Name_Library, this, "Execute_SaveRecordset", log_Reports);
            //
            //

            //
            // 既に、一時記憶に同名のレコードセットがないか検索。

            string sStorage = this.Expression_Storage.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports);
            if (!this.Owner_MemoryApplication.MemoryRecordset.RecordsetStorage.Contains(this.Expression_Storage, log_Reports))
            {
                RecordSet dst_Rs_ToSave;
                Selectstatement selectSt_ToSave;
                {
                    if ("" == this.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim())
                    {
                        //
                        // エラー。
                        goto gt_Error_EmptyTableName;
                    }

                    Table_Humaninput oTable = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(
                        this.Expression_From,//これが空文字列の場合がある??
                        true,
                        log_Reports
                        );
                    dst_Rs_ToSave = new RecordSetImpl(oTable);

                    //
                    // 要求の作成。
                    {
                        // <startup-special-rule>の中で使う子要素。
                        selectSt_ToSave = new SelectstatementImpl(this, this.Cur_Configuration);
                        {
                            Recordcondition recCond1;// = new RecordconditionImpl(s_ParentNode);

                            // TODO: logic要素がある版も要るはず。
                            bool bSuccessful = RecordconditionImpl.TryBuild(
                                out recCond1,
                                EnumLogic.None,
                                this.Expression_Field.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports),
                                this.Cur_Configuration.Parent,
                                log_Reports
                                );
                            recCond1.Value = this.Expression_LookupVal.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports);
                            selectSt_ToSave.List_Recordcondition.Add(recCond1);
                        }
                        selectSt_ToSave.Required = this.Expression_Required.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports);
                        selectSt_ToSave.Expression_From = this.Expression_From;
                        selectSt_ToSave.Storage = this.Expression_Storage.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports);
                    }
                }

                //
                // レコードの検索。
                {
                    //Configurationtree_Node
                    Configuration_Node parent_Cf_Query = this.Cur_Configuration.Parent;

                    // テーブル名。
                    if ("" == selectSt_ToSave.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim())
                    {
                        //
                        // エラー。
                        goto gt_Error_EmptyTableName;
                    }

                    Table_Humaninput o_Table = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(selectSt_ToSave.Expression_From, true, log_Reports);

                    if (null == o_Table)
                    {
                        goto gt_Error_NullTable;
                    }

                    bool bExpectedValueRequired;
                    {
                        bool parseSuccessful = bool.TryParse(selectSt_ToSave.Required, out bExpectedValueRequired);
                    }

                    //
                    //
                    //
                    // 条件
                    //
                    //
                    //
                    string name_KeyField;
                    Fielddefinition fielddefinition_Key;
                    string value_Expected;
                    P2_ReccondImpl sel2 = new P2_ReccondImpl();
                    sel2.GetFirstAwhrReccond(
                        out name_KeyField,
                        out fielddefinition_Key,
                        out value_Expected,
                        selectSt_ToSave.List_Recordcondition,
                        o_Table,
                        log_Reports
                        );
                    List<DataRow> dst_Row = new List<DataRow>();

                    SelectPerformerImpl sp = new SelectPerformerImpl();
                    sp.Select(
                        out dst_Row,
                        name_KeyField,
                        value_Expected,
                        bExpectedValueRequired,
                        fielddefinition_Key,
                        o_Table.DataTable,
                        parent_Cf_Query,
                        log_Reports
                        );

                    dst_Rs_ToSave.AddList(dst_Row, log_Reports);
                    if (!log_Reports.Successful)
                    {
                        // 既エラー。
                        goto gt_EndMethod;
                    }

                    //P2_SelectCellImpl sel2 = new P2_SelectCellImpl(this.MoOpyopyo);
                    //sel2.P2_Select(
                    //    ref dst_Rs_ToSave,
                    //    selectSt_ToSave,
                    //    this.Parent,
                    //    log_Reports
                    //    );
                }

                // debug:
                //if (false)
                //{
                //    StringBuilder txt = new StringBuilder();

                //    txt.Append(Info_E.LibraryName + ":" + this.GetType().Name + "#SaveRecordSet: 【検索してきたレコードセット】ここで内容消えてない?(2)?");
                //    txt.Append(" fld=[" + recordSet_toSave.Selectstatement.E_Field.E_Execute(log_Reports) + "]");
                //    txt.Append(" lookup-value=[" + recordSet_toSave.Selectstatement.E_Value.E_Execute( log_Reports) + "]");
                //    txt.Append(" description=[" + recordSet_toSave.Selectstatement.Expression_Description.E_Execute( log_Reports) + "]");
                //    txt.Append(" from=[" + recordSet_toSave.Selectstatement.Expression_From.E_Execute( log_Reports) + "]");
                //    txt.Append(" required=[" + recordSet_toSave.Selectstatement.E_Required.E_Execute( log_Reports) + "]");
                //    txt.Append(" Storage=[" + recordSet_toSave.Selectstatement.Expression_Storage.E_Execute( log_Reports) + "]");

                //    //txt.Append(" this.NFld=[" + RecordSet_toSave.NField.E_Execute(EnumHitcount.Unconstraint, log_Reports) + "]");
                //    //txt.Append(" this.NLookupValue=[" + RecordSet_toSave.NLookupValue.E_Execute(EnumHitcount.Unconstraint, log_Reports) + "]");
                //    //txt.Append(" this.NRequired=[" + RecordSet_toSave.NRequired.E_Execute(EnumHitcount.Unconstraint, log_Reports) + "]");
                //    //txt.Append(" this.NFrom=[" + RecordSet_toSave.NFrom.E_Execute(EnumHitcount.Unconstraint, log_Reports) + "]");

                //    //txt.Append(" ヒット件数=[" + RecordSet_toSave.O_Items.Count + "]");
                //    txt.Append(" ヒット件数=[" + recordSet.Count + "]");

                //    // レコードの内容
                //    //foreach (Dictionary<string, OValue> oRecord in RecordSet_toSave.O_Items)
                //    //{
                //    //    txt.Append(" フィールド数=[" + oRecord.Count + "]");
                //    //    foreach (string sKey in oRecord.Keys)
                //    //    {
                //    //        OValue oValue = oRecord[sKey];
                //    //        txt.Append(" 要素=[" + sKey + ":" + oValue.HumanInputString + "]");
                //    //    }
                //    //}
                //    foreach (DataRow record in recordSet)
                //    {
                //        txt.Append(" フィールド数=[" + record.Table.Columns.Count + "]");
                //        foreach (DataColumn column in record.Table.Columns)
                //        {

                //            Value_Humaninput oValue = (Value_Humaninput)record[column.ColumnName];

                //            txt.Append(" ★" + column.ColumnName + "=[" + oValue.Humaninput + "]");
                //        }
                //    }

                //    //ystem.Console.WriteLine(txt.ToString());
                //}

                // debug:
                //if (false)
                //{
                //    StringBuilder txt = new StringBuilder();

                //    txt.Append(Info_E.LibraryName + ":" + this.GetType().Name + "#SaveRecordSet:  【検索してきたレコードセット】内容入っていますか(3)?");

                //    txt.Append(" ヒット件数=[" + recordSet_toSave.O_Items.Count + "]←検索後");

                //    // レコードの内容
                //    foreach (Dictionary<string, Value_Humaninput> oRecord in recordSet_toSave.O_Items)
                //    {
                //        txt.Append(" フィールド数=[" + oRecord.Count + "]");
                //        foreach (string sKey in oRecord.Keys)
                //        {
                //            Value_Humaninput oValue = oRecord[sKey];
                //            txt.Append(" ■" + sKey + "=[" + oValue.Humaninput + "]");
                //        }
                //    }

                //    //ystem.Console.WriteLine(txt.ToString());
                //}

                //
                // レコードの一時保存。
                P4_RecordSetSaverImpl sel4 = new P4_RecordSetSaverImpl(this.Owner_MemoryApplication);
                sel4.P4_Save(
                    dst_Rs_ToSave,
                    this,
                    log_Reports
                    );
            }
            else
            {
                //ystem.Console.WriteLine(this.GetType().Name + "#SaveRecordSet: レコードセットは既に登録済みです。");
            }

            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
            gt_Error_EmptyTableName:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(this.Cur_Configuration.Parent), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6030;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_NullTable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(this.Cur_Configuration.Parent), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6031;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
            gt_EndMethod:
            log_Method.EndMethod(log_Reports);
        }
Example #4
0
        //────────────────────────────────────────
        #endregion



        #region アクション
        //────────────────────────────────────────

        /// <summary>
        /// ユーザー定義プログラムの実行。
        /// </summary>
        /// <returns></returns>
        public override string Execute5_Main(
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);

            log_Method.BeginMethod(Info_Expr.Name_Library, this, "Execute5_Main", log_Reports);
            //
            //

            Configuration_Node parent_Configurationtree_Node_Query = this.Cur_Configuration;

            StringBuilder sb_Result = new StringBuilder();

            //
            // 外観
            //
            // <f-text-template table="Ut:条件テーブル" lookup-id="100">
            //
            // ・lookup-id は、lookup-value という名前の方が良かった。
            //

            //
            // 指定のテーブルの ID列を指定して、TEXT列の内容を取得。
            Builder_TexttemplateP1pImpl p1pText = new Builder_TexttemplateP1pImpl();
            {
                // <f-text-template>要素。
                Selectstatement selectSt = new SelectstatementImpl(this, this.Cur_Configuration);

                // TODO: logic属性がある版も要るはず。
                Recordcondition recCond1;
                bool            bSuccessful = RecordconditionImpl.TryBuild(out recCond1, EnumLogic.None, Expression_SftextTemplate.S_FIELD_ID, parent_Configurationtree_Node_Query, log_Reports);
                selectSt.List_Recordcondition.Add(recCond1);

                ////
                //// (1)キー_フィールド名
                //{
                //    recCond1.Name_Field = "ID";
                //}

                //
                // (2)探したいキー値
                {
                    //
                    // thisは、<f-text-template>。
                    //

                    string sLookupId;
                    bool   bHit = this.TrySelectAttribute(out sLookupId, PmNames.S_LOOKUP_ID.Name_Pm, EnumHitcount.One, log_Reports);
                    if (bHit)
                    {
                        recCond1.Value = sLookupId;
                    }

                    string sLookupValue;
                    if (log_Reports.Successful)
                    {
                        sLookupValue = recCond1.Value;
                    }
                    else
                    {
                        // エラー
                        goto gt_Error_NotFoundVariable;
                    }

                    // bug:
                    if ("" == sLookupValue.Trim())
                    {
                        //
                        // 検索キーが空欄の場合。
                        sb_Result.Length = 0; //空文字列にする。
                        goto gt_EndMethod;
                    }
                }

                //
                // (3)検索ヒットの必須の有無
                {
                    // 必須指定。
                    selectSt.Required = Expression_SftextTemplate.S_TRUE;
                }

                //
                // (4)テーブル名
                {
                    Expression_Node_String ec_Result;//ソース情報利用
                    bool bHit = this.TrySelectAttribute(out ec_Result, PmNames.S_TABLE.Name_Pm, EnumHitcount.One, log_Reports);
                    selectSt.Expression_From = ec_Result;
                }

                //
                // (5)欲しいデータのあるフィールド名
                selectSt.List_SName_SelectField.Add(Expression_SftextTemplate.S_FIELD_TEXT);



                //
                // (1)レコードセットの絞り込み。
                RecordSet dst_Rs;
                {
                    Table_Humaninput o_Tbl = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(
                        selectSt.Expression_From,//これが空文字列の場合がある??
                        true,
                        log_Reports
                        );
                    dst_Rs = new RecordSetImpl(o_Tbl);
                }
                //dst_Rs.Selectstatement = selectSt;//★


                {
                    // テーブル名。
                    if ("" == selectSt.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim())
                    {
                        //
                        // エラー。
                        goto gt_Error_EmptyTableName;
                    }

                    Table_Humaninput o_Table = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(selectSt.Expression_From, true, log_Reports);

                    if (null == o_Table)
                    {
                        goto gt_Error_NullTable;
                    }



                    bool isRequired_ExpectedValue;
                    {
                        bool parseSuccessful = bool.TryParse(selectSt.Required, out isRequired_ExpectedValue);
                    }


                    //
                    //
                    //
                    // 条件
                    //
                    //
                    //
                    string          name_KeyField;
                    Fielddefinition fielddefinition_Key;
                    string          value_Expected;
                    P2_ReccondImpl  sel2 = new P2_ReccondImpl();
                    sel2.GetFirstAwhrReccond(
                        out name_KeyField,
                        out fielddefinition_Key,
                        out value_Expected,
                        selectSt.List_Recordcondition,
                        o_Table,
                        log_Reports
                        );

                    List <DataRow> dst_Row = new List <DataRow>();

                    if (log_Reports.Successful)
                    {
                        SelectPerformerImpl sp = new SelectPerformerImpl();
                        sp.Select(
                            out dst_Row,
                            name_KeyField,
                            value_Expected,
                            isRequired_ExpectedValue,
                            fielddefinition_Key,
                            o_Table.DataTable,
                            parent_Configurationtree_Node_Query,
                            log_Reports
                            );
                    }

                    if (log_Reports.Successful)
                    {
                        dst_Rs.AddList(dst_Row, log_Reports);
                    }

                    if (!log_Reports.Successful)
                    {
                        // 既エラー。
                        goto gt_EndMethod;
                    }
                }


                if (!log_Reports.Successful)
                {
                    //
                    // エラーが出ていたら、さっさと抜ける。
                    //sResult = "";
                    goto gt_EndMethod;
                }

                //
                // フィールド値の取得。
                P5_CellsSelecterImpl  sel5            = new P5_CellsSelecterImpl(this.Owner_MemoryApplication);
                List <List <string> > sListList_reslt = sel5.P5_Select_CellType(
                    dst_Rs,
                    selectSt,
                    null,//nwhere_recordSetSaveTo,
                    this.Cur_Configuration,
                    log_Reports
                    );



                if (0 < sListList_reslt.Count)
                {
                    // 先頭行の、
                    List <string> sList_Fld = sListList_reslt[0];
                    // 先頭フィールドの値。
                    string sString = sList_Fld[0];

                    //e_string.SetValidation(...);
                    p1pText.Text = sString;
                }
                else
                {
                    // エラー

                    Log_TextIndented txt = new Log_TextIndentedImpl();
                    txt.Append(this.GetType().Name);
                    txt.Append("#GetString:(" + Info_Expr.Name_Library + ") エラー。該当なし。");

                    txt.Append(" 選択フィールド=[");

                    txt.Append(selectSt.ToSelectFieldNameListCsv());

                    txt.Append("]");

                    txt.Append(" テーブル=[");

                    txt.Append(selectSt.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));
                    txt.Append("]");

                    // キーフィールド
                    txt.Append(" [");

                    txt.Append(recCond1.Name_Field);

                    txt.Append("]が");

                    // 探す値。
                    txt.Append("[");
                    txt.Append(recCond1.Value);
                    txt.Append("]のとき");



                    p1pText.Text = txt.ToString();
                }
            }



            List <int> nList_P1p = p1pText.ExistsP1pNumbers(
                this.Dictionary_Expression_Attribute,
                log_Reports
                );

            foreach (int n_P1p in nList_P1p)
            {
                string p1pValue;
                {
                    bool bHit = this.TrySelectAttribute(
                        out p1pValue,
                        "p" + n_P1p + "p",
                        EnumHitcount.One,
                        log_Reports
                        );

                    if (log_Reports.Successful)
                    {
                    }
                    else
                    {
                        p1pValue = null;
                    }

                    p1pText.Dictionary_NumberAndValue_Parameter.Add(n_P1p, p1pValue);
                }
            }


            Expression_Node_String ec_TextTemplate = p1pText.Compile(
                log_Reports
                );

            sb_Result.Append(ec_TextTemplate.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));


            //
            //
            //
            // TODO: 制約の判定
            //
            //
            //

            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
gt_Error_NotFoundVariable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Configurationtree_Node_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6009;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_EmptyTableName:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Configurationtree_Node_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6010;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_NullTable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Configurationtree_Node_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6011;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(sb_Result.ToString());
        }
Example #5
0
        //────────────────────────────────────────
        #endregion



        #region アクション
        //────────────────────────────────────────

        /// <summary>
        /// レコードセットを、名前を付けて一時記憶します。
        /// </summary>
        public void Execute_SaveRecordset(Log_Reports log_Reports)
        {
            Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);

            log_Method.BeginMethod(Info_Expr.Name_Library, this, "Execute_SaveRecordset", log_Reports);
            //
            //

            //
            // 既に、一時記憶に同名のレコードセットがないか検索。

            string sStorage = this.Expression_Storage.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports);

            if (!this.Owner_MemoryApplication.MemoryRecordset.RecordsetStorage.Contains(this.Expression_Storage, log_Reports))
            {
                RecordSet       dst_Rs_ToSave;
                Selectstatement selectSt_ToSave;
                {
                    if ("" == this.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim())
                    {
                        //
                        // エラー。
                        goto gt_Error_EmptyTableName;
                    }

                    Table_Humaninput oTable = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(
                        this.Expression_From,//これが空文字列の場合がある??
                        true,
                        log_Reports
                        );
                    dst_Rs_ToSave = new RecordSetImpl(oTable);

                    //
                    // 要求の作成。
                    {
                        // <startup-special-rule>の中で使う子要素。
                        selectSt_ToSave = new SelectstatementImpl(this, this.Cur_Configuration);
                        {
                            Recordcondition recCond1;// = new RecordconditionImpl(s_ParentNode);

                            // TODO: logic要素がある版も要るはず。
                            bool bSuccessful = RecordconditionImpl.TryBuild(
                                out recCond1,
                                EnumLogic.None,
                                this.Expression_Field.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports),
                                this.Cur_Configuration.Parent,
                                log_Reports
                                );
                            recCond1.Value = this.Expression_LookupVal.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports);
                            selectSt_ToSave.List_Recordcondition.Add(recCond1);
                        }
                        selectSt_ToSave.Required        = this.Expression_Required.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports);
                        selectSt_ToSave.Expression_From = this.Expression_From;
                        selectSt_ToSave.Storage         = this.Expression_Storage.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports);
                    }
                }

                //
                // レコードの検索。
                {
                    //Configurationtree_Node
                    Configuration_Node parent_Cf_Query = this.Cur_Configuration.Parent;

                    // テーブル名。
                    if ("" == selectSt_ToSave.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim())
                    {
                        //
                        // エラー。
                        goto gt_Error_EmptyTableName;
                    }

                    Table_Humaninput o_Table = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(selectSt_ToSave.Expression_From, true, log_Reports);

                    if (null == o_Table)
                    {
                        goto gt_Error_NullTable;
                    }



                    bool bExpectedValueRequired;
                    {
                        bool parseSuccessful = bool.TryParse(selectSt_ToSave.Required, out bExpectedValueRequired);
                    }


                    //
                    //
                    //
                    // 条件
                    //
                    //
                    //
                    string          name_KeyField;
                    Fielddefinition fielddefinition_Key;
                    string          value_Expected;
                    P2_ReccondImpl  sel2 = new P2_ReccondImpl();
                    sel2.GetFirstAwhrReccond(
                        out name_KeyField,
                        out fielddefinition_Key,
                        out value_Expected,
                        selectSt_ToSave.List_Recordcondition,
                        o_Table,
                        log_Reports
                        );
                    List <DataRow> dst_Row = new List <DataRow>();

                    SelectPerformerImpl sp = new SelectPerformerImpl();
                    sp.Select(
                        out dst_Row,
                        name_KeyField,
                        value_Expected,
                        bExpectedValueRequired,
                        fielddefinition_Key,
                        o_Table.DataTable,
                        parent_Cf_Query,
                        log_Reports
                        );



                    dst_Rs_ToSave.AddList(dst_Row, log_Reports);
                    if (!log_Reports.Successful)
                    {
                        // 既エラー。
                        goto gt_EndMethod;
                    }


                    //P2_SelectCellImpl sel2 = new P2_SelectCellImpl(this.MoOpyopyo);
                    //sel2.P2_Select(
                    //    ref dst_Rs_ToSave,
                    //    selectSt_ToSave,
                    //    this.Parent,
                    //    log_Reports
                    //    );
                }


                // debug:
                //if (false)
                //{
                //    StringBuilder txt = new StringBuilder();

                //    txt.Append(Info_E.LibraryName + ":" + this.GetType().Name + "#SaveRecordSet: 【検索してきたレコードセット】ここで内容消えてない?(2)?");
                //    txt.Append(" fld=[" + recordSet_toSave.Selectstatement.E_Field.E_Execute(log_Reports) + "]");
                //    txt.Append(" lookup-value=[" + recordSet_toSave.Selectstatement.E_Value.E_Execute( log_Reports) + "]");
                //    txt.Append(" description=[" + recordSet_toSave.Selectstatement.Expression_Description.E_Execute( log_Reports) + "]");
                //    txt.Append(" from=[" + recordSet_toSave.Selectstatement.Expression_From.E_Execute( log_Reports) + "]");
                //    txt.Append(" required=[" + recordSet_toSave.Selectstatement.E_Required.E_Execute( log_Reports) + "]");
                //    txt.Append(" Storage=[" + recordSet_toSave.Selectstatement.Expression_Storage.E_Execute( log_Reports) + "]");

                //    //txt.Append(" this.NFld=[" + RecordSet_toSave.NField.E_Execute(EnumHitcount.Unconstraint, log_Reports) + "]");
                //    //txt.Append(" this.NLookupValue=[" + RecordSet_toSave.NLookupValue.E_Execute(EnumHitcount.Unconstraint, log_Reports) + "]");
                //    //txt.Append(" this.NRequired=[" + RecordSet_toSave.NRequired.E_Execute(EnumHitcount.Unconstraint, log_Reports) + "]");
                //    //txt.Append(" this.NFrom=[" + RecordSet_toSave.NFrom.E_Execute(EnumHitcount.Unconstraint, log_Reports) + "]");

                //    //txt.Append(" ヒット件数=[" + RecordSet_toSave.O_Items.Count + "]");
                //    txt.Append(" ヒット件数=[" + recordSet.Count + "]");

                //    // レコードの内容
                //    //foreach (Dictionary<string, OValue> oRecord in RecordSet_toSave.O_Items)
                //    //{
                //    //    txt.Append(" フィールド数=[" + oRecord.Count + "]");
                //    //    foreach (string sKey in oRecord.Keys)
                //    //    {
                //    //        OValue oValue = oRecord[sKey];
                //    //        txt.Append(" 要素=[" + sKey + ":" + oValue.HumanInputString + "]");
                //    //    }
                //    //}
                //    foreach (DataRow record in recordSet)
                //    {
                //        txt.Append(" フィールド数=[" + record.Table.Columns.Count + "]");
                //        foreach (DataColumn column in record.Table.Columns)
                //        {

                //            Value_Humaninput oValue = (Value_Humaninput)record[column.ColumnName];

                //            txt.Append(" ★" + column.ColumnName + "=[" + oValue.Humaninput + "]");
                //        }
                //    }

                //    //ystem.Console.WriteLine(txt.ToString());
                //}

                // debug:
                //if (false)
                //{
                //    StringBuilder txt = new StringBuilder();

                //    txt.Append(Info_E.LibraryName + ":" + this.GetType().Name + "#SaveRecordSet:  【検索してきたレコードセット】内容入っていますか(3)?");


                //    txt.Append(" ヒット件数=[" + recordSet_toSave.O_Items.Count + "]←検索後");

                //    // レコードの内容
                //    foreach (Dictionary<string, Value_Humaninput> oRecord in recordSet_toSave.O_Items)
                //    {
                //        txt.Append(" フィールド数=[" + oRecord.Count + "]");
                //        foreach (string sKey in oRecord.Keys)
                //        {
                //            Value_Humaninput oValue = oRecord[sKey];
                //            txt.Append(" ■" + sKey + "=[" + oValue.Humaninput + "]");
                //        }
                //    }


                //    //ystem.Console.WriteLine(txt.ToString());
                //}


                //
                // レコードの一時保存。
                P4_RecordSetSaverImpl sel4 = new P4_RecordSetSaverImpl(this.Owner_MemoryApplication);
                sel4.P4_Save(
                    dst_Rs_ToSave,
                    this,
                    log_Reports
                    );
            }
            else
            {
                //ystem.Console.WriteLine(this.GetType().Name + "#SaveRecordSet: レコードセットは既に登録済みです。");
            }

            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
gt_Error_EmptyTableName:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(this.Cur_Configuration.Parent), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6030;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_NullTable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(this.Cur_Configuration.Parent), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6031;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
        }
        //────────────────────────────────────────
        /// <summary>
        /// ユーザー定義プログラムの実行。
        /// </summary>
        /// <returns></returns>
        public override string Execute5_Main(
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);
            log_Method.BeginMethod(Info_Expr.Name_Library, this, "Execute5_Main", log_Reports);
            //
            //

            Configuration_Node parent_Configurationtree_Node_Query = this.Cur_Configuration;

            StringBuilder sb_Result = new StringBuilder();

            //
            // 外観
            //
            // <f-text-template table="Ut:条件テーブル" lookup-id="100">
            //
            // ・lookup-id は、lookup-value という名前の方が良かった。
            //

            //
            // 指定のテーブルの ID列を指定して、TEXT列の内容を取得。
            Builder_TexttemplateP1pImpl p1pText = new Builder_TexttemplateP1pImpl();
            {
                // <f-text-template>要素。
                Selectstatement selectSt = new SelectstatementImpl(this, this.Cur_Configuration);

                // TODO: logic属性がある版も要るはず。
                Recordcondition recCond1;
                bool bSuccessful = RecordconditionImpl.TryBuild(out recCond1, EnumLogic.None, Expression_SftextTemplate.S_FIELD_ID, parent_Configurationtree_Node_Query, log_Reports);
                selectSt.List_Recordcondition.Add(recCond1);

                ////
                //// (1)キー_フィールド名
                //{
                //    recCond1.Name_Field = "ID";
                //}

                //
                // (2)探したいキー値
                {
                    //
                    // thisは、<f-text-template>。
                    //

                    string sLookupId;
                    bool bHit = this.TrySelectAttribute(out sLookupId, PmNames.S_LOOKUP_ID.Name_Pm, EnumHitcount.One, log_Reports);
                    if (bHit)
                    {
                        recCond1.Value = sLookupId;
                    }

                    string sLookupValue;
                    if (log_Reports.Successful)
                    {
                        sLookupValue = recCond1.Value;
                    }
                    else
                    {
                        // エラー
                        goto gt_Error_NotFoundVariable;
                    }

                    // bug:
                    if ("" == sLookupValue.Trim())
                    {
                        //
                        // 検索キーが空欄の場合。
                        sb_Result.Length = 0; //空文字列にする。
                        goto gt_EndMethod;
                    }
                }

                //
                // (3)検索ヒットの必須の有無
                {
                    // 必須指定。
                    selectSt.Required = Expression_SftextTemplate.S_TRUE;
                }

                //
                // (4)テーブル名
                {
                    Expression_Node_String ec_Result;//ソース情報利用
                    bool bHit = this.TrySelectAttribute(out ec_Result, PmNames.S_TABLE.Name_Pm, EnumHitcount.One, log_Reports);
                    selectSt.Expression_From = ec_Result;
                }

                //
                // (5)欲しいデータのあるフィールド名
                selectSt.List_SName_SelectField.Add(Expression_SftextTemplate.S_FIELD_TEXT);

                //
                // (1)レコードセットの絞り込み。
                RecordSet dst_Rs;
                {
                    Table_Humaninput o_Tbl = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(
                        selectSt.Expression_From,//これが空文字列の場合がある??
                        true,
                        log_Reports
                        );
                    dst_Rs = new RecordSetImpl(o_Tbl);
                }
                //dst_Rs.Selectstatement = selectSt;//★

                {

                    // テーブル名。
                    if ("" == selectSt.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports).Trim())
                    {
                        //
                        // エラー。
                        goto gt_Error_EmptyTableName;
                    }

                    Table_Humaninput o_Table = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(selectSt.Expression_From, true, log_Reports);

                    if (null == o_Table)
                    {
                        goto gt_Error_NullTable;
                    }

                    bool isRequired_ExpectedValue;
                    {
                        bool parseSuccessful = bool.TryParse(selectSt.Required, out isRequired_ExpectedValue);
                    }

                    //
                    //
                    //
                    // 条件
                    //
                    //
                    //
                    string name_KeyField;
                    Fielddefinition fielddefinition_Key;
                    string value_Expected;
                    P2_ReccondImpl sel2 = new P2_ReccondImpl();
                    sel2.GetFirstAwhrReccond(
                        out name_KeyField,
                        out fielddefinition_Key,
                        out value_Expected,
                        selectSt.List_Recordcondition,
                        o_Table,
                        log_Reports
                        );

                    List<DataRow> dst_Row = new List<DataRow>();

                    if (log_Reports.Successful)
                    {
                        SelectPerformerImpl sp = new SelectPerformerImpl();
                        sp.Select(
                            out dst_Row,
                            name_KeyField,
                            value_Expected,
                            isRequired_ExpectedValue,
                            fielddefinition_Key,
                            o_Table.DataTable,
                            parent_Configurationtree_Node_Query,
                            log_Reports
                            );
                    }

                    if (log_Reports.Successful)
                    {
                        dst_Rs.AddList(dst_Row, log_Reports);
                    }

                    if (!log_Reports.Successful)
                    {
                        // 既エラー。
                        goto gt_EndMethod;
                    }
                }

                if (!log_Reports.Successful)
                {
                    //
                    // エラーが出ていたら、さっさと抜ける。
                    //sResult = "";
                    goto gt_EndMethod;
                }

                //
                // フィールド値の取得。
                P5_CellsSelecterImpl sel5 = new P5_CellsSelecterImpl(this.Owner_MemoryApplication);
                List<List<string>> sListList_reslt = sel5.P5_Select_CellType(
                    dst_Rs,
                    selectSt,
                    null,//nwhere_recordSetSaveTo,
                    this.Cur_Configuration,
                    log_Reports
                    );

                if (0 < sListList_reslt.Count)
                {
                    // 先頭行の、
                    List<string> sList_Fld = sListList_reslt[0];
                    // 先頭フィールドの値。
                    string sString = sList_Fld[0];

                    //e_string.SetValidation(...);
                    p1pText.Text = sString;
                }
                else
                {
                    // エラー

                    Log_TextIndented txt = new Log_TextIndentedImpl();
                    txt.Append(this.GetType().Name);
                    txt.Append("#GetString:(" + Info_Expr.Name_Library + ") エラー。該当なし。");

                    txt.Append(" 選択フィールド=[");

                    txt.Append(selectSt.ToSelectFieldNameListCsv());

                    txt.Append("]");

                    txt.Append(" テーブル=[");

                    txt.Append(selectSt.Expression_From.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));
                    txt.Append("]");

                    // キーフィールド
                    txt.Append(" [");

                    txt.Append(recCond1.Name_Field);

                    txt.Append("]が");

                    // 探す値。
                    txt.Append("[");
                    txt.Append(recCond1.Value);
                    txt.Append("]のとき");

                    p1pText.Text = txt.ToString();
                }

            }

            List<int> nList_P1p = p1pText.ExistsP1pNumbers(
                this.Dictionary_Expression_Attribute,
                log_Reports
                );

            foreach (int n_P1p in nList_P1p)
            {
                string p1pValue;
                {
                    bool bHit = this.TrySelectAttribute(
                        out p1pValue,
                        "p" + n_P1p+"p",
                        EnumHitcount.One,
                        log_Reports
                        );

                    if (log_Reports.Successful)
                    {
                    }
                    else
                    {
                        p1pValue = null;
                    }

                    p1pText.Dictionary_NumberAndValue_Parameter.Add(n_P1p, p1pValue);
                }
            }

            Expression_Node_String ec_TextTemplate = p1pText.Compile(
                log_Reports
                );

            sb_Result.Append(ec_TextTemplate.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));

            //
            //
            //
            // TODO: 制約の判定
            //
            //
            //

            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
            gt_Error_NotFoundVariable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Configurationtree_Node_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6009;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_EmptyTableName:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Configurationtree_Node_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6010;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_NullTable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Configurationtree_Node_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6011;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
            gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return sb_Result.ToString();
        }
Example #7
0
        //────────────────────────────────────────
        /// <summary>
        /// フィールドから値を取得。
        /// 
        /// TODO:セルタイプ以外にも対応したい。
        /// </summary>
        /// <param name="RecordSet_toSave">ヌル不可</param>
        /// <param name="eSelectedFldName">選択フィールド</param>
        /// <param name="RecordSetSaveTo_or_null"></param>
        /// <param name="log_Reports"></param>
        /// <returns>行リスト<列リスト></returns>
        public List<List<string>> P5_Select_CellType(
            RecordSet dst_Rs_toSave,
            Selectstatement selectSt_ToSave,
            Expressionv_4ASelectRecord ecv_selRec_OrNull,//where
            Configuration_Node parent_Cf_Query,//this
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static);
            log_Method.BeginMethod(Info_Expr.Name_Library, this, "P5_Select",log_Reports);
            //
            //

            List<List<string>> reslt_sFieldListList = new List<List<string>>();

            //
            // (1)テーブル
            Table_Humaninput o_Table;
            {
                o_Table = this.Owner_MemoryApplication.MemoryTables.GetTable_HumaninputByName(
                    selectSt_ToSave.Expression_From, true, log_Reports);

                if (null == o_Table)
                {
                    // エラー。
                    goto gt_Error_NullTable;
                }
            }
            if (!log_Reports.Successful)
            {
                //
                // エラーが出ていたら、さっさと抜ける。
                goto gt_EndMethod;
            }

            //
            //
            //
            //
            // 条件
            //
            //
            //
            //
            Fielddefinition keyFldDefinition = null;
            string err_SSelectedFldName = null;
            Exception err_Exception = null;
            Recordcondition err_Recordcondition = null;
            foreach (Recordcondition recCond in selectSt_ToSave.List_Recordcondition)
            {
                err_Recordcondition = recCond;

                //
                // (2)検索のキーフィールドの定義を調べます。

                // キーフィールド定義
                {

                    List<string> sList_KeyFldName;
                    {
                        // 要素数1個。
                        sList_KeyFldName = new List<string>();
                        sList_KeyFldName.Add(recCond.Name_Field);
                    }

                    RecordFielddefinition recordFielddefinition;
                    bool bHit = o_Table.TryGetFieldDefinitionByName(
                         out recordFielddefinition,
                        sList_KeyFldName,
                        false,
                        log_Reports
                        );
                    if (!log_Reports.Successful || !bHit)
                    {
                        // エラー
                        goto gt_EndMethod;
                    }

                    keyFldDefinition = recordFielddefinition.ValueAt(0);
                }

                //
                // (3)選択対象のフィールドの定義を調べます。
                RecordFielddefinition recordFieldDefinition_Selected;
                {
                    bool bHit = o_Table.TryGetFieldDefinitionByName(
                        out recordFieldDefinition_Selected,
                        selectSt_ToSave.List_SName_SelectField,
                        true,
                        log_Reports
                        );
                    if (!log_Reports.Successful)
                    {
                        // エラー
                        goto gt_EndMethod;
                    }
                }

                //
                // (4)
                if (null == keyFldDefinition)
                {
                    // エラー。
                    goto gt_Error_NullKeyFldDefinition;
                }

                List<string> list_FldImpl3 = new List<string>();

                recordFieldDefinition_Selected.ForEach(delegate(Fielddefinition fielddefinition_Selected,ref bool isBreak2,Log_Reports log_Reports2)
                {
                    string sSelectField = fielddefinition_Selected.Name_Trimupper;

                    //
                    // (5)
                    if (null == fielddefinition_Selected)
                    {
                        // エラー。
                        isBreak2 = true;
                        goto gt_Error_NullSelectedFldDefinition;
                    }

                    //
                    // (6)欠番

                    //
                    // (7)
                    if (null == dst_Rs_toSave || dst_Rs_toSave.List_Field.Count < 1)
                    {
                        bool bExpectedValueRequired;
                        {
                            bool parseSuccessful = bool.TryParse(selectSt_ToSave.Required, out bExpectedValueRequired);
                        }

                        //
                        // 条件
                        //
                        string name_KeyField;
                        Fielddefinition fielddefinition_Key;
                        string value_Expected;
                        P2_ReccondImpl sel2 = new P2_ReccondImpl();
                        sel2.GetFirstAwhrReccond(
                            out name_KeyField,
                            out fielddefinition_Key,
                            out value_Expected,
                            selectSt_ToSave.List_Recordcondition,
                            o_Table,
                            log_Reports
                            );
                        List<DataRow> dst_Row = new List<DataRow>();

                        SelectPerformerImpl sp = new SelectPerformerImpl();
                        sp.Select(
                            out dst_Row,
                            name_KeyField,
                            value_Expected,
                            bExpectedValueRequired,
                            fielddefinition_Key,
                            o_Table.DataTable,
                            parent_Cf_Query,
                            log_Reports
                            );

                        dst_Rs_toSave.AddList(dst_Row, log_Reports);
                        if (!log_Reports.Successful)
                        {
                            // 既エラー。
                            isBreak2 = true;
                            goto gt_EndInnermethod;
                        }

                        if (null == dst_Rs_toSave)
                        {
                            // (7-2)

                            isBreak2 = true;
                            goto gt_Error_UndefinedPrimitiveType;
                        }
                    }
                    else
                    {
                        // レコードセットは、一時記憶から取得済み。
                    }

                    // (8)
                    if (log_Reports.Successful)
                    {

                        // キー_フィールドの型別に、処理。
                        switch (keyFldDefinition.Type_Field)
                        {
                            case EnumTypeFielddefinition.String:
                                {
                                    // (8-1)キーが string型フィールドなら

                                    // この行の、選択対象のフィールドの値。

                                    foreach (Dictionary<string, Value_Humaninput> record in dst_Rs_toSave.List_Field)
                                    {
                                        // 値。

                                        Value_Humaninput selectedCellData;
                                        try
                                        {
                                            selectedCellData = (Value_Humaninput)record[sSelectField];
                                        }
                                        catch (KeyNotFoundException ex)
                                        {
                                            selectedCellData = null;
                                            err_SSelectedFldName = sSelectField;
                                            err_Exception = ex;
                                            isBreak2 = true;
                                            goto gt_Error_NotFoundFld;
                                        }

                                        Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue(
                                            fielddefinition_Selected,
                                            selectedCellData,
                                            parent_Cf_Query,
                                            log_Reports
                                            );

                                        list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));
                                    }
                                }
                                break;
                            case EnumTypeFielddefinition.Int:
                                {
                                    //
                                    // (8-2) キー・フィールドが int型の場合。

                                    foreach (Dictionary<string, Value_Humaninput> record in dst_Rs_toSave.List_Field)
                                    {
                                        // この行の、選択対象のフィールドの値。

                                        if (null != log_Reports && !log_Reports.Successful)//無限ループ防止
                                        {
                                            // エラー発生時は無視。
                                        }
                                        else
                                        {
                                            Value_Humaninput selectedCellData;
                                            try
                                            {
                                                selectedCellData = record[sSelectField];
                                            }
                                            catch (KeyNotFoundException ex)
                                            {
                                                selectedCellData = null;
                                                err_SSelectedFldName = sSelectField;
                                                err_Exception = ex;
                                                isBreak2 = true;
                                                goto gt_Error_NotFoundFld;
                                            }

                                            {
                                                // 値。
                                                Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue(
                                                    fielddefinition_Selected,
                                                    selectedCellData,
                                                    parent_Cf_Query,
                                                    log_Reports
                                                    );

                                                list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));
                                            }
                                        }
                                    }
                                }
                                break;
                            case EnumTypeFielddefinition.Bool:
                                {
                                    // (8-3) キーが、bool型フィールド

                                    // 値。
                                    foreach (Dictionary<string, Value_Humaninput> record in dst_Rs_toSave.List_Field)
                                    {
                                        // この行の、選択対象のフィールドの値。
                                        Value_Humaninput selectedCellData;
                                        try
                                        {
                                            selectedCellData = (Value_Humaninput)record[sSelectField];
                                        }
                                        catch (KeyNotFoundException ex)
                                        {
                                            selectedCellData = null;
                                            err_SSelectedFldName = sSelectField;
                                            err_Exception = ex;
                                            isBreak2 = true;
                                            goto gt_Error_NotFoundFld;
                                        }

                                        Expression_Node_String ec_SelectedValue = this.GetSelectedFieldValue(
                                            fielddefinition_Selected,
                                            selectedCellData,
                                            parent_Cf_Query,
                                            log_Reports
                                            );

                                        list_FldImpl3.Add(ec_SelectedValue.Execute4_OnExpressionString(EnumHitcount.Unconstraint, log_Reports));
                                    }
                                }
                                break;
                            default:
                                {
                                    //
                                    // (8-4)

                                    //
                                    // 既にエラー対策済み。

                                    if (null != log_Reports)//無限ループ防止
                                    {
                                        //
                                        // エラー。
                                        isBreak2 = true;
                                        goto gt_Error_UndefinedPrimitiveType;
                                    }

                                    //
                                    // 非エラー中断。
                                    isBreak2 = true;
                                    goto gt_EndInnermethod;
                                }
                                break;
                        }

                    }

                    goto gt_EndInnermethod;
                //
                    #region 異常系
                //────────────────────────────────────────
                gt_Error_NullSelectedFldDefinition:
                    {
                        Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                        tmpl.SetParameter(1, o_Table.Name, log_Reports);//テーブル名
                        tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト

                        this.Owner_MemoryApplication.CreateErrorReport("Er:6026;", tmpl, log_Reports);
                    }
                goto gt_EndInnermethod;
                //────────────────────────────────────────
                gt_Error_UndefinedPrimitiveType:
                    {
                        Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                        tmpl.SetParameter(1, keyFldDefinition.ToString_Type(), log_Reports);//キー・フィールド定義型名
                        tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト

                        this.Owner_MemoryApplication.CreateErrorReport("Er:6027;", tmpl, log_Reports);
                    }
                goto gt_EndInnermethod;
                //────────────────────────────────────────
                gt_Error_NotFoundFld:
                    {
                        Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                        tmpl.SetParameter(1, err_SSelectedFldName, log_Reports);//選択フィールド名
                        tmpl.SetParameter(2, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト
                        tmpl.SetParameter(3, Log_RecordReportsImpl.ToText_Exception(err_Exception), log_Reports);//例外メッセージ

                        this.Owner_MemoryApplication.CreateErrorReport("Er:6028;", tmpl, log_Reports);
                    }
                goto gt_EndInnermethod;
                //────────────────────────────────────────
                    #endregion
                    //
                gt_EndInnermethod:
                    ;
                }, log_Reports);//select列1つ

                if (0 < list_FldImpl3.Count)
                {
                    // フィールドがあれば追加。
                    reslt_sFieldListList.Add(list_FldImpl3);
                }
            }

            goto gt_EndMethod;
            //
            #region 異常系
            //────────────────────────────────────────
            gt_Error_NullTable:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();

                this.Owner_MemoryApplication.CreateErrorReport("Er:6024;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_NullKeyFldDefinition:
            {
                Builder_TexttemplateP1p tmpl = new Builder_TexttemplateP1pImpl();
                tmpl.SetParameter(1, Log_RecordReportsImpl.ToText_Configuration(parent_Cf_Query), log_Reports);//設定位置パンくずリスト

                this.Owner_MemoryApplication.CreateErrorReport("Er:6025;", tmpl, log_Reports);
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return reslt_sFieldListList;
        }