private void GatewayReservation_Add(object sender, RoutedEventArgs e)
        {
            Oltp.PageRow currentPage = Page_dialog.Content as Oltp.PageRow;
            long         fromID      = 0;
            long         toID        = 0;

            if (!Int64.TryParse(_reservationFrom.Text, out fromID) || !Int64.TryParse(_reservationTo.Text, out toID))
            {
                // Validation
                MessageBoxError("Please enter 2 valid numbers.", null);
                _reservationFrom.SelectAll();
                _reservationFrom.Focus();
                return;
            }

            long fromIDTemp = fromID;

            fromID = fromID <= toID ? fromID : toID;
            toID   = toID >= fromIDTemp ? toID: fromIDTemp;

            // Get other accounts to check against
            string[] otherAccountStrings = Window.CurrentAccount.GatewayAccountScope != null?Window.CurrentAccount.GatewayAccountScope.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) : new string[0];

            int[] otherAccounts = Array.ConvertAll <string, int>(otherAccountStrings, new Converter <string, int>(delegate(string input)
            {
                int val;
                if (!Int32.TryParse(input, out val))
                {
                    val = -1;
                }
                return(val);
            }));


            // Check if any gateways are already in use or reserved
            int nonReservableCount = 0;

            using (OltpLogicClient proxy = new OltpLogicClient())
            {
                Oltp.GatewayReservationDataTable existingReservations =
                    proxy.Service.GatewayReservation_GetByOverlap(Window.CurrentAccount.ID, fromID, toID, otherAccounts);

                // Get local additions as well
                DataRow[] localReservations =
                    _reservationTable.Select(String.Format(
                                                 "({0} >= {2} AND {0} <= {3}) OR ({1} >= {2} AND {1} <= {3})",
                                                 _reservationTable.FromGatewayColumn.ColumnName,
                                                 _reservationTable.ToGatewayColumn.ColumnName,
                                                 fromID,
                                                 toID
                                                 ));

                if (existingReservations.Rows.Count > 0 || localReservations.Length > 0)
                {
                    Oltp.GatewayReservationRow existingReservation =
                        (existingReservations.Rows.Count > 0 ?  existingReservations.Rows[0] : localReservations[0]) as Oltp.GatewayReservationRow;

                    MessageBoxError(String.Format(
                                        "An overlapping range ({0} to {1}) has already been reserved for {2} page.",
                                        existingReservation.FromGateway, existingReservation.ToGateway, existingReservation.PageGK == currentPage.GK ? "this" : "another"
                                        ), null);
                    _reservationFrom.SelectAll();
                    _reservationFrom.Focus();
                    return;
                }

                nonReservableCount = proxy.Service.Gateway_CountByRange(Window.CurrentAccount.ID, fromID, toID, otherAccounts);
            }

            if (nonReservableCount > 0)
            {
                MessageBoxResult result = MessageBox.Show(
                    String.Format("{0} gateway{1} already in use within the specified range. Only available numbers within the range will be reserved.\n\nProceed?",
                                  nonReservableCount > toID - fromID ? "All" : nonReservableCount.ToString(),
                                  nonReservableCount > 1 ? "s are" : " is"
                                  ),
                    "Confirmation",
                    MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.OK
                    );

                if (result == MessageBoxResult.Cancel)
                {
                    _reservationFrom.SelectAll();
                    _reservationFrom.Focus();
                    return;
                }
            }

            Oltp.GatewayReservationRow reservation = _reservationTable.NewGatewayReservationRow();
            reservation.AccountID          = Window.CurrentAccount.ID;
            reservation.PageGK             = currentPage.GK;
            reservation.FromGateway        = fromID;
            reservation.ToGateway          = toID;
            reservation.ReservedByUserID   = Window.CurrentUser.ID;
            reservation.ReservedByUserName = Window.CurrentUser.Name;
            _reservationTable.AddGatewayReservationRow(reservation);
            _reservationItems.Add(reservation);
        }