/// <summary> /// Called when the user presses the save button to save modified information to the database. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonSaveRoom_Click(object sender, EventArgs e) { Close(); Resource resource = new Resource() { Program = CheckedListBoxRoomResources.CheckedItems.Contains("Programming Software"), Cad = CheckedListBoxRoomResources.CheckedItems.Contains("CAD Software"), Multi = CheckedListBoxRoomResources.CheckedItems.Contains("Multi-Media Software"), Gaming = CheckedListBoxRoomResources.CheckedItems.Contains("Gaming Software"), Smartboard = CheckedListBoxRoomResources.CheckedItems.Contains("Smart Board"), PodWithProj = CheckedListBoxRoomResources.CheckedItems.Contains("Projector Pod"), Classroom = CheckBoxRoomClassroom.Checked, Instruct = CheckBoxRoomInstructional.Checked, Lab = CheckBoxRoomLab.Checked, }; // Check to see if we have any resources with these specifications foreach (Resource existing in Program.Database.Resources) if (existing.Program == resource.Program && existing.Cad == resource.Cad && existing.Multi == resource.Multi && existing.Gaming == resource.Gaming && existing.Smartboard == resource.Smartboard && existing.PodWithProj == resource.PodWithProj && existing.Classroom == resource.Classroom && existing.Instruct == resource.Instruct && existing.Lab == resource.Lab) { resource = existing; break; } Target.ResourceID = resource.ResourceID; if (Program.Database.Resources.Find(resource.ResourceID) == null) Program.Database.Resources.Add(resource); Program.Database.SaveChanges(); }
/// <summary> /// Called when the user clicks the create button on the room management tab. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonCreateNewRoom_Click(object sender, EventArgs e) { TextBoxNewRoomNumber.Text = TextBoxNewRoomNumber.Text.Trim(); string roomNumber = TextBoxNewRoomNumber.Text; if (roomNumber.Length == 0) { MessageBox.Show("Please assign the room a room number.", "Error"); return; } // How many people can fit in here? int headCount = (int)NumericUpDownNewRoomCapacity.Value; if (headCount == 0) { MessageBox.Show("Can't have a room with support for zero people.", "Error"); return; } // Create a resource entry Resource resource = new Resource() { Program = CheckedListBoxNewRoomResources.CheckedItems.Contains("Programming Software"), Cad = CheckedListBoxNewRoomResources.CheckedItems.Contains("CAD Software"), Multi = CheckedListBoxNewRoomResources.CheckedItems.Contains("Multi-Media Software"), Gaming = CheckedListBoxNewRoomResources.CheckedItems.Contains("Gaming Software"), Smartboard = CheckedListBoxNewRoomResources.CheckedItems.Contains("Smart Board"), PodWithProj = CheckedListBoxNewRoomResources.CheckedItems.Contains("Projector Pod"), Classroom = CheckBoxNewRoomClassroom.Checked, Instruct = CheckBoxNewRoomInstructional.Checked, Lab = CheckBoxNewRoomLab.Checked, }; // See if there's a resource with these specifications already foreach (Resource existing in Program.Database.Resources) if (existing.Program == resource.Program && existing.Cad == resource.Cad && existing.Multi == resource.Multi && existing.Gaming == resource.Gaming && existing.Smartboard == resource.Smartboard && existing.PodWithProj == resource.PodWithProj && existing.Classroom == resource.Classroom && existing.Instruct == resource.Instruct && existing.Lab == resource.Lab) { resource = existing; break; } // Attempt the database creation Room newRoom = new Room() { RoomID = roomNumber, ResourceID = resource.ResourceID, Capacity = (int)NumericUpDownNewRoomCapacity.Value, }; Program.Database.Resources.Add(resource); Program.Database.Rooms.Add(newRoom); Program.Database.SaveChanges(); MessageBox.Show("Successfully created the new room.", "Success"); // Clear the existing information ButtonClearNewRoom_Click(sender, e); }