Exemple #1
0
        //タブ描画
        private void TabDraw()
        {
            string tableName = TabItems[TabIndex].Header;

            //Content
            //DataTable初期化
            var table = new DataTable();

            //List<PRAGMAModel>
            var allColumns = DBOperation.AllColumns(SelectedPath, tableName, true);

            //DataTableのColumns
            foreach (var v in allColumns)
            {
                var t = TypeClassification.Judge(v.Type);
                table.Columns.Add(v.Name, t);
            }

            //テーブル全レコード
            var allRecords = DBOperation.AllRecords(SelectedPath, tableName);

            foreach (var v1 in allRecords)
            {
                var row = table.NewRow();
                //DapperRowオブジェクトをキャスト
                var data = (IDictionary <string, object>)v1;
                var n    = 0;
                foreach (var v2 in allColumns)
                {
                    if (data[v2.Name] != null)
                    {
                        //改行削除
                        data[v2.Name] = data[v2.Name].ToString().Replace("\r", "").Replace("\n", "");
                        //長文を短くする
                        int len = data[v2.Name].ToString().Length;
                        if (len > 50)
                        {
                            data[v2.Name] = data[v2.Name].ToString().Substring(0, 50) + "…";
                        }

                        row[n] = data[v2.Name];
                    }
                    else
                    {
                        row[n] = DBNull.Value;
                    }

                    n++;
                }
                table.Rows.Add(row);
            }

            TabItems[TabIndex].Content = table;
        }