Разработка программы с целью обработки и сортировки чисел, страница 7

            {

                FileStream FS = new FileStream(openFileDialog2.FileName, FileMode.Open);

                StreamReader SR = new StreamReader(FS);

                string s;

                while ((s = SR.ReadLine()) != null)

                    listBox4.Items.Add(s);

                SR.Close();

                FS.Close();

                button2.Enabled = true;

            }

        }

        private void button3_Click(object sender, EventArgs e)

        {

            if (saveFileDialog1.ShowDialog() == DialogResult.OK)

            {

                if (saveFileDialog1.FileName.IndexOf('.') == -1)

                    saveFileDialog1.FileName = saveFileDialog1.FileName + ".txt";

                FileStream FS = new FileStream(saveFileDialog1.FileName, FileMode.Create);

                StreamWriter WR = new StreamWriter(FS);

                foreach (object value in listBox1.Items)

                    WR.WriteLine(value.ToString());

                WR.Flush();

                WR.Close();

                FS.Close();

            }

        }

        private void button4_Click(object sender, EventArgs e)

        {

            if (saveFileDialog2.ShowDialog() == DialogResult.OK)

            {

                if (saveFileDialog1.FileName.IndexOf('.') == -1)

                    saveFileDialog1.FileName = saveFileDialog1.FileName + ".txt";

                FileStream FS = new FileStream(saveFileDialog2.FileName, FileMode.Create);

                StreamWriter WR = new StreamWriter(FS);

                foreach (object value in listBox2.Items)

                    WR.WriteLine(value.ToString());

                WR.Flush();

                WR.Close();

                FS.Close();

                button5.Enabled = true;

                button6.Enabled = true;

            }

        }

    }

      }

                              Work.cs

    // Основной объект

using System;

using System.IO;

using System.Windows.Forms;

using System.Runtime.Serialization.Formatters.Binary;

namespace lab_1

{

    /// <summary>

    /// Summary description for work.

    /// </summary>

    public class work

    {

        private string SaveFileName;

        private string OpenFileName;

        private string Data1;  //Поле входных данных

        private string Data2;  //Поле входных данных

        private string Res;  // Поле результата

        private int Counter = 0; //счетчик

        private System.DateTime StartTime;

        public work()

        {

            this.Data1 = "";

            this.Data2 = "";

            this.Res = "";

        }

        public string GetOpenFile()

        {

            return OpenFileName;

        }

        public void Write(string D1, string D2)

        {

            this.Data1 = D1;

            this.Data2 = D2;

        }

        public string Read()

        {

            return this.Res;

        }

        public void Arbeit()

        {//прога

            int i, summ1 = 0, summ2 = 0;

            for (i = 0; i < 5; i++)

            {

                summ1 += (int)Data1[i] - (int)'0';

            }

            for (i = 0; i < 8; i++)

            {

                summ2 += (int)Data2[Data2.Length - i - 1] - (int)'0';

            }

            if (summ1 == summ2)

            {

                Res = "  СУММА РАВНА  ";

            }

            else

            {

                Res = "  СУММА НЕ РАВНА  ";

            }

        }

        public void SaveFileNameWrite(string Name)

        {

            if(Name=="")

            {

                MessageBox.Show("Имя файла не заданно","Ошибка");

                return;

            }

            try

            {

                BinaryWriter FileOpen = new

                     BinaryWriter(new FileStream(Name, FileMode.OpenOrCreate));

                FileOpen.Close();

                this.SaveFileName = Name;

            }

            catch

            {

                MessageBox.Show("Невозможно работать с файлом", "Ошибка");

            }

        }

        public bool IsFileHere()

        {

            if (this.SaveFileName == null) return false;

            else return true;

        }

        public void OpenFileNameWrite(string Name)

        {

            this.OpenFileName = Name;

        }

        public void WriteInFile()

        {

            Data1 D= new Data1();

            D.Key = Count();

            D.InPut1 = this.Data1;

            D.InPut2 = this.Data2;

            D.Result = this.Res;

            Stream S;

            if (File.Exists(this.SaveFileName))

                S = File.Open(this.SaveFileName, FileMode.Append);

            else

                S = File.Open(this.SaveFileName, FileMode.Create);

            BinaryFormatter bf = new BinaryFormatter();

            bf.Serialize(S,D);

            S.Close();

         }

        public void ReadFromFile(ListBox lb_read1)

        {

            Stream S = File.Open(this.OpenFileName, FileMode.Open);

            BinaryFormatter bf = new  BinaryFormatter();

            Data1 D; object O;

            while (S.Position < S.Length)

            {

                O = bf.Deserialize(S);

                D = O as Data1;

                if (D ==null)

                {

                    MessageBox.Show("Выбран конктретный файл");

                    break;

                }

                lb_read1.Items.Add(D.InPut1);

                lb_read1.Items.Add(D.InPut2);

                lb_read1.Items.Add(D.Result);

                lb_read1.Items.Add(D.Key);

                lb_read1.Items.Add(' ');

            }

            S.Close();

        }

        public void CatchTime()

        {

            this.StartTime = System.DateTime.Now;

        }

        public System.DateTime GetTime()

        {

            return StartTime;

        }

        private int Count()

        {