Example #1
0
        //────────────────────────────────────────

        /// <summary>
        ///
        /// </summary>
        /// <param name="out_sFieldListList"></param>
        /// <param name="out_O_NewFldDefList"></param>
        /// <param name="src_sNewFieldNameList"></param>
        /// <param name="e_Where"></param>
        /// <param name="tableH_Source"></param>
        /// <param name="log_Reports"></param>
        public static void SelectFieldListList(
            out List <List <string> > listList_SField_Out,
            out RecordFielddefinition out_RecordFielddefinition_New,
            EnumLogic enumWhereLogic,
            List <string> list_SName_NewField_Src,
            List <Recordcondition> list_Reccond,
            Table_Humaninput tableH_Source,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

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

            //

            RecordFielddefinition recordFielddefinition_New = new RecordFielddefinitionImpl();
            List <int>            list_indexField           = new List <int>();

            //
            // 新しい、列定義リストを作成します。
            //
            {
                // 最初の列は「NO」とします。
                list_SName_NewField_Src.Insert(0, Utility_Table.S_FIELD_NO);

                //fieldIndex
                int nFIx = 0;
                tableH_Source.RecordFielddefinition.ForEach(delegate(Fielddefinition fielddefinition, ref bool isBreak, Log_Reports log_Reports2)
                {
                    if (list_SName_NewField_Src.Contains(fielddefinition.Name_Humaninput))
                    {
                        // 選出されたフィールドだけでリストを作ります。
                        recordFielddefinition_New.Add(fielddefinition);
                        list_indexField.Add(nFIx);
                    }

                    nFIx++;
                }, log_Reports);
            }



            //
            // テーブルに列定義を設定した後で。
            // 移し替えたいデータ値の配列を作ります。
            listList_SField_Out = new List <List <string> >();
            //
            {
                int nEndover = list_indexField.Count;
                foreach (DataRow srcRow in tableH_Source.DataTable.Rows)
                {
                    List <string> sList_NewField = new List <string>();


                    //
                    // 「E■@where」属性を解析します。
                    //
                    // 該当しないレコードは除去していきます。
                    //
                    // 「E■@where」に logic属性が無い場合は logic="and" とします。
                    if (EnumLogic.None == enumWhereLogic)
                    {
                        enumWhereLogic = EnumLogic.And;
                    }
                    bool bHit = Utility_Table.ApplyReccond(srcRow, tableH_Source, enumWhereLogic, list_Reccond, 0, log_Reports);
                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.SelectFieldListList: (結果) [" + bHit + "]");

                    if (bHit)
                    {
                        for (int nA = 0; nA < nEndover; nA++)
                        {
                            // TODO:指定のフィールド・インデックスだけをピックアップしたい。
                            int nB = list_indexField[nA];
                            Value_Humaninput o_Value = (Value_Humaninput)srcRow[nB];

                            sList_NewField.Add(o_Value.Text);
                        }

                        listList_SField_Out.Add(sList_NewField);
                    }
                    //hit
                }
            }


            goto gt_EndMethod;

            //
            //
            //
            //
gt_EndMethod:
            out_RecordFielddefinition_New = recordFielddefinition_New;
            log_Method.EndMethod(log_Reports);
        }
        //────────────────────────────────────────
        /// <summary>
        /// TODO:「,」「"」に対応したい。
        /// 
        /// 
        /// 縦と横が逆のテーブル。
        /// 
        /// CSVを読取り、テーブルにして返します。
        /// 
        /// 
        /// SRS仕様の実装状況
        /// ここでは、先頭行を[0]行目と数えるものとします。
        /// (1)CSVの[0]行目は列名です。
        /// (2)CSVの[1]行目は型名です。
        /// (3)CSVの[2]行目はコメントです。
        /// 
        /// (4)データ・テーブル部で、0列目に「EOF」と入っていれば終了。大文字・小文字は区別せず。
        ///    それ以降に、コメントのようなデータが入力されていることがあるが、フィールドの型に一致しないことがあるので無視。
        ///    TODO EOF以降の行も、コメントとして残したい。
        /// 
        /// (5)列名にENDがある場合、その手前までの列が有効データです。
        ///    END以降の列は無視します。
        ///    TODO END以降の行も、コメントとして残したい。
        /// 
        /// (6)int型として指定されているフィールドのデータ・テーブル部に空欄があった場合、DBNull(データベース用のヌル)とします。
        /// </summary>
        /// <param name="csvText"></param>
        /// <returns>列名情報も含むテーブル。列の型は文字列型とします。</returns>
        public Table_Humaninput Read(
            string string_Csv,
            Request_ReadsTable forTable_Request,
            Format_Table_Humaninput forTable_Format,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();
            log_Method.BeginMethod(Info_Table.Name_Library, this, "Read",log_Reports);

            //
            //
            //
            //
            CsvLineParserImpl csvParser = new CsvLineParserImpl();

            Table_Humaninput xenonTable = new Table_HumaninputImpl(
                forTable_Request.Name_PutToTable, forTable_Request.Expression_Filepath, forTable_Request.Expression_Filepath.Cur_Configuration );
            xenonTable.Tableunit = forTable_Request.Tableunit;
            xenonTable.Typedata = forTable_Request.Typedata;
            xenonTable.IsDatebackupActivated = forTable_Request.IsDatebackupActivated;
            xenonTable.Format_Table_Humaninput = forTable_Format;

            //
            // 一旦、テーブルを全て読み込みます。
            //
            List<List<string>> lines = new List<List<string>>();

            {
                // CSVテキストを読み込み、型とデータのバッファーを作成します。
                System.IO.StringReader reader = new System.IO.StringReader(string_Csv);

                while (-1 < reader.Peek())
                {
                    string sLine = reader.ReadLine();
                    List<string> tokens = new List<string>();

                    string[] sFields;
                    sFields = csvParser.UnescapeLineToFieldList(sLine, this.charSeparator).ToArray();

                    int nColumnIndex = 0;
                    foreach (string sToken in sFields)
                    {
                        if (nColumnIndex == 0 && ToCsv_Table_Humaninput_RowColRegularImpl.S_END == sToken.Trim().ToUpper())
                        {
                            // 1列目にENDがある場合、その手前までの列が有効データです。
                            // END以降の行は無視します。
                            goto row_end;
                        }

                        tokens.Add(sToken);

                        nColumnIndex++;
                    }
                    lines.Add(tokens);
                }
            row_end:

                // ストリームを閉じます。
                reader.Close();
            }

            //
            // 型定義部
            //
            // (※NO,ID,EXPL,NAME など、フィールドの定義を持つテーブル)
            //
            RecordFielddefinition recordFielddefinition = new RecordFielddefinitionImpl();

            //
            // データ・テーブル部
            //
            List<List<string>> rows = new List<List<string>>();

            //
            // まず、0列目、1列目、2列目のデータを読み取ります。
            //
            int nRowIndex=0;
            foreach (List<string> tokens in lines)
            {
                Fielddefinition fieldDefinition = null;

                int nColumnIndex = 0;
                foreach(string sToken in tokens)
                {

                    if(0==nColumnIndex)
                    {
                        //
                        // 0列目は、フィールド名です。
                        //
                        string sFieldName = sToken;//.Trim().ToUpper();

                        // テーブルのフィールドを追加します。型の既定値は文字列型とします。
                        fieldDefinition = new FielddefinitionImpl(sFieldName, EnumTypeFielddefinition.String);
                        recordFielddefinition.Add(fieldDefinition);
                    }
                    else if(1==nColumnIndex)
                    {
                        //
                        // 1列目は、フィールドの型名です。
                        //
                        nColumnIndex = 1;
                        string sFieldTypeNameLower = sToken.Trim().ToLower();

                        // テーブルのフィールドを追加します。型の既定値は文字列型とします。
                        // TODO int型とboolean型にも対応したい。
                        if (FielddefinitionImpl.S_STRING.Equals(sFieldTypeNameLower))
                        {
                            fieldDefinition.Type_Field = EnumTypeFielddefinition.String;
                        }
                        else if (FielddefinitionImpl.S_INT.Equals(sFieldTypeNameLower))
                        {
                            fieldDefinition.Type_Field = EnumTypeFielddefinition.Int;
                        }
                        else if (FielddefinitionImpl.S_BOOL.Equals(sFieldTypeNameLower))
                        {
                            fieldDefinition.Type_Field = EnumTypeFielddefinition.Bool;
                        }
                        else
                        {
                            // 型が未定義の列は、文字列型として読み取ります。

                            // TODO: 警告。(エラーではない)

                            Log_TextIndented t = new Log_TextIndentedImpl();
                            t.Append("▲エラー45!(" + Info_Table.Name_Library + ")");
                            t.Newline();

                            t.Append("型の名前を記入してください。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("※縦と横がひっくり返っているテーブルと指定されています。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("1列目(先頭を0とする)に、型の名前は必須です。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("[");

                            t.Append(fieldDefinition.Name_Humaninput);

                            t.Append("]フィールド ([");
                            t.Append(nRowIndex);
                            t.Append("]行目)に、");
                            t.Append(Environment.NewLine);
                            t.Append("型名が[");
                            t.Append(sFieldTypeNameLower);
                            t.Append("]と入っています。この名前には、未対応です。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("文字列型として続行します。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("テーブル名=[");
                            t.Append(forTable_Request.Name_PutToTable);
                            t.Append("]");
                            t.Append(Environment.NewLine);
                            t.Append("ファイル・パス=[");
                            t.Append(forTable_Request.Expression_Filepath.Humaninput);
                            t.Append("]");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);

                            string sWarning = t.ToString();

                            MessageBox.Show(sWarning, "▲警告!(L02)");

                            fieldDefinition.Type_Field = EnumTypeFielddefinition.String;
                        }
                    }
                    else if(2==nColumnIndex)
                    {
                        //
                        // 2列目は、フィールドのコメントとします。
                        //
                        nColumnIndex = 2;
                        {
                            fieldDefinition.Comment = sToken;
                        }

                    }
                    else
                    {
                        //
                        // 3列目から右側は、データ・テーブル部。
                        //

                        if(0==nRowIndex)
                        {
                            //
                            // 先頭行
                            //

                            //
                            // 「EOF」というトークンが出てくるまで。
                            //
                            if(ToCsv_Table_Humaninput_RowColRegularImpl.S_EOF==sToken.Trim().ToUpper())
                            {
                                goto column_end;
                            }

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

                            // 1番目のフィールド_データを追加。
                            record.Add( sToken);

                            rows.Add(record);
                        }
                        else
                        {
                            //
                            // 2番目以降のフィールド_データを追加。
                            //

                            //
                            // 先頭の3つのレコード分、切り詰めます。
                            //
                            int nDataIndex = nColumnIndex - 3;
                            if (nDataIndex < rows.Count)
                            {
                                List<string> record = rows[nDataIndex];

                                record.Add(sToken);
                            }
                            else
                            {
                                // 無視
                            }
                        }
                    }

                    nColumnIndex ++;
                }//c
            column_end:

                nRowIndex++;
            }

            //essageBox.Show("CSV読取終わり1 rows.Count=[" + rows.Count + "]", "TableCsvLibデバッグ");

            // テーブル作成。テーブルのフィールド型定義と、データ本体をセットします。
            xenonTable.CreateTable(recordFielddefinition, log_Reports);
            if (log_Reports.Successful)
            {
                xenonTable.AddRecordList(rows, recordFielddefinition, log_Reports);
                //essageBox.Show("CSV読取後のテーブル作成終わり", "TableCsvLibデバッグ");
            }

            goto gt_EndMethod;
            //
            //
            gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return xenonTable;
        }
Example #3
0
        //────────────────────────────────────────
        #endregion



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

        /// <summary>
        /// TODO:「,」「"」に対応したい。
        ///
        ///
        /// 縦と横が逆のテーブル。
        ///
        /// CSVを読取り、テーブルにして返します。
        ///
        ///
        /// SRS仕様の実装状況
        /// ここでは、先頭行を[0]行目と数えるものとします。
        /// (1)CSVの[0]行目は列名です。
        /// (2)CSVの[1]行目は型名です。
        /// (3)CSVの[2]行目はコメントです。
        ///
        /// (4)データ・テーブル部で、0列目に「EOF」と入っていれば終了。大文字・小文字は区別せず。
        ///    それ以降に、コメントのようなデータが入力されていることがあるが、フィールドの型に一致しないことがあるので無視。
        ///    TODO EOF以降の行も、コメントとして残したい。
        ///
        /// (5)列名にENDがある場合、その手前までの列が有効データです。
        ///    END以降の列は無視します。
        ///    TODO END以降の行も、コメントとして残したい。
        ///
        /// (6)int型として指定されているフィールドのデータ・テーブル部に空欄があった場合、DBNull(データベース用のヌル)とします。
        /// </summary>
        /// <param name="csvText"></param>
        /// <returns>列名情報も含むテーブル。列の型は文字列型とします。</returns>
        public Table_Humaninput Read(
            string string_Csv,
            Request_ReadsTable forTable_Request,
            Format_Table_Humaninput forTable_Format,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

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

            //
            //
            //
            //
            CsvLineParserImpl csvParser = new CsvLineParserImpl();


            Table_Humaninput xenonTable = new Table_HumaninputImpl(
                forTable_Request.Name_PutToTable, forTable_Request.Expression_Filepath, forTable_Request.Expression_Filepath.Cur_Configuration);

            xenonTable.Tableunit               = forTable_Request.Tableunit;
            xenonTable.Typedata                = forTable_Request.Typedata;
            xenonTable.IsDatebackupActivated   = forTable_Request.IsDatebackupActivated;
            xenonTable.Format_Table_Humaninput = forTable_Format;


            //
            // 一旦、テーブルを全て読み込みます。
            //
            List <List <string> > lines = new List <List <string> >();

            {
                // CSVテキストを読み込み、型とデータのバッファーを作成します。
                System.IO.StringReader reader = new System.IO.StringReader(string_Csv);


                while (-1 < reader.Peek())
                {
                    string        sLine  = reader.ReadLine();
                    List <string> tokens = new List <string>();

                    string[] sFields;
                    sFields = csvParser.UnescapeLineToFieldList(sLine, this.charSeparator).ToArray();

                    int nColumnIndex = 0;
                    foreach (string sToken in sFields)
                    {
                        if (nColumnIndex == 0 && ToCsv_Table_Humaninput_RowColRegularImpl.S_END == sToken.Trim().ToUpper())
                        {
                            // 1列目にENDがある場合、その手前までの列が有効データです。
                            // END以降の行は無視します。
                            goto row_end;
                        }


                        tokens.Add(sToken);

                        nColumnIndex++;
                    }
                    lines.Add(tokens);
                }
row_end:

                // ストリームを閉じます。
                reader.Close();
            }



            //
            // 型定義部
            //
            // (※NO,ID,EXPL,NAME など、フィールドの定義を持つテーブル)
            //
            RecordFielddefinition recordFielddefinition = new RecordFielddefinitionImpl();

            //
            // データ・テーブル部
            //
            List <List <string> > rows = new List <List <string> >();

            //
            // まず、0列目、1列目、2列目のデータを読み取ります。
            //
            int nRowIndex = 0;

            foreach (List <string> tokens in lines)
            {
                Fielddefinition fieldDefinition = null;



                int nColumnIndex = 0;
                foreach (string sToken in tokens)
                {
                    if (0 == nColumnIndex)
                    {
                        //
                        // 0列目は、フィールド名です。
                        //
                        string sFieldName = sToken;//.Trim().ToUpper();

                        // テーブルのフィールドを追加します。型の既定値は文字列型とします。
                        fieldDefinition = new FielddefinitionImpl(sFieldName, EnumTypeFielddefinition.String);
                        recordFielddefinition.Add(fieldDefinition);
                    }
                    else if (1 == nColumnIndex)
                    {
                        //
                        // 1列目は、フィールドの型名です。
                        //
                        nColumnIndex = 1;
                        string sFieldTypeNameLower = sToken.Trim().ToLower();

                        // テーブルのフィールドを追加します。型の既定値は文字列型とします。
                        // TODO int型とboolean型にも対応したい。
                        if (FielddefinitionImpl.S_STRING.Equals(sFieldTypeNameLower))
                        {
                            fieldDefinition.Type_Field = EnumTypeFielddefinition.String;
                        }
                        else if (FielddefinitionImpl.S_INT.Equals(sFieldTypeNameLower))
                        {
                            fieldDefinition.Type_Field = EnumTypeFielddefinition.Int;
                        }
                        else if (FielddefinitionImpl.S_BOOL.Equals(sFieldTypeNameLower))
                        {
                            fieldDefinition.Type_Field = EnumTypeFielddefinition.Bool;
                        }
                        else
                        {
                            // 型が未定義の列は、文字列型として読み取ります。

                            // TODO: 警告。(エラーではない)

                            Log_TextIndented t = new Log_TextIndentedImpl();
                            t.Append("▲エラー45!(" + Info_Table.Name_Library + ")");
                            t.Newline();

                            t.Append("型の名前を記入してください。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("※縦と横がひっくり返っているテーブルと指定されています。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("1列目(先頭を0とする)に、型の名前は必須です。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("[");

                            t.Append(fieldDefinition.Name_Humaninput);

                            t.Append("]フィールド ([");
                            t.Append(nRowIndex);
                            t.Append("]行目)に、");
                            t.Append(Environment.NewLine);
                            t.Append("型名が[");
                            t.Append(sFieldTypeNameLower);
                            t.Append("]と入っています。この名前には、未対応です。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("文字列型として続行します。");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);
                            t.Append("テーブル名=[");
                            t.Append(forTable_Request.Name_PutToTable);
                            t.Append("]");
                            t.Append(Environment.NewLine);
                            t.Append("ファイル・パス=[");
                            t.Append(forTable_Request.Expression_Filepath.Humaninput);
                            t.Append("]");
                            t.Append(Environment.NewLine);
                            t.Append(Environment.NewLine);

                            string sWarning = t.ToString();

                            MessageBox.Show(sWarning, "▲警告!(L02)");

                            fieldDefinition.Type_Field = EnumTypeFielddefinition.String;
                        }
                    }
                    else if (2 == nColumnIndex)
                    {
                        //
                        // 2列目は、フィールドのコメントとします。
                        //
                        nColumnIndex = 2;
                        {
                            fieldDefinition.Comment = sToken;
                        }
                    }
                    else
                    {
                        //
                        // 3列目から右側は、データ・テーブル部。
                        //

                        if (0 == nRowIndex)
                        {
                            //
                            // 先頭行
                            //

                            //
                            // 「EOF」というトークンが出てくるまで。
                            //
                            if (ToCsv_Table_Humaninput_RowColRegularImpl.S_EOF == sToken.Trim().ToUpper())
                            {
                                goto column_end;
                            }

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

                            // 1番目のフィールド_データを追加。
                            record.Add(sToken);

                            rows.Add(record);
                        }
                        else
                        {
                            //
                            // 2番目以降のフィールド_データを追加。
                            //

                            //
                            // 先頭の3つのレコード分、切り詰めます。
                            //
                            int nDataIndex = nColumnIndex - 3;
                            if (nDataIndex < rows.Count)
                            {
                                List <string> record = rows[nDataIndex];

                                record.Add(sToken);
                            }
                            else
                            {
                                // 無視
                            }
                        }
                    }


                    nColumnIndex++;
                }//c
column_end:


                nRowIndex++;
            }



            //essageBox.Show("CSV読取終わり1 rows.Count=[" + rows.Count + "]", "TableCsvLibデバッグ");

            // テーブル作成。テーブルのフィールド型定義と、データ本体をセットします。
            xenonTable.CreateTable(recordFielddefinition, log_Reports);
            if (log_Reports.Successful)
            {
                xenonTable.AddRecordList(rows, recordFielddefinition, log_Reports);
                //essageBox.Show("CSV読取後のテーブル作成終わり", "TableCsvLibデバッグ");
            }

            goto gt_EndMethod;
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(xenonTable);
        }
Example #4
0
        //────────────────────────────────────────
        #endregion



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

        /// <summary>
        /// TODO:「,」「"」に対応したい。
        ///
        ///
        /// 縦、横がひっくり返っていて、
        /// 型定義レコードがないCSVテーブルの読取。
        /// </summary>
        /// <param name="csvText"></param>
        /// <returns>列名情報も含むテーブル。</returns>
        public Table_Humaninput Read(
            string string_Csv,
            Request_ReadsTable forTable_Request,
            Format_Table_Humaninput forTable_Format,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

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

            //
            //
            //
            //
            CsvLineParserImpl csvParser = new CsvLineParserImpl();

            Table_Humaninput xenonTable = new Table_HumaninputImpl(
                forTable_Request.Name_PutToTable, forTable_Request.Expression_Filepath, forTable_Request.Expression_Filepath.Cur_Configuration);

            xenonTable.Tableunit               = forTable_Request.Tableunit;
            xenonTable.Typedata                = forTable_Request.Typedata;
            xenonTable.IsDatebackupActivated   = forTable_Request.IsDatebackupActivated;
            xenonTable.Format_Table_Humaninput = forTable_Format;


            //
            // 一旦、テーブルを全て読み込みます。
            //
            List <List <string> > lines = new List <List <string> >();

            {
                // CSVテキストを読み込み、型とデータのバッファーを作成します。
                System.IO.StringReader reader = new System.IO.StringReader(string_Csv);


                string[] sFields;
                while (-1 < reader.Peek())
                {
                    string        sLine  = reader.ReadLine();
                    List <string> tokens = new List <string>();

                    sFields = csvParser.UnescapeLineToFieldList(sLine, this.charSeparator).ToArray();

                    int nColumnIndex = 0;
                    foreach (string sToken in sFields)
                    {
                        if (nColumnIndex == 0 && ToCsv_Table_Humaninput_RowColRegularImpl.S_END == sToken.Trim().ToUpper())
                        {
                            // 1列目にENDがある場合、その手前までの列が有効データです。
                            // END以降の行は無視します。
                            goto row_end;
                        }


                        tokens.Add(sToken);

                        nColumnIndex++;
                    }
                    lines.Add(tokens);
                }
row_end:

                // ストリームを閉じます。
                reader.Close();
            }



            //
            // 型定義部
            //
            // (※NO,ID,EXPL,NAME など、フィールドの定義を持つテーブル)
            //
            RecordFielddefinition recordFielddefinition = new RecordFielddefinitionImpl();

            //
            // データ・テーブル部
            //
            List <List <string> > rows = new List <List <string> >();

            //
            // まず、0列目、1列目のデータを読み取ります。
            //
            int nRowIndex = 0;

            foreach (List <string> tokens in lines)
            {
                Fielddefinition fieldDefinition = null;



                int nColumnIndex = 0;
                foreach (string sToken in tokens)
                {
                    if (0 == nColumnIndex)
                    {
                        //
                        // 0列目は、フィールド名です。
                        //
                        string sFieldName = sToken;//.Trim().ToUpper();

                        // テーブルのフィールドを追加します。フィールドの型は、intに固定です。
                        fieldDefinition = new FielddefinitionImpl(sFieldName, EnumTypeFielddefinition.Int);
                        recordFielddefinition.Add(fieldDefinition);
                    }
                    else if (1 == nColumnIndex)
                    {
                        //
                        // 1列目は、フィールドのコメントとします。
                        //
                        nColumnIndex = 1;
                        {
                            fieldDefinition.Comment = sToken;
                        }
                    }
                    else
                    {
                        //
                        // 2列目から右側は、データ・テーブル部。
                        //

                        if (0 == nRowIndex)
                        {
                            //
                            // 先頭行
                            //

                            //
                            // 「EOF」というトークンが出てくるまで。
                            //
                            if (ToCsv_Table_Humaninput_RowColRegularImpl.S_EOF == sToken.Trim().ToUpper())
                            {
                                goto column_end;
                            }

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

                            // 1番目のフィールド_データを追加。
                            record.Add(sToken);

                            rows.Add(record);
                        }
                        else
                        {
                            //
                            // 2番目以降のフィールド_データを追加。
                            //

                            //
                            // 先頭の2つのレコード分、切り詰めます。
                            //
                            int nDataIndex = nColumnIndex - 2;
                            if (nDataIndex < rows.Count)
                            {
                                List <string> record = rows[nDataIndex];

                                record.Add(sToken);
                            }
                            else
                            {
                                // 無視
                            }
                        }
                    }


                    nColumnIndex++;
                }//c
column_end:


                nRowIndex++;
            }



            //essageBox.Show("CSV読取終わり1 rows.Count=[" + rows.Count + "]", "TableCsvLibデバッグ");

            // テーブル作成。テーブルのフィールド型定義と、データ本体をセットします。
            xenonTable.CreateTable(recordFielddefinition, log_Reports);
            if (log_Reports.Successful)
            {
                xenonTable.AddRecordList(rows, recordFielddefinition, log_Reports);
                //essageBox.Show("CSV読取後のテーブル作成終わり", "TableCsvLibデバッグ");
            }

            goto gt_EndMethod;
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(xenonTable);
        }
Example #5
0
        //────────────────────────────────────────
        #endregion



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

        /// <summary>
        /// CSVを読取り、テーブルにして返します。
        ///
        ///
        /// SRS仕様の実装状況
        /// ここでは、先頭行を[0]行目と数えるものとします。
        /// (1)CSVの[0]行目は列名です。
        /// (2)CSVの[1]行目は型名です。
        /// (3)CSVの[2]行目はコメントです。
        ///
        /// (4)データ・テーブル部で、0列目に「EOF」と入っていれば終了。大文字・小文字は区別せず。
        ///    それ以降に、コメントのようなデータが入力されていることがあるが、フィールドの型に一致しないことがあるので無視。
        ///    TODO: EOF以降の行も、コメントとして残したい。
        ///
        /// (5)列名に ”END”(半角) がある場合、その手前までの列が有効データです。
        ///    ”END”以降の列は無視します。
        ///    TODO: ”END”以降の行も、コメントとして残したい。
        ///
        /// (6)int型として指定されているフィールドのデータ・テーブル部に空欄があった場合、DBNull(データベース用のヌル)とします。
        /// </summary>
        /// <param name="csvText"></param>
        /// <returns>列名情報も含むテーブル。列の型は文字列型とします。</returns>
        public Table_Humaninput Read(
            string string_Csv,
            Request_ReadsTable forTable_request,
            Format_Table_Humaninput forTable_puts,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();

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

            Table_Humaninput xenonTable = new Table_HumaninputImpl(
                forTable_request.Name_PutToTable, forTable_request.Expression_Filepath, forTable_request.Expression_Filepath.Cur_Configuration);

            xenonTable.Tableunit               = forTable_request.Tableunit;
            xenonTable.Typedata                = forTable_request.Typedata;
            xenonTable.IsDatebackupActivated   = forTable_request.IsDatebackupActivated;
            xenonTable.Format_Table_Humaninput = forTable_puts;


            Exception err_Excp;
            int       error_Count_Index;

            string[] error_Fields_Cur;


            //
            // 型定義部
            //
            // (※NO,ID,EXPL,NAME など、フィールドの定義を持つテーブル)
            //
            RecordFielddefinition recordFielddefinition = new RecordFielddefinitionImpl();

            //
            // データ・テーブル部
            //
            List <List <string> > dataTableRows = new List <List <string> >();

            // CSVテキストを読み込み、型とデータのバッファーを作成します。
            System.IO.StringReader reader    = new System.IO.StringReader(string_Csv);
            CsvLineParserImpl      csvParser = new CsvLineParserImpl();

            // CSVを解析して、テーブル形式で格納。
            {
                // データとして認識する列の総数です。
                int nDataColumnsCount = 0;

                int      nRowIndex = 0;
                string[] fields_Cur;
                while (-1 < reader.Peek())
                {
                    string line = reader.ReadLine();

                    fields_Cur = csvParser.UnescapeLineToFieldList(line, this.charSeparator).ToArray();


                    if (0 == nRowIndex)
                    {
                        // 0行目

                        // 列名の行とします。

                        for (int nColumnIx = 0; nColumnIx < fields_Cur.Length; nColumnIx++)
                        {
                            string sColumnName = fields_Cur[nColumnIx];

                            // 列名を読み込みました。

                            // トリム&大文字
                            string sCellValueTU = sColumnName.Trim().ToUpper();
                            if (ToCsv_Table_Humaninput_RowColRegularImpl.S_END == sCellValueTU)
                            {
                                // 列名に ”END” がある場合、その手前までの列が有効データです。
                                // ”END” 以降の列は無視します。
                                goto field_name_reading_end;
                            }

                            // テーブルのフィールドを追加します。型の既定値は文字列型とします。
                            FielddefinitionImpl fieldDef = new FielddefinitionImpl(sColumnName, EnumTypeFielddefinition.String);
                            recordFielddefinition.Add(fieldDef);
                            nDataColumnsCount++;
                        }


                        // 0行目は、テーブルのデータとしては持ちません。
                    }
                    else if (1 == nRowIndex)
                    {
                        // 1行目

                        // フィールド型名の行。

                        for (int nColumnIx = 0; nColumnIx < nDataColumnsCount; nColumnIx++)
                        {
                            string name_FieldType_Lower;
                            try
                            {
                                name_FieldType_Lower = fields_Cur[nColumnIx].ToLower();
                            }
                            catch (IndexOutOfRangeException e)
                            {
                                err_Excp = e;
                                goto gt_Error_FdIndexOutOfRangeException;
                            }

                            // 列の型名を読み込みました。

                            // テーブルのフィールドを追加します。型の既定値は文字列型とします。
                            // TODO int型とboolean型にも対応したい。
                            if (FielddefinitionImpl.S_STRING.Equals(name_FieldType_Lower))
                            {
                                recordFielddefinition.ValueAt(nColumnIx).Type_Field = EnumTypeFielddefinition.String;
                            }
                            else if (FielddefinitionImpl.S_INT.Equals(name_FieldType_Lower))
                            {
                                recordFielddefinition.ValueAt(nColumnIx).Type_Field = EnumTypeFielddefinition.Int;
                            }
                            else if (FielddefinitionImpl.S_BOOL.Equals(name_FieldType_Lower))
                            {
                                // 2009-11-11修正:SRS仕様では「bool」が正しい。「boolean」は間違い。
                                recordFielddefinition.ValueAt(nColumnIx).Type_Field = EnumTypeFielddefinition.Bool;
                            }
                            else
                            {
                                // 型が未定義の列は、文字列型として読み取ります。

                                // TODO:警告を出すか?

                                recordFielddefinition.ValueAt(nColumnIx).Type_Field = EnumTypeFielddefinition.String;
                            }
                        }

                        // 1行目は、テーブルのデータとしては持ちません。
                    }
                    else if (2 == nRowIndex)
                    {
                        // 2行目

                        // フィールドのコメントの行。
                        // TODO: フィールドのコメントの行は省略されることがある。

                        for (int column = 0; column < nDataColumnsCount; column++)
                        {
                            if (fields_Cur.Length <= column)
                            {
                                error_Fields_Cur = fields_Cur;
                                //error_Count_Columns = fields_Cur.Length;
                                error_Count_Index = column;
                                goto gt_Error_CommentFieldCount;
                            }

                            string comment_Field = fields_Cur[column];//todo:bug:境界線エラーをキャッチしてない。

                            recordFielddefinition.ValueAt(column).Comment = comment_Field;
                        }

                        // 2行目は、テーブルのデータとしては持ちません。
                    }
                    else
                    {
                        // 3行目以降のループ。
                        List <string> sList_Column = new List <string>();

                        // データ・テーブル部で、0列目に「EOF」と入っていれば終了。大文字・小文字は区別せず。

                        if (fields_Cur.Length < 1)
                        {
                            // 空行は無視。
                            goto end_recordAdd;
                        }
                        //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":" + this.GetType().Name + "#UnescapeToList: sFields[0]=[" + sFields[0] + "] sLine=[" + sLine + "]");

                        string sCellValueTrimUpper = fields_Cur[0].Trim().ToUpper();
                        if (ToCsv_Table_Humaninput_RowColRegularImpl.S_EOF == sCellValueTrimUpper)
                        {
                            goto reading_end;
                        }

                        int nColumnCount;
                        if (fields_Cur.Length < nDataColumnsCount)
                        {
                            // 「実際にデータとして存在する列数」
                            nColumnCount = fields_Cur.Length;
                        }
                        else
                        {
                            // 「データとして存在する筈の列数」(これ以降の列は無視)
                            nColumnCount = nDataColumnsCount;
                        }


                        for (int nColumnIx = 0; nColumnIx < nColumnCount; nColumnIx++)
                        {
                            string sValue;

                            sValue = fields_Cur[nColumnIx];

                            if (recordFielddefinition.Count <= nColumnIx)
                            {
                                // 0行目で数えた列数より多い場合。

                                // テーブルのフィールドを追加します。型は文字列型とします。名前は空文字列です。
                                recordFielddefinition.Add(new FielddefinitionImpl("", EnumTypeFielddefinition.String));
                            }

                            sList_Column.Add(sValue);
                        }

                        dataTableRows.Add(sList_Column);
end_recordAdd:
                        ;
                    }
field_name_reading_end:

                    //essageBox.Show("ttbwIndex=[" + ttbwIndex + "]行目ループ終わり", "TableCsvLibデバッグ");
                    nRowIndex++;
                }
            }
reading_end:

            // ストリームを閉じます。
            reader.Close();

            //essageBox.Show("CSV読取終わり1 rows.Count=[" + rows.Count + "]", "TableCsvLibデバッグ");


            // テーブルのフィールド定義。
            xenonTable.CreateTable(recordFielddefinition, log_Reports);
            if (log_Reports.Successful)
            {
                // データ本体のセット。
                xenonTable.AddRecordList(dataTableRows, recordFielddefinition, log_Reports);
            }

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

                Log_TextIndented s = new Log_TextIndentedImpl();

                s.Append("「フィールド・コメント」行のフィールド数が合いませんでした。");
                s.Append(Environment.NewLine);
                s.Append(Environment.NewLine);

                s.Append("index=[");
                s.Append(error_Count_Index);
                s.Append("]");
                s.Append(Environment.NewLine);

                s.Append("列数=[");
                s.Append(error_Fields_Cur.Length);
                s.Append("]");
                s.Append(Environment.NewLine);
                s.Append(Environment.NewLine);

                s.Append("──────────fields ここから");
                s.Append(Environment.NewLine);
                foreach (string field in error_Fields_Cur)
                {
                    s.Append("field=[");
                    s.Append(field);
                    s.Append("]");
                    s.Append(Environment.NewLine);
                }
                s.Append("──────────fields ここまで");
                s.Append(Environment.NewLine);

                //
                // ヒント
                s.Append(Log_RecordReportsImpl.ToText_Configuration(xenonTable));

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
gt_Error_FdIndexOutOfRangeException:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー132!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Newline();

                s.Append("フィールド定義の数が合いませんでした。");
                s.Append(Environment.NewLine);
                s.Append(Environment.NewLine);

                string sFpatha = forTable_request.Expression_Filepath.Execute4_OnExpressionString(
                    EnumHitcount.Unconstraint, log_Reports);
                s.Append("ファイルパス=[");
                s.Append(sFpatha);
                s.Append("]");
                s.Append(Environment.NewLine);
                s.Append(Environment.NewLine);

                //
                // ヒント
                s.Append(err_Excp.Message);

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return(xenonTable);
        }
        //────────────────────────────────────────
        /// <summary>
        /// CSVを読取り、テーブルにして返します。
        /// 
        /// 
        /// SRS仕様の実装状況
        /// ここでは、先頭行を[0]行目と数えるものとします。
        /// (1)CSVの[0]行目は列名です。
        /// (2)CSVの[1]行目は型名です。
        /// (3)CSVの[2]行目はコメントです。
        /// 
        /// (4)データ・テーブル部で、0列目に「EOF」と入っていれば終了。大文字・小文字は区別せず。
        ///    それ以降に、コメントのようなデータが入力されていることがあるが、フィールドの型に一致しないことがあるので無視。
        ///    TODO: EOF以降の行も、コメントとして残したい。
        /// 
        /// (5)列名に ”END”(半角) がある場合、その手前までの列が有効データです。
        ///    ”END”以降の列は無視します。
        ///    TODO: ”END”以降の行も、コメントとして残したい。
        /// 
        /// (6)int型として指定されているフィールドのデータ・テーブル部に空欄があった場合、DBNull(データベース用のヌル)とします。
        /// </summary>
        /// <param name="csvText"></param>
        /// <returns>列名情報も含むテーブル。列の型は文字列型とします。</returns>
        public Table_Humaninput Read(
            string string_Csv,
            Request_ReadsTable forTable_request,
            Format_Table_Humaninput forTable_puts,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();
            log_Method.BeginMethod(Info_Table.Name_Library, this, "Read(1)",log_Reports);

            Table_Humaninput xenonTable = new Table_HumaninputImpl(
                forTable_request.Name_PutToTable, forTable_request.Expression_Filepath, forTable_request.Expression_Filepath.Cur_Configuration );
            xenonTable.Tableunit = forTable_request.Tableunit;
            xenonTable.Typedata = forTable_request.Typedata;
            xenonTable.IsDatebackupActivated = forTable_request.IsDatebackupActivated;
            xenonTable.Format_Table_Humaninput = forTable_puts;

            Exception err_Excp;
            int error_Count_Index;
            string[] error_Fields_Cur;

            //
            // 型定義部
            //
            // (※NO,ID,EXPL,NAME など、フィールドの定義を持つテーブル)
            //
            RecordFielddefinition recordFielddefinition = new RecordFielddefinitionImpl();

            //
            // データ・テーブル部
            //
            List<List<string>> dataTableRows = new List<List<string>>();

            // CSVテキストを読み込み、型とデータのバッファーを作成します。
            System.IO.StringReader reader = new System.IO.StringReader(string_Csv);
            CsvLineParserImpl csvParser = new CsvLineParserImpl();

            // CSVを解析して、テーブル形式で格納。
            {
                // データとして認識する列の総数です。
                int nDataColumnsCount = 0;

                int nRowIndex = 0;
                string[] fields_Cur;
                while (-1 < reader.Peek())
                {
                    string line = reader.ReadLine();

                    fields_Cur = csvParser.UnescapeLineToFieldList(line, this.charSeparator).ToArray();

                    if (0 == nRowIndex)
                    {
                        // 0行目

                        // 列名の行とします。

                        for (int nColumnIx = 0; nColumnIx < fields_Cur.Length; nColumnIx++)
                        {
                            string sColumnName = fields_Cur[nColumnIx];

                            // 列名を読み込みました。

                            // トリム&大文字
                            string sCellValueTU = sColumnName.Trim().ToUpper();
                            if (ToCsv_Table_Humaninput_RowColRegularImpl.S_END == sCellValueTU)
                            {
                                // 列名に ”END” がある場合、その手前までの列が有効データです。
                                // ”END” 以降の列は無視します。
                                goto field_name_reading_end;
                            }

                            // テーブルのフィールドを追加します。型の既定値は文字列型とします。
                            FielddefinitionImpl fieldDef = new FielddefinitionImpl(sColumnName, EnumTypeFielddefinition.String);
                            recordFielddefinition.Add(fieldDef);
                            nDataColumnsCount++;
                        }

                        // 0行目は、テーブルのデータとしては持ちません。
                    }
                    else if (1 == nRowIndex)
                    {
                        // 1行目

                        // フィールド型名の行。

                        for (int nColumnIx = 0; nColumnIx < nDataColumnsCount; nColumnIx++)
                        {
                            string name_FieldType_Lower;
                            try
                            {
                                name_FieldType_Lower = fields_Cur[nColumnIx].ToLower();
                            }
                            catch (IndexOutOfRangeException e)
                            {
                                err_Excp = e;
                                goto gt_Error_FdIndexOutOfRangeException;
                            }

                            // 列の型名を読み込みました。

                            // テーブルのフィールドを追加します。型の既定値は文字列型とします。
                            // TODO int型とboolean型にも対応したい。
                            if (FielddefinitionImpl.S_STRING.Equals(name_FieldType_Lower))
                            {
                                recordFielddefinition.ValueAt(nColumnIx).Type_Field = EnumTypeFielddefinition.String;
                            }
                            else if (FielddefinitionImpl.S_INT.Equals(name_FieldType_Lower))
                            {
                                recordFielddefinition.ValueAt(nColumnIx).Type_Field = EnumTypeFielddefinition.Int;
                            }
                            else if (FielddefinitionImpl.S_BOOL.Equals(name_FieldType_Lower))
                            {
                                // 2009-11-11修正:SRS仕様では「bool」が正しい。「boolean」は間違い。
                                recordFielddefinition.ValueAt(nColumnIx).Type_Field = EnumTypeFielddefinition.Bool;
                            }
                            else
                            {
                                // 型が未定義の列は、文字列型として読み取ります。

                                // TODO:警告を出すか?

                                recordFielddefinition.ValueAt(nColumnIx).Type_Field = EnumTypeFielddefinition.String;
                            }
                        }

                        // 1行目は、テーブルのデータとしては持ちません。
                    }
                    else if (2 == nRowIndex)
                    {
                        // 2行目

                        // フィールドのコメントの行。
                        // TODO: フィールドのコメントの行は省略されることがある。

                        for (int column = 0; column < nDataColumnsCount; column++)
                        {
                            if (fields_Cur.Length<=column)
                            {
                                error_Fields_Cur = fields_Cur;
                                //error_Count_Columns = fields_Cur.Length;
                                error_Count_Index = column;
                                goto gt_Error_CommentFieldCount;
                            }

                            string comment_Field = fields_Cur[column];//todo:bug:境界線エラーをキャッチしてない。

                            recordFielddefinition.ValueAt(column).Comment = comment_Field;
                        }

                        // 2行目は、テーブルのデータとしては持ちません。
                    }
                    else
                    {
                        // 3行目以降のループ。
                        List<string> sList_Column = new List<string>();

                        // データ・テーブル部で、0列目に「EOF」と入っていれば終了。大文字・小文字は区別せず。

                        if (fields_Cur.Length < 1)
                        {
                            // 空行は無視。
                            goto end_recordAdd;
                        }
                        //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":" + this.GetType().Name + "#UnescapeToList: sFields[0]=[" + sFields[0] + "] sLine=[" + sLine + "]");

                        string sCellValueTrimUpper = fields_Cur[0].Trim().ToUpper();
                        if (ToCsv_Table_Humaninput_RowColRegularImpl.S_EOF == sCellValueTrimUpper)
                        {
                            goto reading_end;
                        }

                        int nColumnCount;
                        if (fields_Cur.Length < nDataColumnsCount)
                        {
                            // 「実際にデータとして存在する列数」
                            nColumnCount = fields_Cur.Length;
                        }
                        else
                        {
                            // 「データとして存在する筈の列数」(これ以降の列は無視)
                            nColumnCount = nDataColumnsCount;
                        }

                        for (int nColumnIx = 0; nColumnIx < nColumnCount; nColumnIx++)
                        {
                            string sValue;

                            sValue = fields_Cur[nColumnIx];

                            if (recordFielddefinition.Count <= nColumnIx)
                            {
                                // 0行目で数えた列数より多い場合。

                                // テーブルのフィールドを追加します。型は文字列型とします。名前は空文字列です。
                                recordFielddefinition.Add(new FielddefinitionImpl("", EnumTypeFielddefinition.String));
                            }

                            sList_Column.Add(sValue);
                        }

                        dataTableRows.Add(sList_Column);
                    end_recordAdd:
                        ;
                    }
                field_name_reading_end:

                    //essageBox.Show("ttbwIndex=[" + ttbwIndex + "]行目ループ終わり", "TableCsvLibデバッグ");
                    nRowIndex++;
                }
            }
            reading_end:

            // ストリームを閉じます。
            reader.Close();

            //essageBox.Show("CSV読取終わり1 rows.Count=[" + rows.Count + "]", "TableCsvLibデバッグ");

            // テーブルのフィールド定義。
            xenonTable.CreateTable(recordFielddefinition,log_Reports);
            if(log_Reports.Successful)
            {
                // データ本体のセット。
                xenonTable.AddRecordList(dataTableRows, recordFielddefinition, log_Reports);
            }

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

                Log_TextIndented s = new Log_TextIndentedImpl();

                s.Append("「フィールド・コメント」行のフィールド数が合いませんでした。");
                s.Append(Environment.NewLine);
                s.Append(Environment.NewLine);

                s.Append("index=[");
                s.Append(error_Count_Index);
                s.Append("]");
                s.Append(Environment.NewLine);

                s.Append("列数=[");
                s.Append(error_Fields_Cur.Length);
                s.Append("]");
                s.Append(Environment.NewLine);
                s.Append(Environment.NewLine);

                s.Append("──────────fields ここから");
                s.Append(Environment.NewLine);
                foreach (string field in error_Fields_Cur)
                {
                    s.Append("field=[");
                    s.Append(field);
                    s.Append("]");
                    s.Append(Environment.NewLine);
                }
                s.Append("──────────fields ここまで");
                s.Append(Environment.NewLine);

                //
                // ヒント
                s.Append(Log_RecordReportsImpl.ToText_Configuration(xenonTable));

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_FdIndexOutOfRangeException:
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー132!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Newline();

                s.Append("フィールド定義の数が合いませんでした。");
                s.Append(Environment.NewLine);
                s.Append(Environment.NewLine);

                string sFpatha = forTable_request.Expression_Filepath.Execute4_OnExpressionString(
                    EnumHitcount.Unconstraint, log_Reports);
                s.Append("ファイルパス=[");
                s.Append(sFpatha);
                s.Append("]");
                s.Append(Environment.NewLine);
                s.Append(Environment.NewLine);

                //
                // ヒント
                s.Append(err_Excp.Message);

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
            gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return xenonTable;
        }
Example #7
0
        //────────────────────────────────────────
        /// <summary>
        /// 
        /// </summary>
        /// <param name="out_sFieldListList"></param>
        /// <param name="out_O_NewFldDefList"></param>
        /// <param name="src_sNewFieldNameList"></param>
        /// <param name="e_Where"></param>
        /// <param name="tableH_Source"></param>
        /// <param name="log_Reports"></param>
        public static void SelectFieldListList(
            out List<List<string>> listList_SField_Out,
            out RecordFielddefinition out_RecordFielddefinition_New,
            EnumLogic enumWhereLogic,
            List<string> list_SName_NewField_Src,
            List<Recordcondition> list_Reccond,
            Table_Humaninput tableH_Source,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();
            log_Method.BeginMethod(Info_Table.Name_Library, "Util_Table", "SelectFieldListList",log_Reports);

            //

            RecordFielddefinition recordFielddefinition_New = new RecordFielddefinitionImpl();
            List<int> list_indexField = new List<int>();

            //
            // 新しい、列定義リストを作成します。
            //
            {
                // 最初の列は「NO」とします。
                list_SName_NewField_Src.Insert(0, Utility_Table.S_FIELD_NO);

                //fieldIndex
                int nFIx = 0;
                tableH_Source.RecordFielddefinition.ForEach(delegate(Fielddefinition fielddefinition, ref bool isBreak, Log_Reports log_Reports2)
                {
                    if (list_SName_NewField_Src.Contains(fielddefinition.Name_Humaninput))
                    {
                        // 選出されたフィールドだけでリストを作ります。
                        recordFielddefinition_New.Add(fielddefinition);
                        list_indexField.Add(nFIx);
                    }

                    nFIx++;
                }, log_Reports);
            }

            //
            // テーブルに列定義を設定した後で。
            // 移し替えたいデータ値の配列を作ります。
            listList_SField_Out = new List<List<string>>();
            //
            {
                int nEndover = list_indexField.Count;
                foreach (DataRow srcRow in tableH_Source.DataTable.Rows)
                {
                    List<string> sList_NewField = new List<string>();

                    //
                    // 「E■@where」属性を解析します。
                    //
                    // 該当しないレコードは除去していきます。
                    //
                    // 「E■@where」に logic属性が無い場合は logic="and" とします。
                    if (EnumLogic.None == enumWhereLogic)
                    {
                        enumWhereLogic = EnumLogic.And;
                    }
                    bool bHit = Utility_Table.ApplyReccond(srcRow, tableH_Source, enumWhereLogic, list_Reccond, 0, log_Reports);
                    //ystem.Console.WriteLine(InfxenonTable.LibraryName + ":Util_Table.SelectFieldListList: (結果) [" + bHit + "]");

                    if (bHit)
                    {
                        for (int nA = 0; nA < nEndover; nA++)
                        {
                            // TODO:指定のフィールド・インデックスだけをピックアップしたい。
                            int nB = list_indexField[nA];
                            Value_Humaninput o_Value = (Value_Humaninput)srcRow[nB];

                            sList_NewField.Add(o_Value.Text);
                        }

                        listList_SField_Out.Add(sList_NewField);
                    }
                    //hit

                }

            }

            goto gt_EndMethod;

            //
            //
            //
            //
            gt_EndMethod:
            out_RecordFielddefinition_New = recordFielddefinition_New;
            log_Method.EndMethod(log_Reports);
        }
Example #8
0
        //────────────────────────────────────────
        /// <summary>
        /// フィールドの定義を取得します。
        /// 
        /// フィールド名の英字大文字、小文字は無視します。
        /// </summary>
        /// <param name="expectedFieldName"></param>
        /// <param name="isRequired">該当なしの時に例外を投げるなら真。</param>
        /// <returns>該当なし、エラーの場合偽。</returns>
        public bool TryGetFieldDefinitionByName(
            out RecordFielddefinition out_RecordFielddefinition3,
            List<string> list_NameField_Expected,
            bool isRequired,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl(0);
            log_Method.BeginMethod(Info_Table.Name_Library, this, "TryGetFieldDefinitionByName",log_Reports);

            bool isResult = true;
            RecordFielddefinition recordFielddefinition1 = new RecordFielddefinitionImpl();

            if (list_NameField_Expected.Count < 1)
            {
                // エラー。
                goto gt_Error_ParamNothingField;
            }

            string error_NameField_Expected;
            int count = 0;
            foreach (string nameField_Expected in list_NameField_Expected)
            {
                //
                // TODO:現状、「ID,NAME」などのカンマ区切りに対応できていない?
                //

                string name_Field_ExpectedUpper = nameField_Expected.ToUpper();

                bool isHit2 = false;
                this.RecordFielddefinition.ForEach(delegate(Fielddefinition fielddefinition,ref bool isBreak2, Log_Reports log_Reports2)
                {
                    if (fielddefinition.Name_Trimupper == name_Field_ExpectedUpper)
                    {
                        //ヒット
                        isHit2 = true;
                        recordFielddefinition1.Add(fielddefinition);
                        count++;
                        isBreak2 = true;
                        goto gt_NextField;
                    }

                gt_NextField:
                    ;
                }, log_Reports);

                if (!isHit2)
                {
                    // 一致するものが無かった場合。
                    recordFielddefinition1.Add(new FielddefinitionImpl("<null>", EnumTypeFielddefinition.String));//桁合わせ。
                    isResult = false;

                    if (isRequired)
                    {
                        // エラー。
                        error_NameField_Expected = nameField_Expected;
                        goto gt_Error_NothingField1;
                    }

                    // 正常
                    goto gt_EndMethod;
                }
            }
            // 正常

            if (count < 1)
            {
                isResult = false;

                if (isRequired)
                {
                    // エラー。
                    StringBuilder s = new StringBuilder();
                    foreach (string sFld in list_NameField_Expected)
                    {
                        s.Append("[");
                        s.Append(sFld);
                        s.Append("]");
                    }
                    error_NameField_Expected = s.ToString();
                    goto gt_Error_NothingField2;
                }

            }

            // 正常
            goto gt_EndMethod;
            //
            //
            #region 異常系
            //────────────────────────────────────────
            gt_Error_ParamNothingField:
            {
                isResult = false;

                if (log_Reports.CanCreateReport)
                {
                    Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                    r.SetTitle("▲エラー121!", log_Method);

                    Log_TextIndented s = new Log_TextIndentedImpl();
                    s.Append("[");
                    s.Append(this.Name);
                    s.Append("]テーブルの列定義を調べようとしましたが、列名が指定されていません。sExpectedFieldNameList.Count=[");
                    s.Append(list_NameField_Expected.Count);
                    s.Append("]");

                    // ヒント

                    r.Message = s.ToString();
                    log_Reports.EndCreateReport();
                }
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_NothingField1:
            isResult = false;
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー131!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Append("[");
                s.Append(this.Name);
                s.Append("]テーブルに、[");

                s.Append(error_NameField_Expected);
                s.Append("]フィールドは存在しませんでした。");
                s.Newline();
                s.Newline();

                // ヒント
                s.Append("──────────定義されている列のリスト");
                s.Newline();
                s.Append(recordFielddefinition1.ToString_DebugDump());
                s.Newline();
                s.Append("──────────");
                s.Newline();

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            gt_Error_NothingField2:
            isResult = false;
            if (log_Reports.CanCreateReport)
            {
                Log_RecordReports r = log_Reports.BeginCreateReport(EnumReport.Error);
                r.SetTitle("▲エラー132!", log_Method);

                Log_TextIndented s = new Log_TextIndentedImpl();
                s.Append("[");
                s.Append(this.Name);
                s.Append("]テーブルに、[");

                s.Append(error_NameField_Expected);
                s.Append("]フィールドは存在しませんでした。");
                s.Newline();
                s.Newline();

                // ヒント
                s.Append("──────────定義されている列のリスト");
                s.Newline();
                s.Append(recordFielddefinition1.ToString_DebugDump());
                s.Newline();
                s.Append("──────────");
                s.Newline();

                r.Message = s.ToString();
                log_Reports.EndCreateReport();
            }
            goto gt_EndMethod;
            //────────────────────────────────────────
            #endregion
            //
            //
            gt_EndMethod:
            out_RecordFielddefinition3 = recordFielddefinition1;
            log_Method.EndMethod(log_Reports);
            return isResult;
        }
        //────────────────────────────────────────
        /// <summary>
        /// TODO:「,」「"」に対応したい。
        /// 
        /// 
        /// 縦、横がひっくり返っていて、
        /// 型定義レコードがないCSVテーブルの読取。
        /// </summary>
        /// <param name="csvText"></param>
        /// <returns>列名情報も含むテーブル。</returns>
        public Table_Humaninput Read(
            string string_Csv,
            Request_ReadsTable forTable_Request,
            Format_Table_Humaninput forTable_Format,
            Log_Reports log_Reports
            )
        {
            Log_Method log_Method = new Log_MethodImpl();
            log_Method.BeginMethod(Info_Table.Name_Library, this, "Read",log_Reports);

            //
            //
            //
            //
            CsvLineParserImpl csvParser = new CsvLineParserImpl();

            Table_Humaninput xenonTable = new Table_HumaninputImpl(
                forTable_Request.Name_PutToTable, forTable_Request.Expression_Filepath, forTable_Request.Expression_Filepath.Cur_Configuration);
            xenonTable.Tableunit = forTable_Request.Tableunit;
            xenonTable.Typedata = forTable_Request.Typedata;
            xenonTable.IsDatebackupActivated = forTable_Request.IsDatebackupActivated;
            xenonTable.Format_Table_Humaninput = forTable_Format;

            //
            // 一旦、テーブルを全て読み込みます。
            //
            List<List<string>> lines = new List<List<string>>();

            {
                // CSVテキストを読み込み、型とデータのバッファーを作成します。
                System.IO.StringReader reader = new System.IO.StringReader(string_Csv);

                string[] sFields;
                while (-1 < reader.Peek())
                {
                    string sLine = reader.ReadLine();
                    List<string> tokens = new List<string>();

                    sFields = csvParser.UnescapeLineToFieldList(sLine, this.charSeparator).ToArray();

                    int nColumnIndex = 0;
                    foreach (string sToken in sFields)
                    {
                        if (nColumnIndex == 0 && ToCsv_Table_Humaninput_RowColRegularImpl.S_END == sToken.Trim().ToUpper())
                        {
                            // 1列目にENDがある場合、その手前までの列が有効データです。
                            // END以降の行は無視します。
                            goto row_end;
                        }

                        tokens.Add(sToken);

                        nColumnIndex++;
                    }
                    lines.Add(tokens);
                }
            row_end:

                // ストリームを閉じます。
                reader.Close();
            }

            //
            // 型定義部
            //
            // (※NO,ID,EXPL,NAME など、フィールドの定義を持つテーブル)
            //
            RecordFielddefinition recordFielddefinition = new RecordFielddefinitionImpl();

            //
            // データ・テーブル部
            //
            List<List<string>> rows = new List<List<string>>();

            //
            // まず、0列目、1列目のデータを読み取ります。
            //
            int nRowIndex=0;
            foreach (List<string> tokens in lines)
            {
                Fielddefinition fieldDefinition = null;

                int nColumnIndex = 0;
                foreach(string sToken in tokens)
                {

                    if(0==nColumnIndex)
                    {
                        //
                        // 0列目は、フィールド名です。
                        //
                        string sFieldName = sToken;//.Trim().ToUpper();

                        // テーブルのフィールドを追加します。フィールドの型は、intに固定です。
                        fieldDefinition = new FielddefinitionImpl(sFieldName, EnumTypeFielddefinition.Int);
                        recordFielddefinition.Add(fieldDefinition);
                    }
                    else if(1==nColumnIndex)
                    {
                        //
                        // 1列目は、フィールドのコメントとします。
                        //
                        nColumnIndex = 1;
                        {
                            fieldDefinition.Comment = sToken;
                        }

                    }
                    else
                    {
                        //
                        // 2列目から右側は、データ・テーブル部。
                        //

                        if(0==nRowIndex)
                        {
                            //
                            // 先頭行
                            //

                            //
                            // 「EOF」というトークンが出てくるまで。
                            //
                            if(ToCsv_Table_Humaninput_RowColRegularImpl.S_EOF==sToken.Trim().ToUpper())
                            {
                                goto column_end;
                            }

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

                            // 1番目のフィールド_データを追加。
                            record.Add( sToken);

                            rows.Add(record);
                        }
                        else
                        {
                            //
                            // 2番目以降のフィールド_データを追加。
                            //

                            //
                            // 先頭の2つのレコード分、切り詰めます。
                            //
                            int nDataIndex = nColumnIndex - 2;
                            if (nDataIndex < rows.Count)
                            {
                                List<string> record = rows[nDataIndex];

                                record.Add(sToken);
                            }
                            else
                            {
                                // 無視
                            }
                        }
                    }

                    nColumnIndex ++;
                }//c
            column_end:

                nRowIndex++;
            }

            //essageBox.Show("CSV読取終わり1 rows.Count=[" + rows.Count + "]", "TableCsvLibデバッグ");

            // テーブル作成。テーブルのフィールド型定義と、データ本体をセットします。
            xenonTable.CreateTable(recordFielddefinition,log_Reports);
            if( log_Reports.Successful)
            {
                xenonTable.AddRecordList(rows, recordFielddefinition, log_Reports);
                //essageBox.Show("CSV読取後のテーブル作成終わり", "TableCsvLibデバッグ");
            }

            goto gt_EndMethod;
            //
            //
            gt_EndMethod:
            log_Method.EndMethod(log_Reports);
            return xenonTable;
        }