Exemple #1
0
        public override Room GetItem()
        {
            Room New = new Room();

            try
            {
                // Fill out all the details
                New.RoomName        = RoomName;
                New.StandardSeats   = Convert.ToInt32(StandardSeats);
                New.SpecialSeatType = SpecialSeatType;
                New.SpecialSeats    = Convert.ToInt32(SpecialSeats);
                New.Id            = RoomId;
                New.Bookings      = Bookings;
                New.ComputerNames = ComputerLines.ToList();

                // Select the correct department
                using (DataRepository Repo = new DataRepository())
                    New.Department = Repo.Departments.Single(d => d.Name == Department);
            }
            catch
            {
                return(null);
            }

            return(New);
        }
Exemple #2
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();
            }
        }