嗨,我是 c# 的新手,我正在尝试将 12 个复选框保存到以所选日期命名的 TEXT 文件中。
我有要输出的复选框,但似乎没有以日期命名的文件。我似乎也在这方面走了很长一段路。如果任何机构现在有任何更短的路线或我出错的地方,那就太好了。
public void timepicker_ValueChanged(object sender, EventArgs e)
{
string date = timepicker.Value.ToString("dd-MM-yyyy");
}
string amorpm = "";
if (rb_am.Checked)
{
am = rb_am.Text;
}
else if (rb_pm.Checked)
{
pm = rb_pm.Text;
}
SteamWriter am = File.CreateText("seats_file.txt");
am.WriteLine ("am morning run");
am.close;
SteamWrite pm = File.CreateText("seats_file.txt");
pm.WriteLne ("pm afternoon nrun");
pm.Close;
public void btn_saveseats_Click(object sender, EventArgs e)
{
{
String date = timepicker.Value.ToString("dd-mm-yyyy");
//String fileName = String.Format("{0}File.txt", date);
try
if (File.Exists(date))
{
(MessageBox.Show("Warning: file already exists. Contents will be replaced - do you want to continue?", "File Demo", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly) == DialogResult.Yes)
{
//write lines of text to file
StreamWriter date = File.CreateText(date);
date.WriteLine(date);
date.Close();
if (cbseat1.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat1 = File.CreateText("seats_file.txt");
seat1.WriteLine("seat 1 taken");
seat1.Close();
}
if (cbseat2.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat2 = File.AppendText("seats_file.txt");
seat2.WriteLine("seat 2 taken.Text");
seat2.Close();
}
if (cbseat3.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat3 = File.AppendText("seats_file.txt");
seat3.WriteLine("seat 3 taken");
seat3.Close();
}
if (cbseat4.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat4 = File.AppendText("seats_file.txt");
seat4.WriteLine("seat 4 taken");
seat4.Close();
}
if (cbseat5.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat5 = File.AppendText("seats_file.txt");
seat5.WriteLine("seat 5 taken");
seat5.Close();
}
if (cbseat6.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat6 = File.AppendText("seats_file.txt");
seat6.WriteLine("seat 6 taken");
seat6.Close();
}
if (cbseat7.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat7 = File.AppendText("seats_file.txt");
seat7.WriteLine("seat 7 taken");
seat7.Close();
}
if (cbseat8.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat8 = File.AppendText("seats_file.txt");
seat8.WriteLine("seat 8 taken");
seat8.Close();
}
if (cbseat9.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat9 = File.AppendText("seats_file.txt");
seat9.WriteLine("seat 9 taken");
seat9.Close();
}
if (cbseat10.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat10 = File.AppendText("seats_file.txt");
seat10.WriteLine("seat 10 taken");
seat10.Close();
}
if (cbseat11.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat11 = File.AppendText("seats_file.txt");
seat11.WriteLine("seat 11 taken");
seat11.Close();
}
if (cbseat12.Checked)
{
// Do something when CheckBox is checked
StreamWriter seat12 = File.AppendText("seats_file.txt");
seat12.WriteLine("seat 12 taken");
seat12.Close();
}
MessageBox.Show("saved");
}
}
}
}
}
}