Esempio n. 1
0
 /// <summary>
 /// Read all members in a member list
 /// </summary>
 public List <model.Member> GetMembersFromFile()
 {
     try
     {
         List <model.Member> members = new List <Member>();
         if (File.Exists(m_memberFilePath))
         {
             using (StreamReader sr = new StreamReader(m_memberFilePath))
             {
                 while (!sr.EndOfStream)
                 {
                     string         name     = sr.ReadLine();
                     long           pNumber  = long.Parse(sr.ReadLine());
                     int            memberID = int.Parse(sr.ReadLine());
                     model.BoatList boatList = new model.BoatList(memberID);
                     members.Add(new model.Member(name, pNumber, memberID, boatList));
                 }
                 sr.Close();
             }
         }
         return(members);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Read all members in a member list
 /// </summary>
 public List<model.Member> GetMembersFromFile()
 {
     try
     {
         List<model.Member> members = new List<Member>();
         if (File.Exists(m_memberFilePath))
         {
             using (StreamReader sr = new StreamReader(m_memberFilePath))
             {
                 while (!sr.EndOfStream)
                 {
                     string name = sr.ReadLine();
                     long pNumber = long.Parse(sr.ReadLine());
                     int memberID = int.Parse(sr.ReadLine());
                     model.BoatList boatList = new model.BoatList(memberID);
                     members.Add(new model.Member(name, pNumber, memberID, boatList));
                 }
                 sr.Close();
             }
         }
         return members;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Save all boats in the list to the boat list file
        /// </summary>
        /// <param name="a_boatList">BoatList. A list of boats to be saved</param>
        public void SaveBoats(model.BoatList a_boatList)
        {
            try
            {
                List <model.BoatList> boatLists = new List <model.BoatList>();
                if (File.Exists(m_boatFilePath))
                {
                    // Add all boatLists not owned by the saving member to boatLists
                    using (StreamReader sr = new StreamReader(m_memberFilePath))
                    {
                        while (!sr.EndOfStream)
                        {
                            sr.ReadLine();
                            sr.ReadLine();
                            int memberID = int.Parse(sr.ReadLine());
                            if (memberID != m_memberID)
                            {
                                boatLists.Add(new model.BoatList(memberID));
                            }
                        }
                        sr.Close();
                    }
                }

                // Add this boatList to the boatLists
                boatLists.Add(a_boatList);

                // Remove the old boats file to make room for the new one
                File.Create(m_boatFilePath).Dispose();

                // Save all boats to the file
                using (StreamWriter sw = File.AppendText(m_boatFilePath))
                {
                    if (boatLists.Count > 0)
                    {
                        foreach (model.BoatList boatList in boatLists)
                        {
                            foreach (model.Boat boat in boatList.GetBoats())
                            {
                                sw.WriteLine((int)boat.GetBoatType());
                                sw.WriteLine(boat.GetLength());
                                sw.WriteLine(boatList.GetMemberID());
                            }
                        }
                        sw.Close();
                    }
                    else
                    {
                        sw.Close();
                        File.WriteAllText(m_boatFilePath, String.Empty);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }