//Update the tableInGroupTable
        private void btnUpdateTable_Click(object sender, EventArgs e)
        {
            //New form to Add a tableInGroupTable
            frmTableInTableGroupUpdate thirdForm = new frmTableInTableGroupUpdate();

            // Edit, not Add
            thirdForm.IsAdd = false;

            //Choode the tableInGroupTable to be Updated
            thirdForm.tableInGroupTable = (TableInGroup)tableInGroupTables[tableInGroupDataGridView.CurrentCell.RowIndex]; // this is reference to the product to edit

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

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

            //Restaurant Tables
            thirdForm.restTables = restTables;

            //Restaurant tableIds
            thirdForm.restTableIds = restTableIds;

            //Available tables
            thirdForm.availableTables = availableTables;

            //tableInGroupTableIds
            thirdForm.tableInGroupTableIds = tableInGroupTableIds;

            DialogResult result = thirdForm.ShowDialog(); // show third as dialog (modal)


            if (result == DialogResult.OK)
            {
                MessageBox.Show("Successful Update ");
            }
        }
        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);
                    }
                }
            }
        }