//タブ描画 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; }
public SubWindowViewModel(string path, string table, int rowid) { SelectedPath = path; Table = table; RowID = rowid; //List<PRAGMAModel> Columns = DBOperation.AllColumns(SelectedPath, Table, false); //新規追加 if (rowid == 0) { NewBtn = true; EditBtn = false; foreach (var v in Columns) { v.Content = ""; } } //編集削除 else { NewBtn = false; EditBtn = true; dynamic one = DBOperation.OneRecord(SelectedPath, Table, RowID); var data = (IDictionary <string, object>)one; foreach (var v in Columns) { foreach (KeyValuePair <string, object> pair in data) { if (v.Name == pair.Key) { try { v.Content = pair.Value.ToString(); } catch { v.Content = ""; } } } } } }