public async void Edit() { TablePackagesController tpCtrl = new TablePackagesController(); VenuesController vCtrl = new VenuesController(); tablePackagesGUI = TablePackagesGUI.Instance; try { editedTablePackage = await tpCtrl.Get(tablePackagesGUI.idFromTable); // Finding venue from venueID on table and adding it to combobox. Venue venue = await vCtrl.Get(editedTablePackage.VenueId); // Creating a list because combobox demands it. var venuesList = new List <Venue>(); venuesList.Add(venue); lblTitle.Text = "Edit Table Package"; create = false; BtnSaveChanges.Text = "Save changes"; tbName.Text = editedTablePackage.Name; tbPrice.Text = "" + editedTablePackage.Price; cbVenue.DataSource = venuesList; } catch (Exception) { MessageBox.Show("No connection to service"); this.Visible = false; } // Resetting idFromTable to remove possibility to show other employees tables tablePackagesGUI.idFromTable = -1; }
private async void BtnSaveChanges_Click(object sender, EventArgs e) { TablePackagesController tpCtrl = new TablePackagesController(); DashboardGUI dGUI = DashboardGUI.Instance; if (TextBoxesHasValues()) { if (create) { try { Venue currVenue = (Venue)cbVenue.SelectedItem; TablePackage newTablePackage = new TablePackage { Name = tbName.Text, Price = Int32.Parse(tbPrice.Text), VenueId = currVenue.Id }; await tpCtrl.Create(newTablePackage); this.Visible = false; dGUI.AddTablePackageStats(); } catch (Exception) { MessageBox.Show("No connection to service"); } } else if (!create) { MessageBox.Show("Method not implemented"); this.Visible = false; /*int id = editedTablePackage.Id; * TablePackage updatedTablePackage = await tpCtrl.Get(editedTablePackage.Id); * await tpCtrl.Update(updatedTablePackage.Id, updatedTablePackage); * this.Visible = false;*/ } else { MessageBox.Show("Error...One or more fields are empty!");; } } }
private async void BtnDelete_Click(object sender, EventArgs e) { if (nameOfFormOpen.Equals("VenuesGUI") && VenuesGUI.Instance.idFromTable != -1) { try { VenuesController vCtrl = new VenuesController(); VenuesGUI.Instance.UseWaitCursor = true; await vCtrl.Delete(VenuesGUI.Instance.idFromTable); VenuesGUI.Instance.UseWaitCursor = false; } catch (Exception) { MessageBox.Show("Error...occured"); VenuesGUI.Instance.UseWaitCursor = false; } } else if (nameOfFormOpen.Equals("TablesGUI") && TablesGUI.Instance.idFromTable != -1) { try { TablesController tCtrl = new TablesController(); TablesGUI.Instance.UseWaitCursor = true; await tCtrl.Delete(TablesGUI.Instance.idFromTable); TablesGUI.Instance.UseWaitCursor = false; } catch (Exception) { MessageBox.Show("Error...occured"); TablesGUI.Instance.UseWaitCursor = false; } } else if (nameOfFormOpen.Equals("TablePackagesGUI") && TablePackagesGUI.Instance.idFromTable != -1) { try { TablePackagesController tpCtrl = new TablePackagesController(); TablePackagesGUI.Instance.UseWaitCursor = true; await tpCtrl.Delete(TablePackagesGUI.Instance.idFromTable); TablePackagesGUI.Instance.UseWaitCursor = false; } catch (Exception) { MessageBox.Show("Error...occured"); TablePackagesGUI.Instance.UseWaitCursor = false; } } else if (nameOfFormOpen.Equals("EmployeesGUI") && EmployeesGUI.Instance.IdFromTable != -1) { try { EmployeesController eCtrl = new EmployeesController(); EmployeesGUI.Instance.UseWaitCursor = true; await eCtrl.Delete(EmployeesGUI.Instance.IdFromTable); EmployeesGUI.Instance.UseWaitCursor = false; } catch (Exception) { MessageBox.Show("Error...occured"); EmployeesGUI.Instance.UseWaitCursor = false; } } else if (nameOfFormOpen.Equals("ReservationsGUI") && ReservationsGUI.Instance.IdFromTable != -1) { try { ReservationsController rCtrl = new ReservationsController(); ReservationsGUI.Instance.UseWaitCursor = true; await rCtrl.Delete(ReservationsGUI.Instance.IdFromTable); ReservationsGUI.Instance.UseWaitCursor = false; } catch (Exception) { MessageBox.Show("Error...occured"); EmployeesGUI.Instance.UseWaitCursor = false; } } else { MessageBox.Show("Please select a " + newTitle + " from the list"); } }