質問編集履歴

2

2020/10/04 12:44

投稿

AIUABC
AIUABC

スコア0

test CHANGED
File without changes
test CHANGED
@@ -1,365 +1,5 @@
1
- ```C#
1
+ RowCountについて
2
2
 
3
- using System;
3
+ RowCountについて
4
4
 
5
- using System.Collections.Generic;
6
-
7
- using System.ComponentModel;
8
-
9
- using System.Data;
10
-
11
- using System.Drawing;
12
-
13
- using System.Linq;
14
-
15
- using System.Text;
16
-
17
- using System.Threading.Tasks;
18
-
19
- using System.Windows.Forms;
20
-
21
-
22
-
23
- namespace MyHouseKeepingBook
24
-
25
- {
26
-
27
- public partial class Form1 : Form
28
-
29
- {
30
-
31
- public Form1()
32
-
33
- {
34
-
35
- InitializeComponent();
36
-
37
- }
38
-
39
-
40
-
41
- private void buttonAdd_Click(object sender, EventArgs e)
42
-
43
- {
44
-
45
- AddData();
46
-
47
- }
48
-
49
-
50
-
51
- private void 追加AToolStripMenuItem_Click(object sender, EventArgs e)
52
-
53
- {
54
-
55
- AddData();
56
-
57
- }
58
-
59
-
60
-
61
- private void AddData()
62
-
63
- {
64
-
65
- ItemForm frmItem = new ItemForm(CategoryDataSet1);
66
-
67
- DialogResult drRet = frmItem.ShowDialog();
68
-
69
- if (drRet == DialogResult.OK)
70
-
71
- {
72
-
73
- moneyDataSet.moneyDataTable.AddmoneyDataTableRow(
74
-
75
- frmItem.monCalendar.SelectionRange.Start,
76
-
77
- frmItem.cmbCategory.Text,
78
-
79
- frmItem.txtItem.Text,
80
-
81
- int.Parse(frmItem.mtxtMoney.Text),
82
-
83
- frmItem.txtRemarks.Text);
84
-
85
- }
86
-
87
- }
88
-
89
-
90
-
91
- private void Form1_Load(object sender, EventArgs e)
92
-
93
- {
94
-
95
- LoadData();
5
+ RowCountについて
96
-
97
- categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("給料", "入金");
98
-
99
- categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("食費", "出金");
100
-
101
- categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("雑費", "出金");
102
-
103
- categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("住居", "出金");
104
-
105
- }
106
-
107
-
108
-
109
- private void buttonEnd_Click(object sender, EventArgs e)
110
-
111
- {
112
-
113
- this.Close();
114
-
115
- }
116
-
117
-
118
-
119
- private void 終了XToolStripMenuItem_Click(object sender, EventArgs e)
120
-
121
- {
122
-
123
- this.Close();
124
-
125
- }
126
-
127
-
128
-
129
- private void SaveData()
130
-
131
- {
132
-
133
- string path = "MoneyData.csv"; //出力ファイル名
134
-
135
- string strData = ""; //一行分のデータ
136
-
137
- System.IO.StreamWriter sw = new System.IO.StreamWriter(
138
-
139
- path,
140
-
141
- false,
142
-
143
- System.Text.Encoding.Default);
144
-
145
- foreach (MoneyDataSet.moneyDataTableRow drMoney
146
-
147
- in moneyDataSet.moneyDataTable)
148
-
149
- {
150
-
151
- strData = drMoney.日付.ToShortDataString() + ","
152
-
153
- + drMoney.分類 + ","
154
-
155
- + drMoney.品目 + ","
156
-
157
- + drMoney.金額.ToString() + ","
158
-
159
- + drMoney.備考;
160
-
161
- sw.WriteLine(strData);
162
-
163
- }
164
-
165
- sw.Close();
166
-
167
- }
168
-
169
-
170
-
171
- private void 保存SToolStripMenuItem_Click(object sender, EditorArgs e)
172
-
173
- {
174
-
175
- SaveData();
176
-
177
- }
178
-
179
-
180
-
181
- private void form1_FormClosing(object sender, FormClosingEditorArgs e)
182
-
183
- {
184
-
185
- SaveData();
186
-
187
- }
188
-
189
-
190
-
191
- private void LoadData()
192
-
193
- {
194
-
195
- string path = "MoneyData.csv"; //入力ファイル名
196
-
197
- string delimStr = ","; // 区切り文字
198
-
199
- char[] delimiter = delimStr.ToCharArray(); // 区切り文字をまとめる
200
-
201
- string[] strLine; // 分解後の文字の入れ物
202
-
203
- string strLine; // 一行分のデータ
204
-
205
- bool fileExists = System.IO.File.Exists(path);
206
-
207
- if (fileExists)
208
-
209
- {
210
-
211
- System.IO.StreamReader sr = new System.IO.StreamReader(
212
-
213
- path,
214
-
215
- System.Text.Encoding.Default);
216
-
217
- while (sr.Peek() >= 0)
218
-
219
- {
220
-
221
- strLine = sr.ReadLine();
222
-
223
- strData = strLine.Splite(delimiter);
224
-
225
- moneyDataSet.moneyDataTable.AddmoneyDataTableRow(
226
-
227
- DateTime.Parse(strData[0]),
228
-
229
- strData[1],
230
-
231
- strData[2],
232
-
233
- int, Parse(strData[3]),
234
-
235
- strData[4];
236
-
237
- }
238
-
239
- sr.Close;
240
-
241
- }
242
-
243
- }
244
-
245
-
246
-
247
- private void UpdateData()
248
-
249
- {
250
-
251
- int nowRow = dgv.CurrentRow, Index;
252
-
253
- DateTime oldDate
254
-
255
- = DateTime.Parse(dgv.Rows[nowRow].Cell[0].Value.ToString());
256
-
257
- string oldCategory = dgv.Rows[nowRow].Cell[1].Value.ToString();
258
-
259
- string oldItem = dgv.Rows[nowRow].Cell[2].Value.ToString();
260
-
261
- int oldMoney
262
-
263
- = int.Parse(dgv.Rows[nowRow].Cells[3].Value.ToString());
264
-
265
- string oldRemarks = dgv.Rows[nowRow].Cells[4].Value.ToString();
266
-
267
- ItemForm frmItem = newItemForm(categoryDataSet1,
268
-
269
- oldDate,
270
-
271
- oldCategory,
272
-
273
- oldItem,
274
-
275
- oldMoney,
276
-
277
- oldRemarks);
278
-
279
- DialogResult draRet = frmItem.ShowDialog();
280
-
281
- if (draRet == DialogResult.OK)
282
-
283
- {
284
-
285
- dgv.Rows[nowRow].Cells[0].Value
286
-
287
- = frmItem.monCalendar.SelectionRangr.Start;
288
-
289
- dgv.Rows[nowRow].Cells[1].Value = frmItem.cmbCategory.Text;
290
-
291
- dgv.Rows[nowRow].Cells[2].Value = frmItem.txtItem.Text;
292
-
293
- dgv.Rows[nowRow].Cells[3].Value = int.Parse.(frmItem.mtxtMoney.Text);
294
-
295
- dgv.Rows[nowRow].Cells[4].Value = frmItem.txtRemarks.Text;
296
-
297
- }
298
-
299
- }
300
-
301
-
302
-
303
- private void buttonChange_Click(object sender, EditorArgs e)
304
-
305
- {
306
-
307
- UpdateData();
308
-
309
- }
310
-
311
-
312
-
313
- private void 変更CToolStripMenuItem_Click(object sender, EditorArgs e)
314
-
315
- {
316
-
317
- UpdateData();
318
-
319
- }
320
-
321
-
322
-
323
- private void DeleteData()
324
-
325
- {
326
-
327
- int nowRow = DataGridView.CurrentRow.Index;
328
-
329
- DataGridView.Rows.RemoveAt(nowRow); // 現在行を削除
330
-
331
- }
332
-
333
-
334
-
335
- private void buttonDelete_Click(object sender, EditorArgs e)
336
-
337
- {
338
-
339
- DeleteData();
340
-
341
- }
342
-
343
-
344
-
345
- private void buttonChange_Click(object sender, EditorArgs e)
346
-
347
- {
348
-
349
- DeleteData();
350
-
351
- }
352
-
353
- }
354
-
355
- }
356
-
357
-
358
-
359
- ```ただいまC#で家計簿を作成しています。
360
-
361
- 日付をmonth calendar で登録し、Data grid view で一覧表示、CSVファイルで保存しております。
362
-
363
- このとき、既に登録してある日付を登録画面で再度登録しようとすると強制的に登録画面を終了させたたいです。
364
-
365
- これをRowCountを使い実装するにはどうしたらよろしいでしょうか。

