//method that validates the user input private bool ValidateInputs() { //if number feild is empty if (string.IsNullOrEmpty(TableNumber.Text)) { //message box display the error MessageBox.Show("Table number Empty! Please enter again!"); TableNumber.Focus(); return(false); } //check for numeric number try { int num = Convert.ToInt32(TableNumber.Text); } catch (Exception ex) { //message box display the error MessageBox.Show("Wrong Input! Number must be a numeric value."); TableNumber.SelectAll(); return(false); } //check if waiter name is empty if (string.IsNullOrEmpty(WaiterName.Text)) { //message box display the error MessageBox.Show("Waiter name is empty! Please enter waiter's name."); WaiterName.Focus(); return(false); } return(true); }
//method that perform ok button function from main window private void okButton_Click(object sender, RoutedEventArgs e) { //check for valid input from user if (ValidateInputs()) { //create a new list for bills TableBill bill = new TableBill(); bill.Table_Number = Convert.ToInt32(TableNumber.Text); bill.Waiter_Name = WaiterName.Text; bills.Add(bill); MenuWindow menuWindow = new MenuWindow(); menuWindow.Tag = bill; this.Hide(); menuWindow.ShowDialog(); // Clear input fields TableNumber.Clear(); WaiterName.Clear(); TableNumber.Focus(); //main windnow this.ShowDialog(); } }