public void SetCondition(Laptop.Condition condition) { //we can get the name of the enumeration for the given rating number this.condition = condition; }
private void buttonOK_Click(object sender, EventArgs e) { //get the selected condition if (comboBoxAddCondition.SelectedIndex == 1) { condition = Laptop.Condition.poor; } if (comboBoxAddCondition.SelectedIndex == 2) { condition = Laptop.Condition.fair; } if (comboBoxAddCondition.SelectedIndex == 3) { condition = Laptop.Condition.good; } if (comboBoxAddCondition.SelectedIndex == 4) { condition = Laptop.Condition.mint; } //get the make name = textAddBoxName.Text; //check the date and get the date try { //need to reverse the date to add it dateString = textBoxAddDateYYYY.Text + "/" + textBoxAddDateMM.Text + "/" + textBoxAddDateDD.Text; //converts text box value to price date = Convert.ToDateTime(dateString); } catch { //if the value is not a date MessageBox.Show("date must be a date", "Date Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //get the decimal -check its a decimal try { //converts text box value to price price = Convert.ToDecimal(textBoxAddOriginalPrice.Text); } catch { //if the value is not a decimal MessageBox.Show("price must be a decimal number", "Price Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //if the selected brand is Apple do use the AppleLaptop object if (comboBoxAddBrand.SelectedIndex == 0) { brand = "Apple"; AppleLaptop.SetName(name.PadRight(10, ' ')); AppleLaptop.SetBrand(brand); AppleLaptop.SetCondition(condition); AppleLaptop.SetOriginalPrice(price); AppleLaptop.SetReleaseDate(date); } //if the selected brand is HP use the HPLaptop object if (comboBoxAddBrand.SelectedIndex == 1) { brand = "HP"; HPLaptop.SetName(name.PadRight(10, ' ')); HPLaptop.SetBrand(brand); HPLaptop.SetCondition(condition); HPLaptop.SetOriginalPrice(price); HPLaptop.SetReleaseDate(date); } }