-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathStatisticWindow.xaml.cs
145 lines (139 loc) · 5.28 KB
/
StatisticWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
using Livet;
using Livet.EventListeners;
using Livet.Messaging;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace HoppoPlugin
{
/// <summary>
/// Interaction logic for StatisticWindow.xaml
/// </summary>
public partial class StatisticWindow
{
public StatisticWindow()
{
InitializeComponent();
}
private DataTable loadAndDisplayCsvFile(string filePath)
{
string content = File.ReadAllText(filePath);
List<List<string>> lists = new List<List<string>>();
List<string> lastList = new List<string>();
lists.Add(lastList); //1行目を追加
lastList.Add("");
Regex regex = new Regex(",|\\r?\\n|[^,\"\\r\\n][^,\\r\\n]*|\"(?:[^\"]|\"\")*\"");
MatchCollection mc = regex.Matches(Regex.Replace(content, "\\r?\\n$", ""));
foreach (Match m in mc)
{
switch (m.Value)
{
case ",":
lastList.Add("");
break;
case "\n":
case "\r\n":
//改行コードの場合は行を追加する
lastList = new List<string>();
lists.Add(lastList);
lastList.Add("");
break;
default:
if (m.Value.StartsWith("\""))
{
//ダブルクォートで囲われている場合は最初と最後のダブルクォートを外し、
//文字列中のダブルクォートのエスケープをアンエスケープする
lastList[lastList.Count - 1] =
m.Value.Substring(1, m.Value.Length - 2).Replace("\"\"", "\"");
}
else
{
lastList[lastList.Count - 1] = m.Value;
}
break;
}
}
// データテーブルにコピーする
DataTable dt = new DataTable();
for (int i = 0; i < lists[0].Count; i++)
{
dt.Columns.Add(lists[0][i]);
}
foreach (List<string> list in lists)
{
DataRow dr = dt.NewRow();
for (int i = 0; i < list.Count; i++)
{
dr[i] = list[i];
}
dt.Rows.Add(dr);
}
return dt;
}
private void TabControl_SelectionChanged(object sender, RoutedEventArgs e)
{
try
{
if (MainTabControl.SelectedIndex == 0)
{
BuildDataGrid.ItemsSource = null;
BuildDataGrid.ItemsSource = loadAndDisplayCsvFile(UniversalConstants.CurrentDirectory + "ShipBuildLog.csv").DefaultView;
}
if (MainTabControl.SelectedIndex == 1)
{
DevelopDataGrid.ItemsSource = null;
DevelopDataGrid.ItemsSource = loadAndDisplayCsvFile(UniversalConstants.CurrentDirectory + "ItemBuildLog.csv").DefaultView;
}
if (MainTabControl.SelectedIndex == 2)
{
DropDataGrid.ItemsSource = null;
DropDataGrid.ItemsSource = loadAndDisplayCsvFile(UniversalConstants.CurrentDirectory + "DropLog.csv").DefaultView;
}
if (MainTabControl.SelectedIndex == 3)
{
MessageBoxResult mbr = MessageBox.Show("这是一个垃圾功能,难看而且有大量bug,乃确定还要继续用嘛?", "WARNING", MessageBoxButton.YesNo, MessageBoxImage.Question);
if (mbr == MessageBoxResult.No)
return;
ChartWindow c = new ChartWindow();
c.Show();
}
}
catch (FileNotFoundException)
{
MessageBox.Show("没有对应的记录!");
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void Window_CR(object sender, EventArgs e)
{
MainTabControl.AddHandler(TabControl.SelectionChangedEvent, new RoutedEventHandler(TabControl_SelectionChanged));
try
{
BuildDataGrid.ItemsSource = null;
BuildDataGrid.ItemsSource = loadAndDisplayCsvFile(UniversalConstants.CurrentDirectory + "ShipBuildLog.csv").DefaultView;
}
catch (FileNotFoundException)
{
MessageBox.Show("没有对应的记录!");
}
catch { }
}
}
}