1

現時点でのコードです。

2020/10/04 12:44

投稿

AIUABC
AIUABC

スコア0

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,362 @@
1
+ ```C#
2
+
3
+ using System;
4
+
5
+ using System.Collections.Generic;
6
+
7
+ using System.ComponentModel;
8
+
9
+ using System.Data;
10
+
11
+ using System.Drawing;
12
+
13
+ using System.Linq;
14
+
15
+ using System.Text;
16
+
17
+ using System.Threading.Tasks;
18
+
19
+ using System.Windows.Forms;
20
+
21
+
22
+
23
+ namespace MyHouseKeepingBook
24
+
25
+ {
26
+
27
+ public partial class Form1 : Form
28
+
29
+ {
30
+
31
+ public Form1()
32
+
33
+ {
34
+
35
+ InitializeComponent();
36
+
37
+ }
38
+
39
+
40
+
41
+ private void buttonAdd_Click(object sender, EventArgs e)
42
+
43
+ {
44
+
45
+ AddData();
46
+
47
+ }
48
+
49
+
50
+
51
+ private void 追加AToolStripMenuItem_Click(object sender, EventArgs e)
52
+
53
+ {
54
+
55
+ AddData();
56
+
57
+ }
58
+
59
+
60
+
61
+ private void AddData()
62
+
63
+ {
64
+
65
+ ItemForm frmItem = new ItemForm(CategoryDataSet1);
66
+
67
+ DialogResult drRet = frmItem.ShowDialog();
68
+
69
+ if (drRet == DialogResult.OK)
70
+
71
+ {
72
+
73
+ moneyDataSet.moneyDataTable.AddmoneyDataTableRow(
74
+
75
+ frmItem.monCalendar.SelectionRange.Start,
76
+
77
+ frmItem.cmbCategory.Text,
78
+
79
+ frmItem.txtItem.Text,
80
+
81
+ int.Parse(frmItem.mtxtMoney.Text),
82
+
83
+ frmItem.txtRemarks.Text);
84
+
85
+ }
86
+
87
+ }
88
+
89
+
90
+
91
+ private void Form1_Load(object sender, EventArgs e)
92
+
93
+ {
94
+
95
+ LoadData();
96
+
97
+ categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("給料", "入金");
98
+
99
+ categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("食費", "出金");
100
+
101
+ categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("雑費", "出金");
102
+
103
+ categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("住居", "出金");
104
+
105
+ }
106
+
107
+
108
+
109
+ private void buttonEnd_Click(object sender, EventArgs e)
110
+
111
+ {
112
+
113
+ this.Close();
114
+
115
+ }
116
+
117
+
118
+
119
+ private void 終了XToolStripMenuItem_Click(object sender, EventArgs e)
120
+
121
+ {
122
+
123
+ this.Close();
124
+
125
+ }
126
+
127
+
128
+
129
+ private void SaveData()
130
+
131
+ {
132
+
133
+ string path = "MoneyData.csv"; //出力ファイル名
134
+
135
+ string strData = ""; //一行分のデータ
136
+
137
+ System.IO.StreamWriter sw = new System.IO.StreamWriter(
138
+
139
+ path,
140
+
141
+ false,
142
+
143
+ System.Text.Encoding.Default);
144
+
145
+ foreach (MoneyDataSet.moneyDataTableRow drMoney
146
+
147
+ in moneyDataSet.moneyDataTable)
148
+
149
+ {
150
+
151
+ strData = drMoney.日付.ToShortDataString() + ","
152
+
153
+ + drMoney.分類 + ","
154
+
155
+ + drMoney.品目 + ","
156
+
157
+ + drMoney.金額.ToString() + ","
158
+
159
+ + drMoney.備考;
160
+
161
+ sw.WriteLine(strData);
162
+
163
+ }
164
+
165
+ sw.Close();
166
+
167
+ }
168
+
169
+
170
+
171
+ private void 保存SToolStripMenuItem_Click(object sender, EditorArgs e)
172
+
173
+ {
174
+
175
+ SaveData();
176
+
177
+ }
178
+
179
+
180
+
181
+ private void form1_FormClosing(object sender, FormClosingEditorArgs e)
182
+
183
+ {
184
+
185
+ SaveData();
186
+
187
+ }
188
+
189
+
190
+
191
+ private void LoadData()
192
+
193
+ {
194
+
195
+ string path = "MoneyData.csv"; //入力ファイル名
196
+
197
+ string delimStr = ","; // 区切り文字
198
+
199
+ char[] delimiter = delimStr.ToCharArray(); // 区切り文字をまとめる
200
+
201
+ string[] strLine; // 分解後の文字の入れ物
202
+
203
+ string strLine; // 一行分のデータ
204
+
205
+ bool fileExists = System.IO.File.Exists(path);
206
+
207
+ if (fileExists)
208
+
209
+ {
210
+
211
+ System.IO.StreamReader sr = new System.IO.StreamReader(
212
+
213
+ path,
214
+
215
+ System.Text.Encoding.Default);
216
+
217
+ while (sr.Peek() >= 0)
218
+
219
+ {
220
+
221
+ strLine = sr.ReadLine();
222
+
223
+ strData = strLine.Splite(delimiter);
224
+
225
+ moneyDataSet.moneyDataTable.AddmoneyDataTableRow(
226
+
227
+ DateTime.Parse(strData[0]),
228
+
229
+ strData[1],
230
+
231
+ strData[2],
232
+
233
+ int, Parse(strData[3]),
234
+
235
+ strData[4];
236
+
237
+ }
238
+
239
+ sr.Close;
240
+
241
+ }
242
+
243
+ }
244
+
245
+
246
+
247
+ private void UpdateData()
248
+
249
+ {
250
+
251
+ int nowRow = dgv.CurrentRow, Index;
252
+
253
+ DateTime oldDate
254
+
255
+ = DateTime.Parse(dgv.Rows[nowRow].Cell[0].Value.ToString());
256
+
257
+ string oldCategory = dgv.Rows[nowRow].Cell[1].Value.ToString();
258
+
259
+ string oldItem = dgv.Rows[nowRow].Cell[2].Value.ToString();
260
+
261
+ int oldMoney
262
+
263
+ = int.Parse(dgv.Rows[nowRow].Cells[3].Value.ToString());
264
+
265
+ string oldRemarks = dgv.Rows[nowRow].Cells[4].Value.ToString();
266
+
267
+ ItemForm frmItem = newItemForm(categoryDataSet1,
268
+
269
+ oldDate,
270
+
271
+ oldCategory,
272
+
273
+ oldItem,
274
+
275
+ oldMoney,
276
+
277
+ oldRemarks);
278
+
279
+ DialogResult draRet = frmItem.ShowDialog();
280
+
281
+ if (draRet == DialogResult.OK)
282
+
283
+ {
284
+
285
+ dgv.Rows[nowRow].Cells[0].Value
286
+
287
+ = frmItem.monCalendar.SelectionRangr.Start;
288
+
289
+ dgv.Rows[nowRow].Cells[1].Value = frmItem.cmbCategory.Text;
290
+
291
+ dgv.Rows[nowRow].Cells[2].Value = frmItem.txtItem.Text;
292
+
293
+ dgv.Rows[nowRow].Cells[3].Value = int.Parse.(frmItem.mtxtMoney.Text);
294
+
295
+ dgv.Rows[nowRow].Cells[4].Value = frmItem.txtRemarks.Text;
296
+
297
+ }
298
+
299
+ }
300
+
301
+
302
+
303
+ private void buttonChange_Click(object sender, EditorArgs e)
304
+
305
+ {
306
+
307
+ UpdateData();
308
+
309
+ }
310
+
311
+
312
+
313
+ private void 変更CToolStripMenuItem_Click(object sender, EditorArgs e)
314
+
315
+ {
316
+
317
+ UpdateData();
318
+
319
+ }
320
+
321
+
322
+
323
+ private void DeleteData()
324
+
325
+ {
326
+
327
+ int nowRow = DataGridView.CurrentRow.Index;
328
+
329
+ DataGridView.Rows.RemoveAt(nowRow); // 現在行を削除
330
+
331
+ }
332
+
333
+
334
+
335
+ private void buttonDelete_Click(object sender, EditorArgs e)
336
+
337
+ {
338
+
339
+ DeleteData();
340
+
341
+ }
342
+
343
+
344
+
345
+ private void buttonChange_Click(object sender, EditorArgs e)
346
+
347
+ {
348
+
349
+ DeleteData();
350
+
351
+ }
352
+
353
+ }
354
+
355
+ }
356
+
357
+
358
+
1
- ただいまC#で家計簿を作成しています。
359
+ ```ただいまC#で家計簿を作成しています。
2
360
 
3
361
  日付をmonth calendar で登録し、Data grid view で一覧表示、CSVファイルで保存しております。
4
362