public CSpisok(string s) { int i = 0; s = s + ".txt"; nameFile = s; try { StreamReader reader = new StreamReader(nameFile, Encoding.GetEncoding(1251)); while (!reader.EndOfStream) { i = i + 1; MasPerson[i] = new CPerson(reader); } kw = i; reader.Close(); } catch (FileNotFoundException) { MessageBox.Show("Файл не найден! Будет создан новый файл", "Предупреждение", MessageBoxButtons.OK, MessageBoxIcon.Warning); FileStream file1 = new FileStream(nameFile, FileMode.Create); StreamReader reader = new StreamReader(file1, Encoding.GetEncoding(1251)); while (!reader.EndOfStream) { i = i + 1; MasPerson[i] = new CPerson(reader); } kw = i; reader.Close(); } }
private void btnAdd_Click(object sender, EventArgs e) { if ((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == "")) { MessageBox.Show("Заполните все поля!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { if (radioButton1.Checked) { CStudent Student = new CStudent(textBox1.Text, textBox2.Text, textBox3.Text, EditGroup.Text, EditKurs.Text); spisok.AddPerson(Student); } if (radioButton3.Checked) { CPerson person = new CPerson(textBox1.Text, textBox2.Text, textBox3.Text); spisok.AddPerson(person); } label_kw.Text = Convert.ToString(spisok.Kw_pers); textBox1.Text = ""; textBox2.Text = ""; textBox3.Text = ""; //radioButton1.Enabled = false; //radioButton3.Enabled = false; } }
public CSpisok() { int i = 0; nameFile = "temp.txt"; try { StreamReader reader = new StreamReader(nameFile, Encoding.GetEncoding(1251)); while (!reader.EndOfStream) { i = i + 1; MasPerson[i] = new CPerson(reader); } kw = i; reader.Close(); } catch (Exception) { MessageBox.Show("Файл не temp.txt найден!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); Application.Exit(); } }