Exemplo n.º 1
0
        private void OpenCloseArea(Domain.States state)
        {
            try
            {
                //Get the selected Area object
                var a = dgvArea.SelectedRows[0].Cells[2].Value as IArea;
                //Get the row index of the selected Area object
                int selectedRowIndex = dgvArea.SelectedRows[0].Index;
                switch (state)
                {
                case States.Open:
                    (Controller as AreaManagementViewController).OpenArea(a);
                    break;

                case States.Closed:
                    //Update the table status to closed in the Domain/database
                    (Controller as AreaManagementViewController).CloseArea(a);
                    break;
                }
                UpdateView();
                //Clears any selected rows
                dgvArea.ClearSelection();
                //Reselect the row associated with the table being closed
                dgvArea.Rows[selectedRowIndex].Selected = true;
            }
            catch (BusinessRuleException ex)
            {
                lblError.Text = ex.Message;
            }
            catch (Exception ex)
            {
                lblError.Text = ex.Message;
            }
        }
        public void OpenCloseTable(Domain.States state)
        {
            try
            {
                if (dgvTables.SelectedRows.Count < 1)
                {
                    lblError.Text = "No table selected for the chosen operation, Please select a table first";
                    return;
                }

                //Get the selected table object
                var table = dgvTables.SelectedRows[0].Cells[3].Value as ITable;
                //Get the row index of the selected table object
                int selectedRowIndex = dgvTables.SelectedRows[0].Index;
                if (table.State == States.Occupied)
                {
                    lblError.Text = "Cannot close table as it is reserved";
                    return;
                }
                switch (state)
                {
                case States.Open:
                    (Controller as TableManagementViewController).OpenTable(table);
                    break;

                case States.Closed:
                    //Update the table status to closed in the Domain/database
                    (Controller as TableManagementViewController).CloseTable(table);
                    break;
                }
                UpdateView();
                //Clears any selected rows
                dgvTables.ClearSelection();
                //Reselect the row associated with the table being closed
                dgvTables.Rows[selectedRowIndex].Selected = true;
            }
            catch (BusinessRuleException ex)
            {
                lblError.Text    = ex.Message;
                lblError.Visible = true;
            }
            catch (Exception ex)
            {
                lblError.Text    = ex.Message;
                lblError.Visible = true;
            }
        }
        private Color LookupColor(Domain.States state)
        {
            Color color;

            switch (state)
            {
            case States.Open:
                color = Color.Green;
                break;

            case States.Occupied:
                color = Color.Red;
                break;

            case States.Closed:
                color = Color.Black;
                break;

            default:
                color = Color.Wheat;
                break;
            }
            return(color);
        }