private void btnClearTable_Click(object sender, EventArgs e) { //clear table from assigned table list foreach (var item in lstAssignments.SelectedItems) { ServerDA.FreeTable(((DisplayData)item).Value); TableDA.UpdateTableState(((DisplayData)item).Value, TableState.Bussable.ToString()); } pnlRoom.Controls.Clear(); DisplayAssignments(); DisplayAvailableTables(); LoadTables(); LoadBarTable(); LoadBarSeats(); btnClearTable.Visible = false; lstAssignments.ClearSelected(); }
private void btnSeatClick(object sender, EventArgs e) { Button oButton = sender as Button; string sTableNumber = oButton.Tag.ToString(); string sErrorMess = ""; bool bIsValid = true; bool bReservationSelected = false; //get table by id to check/update state Table oSpecificTable = TableDA.GetTableByID(sTableNumber); int nSectionNumber = SectionDA.GetAssignedSection(sTableNumber); if (rdoAssignTable.Checked) { //makes sure a server is selected in the list box if (!(lstServers.SelectedIndex == -1)) { try { Convert.ToInt32(cboSeats.SelectedItem); } catch (Exception) { bIsValid = false; sErrorMess += "\nNumber of Seats is required and must be a number"; } if (bIsValid) { if (!(lstReservations.SelectedIndex == -1)) { bReservationSelected = true; int groupSize = ReservationDA.GetGroupSize((lstReservations.SelectedItem as DisplayData).Value); cboSeats.SelectedItem = groupSize.ToString(); } if (cboSeats.SelectedItem == null) { bIsValid = false; sErrorMess += "Number of seats must be provided"; } if (oSpecificTable.NumberOfSeats >= Convert.ToInt16(cboSeats.SelectedItem) && bIsValid) { //Number of seats fit the amount to be seated if (oSpecificTable.TableState.ToLower() == TableState.Occupied.ToString().ToLower()) { bIsValid = false; sErrorMess = "Error: Table is currently busy"; } else if (oSpecificTable.TableState.ToLower() == TableState.Bussable.ToString().ToLower()) { bIsValid = false; sErrorMess = "Error: Table is not clean"; } } else { bIsValid = false; sErrorMess = "Error: That table cannot seat that many customers"; } } } else { bIsValid = false; sErrorMess = "Error: You have to select a server"; } } else if (rdoClearTable.Checked) { if (oSpecificTable.TableState.ToLower() == TableState.Empty.ToString().ToLower()) { bIsValid = false; sErrorMess = "Error: Table has nothing to clear"; } else if (oSpecificTable.TableState.ToLower() == TableState.Bussable.ToString().ToLower()) { bIsValid = false; sErrorMess = "Error: Table is not clean"; } } else if (rdoBusTable.Checked) { if (oSpecificTable.TableState.ToLower() == TableState.Empty.ToString().ToLower()) { bIsValid = false; sErrorMess = "Error: Table is already clean"; } else if (oSpecificTable.TableState.ToLower() == TableState.Occupied.ToString().ToLower()) { bIsValid = false; sErrorMess = "Error: Table is currently busy"; } } if (bIsValid) { string sUpdatedState = oSpecificTable.TableState; if (sUpdatedState.ToLower() == TableState.Empty.ToString().ToLower()) { //assign server here string sServerID = (lstServers.SelectedItem as DisplayData).Value; ServerDA.AssignServerToTable(sTableNumber, sServerID, nSectionNumber.ToString()); if (bReservationSelected) { ReservationDA.DeleteReservation((lstReservations.SelectedItem as DisplayData).Value); lstReservations.ClearSelected(); } sUpdatedState = TableState.Occupied.ToString(); } else if (sUpdatedState.ToLower() == TableState.Occupied.ToString().ToLower()) { ServerDA.FreeTable(sTableNumber); DisplayAssignments(); sUpdatedState = TableState.Bussable.ToString(); } else if (sUpdatedState.ToLower() == TableState.Bussable.ToString().ToLower()) { sUpdatedState = TableState.Empty.ToString(); } //Updating Table State TableDA.UpdateTableState(oSpecificTable.TableNumber.ToString(), sUpdatedState); pnlRoom.Controls.Clear(); LoadTables(); LoadBarTable(); LoadBarSeats(); DisplayReservationList(); DisplayAssignments(); DisplayAvailableTables(); if (btnUse.Text == "Cancel") { lstReservations.Enabled = false; btnUse.Text = "Use Reservation"; } } else { MessageBox.Show(sErrorMess, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }