Пример #1
0
        public bool GetInfoFromFile(string ext, ref CStudents cs)
        {
            bool res = true;

            if (cs == null)
            {
                cs = new CStudents();
            }
            else
            {
                cs.Collection.Clear();
            }
            ext = ext.Trim();
            ext = ext.ToLower();
            switch (ext)
            {
            case ".bin":
                WorkWithBinary work = new WorkWithBinary();
                res = work.GetAllFromFile(ref cs);
                break;

            case ".xml":
                WorkWithXml xml = new WorkWithXml();
                res = xml.GetAllFromFile(ref cs);
                break;

            case ".txt":
                WorkWithText text = new WorkWithText();
                res = text.GetAllFromFile(ref cs);
                break;
            }
            return(res);
        }
Пример #2
0
        public bool PutInfoToFile(CStudents cs, string ext, bool Save)
        {
            cs.CleanList();
            if (!cs.IsAllCorrect())
            {
                MessageBox.Show("You did not filled all fields", "Uncorrect data", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                Save = true;
                return(false);
            }
            else
            {
                ext = ext.Trim();
                ext = ext.ToLower();
                switch (ext)
                {
                case ".bin":
                    WorkWithBinary work = new WorkWithBinary();
                    work.PutAllToFile(cs);
                    break;

                case ".xml":
                    WorkWithXml xml = new WorkWithXml();
                    xml.PutAllToFile(cs);
                    break;

                case ".txt":
                default:
                    WorkWithText text = new WorkWithText();
                    text.PutAllToFile(cs);
                    break;
                }
                Save = false;
                return(true);
            }
        }
Пример #3
0
 public void PutAllToFile(CStudents c)
 {
     using (FileStream fs = new FileStream(FileName, FileMode.Create))
     {
         serializer.Serialize(fs, c);
     }
 }
Пример #4
0
 public Form1()
 {
     InitializeComponent();
     students      = new CStudents();
     visualization = new CVisualization(students.Collection, new Point(40, 40));
     work          = new WorkWithFile();
 }
Пример #5
0
 private void makeTheTaskToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (IsOpened)
     {
         byte c  = 0;
         bool ok = true;
         do
         {
             string course = Interaction.InputBox("Input The course");
             ok = (course == "" || byte.TryParse(course, out c));
             if (!ok)
             {
                 c = 0;
             }
         } while (!ok);
         if (c != 0)
         {
             CStudents res     = students.MainTAsk(c);
             Form      ResForm = new Form();
             ResForm.Width       = 830;
             ResForm.Height      = 600;
             ResForm.MaximumSize = ResForm.MinimumSize = new Size(830, 600);
             CVisualization resV = new CVisualization(res.Collection, new Point(40, 40));
             resV.Display(false);
             resV.MakeUnAviable();
             resV.DisplayOnForm(ResForm);
             ResForm.Show();
         }
     }
     else
     {
         MessageBox.Show("You did not chose a file");
     }
 }
Пример #6
0
 public void PutAllToFile(CStudents c)
 {
     formatter = new BinaryFormatter();
     using (FileStream file = new FileStream(FileName, FileMode.OpenOrCreate))
     {
         formatter.Serialize(file, c);
     }
 }
Пример #7
0
 public void PutAllToFile(CStudents cs)
 {
     string[] buff;
     using (StreamWriter file = new StreamWriter(FileName, false))
     {
         for (int i = 0; i < cs.Collection.Count; i++)
         {
             buff = (cs.Collection.ElementAt(i)).ToStrArr();
             for (int j = 0; j < 9; j++)
             {
                 file.WriteLine(buff[j]);
             }
         }
     }
 }
Пример #8
0
        public CStudents MainTAsk(byte c)
        {
            CStudents res = new CStudents();

            for (int i = 0; i < Collection.Count; i++)
            {
                if (Collection.ElementAt(i).course == c &&
                    (Collection.ElementAt(i)).IsNotFailing() &&
                    Collection.ElementAt(i).IsActive)
                {
                    res.Collection.Add(Collection.ElementAt(i).Clone());
                }
            }
            return(res);
        }
Пример #9
0
            public bool GetAllFromFile(ref CStudents c)
            {
                string[]     buff   = new string[StringEquivalents.Nsemestrs];
                bool         res    = true;
                StreamReader reader = null;

                try
                {
                    reader = new StreamReader(FileName, false);
                    c.AddFromFile(reader);
                }
                catch
                {
                    res = false;
                }
                finally
                {
                    if (reader != null)
                    {
                        reader.Close();
                    }
                }
                return(res);
            }
Пример #10
0
            public bool GetAllFromFile(ref CStudents s)
            {
                bool          res = true;
                XmlSerializer xml = new XmlSerializer(typeof(CStudents));
                FileStream    fs  = null;

                try
                {
                    fs = new FileStream(FileName, FileMode.Open);
                    s  = (CStudents)xml.Deserialize(fs);
                }
                catch
                {
                    res = false;
                }
                finally
                {
                    if (fs != null)
                    {
                        fs.Close();
                    }
                }
                return(res);
            }
Пример #11
0
            public bool GetAllFromFile(ref CStudents cs)
            {
                formatter = new BinaryFormatter();
                FileStream file = null;
                bool       res  = true;

                try
                {
                    file = new FileStream(FileName, FileMode.Open);
                    cs   = (CStudents)formatter.Deserialize(file);
                }
                catch
                {
                    res = false;
                }
                finally
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                }
                return(res);
            }