//──────────────────────────────────────── #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> /// <param name="out_recCond"></param> /// <param name="logic"></param> /// <param name="sField"></param> /// <param name="s_ParentNode"></param> /// <returns></returns> public static bool TryBuild( out Recordcondition out_RecCond, EnumLogic enumLogic, string sField, Configuration_Node parent_Conf, Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0); log_Method.BeginMethod(Info_Table.Name_Library, "RecCondImpl", "TryBuild",log_Reports); bool bSuccessful; sField = sField.Trim(); if (EnumLogic.None == enumLogic && "" != sField) { // 条件式 RecordconditionImpl rc = new RecordconditionImpl(parent_Conf); rc.sField = sField; out_RecCond = rc; bSuccessful = true; } else if (EnumLogic.None != enumLogic && "" == sField) { // グループ RecordconditionImpl rc = new RecordconditionImpl(parent_Conf); rc.sField = "(▲グループにフィールド属性無し103![" + enumLogic + "])"; rc.enumLogic = enumLogic; out_RecCond = rc; bSuccessful = true; } else { out_RecCond = null; bSuccessful = false; goto gt_Error_Attribute; } goto gt_EndMethod; // // #region 異常系 //──────────────────────────────────────── gt_Error_Attribute: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー101!", log_Method); StringBuilder s = new StringBuilder(); s.Append("<rec-cond>インスタンスを作成する引数にエラー。"); s.Append(Environment.NewLine); s.Append("logic=["); s.Append(enumLogic); s.Append("] sField=["); s.Append(sField); s.Append("]"); s.Append(Environment.NewLine); s.Append(r.Message_Configuration(parent_Conf)); r.Message = s.ToString(); log_Reports.EndCreateReport(); //throw new Exception(s.ToString()); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // // gt_EndMethod: log_Method.EndMethod(log_Reports); return bSuccessful; }
//──────────────────────────────────────── #endregion #region アクション //──────────────────────────────────────── /// <summary> /// where句の最初の条件を引っこ抜く。 /// 条件に合うものを一気に集めてくる形になっているが、 /// SelectedRecords に機能を持たせるか? /// </summary> /// <param name="out_Name_KeyField"></param> /// <param name="out_FielddefinitionKey2"></param> /// <param name="out_Value_Expected"></param> /// <param name="childReccondList"></param> /// <param name="tableH"></param> /// <param name="log_Reports"></param> public void GetFirstAwhrReccond( out string out_Name_KeyField, out Fielddefinition out_FielddefinitionKey2, out string out_Value_Expected, List <Recordcondition> list_ChildReccond, Table_Humaninput tableH, Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0, Log_ReportsImpl.BDebugmode_Static); log_Method.BeginMethod(Info_Expr.Name_Library, this, "GetFirstAwhrReccond", log_Reports); // // Recordcondition err_Recordcondition = null; if (0 < list_ChildReccond.Count) { Recordcondition recCond_First = list_ChildReccond[0]; err_Recordcondition = recCond_First; // // 検索のキーとなるフィールドの定義を調べます。 List <string> list_Name_KeyFld; { // 要素数1個 list_Name_KeyFld = new List <string>(); list_Name_KeyFld.Add(recCond_First.Name_Field); } // 該当なしの場合、ヌルを返す。 RecordFielddefinition recordFielddefinition; bool bHit = tableH.TryGetFieldDefinitionByName( out recordFielddefinition, list_Name_KeyFld, true,// 必須指定。 log_Reports ); if (!log_Reports.Successful || !bHit) { // エラー out_Name_KeyField = ""; out_FielddefinitionKey2 = null; out_Value_Expected = ""; goto gt_EndMethod; } //正常 out_FielddefinitionKey2 = recordFielddefinition.ValueAt(0); out_Name_KeyField = recCond_First.Name_Field; out_Value_Expected = recCond_First.Value; } else { //正常 out_Name_KeyField = ""; out_FielddefinitionKey2 = null; out_Value_Expected = ""; } goto gt_EndMethod; // // // // gt_EndMethod: log_Method.EndMethod(log_Reports); }
//──────────────────────────────────────── #endregion #region アクション //──────────────────────────────────────── /// <summary> /// インスタンスを作ります。 /// </summary> /// <param name="out_recCond"></param> /// <param name="logic"></param> /// <param name="sField"></param> /// <param name="s_ParentNode"></param> /// <returns></returns> public static bool TryBuild( out Recordcondition out_RecCond, EnumLogic enumLogic, string sField, Conf_String parent_Conf, Log_Reports log_Reports ) { Log_Method log_Method = new Log_MethodImpl(0); log_Method.BeginMethod(Info_Table.Name_Library, "RecCondImpl", "TryBuild", log_Reports); bool bSuccessful; sField = sField.Trim(); if (EnumLogic.None == enumLogic && "" != sField) { // 条件式 RecordconditionImpl rc = new RecordconditionImpl(parent_Conf); rc.sField = sField; out_RecCond = rc; bSuccessful = true; } else if (EnumLogic.None != enumLogic && "" == sField) { // グループ RecordconditionImpl rc = new RecordconditionImpl(parent_Conf); rc.sField = "(▲グループにフィールド属性無し103![" + enumLogic + "])"; rc.enumLogic = enumLogic; out_RecCond = rc; bSuccessful = true; } else { out_RecCond = null; bSuccessful = false; goto gt_Error_Attribute; } goto gt_EndMethod; // // #region 異常系 //──────────────────────────────────────── gt_Error_Attribute: if (log_Reports.CanCreateReport) { Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error); r.SetTitle("▲エラー101!", log_Method); StringBuilder s = new StringBuilder(); s.Append("<rec-cond>インスタンスを作成する引数にエラー。"); s.Append(Environment.NewLine); s.Append("logic=["); s.Append(enumLogic); s.Append("] sField=["); s.Append(sField); s.Append("]"); s.Append(Environment.NewLine); s.Append(r.Message_Conf(parent_Conf)); r.Message = s.ToString(); log_Reports.EndCreateReport(); //throw new Exception(s.ToString()); } goto gt_EndMethod; //──────────────────────────────────────── #endregion // // gt_EndMethod: log_Method.EndMethod(log_Reports); return(bSuccessful); }