Exemple #1
0
        private void Button_Save_Click(object sender, RoutedEventArgs e)
        {
            string Error = null;

            // Validate
            int Temp;

            if (string.IsNullOrWhiteSpace(RoomName))
            {
                Error = "You must enter a room name.";
            }
            else if (!int.TryParse(StandardSeats, out Temp) || Temp <= 0)
            {
                Error = "Standard seats must be a non-negative integer";
            }
            else if (!int.TryParse(SpecialSeats, out Temp) || Temp < 0)
            {
                Error = "Special seats must be a non-negative integer";
            }
            else if (Temp != 0 && string.IsNullOrWhiteSpace(SpecialSeatType))
            {
                Error = "You must enter a special seat type (eg Workbench, Computer)";
            }
            else if (ComputerLines.Any(s => s.Contains(Room.ComputerNameSeperator)))
            {
                Error = "A computer name cannot contain '" + Room.ComputerNameSeperator + "'.";
            }
            else if (string.IsNullOrWhiteSpace(Department))
            {
                Error = "You must select a department.";
            }
            else
            {
                // Check for naming conflicts
                using (DataRepository Repo = new DataRepository())
                    if (Repo.Rooms.Any(r => r.Id != RoomId && r.RoomName == RoomName))
                    {
                        Error = "Another room with that name already exists.";
                    }
            }

            // Show an error message or close the window
            if (Error != null)
            {
                MessageBox.Show(Error, "Error", MessageBoxButton.OK);
            }
            else
            {
                DialogResult = true;
                Close();
            }
        }