/// <summary> /// /// </summary> /// <param name="db"></param> /// <param name="roomNum"></param> public FormRoomDetails(Room target) { InitializeComponent(); Target = target; CheckedListBoxRoomResources.Items.Clear(); CheckedListBoxRoomResources.Items.Add("Gaming Software"); CheckedListBoxRoomResources.Items.Add("CAD Software"); CheckedListBoxRoomResources.Items.Add("Multi-Media Software"); CheckedListBoxRoomResources.Items.Add("Programming Software"); CheckedListBoxRoomResources.Items.Add("Smart Board"); CheckedListBoxRoomResources.Items.Add("Projector Pod"); // Check the appropriate items if (Target.Resource != null) { CheckedListBoxRoomResources.SetItemChecked(0, Target.Resource.Gaming); CheckedListBoxRoomResources.SetItemChecked(1, Target.Resource.Cad); CheckedListBoxRoomResources.SetItemChecked(2, Target.Resource.Multi); CheckedListBoxRoomResources.SetItemChecked(3, Target.Resource.Program); CheckedListBoxRoomResources.SetItemChecked(4, Target.Resource.Smartboard); CheckedListBoxRoomResources.SetItemChecked(5, Target.Resource.PodWithProj); CheckBoxRoomClassroom.Checked = Target.Resource.Classroom; CheckBoxRoomLab.Checked = Target.Resource.Lab; CheckBoxRoomInstructional.Checked = Target.Resource.Instruct; } }
/// <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); }