質問編集履歴
3
表題変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Dictionary → List →
|
1
|
+
Dictionary → List → DataGridViewで表示させたい。
|
body
CHANGED
File without changes
|
2
表題変更
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
Dictionary
|
1
|
+
Dictionary → List → DataGridで表示させたい。
|
body
CHANGED
File without changes
|
1
書式変更
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,27 +1,27 @@
|
|
1
|
+
### **前提・実現したいこと**
|
1
|
-
|
2
|
+
C#を勉強してから間もない初心者です。
|
3
|
+
CSV ファイル → A Fast CSV Reader → Dictionary → 数量、金額、利益 を 集計 → List → DataGridView 表示
|
2
|
-
|
4
|
+
学習のためDictionary → Listにしています。
|
3
|
-
gridviewに表示させたいです。
|
4
|
-
どのようにかけばいいでしょう。
|
5
|
-
C#の勉強を始めてまもないので
|
6
|
-
不明点が多いです。
|
7
|
-
|
5
|
+
DataTableやDataSetに疎いため困っています。
|
8
6
|
|
9
|
-
|
7
|
+
分類や対象商品が増えると必要に応じ
|
8
|
+
DataGridViewに行、列が増える。
|
10
9
|
|
10
|
+
**表示イメージ**
|
11
|
-
|
11
|
+

|
12
12
|
|
13
|
-
数量 金額 利益 数量 金額 利益 数量 金額 利益
|
14
|
-
分類1 | | | |
|
15
|
-
分類2 | | | |
|
16
|
-
分類3 | | | |
|
17
13
|
|
14
|
+
```C#
|
15
|
+
using System;
|
16
|
+
using System.Collections.Generic;
|
17
|
+
using System.Data;
|
18
|
+
using System.IO;
|
19
|
+
using System.Linq;
|
20
|
+
using System.Text;
|
21
|
+
using System.Threading.Tasks;
|
22
|
+
using System.Windows.Forms;
|
18
23
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
namespace
|
24
|
+
namespace Gridsyuukei
|
25
25
|
{
|
26
26
|
static class Program
|
27
27
|
{
|
@@ -29,24 +29,26 @@
|
|
29
29
|
Add(LumenWorks.Framework.IO.Csv.CsvReader rcsv,
|
30
30
|
Dictionary<string, Dictionary<string, Dictionary<string, int>>> dic)
|
31
31
|
{
|
32
|
-
Dictionary<string, int>
|
32
|
+
Dictionary<string, int> work = new Dictionary<string, int>();
|
33
|
-
|
33
|
+
work.Add("数量", int.Parse(rcsv[3]));
|
34
|
-
|
34
|
+
work.Add("金額", int.Parse(rcsv[4]));
|
35
|
-
|
35
|
+
work.Add("利益", int.Parse(rcsv[5]));
|
36
|
-
dic[rcsv[0]].Add(rcsv[2],
|
36
|
+
dic[rcsv[0]].Add(rcsv[2], work);
|
37
37
|
return dic;
|
38
38
|
}
|
39
39
|
|
40
|
+
/// <summary>
|
40
|
-
|
41
|
+
/// アプリケーションのメイン エントリ ポイントです。
|
42
|
+
/// </summary>
|
41
43
|
[STAThread]
|
42
44
|
static void Main()
|
43
45
|
{
|
44
46
|
Application.EnableVisualStyles();
|
45
47
|
Application.SetCompatibleTextRenderingDefault(false);
|
46
|
-
Application.Run(new ShopManager());
|
48
|
+
Application.Run(new ShopManager());
|
47
49
|
|
48
50
|
//csvファイルのパス
|
49
|
-
string csvpath = "csv
|
51
|
+
string csvpath = "C: \Users\nbs\Desktop\クロス集計2号\import.csv";
|
50
52
|
|
51
53
|
|
52
54
|
//csvファイル読み込み
|
@@ -54,7 +56,11 @@
|
|
54
56
|
new LumenWorks.Framework.IO.Csv.CsvReader(new StreamReader(csvpath, Encoding.GetEncoding("shift_jis")), true))
|
55
57
|
|
56
58
|
{
|
59
|
+
//格納用Dictionary
|
60
|
+
Dictionary<string, Dictionary<string, Dictionary<string, int>>> dic =
|
61
|
+
new Dictionary<string, Dictionary<string, Dictionary<string, int>>>();
|
57
62
|
|
63
|
+
|
58
64
|
//集計処理
|
59
65
|
//値があれば計算する
|
60
66
|
//なければ参照しくる
|
@@ -70,7 +76,6 @@
|
|
70
76
|
}
|
71
77
|
else
|
72
78
|
{
|
73
|
-
|
74
79
|
dic = Add(rcsv, dic);
|
75
80
|
}
|
76
81
|
|
@@ -79,25 +84,33 @@
|
|
79
84
|
{
|
80
85
|
dic[rcsv[0]] = new Dictionary<string, Dictionary<string, int>>();
|
81
86
|
dic = Add(rcsv, dic);
|
82
|
-
|
83
87
|
}
|
84
88
|
|
85
|
-
}
|
89
|
+
}
|
90
|
+
|
86
91
|
//キーをListに変換する
|
92
|
+
List<string> keysList = new List<string>(dic.Keys);//ウィンドウ等
|
87
93
|
|
88
|
-
List<string> keysList = new List<string>(dic.Keys);//
|
89
|
-
|
90
|
-
|
94
|
+
foreach (string key in keysList)
|
91
|
-
{
|
92
|
-
|
93
|
-
//ここがどうしていいかわからない
|
94
|
-
|
95
|
-
|
96
95
|
{
|
97
|
-
|
96
|
+
//ここから処理をどうしたらいいかわからない
|
98
|
-
|
97
|
+
}
|
99
|
-
|
98
|
+
}
|
100
99
|
}
|
101
100
|
}
|
102
101
|
}
|
103
|
-
}
|
102
|
+
}
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
|
114
|
+
### 補足情報(FW/ツールのバージョンなど)
|
115
|
+
|
116
|
+
Windows, VisualStudio2017.15.7.5, Windows Forms
|