Exemplo n.º 1
0
        public bool DisplaySaveAccountInfo(Salesperson salesperson, out bool maxAttemptsExceeded)
        {
            string userResponse;

            maxAttemptsExceeded = false;

            ConsoleUtil.HeaderText = "Save Account";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("The current account information.");
            DisplayAccountDetail(salesperson);

            ConsoleUtil.DisplayMessage("");
            userResponse = ConsoleValidator.GetYesNoFromUser(MAXIMUM_ATTEMPTS, "Save the account information?", out maxAttemptsExceeded);

            if (maxAttemptsExceeded)
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulty. You will return to the main menu.");
                return(false);
            }
            else
            {
                return(userResponse == "YES" ? true : false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// display the current account information
        /// </summary>
        public void DisplayAccountInfo(Salesperson salesperson)
        {
            ConsoleUtil.HeaderText = "Account Info";
            ConsoleUtil.DisplayReset();

            DisplayAccountDetail(salesperson);
            DisplayContinuePrompt();
        }
Exemplo n.º 3
0
        public void DisplayConfirmLoadAccountInfo(Salesperson salesperson)
        {
            ConsoleUtil.HeaderText = "Load Account";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Account information loaded.");

            DisplayAccountDetail(salesperson);

            DisplayContinuePrompt();
        }
Exemplo n.º 4
0
        public void WriteSalespersonToDataFile(Salesperson salesperson)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Salesperson), new XmlRootAttribute("Salesperson"));

            StreamWriter sWriter = new StreamWriter(_dataFilePath);

            using (sWriter)
            {
                serializer.Serialize(sWriter, salesperson);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// display a list of the cities traveled
        /// </summary>
        public void DisplayCitiesTraveled(Salesperson salesperson)
        {
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("You have traveled to the following cities.");
            ConsoleUtil.DisplayMessage("");

            foreach (string city in salesperson.CitiesVisited)
            {
                ConsoleUtil.DisplayMessage(city);
            }

            DisplayContinuePrompt();
        }
        /// <summary>
        /// Deserializes a serialized salesperson, and adds the properties to it automatically
        /// </summary>
        /// <param name="salesperson"></param>
        /// <param name="serializedString"></param>
        /// <returns></returns>
        public static bool Deserialize(this Salesperson salesperson, string serializedString)
        {
            //
            // initialize variables
            //
            int age;

            Salesperson.Ranks rank;

            if (!serializedString.Contains(','))
            {
                throw new Exception("Invalid salesman format");
            }

            string[] parameters = serializedString.Split(',');

            if (parameters.Length < 4)
            {
                throw new Exception("Invalid salesman parameters");
            }

            //
            // validate the text file
            //

            salesperson.AccountID = parameters[0];

            if (int.TryParse(parameters[1], out age))
            {
                salesperson.Age = age;
            }
            else
            {
                throw new Exception("Invalid or missing salesman age");
            }

            salesperson.FirstName = parameters[2];
            salesperson.LastName  = parameters[3];

            if (Enum.TryParse <Salesperson.Ranks>(parameters[4], out rank))
            {
                salesperson.Rank = rank;
            }
            else
            {
                throw new Exception("Invalid or missing salesman rank");
            }

            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// display the current account information
        /// </summary>
        public void DisplayAccountInfo(Salesperson salesperson)
        {
            //
            // set up the console
            //
            ConsoleUtil.HeaderText = "Account Information";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage($"First Name: {ConsoleUtil.UppercaseFirst(salesperson.FirstName)}");
            ConsoleUtil.DisplayMessage($"Last Name: {ConsoleUtil.UppercaseFirst(salesperson.LastName)}");
            ConsoleUtil.DisplayMessage($"Age: {salesperson.Age}");
            ConsoleUtil.DisplayMessage($"Account ID: {salesperson.AccountID}");
            ConsoleUtil.DisplayMessage($"Rank: {salesperson.Rank}");

            DisplayContinuePrompt();
        }
Exemplo n.º 8
0
        public Salesperson ReadSalespersonFromDataFile()
        {
            Salesperson salesperson = new Salesperson();

            StreamReader sReader = new StreamReader(_dataFilePath);

            XmlSerializer deserializer = new XmlSerializer(typeof(Salesperson));

            using (sReader)
            {
                object xmlObject = deserializer.Deserialize(sReader);
                Console.WriteLine(xmlObject);
                salesperson = (Salesperson)xmlObject;
            }

            return(salesperson);
        }
        /// <summary>
        /// Returns a string containing a single serialized salesperson
        /// </summary>
        /// <param name="salesperson"></param>
        /// <returns></returns>
        public static string Serialize(this Salesperson salesperson)
        {
            //
            // initialize string builder
            //
            StringBuilder sb = new StringBuilder();

            //
            // build out string
            //
            sb.Append(salesperson.AccountID + ",");
            sb.Append(salesperson.Age + ",");
            sb.Append(salesperson.FirstName + ",");
            sb.Append(salesperson.LastName + ",");
            sb.Append(salesperson.Rank);

            return(sb.ToString());
        }
Exemplo n.º 10
0
        private static Salesperson InitializeSalesperson()
        {
            Salesperson salesperson = new Salesperson()
            {
                FirstName     = "Bonzo",
                LastName      = "Regan",
                AccountID     = "banana103",
                CurrentStock  = new Product(ProductType.Furry, 20, false),
                CitiesVisited = new List <string>()
                {
                    "Detriot",
                    "Grand Rapids",
                    "Ann Arbor"
                }
            };

            return(salesperson);
        }
Exemplo n.º 11
0
        public Controller()
        {
            InitializeController();

            //
            // instantiate a Salesperson object
            //
            _salesPerson = new Salesperson();

            //
            // instantiate a ConsoleView object
            //
            _consoleView = new ConsoleView();

            //
            // begins running the application UI
            //
            ManageApplicationLoop();
        }
Exemplo n.º 12
0
        /// <summary>
        /// display a list of the cities traveled
        /// </summary>
        public void DisplayCitiesTraveled(Salesperson salesperson)
        {
            //
            // set up the console
            //
            ConsoleUtil.HeaderText = "Cities Traveled";
            ConsoleUtil.DisplayReset();

            //
            // go through the list, and display each city
            //
            foreach (City city in salesperson.CitiesVisited)
            {
                ConsoleUtil.DisplayMessage(city.Name);
                if (city.Departed())
                {
                    ConsoleUtil.DisplayMessage($"Spent {city.DaysSpent()} days");
                }
                if (city.ProductsBought > 0)
                {
                    ConsoleUtil.DisplayMessage($"Bought {city.ProductsBought} units");
                }
                if (city.ProductsSold > 0)
                {
                    ConsoleUtil.DisplayMessage($"Sold {city.ProductsSold} units");
                }
                if (city.CompaniesVisited.Count > 0)
                {
                    ConsoleUtil.DisplayMessage("\nVisited Companies: ");
                }

                foreach (string company in city.CompaniesVisited)
                {
                    ConsoleUtil.DisplayMessage("\t" + company);
                }

                Console.WriteLine();
            }

            DisplayContinuePrompt();
        }
Exemplo n.º 13
0
        private void DisplayLoadAccountInfo()
        {
            bool maxAtemptsExceeded = false;
            bool loadAccountInfo    = false;

            if (_salesperson.AccountID != "")
            {
                loadAccountInfo = _consoleView.DisplayLoadAccountInfo(_salesperson, out maxAtemptsExceeded);
            }
            else
            {
                loadAccountInfo = _consoleView.DisplayLoadAccountInfo(out maxAtemptsExceeded);
            }

            if (true)
            {
                XmlServices xmlServices = new XmlServices(DataSettings.dataFilePathXml);

                _salesperson = xmlServices.ReadSalespersonFromDataFile();

                _consoleView.DisplayConfirmLoadAccountInfo(_salesperson);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// setup the new salesperson object with the initial data
        /// Note: To maintain the pattern of only the Controller changing the data this method should
        ///       return a Salesperson object with the initial data to the controller. For simplicity in
        ///       this demo, the ConsoleView object is allowed to access the Salesperson object's properties.
        /// </summary>
        public Salesperson DisplaySetupAccount()
        {
            Salesperson salesperson = new Salesperson();

            ConsoleUtil.HeaderText = "Account Setup";
            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Setup your account now.");
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your first name: ");
            salesperson.FirstName = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your last name: ");
            salesperson.LastName = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Enter your account ID: ");
            salesperson.AccountID = Console.ReadLine();
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayPromptMessage("Product Types: ");
            ConsoleUtil.DisplayMessage("");

            foreach (string productTypeName in Enum.GetNames(typeof(ProductType)))
            {
                if (productTypeName != ProductType.None.ToString())
                {
                    ConsoleUtil.DisplayMessage(productTypeName);
                }
            }

            ConsoleUtil.DisplayMessage("");
            ConsoleUtil.DisplayPromptMessage("Enter the product type: ");
            ProductType productType;

            if (Enum.TryParse <ProductType>(UppercaseFirst(Console.ReadLine()), out productType))
            {
                salesperson.CurrentStock.Type = productType;
            }
            else
            {
                salesperson.CurrentStock.Type = ProductType.None;
            }

            if (ConsoleValidator.TryGetIntegerFromUser(0, 100, 3, "products", out int numberOfUnits))
            {
                salesperson.CurrentStock.AddProducts(numberOfUnits);
            }
            else
            {
                ConsoleUtil.DisplayMessage("It appears you are having difficulty setting the number of products in your stock.");
                ConsoleUtil.DisplayMessage("By default, the number of products in your inventory are now set to zero.");
                salesperson.CurrentStock.AddProducts(0);
                DisplayContinuePrompt();
            }

            ConsoleUtil.DisplayReset();

            ConsoleUtil.DisplayMessage("Your account is setup");

            DisplayContinuePrompt();

            return(salesperson);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Edits the salesperson's account information
        /// </summary>
        /// <param name="salesperson"></param>
        public void DisplayEditAccountInfo(Salesperson salesperson)
        {
            bool   validResponse = false;
            int    userAge       = 0;
            string userResponse;

            Salesperson.Ranks rank;
            //
            // set up the console
            //
            ConsoleUtil.HeaderText = "Account Editing";
            ConsoleUtil.DisplayReset();

            //
            // get new account info
            //
            ConsoleUtil.DisplayMessage("Just press enter if you wish to skip the current field");
            ConsoleUtil.DisplayMessage("");

            ConsoleUtil.DisplayMessage($"First Name: {salesperson.FirstName}");

            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                salesperson.FirstName = userResponse;
            }

            Console.WriteLine("");

            ConsoleUtil.DisplayMessage($"Last Name: {salesperson.LastName}");

            userResponse = Console.ReadLine();
            if (userResponse != "")
            {
                salesperson.LastName = userResponse;
            }

            Console.WriteLine("");


            ConsoleUtil.DisplayMessage($"Age: {salesperson.Age}");

            validResponse = ConsoleValidator.TryGetIntegerFromUser(10, 90, MAXIMUM_ATTEMPTS, "years old", out userAge, true);
            if (validResponse)
            {
                salesperson.Age = userAge;
            }

            ConsoleUtil.DisplayMessage($"Account ID: {salesperson.AccountID}");

            if (userResponse != "")
            {
                salesperson.AccountID = userResponse;
            }
            Console.WriteLine("");


            ConsoleUtil.DisplayMessage($"Rank: {salesperson.Rank}");

            if (ConsoleValidator.GetEnumValueFromUser <Salesperson.Ranks>(MAXIMUM_ATTEMPTS, "Rank:", out rank, true))
            {
                salesperson.Rank = rank;
            }

            DisplayContinuePrompt();
        }
Exemplo n.º 16
0
        /// <summary>
        /// setup the new salesperson object with the initial data
        /// Note: To maintain the pattern of only the Controller changing the data this method should
        ///       return a Salesperson object with the initial data to the controller. For simplicity in
        ///       this demo, the ConsoleView object is allowed to access the Salesperson object's properties.
        /// </summary>
        public Salesperson DisplaySetupAccount()
        {
            //
            // initialize variables
            //
            bool validResponse;
            int  userAge;
            int  productAmount;

            Product.ProductType productType;
            Salesperson         salesperson = new Salesperson();

            //
            // set up the console
            //
            ConsoleUtil.HeaderText = "Account Setup";
            ConsoleUtil.DisplayReset();

            //
            // get new account info
            //
            ConsoleUtil.DisplayPromptMessage("First name: ");
            salesperson.FirstName = Console.ReadLine();
            Console.WriteLine("");

            ConsoleUtil.DisplayPromptMessage("Last name: ");
            salesperson.LastName = Console.ReadLine();
            Console.WriteLine("");

            ConsoleUtil.DisplayMessage("Age");
            validResponse = ConsoleValidator.TryGetIntegerFromUser(10, 90, MAXIMUM_ATTEMPTS, "years old", out userAge);
            if (validResponse)
            {
                salesperson.Age = userAge;
            }

            ConsoleUtil.DisplayPromptMessage("Account ID: ");
            salesperson.AccountID = Console.ReadLine();
            Console.WriteLine("");

            //
            // validate user input
            //
            ConsoleUtil.DisplayMessage("Setting up inventory..");
            ConsoleUtil.DisplayMessage("");
            if (!ConsoleValidator.GetEnumValueFromUser <Product.ProductType>(MAXIMUM_ATTEMPTS, "Body Style:", out productType))
            {
                ConsoleUtil.DisplayMessage("Maximum attempts exceeded, returning to main menu.");
            }


            if (!ConsoleValidator.TryGetIntegerFromUser(MINIMUM_BUYSELL_AMOUNT, MAXIMUM_BUYSELL_AMOUNT, MAXIMUM_ATTEMPTS, $"{productType.ToString()}s", out productAmount))
            {
                ConsoleUtil.DisplayMessage("Max attempts exceeded, returning to main menu with default value of 0 vehicles.");
            }

            //
            // set salesman product object
            //
            salesperson.CurrentStock[productType].NumberOfUnits = productAmount;

            salesperson.Rank = Salesperson.Ranks.Beginner;

            DisplayContinuePrompt();
            return(salesperson);
        }
Exemplo n.º 17
0
 /// <summary>
 /// sets up the salesman account
 /// </summary>
 private void DisplaySetUpAccount()
 {
     _salesPerson = _consoleView.DisplaySetupAccount();
 }
Exemplo n.º 18
0
 public void DisplayAccountDetail(Salesperson salesperson)
 {
     ConsoleUtil.DisplayMessage("First Name: " + salesperson.FirstName);
     ConsoleUtil.DisplayMessage("Last Name: " + salesperson.LastName);
     ConsoleUtil.DisplayMessage("Account ID: " + salesperson.AccountID);
 }