private void addPhoneButton_Click(object sender, EventArgs e)
        {
            if (IsInputValid())
            {
                CellPhone phone = new CellPhone();

                GetPhoneData(phone);

                if (!IsDuplicateEntry(phone))
                {
                    DisplayPhoneData(phone);
                }
                else
                {
                    MessageBox.Show("Phone already exists.");
                    Clear();
                    brandTextBox.Focus();
                }

                Clear();
                brandTextBox.Focus();
            }
            else
            {
                MessageBox.Show("Please make sure all textboxes are filled in and contain valid input.");
                Clear();
                brandTextBox.Focus();
            }
        }
        //the get the phone method accepts a cellphone object as an argument
        private void GetPhoneData(CellPhone phone)
        {
            //Get the phone's brand
            phone.Brand = brandTextBox.Text;

            //Get the phone's model
            phone.Model = modelTextBox.Text;

            //get the phones price
            phone.Price = priceTextBox.Text;
        }
        private void addPhoneButton_Click(object sender, EventArgs e)
        {
            CellPhone myPhone = new CellPhone();

            GetPhonedata(myPhone);
            phoneList.Add(myPhone);
            phoneListBox.Items.Add(myPhone.Brand + "  " + myPhone.Model);
            brandTextBox.Clear();
            modelTextBox.Clear();
            priceTextBox.Clear();
            brandTextBox.Focus();
        }
        private void GetPhonedata(CellPhone phone)
        {
            decimal price;

            phone.Brand = brandTextBox.Text;
            phone.Model = modelTextBox.Text;
            if (decimal.TryParse(priceTextBox.Text, out price))
            {
                phone.Price = price;
            }
            else
            {
                MessageBox.Show("Invalid priice");
            }
        }
Esempio n. 5
0
        //Creates a new phone, executes the previous method, and adds the new phone number into the phone list, and displays it
        //in the list box; then most controls reset.
        private void btnAdd_Click(object sender, EventArgs e)
        {
            CellPhone phone = new CellPhone();

            GetPhoneData(phone);

            phoneList.Add(phone);

            lbPhones.Items.Add(phone.Brand + " " + phone.Model);

            txtBrand.Clear();
            txtModel.Clear();
            txtPrice.Clear();

            txtBrand.Focus();
        }
Esempio n. 6
0
        private void GetPhoneData(CellPhone phone)
        {
            decimal price;

            phone.Brand = brandTextBox.Text;
            phone.Model = modelTextBox.Text;

            if (decimal.TryParse(priceTextBox.Text, out price))
            {
                phone.Price = price;
            }
            else
            {
                MessageBox.Show("Invalid Amount");
            }
        }
Esempio n. 7
0
        private void addPhoneButton_Click(object sender, EventArgs e)
        {
            CellPhone myPhone = new CellPhone ();

            GetPhoneData(myPhone);

            phoneList.Add(myPhone);

            phoneListBox.Items.Add(myPhone.Brand + " " + myPhone.Model);

            brandTextBox.Clear();
            modelTextBox.Clear();
            priceTextBox.Clear();

            brandTextBox.Focus();
        }
Esempio n. 8
0
        //Method to gather all phone data from the text boxes.
        private void GetPhoneData(CellPhone phone)
        {
            decimal price;

            phone.Brand = txtBrand.Text;

            phone.Model = txtModel.Text;

            if (decimal.TryParse(txtPrice.Text, out price))
            {
                phone.Price = price;
            }
            else
            {
                MessageBox.Show("Invalid Price.");
            }
        }
Esempio n. 9
0
        private void GetPhoneData(CellPhone myPhone)
        {
            // variable to hold the price
            decimal price;

            // get the Phone's brand
            myPhone.Brand = brandTextBox.Text;
            myPhone.Model = modelTextBox.Text;
            if (decimal.TryParse(priceTextBox.Text, out price))
            {
                myPhone.Price = price;
            }
            else
            {
                MessageBox.Show("Invalid Price");
            }
        }
        private bool IsDuplicateEntry(CellPhone phone)
        {
            bool isDuplicate = false;
            int  index       = 0;

            if (phoneList.Count != 0)
            {
                while (!isDuplicate && index < phoneList.Count)
                {
                    if (phoneList[index].Brand == phone.Brand && phoneList[index].Model == phone.Model &&
                        phoneList[index].Price == phone.Price)
                    {
                        isDuplicate = true;
                    }

                    index++;
                }
            }

            return(isDuplicate);
        }
Esempio n. 11
0
        private void addPhoneButton_Click(object sender, EventArgs e)
        {
            // Create a CellPhone object.
            CellPhone myPhone = new CellPhone();

            // Get the phone data.
            GetPhoneData(myPhone);

            // Add the CellPhone object to the List.
            phoneList.Add(myPhone);

            // Add an entry to the list box.
            phoneListBox.Items.Add(myPhone.Brand + " " + myPhone.Model);

            // Clear the TextBox controls.
            brandTextBox.Clear();
            modelTextBox.Clear();
            priceTextBox.Clear();

            // Reset the focus.
            brandTextBox.Focus();
        }
Esempio n. 12
0
        // The GetPhoneData method accepts a CellPhone object
        // as an arugment. It assigns the data entered by the
        // user to the object's properties.
        private void GetPhoneData(CellPhone phone)
        {
            // Temporary variable to hold the price.
            decimal price;

            // Get the phone's brand.
            phone.Brand = brandTextBox.Text;

            // Get the phone's model.
            phone.Model = modelTextBox.Text;

            // Get the phone's price.
            if (decimal.TryParse(priceTextBox.Text, out price))
            {
                phone.Price = price;
            }
            else
            {
                // Display an error message.
                MessageBox.Show("Invalid price");
            }
        }
        private void addPhoneButton_Click(object sender, EventArgs e)
        {
            //create a cellphone object
            CellPhone myPhone = new CellPhone();

            //get the phone data
            GetPhoneData(myPhone);

            //add the cellphone object to the list
            phoneList.Add(myPhone);

            //add an entry to the list box
            phoneListBox.Items.Add(myPhone.Brand + " " + myPhone.Model);

            //clear text boxes
            brandTextBox.Clear();
            modelTextBox.Clear();
            priceTextBox.Clear();

            //reset the focus
            brandTextBox.Focus();
        }
Esempio n. 14
0
        private void addPhoneButton_Click(object sender, EventArgs e)
        {
            // Create a Cellphone Object
            CellPhone myPhone = new CellPhone();

            //Get Phone Data

            GetPhoneData(myPhone);

            // Add a CellPhone object to the List of Objects
            PhoneList.Add(myPhone);

            // Add an entry to the ListBox
            phoneListBox.Items.Add(myPhone.Brand + " " + myPhone.Model + " " + myPhone.Price);

            // clear out Form
            brandTextBox.Clear();
            modelTextBox.Clear();
            priceTextBox.Clear();

            //Reset Focus
            brandTextBox.Focus();
        }
 private void DisplayPhoneData(CellPhone phone)
 {
     phoneList.Add(phone);
     phoneListBox.Items.Add(phone.Brand + " " + phone.Model);
 }
 private void GetPhoneData(CellPhone phone)
 {
     phone.Brand = brandTextBox.Text;
     phone.Model = modelTextBox.Text;
     phone.Price = price;
 }