private void btnAddCarpet_Click(object sender, EventArgs e) { double price; //Check if textbox is empty or has a white spaces if (string.IsNullOrWhiteSpace(txtName.Text)) { //Display Error message MessageBox.Show("Carpet Name empty! Please re-enter"); //Clear textbox txtName.Clear(); //Focus on text box txtName.Focus(); } else if (string.IsNullOrWhiteSpace(txtQuality.Text)) { //Display Error message MessageBox.Show("Carpet Quality empty! Please re-enter"); //Clear textbox txtQuality.Clear(); //Focus on text box txtQuality.Focus(); } else if (double.TryParse(txtPrice.Text, out price) == false) { //Display Error message MessageBox.Show("Carpet Price invalid! Please re-enter"); //Clear textbox txtPrice.Clear(); //Focus on text box txtPrice.Focus(); } else { //All data validation has passed - add carpet to the list //Create temp carpet object Carpet myCarpet = new Carpet(); //Add information from the form to the carpet object myCarpet.Name = txtName.Text; myCarpet.Quality = txtQuality.Text; myCarpet.Price = price; //Add object to list of carpets - arraylist in Main form FrmMain.carpets.Add(myCarpet); //let the user know carpet is added MessageBox.Show("Carpet Added!"); //Clear textboxes to allow user to add a new carpet txtName.Clear(); txtPrice.Clear(); txtQuality.Clear(); //Set focus on name textbox txtName.Focus(); } }
private void btnDisplayCost_Click(object sender, EventArgs e) { btnBack.Visible = true; Carpet selectedCt = new Carpet(); Room selectedRm = new Room(); int carpetNum, roomNum; double totalCost; //Figure out which carpet and room is selected carpetNum = cmbCarpet.SelectedIndex; roomNum = cmbRoom.SelectedIndex; //Find the correct carpet and room in thier respective lists selectedCt = (Carpet)FrmMain.carpets[carpetNum]; selectedRm = (Room)FrmMain.rooms[roomNum]; totalCost = selectedRm.CalculateArea() * selectedCt.Price; //Display out in rich textbox rtbOutput.Text = selectedCt.ToString() + "\n" + selectedRm.ToString() + "\nTotal Cost: " + totalCost.ToString("C"); }