Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Creates a form to check if the user is sure they want to delete data or not
            using (var form = new DeleteValidate())
            {
                var result = form.ShowDialog();
                //If the user clicks 'Yes'
                if (result == DialogResult.Yes)
                {
                    //Make the form hide
                    this.Hide();
                    BookingDBAccess bdba = new BookingDBAccess(db);

                    //If the user hasn't selected a row
                    if (Results.SelectedRows.Count == 0)
                    {
                        MessageBox.Show("No Row Selected Was Selected", "Error");
                        this.Hide();
                        new MainApp(db).Show();
                    }
                    //If there's more than one row selected, show an error message
                    else if (Results.SelectedRows.Count > 1)
                    {
                        MessageBox.Show("There are too many rows selected. Only select one please.", "Error");
                    }
                    //If the user has selected one row delete that row from the booking table and populate it in the cancelation table with the entered reason
                    else if (Results.SelectedRows.Count == 1)
                    {
                        int            rowNum         = Results.SelectedRows[0].Index;
                        int            cancellationId = int.Parse(Results.Rows[rowNum].Cells[0].Value.ToString());
                        int            childId        = int.Parse(Results.Rows[rowNum].Cells[1].Value.ToString());
                        DateTime       date           = Convert.ToDateTime(Results.Rows[rowNum].Cells[4].Value.ToString());
                        string         reason         = reasonBox.Text;
                        List <Booking> results        = new List <Booking>();
                        results = bdba.getBookWithID(cancellationId);

                        CancellationDBAccess cdba = new CancellationDBAccess(db);
                        cdba.InsertCancell(cancellationId, childId, date, reason);



                        foreach (Booking book in results)
                        {
                            //When the entry is deleted show a message saying 'Success'
                            bdba.DeleteEntry(book.BookingId);
                            new SuccessForm(db, "Success, Booking Cancelled").Show();
                            this.Hide();
                            new MainApp(db).Show();
                        }
                    }

                    //If the user clicks 'No', make the form dissappear
                    else if (result == DialogResult.No)
                    {
                        this.Hide();
                        new CancellForm(db).Show();
                    }
                }
            }
        }
Beispiel #2
0
 private void button3_Click(object sender, EventArgs e)
 {
     //Shows all the data for bookings when the 'View' button is clicked
     if (comboBox1.Text == "Show All")
     {
         BookingDBAccess bdba = new BookingDBAccess(db);
         createTable(bdba.getAllBook());
     }
     //Shows the data for the bookings which matches the searched for BookingId
     else if (comboBox1.Text == "Booking ID")
     {
         BookingDBAccess bdba   = new BookingDBAccess(db);
         int             BookNo = Convert.ToInt32(searchBox.Text);
         createTable(bdba.getBookWithID(BookNo));
     }
     //shows the data for the bookings which matches the searched for Childs name
     else if (comboBox1.Text == "Child Name")
     {
         ChildrenDBAccess cdba = new ChildrenDBAccess(db);
         string           name = searchBox.Text;
         createTableShowAllChild(cdba.GetChildByName(name));
         selectedTable = "Children";
     }
     //Shows the data for the bookings which matches the searched for childs age
     else if (comboBox1.Text == "Child Age")
     {
         ChildrenDBAccess cdba = new ChildrenDBAccess(db);
         int age = Convert.ToInt32(searchBox.Text);
         createTableShowAllChild(cdba.GetChildByAge("=", age.ToString()));
         selectedTable = "Children";
     }
 }