private void RoomForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dgvRoom[0, 0].Selected = true;

            // ----------------------------------------------------------------------------------------------
            //
            var db = new LINQDataContext();

            for (int rowCounter = 0; rowCounter < dgvRoom.RowCount - 1; rowCounter++)
            {
                try
                {
                    //
                    // search dgvRoom.rows in db.Room
                    //
                    int ID_No = 0;
                    int.TryParse(dgvRoom[0, rowCounter].Value.ToString(), out ID_No);
                    // Define the query expression.
                    IEnumerable <int> query =
                        from room in db.Rooms
                        where room.Room_ID == ID_No
                        select room.Room_ID;

                    if (query.ToArray().Length > 0) // EDIT
                    {
                        int size = 0;
                        db.RoomEdit(ID_No,
                                    (dgvRoom[1, rowCounter].Value != null) ? (string)dgvRoom[1, rowCounter].Value.ToString() : "",
                                    (dgvRoom[2, rowCounter].Value != null) ? dgvRoom[2, rowCounter].Value.ToString() : "",
                                    (dgvRoom[3, rowCounter].Value != null) ? (int.TryParse(dgvRoom[3, rowCounter].Value.ToString(), out size)) ? size : 0 : 0);
                    }
                    else
                    {
                        int size = 0;
                        db.RoomSave(ID_No,
                                    (dgvRoom[1, rowCounter].Value != null) ? (string)dgvRoom[1, rowCounter].Value.ToString() : "",
                                    (dgvRoom[2, rowCounter].Value != null) ? dgvRoom[2, rowCounter].Value.ToString() : "",
                                    (dgvRoom[3, rowCounter].Value != null) ? (int.TryParse(dgvRoom[3, rowCounter].Value.ToString(), out size)) ? size : 0 : 0);
                    }
                }
                catch { }
            }
            db.Dispose();
        }
        private void RoomForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            dgvRoom[0, 0].Selected = true;

            // ----------------------------------------------------------------------------------------------
            //
            var db = new LINQDataContext();

            for (int rowCounter = 0; rowCounter < dgvRoom.RowCount - 1; rowCounter++)
            {
                try
                {
                    //
                    // search dgvRoom.rows in db.Room
                    //
                    int ID_No = 0;
                    int.TryParse(dgvRoom[0, rowCounter].Value.ToString(), out ID_No);
                    // Define the query expression.
                    IEnumerable<int> query =
                        from room in db.Rooms
                        where room.Room_ID == ID_No
                        select room.Room_ID;

                    if (query.ToArray().Length > 0) // EDIT
                    {
                        int size = 0;
                        db.RoomEdit(ID_No,
                            (dgvRoom[1, rowCounter].Value != null) ? (string)dgvRoom[1, rowCounter].Value.ToString() : "",
                            (dgvRoom[2, rowCounter].Value != null) ? dgvRoom[2, rowCounter].Value.ToString() : "",
                            (dgvRoom[3, rowCounter].Value != null) ? (int.TryParse(dgvRoom[3, rowCounter].Value.ToString(), out size)) ? size : 0 : 0);
                    }
                    else
                    {
                        int size = 0;
                        db.RoomSave(ID_No,
                            (dgvRoom[1, rowCounter].Value != null) ? (string)dgvRoom[1, rowCounter].Value.ToString() : "",
                            (dgvRoom[2, rowCounter].Value != null) ? dgvRoom[2, rowCounter].Value.ToString() : "",
                            (dgvRoom[3, rowCounter].Value != null) ? (int.TryParse(dgvRoom[3, rowCounter].Value.ToString(), out size)) ? size : 0 : 0);
                    }
                }
                catch { }
            }
            db.Dispose();
        }