Example #1
0
 /// <summary>
 /// takes the values given below and displays them in the text boxes
 /// </summary>
 /// <param name="myphone"></param>
 private void DisplayCellPhone(CellPhone myphone)
 {
     //display input in text boxes
     lblResultBrand.Text = myphone.Brand;
     lblResultModel.Text = myphone.Model;
     lblResultPrice.Text = myphone.Price.ToString("c");
 }
Example #2
0
 /// <summary>
 /// takes the values given below and displays them in the text boxes
 /// </summary>
 /// <param name="myphone"></param>
 private void DisplayCellPhone(CellPhone myphone)
 {
     //display input in text boxes
     lblResultBrand.Text = myphone.Brand;
     lblResultModel.Text = myphone.Model;
     lblResultPrice.Text = myphone.Price.ToString("c");
 }
Example #3
0
        static void Main(string[] args)
        {
            var cp1 = new CellPhone {
                PhoneNumber     = "513-555-1212",
                Serviceprovider = "Verizon",
                OperatingSystem = "iOS",
                Capacity        = 128,
                Model           = "iPhone X"
            };
            var cp2 = new CellPhone {
                PhoneNumber     = "614-555--1212",
                Serviceprovider = "T-Mobile",
                OperatingSystem = "Android",
                Capacity        = 64,
                Model           = "Samsung s6"
            };


            var cellphones = new CellPhone[] { cp1, cp2 };

            foreach (var CP in cellphones)
            {
                Console.WriteLine($"Phone Number is {CP.PhoneNumber}");
            }
        }
Example #4
0
        /// <summary>
        /// click event for create phone button to get and set cellphone
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreatePhone_Click(object sender, EventArgs e)
        {
            //create new instance of CellPhone class
            CellPhone myphone = new CellPhone();

            //validate and set cellphone values
            if (ValidateSetCellPhone(myphone))
            {
                //display cellphone values in results labels
                DisplayCellPhone(myphone);
            }
        }
Example #5
0
        /// <summary>
        /// click event for create phone button to get and set cellphone
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCreatePhone_Click(object sender, EventArgs e)
        {
            //create new instance of CellPhone class
            CellPhone myphone = new CellPhone();

            //validate and set cellphone values
            if (ValidateSetCellPhone(myphone))
            {
                //display cellphone values in results labels
                DisplayCellPhone(myphone);
            }
        }
Example #6
0
        private void BtnMove_Click(object sender, EventArgs e)
        {
            // Create an instance of CellPhone class
            CellPhone myPhone = new CellPhone();

            // Set the phone data
            SetPhoneData(myPhone);

            // Get the Phone Data
            lblModel.Text = myPhone.Model;
            lblPrice.Text = myPhone.Price.ToString("c"); // parm for ToString "c" means to format as currency
        }
Example #7
0
        // private is default.
        private void SetPhoneData(CellPhone phone)
        {
            decimal price;

            phone.Model = txtModel.Text;

            if (decimal.TryParse(txtPrice.Text, out price)) // tries to parse it into a decimal
            {
                phone.Price = price;
            }
            else
            {
                MessageBox.Show("Invalid Price");
            }
        }
Example #8
0
        /// <summary>
        /// validates user input and sets values for CellPhone class
        /// </summary>
        /// <param name="myphone"></param>
        /// <returns></returns>
        private bool ValidateSetCellPhone(CellPhone myphone)
        {
            //declare local decimal variable for price
            decimal price;

            //validate Model, Brand and Price; and set Model, Brand, and Price
            if (decimal.TryParse(txtBoxPrice.Text, out price) && price > 0 && txtBoxModel.Text != "" && txtBoxBrand.Text != "")
            {
                myphone.Model = txtBoxModel.Text;
                myphone.Brand = txtBoxBrand.Text;
                myphone.Price = price;
                //return true if valid
                return true;
            }

            //error if one or more field is incorrect
            MessageBox.Show("Please enter a valid model, brand, and price.");
            //return false if not valid
            return false;
        }
Example #9
0
        /// <summary>
        /// validates user input and sets values for CellPhone class
        /// </summary>
        /// <param name="myphone"></param>
        /// <returns></returns>
        private bool ValidateSetCellPhone(CellPhone myphone)
        {
            //declare local decimal variable for price
            decimal price;

            //validate Model, Brand and Price; and set Model, Brand, and Price
            if (decimal.TryParse(txtBoxPrice.Text, out price) && price > 0 && txtBoxModel.Text != "" && txtBoxBrand.Text != "")
            {
                myphone.Model = txtBoxModel.Text;
                myphone.Brand = txtBoxBrand.Text;
                myphone.Price = price;
                //return true if valid
                return(true);
            }

            //error if one or more field is incorrect
            MessageBox.Show("Please enter a valid model, brand, and price.");
            //return false if not valid
            return(false);
        }