質問編集履歴
2
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,183 +1,3 @@
|
|
1
|
-
```C#
|
2
|
-
using System;
|
3
|
-
using System.Collections.Generic;
|
4
|
-
using System.ComponentModel;
|
5
|
-
using System.Data;
|
6
|
-
using System.Drawing;
|
7
|
-
using System.Linq;
|
8
|
-
using System.Text;
|
9
|
-
using System.Threading.Tasks;
|
10
|
-
using System.Windows.Forms;
|
11
|
-
|
12
|
-
namespace MyHouseKeepingBook
|
13
|
-
{
|
14
|
-
public partial class Form1 : Form
|
15
|
-
{
|
16
|
-
public Form1()
|
17
|
-
{
|
18
|
-
InitializeComponent();
|
19
|
-
}
|
20
|
-
|
21
|
-
private void buttonAdd_Click(object sender, EventArgs e)
|
22
|
-
{
|
23
|
-
AddData();
|
24
|
-
}
|
25
|
-
|
26
|
-
private void 追加AToolStripMenuItem_Click(object sender, EventArgs e)
|
27
|
-
{
|
28
|
-
AddData();
|
29
|
-
}
|
30
|
-
|
31
|
-
private void AddData()
|
32
|
-
{
|
33
|
-
ItemForm frmItem = new ItemForm(CategoryDataSet1);
|
34
|
-
DialogResult drRet = frmItem.ShowDialog();
|
35
|
-
if (drRet == DialogResult.OK)
|
36
|
-
{
|
37
|
-
moneyDataSet.moneyDataTable.AddmoneyDataTableRow(
|
38
|
-
frmItem.monCalendar.SelectionRange.Start,
|
39
|
-
frmItem.cmbCategory.Text,
|
40
|
-
frmItem.txtItem.Text,
|
41
|
-
int.Parse(frmItem.mtxtMoney.Text),
|
42
|
-
frmItem.txtRemarks.Text);
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
private void Form1_Load(object sender, EventArgs e)
|
47
|
-
{
|
48
|
-
|
1
|
+
RowCountについて
|
49
|
-
categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("給料", "入金");
|
50
|
-
categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("食費", "出金");
|
51
|
-
categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("雑費", "出金");
|
52
|
-
categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("住居", "出金");
|
53
|
-
}
|
54
|
-
|
55
|
-
private void buttonEnd_Click(object sender, EventArgs e)
|
56
|
-
{
|
57
|
-
this.Close();
|
58
|
-
}
|
59
|
-
|
60
|
-
private void 終了XToolStripMenuItem_Click(object sender, EventArgs e)
|
61
|
-
{
|
62
|
-
this.Close();
|
63
|
-
}
|
64
|
-
|
65
|
-
private void SaveData()
|
66
|
-
{
|
67
|
-
string path = "MoneyData.csv"; //出力ファイル名
|
68
|
-
string strData = ""; //一行分のデータ
|
69
|
-
System.IO.StreamWriter sw = new System.IO.StreamWriter(
|
70
|
-
path,
|
71
|
-
false,
|
72
|
-
System.Text.Encoding.Default);
|
73
|
-
foreach (MoneyDataSet.moneyDataTableRow drMoney
|
74
|
-
in moneyDataSet.moneyDataTable)
|
75
|
-
{
|
76
|
-
strData = drMoney.日付.ToShortDataString() + ","
|
77
|
-
+ drMoney.分類 + ","
|
78
|
-
+ drMoney.品目 + ","
|
79
|
-
+ drMoney.金額.ToString() + ","
|
80
|
-
+ drMoney.備考;
|
81
|
-
sw.WriteLine(strData);
|
82
|
-
}
|
83
|
-
sw.Close();
|
84
|
-
}
|
85
|
-
|
86
|
-
private void 保存SToolStripMenuItem_Click(object sender, EditorArgs e)
|
87
|
-
{
|
88
|
-
SaveData();
|
89
|
-
}
|
90
|
-
|
91
|
-
private void form1_FormClosing(object sender, FormClosingEditorArgs e)
|
92
|
-
{
|
93
|
-
SaveData();
|
94
|
-
}
|
95
|
-
|
96
|
-
private void LoadData()
|
97
|
-
{
|
98
|
-
string path = "MoneyData.csv"; //入力ファイル名
|
99
|
-
string delimStr = ","; // 区切り文字
|
100
|
-
char[] delimiter = delimStr.ToCharArray(); // 区切り文字をまとめる
|
101
|
-
string[] strLine; // 分解後の文字の入れ物
|
102
|
-
string strLine; // 一行分のデータ
|
103
|
-
bool fileExists = System.IO.File.Exists(path);
|
104
|
-
if (fileExists)
|
105
|
-
{
|
106
|
-
System.IO.StreamReader sr = new System.IO.StreamReader(
|
107
|
-
path,
|
108
|
-
System.Text.Encoding.Default);
|
109
|
-
while (sr.Peek() >= 0)
|
110
|
-
{
|
111
|
-
strLine = sr.ReadLine();
|
112
|
-
strData = strLine.Splite(delimiter);
|
113
|
-
moneyDataSet.moneyDataTable.AddmoneyDataTableRow(
|
114
|
-
DateTime.Parse(strData[0]),
|
115
|
-
strData[1],
|
116
|
-
strData[2],
|
117
|
-
int, Parse(strData[3]),
|
118
|
-
strData[4];
|
119
|
-
}
|
120
|
-
sr.Close;
|
121
|
-
}
|
122
|
-
}
|
123
|
-
|
124
|
-
private void UpdateData()
|
125
|
-
{
|
126
|
-
int nowRow = dgv.CurrentRow, Index;
|
127
|
-
DateTime oldDate
|
128
|
-
= DateTime.Parse(dgv.Rows[nowRow].Cell[0].Value.ToString());
|
129
|
-
string oldCategory = dgv.Rows[nowRow].Cell[1].Value.ToString();
|
130
|
-
string oldItem = dgv.Rows[nowRow].Cell[2].Value.ToString();
|
131
|
-
|
2
|
+
RowCountについて
|
132
|
-
= int.Parse(dgv.Rows[nowRow].Cells[3].Value.ToString());
|
133
|
-
string oldRemarks = dgv.Rows[nowRow].Cells[4].Value.ToString();
|
134
|
-
ItemForm frmItem = newItemForm(categoryDataSet1,
|
135
|
-
oldDate,
|
136
|
-
|
3
|
+
RowCountについて
|
137
|
-
oldItem,
|
138
|
-
oldMoney,
|
139
|
-
oldRemarks);
|
140
|
-
DialogResult draRet = frmItem.ShowDialog();
|
141
|
-
if (draRet == DialogResult.OK)
|
142
|
-
{
|
143
|
-
dgv.Rows[nowRow].Cells[0].Value
|
144
|
-
= frmItem.monCalendar.SelectionRangr.Start;
|
145
|
-
dgv.Rows[nowRow].Cells[1].Value = frmItem.cmbCategory.Text;
|
146
|
-
dgv.Rows[nowRow].Cells[2].Value = frmItem.txtItem.Text;
|
147
|
-
dgv.Rows[nowRow].Cells[3].Value = int.Parse.(frmItem.mtxtMoney.Text);
|
148
|
-
dgv.Rows[nowRow].Cells[4].Value = frmItem.txtRemarks.Text;
|
149
|
-
}
|
150
|
-
}
|
151
|
-
|
152
|
-
private void buttonChange_Click(object sender, EditorArgs e)
|
153
|
-
{
|
154
|
-
UpdateData();
|
155
|
-
}
|
156
|
-
|
157
|
-
private void 変更CToolStripMenuItem_Click(object sender, EditorArgs e)
|
158
|
-
{
|
159
|
-
UpdateData();
|
160
|
-
}
|
161
|
-
|
162
|
-
private void DeleteData()
|
163
|
-
{
|
164
|
-
int nowRow = DataGridView.CurrentRow.Index;
|
165
|
-
DataGridView.Rows.RemoveAt(nowRow); // 現在行を削除
|
166
|
-
}
|
167
|
-
|
168
|
-
private void buttonDelete_Click(object sender, EditorArgs e)
|
169
|
-
{
|
170
|
-
DeleteData();
|
171
|
-
}
|
172
|
-
|
173
|
-
private void buttonChange_Click(object sender, EditorArgs e)
|
174
|
-
{
|
175
|
-
DeleteData();
|
176
|
-
}
|
177
|
-
}
|
178
|
-
}
|
179
|
-
|
180
|
-
```ただいまC#で家計簿を作成しています。
|
181
|
-
日付をmonth calendar で登録し、Data grid view で一覧表示、CSVファイルで保存しております。
|
182
|
-
このとき、既に登録してある日付を登録画面で再度登録しようとすると強制的に登録画面を終了させたたいです。
|
183
|
-
これをRowCountを使い実装するにはどうしたらよろしいでしょうか。
|
1
現時点でのコードです。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,183 @@
|
|
1
|
+
```C#
|
2
|
+
using System;
|
3
|
+
using System.Collections.Generic;
|
4
|
+
using System.ComponentModel;
|
5
|
+
using System.Data;
|
6
|
+
using System.Drawing;
|
7
|
+
using System.Linq;
|
8
|
+
using System.Text;
|
9
|
+
using System.Threading.Tasks;
|
10
|
+
using System.Windows.Forms;
|
11
|
+
|
12
|
+
namespace MyHouseKeepingBook
|
13
|
+
{
|
14
|
+
public partial class Form1 : Form
|
15
|
+
{
|
16
|
+
public Form1()
|
17
|
+
{
|
18
|
+
InitializeComponent();
|
19
|
+
}
|
20
|
+
|
21
|
+
private void buttonAdd_Click(object sender, EventArgs e)
|
22
|
+
{
|
23
|
+
AddData();
|
24
|
+
}
|
25
|
+
|
26
|
+
private void 追加AToolStripMenuItem_Click(object sender, EventArgs e)
|
27
|
+
{
|
28
|
+
AddData();
|
29
|
+
}
|
30
|
+
|
31
|
+
private void AddData()
|
32
|
+
{
|
33
|
+
ItemForm frmItem = new ItemForm(CategoryDataSet1);
|
34
|
+
DialogResult drRet = frmItem.ShowDialog();
|
35
|
+
if (drRet == DialogResult.OK)
|
36
|
+
{
|
37
|
+
moneyDataSet.moneyDataTable.AddmoneyDataTableRow(
|
38
|
+
frmItem.monCalendar.SelectionRange.Start,
|
39
|
+
frmItem.cmbCategory.Text,
|
40
|
+
frmItem.txtItem.Text,
|
41
|
+
int.Parse(frmItem.mtxtMoney.Text),
|
42
|
+
frmItem.txtRemarks.Text);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
private void Form1_Load(object sender, EventArgs e)
|
47
|
+
{
|
48
|
+
LoadData();
|
49
|
+
categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("給料", "入金");
|
50
|
+
categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("食費", "出金");
|
51
|
+
categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("雑費", "出金");
|
52
|
+
categoryDataSet1.CategoryDataTable.AddCategoryDataTableRow("住居", "出金");
|
53
|
+
}
|
54
|
+
|
55
|
+
private void buttonEnd_Click(object sender, EventArgs e)
|
56
|
+
{
|
57
|
+
this.Close();
|
58
|
+
}
|
59
|
+
|
60
|
+
private void 終了XToolStripMenuItem_Click(object sender, EventArgs e)
|
61
|
+
{
|
62
|
+
this.Close();
|
63
|
+
}
|
64
|
+
|
65
|
+
private void SaveData()
|
66
|
+
{
|
67
|
+
string path = "MoneyData.csv"; //出力ファイル名
|
68
|
+
string strData = ""; //一行分のデータ
|
69
|
+
System.IO.StreamWriter sw = new System.IO.StreamWriter(
|
70
|
+
path,
|
71
|
+
false,
|
72
|
+
System.Text.Encoding.Default);
|
73
|
+
foreach (MoneyDataSet.moneyDataTableRow drMoney
|
74
|
+
in moneyDataSet.moneyDataTable)
|
75
|
+
{
|
76
|
+
strData = drMoney.日付.ToShortDataString() + ","
|
77
|
+
+ drMoney.分類 + ","
|
78
|
+
+ drMoney.品目 + ","
|
79
|
+
+ drMoney.金額.ToString() + ","
|
80
|
+
+ drMoney.備考;
|
81
|
+
sw.WriteLine(strData);
|
82
|
+
}
|
83
|
+
sw.Close();
|
84
|
+
}
|
85
|
+
|
86
|
+
private void 保存SToolStripMenuItem_Click(object sender, EditorArgs e)
|
87
|
+
{
|
88
|
+
SaveData();
|
89
|
+
}
|
90
|
+
|
91
|
+
private void form1_FormClosing(object sender, FormClosingEditorArgs e)
|
92
|
+
{
|
93
|
+
SaveData();
|
94
|
+
}
|
95
|
+
|
96
|
+
private void LoadData()
|
97
|
+
{
|
98
|
+
string path = "MoneyData.csv"; //入力ファイル名
|
99
|
+
string delimStr = ","; // 区切り文字
|
100
|
+
char[] delimiter = delimStr.ToCharArray(); // 区切り文字をまとめる
|
101
|
+
string[] strLine; // 分解後の文字の入れ物
|
102
|
+
string strLine; // 一行分のデータ
|
103
|
+
bool fileExists = System.IO.File.Exists(path);
|
104
|
+
if (fileExists)
|
105
|
+
{
|
106
|
+
System.IO.StreamReader sr = new System.IO.StreamReader(
|
107
|
+
path,
|
108
|
+
System.Text.Encoding.Default);
|
109
|
+
while (sr.Peek() >= 0)
|
110
|
+
{
|
111
|
+
strLine = sr.ReadLine();
|
112
|
+
strData = strLine.Splite(delimiter);
|
113
|
+
moneyDataSet.moneyDataTable.AddmoneyDataTableRow(
|
114
|
+
DateTime.Parse(strData[0]),
|
115
|
+
strData[1],
|
116
|
+
strData[2],
|
117
|
+
int, Parse(strData[3]),
|
118
|
+
strData[4];
|
119
|
+
}
|
120
|
+
sr.Close;
|
121
|
+
}
|
122
|
+
}
|
123
|
+
|
124
|
+
private void UpdateData()
|
125
|
+
{
|
126
|
+
int nowRow = dgv.CurrentRow, Index;
|
127
|
+
DateTime oldDate
|
128
|
+
= DateTime.Parse(dgv.Rows[nowRow].Cell[0].Value.ToString());
|
129
|
+
string oldCategory = dgv.Rows[nowRow].Cell[1].Value.ToString();
|
130
|
+
string oldItem = dgv.Rows[nowRow].Cell[2].Value.ToString();
|
131
|
+
int oldMoney
|
132
|
+
= int.Parse(dgv.Rows[nowRow].Cells[3].Value.ToString());
|
133
|
+
string oldRemarks = dgv.Rows[nowRow].Cells[4].Value.ToString();
|
134
|
+
ItemForm frmItem = newItemForm(categoryDataSet1,
|
135
|
+
oldDate,
|
136
|
+
oldCategory,
|
137
|
+
oldItem,
|
138
|
+
oldMoney,
|
139
|
+
oldRemarks);
|
140
|
+
DialogResult draRet = frmItem.ShowDialog();
|
141
|
+
if (draRet == DialogResult.OK)
|
142
|
+
{
|
143
|
+
dgv.Rows[nowRow].Cells[0].Value
|
144
|
+
= frmItem.monCalendar.SelectionRangr.Start;
|
145
|
+
dgv.Rows[nowRow].Cells[1].Value = frmItem.cmbCategory.Text;
|
146
|
+
dgv.Rows[nowRow].Cells[2].Value = frmItem.txtItem.Text;
|
147
|
+
dgv.Rows[nowRow].Cells[3].Value = int.Parse.(frmItem.mtxtMoney.Text);
|
148
|
+
dgv.Rows[nowRow].Cells[4].Value = frmItem.txtRemarks.Text;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
private void buttonChange_Click(object sender, EditorArgs e)
|
153
|
+
{
|
154
|
+
UpdateData();
|
155
|
+
}
|
156
|
+
|
157
|
+
private void 変更CToolStripMenuItem_Click(object sender, EditorArgs e)
|
158
|
+
{
|
159
|
+
UpdateData();
|
160
|
+
}
|
161
|
+
|
162
|
+
private void DeleteData()
|
163
|
+
{
|
164
|
+
int nowRow = DataGridView.CurrentRow.Index;
|
165
|
+
DataGridView.Rows.RemoveAt(nowRow); // 現在行を削除
|
166
|
+
}
|
167
|
+
|
168
|
+
private void buttonDelete_Click(object sender, EditorArgs e)
|
169
|
+
{
|
170
|
+
DeleteData();
|
171
|
+
}
|
172
|
+
|
173
|
+
private void buttonChange_Click(object sender, EditorArgs e)
|
174
|
+
{
|
175
|
+
DeleteData();
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
|
1
|
-
ただいまC#で家計簿を作成しています。
|
180
|
+
```ただいまC#で家計簿を作成しています。
|
2
181
|
日付をmonth calendar で登録し、Data grid view で一覧表示、CSVファイルで保存しております。
|
3
182
|
このとき、既に登録してある日付を登録画面で再度登録しようとすると強制的に登録画面を終了させたたいです。
|
4
183
|
これをRowCountを使い実装するにはどうしたらよろしいでしょうか。
|