Changeset 14 for Common/Table.cs
- Timestamp:
- Aug 2, 2022, 11:46:25 AM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Common/Table.cs
r13 r14 1 1 using System; 2 2 using System.Collections.Generic; 3 using System.Diagnostics.Eventing.Reader;4 3 using System.Linq; 4 using System.Windows.Forms; 5 5 using System.Text; 6 using System.Threading.Tasks;7 6 8 7 namespace Common 9 8 { 10 public class Row11 {12 public List<string> cells = new List<string>();13 14 public void AddCell(string text)15 {16 cells.Add(text);17 }18 }19 20 9 public enum OutputFormat 21 10 { 22 11 Excel, 23 12 Plain, 24 Csv 13 Csv, 14 Html, 15 ListView 25 16 }; 17 18 public class Row 19 { 20 public List<string> Cells = new List<string>(); 21 22 public void AddCell(string text) 23 { 24 Cells.Add(text); 25 } 26 } 26 27 27 28 public class Table 28 29 { 29 public List<Row> rows = new List<Row>();30 public List<Row> Rows = new List<Row>(); 30 31 31 32 public void Clear() 32 33 { 33 rows.Clear();34 Rows.Clear(); 34 35 } 35 36 … … 37 38 { 38 39 Row row = new Row(); 39 rows.Add(row);40 Rows.Add(row); 40 41 return row; 41 42 } … … 44 45 { 45 46 StringBuilder output = new StringBuilder(); 46 foreach (var row in rows)47 foreach (var row in Rows) 47 48 { 48 output.AppendLine(string.Join("\t", row. cells));49 output.AppendLine(string.Join("\t", row.Cells)); 49 50 } 50 51 return output.ToString(); … … 54 55 { 55 56 StringBuilder output = new StringBuilder(); 56 foreach (var row in rows)57 foreach (var row in Rows) 57 58 { 58 output.AppendLine(string.Join(Environment.NewLine, row. cells));59 output.AppendLine(string.Join(Environment.NewLine, row.Cells)); 59 60 output.AppendLine(); 60 61 output.AppendLine("==========================="); … … 67 68 { 68 69 StringBuilder output = new StringBuilder(); 69 foreach (var row in rows)70 foreach (var row in Rows) 70 71 { 71 output.AppendLine(string.Join(",", row. cells.Select(x => "\"" + x + "\"")));72 output.AppendLine(string.Join(",", row.Cells.Select(x => "\"" + x + "\""))); 72 73 } 73 74 return output.ToString(); 75 } 76 77 public string GetOutputHtml() 78 { 79 StringBuilder output = new StringBuilder(); 80 output.AppendLine("<table border=\"1\">"); 81 foreach (var row in Rows) 82 { 83 output.AppendLine("<tr><td>" + string.Join("</td><td>", row.Cells.Select(x => x.Replace(Environment.NewLine, "<br/>"))) + "</td></tr>"); 84 } 85 output.AppendLine("</table>"); 86 return output.ToString(); 87 } 88 89 public void GetOutputListView(ListView listView) 90 { 91 foreach (var row in Rows) 92 { 93 if (listView.Columns.Count == 0 && row.Cells.Count > 0) 94 { 95 while (listView.Columns.Count < row.Cells.Count) 96 listView.Columns.Add(row.Cells[listView.Columns.Count]); 97 } 98 else 99 { 100 while (listView.Columns.Count < row.Cells.Count) 101 listView.Columns.Add(""); 102 ListViewItem item = new ListViewItem(); 103 int i = 0; 104 foreach (var cell in row.Cells) 105 { 106 if (i == 0) item.Text = cell; 107 else item.SubItems.Add(cell); 108 i++; 109 } 110 listView.Items.Add(item); 111 } 112 } 113 114 foreach (ColumnHeader column in listView.Columns) 115 { 116 column.Width = listView.Width / listView.Columns.Count; 117 } 74 118 } 75 119 … … 79 123 else if (outputFormat == OutputFormat.Plain) return GetOutputPlain(); 80 124 else if (outputFormat == OutputFormat.Csv) return GetOutputCsv(); 125 else if (outputFormat == OutputFormat.Html) return GetOutputHtml(); 81 126 else return ""; 82 127 }
Note:
See TracChangeset
for help on using the changeset viewer.