// Method checks validation user input when requesting the ID to be modified private void ModifyCRMValidationInput() { bool IDisValid; do { Console.Write("Please enter the customer ID of the customer to be modified: "); id = Console.ReadLine(); // Here we use ID to modify as a means for the operator to input customer ID needed to be modified. IDisValid = int.TryParse(id, out IDtoMofify); if (IDtoMofify < 0) { Console.WriteLine("\nYou entered '{0}', which is not a positive integer", IDtoMofify); Console.WriteLine("Enter an ID which is a positive integer\n"); IDisValid = false; } else if (!int.TryParse(id, out IDtoMofify)) { Console.WriteLine("\nYou entered '{0}', which is not an integer", id); Console.WriteLine("Enter an ID which is an integer\n"); IDisValid = false; } else if (Fleet.IsRenting(IDtoMofify)) { Console.WriteLine("\nCould not modify customer ID '{0}' as this customer is currently renting a vehicle. Try another ID.\n", IDtoMofify); IDisValid = false; } } while (!IDisValid); }
private void custRemoveButton_Click(object sender, EventArgs e) { bool exists = false; if (int.TryParse(selectedIDTextBox.Text, out int ID)) { foreach (Customer cust in custmers.Customers) { if (cust.ID == ID) { exists = true; } } if (exists) { DialogResult dialogResult1 = MessageBox.Show(String.Format("Remove Customer {0}?", ID), "Remove Customer", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dialogResult1 == DialogResult.Yes) { if (fleet.IsRenting(ID)) { DialogResult dialogResult2 = MessageBox.Show(String.Format("Customer {0} is rentig!", ID), "Remove Customer", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { custmers.RemoveCustomer(GetCustomer(ID), fleet); SetUpGridCustmer(); } } } else { DialogResult dialogResult3 = MessageBox.Show(String.Format("ID Does not Exists!"), "Remove Customer", MessageBoxButtons.OK, MessageBoxIcon.Stop); } } else { DialogResult dialogResult = MessageBox.Show(String.Format("ID must be a number!"), "Remove Customer", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }