示例#1
0
        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();
            }
        }
示例#2
0
 private void button1_Click(object sender, EventArgs e)
 {
     if ((textBox1.Text == "") || (textBox2.Text == "") || (textBox3.Text == ""))
     {
         MessageBox.Show("Заполните все поля!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         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 = "";
     }
 }
示例#3
0
        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();
            }
        }