/// <summary>
        /// Selects the order with the specified order number.
        /// </summary>
        /// <param name="orderNumber">Number of the order to select.</param>
        public void SelectOrder(string orderNumber)
        {
            _selectedOrder = null;

            foreach (var order in _orderList)
            {
                if (order.OrderNumber == orderNumber)
                {
                    _selectedOrder = order;
                    break;
                }
            }

            UpdateOrderModel();

            _orderBoxModel.Clear();
            if (_orderBoxes.Where(x => x.Key.Equals(orderNumber)).FirstOrDefault().Value != null)
            {
                foreach (var box in _orderBoxes.Where(x => x.Key.Equals(orderNumber)).FirstOrDefault().Value)
                {
                    var row = _orderBoxModel.NewRow();
                    row[0] = orderNumber;
                    row[1] = box;
                    _orderBoxModel.Rows.Add(row);
                }
            }
        }
        /// <summary>
        /// Updates the order model itself.
        /// </summary>
        private void UpdateModel()
        {
            _orderModel.Rows.Clear();

            foreach (var order in _orderList)
            {
                DataRow row = _orderModel.NewRow();
                row[0] = order.OrderNumber;
                row[1] = order.Priority.ToString();
                row[2] = order.OutputDestination;
                row[3] = order.OutputPoint;
                row[4] = order.BoxNumber;
                row[5] = _orderStates[order].ToString();
                _orderModel.Rows.Add(row);
            }

            if ((_selectedOrder != null) && (_orderList.Contains(_selectedOrder) == false))
            {
                _selectedOrder = null;
            }

            if ((_selectedOrder == null) && (_orderList.Count > 0))
            {
                _selectedOrder = _orderList[0];
            }

            UpdateOrderModel();
        }
        /// <summary>
        /// Adds the specified order to the data model.
        /// </summary>
        /// <param name="order">The order to add.</param>
        public void AddOrder(IOutputProcess order)
        {
            if (order == null)
            {
                return;
            }

            foreach (var existingOrder in _orderList)
            {
                if (existingOrder.OrderNumber == order.OrderNumber)
                {
                    existingOrder.Finished -= OnOrderFinished;
                    order.BoxReleased      -= OnBoxReleased;
                    _orderList.Remove(existingOrder);
                    break;
                }
            }

            order.Finished    += OnOrderFinished;
            order.BoxReleased += OnBoxReleased;
            _orderList.Add(order);
            _orderStates[order] = order.State;

            UpdateModel();
        }
 /// <summary>
 /// Handles the TextChanged event of the txtBoxNumber control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void txtBoxNumber_TextChanged(object sender, EventArgs e)
 {
     try
     {
         _order = CreateNewOrder(true);
     }
     catch (Exception)
     {
     }
 }
 /// <summary>
 /// Handles the ValueChanged event of the numPoint control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void numPoint_ValueChanged(object sender, EventArgs e)
 {
     try
     {
         _order = CreateNewOrder(true);
     }
     catch (Exception)
     {
     }
 }
 /// <summary>
 /// Handles the SelectedIndexChanged event of the cmbPriority control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void cmbPriority_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         _order = CreateNewOrder(true);
     }
     catch (Exception)
     {
     }
 }
        /// <summary>
        /// Handles the Click event of the btnAddItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void btnAddItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (_order == null)
                {
                    _order = CreateNewOrder(false);
                }

                var addOrderItem = new FOrderItem(_order, _articleList);
                addOrderItem.ShowDialog(this);
                lblNumItems.Text = _order.Criteria.Length.ToString();
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// Handles the TextChanged event of the txtOrderNumber control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void txtOrderNumber_TextChanged(object sender, EventArgs e)
        {
            btnOK.Enabled = (string.IsNullOrWhiteSpace(txtOrderNumber.Text) == false);

            if (btnOK.Enabled == false)
            {
                return;
            }

            try
            {
                _order = CreateNewOrder(true);
            }
            catch (Exception)
            {
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="FOrderItem" /> class.
        /// </summary>
        /// <param name="outputProcess">The output process reference to use.</param>
        /// <param name="articleList">The article list to use.</param>
        public FOrderItem(IOutputProcess outputProcess, string[] articleList)
        {
            InitializeComponent();

            if (outputProcess == null)
            {
                throw new ArgumentException("Invalid outputProcess specified.");
            }

            _outputProcess = outputProcess;

            if (articleList != null)
            {
                for (int i = 0; i < articleList.Length; ++i)
                {
                    cmbArticleId.Items.Add(articleList[i]);
                }
            }
        }
 /// <summary>
 /// Clears the current order selection.
 /// </summary>
 public void ClearOrderSelection()
 {
     _selectedOrder = null;
     UpdateOrderModel();
 }
 /// <summary>
 /// Handles the Click event of the btnCancel control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
 private void btnCancel_Click(object sender, EventArgs e)
 {
     _order            = null;
     this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
 }