private void btnDeleteTable_Click(object sender, EventArgs e)
        {
            //Error Message
            string message;
            //Select tableInGroupTable to be deleted
            TableInGroup tableInGroupTableDel = (TableInGroup)tableInGroupTables[tableInGroupDataGridView.CurrentCell.RowIndex];

            //Verify if table is in use
            if (tableInGroupInUse)
            {
                //if tableGroup is in use, it cannot be deleted
                message = "Table Group ID " + Convert.ToString(tableGroup.TableGroupID) + " Name: " + tableGroup.TableGroupName + "cannot be deleted beacuse it is in use";
                MessageBox.Show(message, "Delete is not possible");
            }
            else
            {
                //Confirm Delete
                message = "Are you sure you want to delete Table ID"
                          + tableInGroupTableDel.TableID + " from table Group?";
                DialogResult button =
                    MessageBox.Show(message, "Confirm Delete",
                                    MessageBoxButtons.YesNo);
                if (button == DialogResult.Yes)
                {
                    //Update local lists
                    local_tableInGroupTables.Remove(tableInGroupTableDel);
                    local_tableInGroupTableIds.Remove(tableInGroupTableDel.TableID);
                    //Find index
                    int indexTIG = tableInGroupTableIds.FindIndex(j => j == tableInGroupTableDel.TableID);
                    if (indexTIG >= 0)
                    {
                        //Update the tableStatus if the table is in tableInGroupTableIds
                        tableInGroupTableStatus[indexTIG] = -1;
                    }

                    //if TableId is active
                    int indexTIG1 = restTables.FindIndex(j => j.TableID == tableInGroupTableDel.TableID);
                    if (restTables[indexTIG1].TableActive == true)
                    {
                        //Update availableTables
                        availableTables.Add(tableInGroupTableDel.TableID);
                    }

                    //Update users interface
                    source.DataSource = local_tableInGroupTables;
                    source.ResetBindings(false);
                    if (local_tableInGroupTables.Count > 0)
                    {
                        tableInGroupDataGridView.Visible = true;
                        btnUpdateTable.Enabled           = true;
                        if (tableInGroupInUse == false)
                        {
                            btnDeleteTable.Enabled = true;
                            btnAddTable.Enabled    = true;
                        }
                    }
                    else
                    {
                        btnDeleteTable.Enabled           = false;
                        btnUpdateTable.Enabled           = false;
                        btnAddTable.Enabled              = true;
                        tableInGroupDataGridView.Visible = false;
                    }
                    MessageBox.Show("Table Group Deleted ");
                }
            }
        }
        private void btnAccept_Click(object sender, EventArgs e)
        {
            //Validate the Date
            if (IsValidData()) // validation for both Add  and Edit
            {
                //ADD
                if (IsAdd)
                {
                    //set the attributes of the new tableInGroupTable
                    tableInGroupTable = new TableInGroup();
                    tableInGroupTable.TableGroupID = tableGroupId;

                    tableInGroupTable.TableID            = Convert.ToInt32(tableIDTextBox.Text);
                    tableInGroupTable.MaxTableSeatNumber = Convert.ToInt32(maxTableSeatNumberTextBox.Text);

                    if (tablePosXTextBox.Text == "")
                    {
                        tableInGroupTable.TablePosX = null;
                    }
                    else
                    {
                        tableInGroupTable.TablePosX = Convert.ToDecimal(tablePosXTextBox.Text);
                    }
                    if (tablePosYTextBox.Text == "")
                    {
                        tableInGroupTable.TablePosY = null;
                    }
                    else
                    {
                        tableInGroupTable.TablePosY = Convert.ToDecimal(tablePosYTextBox.Text);
                    }

                    if (restaurantAreaTextBox.Text == "")
                    {
                        tableInGroupTable.RestaurantArea = null;
                    }
                    else
                    {
                        tableInGroupTable.RestaurantArea = restaurantAreaTextBox.Text;
                    }

                    if (restaurantZoneTextBox.Text == "")
                    {
                        tableInGroupTable.RestaurantZone = null;
                    }
                    else
                    {
                        tableInGroupTable.RestaurantZone = restaurantZoneTextBox.Text;
                    }

                    if (restaurantFloorTextBox.Text == "")
                    {
                        tableInGroupTable.RestaurantFloor = null;
                    }
                    else
                    {
                        tableInGroupTable.RestaurantFloor = Convert.ToInt32(restaurantFloorTextBox.Text);
                    }

                    //Confirmation Dialog

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else // edit
                {
                    //update the attributes of the new tableInGroupTable
                    tableInGroupTable.MaxTableSeatNumber = Convert.ToInt32(maxTableSeatNumberTextBox.Text);
                    if (tablePosXTextBox.Text == "")
                    {
                        tableInGroupTable.TablePosX = null;
                    }
                    else
                    {
                        tableInGroupTable.TablePosX = Convert.ToDecimal(tablePosXTextBox.Text);
                    }
                    if (tablePosYTextBox.Text == "")
                    {
                        tableInGroupTable.TablePosY = null;
                    }
                    else
                    {
                        tableInGroupTable.TablePosY = Convert.ToDecimal(tablePosYTextBox.Text);
                    }
                    if (restaurantAreaTextBox.Text == "")
                    {
                        tableInGroupTable.RestaurantArea = null;
                    }
                    else
                    {
                        tableInGroupTable.RestaurantArea = restaurantAreaTextBox.Text;
                    }

                    if (restaurantZoneTextBox.Text == "")
                    {
                        tableInGroupTable.RestaurantZone = null;
                    }
                    else
                    {
                        tableInGroupTable.RestaurantZone = restaurantZoneTextBox.Text;
                    }

                    if (restaurantFloorTextBox.Text == "")
                    {
                        tableInGroupTable.RestaurantFloor = null;
                    }
                    else
                    {
                        tableInGroupTable.RestaurantFloor = Convert.ToInt32(restaurantFloorTextBox.Text);
                    }

                    //Confirmation Dialog
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
        }
        private void btnAddTable_Click(object sender, EventArgs e)
        {
            //Set  tableGroupId = -1, when new tableGroup
            if (tableGroup == null)
            {
                tableGroupId = -1;
            }
            else
            {
                tableGroupId = tableGroup.TableGroupID;
            }

            frmTableInTableGroupUpdate newTableForm = new frmTableInTableGroupUpdate();

            //ADD, not Edit
            newTableForm.IsAdd = true;

            //Identify the restaurant Id and pass to the other form
            newTableForm.restaurantId = restaurantId;

            //Identify the layout Id and pass to the other form
            newTableForm.layoutId = layoutId;

            //Restaurant Tables
            newTableForm.restTables = restTables;

            //Restaurant tableIds
            newTableForm.restTableIds = restTableIds;

            //Available tables
            newTableForm.availableTables = availableTables;

            //tableGroupId
            newTableForm.tableGroupId = tableGroupId;

            //tableInGroupTableIds
            newTableForm.tableInGroupTableIds = tableInGroupTableIds;

            //New tableInGroupTable
            TableInGroup tableInGroupTable = newTableForm.GetNewTableInGroup();

            if (tableInGroupTable != null)
            {
                if (tableGroup != null)
                {
                    tableInGroupTable.TableGroupID = tableGroup.TableGroupID;

                    //Find index
                    int indexTIG = tableInGroupTableIds.FindIndex(j => j == tableInGroupTable.TableID);
                    if (indexTIG >= 0)
                    {
                        //Update the tableStatus if the table is in tableInGroupTableIds
                        tableInGroupTableStatus[indexTIG] = 1;
                    }
                    else
                    {
                        //Add tableInTableGroupTable to  tableInTableGroupTable and set status, if not
                        tableInGroupTables.Add(tableInGroupTable);
                        tableInGroupTableIds.Add(tableInGroupTable.TableID);
                        tableInGroupTableStatus.Add(1);
                    }
                    //Update local lists
                    local_tableInGroupTables.Add(tableInGroupTable);
                    local_tableInGroupTableIds.Add(tableInGroupTable.TableID);


                    //Update availableTables
                    availableTables.Remove(tableInGroupTable.TableID);

                    //Update user interface
                    if (local_tableInGroupTables.Count == 1)
                    {
                        source.DataSource = local_tableInGroupTables;
                        tableInGroupDataGridView.DataSource = source;
                        tableInGroupDataGridView.Visible    = true;
                        btnDeleteTable.Enabled = true;
                        btnUpdateTable.Enabled = true;
                    }

                    MessageBox.Show("New Table Added");
                    source.ResetBindings(false);
                    tableInGroupDataGridView.Visible = true;
                    //btnDeleteTable.Enabled = true;
                    btnAddTable.Enabled = true;
                }
                else
                {
                    //Inititialize tables
                    if (tableInGroupTables == null)
                    {
                        tableInGroupTables       = new List <TableInGroup>();
                        local_tableInGroupTables = new List <TableInGroup>();
                    }
                    if (tableInGroupTableIds == null)
                    {
                        tableInGroupTableIds    = new List <int>();
                        tableInGroupTableStatus = new List <int>();
                    }
                    //Find index
                    int indexTIG = tableInGroupTableIds.FindIndex(j => j == tableInGroupTable.TableID);
                    if (indexTIG >= 0)
                    {
                        //Update the tableStatus if the table is in tableInGroupTableIds
                        tableInGroupTableStatus[indexTIG] = 1;
                    }
                    else
                    {
                        //Add tableInTableGroupTable to  tableInTableGroupTable and set status, if not
                        tableInGroupTables.Add(tableInGroupTable);
                        tableInGroupTableIds.Add(tableInGroupTable.TableID);
                        tableInGroupTableStatus.Add(1);
                    }
                    //Update local lists
                    local_tableInGroupTables.Add(tableInGroupTable);
                    local_tableInGroupTableIds.Add(tableInGroupTable.TableID);
                    //Update availableTables
                    availableTables.Remove(tableInGroupTable.TableID);
                    //Update user interface
                    if (local_tableInGroupTables.Count == 1)
                    {
                        source.DataSource = local_tableInGroupTables;
                        tableInGroupDataGridView.DataSource = source;
                        tableInGroupDataGridView.Visible    = true;
                        btnUpdateTable.Enabled = true;
                        if (tableInGroupInUse == false)
                        {
                            btnDeleteTable.Enabled = true;
                            btnAddTable.Enabled    = true;
                        }
                    }
                    else
                    {
                        source.ResetBindings(false);
                    }
                }
            }
        }