質問編集履歴

3

表題変更

2018/08/06 08:22

投稿

ppsspp
ppsspp

スコア6

test CHANGED
@@ -1 +1 @@
1
- Dictionary → List → DataGridで表示させたい。
1
+ Dictionary → List → DataGridViewで表示させたい。
test CHANGED
File without changes

2

表題変更

2018/08/06 08:22

投稿

ppsspp
ppsspp

スコア6

test CHANGED
@@ -1 +1 @@
1
- DictionaryをdataGrid表示させたい。
1
+ Dictionary → List → DataGrid表示させたい。
test CHANGED
File without changes

1

書式変更

2018/08/06 04:33

投稿

ppsspp
ppsspp

スコア6

test CHANGED
File without changes
test CHANGED
@@ -1,50 +1,50 @@
1
+ ### **前提・実現したいこと**
2
+
1
- データ集計するプログラムを考えていす。
3
+ C#勉強しから間もな初心者です。
4
+
2
-
5
+ CSV ファイル → A Fast CSV Reader → Dictionary → 数量、金額、利益 を 集計 → List → DataGridView 表示
6
+
3
- dictionaryの内容をListにして
7
+ 学習のためDictionary → Listにしています。
8
+
4
-
9
+ DataTableやDataSetに疎いため困っています。
10
+
11
+
12
+
13
+ 分類や対象商品が増えると必要に応じ
14
+
5
- gridviewに表示させたいです
15
+ DataGridViewに行、列が増える
6
-
7
- どのようにかけばいいでしょう。
16
+
8
-
9
- C#の勉強を始めてまもないので
17
+
10
-
11
- 不明点が多いです。
18
+
12
-
13
- csvの中身が「分類,空欄,対象商品,数量,金額,利益」で
14
-
15
-
16
-
17
-   表示時のイメージ
19
+ **表示イメージ**
20
+
18
-
21
+ ![イメージ説明](e39d439cef698d85796f9feb2f0dd17c.png)
22
+
23
+
24
+
25
+
26
+
19
-
27
+ ```C#
28
+
20
-
29
+ using System;
30
+
31
+ using System.Collections.Generic;
32
+
33
+ using System.Data;
34
+
35
+ using System.IO;
36
+
37
+ using System.Linq;
38
+
39
+ using System.Text;
40
+
41
+ using System.Threading.Tasks;
42
+
21
-       対象商品A      対象商品B      対象商品C
43
+ using System.Windows.Forms;
22
-
23
-
24
-
25
-     数量 金額 利益  数量 金額 利益  数量 金額 利益
44
+
26
-
27
- 分類1 |  |  |  |   
45
+
28
-
29
- 分類2 |  |  |  | 
46
+
30
-
31
- 分類3 |  |  |  | 
32
-
33
-
34
-
35
-
36
-
37
-
38
-
39
-
40
-
41
-
42
-
43
-
44
-
45
-
46
-
47
- namespace mast
47
+ namespace Gridsyuukei
48
48
 
49
49
  {
50
50
 
@@ -60,15 +60,15 @@
60
60
 
61
61
  {
62
62
 
63
- Dictionary<string, int> wor = new Dictionary<string, int>();
63
+ Dictionary<string, int> work = new Dictionary<string, int>();
64
-
64
+
65
- wor.Add("数量", int.Parse(rcsv[3]));
65
+ work.Add("数量", int.Parse(rcsv[3]));
66
-
66
+
67
- wor.Add("金額", int.Parse(rcsv[4]));
67
+ work.Add("金額", int.Parse(rcsv[4]));
68
-
68
+
69
- wor.Add("利益", int.Parse(rcsv[5]));
69
+ work.Add("利益", int.Parse(rcsv[5]));
70
-
70
+
71
- dic[rcsv[0]].Add(rcsv[2], wor);
71
+ dic[rcsv[0]].Add(rcsv[2], work);
72
72
 
73
73
  return dic;
74
74
 
@@ -76,7 +76,11 @@
76
76
 
77
77
 
78
78
 
79
+ /// <summary>
80
+
79
- 番号
81
+ /// アプケーションのメイン エンリ ポイントです。
82
+
83
+ /// </summary>
80
84
 
81
85
  [STAThread]
82
86
 
@@ -88,13 +92,13 @@
88
92
 
89
93
  Application.SetCompatibleTextRenderingDefault(false);
90
94
 
91
- Application.Run(new ShopManager());
95
+ Application.Run(new ShopManager());
92
96
 
93
97
 
94
98
 
95
99
  //csvファイルのパス
96
100
 
97
- string csvpath = "csvファイル";
101
+ string csvpath = "C: \Users\nbs\Desktop\クロス集計2号\import.csv";
98
102
 
99
103
 
100
104
 
@@ -110,7 +114,15 @@
110
114
 
111
115
  {
112
116
 
113
-
117
+ //格納用Dictionary
118
+
119
+ Dictionary<string, Dictionary<string, Dictionary<string, int>>> dic =
120
+
121
+ new Dictionary<string, Dictionary<string, Dictionary<string, int>>>();
122
+
123
+
124
+
125
+
114
126
 
115
127
  //集計処理
116
128
 
@@ -142,8 +154,6 @@
142
154
 
143
155
  {
144
156
 
145
-
146
-
147
157
  dic = Add(rcsv, dic);
148
158
 
149
159
  }
@@ -160,42 +170,30 @@
160
170
 
161
171
  dic = Add(rcsv, dic);
162
172
 
163
-
164
-
165
173
  }
166
174
 
167
175
 
168
176
 
177
+ }
178
+
179
+
180
+
181
+ //キーをListに変換する
182
+
183
+ List<string> keysList = new List<string>(dic.Keys);//ウィンドウ等
184
+
185
+
186
+
187
+ foreach (string key in keysList)
188
+
189
+ {
190
+
191
+   //ここから処理をどうしたらいいかわからない
192
+
193
+ }
194
+
169
195
  }
170
196
 
171
- //キーをListに変換する
172
-
173
-
174
-
175
- List<string> keysList = new List<string>(dic.Keys);//
176
-
177
-
178
-
179
- foreach (string key in keysList)
180
-
181
- {
182
-
183
-
184
-
185
-                 //ここがどうしていいかわからない
186
-
187
-
188
-
189
-
190
-
191
- {
192
-
193
-
194
-
195
- }
196
-
197
- }
198
-
199
197
  }
200
198
 
201
199
  }
@@ -203,3 +201,31 @@
203
201
  }
204
202
 
205
203
  }
204
+
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+
213
+
214
+
215
+
216
+
217
+
218
+
219
+
220
+
221
+ ```
222
+
223
+
224
+
225
+
226
+
227
+ ### 補足情報(FW/ツールのバージョンなど)
228
+
229
+
230
+
231
+ Windows, VisualStudio2017.15.7.5, Windows Forms