コード例 #1
0
ファイル: User.cs プロジェクト: dv222bk/1DV607_Portfolio
        /// <summary>
        /// Add new member menu
        /// </summary>
        private void AddMember()
        {
            m_console.AddMember();
            string name;

            while (true)
            {
                m_console.WriteMessage("Name: ");
                name = m_console.ReadResponse();
                if (name.Length > 0)
                {
                    break;
                }
                m_console.WriteMessage("The member must have a name");
            }
            m_console.WriteMessage("Name: ");
            string pNumber;

            while (true)
            {
                m_console.WriteMessage("Personal Number: ");
                pNumber = m_console.ReadResponse();
                if (pNumber.All(char.IsNumber) && pNumber.Length == 12 && long.Parse(pNumber) >= 100000000000)
                {
                    break;
                }
                m_console.WriteMessage("Wrong format, format should be YYYYMMDDXXXX");
            }
            m_memberList.AddMember(name, long.Parse(pNumber));
            m_console.SetCurrentMenu(view.Console.CurrentMenu.Main);
            GoToCurrentMenu();
        }
コード例 #2
0
 // Display views, get inputs to create/save member to list
 private void AddMember()
 {
     try
     {
         _startView.DisplayStartMenu();
         int          memberId       = _list.GetUniqueMemberId();
         string       name           = _startView.GetStringFromUser(true);
         string       personalNumber = _startView.GetStringFromUser(false);
         model.Member member         = new model.Member(memberId, name, personalNumber); // Throws exception if fail
         _list.AddMember(member);
         _list.SaveMemberList();
         DoMemberView(member);
     }
     // Using catch do display error messages to user
     catch (Exception ex)
     {
         _startView.DisplayErrorMessage(ex.Message);
         if (_startView.DoesUserWantsToQuit() == true)
         {
             DoStartMenu();
         }
         else
         {
             AddMember();
         }
     }
 }